@ms-cloudpack/esm-stub-utilities 0.8.0 → 0.9.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.
Files changed (67) hide show
  1. package/README.md +10 -36
  2. package/lib/generateESMStubFromCJS.d.ts.map +1 -1
  3. package/lib/generateESMStubFromCJS.js +3 -4
  4. package/lib/generateESMStubFromCJS.js.map +1 -1
  5. package/lib/index.d.ts +2 -4
  6. package/lib/index.d.ts.map +1 -1
  7. package/lib/index.js.map +1 -1
  8. package/lib/processError.d.ts +6 -0
  9. package/lib/processError.d.ts.map +1 -0
  10. package/lib/processError.js +75 -0
  11. package/lib/processError.js.map +1 -0
  12. package/lib/processStubsInWorker.d.ts +4 -7
  13. package/lib/processStubsInWorker.d.ts.map +1 -1
  14. package/lib/processStubsInWorker.js +12 -15
  15. package/lib/processStubsInWorker.js.map +1 -1
  16. package/lib/types/ESMStubWorkerMessages.d.ts +9 -0
  17. package/lib/types/ESMStubWorkerMessages.d.ts.map +1 -0
  18. package/lib/types/ESMStubWorkerMessages.js +2 -0
  19. package/lib/types/ESMStubWorkerMessages.js.map +1 -0
  20. package/lib/types/WriteESMStubsOptions.d.ts +7 -0
  21. package/lib/types/WriteESMStubsOptions.d.ts.map +1 -0
  22. package/lib/types/WriteESMStubsOptions.js +2 -0
  23. package/lib/types/WriteESMStubsOptions.js.map +1 -0
  24. package/lib/types/WriteESMStubsResult.d.ts +6 -0
  25. package/lib/types/WriteESMStubsResult.d.ts.map +1 -0
  26. package/lib/types/WriteESMStubsResult.js +2 -0
  27. package/lib/types/WriteESMStubsResult.js.map +1 -0
  28. package/lib/worker/globals.js +1 -1
  29. package/lib/worker/globals.js.map +1 -1
  30. package/lib/worker/initBrowserEnvironment.d.ts.map +1 -1
  31. package/lib/worker/initBrowserEnvironment.js +20 -20
  32. package/lib/worker/initBrowserEnvironment.js.map +1 -1
  33. package/lib/worker/workerEntry.js +10 -9
  34. package/lib/worker/workerEntry.js.map +1 -1
  35. package/lib/writeESMStubs.d.ts +6 -7
  36. package/lib/writeESMStubs.d.ts.map +1 -1
  37. package/lib/writeESMStubs.js +3 -2
  38. package/lib/writeESMStubs.js.map +1 -1
  39. package/lib/writeESMStubsInternal.d.ts +3 -3
  40. package/lib/writeESMStubsInternal.d.ts.map +1 -1
  41. package/lib/writeESMStubsInternal.js +30 -28
  42. package/lib/writeESMStubsInternal.js.map +1 -1
  43. package/package.json +3 -8
  44. package/lib/types/ESMStub.d.ts +0 -7
  45. package/lib/types/ESMStub.d.ts.map +0 -1
  46. package/lib/types/ESMStub.js +0 -2
  47. package/lib/types/ESMStub.js.map +0 -1
  48. package/lib/types/ProcessStubsFunction.d.ts +0 -4
  49. package/lib/types/ProcessStubsFunction.d.ts.map +0 -1
  50. package/lib/types/ProcessStubsFunction.js +0 -2
  51. package/lib/types/ProcessStubsFunction.js.map +0 -1
  52. package/lib/types/SandboxWorkerResponse.d.ts +0 -21
  53. package/lib/types/SandboxWorkerResponse.d.ts.map +0 -1
  54. package/lib/types/SandboxWorkerResponse.js +0 -2
  55. package/lib/types/SandboxWorkerResponse.js.map +0 -1
  56. package/lib/types/StubError.d.ts +0 -31
  57. package/lib/types/StubError.d.ts.map +0 -1
  58. package/lib/types/StubError.js +0 -2
  59. package/lib/types/StubError.js.map +0 -1
  60. package/lib/types/WriteESMStubsInput.d.ts +0 -7
  61. package/lib/types/WriteESMStubsInput.d.ts.map +0 -1
  62. package/lib/types/WriteESMStubsInput.js +0 -2
  63. package/lib/types/WriteESMStubsInput.js.map +0 -1
  64. package/lib/types/WriteESMStubsOutput.d.ts +0 -6
  65. package/lib/types/WriteESMStubsOutput.d.ts.map +0 -1
  66. package/lib/types/WriteESMStubsOutput.js +0 -2
  67. package/lib/types/WriteESMStubsOutput.js.map +0 -1
package/README.md CHANGED
@@ -4,44 +4,18 @@ This library contains utilities for generating ESM stubs for CommonJS modules. S
4
4
 
5
5
  ## Usage
6
6
 
7
- Call `createESMStub` to generate a stub for the cjs entry:
7
+ Call `writeESMStubs` to generate stubs for CJS entries of a package:
8
8
 
9
9
  ```js
10
- import { createESMStub } from '@ms-cloudpack/esm-stub-utilities';
11
-
12
- const esmStub = await createESMStub('/path/to/cjs/entry.js', '/path/to/esm/stub.js');
13
- ```
14
-
15
- This call returns an esm stub string, but does not write the file. The path in the second argument is needed to derive import paths.
16
-
17
- Example cjs file `entry.js`:
18
-
19
- ```js
20
- module.exports = {
21
- named1: 'named1',
22
- named2: 'named2',
23
- };
24
- ```
25
-
26
- Example output (`stub.js`):
27
-
28
- ```js
29
- import content from '../cjs/entry.js';
30
-
31
- export {
32
- default: content,
33
- named1: content.named1,
34
- named2: content.named2
35
- };
36
- ```
37
-
38
- To write the file in the same call, the `writeESMStub` helper does this (which writes the stub to the node_modules/.cache folder in
39
- the package):
40
-
41
- ```js
42
- import { writeESMStub } from '@ms-cloudpack/esm-stub-utilities';
43
-
44
- const stubPath = await writeESMStub('./path/to/entry.js');
10
+ import { writeESMStubs } from '@ms-cloudpack/esm-stub-utilities';
11
+
12
+ const esmStub = await writeESMStubs({
13
+ inputPath: '/path/to/package',
14
+ entries: {
15
+ './entry1': './cjsEntry1.js',
16
+ './entry2': './cjsEntry2.js',
17
+ },
18
+ });
45
19
  ```
46
20
 
47
21
  ## Special considerations
@@ -1 +1 @@
1
- {"version":3,"file":"generateESMStubFromCJS.d.ts","sourceRoot":"","sources":["../src/generateESMStubFromCJS.ts"],"names":[],"mappings":"AASA;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAqD9F"}
1
+ {"version":3,"file":"generateESMStubFromCJS.d.ts","sourceRoot":"","sources":["../src/generateESMStubFromCJS.ts"],"names":[],"mappings":"AASA;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAoD9F"}
@@ -1,9 +1,9 @@
1
- import path from 'path';
2
- import os from 'os';
3
1
  import { slash } from '@ms-cloudpack/path-string-parsing';
4
- import { isValidIdentifierName } from './isValidIdentifierName.js';
5
2
  import { createRequire } from 'module';
3
+ import os from 'os';
4
+ import path from 'path';
6
5
  import { getExportInfo } from './getExportInfo.js';
6
+ import { isValidIdentifierName } from './isValidIdentifierName.js';
7
7
  const require = createRequire(import.meta.url);
8
8
  /**
9
9
  * Given entry/stub paths and cjs export info, generates the esm stub content.
@@ -11,7 +11,6 @@ const require = createRequire(import.meta.url);
11
11
  */
12
12
  export function generateESMStubFromCJS(options) {
13
13
  const { filePath, stubPath } = options;
14
- // Assume CJS.
15
14
  const exportInfo = getExportInfo(require(filePath));
16
15
  const { type: exportType } = exportInfo;
17
16
  let relativePath;
@@ -1 +1 @@
1
- {"version":3,"file":"generateESMStubFromCJS.js","sourceRoot":"","sources":["../src/generateESMStubFromCJS.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAA+C;IACpF,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAEvC,cAAc;IACd,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,CAAC,QAAQ,CAAY,CAAC,CAAC;IAE/D,MAAM,EAAE,IAAI,E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AClF,+BAA+B,CAChC,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI,YAAY,CAAC,MAAM,EAAE,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC,YAAY,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC","sourcesContent":["import path from 'path';\nimport os from 'os';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { isValidIdentifierName } from './isValidIdentifierName.js';\nimport { createRequire } from 'module';\nimport { getExportInfo } from './getExportInfo.js';\n\nconst require = createRequire(import.meta.url);\n\n/**\n * Given entry/stub paths and cjs export info, generates the esm stub content.\n * The stubPath is required to generate the proper import statement.\n */\nexport function generateESMStubFromCJS(options: { filePath: string; stubPath: string }): string {\n const { filePath, stubPath } = options;\n\n // Assume CJS.\n const exportInfo = getExportInfo(require(filePath) as unknown);\n\n const { type: exportType } = exportInfo;\n let relativePath: string;\n\n // We need to compute a relative path from the stub to the entry to construct the proper import in the stub.\n if (os.platform() === 'win32' && path.parse(filePath).root !== path.parse(stubPath).root) {\n // Different drive letters. These can't be relative to each other.\n relativePath = filePath;\n } else {\n relativePath = './' + slash(path.relative(path.dirname(stubPath), filePath));\n }\n\n if (exportType === 'none') {\n // No exports. Just import the module.\n return `import \"${relativePath}\";`;\n }\n\n if (exportType === 'other') {\n // Some kind of value. Import then re-export as default.\n // (Note that even for values such as numbers which we could in theory rewrite inline,\n // we don't know how the value is calculated at runtime or what other side effects the module\n // might have, so we should preserve the import.)\n return `import moduleExport from \"${relativePath}\";\\nexport default moduleExport;`;\n }\n\n // Object or function. Export both named properties (if any, and filtering keywords) and a default.\n const namedExports = exportInfo.keys.filter((name) => isValidIdentifierName(name));\n const hasDefaultExport = exportInfo.keys.includes('default');\n const stub = [`import moduleExport from \"${relativePath}\";`];\n\n if (namedExports.length) {\n stub.push(`const { ${namedExports.join(', ')} } = moduleExport;`);\n }\n\n if (hasDefaultExport) {\n stub.push(\n `const defaultExport = (moduleExport?.default?.default) ?? moduleExport?.default;`,\n `export default defaultExport;`,\n );\n } else {\n stub.push(`export default moduleExport;`);\n }\n\n if (namedExports.length) {\n stub.push(`export { ${namedExports.join(', ')} }`);\n }\n\n return stub.join('\\n');\n}\n"]}
1
+ {"version":3,"file":"generateESMStubFromCJS.js","sourceRoot":"","sources":["../src/generateESMStubFromCJS.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAA+C;IACpF,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAEvC,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,CAAC,QAAQ,CAAY,CAAC,CAAC;IAE/D,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,UAAU,CAAC;IACxC,IAAI,YAAoB,CAAC;IAEzB,4GAA4G;IAC5G,IAAI,EAAE,CAAC,QAAQ,EAAE,KAAK,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;QACzF,kEAAkE;QAClE,YAAY,GAAG,QAAQ,CA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AAI,CAAC,CAAC;AACzB,CAAC","sourcesContent":["import { slash } from '@ms-cloudpack/path-string-parsing';\nimport { createRequire } from 'module';\nimport os from 'os';\nimport path from 'path';\nimport { getExportInfo } from './getExportInfo.js';\nimport { isValidIdentifierName } from './isValidIdentifierName.js';\n\nconst require = createRequire(import.meta.url);\n\n/**\n * Given entry/stub paths and cjs export info, generates the esm stub content.\n * The stubPath is required to generate the proper import statement.\n */\nexport function generateESMStubFromCJS(options: { filePath: string; stubPath: string }): string {\n const { filePath, stubPath } = options;\n\n const exportInfo = getExportInfo(require(filePath) as unknown);\n\n const { type: exportType } = exportInfo;\n let relativePath: string;\n\n // We need to compute a relative path from the stub to the entry to construct the proper import in the stub.\n if (os.platform() === 'win32' && path.parse(filePath).root !== path.parse(stubPath).root) {\n // Different drive letters. These can't be relative to each other.\n relativePath = filePath;\n } else {\n relativePath = './' + slash(path.relative(path.dirname(stubPath), filePath));\n }\n\n if (exportType === 'none') {\n // No exports. Just import the module.\n return `import \"${relativePath}\";`;\n }\n\n if (exportType === 'other') {\n // Some kind of value. Import then re-export as default.\n // (Note that even for values such as numbers which we could in theory rewrite inline,\n // we don't know how the value is calculated at runtime or what other side effects the module\n // might have, so we should preserve the import.)\n return `import moduleExport from \"${relativePath}\";\\nexport default moduleExport;`;\n }\n\n // Object or function. Export both named properties (if any, and filtering keywords) and a default.\n const namedExports = exportInfo.keys.filter((name) => isValidIdentifierName(name));\n const hasDefaultExport = exportInfo.keys.includes('default');\n const stub = [`import moduleExport from \"${relativePath}\";`];\n\n if (namedExports.length) {\n stub.push(`const { ${namedExports.join(', ')} } = moduleExport;`);\n }\n\n if (hasDefaultExport) {\n stub.push(\n `const defaultExport = (moduleExport?.default?.default) ?? moduleExport?.default;`,\n `export default defaultExport;`,\n );\n } else {\n stub.push(`export default moduleExport;`);\n }\n\n if (namedExports.length) {\n stub.push(`export { ${namedExports.join(', ')} }`);\n }\n\n return stub.join('\\n');\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  export { writeESMStubs } from './writeESMStubs.js';
2
- export type { ESMStub } from './types/ESMStub.js';
3
- export type { StubError } from './types/StubError.js';
4
- export type { WriteESMStubsInput } from './types/WriteESMStubsInput.js';
5
- export type { WriteESMStubsOutput } from './types/WriteESMStubsOutput.js';
2
+ export type { WriteESMStubsOptions } from './types/WriteESMStubsOptions.js';
3
+ export type { WriteESMStubsResult } from './types/WriteESMStubsResult.js';
6
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACxE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,YAAY,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC"}
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { writeESMStubs } from './writeESMStubs.js';\nexport type { ESMStub } from './types/ESMStub.js';\nexport type { StubError } from './types/StubError.js';\nexport type { WriteESMStubsInput } from './types/WriteESMStubsInput.js';\nexport type { WriteESMStubsOutput } from './types/WriteESMStubsOutput.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { writeESMStubs } from './writeESMStubs.js';\nexport type { WriteESMStubsOptions } from './types/WriteESMStubsOptions.js';\nexport type { WriteESMStubsResult } from './types/WriteESMStubsResult.js';\n"]}
@@ -0,0 +1,6 @@
1
+ import type { BundleMessage } from '@ms-cloudpack/bundler-types';
2
+ /**
3
+ * Get info from an error which may be useful for debugging.
4
+ */
5
+ export declare function processError(entryKey: string, entryFullPath: string, errorParam: unknown): BundleMessage;
6
+ //# sourceMappingURL=processError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processError.d.ts","sourceRoot":"","sources":["../src/processError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AASjE;;GAEG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,GAAG,aAAa,CA4ExG"}
@@ -0,0 +1,75 @@
1
+ import { slash } from '@ms-cloudpack/path-string-parsing';
2
+ /** Some known error codes that can occur when running a file in a sandbox. */
3
+ const errorCodes = {
4
+ requireESM: 'ERR_REQUIRE_ESM',
5
+ moduleNotFound: 'MODULE_NOT_FOUND',
6
+ };
7
+ /**
8
+ * Get info from an error which may be useful for debugging.
9
+ */
10
+ export function processError(entryKey, entryFullPath, errorParam) {
11
+ const error = errorParam.message ? errorParam : { message: String(errorParam) };
12
+ const { message: originalMessage, code, stack: originalStack, requireStack, } = error;
13
+ let message = originalMessage;
14
+ if (code === errorCodes.requireESM) {
15
+ // Remove the instruction to change to a dynamic import, since it's less likely to be applicable here.
16
+ // Error [ERR_REQUIRE_ESM]: require() of ES Module [...]/esm.mjs not supported.
17
+ // Instead change the require of [...]/esm.mjs to a dynamic import() which is available in all CommonJS modules.
18
+ message = message.split('\n')[0];
19
+ }
20
+ else if (code === errorCodes.moduleNotFound && requireStack) {
21
+ // Module not found errors have a require stack included in the error message, as well as a
22
+ // requireStack property. Remove the stack from the message and rebuild it with filtering.
23
+ // Error: Cannot find module 'foo'
24
+ // Require stack:
25
+ // - [...]/index.js
26
+ // - [...]/generateESMStubFromCJS.js
27
+ message = message.split('\n')[0];
28
+ // remove the generateESMStubFromCJS require line (not interesting)
29
+ const filteredStack = requireStack.filter((line) => !line.includes('generateESMStubFromCJS'));
30
+ if (filteredStack.length > 1) {
31
+ // Only include the stack if it goes beyond the original file
32
+ message += `. Require stack:\n${filteredStack.map((line) => ` ${line}`).join('\n')}`;
33
+ }
34
+ }
35
+ let stack;
36
+ if (originalStack) {
37
+ // Get stack frame lines from the original error stack
38
+ stack = originalStack.split('\n').filter((line) => /^\s+at /.test(line));
39
+ // The user probably only cares about the error location in the original code,
40
+ // so make it easier to see that.
41
+ let utilsIndex = stack.findIndex((line) => line.includes('workerEntry.js'));
42
+ if (utilsIndex !== -1) {
43
+ stack = stack.slice(utilsIndex + 1);
44
+ }
45
+ else {
46
+ // Remove the generateESMStubFromCJS frame and anything after it
47
+ utilsIndex = stack.findIndex((line) => /generateESMStubFromCJS\.[jt]s\b/.test(line));
48
+ if (utilsIndex !== -1) {
49
+ stack = stack.slice(0, utilsIndex);
50
+ }
51
+ }
52
+ if (!stack.length) {
53
+ stack = undefined;
54
+ if (code === errorCodes.requireESM) {
55
+ // If we ended up with no stack besides the worker, this strongly implies that the file
56
+ // itself is an ESM file, not a CommonJS file. We tried to check for this with detectModuleType,
57
+ // but maybe it can fail sometimes.
58
+ message =
59
+ "It appears you're trying to create a stub of an ES module, which is not supported. " +
60
+ 'You may need to add a cloudpack override to bundle this package with ori.';
61
+ }
62
+ }
63
+ }
64
+ // Remove node internals from the stack, and jest stuff for errors while running tests
65
+ const partialStack = stack?.filter((line) => !line.includes('(node:') && !line.includes('jest-runtime') && !line.includes('jest-resolve'));
66
+ if (partialStack && partialStack.length > 1 && code !== errorCodes.moduleNotFound) {
67
+ // Add the stack to the message
68
+ message += `\n\nPartial error stack (node internals omitted):\n${partialStack.join('\n')}`;
69
+ }
70
+ return {
71
+ text: `Error creating stub for entry "./${entryKey}": ${message}`,
72
+ location: { file: slash(entryFullPath), line: 1, column: 0 },
73
+ };
74
+ }
75
+ //# sourceMappingURL=processError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processError.js","sourceRoot":"","sources":["../src/processError.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAE1D,8EAA8E;AAC9E,MAAM,UAAU,GAAG;IACjB,UAAU,EAAE,iBAAiB;IAC7B,cAAc,EAAE,kBAAkB;CACnC,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,QAAgB,EAAE,aAAqB,EAAE,UAAmB;IACvF,MAAM,KAAK,GAAI,UAAoB,CAAC,OAAO,CAAC,CAAC,CAAE,UAAoB,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;IAEtG,MAAM,EACJ,OAAO,EAAE,eAAe,EACxB,IAAI,EACJ,KAAK,EAAE,aAAa,EACpB,YAAY,GACb,GAAG,KAA2D,CAAC;IAEhE,IAAI,OAAO,GAAG,eAAe,CAAC;IAC9B,IAAI,IAAI,KAAK,UAAU,CAAC,UAAU,EAAE,CAAC;QACnC,sGAAsG;QACtG,iFAAiF;QACjF,kHAAkH;QAClH,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;SAAM,IAAI,IAAI,KAAK,UAAU,CAAC,cAAc,IAAI,YAAY,EAAE,CAAC;QAC9D,2FAA2F;QAC3F,0FAA0F;QAC1F,oCAAoC;QACpC,mBAAmB;QACnB,qBAAqB;QACrB,sCAAsC;QACtC,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACjC,m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CAAC;YAClB,KAAK,GAAG,SAAS,CAAC;YAClB,IAAI,IAAI,KAAK,UAAU,CAAC,UAAU,EAAE,CAAC;gBACnC,uFAAuF;gBACvF,gGAAgG;gBAChG,mCAAmC;gBACnC,OAAO;oBACL,qFAAqF;wBACrF,2EAA2E,CAAC;YAChF,CAAC;QACH,CAAC;IACH,CAAC;IAED,sFAAsF;IACtF,MAAM,YAAY,GAAG,KAAK,EAAE,MAAM,CAChC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,CACvG,CAAC;IACF,IAAI,YAAY,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,KAAK,UAAU,CAAC,cAAc,EAAE,CAAC;QAClF,+BAA+B;QAC/B,OAAO,IAAI,sDAAsD,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAC7F,CAAC;IAED,OAAO;QACL,IAAI,EAAE,oCAAoC,QAAQ,MAAM,OAAO,EAAE;QACjE,QAAQ,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;KAC7D,CAAC;AACJ,CAAC","sourcesContent":["import type { BundleMessage } from '@ms-cloudpack/bundler-types';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\n\n/** Some known error codes that can occur when running a file in a sandbox. */\nconst errorCodes = {\n requireESM: 'ERR_REQUIRE_ESM',\n moduleNotFound: 'MODULE_NOT_FOUND',\n};\n\n/**\n * Get info from an error which may be useful for debugging.\n */\nexport function processError(entryKey: string, entryFullPath: string, errorParam: unknown): BundleMessage {\n const error = (errorParam as Error).message ? (errorParam as Error) : { message: String(errorParam) };\n\n const {\n message: originalMessage,\n code,\n stack: originalStack,\n requireStack,\n } = error as Error & { code?: string; requireStack?: string[] };\n\n let message = originalMessage;\n if (code === errorCodes.requireESM) {\n // Remove the instruction to change to a dynamic import, since it's less likely to be applicable here.\n // Error [ERR_REQUIRE_ESM]: require() of ES Module [...]/esm.mjs not supported.\n // Instead change the require of [...]/esm.mjs to a dynamic import() which is available in all CommonJS modules.\n message = message.split('\\n')[0];\n } else if (code === errorCodes.moduleNotFound && requireStack) {\n // Module not found errors have a require stack included in the error message, as well as a\n // requireStack property. Remove the stack from the message and rebuild it with filtering.\n // Error: Cannot find module 'foo'\n // Require stack:\n // - [...]/index.js\n // - [...]/generateESMStubFromCJS.js\n message = message.split('\\n')[0];\n // remove the generateESMStubFromCJS require line (not interesting)\n const filteredStack = requireStack.filter((line) => !line.includes('generateESMStubFromCJS'));\n if (filteredStack.length > 1) {\n // Only include the stack if it goes beyond the original file\n message += `. Require stack:\\n${filteredStack.map((line) => ` ${line}`).join('\\n')}`;\n }\n }\n\n let stack: string[] | undefined;\n if (originalStack) {\n // Get stack frame lines from the original error stack\n stack = originalStack.split('\\n').filter((line) => /^\\s+at /.test(line));\n\n // The user probably only cares about the error location in the original code,\n // so make it easier to see that.\n let utilsIndex = stack.findIndex((line) => line.includes('workerEntry.js'));\n if (utilsIndex !== -1) {\n stack = stack.slice(utilsIndex + 1);\n } else {\n // Remove the generateESMStubFromCJS frame and anything after it\n utilsIndex = stack.findIndex((line) => /generateESMStubFromCJS\\.[jt]s\\b/.test(line));\n if (utilsIndex !== -1) {\n stack = stack.slice(0, utilsIndex);\n }\n }\n\n if (!stack.length) {\n stack = undefined;\n if (code === errorCodes.requireESM) {\n // If we ended up with no stack besides the worker, this strongly implies that the file\n // itself is an ESM file, not a CommonJS file. We tried to check for this with detectModuleType,\n // but maybe it can fail sometimes.\n message =\n \"It appears you're trying to create a stub of an ES module, which is not supported. \" +\n 'You may need to add a cloudpack override to bundle this package with ori.';\n }\n }\n }\n\n // Remove node internals from the stack, and jest stuff for errors while running tests\n const partialStack = stack?.filter(\n (line) => !line.includes('(node:') && !line.includes('jest-runtime') && !line.includes('jest-resolve'),\n );\n if (partialStack && partialStack.length > 1 && code !== errorCodes.moduleNotFound) {\n // Add the stack to the message\n message += `\\n\\nPartial error stack (node internals omitted):\\n${partialStack.join('\\n')}`;\n }\n\n return {\n text: `Error creating stub for entry \"./${entryKey}\": ${message}`,\n location: { file: slash(entryFullPath), line: 1, column: 0 },\n };\n}\n"]}
@@ -1,12 +1,9 @@
1
- import type { ProcessStubsFunction } from './types/ProcessStubsFunction.js';
1
+ import type { WriteESMStubsOptions } from './types/WriteESMStubsOptions.js';
2
+ import type { WriteESMStubsResult } from './types/WriteESMStubsResult.js';
2
3
  /**
3
- * Initializes a worker, where Run a CommonJS file within a sandboxed environment.
4
- * @param entryPath - Path to a CommonJS file to run in a sandbox (does not work with ESM files)
5
- * @returns Info about the file's exports, or error info if there was an issue.
6
- * Should only throw an error on bad input or other cases that likely indicate either a bug
7
- * or bad configuration (as opposed to a problem with the file being stubbed).
4
+ * Generates ESM stubs for CommonJS and JSON modules.
8
5
  */
9
- export declare const processStubsInWorker: ProcessStubsFunction;
6
+ export declare function processStubsInWorker(options: WriteESMStubsOptions): Promise<WriteESMStubsResult>;
10
7
  /** Stop the worker for testing */
11
8
  export declare function _stopWorker(): Promise<void>;
12
9
  //# sourceMappingURL=processStubsInWorker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"processStubsInWorker.d.ts","sourceRoot":"","sources":["../src/processStubsInWorker.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAU5E;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,EAAE,oBAyFlC,CAAC;AAEF,kCAAkC;AAClC,wBAAsB,WAAW,kBAGhC"}
1
+ {"version":3,"file":"processStubsInWorker.d.ts","sourceRoot":"","sources":["../src/processStubsInWorker.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAU1E;;GAEG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CA8FtG;AAED,kCAAkC;AAClC,wBAAsB,WAAW,kBAGhC"}
@@ -7,13 +7,9 @@ let _counter = 0;
7
7
  // TODO do we need a pool?
8
8
  let worker;
9
9
  /**
10
- * Initializes a worker, where Run a CommonJS file within a sandboxed environment.
11
- * @param entryPath - Path to a CommonJS file to run in a sandbox (does not work with ESM files)
12
- * @returns Info about the file's exports, or error info if there was an issue.
13
- * Should only throw an error on bad input or other cases that likely indicate either a bug
14
- * or bad configuration (as opposed to a problem with the file being stubbed).
10
+ * Generates ESM stubs for CommonJS and JSON modules.
15
11
  */
16
- export const processStubsInWorker = async (options) => {
12
+ export async function processStubsInWorker(options) {
17
13
  const id = _counter++;
18
14
  // Initialize worker.
19
15
  if (!worker) {
@@ -43,30 +39,31 @@ export const processStubsInWorker = async (options) => {
43
39
  worker.on('messageerror', onMessageError);
44
40
  worker.on('error', onError);
45
41
  worker.on('exit', onExit);
46
- // Send a message requesting the file to be run.
47
- worker.postMessage({ id, ...options });
42
+ // Send a message requesting the stubs to be created.
43
+ const request = { id, ...options };
44
+ worker.postMessage(request);
48
45
  /** Normally, both success and error results should be sent back as messages. */
49
46
  function onMessage(message) {
50
47
  if (message.id !== id) {
51
- return; // result about a different file
48
+ return; // result about a different request
52
49
  }
53
50
  handlersOff();
54
- if (message) {
51
+ if (message.newEntries) {
55
52
  resolve(message);
56
53
  }
57
54
  else {
58
- reject(new Error(`Unexpected sandbox worker message while running ${JSON.stringify(options, null, 2)}`));
55
+ reject(new Error(`Unexpected sandbox worker message while creating stubs for ${options.inputPath}: ${JSON.stringify(message, null, 2)}`));
59
56
  }
60
57
  }
61
58
  /** 'messageerror' event: deserializing a message failed. */
62
59
  function onMessageError(err) {
63
60
  handlersOff();
64
- reject(new Error(`Error with sandbox worker message serialization while running ${JSON.stringify(options, null, 2)}: ${err.stack || err}\n`));
61
+ reject(new Error(`Error with sandbox worker message serialization while creating stubs for ${options.inputPath}:\n${err.stack || err}\n`));
65
62
  }
66
63
  /** 'error' event: unhandled exception in the worker, which shouldn't happen. */
67
64
  function onError(err) {
68
65
  handlersOff();
69
- reject(new Error(`Uncaught error in sandbox worker while running ${JSON.stringify(options, null, 2)}: ${err.stack || err}\n`));
66
+ reject(new Error(`Uncaught error in sandbox worker while running creating stubs for ${options.inputPath}:\n${err.stack || err}\n`));
70
67
  }
71
68
  /**
72
69
  * Make sure the promise rejects if the worker exits unexpectedly. (This handler is unlikely
@@ -74,7 +71,7 @@ export const processStubsInWorker = async (options) => {
74
71
  */
75
72
  function onExit() {
76
73
  worker = undefined;
77
- reject(new Error(`Sandbox worker exited unexpectedly while running ${JSON.stringify(options, null, 2)}`));
74
+ reject(new Error(`Sandbox worker exited unexpectedly while running creating stubs for ${options.inputPath}`));
78
75
  }
79
76
  /** Remove all event handlers to avoid interference with future sandbox runs. */
80
77
  function handlersOff() {
@@ -84,7 +81,7 @@ export const processStubsInWorker = async (options) => {
84
81
  worker?.off('exit', onExit);
85
82
  }
86
83
  });
87
- };
84
+ }
88
85
  /** Stop the worker for testing */
89
86
  export async function _stopWorker() {
90
87
  await worker?.terminate();
@@ -1 +1 @@
1
- {"version":3,"file":"processStubsInWorker.js","sourceRoot":"","sources":["../src/processStubsInWorker.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAIxC,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACjE,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC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AS,MAAM;YACb,MAAM,GAAG,SAAS,CAAC;YACnB,MAAM,CAAC,IAAI,KAAK,CAAC,oDAAoD,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC5G,CAAC;QAED,gFAAgF;QAChF,SAAS,WAAW;YAClB,MAAM,EAAE,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;YAClC,MAAM,EAAE,GAAG,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;YAC5C,MAAM,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC9B,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,kCAAkC;AAClC,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,MAAM,MAAM,EAAE,SAAS,EAAE,CAAC;IAC1B,MAAM,GAAG,SAAS,CAAC;AACrB,CAAC","sourcesContent":["import path from 'path';\nimport { fileURLToPath } from 'url';\nimport { Worker } from 'worker_threads';\nimport type { ProcessStubsFunction } from './types/ProcessStubsFunction.js';\nimport type { WriteESMStubsOutput } from './types/WriteESMStubsOutput.js';\n\nconst currentPath = path.dirname(fileURLToPath(import.meta.url));\nconst workerPath = path.join(currentPath, './worker/workerEntry.js');\nlet _counter = 0;\n\n// TODO do we need a pool?\nlet worker: Worker | undefined;\n\n/**\n * Initializes a worker, where Run a CommonJS file within a sandboxed environment.\n * @param entryPath - Path to a CommonJS file to run in a sandbox (does not work with ESM files)\n * @returns Info about the file's exports, or error info if there was an issue.\n * Should only throw an error on bad input or other cases that likely indicate either a bug\n * or bad configuration (as opposed to a problem with the file being stubbed).\n */\nexport const processStubsInWorker: ProcessStubsFunction = async (options) => {\n const id = _counter++;\n\n // Initialize worker.\n if (!worker) {\n try {\n worker = new Worker(workerPath, { stdout: true, stderr: true, execArgv: [] });\n worker.stdout?.on('data', (data) => {\n console.debug(`[sandbox stdout] ${data}`);\n });\n worker.stderr?.on('data', (data) => {\n console.debug(`[sandbox stderr] ${data}`);\n });\n worker.on('exit', () => {\n worker = undefined;\n });\n // don't hold the process open if only the worker is left\n worker.unref();\n } catch (err) {\n throw new Error(`Error initializing worker: ${(err as Error)?.stack || err}`);\n }\n }\n\n return new Promise((resolve, reject) => {\n // just for type checking\n if (!worker) return;\n\n worker.on('message', onMessage);\n worker.on('messageerror', onMessageError);\n worker.on('error', onError);\n worker.on('exit', onExit);\n\n // Send a message requesting the file to be run.\n worker.postMessage({ id, ...options });\n\n /** Normally, both success and error results should be sent back as messages. */\n function onMessage(message: WriteESMStubsOutput & { id: number }) {\n if (message.id !== id) {\n return; // result about a different file\n }\n\n handlersOff();\n\n if (message) {\n resolve(message);\n } else {\n reject(new Error(`Unexpected sandbox worker message while running ${JSON.stringify(options, null, 2)}`));\n }\n }\n\n /** 'messageerror' event: deserializing a message failed. */\n function onMessageError(err: Error) {\n handlersOff();\n reject(\n new Error(\n `Error with sandbox worker message serialization while running ${JSON.stringify(options, null, 2)}: ${\n err.stack || err\n }\\n`,\n ),\n );\n }\n\n /** 'error' event: unhandled exception in the worker, which shouldn't happen. */\n function onError(err: Error) {\n handlersOff();\n reject(\n new Error(\n `Uncaught error in sandbox worker while running ${JSON.stringify(options, null, 2)}: ${err.stack || err}\\n`,\n ),\n );\n }\n\n /**\n * Make sure the promise rejects if the worker exits unexpectedly. (This handler is unlikely\n * to be used because the worker should throw an error if a file calls process.exit().)\n */\n function onExit() {\n worker = undefined;\n reject(new Error(`Sandbox worker exited unexpectedly while running ${JSON.stringify(options, null, 2)}`));\n }\n\n /** Remove all event handlers to avoid interference with future sandbox runs. */\n function handlersOff() {\n worker?.off('message', onMessage);\n worker?.off('messageerror', onMessageError);\n worker?.off('error', onError);\n worker?.off('exit', onExit);\n }\n });\n};\n\n/** Stop the worker for testing */\nexport async function _stopWorker() {\n await worker?.terminate();\n worker = undefined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AM,CACJ,IAAI,KAAK,CACP,4EAA4E,OAAO,CAAC,SAAS,MAC3F,GAAG,CAAC,KAAK,IAAI,GACf,IAAI,CACL,CACF,CAAC;QACJ,CAAC;QAED,gFAAgF;QAChF,SAAS,OAAO,CAAC,GAAU;YACzB,WAAW,EAAE,CAAC;YACd,MAAM,CACJ,IAAI,KAAK,CACP,qEAAqE,OAAO,CAAC,SAAS,MAAM,GAAG,CAAC,KAAK,IAAI,GAAG,IAAI,CACjH,CACF,CAAC;QACJ,CAAC;QAED;;;WAGG;QACH,SAAS,MAAM;YACb,MAAM,GAAG,SAAS,CAAC;YACnB,MAAM,CAAC,IAAI,KAAK,CAAC,uEAAuE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QAChH,CAAC;QAED,gFAAgF;QAChF,SAAS,WAAW;YAClB,MAAM,EAAE,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;YAClC,MAAM,EAAE,GAAG,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;YAC5C,MAAM,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC9B,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,kCAAkC;AAClC,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,MAAM,MAAM,EAAE,SAAS,EAAE,CAAC;IAC1B,MAAM,GAAG,SAAS,CAAC;AACrB,CAAC","sourcesContent":["import path from 'path';\nimport { fileURLToPath } from 'url';\nimport { Worker } from 'worker_threads';\nimport type { WriteESMStubsOptions } from './types/WriteESMStubsOptions.js';\nimport type { WriteESMStubsResult } from './types/WriteESMStubsResult.js';\nimport type { ESMStubWorkerRequest, ESMStubWorkerResponse } from './types/ESMStubWorkerMessages.js';\n\nconst currentPath = path.dirname(fileURLToPath(import.meta.url));\nconst workerPath = path.join(currentPath, './worker/workerEntry.js');\nlet _counter = 0;\n\n// TODO do we need a pool?\nlet worker: Worker | undefined;\n\n/**\n * Generates ESM stubs for CommonJS and JSON modules.\n */\nexport async function processStubsInWorker(options: WriteESMStubsOptions): Promise<WriteESMStubsResult> {\n const id = _counter++;\n\n // Initialize worker.\n if (!worker) {\n try {\n worker = new Worker(workerPath, { stdout: true, stderr: true, execArgv: [] });\n worker.stdout?.on('data', (data) => {\n console.debug(`[sandbox stdout] ${data}`);\n });\n worker.stderr?.on('data', (data) => {\n console.debug(`[sandbox stderr] ${data}`);\n });\n worker.on('exit', () => {\n worker = undefined;\n });\n // don't hold the process open if only the worker is left\n worker.unref();\n } catch (err) {\n throw new Error(`Error initializing worker: ${(err as Error)?.stack || err}`);\n }\n }\n\n return new Promise((resolve, reject) => {\n // just for type checking\n if (!worker) return;\n\n worker.on('message', onMessage);\n worker.on('messageerror', onMessageError);\n worker.on('error', onError);\n worker.on('exit', onExit);\n\n // Send a message requesting the stubs to be created.\n const request: ESMStubWorkerRequest = { id, ...options };\n worker.postMessage(request);\n\n /** Normally, both success and error results should be sent back as messages. */\n function onMessage(message: ESMStubWorkerResponse) {\n if (message.id !== id) {\n return; // result about a different request\n }\n\n handlersOff();\n\n if (message.newEntries) {\n resolve(message);\n } else {\n reject(\n new Error(\n `Unexpected sandbox worker message while creating stubs for ${options.inputPath}: ${JSON.stringify(message, null, 2)}`,\n ),\n );\n }\n }\n\n /** 'messageerror' event: deserializing a message failed. */\n function onMessageError(err: Error) {\n handlersOff();\n reject(\n new Error(\n `Error with sandbox worker message serialization while creating stubs for ${options.inputPath}:\\n${\n err.stack || err\n }\\n`,\n ),\n );\n }\n\n /** 'error' event: unhandled exception in the worker, which shouldn't happen. */\n function onError(err: Error) {\n handlersOff();\n reject(\n new Error(\n `Uncaught error in sandbox worker while running creating stubs for ${options.inputPath}:\\n${err.stack || err}\\n`,\n ),\n );\n }\n\n /**\n * Make sure the promise rejects if the worker exits unexpectedly. (This handler is unlikely\n * to be used because the worker should throw an error if a file calls process.exit().)\n */\n function onExit() {\n worker = undefined;\n reject(new Error(`Sandbox worker exited unexpectedly while running creating stubs for ${options.inputPath}`));\n }\n\n /** Remove all event handlers to avoid interference with future sandbox runs. */\n function handlersOff() {\n worker?.off('message', onMessage);\n worker?.off('messageerror', onMessageError);\n worker?.off('error', onError);\n worker?.off('exit', onExit);\n }\n });\n}\n\n/** Stop the worker for testing */\nexport async function _stopWorker() {\n await worker?.terminate();\n worker = undefined;\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import type { WriteESMStubsOptions } from './WriteESMStubsOptions.js';
2
+ import type { WriteESMStubsResult } from './WriteESMStubsResult.js';
3
+ export type ESMStubWorkerRequest = WriteESMStubsOptions & {
4
+ id: number;
5
+ };
6
+ export type ESMStubWorkerResponse = WriteESMStubsResult & {
7
+ id: number;
8
+ };
9
+ //# sourceMappingURL=ESMStubWorkerMessages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ESMStubWorkerMessages.d.ts","sourceRoot":"","sources":["../../src/types/ESMStubWorkerMessages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,MAAM,MAAM,oBAAoB,GAAG,oBAAoB,GAAG;IACxD,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,mBAAmB,GAAG;IACxD,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ESMStubWorkerMessages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ESMStubWorkerMessages.js","sourceRoot":"","sources":["../../src/types/ESMStubWorkerMessages.ts"],"names":[],"mappings":"","sourcesContent":["import type { WriteESMStubsOptions } from './WriteESMStubsOptions.js';\nimport type { WriteESMStubsResult } from './WriteESMStubsResult.js';\n\nexport type ESMStubWorkerRequest = WriteESMStubsOptions & {\n id: number;\n};\n\nexport type ESMStubWorkerResponse = WriteESMStubsResult & {\n id: number;\n};\n"]}
@@ -0,0 +1,7 @@
1
+ export type WriteESMStubsOptions = {
2
+ /** The absolute path to the package. */
3
+ inputPath: string;
4
+ /** An array of entry source paths. */
5
+ entries: Record<string, string>;
6
+ };
7
+ //# sourceMappingURL=WriteESMStubsOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WriteESMStubsOptions.d.ts","sourceRoot":"","sources":["../../src/types/WriteESMStubsOptions.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG;IACjC,wCAAwC;IACxC,SAAS,EAAE,MAAM,CAAC;IAElB,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=WriteESMStubsOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WriteESMStubsOptions.js","sourceRoot":"","sources":["../../src/types/WriteESMStubsOptions.ts"],"names":[],"mappings":"","sourcesContent":["export type WriteESMStubsOptions = {\n /** The absolute path to the package. */\n inputPath: string;\n\n /** An array of entry source paths. */\n entries: Record<string, string>;\n};\n"]}
@@ -0,0 +1,6 @@
1
+ import type { BundleMessage } from '@ms-cloudpack/bundler-types';
2
+ export type WriteESMStubsResult = {
3
+ errors?: BundleMessage[];
4
+ newEntries: Record<string, string>;
5
+ };
6
+ //# sourceMappingURL=WriteESMStubsResult.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WriteESMStubsResult.d.ts","sourceRoot":"","sources":["../../src/types/WriteESMStubsResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAEjE,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,CAAC,EAAE,aAAa,EAAE,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=WriteESMStubsResult.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WriteESMStubsResult.js","sourceRoot":"","sources":["../../src/types/WriteESMStubsResult.ts"],"names":[],"mappings":"","sourcesContent":["import type { BundleMessage } from '@ms-cloudpack/bundler-types';\n\nexport type WriteESMStubsResult = {\n errors?: BundleMessage[];\n newEntries: Record<string, string>;\n};\n"]}
@@ -1,4 +1,4 @@
1
- // See worker.js for why this is a JS file.
1
+ // This file is JS because it's also used in a test worker (see testWorker/verifyStub.ts).
2
2
  /** Get all property descriptor names from the global object. */
3
3
  export function getGlobalProperties() {
4
4
  return Object.keys(Object.getOwnPropertyDescriptors(global));
@@ -1 +1 @@
1
- {"version":3,"file":"globals.js","sourceRoot":"","sources":["../../src/worker/globals.js"],"names":[],"mappings":"AAAA,2CAA2C;AAE3C,gEAAgE;AAChE,MAAM,UAAU,mBAAmB;IACjC,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,uBAAuB;IACpD,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE;QAC7E,IAAI,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YAC9D,IAAI,CAAC;gBACH,OAAO,EAAC,gBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACxC,CAAC;YAAC,MAAM,CAAC;gBACP,SAAS;YACX,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["// See worker.js for why this is a JS file.\n\n/** Get all property descriptor names from the global object. */\nexport function getGlobalProperties() {\n return Object.keys(Object.getOwnPropertyDescriptors(global));\n}\n\n/**\n * Delete any new properties from the global object.\n * @param {string[]} initialGlobalProperties\n */\nexport function cleanUpGlobals(initialGlobalProperties) {\n Object.entries(Object.getOwnPropertyDescriptors(global)).forEach(([k, desc]) => {\n if (!initialGlobalProperties.includes(k) && desc.configurable) {\n try {\n delete (/** @type {*} */ (global)[k]);\n } catch {\n // ignore\n }\n }\n });\n}\n"]}
1
+ {"version":3,"file":"globals.js","sourceRoot":"","sources":["../../src/worker/globals.js"],"names":[],"mappings":"AAAA,0FAA0F;AAE1F,gEAAgE;AAChE,MAAM,UAAU,mBAAmB;IACjC,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,uBAAuB;IACpD,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE;QAC7E,IAAI,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YAC9D,IAAI,CAAC;gBACH,OAAO,EAAC,gBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACxC,CAAC;YAAC,MAAM,CAAC;gBACP,SAAS;YACX,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["// This file is JS because it's also used in a test worker (see testWorker/verifyStub.ts).\n\n/** Get all property descriptor names from the global object. */\nexport function getGlobalProperties() {\n return Object.keys(Object.getOwnPropertyDescriptors(global));\n}\n\n/**\n * Delete any new properties from the global object.\n * @param {string[]} initialGlobalProperties\n */\nexport function cleanUpGlobals(initialGlobalProperties) {\n Object.entries(Object.getOwnPropertyDescriptors(global)).forEach(([k, desc]) => {\n if (!initialGlobalProperties.includes(k) && desc.configurable) {\n try {\n delete (/** @type {*} */ (global)[k]);\n } catch {\n // ignore\n }\n }\n });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"initBrowserEnvironment.d.ts","sourceRoot":"","sources":["../../src/worker/initBrowserEnvironment.js"],"names":[],"mappings":"AAOA;;GAEG;AACH,wDAoEC"}
1
+ {"version":3,"file":"initBrowserEnvironment.d.ts","sourceRoot":"","sources":["../../src/worker/initBrowserEnvironment.js"],"names":[],"mappings":"AAKA;;GAEG;AACH,wDAsEC"}
@@ -1,6 +1,4 @@
1
- // See worker.js for why this is a JS file.
2
- import btoa from 'btoa';
3
- import atob from 'atob';
1
+ // This file is JS because it's used in a worker (see workerEntry.js).
4
2
  import { performance } from 'perf_hooks';
5
3
  import util from 'util';
6
4
  /**
@@ -8,9 +6,9 @@ import util from 'util';
8
6
  */
9
7
  export async function initBrowserEnvironment() {
10
8
  // These must be set up before JSDOM
11
- !global.performance && (global.performance = /** @type {*} */ (performance));
12
- !global.TextEncoder && (global.TextEncoder = util.TextEncoder);
13
- !global.TextDecoder && (global.TextDecoder = /** @type {*} */ (util.TextDecoder));
9
+ global.performance ??= /** @type {*} */ (performance);
10
+ global.TextEncoder ??= util.TextEncoder;
11
+ global.TextDecoder ??= /** @type {*} */ (util.TextDecoder);
14
12
  (await import('jsdom-global')).default();
15
13
  await import('regenerator-runtime');
16
14
  // Ensure assigning to and reading from `window.foo` globals works as expected by copying all the
@@ -29,8 +27,8 @@ export async function initBrowserEnvironment() {
29
27
  /** @type {*} */ (document).window = global;
30
28
  window.requestAnimationFrame = window.setTimeout;
31
29
  window.cancelAnimationFrame = window.clearTimeout;
32
- global.btoa = btoa;
33
- global.atob = atob;
30
+ global.btoa = (str) => Buffer.from(str, 'binary').toString('base64');
31
+ global.atob = (str) => Buffer.from(str, 'base64').toString('binary');
34
32
  // Simulate WebSocket existence. (Needed for isomorphic-ws)
35
33
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
36
34
  global.WebSocket = window.WebSocket = /** @type {*} */ (class WebSocket {
@@ -42,24 +40,26 @@ export async function initBrowserEnvironment() {
42
40
  this.port2 = ({});
43
41
  }
44
42
  };
43
+ // Prevent adding event listeners.
44
+ global.addEventListener = window.addEventListener = document.addEventListener = () => { };
45
+ global.removeEventListener = window.removeEventListener = document.removeEventListener = () => { };
46
+ // Mock out canvas.
45
47
  // eslint-disable-next-line etc/no-deprecated
46
48
  const createElement = window.document.createElement.bind(window.document);
47
- // Mock out canvas.
49
+ const createElementMock = (/** @type {string} */ tagName, /** @type {ElementCreationOptions} */ options) => {
50
+ if (tagName === 'canvas') {
51
+ return /** @type {*} */ ({
52
+ getContext: () => ({ fillRect: () => { } }),
53
+ measureText: () => ({}),
54
+ });
55
+ }
56
+ return createElement.apply(window.document, [tagName, options]);
57
+ };
48
58
  // eslint-disable-next-line etc/no-deprecated
49
59
  global.document.createElement =
50
60
  /** @type {*} */ (window).createElement =
51
61
  /** @type {*} */ (global).createElement =
52
- (/** @type {string} */ tagName, /** @type {ElementCreationOptions} */ options) => {
53
- if (tagName === 'canvas') {
54
- return /** @type {*} */ ({
55
- getContext: () => ({
56
- fillRect: () => { },
57
- }),
58
- measureText: () => ({}),
59
- });
60
- }
61
- return createElement.apply(window.document, [tagName, options]);
62
- };
62
+ createElementMock;
63
63
  window.fetch = /** @type {*} */ (async () => { });
64
64
  // prevent 'debug' package from accessing process.stderr
65
65
  process.env.DEBUG_COLORS = '0';
@@ -1 +1 @@
1
- {"version":3,"file":"initBrowserEnvironment.js","sourceRoot":"","sources":["../../src/worker/initBrowserEnvironment.js"],"names":[],"mappings":"AAAA,2CAA2C;AAE3C,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACz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,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;gBAClE,CAAC,CAAC;IAEN,MAAM,CAAC,KAAK,GAAG,gBAAgB,CAAC,CAAC,KAAK,IAAI,EAAE,GAAE,CAAC,CAAC,CAAC;IAEjD,wDAAwD;IACxD,OAAO,CAAC,GAAG,CAAC,YAAY,GAAG,GAAG,CAAC;IAE/B,mFAAmF;IACnF,gBAAgB,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC;AAC5C,CAAC","sourcesContent":["// See worker.js for why this is a JS file.\n\nimport btoa from 'btoa';\nimport atob from 'atob';\nimport { performance } from 'perf_hooks';\nimport util from 'util';\n\n/**\n * Initialize a fake browser environment.\n */\nexport async function initBrowserEnvironment() {\n // These must be set up before JSDOM\n !global.performance && (global.performance = /** @type {*} */ (performance));\n !global.TextEncoder && (global.TextEncoder = util.TextEncoder);\n !global.TextDecoder && (global.TextDecoder = /** @type {*} */ (util.TextDecoder));\n\n (await import('jsdom-global')).default();\n\n await import('regenerator-runtime');\n\n // Ensure assigning to and reading from `window.foo` globals works as expected by copying all the\n // properties from the jsdom `window` to node's `global`, then assigning `global` to `window`.\n Object.entries(Object.getOwnPropertyDescriptors(window)).forEach(([k, desc]) => {\n // Skip storage to avoid errors \"localStorage is not available for opaque origins\"\n // (these errors could in theory be resolved by passing a URL to jsdom-global setup, but that\n // triggers some weird issues with whatwg-url using TextDecoder in a way that works in other\n // environments but throws in the sandbox)\n if (!(k in global) && !['localStorage', 'sessionStorage'].includes(k)) {\n Object.defineProperty(global, k, desc);\n }\n });\n /** @type {*} */ (global).window = global;\n /** @type {*} */ (global).self = global;\n /** @type {*} */ (document).window = global;\n\n window.requestAnimationFrame = window.setTimeout;\n window.cancelAnimationFrame = window.clearTimeout;\n global.btoa = btoa;\n global.atob = atob;\n\n // Simulate WebSocket existence. (Needed for isomorphic-ws)\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n global.WebSocket = window.WebSocket = /** @type {*} */ (class WebSocket {});\n\n // Fake MessageChannel so scheduler won't hang the process by opening a channel.\n global.MessageChannel = window.MessageChannel = class MessageChannel {\n port1 = /** @type {*} */ ({});\n port2 = /** @type {*} */ ({});\n };\n\n // eslint-disable-next-line etc/no-deprecated\n const createElement = window.document.createElement.bind(window.document);\n\n // Mock out canvas.\n // eslint-disable-next-line etc/no-deprecated\n global.document.createElement =\n /** @type {*} */ (window).createElement =\n /** @type {*} */ (global).createElement =\n (/** @type {string} */ tagName, /** @type {ElementCreationOptions} */ options) => {\n if (tagName === 'canvas') {\n return /** @type {*} */ ({\n getContext: () => ({\n fillRect: () => {},\n }),\n measureText: () => ({}),\n });\n }\n\n return createElement.apply(window.document, [tagName, options]);\n };\n\n window.fetch = /** @type {*} */ (async () => {});\n\n // prevent 'debug' package from accessing process.stderr\n process.env.DEBUG_COLORS = '0';\n\n // Some packages like readable-stream@2.3.7 read process.browser to avoid node code\n /** @type {*} */ (process).browser = true;\n}\n"]}
1
+ {"version":3,"file":"initBrowserEnvironment.js","sourceRoot":"","sources":["../../src/worker/initBrowserEnvironment.js"],"names":[],"mappings":"AAAA,sEAAsE;AAEtE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB;IAC1C,oCAAoC;IACpC,MAAM,CAAC,WAAW,KAAK,gBAAgB,CAAC,CAAC,WAAW,CAAC,CAAC;IACtD,MAAM,CAAC,WAAW,KAAK,IAAI,CAAC,WAAW,CAAC;IACxC,MAAM,CAAC,WAAW,KAAK,gBAAgB,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAE3D,CAAC,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IAEzC,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAC;IAEpC,iGAAiG;IACjG,8FAA8F;IAC9F,MAAM,CAAC,OAAO,C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AAI,EAAE,GAAE,CAAC,CAAC,CAAC;IAEjD,wDAAwD;IACxD,OAAO,CAAC,GAAG,CAAC,YAAY,GAAG,GAAG,CAAC;IAE/B,mFAAmF;IACnF,gBAAgB,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC;AAC5C,CAAC","sourcesContent":["// This file is JS because it's used in a worker (see workerEntry.js).\n\nimport { performance } from 'perf_hooks';\nimport util from 'util';\n\n/**\n * Initialize a fake browser environment.\n */\nexport async function initBrowserEnvironment() {\n // These must be set up before JSDOM\n global.performance ??= /** @type {*} */ (performance);\n global.TextEncoder ??= util.TextEncoder;\n global.TextDecoder ??= /** @type {*} */ (util.TextDecoder);\n\n (await import('jsdom-global')).default();\n\n await import('regenerator-runtime');\n\n // Ensure assigning to and reading from `window.foo` globals works as expected by copying all the\n // properties from the jsdom `window` to node's `global`, then assigning `global` to `window`.\n Object.entries(Object.getOwnPropertyDescriptors(window)).forEach(([k, desc]) => {\n // Skip storage to avoid errors \"localStorage is not available for opaque origins\"\n // (these errors could in theory be resolved by passing a URL to jsdom-global setup, but that\n // triggers some weird issues with whatwg-url using TextDecoder in a way that works in other\n // environments but throws in the sandbox)\n if (!(k in global) && !['localStorage', 'sessionStorage'].includes(k)) {\n Object.defineProperty(global, k, desc);\n }\n });\n /** @type {*} */ (global).window = global;\n /** @type {*} */ (global).self = global;\n /** @type {*} */ (document).window = global;\n\n window.requestAnimationFrame = window.setTimeout;\n window.cancelAnimationFrame = window.clearTimeout;\n global.btoa = (str) => Buffer.from(str, 'binary').toString('base64');\n global.atob = (str) => Buffer.from(str, 'base64').toString('binary');\n\n // Simulate WebSocket existence. (Needed for isomorphic-ws)\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n global.WebSocket = window.WebSocket = /** @type {*} */ (class WebSocket {});\n\n // Fake MessageChannel so scheduler won't hang the process by opening a channel.\n global.MessageChannel = window.MessageChannel = class MessageChannel {\n port1 = /** @type {*} */ ({});\n port2 = /** @type {*} */ ({});\n };\n\n // Prevent adding event listeners.\n global.addEventListener = window.addEventListener = document.addEventListener = () => {};\n global.removeEventListener = window.removeEventListener = document.removeEventListener = () => {};\n\n // Mock out canvas.\n // eslint-disable-next-line etc/no-deprecated\n const createElement = window.document.createElement.bind(window.document);\n const createElementMock = (/** @type {string} */ tagName, /** @type {ElementCreationOptions} */ options) => {\n if (tagName === 'canvas') {\n return /** @type {*} */ ({\n getContext: () => ({ fillRect: () => {} }),\n measureText: () => ({}),\n });\n }\n\n return createElement.apply(window.document, [tagName, options]);\n };\n // eslint-disable-next-line etc/no-deprecated\n global.document.createElement =\n /** @type {*} */ (window).createElement =\n /** @type {*} */ (global).createElement =\n createElementMock;\n\n window.fetch = /** @type {*} */ (async () => {});\n\n // prevent 'debug' package from accessing process.stderr\n process.env.DEBUG_COLORS = '0';\n\n // Some packages like readable-stream@2.3.7 read process.browser to avoid node code\n /** @type {*} */ (process).browser = true;\n}\n"]}
@@ -1,4 +1,4 @@
1
- // These files use JS because they're loaded directly into a worker (see runInSandbox.ts),
1
+ // These files use JS because they're loaded directly into a worker (see processStubsInWorker.ts),
2
2
  // which must work both during tests (where the files are loaded from "src") and at runtime.
3
3
  // They can still be type checked like TS, and the transpilation step doesn't do anything that
4
4
  // should change the desired runtime behavior.
@@ -13,29 +13,30 @@ await initBrowserEnvironment();
13
13
  // TODO should the globals be marked as readonly if possible?
14
14
  const initialGlobalProperties = getGlobalProperties();
15
15
  /**
16
- * @param {import('../types/WriteESMStubsOutput.js').WriteESMStubsOutput & { id: number }} message
16
+ * @param {import('../types/ESMStubWorkerMessages.js').ESMStubWorkerResponse} message
17
17
  */
18
18
  function emitMessage(message) {
19
19
  parentPort?.postMessage(message);
20
20
  }
21
- parentPort.on('message', (/** @type {import('../types/WriteESMStubsInput.js').WriteESMStubsInput & { id: number }} */ options) => {
21
+ parentPort.on('message', (/** @type {import('../types/ESMStubWorkerMessages.js').ESMStubWorkerRequest} */ options) => {
22
22
  const { id } = options;
23
23
  function onExit() {
24
24
  // In this case, throw an error rather than sending a message to avoid handling it twice.
25
25
  // Don't include the filename since that's potentially ambiguous (and redundant with info
26
- // included by the runInSandbox error handler).
26
+ // included by the processStubsInWorker error handler).
27
27
  throw new Error('process.exit() was unexpectedly called');
28
28
  }
29
29
  process.on('exit', onExit);
30
30
  writeESMStubsInternal(options)
31
- .then((stubs) => {
32
- emitMessage({ id, stubs });
31
+ .then((result) => {
32
+ emitMessage({ id, ...result });
33
33
  })
34
- .catch((/** @type {Error} */ error) => {
34
+ .catch((error) => {
35
35
  emitMessage({
36
36
  id,
37
- stubs: [],
38
- error,
37
+ newEntries: {},
38
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
39
+ errors: [{ text: /** @type {Error} */ (error).stack || String(error) }],
39
40
  });
40
41
  })
41
42
  .finally(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"workerEntry.js","sourceRoot":"","sources":["../../src/worker/workerEntry.js"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,4FAA4F;AAC5F,8FAA8F;AAC9F,8CAA8C;AAE9C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,IAAI,YAAY,IAAI,CAAC,UAAU,EAAE,CAAC;IAChC,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,sBAAsB,EAAE,CAAC;AAE/B,6DAA6D;AAC7D,MAAM,uBAAuB,GAAG,mBAAmB,EAAE,CAAC;AAEtD;;GAEG;AACH,SAAS,WAAW,CAAC,OAAO;IAC1B,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;AACnC,CAAC;AAED,UAAU,CAAC,EAAE,CACX,SAAS,EACT,CAAC,2FAA2F,CAAC,OAAO,EAAE,EAAE;IACtG,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC;IAEvB,SAAS,MAAM;QACb,yFAAyF;QACzF,yFAAyF;QACzF,+CAA+C;QAC/C,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IAED,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE3B,qBAAqB,CAAC,OAAO,CAAC;SAC3B,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;QACd,WAAW,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7B,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,oBAAoB,CAAC,KAAK,EAAE,EAAE;QACpC,WAAW,CAAC;YACV,EAAE;YACF,KAAK,EAAE,EAAE;YACT,KAAK;SACN,CAAC,CAAC;IACL,CAAC,CAAC;SACD,OAAO,CAAC,GAAG,EAAE;QACZ,cAAc,CAAC,uBAAuB,CAAC,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;AACP,CAAC,CACF,CAAC","sourcesContent":["// These files use JS because they're loaded directly into a worker (see runInSandbox.ts),\n// which must work both during tests (where the files are loaded from \"src\") and at runtime.\n// They can still be type checked like TS, and the transpilation step doesn't do anything that\n// should change the desired runtime behavior.\n\nimport { isMainThread, parentPort } from 'worker_threads';\nimport { initBrowserEnvironment } from './initBrowserEnvironment.js';\nimport { cleanUpGlobals, getGlobalProperties } from './globals.js';\nimport { writeESMStubsInternal } from '../writeESMStubsInternal.js';\n\nif (isMainThread || !parentPort) {\n throw new Error('This file should only be loaded in a worker thread');\n}\n\nawait initBrowserEnvironment();\n\n// TODO should the globals be marked as readonly if possible?\nconst initialGlobalProperties = getGlobalProperties();\n\n/**\n * @param {import('../types/WriteESMStubsOutput.js').WriteESMStubsOutput & { id: number }} message\n */\nfunction emitMessage(message) {\n parentPort?.postMessage(message);\n}\n\nparentPort.on(\n 'message',\n (/** @type {import('../types/WriteESMStubsInput.js').WriteESMStubsInput & { id: number }} */ options) => {\n const { id } = options;\n\n function onExit() {\n // In this case, throw an error rather than sending a message to avoid handling it twice.\n // Don't include the filename since that's potentially ambiguous (and redundant with info\n // included by the runInSandbox error handler).\n throw new Error('process.exit() was unexpectedly called');\n }\n\n process.on('exit', onExit);\n\n writeESMStubsInternal(options)\n .then((stubs) => {\n emitMessage({ id, stubs });\n })\n .catch((/** @type {Error} */ error) => {\n emitMessage({\n id,\n stubs: [],\n error,\n });\n })\n .finally(() => {\n cleanUpGlobals(initialGlobalProperties);\n process.off('exit', onExit);\n });\n },\n);\n"]}
1
+ {"version":3,"file":"workerEntry.js","sourceRoot":"","sources":["../../src/worker/workerEntry.js"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,4FAA4F;AAC5F,8FAA8F;AAC9F,8CAA8C;AAE9C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,IAAI,YAAY,IAAI,CAAC,UAAU,EAAE,CAAC;IAChC,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,sBAAsB,EAAE,CAAC;AAE/B,6DAA6D;AAC7D,MAAM,uBAAuB,GAAG,mBAAmB,EAAE,CAAC;AAEtD;;GAEG;AACH,SAAS,WAAW,CAAC,OAAO;IAC1B,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;AACnC,CAAC;AAED,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,+EAA+E,CAAC,OAAO,EAAE,EAAE;IACnH,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC;IAEvB,SAAS,MAAM;QACb,yFAAyF;QACzF,yFAAyF;QACzF,uDAAuD;QACvD,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IAED,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE3B,qBAAqB,CAAC,OAAO,CAAC;SAC3B,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;QACf,WAAW,CAAC,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;IACjC,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACf,WAAW,CAAC;YACV,EAAE;YACF,UAAU,EAAE,EAAE;YACd,sEAAsE;YACtE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,oBAAoB,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;SACxE,CAAC,CAAC;IACL,CAAC,CAAC;SACD,OAAO,CAAC,GAAG,EAAE;QACZ,cAAc,CAAC,uBAAuB,CAAC,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["// These files use JS because they're loaded directly into a worker (see processStubsInWorker.ts),\n// which must work both during tests (where the files are loaded from \"src\") and at runtime.\n// They can still be type checked like TS, and the transpilation step doesn't do anything that\n// should change the desired runtime behavior.\n\nimport { isMainThread, parentPort } from 'worker_threads';\nimport { initBrowserEnvironment } from './initBrowserEnvironment.js';\nimport { cleanUpGlobals, getGlobalProperties } from './globals.js';\nimport { writeESMStubsInternal } from '../writeESMStubsInternal.js';\n\nif (isMainThread || !parentPort) {\n throw new Error('This file should only be loaded in a worker thread');\n}\n\nawait initBrowserEnvironment();\n\n// TODO should the globals be marked as readonly if possible?\nconst initialGlobalProperties = getGlobalProperties();\n\n/**\n * @param {import('../types/ESMStubWorkerMessages.js').ESMStubWorkerResponse} message\n */\nfunction emitMessage(message) {\n parentPort?.postMessage(message);\n}\n\nparentPort.on('message', (/** @type {import('../types/ESMStubWorkerMessages.js').ESMStubWorkerRequest} */ options) => {\n const { id } = options;\n\n function onExit() {\n // In this case, throw an error rather than sending a message to avoid handling it twice.\n // Don't include the filename since that's potentially ambiguous (and redundant with info\n // included by the processStubsInWorker error handler).\n throw new Error('process.exit() was unexpectedly called');\n }\n\n process.on('exit', onExit);\n\n writeESMStubsInternal(options)\n .then((result) => {\n emitMessage({ id, ...result });\n })\n .catch((error) => {\n emitMessage({\n id,\n newEntries: {},\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n errors: [{ text: /** @type {Error} */ (error).stack || String(error) }],\n });\n })\n .finally(() => {\n cleanUpGlobals(initialGlobalProperties);\n process.off('exit', onExit);\n });\n});\n"]}
@@ -1,10 +1,9 @@
1
- import type { WriteESMStubsOutput } from './types/WriteESMStubsOutput.js';
1
+ import type { WriteESMStubsOptions } from './types/WriteESMStubsOptions.js';
2
+ import type { WriteESMStubsResult } from './types/WriteESMStubsResult.js';
2
3
  /**
3
- * Generates ESM stubs for CommonJS and JSON modules.
4
- * @returns An object result containing the stubs or error that occured.
4
+ * Writes ESM stubs for CJS entries. Take in `intputPath` and `entries` and returns the stubs.
5
+ * The `entries` record has key of output path minus extension (e.g. './index') and value
6
+ * represents the entry source path (e.g. './src/index.js').
5
7
  */
6
- export declare function writeESMStubs(options: {
7
- inputPath: string;
8
- entryPaths: string[];
9
- }): Promise<WriteESMStubsOutput>;
8
+ export declare function writeESMStubs(options: WriteESMStubsOptions): Promise<WriteESMStubsResult>;
10
9
  //# sourceMappingURL=writeESMStubs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"writeESMStubs.d.ts","sourceRoot":"","sources":["../src/writeESMStubs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAE1E;;;GAGG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAE/B"}
1
+ {"version":3,"file":"writeESMStubs.d.ts","sourceRoot":"","sources":["../src/writeESMStubs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAE1E;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAE/F"}
@@ -1,7 +1,8 @@
1
1
  import { processStubsInWorker } from './processStubsInWorker.js';
2
2
  /**
3
- * Generates ESM stubs for CommonJS and JSON modules.
4
- * @returns An object result containing the stubs or error that occured.
3
+ * Writes ESM stubs for CJS entries. Take in `intputPath` and `entries` and returns the stubs.
4
+ * The `entries` record has key of output path minus extension (e.g. './index') and value
5
+ * represents the entry source path (e.g. './src/index.js').
5
6
  */
6
7
  export async function writeESMStubs(options) {
7
8
  return processStubsInWorker(options);
@@ -1 +1 @@
1
- {"version":3,"file":"writeESMStubs.js","sourceRoot":"","sources":["../src/writeESMStubs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAGjE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAGnC;IACC,OAAO,oBAAoB,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import { processStubsInWorker } from './processStubsInWorker.js';\nimport type { WriteESMStubsOutput } from './types/WriteESMStubsOutput.js';\n\n/**\n * Generates ESM stubs for CommonJS and JSON modules.\n * @returns An object result containing the stubs or error that occured.\n */\nexport async function writeESMStubs(options: {\n inputPath: string;\n entryPaths: string[];\n}): Promise<WriteESMStubsOutput> {\n return processStubsInWorker(options);\n}\n"]}
1
+ {"version":3,"file":"writeESMStubs.js","sourceRoot":"","sources":["../src/writeESMStubs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAIjE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAA6B;IAC/D,OAAO,oBAAoB,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import { processStubsInWorker } from './processStubsInWorker.js';\nimport type { WriteESMStubsOptions } from './types/WriteESMStubsOptions.js';\nimport type { WriteESMStubsResult } from './types/WriteESMStubsResult.js';\n\n/**\n * Writes ESM stubs for CJS entries. Take in `intputPath` and `entries` and returns the stubs.\n * The `entries` record has key of output path minus extension (e.g. './index') and value\n * represents the entry source path (e.g. './src/index.js').\n */\nexport async function writeESMStubs(options: WriteESMStubsOptions): Promise<WriteESMStubsResult> {\n return processStubsInWorker(options);\n}\n"]}
@@ -1,8 +1,8 @@
1
- import type { WriteESMStubsInput } from './types/WriteESMStubsInput.js';
2
- import type { ESMStub } from './types/ESMStub.js';
1
+ import type { WriteESMStubsOptions } from './types/WriteESMStubsOptions.js';
2
+ import type { WriteESMStubsResult } from './types/WriteESMStubsResult.js';
3
3
  /**
4
4
  * Generates a set of ESM stubs for given entries and writes it to disk. If
5
5
  * any files doesn't need a stub, then entry will have an undefined stubPath.
6
6
  */
7
- export declare function writeESMStubsInternal(options: WriteESMStubsInput): Promise<ESMStub[]>;
7
+ export declare function writeESMStubsInternal(options: WriteESMStubsOptions): Promise<WriteESMStubsResult>;
8
8
  //# sourceMappingURL=writeESMStubsInternal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"writeESMStubsInternal.d.ts","sourceRoot":"","sources":["../src/writeESMStubsInternal.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGlD;;;GAGG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CA6C3F"}
1
+ {"version":3,"file":"writeESMStubsInternal.d.ts","sourceRoot":"","sources":["../src/writeESMStubsInternal.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAE1E;;;GAGG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAuCvG"}
@@ -1,50 +1,52 @@
1
+ import { slash } from '@ms-cloudpack/path-string-parsing';
2
+ import { writeFile } from 'fs/promises';
3
+ import path from 'path';
1
4
  import { generateESMStubFromCJS } from './generateESMStubFromCJS.js';
2
5
  import { generateESMStubFromJSON } from './generateESMStubFromJSON.js';
3
6
  import { getStubPath } from './getStubPath.js';
4
- import { writeFile } from 'fs/promises';
5
- import path from 'path';
6
- import { slash } from '@ms-cloudpack/path-string-parsing';
7
+ import { processError } from './processError.js';
7
8
  /**
8
9
  * Generates a set of ESM stubs for given entries and writes it to disk. If
9
10
  * any files doesn't need a stub, then entry will have an undefined stubPath.
10
11
  */
11
12
  export async function writeESMStubsInternal(options) {
12
- const { inputPath, entryPaths } = options;
13
- return await Promise.all(entryPaths.map(async (entryPath) => {
13
+ const { inputPath, entries } = options;
14
+ const result = {
15
+ newEntries: {},
16
+ errors: [],
17
+ };
18
+ for (const [entryKey, entryPath] of Object.entries(entries)) {
14
19
  const filePath = slash(path.join(inputPath, entryPath));
20
+ const safeEntryKey = stripLeadingRelativePath(entryKey);
15
21
  let stubContent = '';
16
22
  let stubPath;
17
23
  try {
18
24
  stubPath = await getStubPath({ inputPath, entryPath });
19
25
  if (!stubPath) {
20
- return { entryPath };
21
- }
22
- // Process .json stubs
23
- if (path.extname(entryPath).toLowerCase() === '.json') {
24
- stubContent = await generateESMStubFromJSON({ filePath });
26
+ result.newEntries[safeEntryKey] = path.join(inputPath, entryPath);
25
27
  }
26
28
  else {
27
- stubContent = generateESMStubFromCJS({
28
- filePath,
29
- stubPath,
30
- });
29
+ if (path.extname(entryPath).toLowerCase() === '.json') {
30
+ stubContent = await generateESMStubFromJSON({ filePath });
31
+ }
32
+ else {
33
+ stubContent = generateESMStubFromCJS({ filePath, stubPath });
34
+ }
35
+ // Attempt to write it to disk.
36
+ await writeFile(stubPath, stubContent, 'utf-8');
37
+ result.newEntries[safeEntryKey] = stubPath;
31
38
  }
32
39
  }
33
40
  catch (e) {
34
- const err = e;
35
- return {
36
- entryPath,
37
- error: {
38
- type: 'other-error',
39
- message: String(err),
40
- stack: err.stack,
41
- },
42
- };
41
+ const entryFullPath = path.join(inputPath, entryPath);
42
+ result.newEntries[safeEntryKey] = entryFullPath;
43
+ result.errors ||= [];
44
+ result.errors.push(processError(safeEntryKey, entryFullPath, e));
43
45
  }
44
- // Attempt to write it to disk.
45
- await writeFile(stubPath, stubContent, 'utf-8');
46
- // Success, return the stub.
47
- return { entryPath, stubPath: slash('./' + path.relative(inputPath, stubPath)) };
48
- }));
46
+ }
47
+ return result;
48
+ }
49
+ function stripLeadingRelativePath(relativePath) {
50
+ return relativePath.replace(/^\.\//, '');
49
51
  }
50
52
  //# sourceMappingURL=writeESMStubsInternal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"writeESMStubsInternal.js","sourceRoot":"","sources":["../src/writeESMStubsInternal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,aAA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AM,SAAS,CAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;QAEhD,4BAA4B;QAC5B,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,EAAa,CAAC;IAC9F,CAAC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import { generateESMStubFromCJS } from './generateESMStubFromCJS.js';\nimport { generateESMStubFromJSON } from './generateESMStubFromJSON.js';\nimport { getStubPath } from './getStubPath.js';\nimport { writeFile } from 'fs/promises';\nimport path from 'path';\nimport type { WriteESMStubsInput } from './types/WriteESMStubsInput.js';\nimport type { ESMStub } from './types/ESMStub.js';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\n\n/**\n * Generates a set of ESM stubs for given entries and writes it to disk. If\n * any files doesn't need a stub, then entry will have an undefined stubPath.\n */\nexport async function writeESMStubsInternal(options: WriteESMStubsInput): Promise<ESMStub[]> {\n const { inputPath, entryPaths } = options;\n\n return await Promise.all<ESMStub>(\n entryPaths.map(async (entryPath) => {\n const filePath = slash(path.join(inputPath, entryPath));\n let stubContent: string = '';\n let stubPath: string | undefined;\n\n try {\n stubPath = await getStubPath({ inputPath, entryPath });\n\n if (!stubPath) {\n return { entryPath };\n }\n\n // Process .json stubs\n if (path.extname(entryPath).toLowerCase() === '.json') {\n stubContent = await generateESMStubFromJSON({ filePath });\n } else {\n stubContent = generateESMStubFromCJS({\n filePath,\n stubPath,\n });\n }\n } catch (e) {\n const err = e as Error & { code?: string; requireStack?: string[] };\n\n return {\n entryPath,\n error: {\n type: 'other-error',\n message: String(err),\n stack: err.stack,\n },\n };\n }\n\n // Attempt to write it to disk.\n await writeFile(stubPath, stubContent, 'utf-8');\n\n // Success, return the stub.\n return { entryPath, stubPath: slash('./' + path.relative(inputPath, stubPath)) } as ESMStub;\n }),\n );\n}\n"]}
1
+ {"version":3,"file":"writeESMStubsInternal.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S,CAAC,CAAC,WAAW,EAAE,KAAK,OAAO,EAAE,CAAC;oBACtD,WAAW,GAAG,MAAM,uBAAuB,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;gBAC5D,CAAC;qBAAM,CAAC;oBACN,WAAW,GAAG,sBAAsB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;gBAC/D,CAAC;gBAED,+BAA+B;gBAC/B,MAAM,SAAS,CAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;gBAEhD,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,GAAG,QAAQ,CAAC;YAC7C,CAAC;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;YACtD,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,GAAG,aAAa,CAAC;YAChD,MAAM,CAAC,MAAM,KAAK,EAAE,CAAC;YACrB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,wBAAwB,CAAC,YAAoB;IACpD,OAAO,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import { slash } from '@ms-cloudpack/path-string-parsing';\nimport { writeFile } from 'fs/promises';\nimport path from 'path';\nimport { generateESMStubFromCJS } from './generateESMStubFromCJS.js';\nimport { generateESMStubFromJSON } from './generateESMStubFromJSON.js';\nimport { getStubPath } from './getStubPath.js';\nimport { processError } from './processError.js';\nimport type { WriteESMStubsOptions } from './types/WriteESMStubsOptions.js';\nimport type { WriteESMStubsResult } from './types/WriteESMStubsResult.js';\n\n/**\n * Generates a set of ESM stubs for given entries and writes it to disk. If\n * any files doesn't need a stub, then entry will have an undefined stubPath.\n */\nexport async function writeESMStubsInternal(options: WriteESMStubsOptions): Promise<WriteESMStubsResult> {\n const { inputPath, entries } = options;\n const result: WriteESMStubsResult = {\n newEntries: {},\n errors: [],\n };\n\n for (const [entryKey, entryPath] of Object.entries(entries)) {\n const filePath = slash(path.join(inputPath, entryPath));\n const safeEntryKey = stripLeadingRelativePath(entryKey);\n let stubContent: string = '';\n let stubPath: string | undefined;\n\n try {\n stubPath = await getStubPath({ inputPath, entryPath });\n\n if (!stubPath) {\n result.newEntries[safeEntryKey] = path.join(inputPath, entryPath);\n } else {\n if (path.extname(entryPath).toLowerCase() === '.json') {\n stubContent = await generateESMStubFromJSON({ filePath });\n } else {\n stubContent = generateESMStubFromCJS({ filePath, stubPath });\n }\n\n // Attempt to write it to disk.\n await writeFile(stubPath, stubContent, 'utf-8');\n\n result.newEntries[safeEntryKey] = stubPath;\n }\n } catch (e) {\n const entryFullPath = path.join(inputPath, entryPath);\n result.newEntries[safeEntryKey] = entryFullPath;\n result.errors ||= [];\n result.errors.push(processError(safeEntryKey, entryFullPath, e));\n }\n }\n\n return result;\n}\n\nfunction stripLeadingRelativePath(relativePath: string) {\n return relativePath.replace(/^\\.\\//, '');\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/esm-stub-utilities",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Generates ESM stubs for CommonJS entry files.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,23 +14,18 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
+ "@ms-cloudpack/bundler-types": "^0.23.12",
17
18
  "@ms-cloudpack/json-utilities": "^0.1.3",
18
- "@ms-cloudpack/path-utilities": "^2.4.3",
19
19
  "@ms-cloudpack/path-string-parsing": "^1.1.3",
20
- "@ms-cloudpack/package-utilities": "^5.7.10",
21
- "atob": "^2.1.2",
22
- "btoa": "^1.2.1",
20
+ "@ms-cloudpack/package-utilities": "^5.8.1",
23
21
  "jsdom-global": "^3.0.2",
24
22
  "jsdom": "^22.0.0",
25
23
  "regenerator-runtime": "^0.14.1"
26
24
  },
27
25
  "devDependencies": {
28
- "@ms-cloudpack/bundler-types": "*",
29
26
  "@ms-cloudpack/eslint-plugin-internal": "*",
30
27
  "@ms-cloudpack/scripts": "*",
31
28
  "@ms-cloudpack/test-utilities": "*",
32
- "@types/atob": "^2.1.2",
33
- "@types/btoa": "^1.2.3",
34
29
  "@types/jsdom": "^21.1.1",
35
30
  "@types/regenerator-runtime": "^0.13.1",
36
31
  "lodash": "^4.17.21",
@@ -1,7 +0,0 @@
1
- import type { StubError } from './StubError.js';
2
- export type ESMStub = {
3
- entryPath: string;
4
- stubPath?: string;
5
- error?: StubError;
6
- };
7
- //# sourceMappingURL=ESMStub.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ESMStub.d.ts","sourceRoot":"","sources":["../../src/types/ESMStub.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,MAAM,OAAO,GAAG;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=ESMStub.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ESMStub.js","sourceRoot":"","sources":["../../src/types/ESMStub.ts"],"names":[],"mappings":"","sourcesContent":["import type { StubError } from './StubError.js';\n\nexport type ESMStub = {\n entryPath: string;\n stubPath?: string;\n error?: StubError;\n};\n"]}
@@ -1,4 +0,0 @@
1
- import type { WriteESMStubsInput } from './WriteESMStubsInput.js';
2
- import type { WriteESMStubsOutput } from './WriteESMStubsOutput.js';
3
- export type ProcessStubsFunction = (options: WriteESMStubsInput) => Promise<WriteESMStubsOutput>;
4
- //# sourceMappingURL=ProcessStubsFunction.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ProcessStubsFunction.d.ts","sourceRoot":"","sources":["../../src/types/ProcessStubsFunction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,EAAE,kBAAkB,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=ProcessStubsFunction.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ProcessStubsFunction.js","sourceRoot":"","sources":["../../src/types/ProcessStubsFunction.ts"],"names":[],"mappings":"","sourcesContent":["import type { WriteESMStubsInput } from './WriteESMStubsInput.js';\nimport type { WriteESMStubsOutput } from './WriteESMStubsOutput.js';\n\nexport type ProcessStubsFunction = (options: WriteESMStubsInput) => Promise<WriteESMStubsOutput>;\n"]}
@@ -1,21 +0,0 @@
1
- import type { StubExportInfo } from './StubExportInfo.js';
2
- /**
3
- * Success or error IPC message after attempting to run a CJS file in a worker.
4
- */
5
- export interface SandboxWorkerResponse {
6
- /** Path to the file that was run */
7
- entryPath: string;
8
- /** If successful: info about the file's exports */
9
- exportInfo?: StubExportInfo;
10
- /** If not successful: info about the error that occurred */
11
- error?: {
12
- /** Message describing the error */
13
- message: string;
14
- /** If there was an exception: error object name */
15
- name?: string;
16
- /** If there was an exception: error code (not always set) */
17
- code?: string;
18
- stack?: string;
19
- };
20
- }
21
- //# sourceMappingURL=SandboxWorkerResponse.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SandboxWorkerResponse.d.ts","sourceRoot":"","sources":["../../src/types/SandboxWorkerResponse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,oCAAoC;IACpC,SAAS,EAAE,MAAM,CAAC;IAElB,mDAAmD;IACnD,UAAU,CAAC,EAAE,cAAc,CAAC;IAE5B,4DAA4D;IAC5D,KAAK,CAAC,EAAE;QACN,mCAAmC;QACnC,OAAO,EAAE,MAAM,CAAC;QAChB,mDAAmD;QACnD,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,6DAA6D;QAC7D,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;CACH"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=SandboxWorkerResponse.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SandboxWorkerResponse.js","sourceRoot":"","sources":["../../src/types/SandboxWorkerResponse.ts"],"names":[],"mappings":"","sourcesContent":["import type { StubExportInfo } from './StubExportInfo.js';\n\n/**\n * Success or error IPC message after attempting to run a CJS file in a worker.\n */\nexport interface SandboxWorkerResponse {\n /** Path to the file that was run */\n entryPath: string;\n\n /** If successful: info about the file's exports */\n exportInfo?: StubExportInfo;\n\n /** If not successful: info about the error that occurred */\n error?: {\n /** Message describing the error */\n message: string;\n /** If there was an exception: error object name */\n name?: string;\n /** If there was an exception: error code (not always set) */\n code?: string;\n stack?: string;\n };\n}\n"]}
@@ -1,31 +0,0 @@
1
- /**
2
- * Error that occurred while attempting to create an ESM stub from a CJS or JSON file.
3
- */
4
- export interface StubError {
5
- /**
6
- * Type of error:
7
- * - `module-not-found`: Some file attempted to load a module that wasn't found.
8
- * - `require-esm`: Some file attempted to load an ESM module using `require()`.
9
- * - `entry-is-esm`: The entry file being stubbed is already ESM.
10
- * - `invalid-syntax`: Some loaded file has invalid syntax.
11
- * - `other-error`: Anything else.
12
- */
13
- type: 'module-not-found' | 'require-esm' | 'entry-is-esm' | 'invalid-syntax' | 'other-error';
14
- /**
15
- * Error message. This will *not* include the path to the file that was being stubbed,
16
- * since it's assumed the caller already has this context, and it should be reported as the
17
- * file location in the final BundleMessage error.
18
- */
19
- message: string;
20
- /**
21
- * Original stack string.
22
- */
23
- stack?: string;
24
- /**
25
- * Stack from the location of the error down to the file attempting to be stubbed,
26
- * omitting frames from Node built-ins. Each line follows the standard stack trace format
27
- * `at <function> (<file>:<line>:<column>)` (but with whitespace trimmed).
28
- */
29
- partialStack?: string[];
30
- }
31
- //# sourceMappingURL=StubError.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StubError.d.ts","sourceRoot":"","sources":["../../src/types/StubError.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB;;;;;;;OAOG;IACH,IAAI,EAAE,kBAAkB,GAAG,aAAa,GAAG,cAAc,GAAG,gBAAgB,GAAG,aAAa,CAAC;IAE7F;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=StubError.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StubError.js","sourceRoot":"","sources":["../../src/types/StubError.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Error that occurred while attempting to create an ESM stub from a CJS or JSON file.\n */\nexport interface StubError {\n /**\n * Type of error:\n * - `module-not-found`: Some file attempted to load a module that wasn't found.\n * - `require-esm`: Some file attempted to load an ESM module using `require()`.\n * - `entry-is-esm`: The entry file being stubbed is already ESM.\n * - `invalid-syntax`: Some loaded file has invalid syntax.\n * - `other-error`: Anything else.\n */\n type: 'module-not-found' | 'require-esm' | 'entry-is-esm' | 'invalid-syntax' | 'other-error';\n\n /**\n * Error message. This will *not* include the path to the file that was being stubbed,\n * since it's assumed the caller already has this context, and it should be reported as the\n * file location in the final BundleMessage error.\n */\n message: string;\n\n /**\n * Original stack string.\n */\n stack?: string;\n\n /**\n * Stack from the location of the error down to the file attempting to be stubbed,\n * omitting frames from Node built-ins. Each line follows the standard stack trace format\n * `at <function> (<file>:<line>:<column>)` (but with whitespace trimmed).\n */\n partialStack?: string[];\n}\n"]}
@@ -1,7 +0,0 @@
1
- export type WriteESMStubsInput = {
2
- /** The absolute path to the package. */
3
- inputPath: string;
4
- /** An array of entry source paths. */
5
- entryPaths: string[];
6
- };
7
- //# sourceMappingURL=WriteESMStubsInput.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WriteESMStubsInput.d.ts","sourceRoot":"","sources":["../../src/types/WriteESMStubsInput.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG;IAC/B,wCAAwC;IACxC,SAAS,EAAE,MAAM,CAAC;IAElB,sCAAsC;IACtC,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=WriteESMStubsInput.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WriteESMStubsInput.js","sourceRoot":"","sources":["../../src/types/WriteESMStubsInput.ts"],"names":[],"mappings":"","sourcesContent":["export type WriteESMStubsInput = {\n /** The absolute path to the package. */\n inputPath: string;\n\n /** An array of entry source paths. */\n entryPaths: string[];\n};\n"]}
@@ -1,6 +0,0 @@
1
- import type { ESMStub } from './ESMStub.js';
2
- export type WriteESMStubsOutput = {
3
- error?: Error;
4
- stubs: ESMStub[];
5
- };
6
- //# sourceMappingURL=WriteESMStubsOutput.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WriteESMStubsOutput.d.ts","sourceRoot":"","sources":["../../src/types/WriteESMStubsOutput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,KAAK,EAAE,OAAO,EAAE,CAAC;CAClB,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=WriteESMStubsOutput.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WriteESMStubsOutput.js","sourceRoot":"","sources":["../../src/types/WriteESMStubsOutput.ts"],"names":[],"mappings":"","sourcesContent":["import type { ESMStub } from './ESMStub.js';\n\nexport type WriteESMStubsOutput = {\n error?: Error;\n stubs: ESMStub[];\n};\n"]}