Skip to content

Commit 39f52b0

Browse files
authored
Update publishing.md
1 parent 7ac914b commit 39f52b0

File tree

1 file changed

+36
-22
lines changed

1 file changed

+36
-22
lines changed

design/publishing.md

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,69 @@
11
##### This design document focuses on the following -
22
1. Separate entry points for node and browser.
3-
2. Specifying the browser field in package.json
4-
3. Changes in the bundling process
3+
2. Specifying the browser field in package.json.
4+
3. Changes in the bundling process.
55

66
##### Terms -
77

8-
bundler - Module bundlers are tools frontend developers used to bundle JavaScript modules into a single JavaScript files that can be executed in the browser.
8+
* bundler - Module bundlers are tools frontend developers used to bundle JavaScript modules into a single JavaScript files that can be executed in the browser.
99

10-
package.json fields -
11-
* main - The main field is a module ID that is the primary entry point to your program. Points to the CJS modules.
10+
* rollup - rollup.js is the module bundler that the JS SDK uses.
1211

13-
* module - The module field is not an official npm feature but a common convention among bundlers to designate how to import an ESM version of a library. Points to the ES modules.
12+
* package.json fields -
13+
* main - The main field is a module ID that is the primary entry point to your program. Points to the CJS modules.
1414

15-
* browser - If your module is meant to be used client-side the browser field should be used instead of the main field.
15+
* module - The module field is not an official npm feature but a common convention among bundlers to designate how to import an ESM version of a library. Points to the ES modules.
16+
17+
* browser - If the module is meant to be used client-side, the browser field should be used instead of the main field.
1618

1719
##### Current set up -
1820

1921
1.
2022
TypeScript Source Code
2123
/ \
2224
Transpiles into JavaScript
25+
'lib' folder
2326
/ \
2427
CJS module ES modules
2528
2. main - `lib/src/index.js`
26-
module - `lib/src/es/index.js`
29+
module - `lib/es/src/index.js`
2730

2831
3. Rollup bundling output
29-
* graph-js-sdk.js - IIFE bundled minified file. This file can be directly used in the browser with a `<script>` tag.
30-
* graph-es-sdk.js - ES bundled file.
31-
4. Entry point for rollup - `lib/es/browser/index.js`.
32+
* `graph-js-sdk.js` - Bundled and minified file in IIFE format. This file can be directly used in the browser with a `<script>` tag.
33+
* `graph-es-sdk.js` - Bundled filein ES format.
34+
4. Entry point for rollup - `lib/es/src/browser/index.js`.
3235

3336
##### Difference between src/index.js and src/browser/index.js
34-
1. src/browser/index.js does not export 'RedirectHandler' and 'RedirectHandlerOptions'. Redirection is handled by the browser.
35-
2. src/index.js exports-> src/ImplicitMsalProvider and src/browser/index.js exports src/browser/ImplicitMsalProvider.
36-
3. Only difference in the implementation is that src/browser/ImplicitMsalProvider does not import or require 'msal' dependency.
37+
1. `src/browser/index.js` does not export `RedirectHandler` and `RedirectHandlerOptions`. Redirection is handled by the browser.
38+
2. `src/browser/index.js` exports `src/browser/ImplicitMsalProvider`.
39+
3. `src/browser/ImplicitMsalProvider` does not import or require 'msal' dependency. While,
40+
`src/ImplicitMsalProvider` imports or requires 'msal' in the implementation.
41+
4. My assumtion is that `src/browser/ImplicitMsalProvider` is implemented specifically for the rollup process and to skip the rollup external dependency while using `graph-js-sdk.js` in the browser.
3742

38-
Presently, some browser applications importing the npm package like Graph Explorer use lib/es/src/index.js and not the browser/index.js.
43+
Note - Browser applications using the ES modules from the npm package of the JS SDK refer to the `module` entry point - `lib/es/src/index.js`(not the browser entry point). Example - Graph Explorer.
3944

4045
##### Upcoming changes -
4146

4247
1. Use the browser field for the following -
4348

44-
* We currently have two entry files, src/index.ts and src/browser/index.ts.
49+
* We currently have two entry files, `src/index` and `src/browser/index`.
4550
Use the browser field to indicate the browser entry point.
4651
Example -
4752
"browser":
48-
{ "lib/es/index.node.js": "lib/es/index.browser.js" }
53+
{ "lib/es/src/index.js": "lib/es/src/browser/index.js" }
4954
Currently, we have the main and "module field in the package.json. This will remain the same.
50-
2. Better way to handle environment specific implementation. For example, using the browser field we can indicate as follows -
55+
* Better way to handle environment specific implementation. For example, using the `browser` field we can indicate as follows -
5156
"browser":
52-
{ "stream": "stream-browserify" }
53-
3. Maintain a separate entry point for the rollup process.
54-
4. Continue rolling up the src/browser/ImplicitMsalProvider as we currently do and not introduce breaking changes here as we are planning to deprecate this.
55-
5. Bundle the authproviders separately as they are optional.
57+
{ "stream": "stream-browserify",
58+
"Feature-Node.js": "Feature-Browser.js"
59+
}
60+
61+
62+
2. Remove export of `src/browser/ImplicitMsalProvider` from `src/browser/index`.
63+
* Till `ImplicitMsalProvider` is maintained in the repo, maintain a separate entry point say `rollup-index` for the rollup process which exports `src/browser/index` and `src/browser/ImplicitMsalProvider`.
64+
* Continue rolling up the `src/browser/ImplicitMsalProvider` as we currently do and not introduce breaking changes here as we are planning to deprecate this.
65+
* Remove the separate entry point once `ImplicitMsalProvider` is removed and use the browser entry point for roll up thereafter. The goal is to maintain a consistent entry point or usage for browser applications using the JS SDK and the rollup/bundling process.
66+
67+
3. Bundle the authproviders separately as they are optional.
68+
69+
4. Stop bundling in ES format, that is remove `graph-es-sdk.js` as the ES modules are being shipped.

0 commit comments

Comments
 (0)