@ms-cloudpack/esbuild-node-helpers 0.1.6 → 0.1.7

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.
@@ -1 +1 @@
1
- {"version":3,"file":"bundleNode.d.ts","sourceRoot":"","sources":["../src/bundleNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAInC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAK/D,OAAO,EAAqB,KAAK,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAEhG,MAAM,WAAW,iBACf,SAAQ,wBAAwB,EAAE,IAAI,CAAC,oBAAoB,EAAE,yBAAyB,GAAG,mBAAmB,CAAC;IAC7G,2FAA2F;IAC3F,GAAG,EAAE,MAAM,CAAC;IAEZ,8FAA8F;IAC9F,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,gCAAgC;IAChC,cAAc,CAAC,EAAE,IAAI,CACnB,OAAO,CAAC,YAAY,EACpB,eAAe,GAAG,QAAQ,GAAG,aAAa,GAAG,UAAU,GAAG,QAAQ,GAAG,UAAU,CAChF,CAAC;IAEF,0EAA0E;IAC1E,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE7B,wFAAwF;IACxF,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAiBD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CA2G1E"}
1
+ {"version":3,"file":"bundleNode.d.ts","sourceRoot":"","sources":["../src/bundleNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAInC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAK/D,OAAO,EAAqB,KAAK,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAEhG,MAAM,WAAW,iBACf,SAAQ,wBAAwB,EAAE,IAAI,CAAC,oBAAoB,EAAE,yBAAyB,GAAG,mBAAmB,CAAC;IAC7G,2FAA2F;IAC3F,GAAG,EAAE,MAAM,CAAC;IAEZ,8FAA8F;IAC9F,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,gCAAgC;IAChC,cAAc,CAAC,EAAE,IAAI,CACnB,OAAO,CAAC,YAAY,EACpB,eAAe,GAAG,QAAQ,GAAG,aAAa,GAAG,UAAU,GAAG,QAAQ,GAAG,UAAU,CAChF,CAAC;IAEF,0EAA0E;IAC1E,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE7B,wFAAwF;IACxF,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAkBD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CA2G1E"}
package/lib/bundleNode.js CHANGED
@@ -12,15 +12,16 @@ import { verifyPackageJson } from "./utils/verifyPackageJson.js";
12
12
  * We need `require()` for bundled CJS that loads Node internals or native packages.
13
13
  * The bundled CJS deps also use `__filename` and `__dirname` in a couple places.
14
14
  * https://github.com/evanw/esbuild/issues/946#issuecomment-814703190
15
+ *
16
+ * `var` is used instead of `const` to avoid re-declaration issues if a bundled package applies the
17
+ * same workaround. The odd `createRequire` import name is for similar reasons.
15
18
  */
16
- const requireHeader = `// @ts-nocheck
19
+ const cjsGlobalsHeader = `// @ts-nocheck
17
20
  /* eslint-disable */
18
- import { createRequire as topLevelCreateRequire } from 'node:module';
19
- import topLevelPath from 'node:path';
20
- import topLevelUrl from 'node:url';
21
- const require = topLevelCreateRequire(import.meta.url);
22
- const __filename = topLevelUrl.fileURLToPath(import.meta.url);
23
- const __dirname = topLevelPath.dirname(__filename);`;
21
+ import { createRequire as esbuildNodeHelpersCreateRequire } from 'node:module';
22
+ var require = esbuildNodeHelpersCreateRequire(import.meta.url);
23
+ var __filename = import.meta.filename;
24
+ var __dirname = import.meta.dirname;`;
24
25
  /**
25
26
  * Bundle a node package with esbuild. By default it creates an ESM bundle for Node 22+.
26
27
  * `dependencies` will be externalized, but all other referenced deps will be bundled.
@@ -53,7 +54,7 @@ export async function bundleNode(options) {
53
54
  }
54
55
  // The header defining require() is needed with ESM output, but not if the user changed the format
55
56
  const format = esbuildOptions?.format ?? 'esm';
56
- const jsBanner = format === 'esm' ? requireHeader : undefined;
57
+ const jsBanner = format === 'esm' ? cjsGlobalsHeader : undefined;
57
58
  let result;
58
59
  try {
59
60
  result = await esbuild.build({
@@ -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,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAiC,MAAM,8BAA8B,CAAC;AAuBhG;;;;;GAKG;AACH,MAAM,aAAa,GAAG;;;;;;;oDAO8B,CAAC;AAErD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAA0B;IACzD,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,iBAAiB,EAAE,cAAc,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IAEzG,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,OAAO,CAAC,GAAG,CA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C;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"]}
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,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAiC,MAAM,8BAA8B,CAAC;AAuBhG;;;;;;;;GAQG;AACH,MAAM,gBAAgB,GAAW;;;;;qCAKI,CAAC;AAEtC;;;;;;;;;;;;;;;;;;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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 *\n * `var` is used instead of `const` to avoid re-declaration issues if a bundled package applies the\n * same workaround. The odd `createRequire` import name is for similar reasons.\n */\nconst cjsGlobalsHeader: string = `// @ts-nocheck\n/* eslint-disable */\nimport { createRequire as esbuildNodeHelpersCreateRequire } from 'node:module';\nvar require = esbuildNodeHelpersCreateRequire(import.meta.url);\nvar __filename = import.meta.filename;\nvar __dirname = import.meta.dirname;`;\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' ? cjsGlobalsHeader : 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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/esbuild-node-helpers",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Helpers for creating a bundle for Node with esbuild",
5
5
  "license": "MIT",
6
6
  "type": "module",