@ms-cloudpack/esm-stub-utilities 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +16 -1
- package/CHANGELOG.md +10 -2
- package/lib/createESMStub.d.ts +1 -1
- package/lib/createESMStub.js +2 -2
- package/lib/createESMStub.js.map +1 -1
- package/lib/createESMStub.test.js +39 -20
- package/lib/createESMStub.test.js.map +1 -1
- package/lib/initializeBrowserEnvironment.js +46 -39
- package/lib/initializeBrowserEnvironment.js.map +1 -1
- package/lib/writeESMStub.js +11 -5
- package/lib/writeESMStub.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,22 @@
|
|
|
2
2
|
"name": "@ms-cloudpack/esm-stub-utilities",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Fri, 12 Aug 2022 08:12:22 GMT",
|
|
6
|
+
"tag": "@ms-cloudpack/esm-stub-utilities_v0.2.1",
|
|
7
|
+
"version": "0.2.1",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"author": "dzearing@microsoft.com",
|
|
12
|
+
"package": "@ms-cloudpack/esm-stub-utilities",
|
|
13
|
+
"commit": "533958ff437ec4556ac825da167e9ad54193f8f4",
|
|
14
|
+
"comment": "Fixing rollup to bundle only supported entries. Also fixing the esm stub creation to asynchronously wait for web environment initialization to complete."
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"date": "Sat, 06 Aug 2022 08:15:40 GMT",
|
|
6
21
|
"tag": "@ms-cloudpack/esm-stub-utilities_v0.2.0",
|
|
7
22
|
"version": "0.2.0",
|
|
8
23
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
# Change Log - @ms-cloudpack/esm-stub-utilities
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Fri, 12 Aug 2022 08:12:22 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 0.2.1
|
|
8
|
+
|
|
9
|
+
Fri, 12 Aug 2022 08:12:22 GMT
|
|
10
|
+
|
|
11
|
+
### Patches
|
|
12
|
+
|
|
13
|
+
- Fixing rollup to bundle only supported entries. Also fixing the esm stub creation to asynchronously wait for web environment initialization to complete. (dzearing@microsoft.com)
|
|
14
|
+
|
|
7
15
|
## 0.2.0
|
|
8
16
|
|
|
9
|
-
Sat, 06 Aug 2022 08:15:
|
|
17
|
+
Sat, 06 Aug 2022 08:15:40 GMT
|
|
10
18
|
|
|
11
19
|
### Minor changes
|
|
12
20
|
|
package/lib/createESMStub.d.ts
CHANGED
package/lib/createESMStub.js
CHANGED
|
@@ -10,11 +10,11 @@ import { forbiddenExportNames } from './forbiddenExportNames.js';
|
|
|
10
10
|
* relative import paths.
|
|
11
11
|
* @param packageExport - The exported package.
|
|
12
12
|
*/
|
|
13
|
-
export function createESMStub(entryPath, stubPath) {
|
|
13
|
+
export async function createESMStub(entryPath, stubPath) {
|
|
14
14
|
const result = [];
|
|
15
15
|
const relativePath = './' + slash(path.relative(path.dirname(stubPath), entryPath));
|
|
16
16
|
// Try and require the entry file.
|
|
17
|
-
initializeBrowserEnvironment();
|
|
17
|
+
await initializeBrowserEnvironment();
|
|
18
18
|
const packageExport = tryRequire(entryPath);
|
|
19
19
|
if (packageExport) {
|
|
20
20
|
let isDefaultExported = false;
|
package/lib/createESMStub.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createESMStub.js","sourceRoot":"","sources":["../src/createESMStub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,IAAI,MAAM,MAAM,CAAC;AACx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,CAAC,+BAA+B,CAAC,CAAC;aAC9C;SACF;aAAM;YACL,4BAA4B;YAC5B,MAAM,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;SAC9C;KACF;SAAM;QACL,uCAAuC;QACvC,MAAM,CAAC,IAAI,CAAC,WAAW,YAAY,IAAI,CAAC,CAAC;KAC1C;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -5,8 +5,8 @@ const dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
5
5
|
const testScenariosPath = path.join(dirname, '../test-scenarios');
|
|
6
6
|
const stubPath = path.join(testScenariosPath, 'esm-stub.js');
|
|
7
7
|
describe('createESMStub', () => {
|
|
8
|
-
it('should create an ESM stub for CommonJS object export without a default', () => {
|
|
9
|
-
expect(createESMStub(path.join(testScenariosPath, 'object-export.cjs'), stubPath)).toMatchInlineSnapshot(`
|
|
8
|
+
it('should create an ESM stub for CommonJS object export without a default', async () => {
|
|
9
|
+
expect(await createESMStub(path.join(testScenariosPath, 'object-export.cjs'), stubPath)).toMatchInlineSnapshot(`
|
|
10
10
|
"import packageExport from \\"./object-export.cjs\\";
|
|
11
11
|
const {
|
|
12
12
|
a,
|
|
@@ -24,8 +24,8 @@ describe('createESMStub', () => {
|
|
|
24
24
|
}"
|
|
25
25
|
`);
|
|
26
26
|
});
|
|
27
|
-
it('should create an ESM stub for CommonJS object export with a named default', () => {
|
|
28
|
-
expect(createESMStub(path.join(testScenariosPath, 'object-export-with-default.cjs'), stubPath))
|
|
27
|
+
it('should create an ESM stub for CommonJS object export with a named default', async () => {
|
|
28
|
+
expect(await createESMStub(path.join(testScenariosPath, 'object-export-with-default.cjs'), stubPath))
|
|
29
29
|
.toMatchInlineSnapshot(`
|
|
30
30
|
"import packageExport from \\"./object-export-with-default.cjs\\";
|
|
31
31
|
const {
|
|
@@ -45,23 +45,23 @@ describe('createESMStub', () => {
|
|
|
45
45
|
}"
|
|
46
46
|
`);
|
|
47
47
|
});
|
|
48
|
-
it('should create an ESM stub for CommonJS function export', () => {
|
|
49
|
-
expect(createESMStub(path.join(testScenariosPath, 'function-export.cjs'), stubPath)).toMatchInlineSnapshot(`
|
|
48
|
+
it('should create an ESM stub for CommonJS function export', async () => {
|
|
49
|
+
expect(await createESMStub(path.join(testScenariosPath, 'function-export.cjs'), stubPath)).toMatchInlineSnapshot(`
|
|
50
50
|
"import packageExport from \\"./function-export.cjs\\";
|
|
51
51
|
export default packageExport;"
|
|
52
52
|
`);
|
|
53
53
|
});
|
|
54
|
-
it('should create an ESM stub for CommonJS string export', () => {
|
|
55
|
-
expect(createESMStub(path.join(testScenariosPath, 'string-export.cjs'), stubPath)).toMatchInlineSnapshot(`"export default packageExport;"`);
|
|
54
|
+
it('should create an ESM stub for CommonJS string export', async () => {
|
|
55
|
+
expect(await createESMStub(path.join(testScenariosPath, 'string-export.cjs'), stubPath)).toMatchInlineSnapshot(`"export default packageExport;"`);
|
|
56
56
|
});
|
|
57
|
-
it("should throw when the code can't be parsed", () => {
|
|
58
|
-
expect(() => createESMStub(path.join(testScenariosPath, 'throws-error.cjs'), stubPath)).
|
|
57
|
+
it("should throw when the code can't be parsed", async () => {
|
|
58
|
+
expect(() => createESMStub(path.join(testScenariosPath, 'throws-error.cjs'), stubPath)).rejects.toBeCalled();
|
|
59
59
|
});
|
|
60
|
-
it('can handle a CommonJS module with no exports', () => {
|
|
61
|
-
expect(createESMStub(path.join(testScenariosPath, 'no-exports.cjs'), stubPath)).toMatchInlineSnapshot(`"import \\"./no-exports.cjs\\";"`);
|
|
60
|
+
it('can handle a CommonJS module with no exports', async () => {
|
|
61
|
+
expect(await createESMStub(path.join(testScenariosPath, 'no-exports.cjs'), stubPath)).toMatchInlineSnapshot(`"import \\"./no-exports.cjs\\";"`);
|
|
62
62
|
});
|
|
63
|
-
it('can snapshot react', () => {
|
|
64
|
-
expect(createESMStub('react', stubPath)).toMatchInlineSnapshot(`
|
|
63
|
+
it('can snapshot react', async () => {
|
|
64
|
+
expect(await createESMStub('react', stubPath)).toMatchInlineSnapshot(`
|
|
65
65
|
"import packageExport from \\"./../react\\";
|
|
66
66
|
const {
|
|
67
67
|
Fragment,
|
|
@@ -127,8 +127,8 @@ describe('createESMStub', () => {
|
|
|
127
127
|
}"
|
|
128
128
|
`);
|
|
129
129
|
});
|
|
130
|
-
it('can snapshot react-dom', () => {
|
|
131
|
-
expect(createESMStub('react-dom', stubPath)).toMatchInlineSnapshot(`
|
|
130
|
+
it('can snapshot react-dom', async () => {
|
|
131
|
+
expect(await createESMStub('react-dom', stubPath)).toMatchInlineSnapshot(`
|
|
132
132
|
"import packageExport from \\"./../react-dom\\";
|
|
133
133
|
const {
|
|
134
134
|
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
|
|
@@ -160,8 +160,8 @@ describe('createESMStub', () => {
|
|
|
160
160
|
}"
|
|
161
161
|
`);
|
|
162
162
|
});
|
|
163
|
-
it('can generate a stub for a browser-sensitive CommonJS module', () => {
|
|
164
|
-
expect(createESMStub(path.join(testScenariosPath, 'browser-sensitive.cjs'), stubPath)).toMatchInlineSnapshot(`
|
|
163
|
+
it('can generate a stub for a browser-sensitive CommonJS module', async () => {
|
|
164
|
+
expect(await createESMStub(path.join(testScenariosPath, 'browser-sensitive.cjs'), stubPath)).toMatchInlineSnapshot(`
|
|
165
165
|
"import packageExport from \\"./browser-sensitive.cjs\\";
|
|
166
166
|
const {
|
|
167
167
|
getDiv,
|
|
@@ -173,9 +173,10 @@ describe('createESMStub', () => {
|
|
|
173
173
|
}"
|
|
174
174
|
`);
|
|
175
175
|
});
|
|
176
|
-
it('can ignore JavaScript keywords in named exports', () => {
|
|
176
|
+
it('can ignore JavaScript keywords in named exports', async () => {
|
|
177
177
|
// Should be missing "delete" in the named exports.
|
|
178
|
-
expect(createESMStub(path.join(testScenariosPath, 'export-with-keyword.cjs'), stubPath))
|
|
178
|
+
expect(await createESMStub(path.join(testScenariosPath, 'export-with-keyword.cjs'), stubPath))
|
|
179
|
+
.toMatchInlineSnapshot(`
|
|
179
180
|
"import packageExport from \\"./export-with-keyword.cjs\\";
|
|
180
181
|
const {
|
|
181
182
|
default: __moduleDefault,
|
|
@@ -188,5 +189,23 @@ describe('createESMStub', () => {
|
|
|
188
189
|
}"
|
|
189
190
|
`);
|
|
190
191
|
});
|
|
192
|
+
it('can generate a stub for node-fetch', async () => {
|
|
193
|
+
expect(await createESMStub(path.join(testScenariosPath, 'node-fetch.cjs'), stubPath)).toMatchInlineSnapshot(`
|
|
194
|
+
"import packageExport from \\"./node-fetch.cjs\\";
|
|
195
|
+
const {
|
|
196
|
+
default: __moduleDefault,
|
|
197
|
+
Headers,
|
|
198
|
+
Request,
|
|
199
|
+
Response,
|
|
200
|
+
} = packageExport;
|
|
201
|
+
|
|
202
|
+
export {
|
|
203
|
+
Headers,
|
|
204
|
+
Request,
|
|
205
|
+
Response,
|
|
206
|
+
__moduleDefault as default,
|
|
207
|
+
}"
|
|
208
|
+
`);
|
|
209
|
+
});
|
|
191
210
|
});
|
|
192
211
|
//# sourceMappingURL=createESMStub.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createESMStub.test.js","sourceRoot":"","sources":["../src/createESMStub.test.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC7D,MAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;AAClE,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,aAAa,CAAC,CAAC;AAE7D,QAAQ,CAA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,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6DAA6D,EAAE,KAAK,IAAI,EAAE;QAC3E,MAAM,CAAC,MAAM,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,uBAAuB,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;KAUlH,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iDAAiD,EAAE,KAAK,IAAI,EAAE;QAC/D,mDAAmD;QACnD,MAAM,CAAC,MAAM,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,yBAAyB,CAAC,EAAE,QAAQ,CAAC,CAAC;aAC3F,qBAAqB,CAAC;;;;;;;;;;;KAWxB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oCAAoC,EAAE,KAAK,IAAI,EAAE;QAClD,MAAM,CAAC,MAAM,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;KAe3G,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,47 +1,54 @@
|
|
|
1
|
+
let hasInitialized = false;
|
|
1
2
|
/**
|
|
2
3
|
* Initializes a browser environment (e.g. by setting up the global `window` in a node environment.)
|
|
3
4
|
*/
|
|
4
5
|
export async function initializeBrowserEnvironment() {
|
|
5
|
-
if (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (tagName === 'canvas') {
|
|
33
|
-
return {
|
|
34
|
-
getContext: () => ({
|
|
35
|
-
fillRect: () => {
|
|
36
|
-
/* no-op */
|
|
37
|
-
},
|
|
38
|
-
}),
|
|
39
|
-
measureText: () => ({}),
|
|
40
|
-
};
|
|
41
|
-
}
|
|
6
|
+
if (!hasInitialized) {
|
|
7
|
+
hasInitialized = true;
|
|
8
|
+
if (typeof window === 'undefined' && typeof global !== 'undefined') {
|
|
9
|
+
const { JSDOM } = await import('jsdom');
|
|
10
|
+
const btoa = await import('btoa');
|
|
11
|
+
const atob = await import('atob');
|
|
12
|
+
await import('jsdom-global');
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
await import('regenerator-runtime');
|
|
16
|
+
const dom = new JSDOM();
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
const globalThis = global;
|
|
19
|
+
globalThis.window = dom.window;
|
|
20
|
+
globalThis.window.requestAnimationFrame = dom.window.setTimeout;
|
|
21
|
+
globalThis.window.cancelAnimationFrame = dom.window.clearTimeout;
|
|
22
|
+
globalThis.btoa = btoa;
|
|
23
|
+
globalThis.atob = atob;
|
|
24
|
+
globalThis.self = dom.window;
|
|
25
|
+
globalThis.document = dom.window.document;
|
|
26
|
+
globalThis.navigator = dom.window.navigator;
|
|
27
|
+
// eslint-disable-next-line etc/no-deprecated
|
|
28
|
+
const createElement = dom.window.document.createElement.bind(dom.window.document);
|
|
29
|
+
// Mock out canvas.
|
|
30
|
+
globalThis.document.createElement =
|
|
31
|
+
globalThis.window.createElement =
|
|
32
|
+
globalThis.createElement =
|
|
42
33
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
(tagName, ...args) => {
|
|
35
|
+
if (tagName === 'canvas') {
|
|
36
|
+
return {
|
|
37
|
+
getContext: () => ({
|
|
38
|
+
fillRect: () => {
|
|
39
|
+
/* no-op */
|
|
40
|
+
},
|
|
41
|
+
}),
|
|
42
|
+
measureText: () => ({}),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
+
return createElement.apply(dom.window.document, [tagName, ...args]);
|
|
47
|
+
};
|
|
48
|
+
globalThis.window.fetch = async () => {
|
|
49
|
+
/* no-op */
|
|
50
|
+
};
|
|
51
|
+
}
|
|
45
52
|
}
|
|
46
53
|
}
|
|
47
54
|
//# sourceMappingURL=initializeBrowserEnvironment.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initializeBrowserEnvironment.js","sourceRoot":"","sources":["../src/initializeBrowserEnvironment.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B;IAChD,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;
|
|
1
|
+
{"version":3,"file":"initializeBrowserEnvironment.js","sourceRoot":"","sources":["../src/initializeBrowserEnvironment.ts"],"names":[],"mappings":"AAAA,IAAI,cAAc,GAAG,KAAK,CAAC;AAE3B;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B;IAChD,IAAI,CAAC,cAAc,EAAE;QACnB,cAAc,GAAG,IAAI,CAAC;QACtB,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;YAClE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC;YACxC,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;YAClC,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;YAElC,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC;YAE7B,6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AA8D;4BAC9D,OAAQ,aAAqB,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;wBAC/E,CAAC,CAAC;YAEN,UAAU,CAAC,MAAM,CAAC,KAAK,GAAG,KAAK,IAAI,EAAE;gBACnC,WAAW;YACb,CAAC,CAAC;SACH;KACF;AACH,CAAC"}
|
package/lib/writeESMStub.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
|
-
import os from 'os';
|
|
3
2
|
import path from 'path';
|
|
4
3
|
import { createESMStub } from './createESMStub.js';
|
|
5
|
-
import { slash } from '@ms-cloudpack/path-utilities';
|
|
6
|
-
const { writeFile,
|
|
4
|
+
import { findPackageRoot, slash } from '@ms-cloudpack/path-utilities';
|
|
5
|
+
const { writeFile, mkdir } = fs.promises;
|
|
7
6
|
/**
|
|
8
7
|
* Generates an ESM stub for CommonJS modules.
|
|
9
8
|
*/
|
|
@@ -11,9 +10,16 @@ export async function writeESMStub(entryPath, stubPath) {
|
|
|
11
10
|
// Ensure forward slashes
|
|
12
11
|
entryPath = slash(entryPath);
|
|
13
12
|
// Ensure stub path is provided.
|
|
14
|
-
|
|
13
|
+
if (!stubPath) {
|
|
14
|
+
const rootPath = findPackageRoot(entryPath);
|
|
15
|
+
const extension = path.extname(entryPath);
|
|
16
|
+
const stubFilename = path.basename(entryPath, extension) + '-stub.js';
|
|
17
|
+
const stubFolderPath = path.join(rootPath, 'node_modules/.cache/cloudpack-stubs/');
|
|
18
|
+
await mkdir(stubFolderPath, { recursive: true });
|
|
19
|
+
stubPath = path.join(stubFolderPath, stubFilename);
|
|
20
|
+
}
|
|
15
21
|
// If we have a package export, we can generate an ESM stub.
|
|
16
|
-
const esmStub = createESMStub(entryPath, stubPath);
|
|
22
|
+
const esmStub = await createESMStub(entryPath, stubPath);
|
|
17
23
|
// Write the stub to disk.
|
|
18
24
|
await writeFile(stubPath, esmStub);
|
|
19
25
|
return stubPath;
|
package/lib/writeESMStub.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeESMStub.js","sourceRoot":"","sources":["../src/writeESMStub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,
|
|
1
|
+
{"version":3,"file":"writeESMStub.js","sourceRoot":"","sources":["../src/writeESMStub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAEtE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC;AAEzC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,SAAiB,EAAE,QAAiB;IACrE,yBAAyB;IACzB,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC;IAE7B,gCAAgC;IAChC,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,QAAQ,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;QAC5C,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC1C,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,GAAG,UAAU,CAAC;QACtE,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,sCAAsC,CAAC,CAAC;QAEnF,MAAM,KAAK,CAAC,cAAc,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAEjD,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;KACpD;IAED,4DAA4D;IAC5D,MAAM,OAAO,GA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