@ms-cloudpack/esm-stub-utilities 0.13.23 → 0.14.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.
- package/lib/generateESMStubFromCJS.d.ts +4 -1
- package/lib/generateESMStubFromCJS.d.ts.map +1 -1
- package/lib/generateESMStubFromCJS.js +7 -3
- package/lib/generateESMStubFromCJS.js.map +1 -1
- package/lib/types/WriteESMStubsOptions.d.ts +1 -1
- package/lib/types/WriteESMStubsOptions.d.ts.map +1 -1
- package/lib/types/WriteESMStubsOptions.js.map +1 -1
- package/lib/writeESMStubs.d.ts.map +1 -1
- package/lib/writeESMStubs.js +3 -2
- package/lib/writeESMStubs.js.map +1 -1
- package/lib/writeESMStubsInWorker.d.ts.map +1 -1
- package/lib/writeESMStubsInWorker.js +2 -1
- package/lib/writeESMStubsInWorker.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Given entry/stub paths
|
|
2
|
+
* Given entry/stub paths, generates the esm stub content.
|
|
3
3
|
* The stubPath is required to generate the proper import statement.
|
|
4
|
+
* namedExports is optional, if present, the given export names will be used,
|
|
5
|
+
* but if missing, we'll attempt to require the CJS and extract export info.
|
|
4
6
|
*/
|
|
5
7
|
export declare function generateESMStubFromCJS(options: {
|
|
6
8
|
filePath: string;
|
|
7
9
|
stubPath: string;
|
|
10
|
+
namedExports?: string[];
|
|
8
11
|
}): string;
|
|
9
12
|
//# sourceMappingURL=generateESMStubFromCJS.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateESMStubFromCJS.d.ts","sourceRoot":"","sources":["../src/generateESMStubFromCJS.ts"],"names":[],"mappings":"AAQA
|
|
1
|
+
{"version":3,"file":"generateESMStubFromCJS.d.ts","sourceRoot":"","sources":["../src/generateESMStubFromCJS.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB,GAAG,MAAM,CAyBT"}
|
|
@@ -5,12 +5,16 @@ import { getExportInfo } from './getExportInfo.js';
|
|
|
5
5
|
import { generateESMStubFromExports } from './generateESMStubFromExports.js';
|
|
6
6
|
const require = createRequire(import.meta.url);
|
|
7
7
|
/**
|
|
8
|
-
* Given entry/stub paths
|
|
8
|
+
* Given entry/stub paths, generates the esm stub content.
|
|
9
9
|
* The stubPath is required to generate the proper import statement.
|
|
10
|
+
* namedExports is optional, if present, the given export names will be used,
|
|
11
|
+
* but if missing, we'll attempt to require the CJS and extract export info.
|
|
10
12
|
*/
|
|
11
13
|
export function generateESMStubFromCJS(options) {
|
|
12
|
-
const { filePath, stubPath } = options;
|
|
13
|
-
const exportInfo =
|
|
14
|
+
const { filePath, stubPath, namedExports } = options;
|
|
15
|
+
const exportInfo = namedExports
|
|
16
|
+
? { type: 'object', keys: namedExports }
|
|
17
|
+
: getExportInfo(require(filePath));
|
|
14
18
|
const { type: exportType } = exportInfo;
|
|
15
19
|
let relativePath;
|
|
16
20
|
// We need to compute a relative path from the stub to the entry to construct the proper import in the stub.
|
|
@@ -1 +1 @@
|
|
|
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,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAE7E,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C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0B,CAAC;QAC7C,eAAe,EACb,UAAU,KAAK,MAAM,CAAC,CAAC,CAAC,WAAW,YAAY,IAAI,CAAC,CAAC,CAAC,6BAA6B,YAAY,IAAI;QACrG,MAAM,EAAE,UAAU;KACnB,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import { slash } from '@ms-cloudpack/path-string-parsing';\nimport { createRequire } from 'module';\nimport path from 'path';\nimport { getExportInfo } from './getExportInfo.js';\nimport { generateESMStubFromExports } from './generateESMStubFromExports.js';\n\nconst require = createRequire(import.meta.url);\n\n/**\n * Given entry/stub paths, generates the esm stub content.\n * The stubPath is required to generate the proper import statement.\n * namedExports is optional, if present, the given export names will be used,\n * but if missing, we'll attempt to require the CJS and extract export info.\n */\nexport function generateESMStubFromCJS(options: {\n filePath: string;\n stubPath: string;\n namedExports?: string[];\n}): string {\n const { filePath, stubPath, namedExports } = options;\n\n const exportInfo = namedExports\n ? ({ type: 'object', keys: namedExports } as const)\n : 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 (process.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 const stubContent = generateESMStubFromExports({\n importStatement:\n exportType === 'none' ? `import \"${relativePath}\";` : `import moduleExport from \"${relativePath}\";`,\n export: exportInfo,\n });\n\n return stubContent;\n}\n"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { BundleOptions } from '@ms-cloudpack/common-types';
|
|
2
|
-
export type WriteESMStubsOptions = Pick<BundleOptions, 'inputPath' | 'entries'>;
|
|
2
|
+
export type WriteESMStubsOptions = Pick<BundleOptions, 'inputPath' | 'entries' | 'unsafeCjsExportNames'>;
|
|
3
3
|
//# sourceMappingURL=WriteESMStubsOptions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WriteESMStubsOptions.d.ts","sourceRoot":"","sources":["../../src/types/WriteESMStubsOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAEhE,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,aAAa,EAAE,WAAW,GAAG,SAAS,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"WriteESMStubsOptions.d.ts","sourceRoot":"","sources":["../../src/types/WriteESMStubsOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAEhE,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,aAAa,EAAE,WAAW,GAAG,SAAS,GAAG,sBAAsB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WriteESMStubsOptions.js","sourceRoot":"","sources":["../../src/types/WriteESMStubsOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { BundleOptions } from '@ms-cloudpack/common-types';\n\nexport type WriteESMStubsOptions = Pick<BundleOptions, 'inputPath' | 'entries'>;\n"]}
|
|
1
|
+
{"version":3,"file":"WriteESMStubsOptions.js","sourceRoot":"","sources":["../../src/types/WriteESMStubsOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { BundleOptions } from '@ms-cloudpack/common-types';\n\nexport type WriteESMStubsOptions = Pick<BundleOptions, 'inputPath' | 'entries' | 'unsafeCjsExportNames'>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeESMStubs.d.ts","sourceRoot":"","sources":["../src/writeESMStubs.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,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC,
|
|
1
|
+
{"version":3,"file":"writeESMStubs.d.ts","sourceRoot":"","sources":["../src/writeESMStubs.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,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CA0C/F"}
|
package/lib/writeESMStubs.js
CHANGED
|
@@ -10,7 +10,7 @@ import { processError } from './processError.js';
|
|
|
10
10
|
* If any files doesn't need a stub, the returned entry will use the original path.
|
|
11
11
|
*/
|
|
12
12
|
export async function writeESMStubs(options) {
|
|
13
|
-
const { inputPath, entries } = options;
|
|
13
|
+
const { inputPath, entries, unsafeCjsExportNames } = options;
|
|
14
14
|
const result = {
|
|
15
15
|
newEntries: {},
|
|
16
16
|
errors: [],
|
|
@@ -27,11 +27,12 @@ export async function writeESMStubs(options) {
|
|
|
27
27
|
}
|
|
28
28
|
console.debug(`Generating ESM stub for ${filePath} at ${stubPath}`);
|
|
29
29
|
let stubContent = '';
|
|
30
|
+
const namedExports = unsafeCjsExportNames ? (unsafeCjsExportNames[entryKey] ?? []) : undefined;
|
|
30
31
|
if (path.extname(entryPath).toLowerCase() === '.json') {
|
|
31
32
|
stubContent = await generateESMStubFromJSON({ filePath });
|
|
32
33
|
}
|
|
33
34
|
else {
|
|
34
|
-
stubContent = generateESMStubFromCJS({ filePath, stubPath });
|
|
35
|
+
stubContent = generateESMStubFromCJS({ filePath, stubPath, namedExports });
|
|
35
36
|
}
|
|
36
37
|
// Attempt to write it to disk.
|
|
37
38
|
await writeFile(stubPath, stubContent, 'utf-8');
|
package/lib/writeESMStubs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeESMStubs.js","sourceRoot":"","sources":["../src/writeESMStubs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,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,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAIjD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAA6B;IAC/D,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"writeESMStubs.js","sourceRoot":"","sources":["../src/writeESMStubs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,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,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAIjD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAA6B;IAC/D,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,oBAAoB,EAAE,GAAG,OAAO,CAAC;IAC7D,MAAM,MAAM,GAAwB;QAClC,UAAU,EAAE,EAAE;QACd,MAAM,EAAE,EAAE;KACX,CAAC;IAEF,KAAK,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,IAA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,CAAC,GAAG,aAAa,CAAC;YAC5C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACrF,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,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.\n * If any files doesn't need a stub, the returned entry will use the original path.\n */\nexport async function writeESMStubs(options: WriteESMStubsOptions): Promise<WriteESMStubsResult> {\n const { inputPath, entries, unsafeCjsExportNames } = 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 entryFullPath = path.join(inputPath, entryPath);\n\n try {\n const stubPath = await getStubPath({ inputPath, entryPath });\n if (!stubPath) {\n // Stub not needed\n result.newEntries[entryKey] = entryFullPath;\n continue;\n }\n\n console.debug(`Generating ESM stub for ${filePath} at ${stubPath}`);\n\n let stubContent: string = '';\n\n const namedExports = unsafeCjsExportNames ? (unsafeCjsExportNames[entryKey] ?? []) : undefined;\n\n if (path.extname(entryPath).toLowerCase() === '.json') {\n stubContent = await generateESMStubFromJSON({ filePath });\n } else {\n stubContent = generateESMStubFromCJS({ filePath, stubPath, namedExports });\n }\n\n // Attempt to write it to disk.\n await writeFile(stubPath, stubContent, 'utf-8');\n\n result.newEntries[entryKey] = stubPath;\n } catch (e) {\n result.newEntries[entryKey] = entryFullPath;\n result.errors.push(processError({ entryKey, entryFullPath, inputPath, error: e }));\n }\n }\n\n return result;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeESMStubsInWorker.d.ts","sourceRoot":"","sources":["../src/writeESMStubsInWorker.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAM1E;;GAEG;AAGH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,oBAAoB,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GACtD,OAAO,CAAC,mBAAmB,CAAC,
|
|
1
|
+
{"version":3,"file":"writeESMStubsInWorker.d.ts","sourceRoot":"","sources":["../src/writeESMStubsInWorker.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAM1E;;GAEG;AAGH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,oBAAoB,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GACtD,OAAO,CAAC,mBAAmB,CAAC,CAwE9B;AAED,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC,CAG3D"}
|
|
@@ -9,7 +9,7 @@ let workerPool;
|
|
|
9
9
|
// This is tested in bundler-rollup/src/writeESMStubsInWorker.test.ts so we can
|
|
10
10
|
// use the compiled version of the workerEntry file.
|
|
11
11
|
export async function writeESMStubsInWorker(options) {
|
|
12
|
-
const { inputPath, entries } = options;
|
|
12
|
+
const { inputPath, entries, unsafeCjsExportNames } = options;
|
|
13
13
|
// Mapping from entry key to entry absolute path
|
|
14
14
|
const nonStubbedEntries = {};
|
|
15
15
|
// We don't want to call into the worker for packages where stubbing is clearly not needed,
|
|
@@ -50,6 +50,7 @@ export async function writeESMStubsInWorker(options) {
|
|
|
50
50
|
const stubOptions = {
|
|
51
51
|
inputPath: options.inputPath,
|
|
52
52
|
entries: entriesToMaybeStub,
|
|
53
|
+
unsafeCjsExportNames,
|
|
53
54
|
};
|
|
54
55
|
try {
|
|
55
56
|
const stubResult = await workerPool.execute({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeESMStubsInWorker.js","sourceRoot":"","sources":["../src/writeESMStubsInWorker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAGvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,IAAI,UAAkC,CAAC;AAEvC;;GAEG;AACH,+EAA+E;AAC/E,oDAAoD;AACpD,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OAAuD;IAEvD,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"writeESMStubsInWorker.js","sourceRoot":"","sources":["../src/writeESMStubsInWorker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAGvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,IAAI,UAAkC,CAAC;AAEvC;;GAEG;AACH,+EAA+E;AAC/E,oDAAoD;AACpD,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OAAuD;IAEvD,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,oBAAoB,EAAE,GAAG,OAAO,CAAC;IAE7D,gDAAgD;IAChD,MAAM,iBA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MAAM,WAAW,GAAyB;QACxC,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,OAAO,EAAE,kBAAkB;QAC3B,oBAAoB;KACrB,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC,OAAO,CAAsB;YAC/D,MAAM,EAAE,eAAe;YACvB,IAAI,EAAE,CAAC,WAAW,CAAC;SACpB,CAAC,CAAC;QAEH,iCAAiC;QACjC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;QAExD,OAAO,UAAU,CAAC;IACpB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO;YACL,UAAU,EAAE,EAAE;YACd,MAAM,EAAE;gBACN;oBACE,MAAM,EAAE,qBAAqB;oBAC7B,mEAAmE;oBACnE,IAAI,EAAG,GAAa,EAAE,KAAK,IAAK,GAAa,EAAE,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC;iBACtE;aACF;SACF,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,qBAAqB;IACzC,MAAM,UAAU,EAAE,OAAO,EAAE,CAAC;IAC5B,UAAU,GAAG,SAAS,CAAC;AACzB,CAAC","sourcesContent":["import { getAdjustedTimeout } from '@ms-cloudpack/environment';\nimport { WorkerPool } from '@ms-cloudpack/worker-pool';\nimport type { WriteESMStubsOptions } from './types/WriteESMStubsOptions.js';\nimport type { WriteESMStubsResult } from './types/WriteESMStubsResult.js';\nimport { supportedExtensions } from './supportedExtensions.js';\nimport path from 'path';\n\nlet workerPool: WorkerPool | undefined;\n\n/**\n * Write ESM stubs using a worker pool.\n */\n// This is tested in bundler-rollup/src/writeESMStubsInWorker.test.ts so we can\n// use the compiled version of the workerEntry file.\nexport async function writeESMStubsInWorker(\n options: WriteESMStubsOptions & { maxWorkers?: number },\n): Promise<WriteESMStubsResult> {\n const { inputPath, entries, unsafeCjsExportNames } = options;\n\n // Mapping from entry key to entry absolute path\n const nonStubbedEntries: WriteESMStubsResult['newEntries'] = {};\n\n // We don't want to call into the worker for packages where stubbing is clearly not needed,\n // such as packages with only TS entries. So filter the entries by whether they potentially\n // need to be stubbed.\n const entriesToMaybeStub: Record<string, string> = {};\n\n for (const [entryKey, entryPath] of Object.entries(entries)) {\n const ext = path.extname(entryPath).toLowerCase();\n if (supportedExtensions.includes(ext)) {\n entriesToMaybeStub[entryKey] = entryPath;\n } else {\n nonStubbedEntries[entryKey] = path.join(inputPath, entryPath);\n }\n }\n\n if (!Object.keys(entriesToMaybeStub).length) {\n // Return early if there's nothing to stub\n return { newEntries: nonStubbedEntries, errors: [] };\n }\n\n workerPool ??= new WorkerPool({\n name: 'ESM stub generation',\n parentPath: import.meta.url,\n entryPath: './worker/workerEntry',\n maxWorkers: options.maxWorkers || 5,\n // Stop inactive workers after 5 minutes. This is intended to prevent one possible cause of\n // OOM crashes if cloudpack start is left running for a long time (though it's much more likely\n // that the issue is caused by servers or file watchers). The timeout is conservative because\n // the fake browser environment has nontrivial startup time, so killing workers too quickly\n // could slow down rebuilds.\n inactiveTimeout: 5 * 60 * 1000,\n // Most stubs seem to stay well under this size, and Node appears to be decent about freeing\n // memory after writeESMStubs finishes, but this will catch anything giant or leaky.\n // (This is only checked after task completion, so a package exceeding it will still be stubbed.)\n maxHeapSize: 500 * 1024 * 1024,\n // console.warn if a stub takes longer than this\n warnAboveTime: getAdjustedTimeout(2000),\n });\n\n const stubOptions: WriteESMStubsOptions = {\n inputPath: options.inputPath,\n entries: entriesToMaybeStub,\n unsafeCjsExportNames,\n };\n\n try {\n const stubResult = await workerPool.execute<WriteESMStubsResult>({\n method: 'writeESMStubs',\n args: [stubOptions],\n });\n\n // Add in any non-stubbed entries\n Object.assign(stubResult.newEntries, nonStubbedEntries);\n\n return stubResult;\n } catch (err) {\n return {\n newEntries: {},\n errors: [\n {\n source: 'ESM stub generation',\n // note: err won't be an instance of Error because of serialization\n text: (err as Error)?.stack || (err as Error)?.message || String(err),\n },\n ],\n };\n }\n}\n\nexport async function disposeStubWorkerPool(): Promise<void> {\n await workerPool?.dispose();\n workerPool = undefined;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/esm-stub-utilities",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Generates ESM stubs for CommonJS entry files.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/common-types": "^0.
|
|
17
|
+
"@ms-cloudpack/common-types": "^0.24.0",
|
|
18
18
|
"@ms-cloudpack/environment": "^0.1.1",
|
|
19
|
-
"@ms-cloudpack/json-utilities": "^0.1.
|
|
20
|
-
"@ms-cloudpack/package-utilities": "^11.0
|
|
19
|
+
"@ms-cloudpack/json-utilities": "^0.1.10",
|
|
20
|
+
"@ms-cloudpack/package-utilities": "^11.1.0",
|
|
21
21
|
"@ms-cloudpack/path-string-parsing": "^1.2.6",
|
|
22
22
|
"@ms-cloudpack/worker-pool": "^0.3.2",
|
|
23
23
|
"jsdom": "^24.0.0",
|