@ms-cloudpack/esm-stub-utilities 0.13.21 → 0.13.23
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/generateESMStubFromExports.d.ts.map +1 -1
- package/lib/generateESMStubFromExports.js.map +1 -1
- package/lib/getStubPath.d.ts +2 -5
- package/lib/getStubPath.d.ts.map +1 -1
- package/lib/getStubPath.js +7 -7
- package/lib/getStubPath.js.map +1 -1
- package/lib/isValidIdentifierName.d.ts.map +1 -1
- package/lib/isValidIdentifierName.js.map +1 -1
- package/lib/supportedExtensions.d.ts +7 -0
- package/lib/supportedExtensions.d.ts.map +1 -0
- package/lib/supportedExtensions.js +7 -0
- package/lib/supportedExtensions.js.map +1 -0
- package/lib/types/WriteESMStubsOptions.d.ts +1 -4
- package/lib/types/WriteESMStubsOptions.d.ts.map +1 -1
- package/lib/types/WriteESMStubsOptions.js.map +1 -1
- package/lib/verifyStub/verifyStub.js.map +1 -1
- package/lib/writeESMStubs.js +2 -2
- package/lib/writeESMStubs.js.map +1 -1
- package/lib/writeESMStubsInWorker.d.ts.map +1 -1
- package/lib/writeESMStubsInWorker.js +31 -9
- package/lib/writeESMStubsInWorker.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateESMStubFromExports.d.ts","sourceRoot":"","sources":["../src/generateESMStubFromExports.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE;IAAE,eAAe,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,cAAc,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"generateESMStubFromExports.d.ts","sourceRoot":"","sources":["../src/generateESMStubFromExports.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE;;;GAG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AC;QACxB,IAAI,CAAC,IAAI,CAAC,WAAW,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IACpE,CAAC;IAED,IAAI,gBAAgB,EAAE,CAAC;QACrB,IAAI,CAAC,IAAI,CACP,kFAAkF,EAClF,+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 { isValidIdentifierName } from './isValidIdentifierName.js';\nimport type { StubExportInfo } from './types/StubExportInfo.js';\n\n/**\n * Given export info and the import statement, generates the esm stub content.\n * The import statement must have moduleExport as the imported value.\n */\nexport function generateESMStubFromExports(options: { importStatement: string; export: StubExportInfo }) {\n const { export: exports, importStatement } = options;\n const exportType = exports.type;\n\n if (exportType === 'none') {\n // No exports. Just import the module.\n return importStatement;\n }\n\n // importStatement must have moduleExport as the imported value.\n // This is not the best way to check this, but it's the best we can do without parsing the code.\n if (!importStatement.includes('moduleExport')) {\n throw new Error('importStatement must have moduleExport');\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 [importStatement, `export default moduleExport;`].join('\\n');\n }\n\n // Object or function. Export both named properties (if any, and filtering keywords) and a default.\n const namedExports = exports.keys.filter((name) => isValidIdentifierName(name));\n const hasDefaultExport = exports.keys.includes('default');\n const stub = [importStatement];\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":"generateESMStubFromExports.js","sourceRoot":"","sources":["../src/generateESMStubFromExports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAGnE;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CAAC,OAA4D;IACrG,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IACrD,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAEhC,IAAI,UAAU,KAAK,MAAM,EAAE,CAAC;QAC1B,sCAAsC;QACtC,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,gEAAgE;IAChE,gGAAgG;IAChG,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IAED,IAAI,UAAU,KAAK,OAAO,EAAE,CAAC;QAC3B,wDAAwD;QACxD,sFAAsF;QACtF,6FAA6F;QAC7F,iDAAiD;QACjD,OAAO,CAAC,eAAe,EAAE,8BAA8B,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtE,CAAC;IAED,mGAAmG;IACnG,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,CAAC;IAChF,MAAM,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC1D,MAAM,IAAI,GAAG,CAAC,eAAe,CAAC,CAAC;IAE/B,IAAI,YAAY,CAAC,MAAM,EAAE,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC,WAAW,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IACpE,CAAC;IAED,IAAI,gBAAgB,EAAE,CAAC;QACrB,IAAI,CAAC,IAAI,CACP,kFAAkF,EAClF,+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 { isValidIdentifierName } from './isValidIdentifierName.js';\nimport type { StubExportInfo } from './types/StubExportInfo.js';\n\n/**\n * Given export info and the import statement, generates the esm stub content.\n * The import statement must have moduleExport as the imported value.\n */\nexport function generateESMStubFromExports(options: { importStatement: string; export: StubExportInfo }): string {\n const { export: exports, importStatement } = options;\n const exportType = exports.type;\n\n if (exportType === 'none') {\n // No exports. Just import the module.\n return importStatement;\n }\n\n // importStatement must have moduleExport as the imported value.\n // This is not the best way to check this, but it's the best we can do without parsing the code.\n if (!importStatement.includes('moduleExport')) {\n throw new Error('importStatement must have moduleExport');\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 [importStatement, `export default moduleExport;`].join('\\n');\n }\n\n // Object or function. Export both named properties (if any, and filtering keywords) and a default.\n const namedExports = exports.keys.filter((name) => isValidIdentifierName(name));\n const hasDefaultExport = exports.keys.includes('default');\n const stub = [importStatement];\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/getStubPath.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import type { WriteESMStubsOptions } from './types/WriteESMStubsOptions.js';
|
|
2
2
|
/**
|
|
3
3
|
* Given an (absolute) inputPath and (relative) entryPath, returns an absolute stub path
|
|
4
4
|
* if a stub should indeed be generated for the entry. Otherwise returns undefined.
|
|
5
5
|
*/
|
|
6
|
-
export declare function getStubPath(options: {
|
|
7
|
-
inputPath: string;
|
|
6
|
+
export declare function getStubPath(options: Pick<WriteESMStubsOptions, 'inputPath'> & {
|
|
8
7
|
entryPath: string;
|
|
9
|
-
/** Assume the entry is CJS (for testing only) */
|
|
10
|
-
forceCJS?: boolean;
|
|
11
8
|
}): Promise<string | undefined>;
|
|
12
9
|
//# sourceMappingURL=getStubPath.d.ts.map
|
package/lib/getStubPath.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getStubPath.d.ts","sourceRoot":"","sources":["../src/getStubPath.ts"],"names":[],"mappings":"AAKA,
|
|
1
|
+
{"version":3,"file":"getStubPath.d.ts","sourceRoot":"","sources":["../src/getStubPath.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAE5E;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,IAAI,CAAC,oBAAoB,EAAE,WAAW,CAAC,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GACvE,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAqB7B"}
|
package/lib/getStubPath.js
CHANGED
|
@@ -2,19 +2,19 @@ import path from 'path';
|
|
|
2
2
|
import { mkdir } from 'fs/promises';
|
|
3
3
|
import { detectModuleType } from '@ms-cloudpack/package-utilities';
|
|
4
4
|
import { slash } from '@ms-cloudpack/path-string-parsing';
|
|
5
|
-
|
|
5
|
+
import { supportedCjsExtensions, supportedOtherExtensions } from './supportedExtensions.js';
|
|
6
6
|
/**
|
|
7
7
|
* Given an (absolute) inputPath and (relative) entryPath, returns an absolute stub path
|
|
8
8
|
* if a stub should indeed be generated for the entry. Otherwise returns undefined.
|
|
9
9
|
*/
|
|
10
10
|
export async function getStubPath(options) {
|
|
11
|
-
const { inputPath, entryPath
|
|
11
|
+
const { inputPath, entryPath } = options;
|
|
12
12
|
const ext = path.extname(entryPath).toLowerCase();
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const stubFilename = path.basename(entryPath,
|
|
13
|
+
const isMaybeCjs = supportedCjsExtensions.includes(ext);
|
|
14
|
+
if (supportedOtherExtensions.includes(ext) ||
|
|
15
|
+
// detectModuleType will only parse the module if it's .js (ambiguous)
|
|
16
|
+
(isMaybeCjs && (await detectModuleType(path.resolve(inputPath, entryPath))) === 'cjs')) {
|
|
17
|
+
const stubFilename = path.basename(entryPath, isMaybeCjs ? ext : undefined) + '-stub.mjs';
|
|
18
18
|
const stubRelativePath = path.dirname(entryPath);
|
|
19
19
|
const stubFolderPath = path.resolve(inputPath, './node_modules/.cache/cloudpack-stubs/', stubRelativePath);
|
|
20
20
|
await mkdir(stubFolderPath, { recursive: true });
|
package/lib/getStubPath.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getStubPath.js","sourceRoot":"","sources":["../src/getStubPath.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAA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,CAAC,CAAC;QAEjD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import path from 'path';\nimport { mkdir } from 'fs/promises';\nimport { detectModuleType } from '@ms-cloudpack/package-utilities';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { supportedCjsExtensions, supportedOtherExtensions } from './supportedExtensions.js';\nimport type { WriteESMStubsOptions } from './types/WriteESMStubsOptions.js';\n\n/**\n * Given an (absolute) inputPath and (relative) entryPath, returns an absolute stub path\n * if a stub should indeed be generated for the entry. Otherwise returns undefined.\n */\nexport async function getStubPath(\n options: Pick<WriteESMStubsOptions, 'inputPath'> & { entryPath: string },\n): Promise<string | undefined> {\n const { inputPath, entryPath } = options;\n\n const ext = path.extname(entryPath).toLowerCase();\n const isMaybeCjs = supportedCjsExtensions.includes(ext);\n\n if (\n supportedOtherExtensions.includes(ext) ||\n // detectModuleType will only parse the module if it's .js (ambiguous)\n (isMaybeCjs && (await detectModuleType(path.resolve(inputPath, entryPath))) === 'cjs')\n ) {\n const stubFilename = path.basename(entryPath, isMaybeCjs ? ext : undefined) + '-stub.mjs';\n const stubRelativePath = path.dirname(entryPath);\n const stubFolderPath = path.resolve(inputPath, './node_modules/.cache/cloudpack-stubs/', stubRelativePath);\n\n await mkdir(stubFolderPath, { recursive: true });\n\n return slash(path.join(stubFolderPath, stubFilename));\n }\n\n return undefined;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isValidIdentifierName.d.ts","sourceRoot":"","sources":["../src/isValidIdentifierName.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,eAAO,MAAM,oBAAoB,UAiDhC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"isValidIdentifierName.d.ts","sourceRoot":"","sources":["../src/isValidIdentifierName.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,eAAO,MAAM,oBAAoB,UAiDhC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isValidIdentifierName.js","sourceRoot":"","sources":["../src/isValidIdentifierName.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,yEAAyE;AACzE,MAAM,iBAAiB,GAAG,4BAA4B,CAAC;AAEvD;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,WAAW;IACX,OAAO;IACP,OAAO;IACP,MAAM;IACN,OAAO;IACP,OAAO;IACP,OAAO;IACP,UAAU;IACV,UAAU;IACV,SAAS;IACT,QAAQ;IACR,IAAI;IACJ,MAAM;IACN,MAAM;IACN,MAAM;IACN,QAAQ;IACR,SAAS;IACT,OAAO;IACP,SAAS;IACT,KAAK;IACL,UAAU;IACV,IAAI;IACJ,YAAY;IACZ,QAAQ;IACR,IAAI;IACJ,YAAY;IACZ,WAAW;IACX,KAAK;IACL,KAAK;IACL,MAAM;IACN,SAAS;IACT,SAAS;IACT,WAAW;IACX,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,MAAM;IACN,OAAO;IACP,MAAM;IACN,KAAK;IACL,QAAQ;IACR,KAAK;IACL,MAAM;IACN,OAAO;IACP,MAAM;IACN,OAAO;CACR,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,OAAO,CAAC,oBAAoB,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC9E,CAAC","sourcesContent":["// A valid variable name must start with a letter, underscore, or dollar sign,\n// and can be followed by letters, numbers, underscores, or dollar signs.\nconst variableNameRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;\n\n/**\n * Lists all export names which create problems with esm output.\n * Mostly this includes the JavaScript keywords, minus \"default\".\n */\nexport const forbiddenExportNames = [\n 'arguments',\n 'await',\n 'break',\n 'case',\n 'catch',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'finally',\n 'for',\n 'function',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'interface',\n 'let',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'static',\n 'super',\n 'switch',\n 'this',\n 'throw',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'while',\n 'with',\n 'yield',\n];\n\n/**\n * Checks if a string is a valid identifier name according to ECMASCript specs,\n * and is not one of the forbidden identifier names.\n * https://262.ecma-international.org/13.0/#sec-names-and-keywords\n * @param name - Identifier to check\n * @returns True if the string is a valid identifier name, false otherwise.\n */\nexport function isValidIdentifierName(name: string) {\n return !forbiddenExportNames.includes(name) && variableNameRegex.test(name);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"isValidIdentifierName.js","sourceRoot":"","sources":["../src/isValidIdentifierName.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,yEAAyE;AACzE,MAAM,iBAAiB,GAAG,4BAA4B,CAAC;AAEvD;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,WAAW;IACX,OAAO;IACP,OAAO;IACP,MAAM;IACN,OAAO;IACP,OAAO;IACP,OAAO;IACP,UAAU;IACV,UAAU;IACV,SAAS;IACT,QAAQ;IACR,IAAI;IACJ,MAAM;IACN,MAAM;IACN,MAAM;IACN,QAAQ;IACR,SAAS;IACT,OAAO;IACP,SAAS;IACT,KAAK;IACL,UAAU;IACV,IAAI;IACJ,YAAY;IACZ,QAAQ;IACR,IAAI;IACJ,YAAY;IACZ,WAAW;IACX,KAAK;IACL,KAAK;IACL,MAAM;IACN,SAAS;IACT,SAAS;IACT,WAAW;IACX,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,MAAM;IACN,OAAO;IACP,MAAM;IACN,KAAK;IACL,QAAQ;IACR,KAAK;IACL,MAAM;IACN,OAAO;IACP,MAAM;IACN,OAAO;CACR,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,OAAO,CAAC,oBAAoB,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC9E,CAAC","sourcesContent":["// A valid variable name must start with a letter, underscore, or dollar sign,\n// and can be followed by letters, numbers, underscores, or dollar signs.\nconst variableNameRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;\n\n/**\n * Lists all export names which create problems with esm output.\n * Mostly this includes the JavaScript keywords, minus \"default\".\n */\nexport const forbiddenExportNames = [\n 'arguments',\n 'await',\n 'break',\n 'case',\n 'catch',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'finally',\n 'for',\n 'function',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'interface',\n 'let',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'static',\n 'super',\n 'switch',\n 'this',\n 'throw',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'while',\n 'with',\n 'yield',\n];\n\n/**\n * Checks if a string is a valid identifier name according to ECMASCript specs,\n * and is not one of the forbidden identifier names.\n * https://262.ecma-international.org/13.0/#sec-names-and-keywords\n * @param name - Identifier to check\n * @returns True if the string is a valid identifier name, false otherwise.\n */\nexport function isValidIdentifierName(name: string): boolean {\n return !forbiddenExportNames.includes(name) && variableNameRegex.test(name);\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** CJS or maybe-CJS extensions supported for stubbing (js, cjs) */
|
|
2
|
+
export declare const supportedCjsExtensions: string[];
|
|
3
|
+
/** Other supported extensions for stubbing (json) */
|
|
4
|
+
export declare const supportedOtherExtensions: string[];
|
|
5
|
+
/** All extensions potentially supported for stubbing (js, cjs, json) */
|
|
6
|
+
export declare const supportedExtensions: string[];
|
|
7
|
+
//# sourceMappingURL=supportedExtensions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supportedExtensions.d.ts","sourceRoot":"","sources":["../src/supportedExtensions.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,eAAO,MAAM,sBAAsB,UAAkB,CAAC;AAEtD,qDAAqD;AACrD,eAAO,MAAM,wBAAwB,UAAY,CAAC;AAElD,wEAAwE;AACxE,eAAO,MAAM,mBAAmB,UAA2D,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** CJS or maybe-CJS extensions supported for stubbing (js, cjs) */
|
|
2
|
+
export const supportedCjsExtensions = ['.js', '.cjs'];
|
|
3
|
+
/** Other supported extensions for stubbing (json) */
|
|
4
|
+
export const supportedOtherExtensions = ['.json'];
|
|
5
|
+
/** All extensions potentially supported for stubbing (js, cjs, json) */
|
|
6
|
+
export const supportedExtensions = [...supportedCjsExtensions, ...supportedOtherExtensions];
|
|
7
|
+
//# sourceMappingURL=supportedExtensions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supportedExtensions.js","sourceRoot":"","sources":["../src/supportedExtensions.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAEtD,qDAAqD;AACrD,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,OAAO,CAAC,CAAC;AAElD,wEAAwE;AACxE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,GAAG,sBAAsB,EAAE,GAAG,wBAAwB,CAAC,CAAC","sourcesContent":["/** CJS or maybe-CJS extensions supported for stubbing (js, cjs) */\nexport const supportedCjsExtensions = ['.js', '.cjs'];\n\n/** Other supported extensions for stubbing (json) */\nexport const supportedOtherExtensions = ['.json'];\n\n/** All extensions potentially supported for stubbing (js, cjs, json) */\nexport const supportedExtensions = [...supportedCjsExtensions, ...supportedOtherExtensions];\n"]}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
import type { BundleOptions } from '@ms-cloudpack/common-types';
|
|
2
|
-
export type WriteESMStubsOptions = Pick<BundleOptions, 'inputPath' | 'entries'
|
|
3
|
-
/** Assume entries are CJS (for testing). */
|
|
4
|
-
forceCJS?: boolean;
|
|
5
|
-
};
|
|
2
|
+
export type WriteESMStubsOptions = Pick<BundleOptions, 'inputPath' | 'entries'>;
|
|
6
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,
|
|
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 +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'
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifyStub.js","sourceRoot":"","sources":["../../src/verifyStub/verifyStub.ts"],"names":[],"mappings":"AAAA,EAAE;AACF,EAAE;AACF,8FAA8F;AAC9F,qDAAqD;AACrD,EAAE;AACF,gDAAgD;AAChD,qFAAqF;AACrF,oEAAoE;AACpE,0EAA0E;AAC1E,EAAE;AACF,EAAE;AAEF,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAIxC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC7D,MAAM,kBAAkB,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;AAEnE,IAAI,MAA0B,CAAC;AAE/B;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAA2B;IAW3D,0DAA0D;IAC1D,MAAM,aAAa,CAAC,OAAO,CAAC,CAAC;IAE7B,qCAAqC;IACrC,MAAM,GAAG,YAAY,EAAE,CAAC;IACxB,MAAM,iBAAiB,GAA0B;QAC/C,QAAQ,EAAE,iBAAiB,CAAC,OAAO,CAAC,QAAQ,CAAC;QAC7C,QAAQ,EAAE,OAAO,CAAC,QA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S,CAAC;IACrB,CAAC;AACH,CAAC","sourcesContent":["//\n//\n// The utilities in this folder are used to verify that a generated stub file can be imported,\n// and that the results of importing are as expected.\n//\n// Why must the stub file be loaded in a worker?\n// - Ensure that the module is imported in a \"vanilla\" way, without interference from\n// Jest's transpilation, custom module resolution, or environment.\n// - Allow the module to run in a simulated browser environment if needed.\n//\n//\n\nimport fs from 'fs/promises';\nimport path from 'path';\nimport { fileURLToPath, pathToFileURL } from 'url';\nimport { Worker } from 'worker_threads';\nimport type { _VerifyStubOptions } from '../types/VerifyStubOptions.js';\nimport type { LoadStubWorkerRequest, LoadStubWorkerResponse } from './loadStubWorker.js';\n\nconst dirname = path.dirname(fileURLToPath(import.meta.url));\nconst loadStubWorkerPath = path.join(dirname, 'loadStubWorker.js');\n\nlet worker: Worker | undefined;\n\n/**\n * FOR TESTING ONLY:\n * Write a stub file (fixing paths for Windows) and try importing it in a worker,\n * to verify that it's valid and returns the expected exports.\n * @internal\n */\nexport async function _verifyStub(options: _VerifyStubOptions): Promise<{\n /**\n * The result of importing the stub in the worker (if successful), in IPC-friendly format.\n * Any non-IPC-friendly values (such as functions) will be pretty-printed as strings.\n */\n value?: unknown;\n /** Error if unsuccessful. */\n error?: unknown;\n /** Dispose the worker. Unless/until this is called, the same worker will be reused. */\n dispose: () => Promise<void>;\n}> {\n // Write the stub content to disk (fixing paths if needed)\n await writeStubFile(options);\n\n // Try to import the stub in a worker\n worker = ensureWorker();\n const stubImportRequest: LoadStubWorkerRequest = {\n stubPath: getStubImportPath(options.stubPath),\n testCode: options.testCode,\n };\n\n return new Promise((resolve) => {\n const onMessage = (response: LoadStubWorkerResponse) => {\n worker?.off('error', onError);\n resolve({ ...response, dispose: disposeWorker });\n };\n // unhandled exception (not expected)\n const onError = (err: Error) => {\n worker?.off('message', onMessage);\n resolve({ error: err, dispose: disposeWorker });\n };\n worker?.once('message', onMessage);\n worker?.once('error', onError);\n\n worker?.postMessage(stubImportRequest);\n });\n}\n\nasync function writeStubFile(options: _VerifyStubOptions) {\n // Fix the stub content on Windows...\n let stub = options.stub;\n if (process.platform === 'win32') {\n // Node only supports Windows absolute paths as file:// URLs.\n // Unfortunately, the bundlers don't like this syntax, so we don't put it in the stub by default.\n // Convert any absolute paths here so that the worker is able to natively import the stub.\n stub = stub.replace(/(?:from|import) \"([^\"]*?)\";/g, (match, importPath: string) => {\n if (path.isAbsolute(importPath)) {\n return match.replace(importPath, pathToFileURL(importPath).href);\n }\n return match;\n });\n }\n\n // Write the stub file\n await fs.writeFile(options.stubPath, stub);\n}\n\n/** Get a stub import path that works for the current platform. */\nfunction getStubImportPath(stubPath: string): string {\n if (process.platform === 'win32' && path.isAbsolute(stubPath)) {\n // Convert the path to a file:// URL so the import works on Windows\n return pathToFileURL(stubPath).href;\n }\n return stubPath;\n}\n\n/**\n * Initialize the worker used by `verifyStub`. For testing only.\n *\n * (The worker is reused between tests for now because it's expensive to set up and tear down;\n * this can be changed later for certain tests if needed.)\n */\nfunction ensureWorker(): Worker {\n if (worker) return worker;\n\n worker = new Worker(loadStubWorkerPath);\n\n // An 'error' event from a worker means an unhandled exception and it's about to exit.\n // Don't throw an error in this fallback handler in case the error occurred during a call\n // to `verifyStub` (which has its own error handler that can fail the calling test),\n // but save the error to be included in the 'exit' handler's error message.\n let lastError: Error | undefined;\n worker.on('error', (err) => {\n lastError = err;\n });\n worker.on('exit', (code) => {\n throw new Error(\n lastError\n ? `Worker exited due to an uncaught exception: ${lastError.stack}`\n : `Worker exited unexpectedly with code ${code || 0}`,\n );\n });\n\n return worker;\n}\n\n/**\n * Stop the worker used by `verifyStub`.\n */\nasync function disposeWorker() {\n if (worker) {\n // Remove all listeners so that the exit handler set up during initialization doesn't throw\n worker.removeAllListeners();\n try {\n await worker.terminate();\n } catch {\n // ignore\n }\n worker = undefined;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"verifyStub.js","sourceRoot":"","sources":["../../src/verifyStub/verifyStub.ts"],"names":[],"mappings":"AAAA,EAAE;AACF,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Y;IACnB,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAE1B,MAAM,GAAG,IAAI,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAExC,sFAAsF;IACtF,yFAAyF;IACzF,oFAAoF;IACpF,2EAA2E;IAC3E,IAAI,SAA4B,CAAC;IACjC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;QACzB,SAAS,GAAG,GAAG,CAAC;IAClB,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;QACzB,MAAM,IAAI,KAAK,CACb,SAAS;YACP,CAAC,CAAC,+CAA+C,SAAS,CAAC,KAAK,EAAE;YAClE,CAAC,CAAC,wCAAwC,IAAI,IAAI,CAAC,EAAE,CACxD,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,aAAa;IAC1B,IAAI,MAAM,EAAE,CAAC;QACX,2FAA2F;QAC3F,MAAM,CAAC,kBAAkB,EAAE,CAAC;QAC5B,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,SAAS,EAAE,CAAC;QAC3B,CAAC;QAAC,MAAM,CAAC;YACP,SAAS;QACX,CAAC;QACD,MAAM,GAAG,SAAS,CAAC;IACrB,CAAC;AACH,CAAC","sourcesContent":["//\n//\n// The utilities in this folder are used to verify that a generated stub file can be imported,\n// and that the results of importing are as expected.\n//\n// Why must the stub file be loaded in a worker?\n// - Ensure that the module is imported in a \"vanilla\" way, without interference from\n// Jest's transpilation, custom module resolution, or environment.\n// - Allow the module to run in a simulated browser environment if needed.\n//\n//\n\nimport fs from 'fs/promises';\nimport path from 'path';\nimport { fileURLToPath, pathToFileURL } from 'url';\nimport { Worker } from 'worker_threads';\nimport type { _VerifyStubOptions } from '../types/VerifyStubOptions.js';\nimport type { LoadStubWorkerRequest, LoadStubWorkerResponse } from './loadStubWorker.js';\n\nconst dirname = path.dirname(fileURLToPath(import.meta.url));\nconst loadStubWorkerPath = path.join(dirname, 'loadStubWorker.js');\n\nlet worker: Worker | undefined;\n\n/**\n * FOR TESTING ONLY:\n * Write a stub file (fixing paths for Windows) and try importing it in a worker,\n * to verify that it's valid and returns the expected exports.\n * @internal\n */\nexport async function _verifyStub(options: _VerifyStubOptions): Promise<{\n /**\n * The result of importing the stub in the worker (if successful), in IPC-friendly format.\n * Any non-IPC-friendly values (such as functions) will be pretty-printed as strings.\n */\n value?: unknown;\n /** Error if unsuccessful. */\n error?: unknown;\n /** Dispose the worker. Unless/until this is called, the same worker will be reused. */\n dispose: () => Promise<void>;\n}> {\n // Write the stub content to disk (fixing paths if needed)\n await writeStubFile(options);\n\n // Try to import the stub in a worker\n worker = ensureWorker();\n const stubImportRequest: LoadStubWorkerRequest = {\n stubPath: getStubImportPath(options.stubPath),\n testCode: options.testCode,\n };\n\n return new Promise((resolve) => {\n const onMessage = (response: LoadStubWorkerResponse) => {\n worker?.off('error', onError);\n resolve({ ...response, dispose: disposeWorker });\n };\n // unhandled exception (not expected)\n const onError = (err: Error) => {\n worker?.off('message', onMessage);\n resolve({ error: err, dispose: disposeWorker });\n };\n worker?.once('message', onMessage);\n worker?.once('error', onError);\n\n worker?.postMessage(stubImportRequest);\n });\n}\n\nasync function writeStubFile(options: _VerifyStubOptions): Promise<void> {\n // Fix the stub content on Windows...\n let stub = options.stub;\n if (process.platform === 'win32') {\n // Node only supports Windows absolute paths as file:// URLs.\n // Unfortunately, the bundlers don't like this syntax, so we don't put it in the stub by default.\n // Convert any absolute paths here so that the worker is able to natively import the stub.\n stub = stub.replace(/(?:from|import) \"([^\"]*?)\";/g, (match, importPath: string) => {\n if (path.isAbsolute(importPath)) {\n return match.replace(importPath, pathToFileURL(importPath).href);\n }\n return match;\n });\n }\n\n // Write the stub file\n await fs.writeFile(options.stubPath, stub);\n}\n\n/** Get a stub import path that works for the current platform. */\nfunction getStubImportPath(stubPath: string): string {\n if (process.platform === 'win32' && path.isAbsolute(stubPath)) {\n // Convert the path to a file:// URL so the import works on Windows\n return pathToFileURL(stubPath).href;\n }\n return stubPath;\n}\n\n/**\n * Initialize the worker used by `verifyStub`. For testing only.\n *\n * (The worker is reused between tests for now because it's expensive to set up and tear down;\n * this can be changed later for certain tests if needed.)\n */\nfunction ensureWorker(): Worker {\n if (worker) return worker;\n\n worker = new Worker(loadStubWorkerPath);\n\n // An 'error' event from a worker means an unhandled exception and it's about to exit.\n // Don't throw an error in this fallback handler in case the error occurred during a call\n // to `verifyStub` (which has its own error handler that can fail the calling test),\n // but save the error to be included in the 'exit' handler's error message.\n let lastError: Error | undefined;\n worker.on('error', (err) => {\n lastError = err;\n });\n worker.on('exit', (code) => {\n throw new Error(\n lastError\n ? `Worker exited due to an uncaught exception: ${lastError.stack}`\n : `Worker exited unexpectedly with code ${code || 0}`,\n );\n });\n\n return worker;\n}\n\n/**\n * Stop the worker used by `verifyStub`.\n */\nasync function disposeWorker(): Promise<void> {\n if (worker) {\n // Remove all listeners so that the exit handler set up during initialization doesn't throw\n worker.removeAllListeners();\n try {\n await worker.terminate();\n } catch {\n // ignore\n }\n worker = undefined;\n }\n}\n"]}
|
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
|
|
13
|
+
const { inputPath, entries } = options;
|
|
14
14
|
const result = {
|
|
15
15
|
newEntries: {},
|
|
16
16
|
errors: [],
|
|
@@ -19,7 +19,7 @@ export async function writeESMStubs(options) {
|
|
|
19
19
|
const filePath = slash(path.join(inputPath, entryPath));
|
|
20
20
|
const entryFullPath = path.join(inputPath, entryPath);
|
|
21
21
|
try {
|
|
22
|
-
const stubPath = await getStubPath({ inputPath, entryPath
|
|
22
|
+
const stubPath = await getStubPath({ inputPath, entryPath });
|
|
23
23
|
if (!stubPath) {
|
|
24
24
|
// Stub not needed
|
|
25
25
|
result.newEntries[entryKey] = entryFullPath;
|
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,
|
|
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;IACvC,MAAM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AAC;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 } = 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 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[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;
|
|
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,CAuE9B;AAED,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC,CAG3D"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getAdjustedTimeout } from '@ms-cloudpack/environment';
|
|
2
2
|
import { WorkerPool } from '@ms-cloudpack/worker-pool';
|
|
3
|
+
import { supportedExtensions } from './supportedExtensions.js';
|
|
4
|
+
import path from 'path';
|
|
3
5
|
let workerPool;
|
|
4
6
|
/**
|
|
5
7
|
* Write ESM stubs using a worker pool.
|
|
@@ -7,13 +9,26 @@ let workerPool;
|
|
|
7
9
|
// This is tested in bundler-rollup/src/writeESMStubsInWorker.test.ts so we can
|
|
8
10
|
// use the compiled version of the workerEntry file.
|
|
9
11
|
export async function writeESMStubsInWorker(options) {
|
|
10
|
-
|
|
11
|
-
//
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
12
|
+
const { inputPath, entries } = options;
|
|
13
|
+
// Mapping from entry key to entry absolute path
|
|
14
|
+
const nonStubbedEntries = {};
|
|
15
|
+
// We don't want to call into the worker for packages where stubbing is clearly not needed,
|
|
16
|
+
// such as packages with only TS entries. So filter the entries by whether they potentially
|
|
17
|
+
// need to be stubbed.
|
|
18
|
+
const entriesToMaybeStub = {};
|
|
19
|
+
for (const [entryKey, entryPath] of Object.entries(entries)) {
|
|
20
|
+
const ext = path.extname(entryPath).toLowerCase();
|
|
21
|
+
if (supportedExtensions.includes(ext)) {
|
|
22
|
+
entriesToMaybeStub[entryKey] = entryPath;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
nonStubbedEntries[entryKey] = path.join(inputPath, entryPath);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (!Object.keys(entriesToMaybeStub).length) {
|
|
29
|
+
// Return early if there's nothing to stub
|
|
30
|
+
return { newEntries: nonStubbedEntries, errors: [] };
|
|
31
|
+
}
|
|
17
32
|
workerPool ??= new WorkerPool({
|
|
18
33
|
name: 'ESM stub generation',
|
|
19
34
|
parentPath: import.meta.url,
|
|
@@ -32,11 +47,18 @@ export async function writeESMStubsInWorker(options) {
|
|
|
32
47
|
// console.warn if a stub takes longer than this
|
|
33
48
|
warnAboveTime: getAdjustedTimeout(2000),
|
|
34
49
|
});
|
|
50
|
+
const stubOptions = {
|
|
51
|
+
inputPath: options.inputPath,
|
|
52
|
+
entries: entriesToMaybeStub,
|
|
53
|
+
};
|
|
35
54
|
try {
|
|
36
|
-
|
|
55
|
+
const stubResult = await workerPool.execute({
|
|
37
56
|
method: 'writeESMStubs',
|
|
38
|
-
args: [
|
|
57
|
+
args: [stubOptions],
|
|
39
58
|
});
|
|
59
|
+
// Add in any non-stubbed entries
|
|
60
|
+
Object.assign(stubResult.newEntries, nonStubbedEntries);
|
|
61
|
+
return stubResult;
|
|
40
62
|
}
|
|
41
63
|
catch (err) {
|
|
42
64
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeESMStubsInWorker.js","sourceRoot":"","sources":["../src/writeESMStub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E;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 } = 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 };\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.13.
|
|
3
|
+
"version": "0.13.23",
|
|
4
4
|
"description": "Generates ESM stubs for CommonJS entry files.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"@ms-cloudpack/common-types": "^0.23.7",
|
|
18
18
|
"@ms-cloudpack/environment": "^0.1.1",
|
|
19
19
|
"@ms-cloudpack/json-utilities": "^0.1.9",
|
|
20
|
-
"@ms-cloudpack/package-utilities": "^11.0.
|
|
20
|
+
"@ms-cloudpack/package-utilities": "^11.0.1",
|
|
21
21
|
"@ms-cloudpack/path-string-parsing": "^1.2.6",
|
|
22
|
-
"@ms-cloudpack/worker-pool": "^0.3.
|
|
22
|
+
"@ms-cloudpack/worker-pool": "^0.3.2",
|
|
23
23
|
"jsdom": "^24.0.0",
|
|
24
24
|
"jsdom-global": "^3.0.2",
|
|
25
25
|
"regenerator-runtime": "^0.14.1"
|