@ms-cloudpack/esm-stub-utilities 0.4.1 → 0.5.0

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.
@@ -1,4 +1,2 @@
1
1
  /** @param {string} modulePath */
2
2
  export function tryRequire(modulePath: string): unknown;
3
- /** @param {string} modulePath */
4
- export function tryRequire(modulePath: string): unknown;
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.33.6"
8
+ "packageVersion": "7.34.0"
9
9
  }
10
10
  ]
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/esm-stub-utilities",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Generates ESM stubs for CommonJS entry files.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -13,12 +13,12 @@
13
13
  }
14
14
  },
15
15
  "dependencies": {
16
- "@ms-cloudpack/path-utilities": "^2.0.0",
17
- "@ms-cloudpack/path-string-parsing": "^1.0.0",
16
+ "@ms-cloudpack/path-utilities": "^2.0.1",
17
+ "@ms-cloudpack/path-string-parsing": "^1.0.1",
18
18
  "atob": "^2.1.2",
19
19
  "btoa": "^1.2.1",
20
20
  "jsdom-global": "^3.0.2",
21
- "jsdom": "^20.0.0",
21
+ "jsdom": "^21.1.0",
22
22
  "regenerator-runtime": "^0.13.9"
23
23
  },
24
24
  "devDependencies": {
@@ -42,11 +42,6 @@
42
42
  "test": "cloudpack-scripts test"
43
43
  },
44
44
  "files": [
45
- "/lib"
46
- ],
47
- "beachball": {
48
- "disallowedChangeTypes": [
49
- "major"
50
- ]
51
- }
45
+ "lib/**/!(*.test.*)"
46
+ ]
52
47
  }
package/CHANGELOG.json DELETED
@@ -1,338 +0,0 @@
1
- {
2
- "name": "@ms-cloudpack/esm-stub-utilities",
3
- "entries": [
4
- {
5
- "date": "Sat, 03 Dec 2022 08:10:22 GMT",
6
- "tag": "@ms-cloudpack/esm-stub-utilities_v0.4.1",
7
- "version": "0.4.1",
8
- "comments": {
9
- "none": [
10
- {
11
- "author": "dake.3601@gmail.com",
12
- "package": "@ms-cloudpack/esm-stub-utilities",
13
- "commit": "9fae6cbdb788baac8236abc9eb44eb1d3296b7e0",
14
- "comment": "Updated beachball config to disallow major bumps"
15
- }
16
- ],
17
- "patch": [
18
- {
19
- "author": "beachball",
20
- "package": "@ms-cloudpack/esm-stub-utilities",
21
- "comment": "Bump @ms-cloudpack/path-utilities to v2.0.0",
22
- "commit": "adb6e5b06d2100f33ff9975c2999b81f81b65616"
23
- }
24
- ]
25
- }
26
- },
27
- {
28
- "date": "Tue, 15 Nov 2022 08:13:12 GMT",
29
- "tag": "@ms-cloudpack/esm-stub-utilities_v0.4.0",
30
- "version": "0.4.0",
31
- "comments": {
32
- "minor": [
33
- {
34
- "author": "dzearing@microsoft.com",
35
- "package": "@ms-cloudpack/esm-stub-utilities",
36
- "commit": "a71972309b615d683a5a3bac7a85c981fb6e89af",
37
- "comment": "When we emit esm stubs, we now try to use import * for object exports, and import for function exports."
38
- },
39
- {
40
- "author": "beachball",
41
- "package": "@ms-cloudpack/esm-stub-utilities",
42
- "comment": "Bump @ms-cloudpack/path-utilities to v1.1.1",
43
- "commit": "a71972309b615d683a5a3bac7a85c981fb6e89af"
44
- }
45
- ]
46
- }
47
- },
48
- {
49
- "date": "Wed, 02 Nov 2022 08:11:20 GMT",
50
- "tag": "@ms-cloudpack/esm-stub-utilities_v0.3.4",
51
- "version": "0.3.4",
52
- "comments": {
53
- "patch": [
54
- {
55
- "author": "dzearing@microsoft.com",
56
- "package": "@ms-cloudpack/esm-stub-utilities",
57
- "commit": "3439c51ff4eb7cb624cf84fb2881a781eabca83f",
58
- "comment": "README updates."
59
- }
60
- ]
61
- }
62
- },
63
- {
64
- "date": "Tue, 01 Nov 2022 08:11:03 GMT",
65
- "tag": "@ms-cloudpack/esm-stub-utilities_v0.3.3",
66
- "version": "0.3.3",
67
- "comments": {
68
- "none": [
69
- {
70
- "author": "dzearing@microsoft.com",
71
- "package": "@ms-cloudpack/esm-stub-utilities",
72
- "commit": "264fdebf12d3c964f2520feef232af76425cdc4c",
73
- "comment": "Updating readme notes."
74
- }
75
- ]
76
- }
77
- },
78
- {
79
- "date": "Tue, 18 Oct 2022 08:16:24 GMT",
80
- "tag": "@ms-cloudpack/esm-stub-utilities_v0.3.3",
81
- "version": "0.3.3",
82
- "comments": {
83
- "patch": [
84
- {
85
- "author": "beachball",
86
- "package": "@ms-cloudpack/esm-stub-utilities",
87
- "comment": "Bump @ms-cloudpack/path-utilities to v1.1.0",
88
- "commit": "1bec1f80bb50ebe897f03dc74437c3e211bea83e"
89
- }
90
- ]
91
- }
92
- },
93
- {
94
- "date": "Sat, 15 Oct 2022 08:11:31 GMT",
95
- "tag": "@ms-cloudpack/esm-stub-utilities_v0.3.2",
96
- "version": "0.3.2",
97
- "comments": {
98
- "none": [
99
- {
100
- "author": "dake.3601@gmail.com",
101
- "package": "@ms-cloudpack/esm-stub-utilities",
102
- "commit": "962ebd9eb867b159565e221c9f5e800a8eb0ec84",
103
- "comment": "Moving dependency to different package."
104
- }
105
- ],
106
- "patch": [
107
- {
108
- "author": "beachball",
109
- "package": "@ms-cloudpack/esm-stub-utilities",
110
- "comment": "Bump @ms-cloudpack/path-utilities to v1.0.0",
111
- "commit": "cc252ba3e978d70205028b940070eac18e0d33aa"
112
- },
113
- {
114
- "author": "beachball",
115
- "package": "@ms-cloudpack/esm-stub-utilities",
116
- "comment": "Bump @ms-cloudpack/path-string-parsing to v1.0.0",
117
- "commit": "cc252ba3e978d70205028b940070eac18e0d33aa"
118
- }
119
- ]
120
- }
121
- },
122
- {
123
- "date": "Wed, 28 Sep 2022 08:15:16 GMT",
124
- "tag": "@ms-cloudpack/esm-stub-utilities_v0.3.1",
125
- "version": "0.3.1",
126
- "comments": {
127
- "patch": [
128
- {
129
- "author": "elcraig@microsoft.com",
130
- "package": "@ms-cloudpack/esm-stub-utilities",
131
- "commit": "084168500b6320d6861a4c7e8f363fea9e4f831e",
132
- "comment": "Rename tryRequire.cjs to tryRequire.cts"
133
- }
134
- ]
135
- }
136
- },
137
- {
138
- "date": "Wed, 21 Sep 2022 08:15:19 GMT",
139
- "tag": "@ms-cloudpack/esm-stub-utilities_v0.3.0",
140
- "version": "0.3.0",
141
- "comments": {
142
- "minor": [
143
- {
144
- "author": "dzearing@microsoft.com",
145
- "package": "@ms-cloudpack/esm-stub-utilities",
146
- "commit": "f67f57c632b247d0375d54d2c839447dc5c34156",
147
- "comment": "Updating string and boolean exports to emit properly."
148
- },
149
- {
150
- "author": "beachball",
151
- "package": "@ms-cloudpack/esm-stub-utilities",
152
- "comment": "Bump @ms-cloudpack/path-utilities to v0.5.0",
153
- "commit": "edaf39b3a641d469b5238c446b23e25399714ebd"
154
- }
155
- ]
156
- }
157
- },
158
- {
159
- "date": "Tue, 06 Sep 2022 08:17:50 GMT",
160
- "tag": "@ms-cloudpack/esm-stub-utilities_v0.2.4",
161
- "version": "0.2.4",
162
- "comments": {
163
- "none": [
164
- {
165
- "author": "dzearing@microsoft.com",
166
- "package": "@ms-cloudpack/esm-stub-utilities",
167
- "commit": "2b961ca2bb0304eec6a5ce25d49a3c66072a113f",
168
- "comment": "Updating api-extractor."
169
- }
170
- ],
171
- "patch": [
172
- {
173
- "author": "beachball",
174
- "package": "@ms-cloudpack/esm-stub-utilities",
175
- "comment": "Bump @ms-cloudpack/path-utilities to v0.4.0",
176
- "commit": "6bfb08a58af608b2e633ae7a4b686a6eabea29ca"
177
- }
178
- ]
179
- }
180
- },
181
- {
182
- "date": "Sat, 03 Sep 2022 08:15:29 GMT",
183
- "tag": "@ms-cloudpack/esm-stub-utilities_v0.2.3",
184
- "version": "0.2.3",
185
- "comments": {
186
- "patch": [
187
- {
188
- "author": "beachball",
189
- "package": "@ms-cloudpack/esm-stub-utilities",
190
- "comment": "Bump @ms-cloudpack/path-utilities to v0.3.2",
191
- "commit": "ec909bf967a54b174cb1d50e7e55bd4b3ed02884"
192
- }
193
- ]
194
- }
195
- },
196
- {
197
- "date": "Fri, 26 Aug 2022 08:12:22 GMT",
198
- "tag": "@ms-cloudpack/esm-stub-utilities_v0.2.2",
199
- "version": "0.2.2",
200
- "comments": {
201
- "patch": [
202
- {
203
- "author": "email not defined",
204
- "package": "@ms-cloudpack/esm-stub-utilities",
205
- "commit": "78a20a9b97f472809849048e1f37f33365366f0b",
206
- "comment": "Update dependency jsdom to v20"
207
- }
208
- ]
209
- }
210
- },
211
- {
212
- "date": "Fri, 12 Aug 2022 08:12:39 GMT",
213
- "tag": "@ms-cloudpack/esm-stub-utilities_v0.2.1",
214
- "version": "0.2.1",
215
- "comments": {
216
- "patch": [
217
- {
218
- "author": "dzearing@microsoft.com",
219
- "package": "@ms-cloudpack/esm-stub-utilities",
220
- "commit": "533958ff437ec4556ac825da167e9ad54193f8f4",
221
- "comment": "Fixing rollup to bundle only supported entries. Also fixing the esm stub creation to asynchronously wait for web environment initialization to complete."
222
- }
223
- ]
224
- }
225
- },
226
- {
227
- "date": "Sat, 06 Aug 2022 08:15:40 GMT",
228
- "tag": "@ms-cloudpack/esm-stub-utilities_v0.2.0",
229
- "version": "0.2.0",
230
- "comments": {
231
- "minor": [
232
- {
233
- "author": "dzearing@microsoft.com",
234
- "package": "@ms-cloudpack/esm-stub-utilities",
235
- "commit": "70b5e51ee1e2bbb80d6b6fef1dbbf819d3634a0b",
236
- "comment": "Fixing stub generation to emit to a physical location on macs, rather than symlink."
237
- }
238
- ]
239
- }
240
- },
241
- {
242
- "date": "Tue, 02 Aug 2022 19:53:54 GMT",
243
- "tag": "@ms-cloudpack/esm-stub-utilities_v0.1.2",
244
- "version": "0.1.2",
245
- "comments": {
246
- "patch": [
247
- {
248
- "author": "renovate@whitesourcesoftware.com",
249
- "package": "@ms-cloudpack/esm-stub-utilities",
250
- "commit": "dc1ecdc793357827f70515d00830ecd35491b76c",
251
- "comment": "Update dependency @types/jsdom to v16.2.15"
252
- }
253
- ]
254
- }
255
- },
256
- {
257
- "date": "Thu, 28 Jul 2022 18:39:20 GMT",
258
- "tag": "@ms-cloudpack/esm-stub-utilities_v0.1.1",
259
- "version": "0.1.1",
260
- "comments": {
261
- "patch": [
262
- {
263
- "author": "email not defined",
264
- "package": "@ms-cloudpack/esm-stub-utilities",
265
- "commit": "ddec754013e36611f3f6b25e1146cb214402de28",
266
- "comment": "Update dependency @types/jsdom-global to v3.0.3"
267
- }
268
- ]
269
- }
270
- },
271
- {
272
- "date": "Wed, 29 Jun 2022 02:45:18 GMT",
273
- "tag": "@ms-cloudpack/esm-stub-utilities_v0.1.0",
274
- "version": "0.1.0",
275
- "comments": {
276
- "none": [
277
- {
278
- "author": "email not defined",
279
- "package": "@ms-cloudpack/esm-stub-utilities",
280
- "commit": "94790eee5ac4401529c3f1215168ffb3725dfd61",
281
- "comment": "Pin devDependencies"
282
- }
283
- ]
284
- }
285
- },
286
- {
287
- "date": "Wed, 08 Jun 2022 20:07:00 GMT",
288
- "tag": "@ms-cloudpack/esm-stub-utilities_v0.1.0",
289
- "version": "0.1.0",
290
- "comments": {
291
- "minor": [
292
- {
293
- "author": "dzearing@microsoft.com",
294
- "package": "@ms-cloudpack/esm-stub-utilities",
295
- "commit": "0e78dd2f1cf4d366f04d52d54996418c4febcfb6",
296
- "comment": "Updating writeESMStub to return the filepath, making path input option (using temp file if not provided.)"
297
- },
298
- {
299
- "author": "beachball",
300
- "package": "@ms-cloudpack/esm-stub-utilities",
301
- "comment": "Bump @ms-cloudpack/path-utilities to v0.3.1",
302
- "commit": "0e78dd2f1cf4d366f04d52d54996418c4febcfb6"
303
- }
304
- ]
305
- }
306
- },
307
- {
308
- "date": "Fri, 03 Jun 2022 21:51:54 GMT",
309
- "tag": "@ms-cloudpack/esm-stub-utilities_v0.0.2",
310
- "version": "0.0.2",
311
- "comments": {
312
- "none": [
313
- {
314
- "author": "bot@renovateapp.com",
315
- "package": "@ms-cloudpack/esm-stub-utilities",
316
- "commit": "c27f62a8cc6cef068c201ce4e0802f49508a01d4",
317
- "comment": "Pin dev dependencies"
318
- }
319
- ]
320
- }
321
- },
322
- {
323
- "date": "Fri, 27 May 2022 20:32:39 GMT",
324
- "tag": "@ms-cloudpack/esm-stub-utilities_v0.0.2",
325
- "version": "0.0.2",
326
- "comments": {
327
- "patch": [
328
- {
329
- "author": "dzearing@microsoft.com",
330
- "package": "@ms-cloudpack/esm-stub-utilities",
331
- "commit": "0cc8ffacb753e45c6fa31b462ea8b90da5b185e5",
332
- "comment": "Initial publish of esm-stub-utilities package."
333
- }
334
- ]
335
- }
336
- }
337
- ]
338
- }
package/CHANGELOG.md DELETED
@@ -1,137 +0,0 @@
1
- # Change Log - @ms-cloudpack/esm-stub-utilities
2
-
3
- This log was last generated on Sat, 03 Dec 2022 08:10:22 GMT and should not be manually modified.
4
-
5
- <!-- Start content -->
6
-
7
- ## 0.4.1
8
-
9
- Sat, 03 Dec 2022 08:10:22 GMT
10
-
11
- ### Patches
12
-
13
- - Bump @ms-cloudpack/path-utilities to v2.0.0
14
-
15
- ## 0.4.0
16
-
17
- Tue, 15 Nov 2022 08:13:12 GMT
18
-
19
- ### Minor changes
20
-
21
- - When we emit esm stubs, we now try to use import * for object exports, and import for function exports. (dzearing@microsoft.com)
22
- - Bump @ms-cloudpack/path-utilities to v1.1.1
23
-
24
- ## 0.3.4
25
-
26
- Wed, 02 Nov 2022 08:11:20 GMT
27
-
28
- ### Patches
29
-
30
- - README updates. (dzearing@microsoft.com)
31
-
32
- ## 0.3.3
33
-
34
- Tue, 18 Oct 2022 08:16:24 GMT
35
-
36
- ### Patches
37
-
38
- - Bump @ms-cloudpack/path-utilities to v1.1.0
39
-
40
- ## 0.3.2
41
-
42
- Sat, 15 Oct 2022 08:11:31 GMT
43
-
44
- ### Patches
45
-
46
- - Bump @ms-cloudpack/path-utilities to v1.0.0
47
- - Bump @ms-cloudpack/path-string-parsing to v1.0.0
48
-
49
- ## 0.3.1
50
-
51
- Wed, 28 Sep 2022 08:15:16 GMT
52
-
53
- ### Patches
54
-
55
- - Rename tryRequire.cjs to tryRequire.cts (elcraig@microsoft.com)
56
-
57
- ## 0.3.0
58
-
59
- Wed, 21 Sep 2022 08:15:19 GMT
60
-
61
- ### Minor changes
62
-
63
- - Updating string and boolean exports to emit properly. (dzearing@microsoft.com)
64
- - Bump @ms-cloudpack/path-utilities to v0.5.0
65
-
66
- ## 0.2.4
67
-
68
- Tue, 06 Sep 2022 08:17:50 GMT
69
-
70
- ### Patches
71
-
72
- - Bump @ms-cloudpack/path-utilities to v0.4.0
73
-
74
- ## 0.2.3
75
-
76
- Sat, 03 Sep 2022 08:15:29 GMT
77
-
78
- ### Patches
79
-
80
- - Bump @ms-cloudpack/path-utilities to v0.3.2
81
-
82
- ## 0.2.2
83
-
84
- Fri, 26 Aug 2022 08:12:22 GMT
85
-
86
- ### Patches
87
-
88
- - Update dependency jsdom to v20 (email not defined)
89
-
90
- ## 0.2.1
91
-
92
- Fri, 12 Aug 2022 08:12:39 GMT
93
-
94
- ### Patches
95
-
96
- - 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)
97
-
98
- ## 0.2.0
99
-
100
- Sat, 06 Aug 2022 08:15:40 GMT
101
-
102
- ### Minor changes
103
-
104
- - Fixing stub generation to emit to a physical location on macs, rather than symlink. (dzearing@microsoft.com)
105
-
106
- ## 0.1.2
107
-
108
- Tue, 02 Aug 2022 19:53:54 GMT
109
-
110
- ### Patches
111
-
112
- - Update dependency @types/jsdom to v16.2.15 (renovate@whitesourcesoftware.com)
113
-
114
- ## 0.1.1
115
-
116
- Thu, 28 Jul 2022 18:39:20 GMT
117
-
118
- ### Patches
119
-
120
- - Update dependency @types/jsdom-global to v3.0.3 (email not defined)
121
-
122
- ## 0.1.0
123
-
124
- Wed, 08 Jun 2022 20:07:00 GMT
125
-
126
- ### Minor changes
127
-
128
- - Updating writeESMStub to return the filepath, making path input option (using temp file if not provided.) (dzearing@microsoft.com)
129
- - Bump @ms-cloudpack/path-utilities to v0.3.1
130
-
131
- ## 0.0.2
132
-
133
- Fri, 27 May 2022 20:32:39 GMT
134
-
135
- ### Patches
136
-
137
- - Initial publish of esm-stub-utilities package. (dzearing@microsoft.com)
@@ -1 +0,0 @@
1
- export {};
@@ -1,145 +0,0 @@
1
- import { describe, it, expect } from '@jest/globals';
2
- import path from 'path';
3
- import { fileURLToPath } from 'url';
4
- import { createESMStub } from './createESMStub.js';
5
- const dirname = path.dirname(fileURLToPath(import.meta.url));
6
- const testScenariosPath = path.join(dirname, '../test-scenarios');
7
- const stubPath = path.join(testScenariosPath, 'esm-stub.js');
8
- // Remove absolute import paths from the generated stub.
9
- const makeStubSafe = (stub) => {
10
- return stub.replace(/from "[a-zA-Z0-9./:-]+";/g, 'from "---omitted for safety---"');
11
- };
12
- describe('createESMStub', () => {
13
- it('should handle sorted-btree', async () => {
14
- const testScenarioPath = path.join(testScenariosPath, 'b-tree.cjs');
15
- const testScenarioStubPath = path.join(testScenariosPath, 'b-tree.stub.mjs');
16
- const stub = await createESMStub(testScenarioPath, testScenarioStubPath);
17
- expect(makeStubSafe(stub)).toMatchInlineSnapshot(`
18
- "import * as packageExport from "---omitted for safety---"
19
- const { defaultComparator, simpleComparator, asSet, EmptyBTree } = packageExport;
20
- const defaultExport = (packageExport && packageExport.default?.default) ? packageExport?.default.default : packageExport?.default;
21
- export default defaultExport;
22
- export { defaultComparator, simpleComparator, asSet, EmptyBTree }"
23
- `);
24
- });
25
- it('should handle yallist', async () => {
26
- const testScenarioPath = path.join(testScenariosPath, 'yallist.cjs');
27
- const testScenarioStubPath = path.join(testScenariosPath, 'yallist.stub.mjs');
28
- const stub = await createESMStub(testScenarioPath, testScenarioStubPath);
29
- expect(makeStubSafe(stub)).toMatchInlineSnapshot(`
30
- "import packageExport from "---omitted for safety---"
31
- const { Node, create } = packageExport;
32
- export default packageExport;
33
- export { Node, create }"
34
- `);
35
- });
36
- it('should handle events', async () => {
37
- const testScenarioPath = path.join(testScenariosPath, 'events.cjs');
38
- const testScenarioStubPath = path.join(testScenariosPath, 'events.stub.mjs');
39
- const stub = await createESMStub(testScenarioPath, testScenarioStubPath);
40
- expect(makeStubSafe(stub)).toMatchInlineSnapshot(`
41
- "import packageExport from "---omitted for safety---"
42
- const { once, EventEmitter, defaultMaxListeners, init, listenerCount } = packageExport;
43
- export default packageExport;
44
- export { once, EventEmitter, defaultMaxListeners, init, listenerCount }"
45
- `);
46
- });
47
- it('should handle object-assign', async () => {
48
- const testScenarioPath = path.join(testScenariosPath, 'object-assign.cjs');
49
- const testScenarioStubPath = path.join(testScenariosPath, 'object-assign.stub.mjs');
50
- const stub = await createESMStub(testScenarioPath, testScenarioStubPath);
51
- expect(makeStubSafe(stub)).toMatchInlineSnapshot(`"export { default } from "---omitted for safety---""`);
52
- });
53
- it(`should handle react-lifecycles-compat`, async () => {
54
- const testScenarioPath = path.join(testScenariosPath, 'react-lifecycles-compat.cjs');
55
- const testScenarioStubPath = path.join(testScenariosPath, 'react-lifecycles-compat.stub.mjs');
56
- const stub = await createESMStub(testScenarioPath, testScenarioStubPath);
57
- expect(makeStubSafe(stub)).toMatchInlineSnapshot(`
58
- "import * as packageExport from "---omitted for safety---"
59
- const { polyfill } = packageExport;
60
- export default packageExport;
61
- export { polyfill }"
62
- `);
63
- });
64
- it('should create an ESM stub for CommonJS object export with a named default', async () => {
65
- expect(await createESMStub(path.join(testScenariosPath, 'object-export-with-default.cjs'), stubPath))
66
- .toMatchInlineSnapshot(`
67
- "import * as packageExport from "./object-export-with-default.cjs";
68
- const { a, b, c, d } = packageExport;
69
- const defaultExport = (packageExport && packageExport.default?.default) ? packageExport?.default.default : packageExport?.default;
70
- export default defaultExport;
71
- export { a, b, c, d }"
72
- `);
73
- });
74
- it('should create an ESM stub for CommonJS function export', async () => {
75
- expect(await createESMStub(path.join(testScenariosPath, 'function-export.cjs'), stubPath)).toMatchInlineSnapshot(`"export { default } from "./function-export.cjs";"`);
76
- });
77
- it('should create an ESM stub for CommonJS string export', async () => {
78
- expect(await createESMStub(path.join(testScenariosPath, 'string-export.cjs'), stubPath)).toMatchInlineSnapshot(`"export default "I am a string with \\"double quotes\\" and 'single quotes'";"`);
79
- });
80
- // it("should throw when the code can't be parsed", async () => {
81
- // expect(() => createESMStub(path.join(testScenariosPath, 'throws-error.cjs'), stubPath)).rejects.toBeCalled();
82
- // });
83
- it('can handle a CommonJS module with no exports', async () => {
84
- expect(await createESMStub(path.join(testScenariosPath, 'no-exports.cjs'), stubPath)).toMatchInlineSnapshot(`"import "./no-exports.cjs";"`);
85
- });
86
- it('can snapshot react', async () => {
87
- expect(await createESMStub(path.join(testScenariosPath, 'react.development.cjs'), stubPath)).toMatchInlineSnapshot(`
88
- "import * as packageExport from "./react.development.cjs";
89
- const { Fragment, StrictMode, Profiler, Suspense, Children, Component, PureComponent, __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, cloneElement, createContext, createElement, createFactory, createRef, forwardRef, isValidElement, lazy, memo, useCallback, useContext, useDebugValue, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useReducer, useRef, useState, version } = packageExport;
90
- export default packageExport;
91
- export { Fragment, StrictMode, Profiler, Suspense, Children, Component, PureComponent, __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, cloneElement, createContext, createElement, createFactory, createRef, forwardRef, isValidElement, lazy, memo, useCallback, useContext, useDebugValue, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useReducer, useRef, useState, version }"
92
- `);
93
- });
94
- it('can snapshot react-dom', async () => {
95
- expect(await createESMStub(path.join(testScenariosPath, 'react-dom.development.cjs'), stubPath))
96
- .toMatchInlineSnapshot(`
97
- "import * as packageExport from "./react-dom.development.cjs";
98
- const { __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, createPortal, findDOMNode, flushSync, hydrate, render, unmountComponentAtNode, unstable_batchedUpdates, unstable_createPortal, unstable_renderSubtreeIntoContainer, version } = packageExport;
99
- export default packageExport;
100
- export { __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, createPortal, findDOMNode, flushSync, hydrate, render, unmountComponentAtNode, unstable_batchedUpdates, unstable_createPortal, unstable_renderSubtreeIntoContainer, version }"
101
- `);
102
- });
103
- it('can generate a stub for a browser-sensitive CommonJS module', async () => {
104
- expect(await createESMStub(path.join(testScenariosPath, 'browser-sensitive.cjs'), stubPath)).toMatchInlineSnapshot(`
105
- "import * as packageExport from "./browser-sensitive.cjs";
106
- const { getDiv } = packageExport;
107
- export default packageExport;
108
- export { getDiv }"
109
- `);
110
- });
111
- it('can ignore JavaScript keywords in named exports', async () => {
112
- // Should be missing "delete" in the named exports.
113
- expect(await createESMStub(path.join(testScenariosPath, 'export-with-keyword.cjs'), stubPath))
114
- .toMatchInlineSnapshot(`
115
- "import * as packageExport from "./export-with-keyword.cjs";
116
- const { a } = packageExport;
117
- const defaultExport = (packageExport && packageExport.default?.default) ? packageExport?.default.default : packageExport?.default;
118
- export default defaultExport;
119
- export { a }"
120
- `);
121
- });
122
- it('can generate a stub for node-fetch', async () => {
123
- expect(await createESMStub(path.join(testScenariosPath, 'node-fetch.cjs'), stubPath)).toMatchInlineSnapshot(`
124
- "import packageExport from "./node-fetch.cjs";
125
- const { Headers, Request, Response } = packageExport;
126
- const defaultExport = (packageExport && packageExport.default?.default) ? packageExport?.default.default : packageExport?.default;
127
- export default defaultExport;
128
- export { Headers, Request, Response }"
129
- `);
130
- });
131
- it('can generate a stub for diff-sequences', async () => {
132
- expect(await createESMStub(path.join(testScenariosPath, 'diff-sequences.cjs'), stubPath)).toMatchInlineSnapshot(`
133
- "import * as packageExport from "./diff-sequences.cjs";
134
- const defaultExport = (packageExport && packageExport.default?.default) ? packageExport?.default.default : packageExport?.default;
135
- export default defaultExport;"
136
- `);
137
- });
138
- it('can generate a stub for isomorphic-ws', async () => {
139
- expect(await createESMStub(path.join(testScenariosPath, 'isomorphic-ws.cjs'), stubPath)).toMatchInlineSnapshot(`"export { default } from "./isomorphic-ws.cjs";"`);
140
- });
141
- it('can generate a stub from something that returns a boolean', async () => {
142
- expect(await createESMStub(path.join(testScenariosPath, 'boolean-return.cjs'), stubPath)).toMatchInlineSnapshot(`"export default true;"`);
143
- });
144
- });
145
- //# sourceMappingURL=createESMStub.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createESMStub.test.js","sourceRoot":"","sources":["../src/createESMStub.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACrD,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,wDAAwD;AACxD,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,EAAE;IACpC,OAAO,IAAI,CAAC,OAAO,CAAC,2BAA2B,EAAE,iCAAiC,CAAC,CAAC;AACtF,CAAC,CAAC;AAEF,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;QAC1C,MAAM,gBAAgB,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC;QACpE,MAAM,oBAAoB,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,CAA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AAC,CAAC;aAC3F,qBAAqB,CAAC;;;;;;KAMxB,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;;;;;;KAM3G,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wCAAwC,EAAE,KAAK,IAAI,EAAE;QACtD,MAAM,CAAC,MAAM,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,qBAAqB,CAAC;;;;KAI/G,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uCAAuC,EAAE,KAAK,IAAI,EAAE;QACrD,MAAM,CAAC,MAAM,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,mBAAmB,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,qBAAqB,CAC5G,kDAAkD,CACnD,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2DAA2D,EAAE,KAAK,IAAI,EAAE;QACzE,MAAM,CAAC,MAAM,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,qBAAqB,CAC7G,wBAAwB,CACzB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,16 +0,0 @@
1
- import { describe, it, expect } from '@jest/globals';
2
- import path from 'path';
3
- import { fileURLToPath } from 'url';
4
- import { tryRequire } from './tryRequire.cjs';
5
- const dirname = path.dirname(fileURLToPath(import.meta.url));
6
- const testScenariosPath = path.join(dirname, '../test-scenarios');
7
- describe('tryRequire', () => {
8
- it('can successfully require a CommonJS module', () => {
9
- const module = tryRequire(path.join(testScenariosPath, 'object-export.cjs'));
10
- expect(module).toBeTruthy();
11
- });
12
- it('can throw when the module cannot be required', () => {
13
- expect(() => tryRequire('this-module-does-not-exist')).toThrow();
14
- });
15
- });
16
- //# sourceMappingURL=tryRequire.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tryRequire.test.js","sourceRoot":"","sources":["../src/tryRequire.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,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;AAElE,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;QACpD,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,mBAAmB,CAAC,CAAC,CAAC;QAC7E,MAAM,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACtD,MAAM,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,4BAA4B,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IACnE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}