|
1 | 1 | ##### This design document focuses on the following - |
2 | 2 | 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. |
5 | 5 |
|
6 | 6 | ##### Terms - |
7 | 7 |
|
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. |
9 | 9 |
|
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. |
12 | 11 |
|
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. |
14 | 14 |
|
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. |
16 | 18 |
|
17 | 19 | ##### Current set up - |
18 | 20 |
|
19 | 21 | 1. |
20 | 22 | TypeScript Source Code |
21 | 23 | / \ |
22 | 24 | Transpiles into JavaScript |
| 25 | + 'lib' folder |
23 | 26 | / \ |
24 | 27 | CJS module ES modules |
25 | 28 | 2. main - `lib/src/index.js` |
26 | | - module - `lib/src/es/index.js` |
| 29 | + module - `lib/es/src/index.js` |
27 | 30 |
|
28 | 31 | 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`. |
32 | 35 |
|
33 | 36 | ##### 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. |
37 | 42 |
|
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. |
39 | 44 |
|
40 | 45 | ##### Upcoming changes - |
41 | 46 |
|
42 | 47 | 1. Use the browser field for the following - |
43 | 48 |
|
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`. |
45 | 50 | Use the browser field to indicate the browser entry point. |
46 | 51 | Example - |
47 | 52 | "browser": |
48 | | -{ "lib/es/index.node.js": "lib/es/index.browser.js" } |
| 53 | +{ "lib/es/src/index.js": "lib/es/src/browser/index.js" } |
49 | 54 | 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 - |
51 | 56 | "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