@ms-cloudpack/esbuild-node-helpers 0.1.3 → 0.1.5
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/bundleNode.js
CHANGED
|
@@ -42,7 +42,7 @@ const __dirname = topLevelPath.dirname(__filename);`;
|
|
|
42
42
|
* with `nodeLinker: 'pnpm'`, but it can be updated as needed for other linkers and/or managers.)
|
|
43
43
|
*/
|
|
44
44
|
export async function bundleNode(options) {
|
|
45
|
-
const { cwd, entryPoints, outDir, errorDupePackages, esbuildOptions, clean = true } = options;
|
|
45
|
+
const { cwd, entryPoints, outDir, noticeDir, errorDupePackages, esbuildOptions, clean = true } = options;
|
|
46
46
|
console.log();
|
|
47
47
|
console.log('Bundling package with esbuild...\n');
|
|
48
48
|
const { packageJson, packageRoot } = findRealPackageJson(cwd);
|
|
@@ -89,7 +89,7 @@ export async function bundleNode(options) {
|
|
|
89
89
|
licensePlugin({
|
|
90
90
|
packageName: packageJson.name,
|
|
91
91
|
packageRoot,
|
|
92
|
-
absOutDir: packageRoot,
|
|
92
|
+
absOutDir: noticeDir ? path.join(packageRoot, noticeDir) : packageRoot,
|
|
93
93
|
unacceptableLicenseTest: options.unacceptableLicenseTest,
|
|
94
94
|
excludeFromNotice: options.excludeFromNotice,
|
|
95
95
|
}),
|
package/lib/bundleNode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundleNode.js","sourceRoot":"","sources":["../src/bundleNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO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A+B,CAAC,EAAE,QAAQ,CAAC,CAAC;IACjF,CAAC;IAED,kDAAkD;IAClD,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,GAAG,qBAAqB,CAC7E,WAAW,EACX,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EACnC,iBAAiB,CAClB,CAAC;IACF,IAAI,aAAa,CAAC,MAAM,IAAI,gBAAgB,CAAC,MAAM,EAAE,CAAC;QACpD,MAAM,IAAI,WAAW,CAAC,6CAA6C,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAChG,CAAC;IACD,MAAM,eAAe,GAAG,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC;IAE9C,MAAM,WAAW,GAAG,eAAe,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;IAChE,MAAM,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;IAC/C,sEAAsE;IACtE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,WAAW,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AACrH,CAAC","sourcesContent":["import * as esbuild from 'esbuild';\nimport fs from 'fs';\nimport path from 'path';\nimport { licensePlugin } from './license/licensePlugin.ts';\nimport type { LicensePluginOptions } from './license/types.ts';\nimport { BundleError } from './utils/BundleError.ts';\nimport { checkForDuplicateDeps } from './utils/checkForDuplicateDeps.ts';\nimport { findRealPackageJson } from './utils/findRealPackageJson.ts';\nimport { colors, logError } from './utils/logHelpers.ts';\nimport { verifyPackageJson, type VerifyPackageJsonOptions } from './utils/verifyPackageJson.ts';\n\nexport interface BundleNodeOptions\n extends VerifyPackageJsonOptions, Pick<LicensePluginOptions, 'unacceptableLicenseTest' | 'excludeFromNotice'> {\n /** Working directory, usually the package root (it will find the actual root from here) */\n cwd: string;\n\n /** Clean output before building (highly recommended due to hashed filenames) @default true */\n clean?: boolean;\n\n /** Extra options for esbuild */\n esbuildOptions?: Omit<\n esbuild.BuildOptions,\n 'absWorkingDir' | 'bundle' | 'entryPoints' | 'metafile' | 'outdir' | 'platform'\n >;\n\n /** Error if there are duplicate packages matching any of these regexps */\n errorDupePackages?: RegExp[];\n\n /** If true, write esbuild's metafile and analysis to disk under `<packageRoot>/temp` */\n writeMetafile?: boolean;\n}\n\n/**\n * This is added at the top of every file and makes CJS globals work in esbuild output.\n * We need `require()` for bundled CJS that loads Node internals or native packages.\n * The bundled CJS deps also use `__filename` and `__dirname` in a couple places.\n * https://github.com/evanw/esbuild/issues/946#issuecomment-814703190\n */\nconst requireHeader = `// @ts-nocheck\n/* eslint-disable */\nimport { createRequire as topLevelCreateRequire } from 'node:module';\nimport topLevelPath from 'node:path';\nimport topLevelUrl from 'node:url';\nconst require = topLevelCreateRequire(import.meta.url);\nconst __filename = topLevelUrl.fileURLToPath(import.meta.url);\nconst __dirname = topLevelPath.dirname(__filename);`;\n\n/**\n * Bundle a node package with esbuild. By default it creates an ESM bundle for Node 22+.\n * `dependencies` will be externalized, but all other referenced deps will be bundled.\n *\n * It also writes a `NOTICE.txt` file at the package root with license information for dependencies\n * from outside the current repo, and if `options.unacceptableLicenseTest` is provided, errors if\n * any packages have disallowed licenses. It also errors if a package is missing license info.\n *\n * Before bundling, it checks for proper configuration of `package.json`:\n * - `NOTICE.txt` and the output directory are included in `files`\n * - If `verifyExportPaths` is set, `exports` are correctly mapped\n * - If `verifyTypesInFiles` is true, `lib/** /*.d.ts` is included in `files`\n *\n * After bundling, it checks for duplicate dependencies:\n * - Always error if there are multiple copies of the same version of a dependency\n * - Optionally error if any dependencies match the regexps provided in `errorDupePackages`\n *\n * (Some of the current logic and messages assume the consuming repo is using yarn v4, likely\n * with `nodeLinker: 'pnpm'`, but it can be updated as needed for other linkers and/or managers.)\n */\nexport async function bundleNode(options: BundleNodeOptions): Promise<void> {\n const { cwd, entryPoints, outDir, errorDupePackages, esbuildOptions, clean = true } = options;\n\n console.log();\n console.log('Bundling package with esbuild...\\n');\n\n const { packageJson, packageRoot } = findRealPackageJson(cwd);\n\n verifyPackageJson(options, packageJson);\n\n if (clean) {\n // Remove old output. This is more important with esbuild due to hashed filenames.\n fs.rmSync(path.join(packageRoot, outDir), { force: true, recursive: true });\n }\n\n // The header defining require() is needed with ESM output, but not if the user changed the format\n const format = esbuildOptions?.format ?? 'esm';\n const jsBanner = format === 'esm' ? requireHeader : undefined;\n\n let result: esbuild.BuildResult<esbuild.BuildOptions & { metafile: true }>;\n try {\n result = await esbuild.build({\n splitting: format === 'esm',\n treeShaking: true,\n target: ['node22'],\n // some packages rely on specific names in instanceof checks\n keepNames: true,\n // log errors, warnings, and a summary (which includes the output file sizes)\n logLevel: 'info',\n // less important if not minifying, and bloats package size\n // sourcemap: true,\n\n ...esbuildOptions,\n\n // Critical options\n absWorkingDir: packageRoot,\n entryPoints: entryPoints,\n outdir: outDir,\n platform: 'node',\n bundle: true,\n format,\n // Exclude non-dev dependencies from the bundle. In a bundled package, generally the only\n // dependencies should be other internal packages and anything with native binaries.\n // (It appears node built-ins are automatically externalized with platform: 'node'.)\n external: [\n ...Object.keys({\n ...packageJson.dependencies,\n ...packageJson.peerDependencies,\n ...packageJson.optionalDependencies,\n }),\n ...(esbuildOptions?.external || []),\n ],\n plugins: [\n licensePlugin({\n packageName: packageJson.name,\n packageRoot,\n absOutDir: packageRoot,\n unacceptableLicenseTest: options.unacceptableLicenseTest,\n excludeFromNotice: options.excludeFromNotice,\n }),\n ...(esbuildOptions?.plugins || []),\n ],\n banner: {\n ...esbuildOptions?.banner,\n js: [esbuildOptions?.banner?.js, jsBanner].filter(Boolean).join('\\n'),\n },\n metafile: true,\n });\n } catch (err) {\n const failure = err as esbuild.BuildFailure;\n if (failure.errors.some((e) => e.text.includes('Could not resolve') && e.location?.file.includes('.store'))) {\n console.log(\n `\\n${colors.red(colors.bold('NOTE:'))} Packages that could not be found are usually missing peers, ` +\n `which may not be specified properly for strict installation layouts. ` +\n `You can work around this by updating ${colors.bold('yarnrc.yml packageExtensions')} to ` +\n `include the missing package as a dependency or peerDependency of the importing package.`,\n );\n }\n const msg = `Bundling failed with ${failure.errors.length} error(s)!`;\n logError(colors.red(colors.bold(msg + '\\n')));\n throw new BundleError(msg, { alreadyLogged: true, cause: err });\n }\n\n if (options.writeMetafile) {\n // Write the metafile and analysis to disk for inspection.\n const tmpDir = path.join(packageRoot, 'temp');\n fs.mkdirSync(tmpDir, { recursive: true }); // do nothing if it exists\n fs.writeFileSync(path.join(tmpDir, 'esbuild-metafile.json'), JSON.stringify(result.metafile, null, 2));\n const analysis = await esbuild.analyzeMetafile(result.metafile, { verbose: true });\n fs.writeFileSync(path.join(tmpDir, 'esbuild-metafile-analysis.txt'), analysis);\n }\n\n // Check for duplicate dependencies in the bundle.\n const { errorDupeDeps, warnDupeDeps, sameVersionDupes } = checkForDuplicateDeps(\n packageRoot,\n Object.keys(result.metafile.inputs),\n errorDupePackages,\n );\n if (errorDupeDeps.length || sameVersionDupes.length) {\n throw new BundleError('Duplicate dependencies detected (see above)', { alreadyLogged: true });\n }\n const hasDupeWarnings = !!warnDupeDeps.length;\n\n const hasWarnings = hasDupeWarnings || !!result.warnings.length;\n const color = hasWarnings ? 'yellow' : 'green';\n // With logLevel set to 'info', esbuild will handle the basic logging.\n console.log(colors[color](colors.bold(`Bundling completed${hasWarnings ? ' with warnings (see above)' : '!'}\\n`)));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bundleNode.js","sourceRoot":"","sources":["../src/bundleNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CA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AAE,CAAC,CAAC,CAAC,CAAC;QACvG,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QACnF,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,+BAA+B,CAAC,EAAE,QAAQ,CAAC,CAAC;IACjF,CAAC;IAED,kDAAkD;IAClD,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,GAAG,qBAAqB,CAC7E,WAAW,EACX,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EACnC,iBAAiB,CAClB,CAAC;IACF,IAAI,aAAa,CAAC,MAAM,IAAI,gBAAgB,CAAC,MAAM,EAAE,CAAC;QACpD,MAAM,IAAI,WAAW,CAAC,6CAA6C,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAChG,CAAC;IACD,MAAM,eAAe,GAAG,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC;IAE9C,MAAM,WAAW,GAAG,eAAe,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;IAChE,MAAM,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;IAC/C,sEAAsE;IACtE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,WAAW,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AACrH,CAAC","sourcesContent":["import * as esbuild from 'esbuild';\nimport fs from 'fs';\nimport path from 'path';\nimport { licensePlugin } from './license/licensePlugin.ts';\nimport type { LicensePluginOptions } from './license/types.ts';\nimport { BundleError } from './utils/BundleError.ts';\nimport { checkForDuplicateDeps } from './utils/checkForDuplicateDeps.ts';\nimport { findRealPackageJson } from './utils/findRealPackageJson.ts';\nimport { colors, logError } from './utils/logHelpers.ts';\nimport { verifyPackageJson, type VerifyPackageJsonOptions } from './utils/verifyPackageJson.ts';\n\nexport interface BundleNodeOptions\n extends VerifyPackageJsonOptions, Pick<LicensePluginOptions, 'unacceptableLicenseTest' | 'excludeFromNotice'> {\n /** Working directory, usually the package root (it will find the actual root from here) */\n cwd: string;\n\n /** Clean output before building (highly recommended due to hashed filenames) @default true */\n clean?: boolean;\n\n /** Extra options for esbuild */\n esbuildOptions?: Omit<\n esbuild.BuildOptions,\n 'absWorkingDir' | 'bundle' | 'entryPoints' | 'metafile' | 'outdir' | 'platform'\n >;\n\n /** Error if there are duplicate packages matching any of these regexps */\n errorDupePackages?: RegExp[];\n\n /** If true, write esbuild's metafile and analysis to disk under `<packageRoot>/temp` */\n writeMetafile?: boolean;\n}\n\n/**\n * This is added at the top of every file and makes CJS globals work in esbuild output.\n * We need `require()` for bundled CJS that loads Node internals or native packages.\n * The bundled CJS deps also use `__filename` and `__dirname` in a couple places.\n * https://github.com/evanw/esbuild/issues/946#issuecomment-814703190\n */\nconst requireHeader = `// @ts-nocheck\n/* eslint-disable */\nimport { createRequire as topLevelCreateRequire } from 'node:module';\nimport topLevelPath from 'node:path';\nimport topLevelUrl from 'node:url';\nconst require = topLevelCreateRequire(import.meta.url);\nconst __filename = topLevelUrl.fileURLToPath(import.meta.url);\nconst __dirname = topLevelPath.dirname(__filename);`;\n\n/**\n * Bundle a node package with esbuild. By default it creates an ESM bundle for Node 22+.\n * `dependencies` will be externalized, but all other referenced deps will be bundled.\n *\n * It also writes a `NOTICE.txt` file at the package root with license information for dependencies\n * from outside the current repo, and if `options.unacceptableLicenseTest` is provided, errors if\n * any packages have disallowed licenses. It also errors if a package is missing license info.\n *\n * Before bundling, it checks for proper configuration of `package.json`:\n * - `NOTICE.txt` and the output directory are included in `files`\n * - If `verifyExportPaths` is set, `exports` are correctly mapped\n * - If `verifyTypesInFiles` is true, `lib/** /*.d.ts` is included in `files`\n *\n * After bundling, it checks for duplicate dependencies:\n * - Always error if there are multiple copies of the same version of a dependency\n * - Optionally error if any dependencies match the regexps provided in `errorDupePackages`\n *\n * (Some of the current logic and messages assume the consuming repo is using yarn v4, likely\n * with `nodeLinker: 'pnpm'`, but it can be updated as needed for other linkers and/or managers.)\n */\nexport async function bundleNode(options: BundleNodeOptions): Promise<void> {\n const { cwd, entryPoints, outDir, noticeDir, errorDupePackages, esbuildOptions, clean = true } = options;\n\n console.log();\n console.log('Bundling package with esbuild...\\n');\n\n const { packageJson, packageRoot } = findRealPackageJson(cwd);\n\n verifyPackageJson(options, packageJson);\n\n if (clean) {\n // Remove old output. This is more important with esbuild due to hashed filenames.\n fs.rmSync(path.join(packageRoot, outDir), { force: true, recursive: true });\n }\n\n // The header defining require() is needed with ESM output, but not if the user changed the format\n const format = esbuildOptions?.format ?? 'esm';\n const jsBanner = format === 'esm' ? requireHeader : undefined;\n\n let result: esbuild.BuildResult<esbuild.BuildOptions & { metafile: true }>;\n try {\n result = await esbuild.build({\n splitting: format === 'esm',\n treeShaking: true,\n target: ['node22'],\n // some packages rely on specific names in instanceof checks\n keepNames: true,\n // log errors, warnings, and a summary (which includes the output file sizes)\n logLevel: 'info',\n // less important if not minifying, and bloats package size\n // sourcemap: true,\n\n ...esbuildOptions,\n\n // Critical options\n absWorkingDir: packageRoot,\n entryPoints: entryPoints,\n outdir: outDir,\n platform: 'node',\n bundle: true,\n format,\n // Exclude non-dev dependencies from the bundle. In a bundled package, generally the only\n // dependencies should be other internal packages and anything with native binaries.\n // (It appears node built-ins are automatically externalized with platform: 'node'.)\n external: [\n ...Object.keys({\n ...packageJson.dependencies,\n ...packageJson.peerDependencies,\n ...packageJson.optionalDependencies,\n }),\n ...(esbuildOptions?.external || []),\n ],\n plugins: [\n licensePlugin({\n packageName: packageJson.name,\n packageRoot,\n absOutDir: noticeDir ? path.join(packageRoot, noticeDir) : packageRoot,\n unacceptableLicenseTest: options.unacceptableLicenseTest,\n excludeFromNotice: options.excludeFromNotice,\n }),\n ...(esbuildOptions?.plugins || []),\n ],\n banner: {\n ...esbuildOptions?.banner,\n js: [esbuildOptions?.banner?.js, jsBanner].filter(Boolean).join('\\n'),\n },\n metafile: true,\n });\n } catch (err) {\n const failure = err as esbuild.BuildFailure;\n if (failure.errors.some((e) => e.text.includes('Could not resolve') && e.location?.file.includes('.store'))) {\n console.log(\n `\\n${colors.red(colors.bold('NOTE:'))} Packages that could not be found are usually missing peers, ` +\n `which may not be specified properly for strict installation layouts. ` +\n `You can work around this by updating ${colors.bold('yarnrc.yml packageExtensions')} to ` +\n `include the missing package as a dependency or peerDependency of the importing package.`,\n );\n }\n const msg = `Bundling failed with ${failure.errors.length} error(s)!`;\n logError(colors.red(colors.bold(msg + '\\n')));\n throw new BundleError(msg, { alreadyLogged: true, cause: err });\n }\n\n if (options.writeMetafile) {\n // Write the metafile and analysis to disk for inspection.\n const tmpDir = path.join(packageRoot, 'temp');\n fs.mkdirSync(tmpDir, { recursive: true }); // do nothing if it exists\n fs.writeFileSync(path.join(tmpDir, 'esbuild-metafile.json'), JSON.stringify(result.metafile, null, 2));\n const analysis = await esbuild.analyzeMetafile(result.metafile, { verbose: true });\n fs.writeFileSync(path.join(tmpDir, 'esbuild-metafile-analysis.txt'), analysis);\n }\n\n // Check for duplicate dependencies in the bundle.\n const { errorDupeDeps, warnDupeDeps, sameVersionDupes } = checkForDuplicateDeps(\n packageRoot,\n Object.keys(result.metafile.inputs),\n errorDupePackages,\n );\n if (errorDupeDeps.length || sameVersionDupes.length) {\n throw new BundleError('Duplicate dependencies detected (see above)', { alreadyLogged: true });\n }\n const hasDupeWarnings = !!warnDupeDeps.length;\n\n const hasWarnings = hasDupeWarnings || !!result.warnings.length;\n const color = hasWarnings ? 'yellow' : 'green';\n // With logLevel set to 'info', esbuild will handle the basic logging.\n console.log(colors[color](colors.bold(`Bundling completed${hasWarnings ? ' with warnings (see above)' : '!'}\\n`)));\n}\n"]}
|
|
@@ -7,6 +7,8 @@ export interface VerifyPackageJsonOptions {
|
|
|
7
7
|
entryPoints: Record<string, string>;
|
|
8
8
|
/** Relative directory for output files with forward slashes */
|
|
9
9
|
outDir: string;
|
|
10
|
+
/** Relative directory to write the NOTICE.txt file (default package root) */
|
|
11
|
+
noticeDir?: string;
|
|
10
12
|
/**
|
|
11
13
|
* If set, verify that the output file is correctly referenced in package.json `exports`.
|
|
12
14
|
* Top-level keys match `entry`. Next level keys match package.json `exports` keys.
|
|
@@ -18,6 +20,11 @@ export interface VerifyPackageJsonOptions {
|
|
|
18
20
|
condition: string;
|
|
19
21
|
};
|
|
20
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* Verify contents of package.json `files` field
|
|
25
|
+
* @default true
|
|
26
|
+
*/
|
|
27
|
+
verifyFiles?: boolean;
|
|
21
28
|
/**
|
|
22
29
|
* If true, verify `lib/** /*.d.ts` (without the space) is included in package.json `files`.
|
|
23
30
|
* If a string, verify it's included in `files`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifyPackageJson.d.ts","sourceRoot":"","sources":["../../src/utils/verifyPackageJson.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEpC,+DAA+D;IAC/D,MAAM,EAAE,MAAM,CAAC;IAEf;;;;OAIG;IACH,iBAAiB,CAAC,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;IAE/E;;;OAGG;IACH,kBAAkB,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;CACpC;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,EAAE,WAAW,EAAE,WAAW,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"verifyPackageJson.d.ts","sourceRoot":"","sources":["../../src/utils/verifyPackageJson.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEpC,+DAA+D;IAC/D,MAAM,EAAE,MAAM,CAAC;IAEf,6EAA6E;IAC7E,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;IAE/E;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;CACpC;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,EAAE,WAAW,EAAE,WAAW,GAAG,IAAI,CAiEnG"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BundleError } from "./BundleError.js";
|
|
2
2
|
import { noticeFilename } from "../license/writeNotice.js";
|
|
3
3
|
export function verifyPackageJson(options, packageJson) {
|
|
4
|
-
const { entryPoints, outDir, verifyExportPaths, verifyTypesInFiles } = options;
|
|
5
|
-
if (!packageJson.files) {
|
|
4
|
+
const { entryPoints, outDir, verifyExportPaths, verifyTypesInFiles, verifyFiles = true, noticeDir = '' } = options;
|
|
5
|
+
if (verifyFiles && !packageJson.files) {
|
|
6
6
|
throw new BundleError('package.json is missing "files" field');
|
|
7
7
|
}
|
|
8
8
|
if (verifyTypesInFiles) {
|
|
@@ -11,10 +11,13 @@ export function verifyPackageJson(options, packageJson) {
|
|
|
11
11
|
throw new BundleError(`package.json "files" must include "${typesGlob}"`);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const noticePath = `${noticeDir ? `${noticeDir}/` : ''}${noticeFilename}`;
|
|
15
|
+
if (verifyFiles && !packageJson.files?.includes(noticePath)) {
|
|
16
|
+
throw new BundleError(`package.json "files" must include "${noticePath}"`);
|
|
16
17
|
}
|
|
17
|
-
if (
|
|
18
|
+
if (verifyFiles &&
|
|
19
|
+
!packageJson.files?.includes(outDir) &&
|
|
20
|
+
!packageJson.files?.some((f) => f.startsWith(`${outDir}/`))) {
|
|
18
21
|
throw new BundleError(`package.json "files" must include "${outDir}"`);
|
|
19
22
|
}
|
|
20
23
|
if (verifyExportPaths) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifyPackageJson.js","sourceRoot":"","sources":["../../src/utils/verifyPackageJson.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"verifyPackageJson.js","sourceRoot":"","sources":["../../src/utils/verifyPackageJson.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAmC3D,MAAM,UAAU,iBAAiB,CAAC,OAAiC,EAAE,WAAwB;IAC3F,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,WAAW,GAAG,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;IAEnH,IAAI,WAAW,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QACtC,MAAM,IAAI,WAAW,CAAC,uCAAuC,CAAC,CAAC;IACjE,CAAC;IAED,IAAI,kBAAkB,EAAE,CAAC;QACvB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,KAAK,MAAM,CAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;YAC/E,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAChC,MAAM,IAAI,WAAW,CAAC,qCAAqC,QAAQ,oCAAoC,CAAC,CAAC;YAC3G,CAAC;YAED,MAAM,OAAO,GAAG,GAAG,MAAM,IAAI,QAAQ,KAAK,CAAC;YAC3C,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;YAElC,MAAM,WAAW,GACf,OAAO,YAAY,KAAK,QAAQ;gBAC9B,CAAC,CAAC,SAAS,KAAK,SAAS;oBACvB,CAAC,CAAC,YAAY;oBACd,CAAC,CAAC,SAAS;gBACb,CAAC,CAAC,YAAY,EAAE,CAAC,SAAS,CAAC,CAAC;YAChC,IAAI,WAAW,KAAK,KAAK,OAAO,EAAE,EAAE,CAAC;gBACnC,MAAM,IAAI,WAAW,CACnB,yBAAyB,GAAG,sBAAsB,SAAS,SAAS,OAAO,iBAAiB,YAAY,IAAI,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG,CAC5I,CAAC;YACJ,CAAC;QACH,CAAC;QAED,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC;YACnB,MAAM,IAAI,WAAW,CACnB,mEAAmE,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC/F,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { PackageJson } from '../types.ts';\nimport { BundleError } from './BundleError.ts';\nimport { noticeFilename } from '../license/writeNotice.ts';\n\nexport interface VerifyPackageJsonOptions {\n /**\n * Mapping from path under `outDir` to original file path. Original paths are usually relative to\n * the package root (with forward slashes) but could also be files in other packages.\n */\n entryPoints: Record<string, string>;\n\n /** Relative directory for output files with forward slashes */\n outDir: string;\n\n /** Relative directory to write the NOTICE.txt file (default package root) */\n noticeDir?: string;\n\n /**\n * If set, verify that the output file is correctly referenced in package.json `exports`.\n * Top-level keys match `entry`. Next level keys match package.json `exports` keys.\n * Value is the condition for that export key (use `'default'` to allow paths with no condition).\n */\n verifyExportPaths?: { [entryKey: string]: { key: string; condition: string } };\n\n /**\n * Verify contents of package.json `files` field\n * @default true\n */\n verifyFiles?: boolean;\n\n /**\n * If true, verify `lib/** /*.d.ts` (without the space) is included in package.json `files`.\n * If a string, verify it's included in `files`.\n */\n verifyTypesInFiles?: true | string;\n}\n\nexport function verifyPackageJson(options: VerifyPackageJsonOptions, packageJson: PackageJson): void {\n const { entryPoints, outDir, verifyExportPaths, verifyTypesInFiles, verifyFiles = true, noticeDir = '' } = options;\n\n if (verifyFiles && !packageJson.files) {\n throw new BundleError('package.json is missing \"files\" field');\n }\n\n if (verifyTypesInFiles) {\n const typesGlob = typeof verifyTypesInFiles === 'string' ? verifyTypesInFiles : 'lib/**/*.d.ts';\n if (!packageJson.files?.includes(typesGlob)) {\n throw new BundleError(`package.json \"files\" must include \"${typesGlob}\"`);\n }\n }\n\n const noticePath = `${noticeDir ? `${noticeDir}/` : ''}${noticeFilename}`;\n if (verifyFiles && !packageJson.files?.includes(noticePath)) {\n throw new BundleError(`package.json \"files\" must include \"${noticePath}\"`);\n }\n\n if (\n verifyFiles &&\n !packageJson.files?.includes(outDir) &&\n !packageJson.files?.some((f) => f.startsWith(`${outDir}/`))\n ) {\n throw new BundleError(`package.json \"files\" must include \"${outDir}\"`);\n }\n\n if (verifyExportPaths) {\n // Verify the package.json exports map and published files are set up properly\n const exports = packageJson.exports as string | Record<string, string | Record<string, string>> | undefined;\n if (!exports || typeof exports === 'string') {\n throw new BundleError(\n `package.json \"exports\" must be an object when verifyExportPaths option is enabled (current: ${exports && JSON.stringify(exports)})`,\n );\n }\n\n const entryKeys = new Set(Object.keys(entryPoints));\n\n for (const [entryKey, { key, condition }] of Object.entries(verifyExportPaths)) {\n if (!entryKeys.delete(entryKey)) {\n throw new BundleError(`verifyExportPaths includes a key \"${entryKey}\" that is missing from entryPoints`);\n }\n\n const outFile = `${outDir}/${entryKey}.js`;\n const exportsValue = exports[key];\n\n const exportsFile =\n typeof exportsValue === 'string'\n ? condition === 'default'\n ? exportsValue\n : undefined\n : exportsValue?.[condition];\n if (exportsFile !== `./${outFile}`) {\n throw new BundleError(\n `package.json exports[\"${key}\"] must include { \"${condition}\": \"./${outFile}\" } (current: ${exportsValue && JSON.stringify(exportsValue)})`,\n );\n }\n }\n\n if (entryKeys.size) {\n throw new BundleError(\n `verifyExportPaths did not reference the following entry points: ${[...entryKeys].join(', ')}`,\n );\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/esbuild-node-helpers",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Helpers for creating a bundle for Node with esbuild",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"test": "cloudpack-scripts test"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@ms-cloudpack/environment": "^0.1.
|
|
26
|
+
"@ms-cloudpack/environment": "^0.1.7",
|
|
27
27
|
"hosted-git-info": "^9.0.0",
|
|
28
28
|
"picocolors": "^1.1.1",
|
|
29
29
|
"validate-npm-package-license": "^3.0.4"
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"esbuild": ">=0.28.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@ms-cloudpack/environment": "^0.1.
|
|
35
|
+
"@ms-cloudpack/environment": "^0.1.7",
|
|
36
36
|
"@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
|
|
37
37
|
"@ms-cloudpack/scripts": "^0.0.1",
|
|
38
38
|
"@ms-cloudpack/test-utilities": "^0.5.0",
|