@ms-cloudpack/esm-stub-utilities 0.6.8 → 0.6.10

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.
@@ -3,6 +3,7 @@ import { readJson } from '@ms-cloudpack/json-utilities';
3
3
  import { slash } from '@ms-cloudpack/path-string-parsing';
4
4
  import { forbiddenExportNames } from './forbiddenExportNames.js';
5
5
  import { runInSandbox } from './runInSandbox.js';
6
+ import { isValidIdentifierName } from './isValidIdentifierName.js';
6
7
  /**
7
8
  * Generates an ESM stub for CommonJS modules.
8
9
  * @param entryPath - The full path to the CommonJS entry file.
@@ -20,7 +21,7 @@ export async function createESMStub(entryPath, stubPath) {
20
21
  `const data = ${JSON.stringify(jsonData, null, 2)};`,
21
22
  'export default data;',
22
23
  ...Object.keys(jsonData)
23
- .filter((name) => !forbiddenExportNames.includes(name))
24
+ .filter((name) => !forbiddenExportNames.includes(name) && isValidIdentifierName(name))
24
25
  .map((prop) => `export const ${prop} = data.${prop};`),
25
26
  ].join('\n');
26
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"createESMStub.js","sourceRoot":"","sources":["../src/createESMStub.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,SAAiB,EAAE,QAAgB;IACrE,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,OAAO,EAAE;QACvC,uDAAuD;QACvD,0GAA0G;QAC1G,+DAA+D;QAC/D,MAAM,QAAQ,GAAG,CAAC,MAAM,QAAQ,CAAC,SAAS,C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AC;KAC9C;SAAM;QACL,iFAAiF;QACjF,MAAM,CAAC,IAAI,CAAC,WAAW,YAAY,IAAI,CAAC,CAAC;KAC1C;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import path from 'path';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { forbiddenExportNames } from './forbiddenExportNames.js';\nimport { runInSandbox } from './runInSandbox.js';\n\n/**\n * Generates an ESM stub for CommonJS modules.\n * @param entryPath - The full path to the CommonJS entry file.\n * @param stubPath - The path where the stub file will live. This is important for determining\n * relative import paths.\n * @param packageExport - The exported package.\n */\nexport async function createESMStub(entryPath: string, stubPath: string): Promise<string> {\n if (path.extname(entryPath) === '.json') {\n // It's not necessary to run JSON files in the sandbox.\n // Also, `import`-ing named keys from JSON files doesn't work, so we just inline the entire file contents.\n // (More info: https://github.com/microsoft/cloudpack/pull/880)\n const jsonData = (await readJson(entryPath)) as Record<string, unknown>;\n return [\n `const data = ${JSON.stringify(jsonData, null, 2)};`,\n 'export default data;',\n ...Object.keys(jsonData)\n .filter((name) => !forbiddenExportNames.includes(name))\n .map((prop) => `export const ${prop} = data.${prop};`),\n ].join('\\n');\n }\n\n const result = [];\n const relativePath = './' + slash(path.relative(path.dirname(stubPath), entryPath));\n\n // Run the entry point file in a sandbox to determine the exports\n const packageExport = (await runInSandbox(entryPath)) as Record<string, unknown>;\n\n const isExportObject = typeof packageExport === 'object';\n const isExportFunction = typeof packageExport === 'function';\n\n if (isExportFunction || (isExportObject && !Array.isArray(packageExport))) {\n // Make sure to filter keywords.\n const namedExports = Object.keys(packageExport).filter((name) => !forbiddenExportNames.includes(name));\n const hasDefaultExport = 'default' in packageExport;\n\n if (namedExports.length || hasDefaultExport) {\n result.push(`import ${isExportFunction ? '' : '* as '}packageExport from \"${relativePath}\";`);\n\n if (namedExports.length) {\n result.push(`const { ${namedExports.join(', ')} } = packageExport;`);\n }\n\n if (hasDefaultExport) {\n result.push(\n `const defaultExport = (packageExport && packageExport.default?.default) ? packageExport?.default.default : packageExport?.default;`,\n );\n result.push(`export default defaultExport;`);\n } else {\n result.push(`export default packageExport;`);\n }\n\n if (namedExports.length) {\n result.push(`export { ${namedExports.join(', ')} }`);\n }\n } else {\n // No named exports...\n // Object with no members? Must be a polyfill. Just import it and don't export anything.\n if (isExportFunction) {\n result.push(`export { default } from \"${relativePath}\";`);\n } else {\n result.push(`import \"${relativePath}\";`);\n }\n }\n } else if (typeof packageExport === 'boolean' || typeof packageExport === 'number') {\n // Export as default.\n result.push(`export default ${packageExport};`);\n } else if (typeof packageExport === 'string') {\n // Export a constant.\n result.push(`export default ${JSON.stringify(packageExport)};`);\n } else if (Array.isArray(packageExport)) {\n result.push(`import packageExport from \"${relativePath}\";`);\n result.push('export default packageExport;');\n } else {\n // Unable to import the module in node, or it exported undefined for some reason.\n result.push(`import \"${relativePath}\";`);\n }\n\n return result.join('\\n');\n}\n"]}
1
+ {"version":3,"file":"createESMStub.js","sourceRoot":"","sources":["../src/createESMStub.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,SAAiB,EAAE,QAAgB;IACrE,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,OAAO,EAAE;QACvC,uDAAuD;QACvD,0GAA0G;QAC1G,+DAA+D;QAC/D,MAAM,QAAQ,GAAG,CAAC,MAAM,QAAQ,CAA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,MAAM,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;KAC9C;SAAM;QACL,iFAAiF;QACjF,MAAM,CAAC,IAAI,CAAC,WAAW,YAAY,IAAI,CAAC,CAAC;KAC1C;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import path from 'path';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { forbiddenExportNames } from './forbiddenExportNames.js';\nimport { runInSandbox } from './runInSandbox.js';\nimport { isValidIdentifierName } from './isValidIdentifierName.js';\n\n/**\n * Generates an ESM stub for CommonJS modules.\n * @param entryPath - The full path to the CommonJS entry file.\n * @param stubPath - The path where the stub file will live. This is important for determining\n * relative import paths.\n * @param packageExport - The exported package.\n */\nexport async function createESMStub(entryPath: string, stubPath: string): Promise<string> {\n if (path.extname(entryPath) === '.json') {\n // It's not necessary to run JSON files in the sandbox.\n // Also, `import`-ing named keys from JSON files doesn't work, so we just inline the entire file contents.\n // (More info: https://github.com/microsoft/cloudpack/pull/880)\n const jsonData = (await readJson(entryPath)) as Record<string, unknown>;\n return [\n `const data = ${JSON.stringify(jsonData, null, 2)};`,\n 'export default data;',\n ...Object.keys(jsonData)\n .filter((name) => !forbiddenExportNames.includes(name) && isValidIdentifierName(name))\n .map((prop) => `export const ${prop} = data.${prop};`),\n ].join('\\n');\n }\n\n const result = [];\n const relativePath = './' + slash(path.relative(path.dirname(stubPath), entryPath));\n\n // Run the entry point file in a sandbox to determine the exports\n const packageExport = (await runInSandbox(entryPath)) as Record<string, unknown>;\n\n const isExportObject = typeof packageExport === 'object';\n const isExportFunction = typeof packageExport === 'function';\n\n if (isExportFunction || (isExportObject && !Array.isArray(packageExport))) {\n // Make sure to filter keywords.\n const namedExports = Object.keys(packageExport).filter((name) => !forbiddenExportNames.includes(name));\n const hasDefaultExport = 'default' in packageExport;\n\n if (namedExports.length || hasDefaultExport) {\n result.push(`import ${isExportFunction ? '' : '* as '}packageExport from \"${relativePath}\";`);\n\n if (namedExports.length) {\n result.push(`const { ${namedExports.join(', ')} } = packageExport;`);\n }\n\n if (hasDefaultExport) {\n result.push(\n `const defaultExport = (packageExport && packageExport.default?.default) ? packageExport?.default.default : packageExport?.default;`,\n );\n result.push(`export default defaultExport;`);\n } else {\n result.push(`export default packageExport;`);\n }\n\n if (namedExports.length) {\n result.push(`export { ${namedExports.join(', ')} }`);\n }\n } else {\n // No named exports...\n // Object with no members? Must be a polyfill. Just import it and don't export anything.\n if (isExportFunction) {\n result.push(`export { default } from \"${relativePath}\";`);\n } else {\n result.push(`import \"${relativePath}\";`);\n }\n }\n } else if (typeof packageExport === 'boolean' || typeof packageExport === 'number') {\n // Export as default.\n result.push(`export default ${packageExport};`);\n } else if (typeof packageExport === 'string') {\n // Export a constant.\n result.push(`export default ${JSON.stringify(packageExport)};`);\n } else if (Array.isArray(packageExport)) {\n result.push(`import packageExport from \"${relativePath}\";`);\n result.push('export default packageExport;');\n } else {\n // Unable to import the module in node, or it exported undefined for some reason.\n result.push(`import \"${relativePath}\";`);\n }\n\n return result.join('\\n');\n}\n"]}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Checks if a string is a valid identifier name according to ECMASCript specs.
3
+ * https://262.ecma-international.org/13.0/#sec-names-and-keywords
4
+ * @param name - Identifier to check
5
+ * @returns True if the string is a valid identifier name, false otherwise.
6
+ */
7
+ export declare function isValidIdentifierName(name: string): boolean;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Checks if a string is a valid identifier name according to ECMASCript specs.
3
+ * https://262.ecma-international.org/13.0/#sec-names-and-keywords
4
+ * @param name - Identifier to check
5
+ * @returns True if the string is a valid identifier name, false otherwise.
6
+ */
7
+ export function isValidIdentifierName(name) {
8
+ // A valid variable name must start with a letter, underscore, or dollar sign,
9
+ // and can be followed by letters, numbers, underscores, or dollar signs.
10
+ const variableNameRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
11
+ return variableNameRegex.test(name);
12
+ }
13
+ //# sourceMappingURL=isValidIdentifierName.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isValidIdentifierName.js","sourceRoot":"","sources":["../src/isValidIdentifierName.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,8EAA8E;IAC9E,yEAAyE;IACzE,MAAM,iBAAiB,GAAG,4BAA4B,CAAC;IACvD,OAAO,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC","sourcesContent":["/**\n * Checks if a string is a valid identifier name according to ECMASCript specs.\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 // 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.\n const variableNameRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;\n return variableNameRegex.test(name);\n}\n"]}
@@ -1,9 +1,8 @@
1
- import fs from 'fs';
1
+ import fsPromises from 'fs/promises';
2
2
  import path from 'path';
3
3
  import { createESMStub } from './createESMStub.js';
4
4
  import { findPackageRoot } from '@ms-cloudpack/path-utilities';
5
5
  import { slash } from '@ms-cloudpack/path-string-parsing';
6
- const { writeFile, mkdir } = fs.promises;
7
6
  /**
8
7
  * Generates an ESM stub for CommonJS modules.
9
8
  */
@@ -19,13 +18,13 @@ export async function writeESMStub(entryPath, stubPath) {
19
18
  const extension = path.extname(entryPath);
20
19
  const stubFilename = path.basename(entryPath, extension) + '-stub.js';
21
20
  const stubFolderPath = path.join(rootPath, 'node_modules/.cache/cloudpack-stubs/');
22
- await mkdir(stubFolderPath, { recursive: true });
21
+ await fsPromises.mkdir(stubFolderPath, { recursive: true });
23
22
  stubPath = path.join(stubFolderPath, stubFilename);
24
23
  }
25
24
  // If we have a package export, we can generate an ESM stub.
26
25
  const esmStub = await createESMStub(entryPath, stubPath);
27
26
  // Write the stub to disk.
28
- await writeFile(stubPath, esmStub);
27
+ await fsPromises.writeFile(stubPath, esmStub);
29
28
  return stubPath;
30
29
  }
31
30
  //# sourceMappingURL=writeESMStub.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"writeESMStub.js","sourceRoot":"","sources":["../src/writeESMStub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAE1D,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC;AAEzC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,SAAiB,EAAE,QAAiB;IACrE,yBAAyB;IACzB,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC;IAE7B,gCAAgC;IAChC,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,QAAQ,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;QAC5C,IAAI,CAAC,QAAQ,EAAE;YACb,MAAM,IAAI,KAAK,CAAC,mCAAmC,SAAS,EAAE,CAAC,CAAC;SACjE;QACD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC1C,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,GAAG,UAAU,CAAC;QACtE,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,sCAAsC,CAAC,CAAC;QAEnF,MAAM,KAAK,CAAC,cAAc,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAEjD,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;KACpD;IAED,4DAA4D;IAC5D,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAEzD,0BAA0B;IAC1B,MAAM,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAEnC,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { createESMStub } from './createESMStub.js';\nimport { findPackageRoot } from '@ms-cloudpack/path-utilities';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\n\nconst { writeFile, mkdir } = fs.promises;\n\n/**\n * Generates an ESM stub for CommonJS modules.\n */\nexport async function writeESMStub(entryPath: string, stubPath?: string): Promise<string> {\n // Ensure forward slashes\n entryPath = slash(entryPath);\n\n // Ensure stub path is provided.\n if (!stubPath) {\n const rootPath = findPackageRoot(entryPath);\n if (!rootPath) {\n throw new Error(`Unable to find package root for ${entryPath}`);\n }\n const extension = path.extname(entryPath);\n const stubFilename = path.basename(entryPath, extension) + '-stub.js';\n const stubFolderPath = path.join(rootPath, 'node_modules/.cache/cloudpack-stubs/');\n\n await mkdir(stubFolderPath, { recursive: true });\n\n stubPath = path.join(stubFolderPath, stubFilename);\n }\n\n // If we have a package export, we can generate an ESM stub.\n const esmStub = await createESMStub(entryPath, stubPath);\n\n // Write the stub to disk.\n await writeFile(stubPath, esmStub);\n\n return stubPath;\n}\n"]}
1
+ {"version":3,"file":"writeESMStub.js","sourceRoot":"","sources":["../src/writeESMStub.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAE1D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,SAAiB,EAAE,QAAiB;IACrE,yBAAyB;IACzB,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC;IAE7B,gCAAgC;IAChC,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,QAAQ,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;QAC5C,IAAI,CAAC,QAAQ,EAAE;YACb,MAAM,IAAI,KAAK,CAAC,mCAAmC,SAAS,EAAE,CAAC,CAAC;SACjE;QACD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC1C,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,GAAG,UAAU,CAAC;QACtE,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,sCAAsC,CAAC,CAAC;QAEnF,MAAM,UAAU,CAAC,KAAK,CAAC,cAAc,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAE5D,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;KACpD;IAED,4DAA4D;IAC5D,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAEzD,0BAA0B;IAC1B,MAAM,UAAU,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAE9C,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import fsPromises from 'fs/promises';\nimport path from 'path';\nimport { createESMStub } from './createESMStub.js';\nimport { findPackageRoot } from '@ms-cloudpack/path-utilities';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\n\n/**\n * Generates an ESM stub for CommonJS modules.\n */\nexport async function writeESMStub(entryPath: string, stubPath?: string): Promise<string> {\n // Ensure forward slashes\n entryPath = slash(entryPath);\n\n // Ensure stub path is provided.\n if (!stubPath) {\n const rootPath = findPackageRoot(entryPath);\n if (!rootPath) {\n throw new Error(`Unable to find package root for ${entryPath}`);\n }\n const extension = path.extname(entryPath);\n const stubFilename = path.basename(entryPath, extension) + '-stub.js';\n const stubFolderPath = path.join(rootPath, 'node_modules/.cache/cloudpack-stubs/');\n\n await fsPromises.mkdir(stubFolderPath, { recursive: true });\n\n stubPath = path.join(stubFolderPath, stubFilename);\n }\n\n // If we have a package export, we can generate an ESM stub.\n const esmStub = await createESMStub(entryPath, stubPath);\n\n // Write the stub to disk.\n await fsPromises.writeFile(stubPath, esmStub);\n\n return stubPath;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/esm-stub-utilities",
3
- "version": "0.6.8",
3
+ "version": "0.6.10",
4
4
  "description": "Generates ESM stubs for CommonJS entry files.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -13,8 +13,8 @@
13
13
  }
14
14
  },
15
15
  "dependencies": {
16
- "@ms-cloudpack/json-utilities": "^0.0.5",
17
- "@ms-cloudpack/path-utilities": "^2.1.1",
16
+ "@ms-cloudpack/json-utilities": "^0.0.6",
17
+ "@ms-cloudpack/path-utilities": "^2.1.2",
18
18
  "@ms-cloudpack/path-string-parsing": "^1.0.1",
19
19
  "atob": "^2.1.2",
20
20
  "btoa": "^1.2.1",