@ms-cloudpack/esbuild-node-helpers 0.1.1 → 0.1.2
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.d.ts +1 -1
- package/lib/bundleNode.d.ts.map +1 -1
- package/lib/bundleNode.js +1 -0
- package/lib/bundleNode.js.map +1 -1
- package/lib/license/licensePlugin.js +1 -1
- package/lib/license/licensePlugin.js.map +1 -1
- package/lib/license/types.d.ts +2 -0
- package/lib/license/types.d.ts.map +1 -1
- package/lib/license/types.js.map +1 -1
- package/lib/license/writeNotice.d.ts +1 -1
- package/lib/license/writeNotice.d.ts.map +1 -1
- package/lib/license/writeNotice.js +5 -2
- package/lib/license/writeNotice.js.map +1 -1
- package/package.json +3 -3
package/lib/bundleNode.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as esbuild from 'esbuild';
|
|
2
2
|
import type { LicensePluginOptions } from './license/types.ts';
|
|
3
3
|
import { type VerifyPackageJsonOptions } from './utils/verifyPackageJson.ts';
|
|
4
|
-
export interface BundleNodeOptions extends VerifyPackageJsonOptions, Pick<LicensePluginOptions, 'unacceptableLicenseTest'> {
|
|
4
|
+
export interface BundleNodeOptions extends VerifyPackageJsonOptions, Pick<LicensePluginOptions, 'unacceptableLicenseTest' | 'excludeFromNotice'> {
|
|
5
5
|
/** Working directory, usually the package root (it will find the actual root from here) */
|
|
6
6
|
cwd: string;
|
|
7
7
|
/** Clean output before building (highly recommended due to hashed filenames) @default true */
|
package/lib/bundleNode.d.ts.map
CHANGED
|
@@ -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,CAAC;
|
|
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"}
|
package/lib/bundleNode.js
CHANGED
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,E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AE,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'> {\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 }),\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,MA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,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, 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"]}
|
|
@@ -58,7 +58,7 @@ export function licensePlugin(options) {
|
|
|
58
58
|
// Include the full text despite having logged it since this can make debugging easier
|
|
59
59
|
throw new BundleError(errorStr, { alreadyLogged: true });
|
|
60
60
|
}
|
|
61
|
-
writeNotice(licenseResult.dependencies, options.absOutDir);
|
|
61
|
+
writeNotice(licenseResult.dependencies, options.absOutDir, options.excludeFromNotice);
|
|
62
62
|
});
|
|
63
63
|
},
|
|
64
64
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"licensePlugin.js","sourceRoot":"","sources":["../../src/license/licensePlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,OAAO,EAAE,mBAAmB,EAA0B,MAAM,iCAAiC,CAAC;AAC9F,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,aAAa,CAAC,OAA6B;IACzD,MAAM,gBAAgB,GAAgC,EAAE,CAAC;IACzD,MAAM,YAAY,GAAG,IAAI,GAAG,EAAoC,CAAC;IAEjE,OAAO;QACL,IAAI,EAAE,0BAA0B;QAChC,KAAK,CAAC,KAAK;YACT,oDAAoD;YACpD,2DAA2D;YAC3D,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE;gBACtC,0EAA0E;gBAC1E,IAAI,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;gBACtF,4DAA4D;gBAC5D,IAAI,CAAC,EAA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AgB,CAAC,WAAW,CAAC,IAAI,WAAW,CAAC,IAAI,KAAK,OAAO,CAAC,WAAW,EAAE,CAAC;oBAC/E,gBAAgB,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC;gBAC9C,CAAC;gBACD,OAAO,IAAI,CAAC;YACd,CAAC,CAAC,CAAC;YAEH,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE;gBACf,0FAA0F;gBAC1F,0FAA0F;gBAC1F,uBAAuB;gBACvB,MAAM,aAAa,GAAG,eAAe,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;gBACjE,IAAI,OAAO,IAAI,aAAa,EAAE,CAAC;oBAC7B,MAAM,QAAQ,GAAG,aAAa,CAAC,KAAK,CAAC;oBACrC,QAAQ,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;oBAC1B,sFAAsF;oBACtF,MAAM,IAAI,WAAW,CAAC,QAAQ,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC3D,CAAC;gBAED,WAAW,CAAC,aAAa,CAAC,YAAY,EAAE,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;YACxF,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { Plugin } from 'esbuild';\nimport fs from 'fs';\nimport { fileURLToPath } from 'url';\nimport type { PackageJson } from '../types.ts';\nimport { findRealPackageJson, type PackageJsonResult } from '../utils/findRealPackageJson.ts';\nimport { logError } from '../utils/logHelpers.ts';\nimport { writeNotice } from './writeNotice.ts';\nimport { BundleError } from '../utils/BundleError.ts';\nimport type { LicensePluginOptions } from './types.ts';\nimport { analyzeLicenses } from './analyzeLicenses.ts';\n\n/**\n * esbuild plugin to generate a NOTICE.txt file with license information for all dependencies\n * that are included in the bundle (excluding any packages from the same repo).\n *\n * This relies on the info published with the package (in package.json or certain predefined files)\n * and doesn't check github for other related files that aren't published.\n *\n * Other implementations:\n * - There's a service [ClearlyDefined](https://clearlydefined.io) which is made by Microsoft\n * and used by CG to generate notices, and is more comprehensive with checking npm/github.\n * However, the public API is badly-documented, subject to unclear rate limits, and not reliable\n * (can't find some packages for the notice even though they exist in its database in the UI).\n * - https://github.com/upupming/esbuild-plugin-license (only writes name, version, license type)\n * - https://github.com/mhassan1/yarn-plugin-licenses (covers whole repo; similar formatting used here)\n * - https://github.com/codepunkt/webpack-license-plugin (json output for webpack only)\n */\nexport function licensePlugin(options: LicensePluginOptions): Plugin {\n const includedPackages: Record<string, PackageJson> = {};\n const packageCache = new Map<string, PackageJsonResult | null>();\n\n return {\n name: 'cloudpack-license-plugin',\n setup(build) {\n // On load, track all the packages that are included\n // (any errors will be caught and logged by esbuild itself)\n build.onLoad({ filter: /.*/ }, (args) => {\n // esbuild docs make it sound like this can be a file URL or arbitrary URL\n let filePath = args.path.startsWith('file://') ? fileURLToPath(args.path) : args.path;\n // if this is something besides a filesystem path, ignore it\n if (!fs.existsSync(filePath)) {\n return null;\n }\n // use the realpath for deduping store files\n filePath = fs.realpathSync(filePath);\n\n if (!filePath.includes('node_modules')) {\n return null;\n }\n\n const { packageRoot, packageJson } = findRealPackageJson(filePath, packageCache);\n if (!includedPackages[packageRoot] && packageJson.name !== options.packageName) {\n includedPackages[packageRoot] = packageJson;\n }\n return null;\n });\n\n build.onEnd(() => {\n // We have to catch any errors and explicitly log them since esbuild doesn't automatically\n // log thrown errors at this point, and our wrapper that calls esbuild assumes errors have\n // already been logged.\n const licenseResult = analyzeLicenses(includedPackages, options);\n if ('error' in licenseResult) {\n const errorStr = licenseResult.error;\n logError(errorStr + '\\n');\n // Include the full text despite having logged it since this can make debugging easier\n throw new BundleError(errorStr, { alreadyLogged: true });\n }\n\n writeNotice(licenseResult.dependencies, options.absOutDir, options.excludeFromNotice);\n });\n },\n };\n}\n"]}
|
package/lib/license/types.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export interface LicensePluginOptions {
|
|
|
5
5
|
packageRoot: string;
|
|
6
6
|
/** Absolute output directory for the NOTICE.txt file */
|
|
7
7
|
absOutDir: string;
|
|
8
|
+
/** Function to determine if a dependency should be excluded from the NOTICE.txt file */
|
|
9
|
+
excludeFromNotice?: (dependency: Dependency) => boolean;
|
|
8
10
|
/**
|
|
9
11
|
* Return true if the license is unacceptable.
|
|
10
12
|
* You can use `unacceptableLicenseTest` exported from this package as a default.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/license/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAC;IAEpB,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;IAEpB,wDAAwD;IACxD,SAAS,EAAE,MAAM,CAAC;IAElB;;;;;;OAMG;IACH,uBAAuB,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC;CACnE;AAED,2DAA2D;AAC3D,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC;AAED,MAAM,WAAW,eAAgB,SAAQ,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3E,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/license/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAC;IAEpB,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;IAEpB,wDAAwD;IACxD,SAAS,EAAE,MAAM,CAAC;IAElB,wFAAwF;IACxF,iBAAiB,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,OAAO,CAAC;IAExD;;;;;;OAMG;IACH,uBAAuB,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC;CACnE;AAED,2DAA2D;AAC3D,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC;AAED,MAAM,WAAW,eAAgB,SAAQ,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3E,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB"}
|
package/lib/license/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/license/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface LicensePluginOptions {\n /** Name of the package being bundled */\n packageName: string;\n\n /** Root directory of the package being bundled */\n packageRoot: string;\n\n /** Absolute output directory for the NOTICE.txt file */\n absOutDir: string;\n\n /**\n * Return true if the license is unacceptable.\n * You can use `unacceptableLicenseTest` exported from this package as a default.\n *\n * @param licenseName A valid SPDX license expression (without \"LicenseRef\"), \"UNLICENSED\",\n * \"SEE LICENSE IN <filename>\", or null if no valid license info was found in package.json.\n */\n unacceptableLicenseTest?: (licenseName: string | null) => boolean;\n}\n\n/** Dependency format used internally by `licensePlugin` */\nexport interface Dependency {\n name: string;\n version: string;\n author: string | undefined;\n maintainers: string | undefined;\n contributors: string | undefined;\n url: string | undefined;\n license: string | null;\n licenseText: string | undefined;\n noticeText: string | undefined;\n}\n\nexport interface ErrorDependency extends Pick<Dependency, 'name' | 'version'> {\n path: string;\n issues: string[];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/license/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface LicensePluginOptions {\n /** Name of the package being bundled */\n packageName: string;\n\n /** Root directory of the package being bundled */\n packageRoot: string;\n\n /** Absolute output directory for the NOTICE.txt file */\n absOutDir: string;\n\n /** Function to determine if a dependency should be excluded from the NOTICE.txt file */\n excludeFromNotice?: (dependency: Dependency) => boolean;\n\n /**\n * Return true if the license is unacceptable.\n * You can use `unacceptableLicenseTest` exported from this package as a default.\n *\n * @param licenseName A valid SPDX license expression (without \"LicenseRef\"), \"UNLICENSED\",\n * \"SEE LICENSE IN <filename>\", or null if no valid license info was found in package.json.\n */\n unacceptableLicenseTest?: (licenseName: string | null) => boolean;\n}\n\n/** Dependency format used internally by `licensePlugin` */\nexport interface Dependency {\n name: string;\n version: string;\n author: string | undefined;\n maintainers: string | undefined;\n contributors: string | undefined;\n url: string | undefined;\n license: string | null;\n licenseText: string | undefined;\n noticeText: string | undefined;\n}\n\nexport interface ErrorDependency extends Pick<Dependency, 'name' | 'version'> {\n path: string;\n issues: string[];\n}\n"]}
|
|
@@ -3,5 +3,5 @@ export declare const noticeFilename = "NOTICE.txt";
|
|
|
3
3
|
/**
|
|
4
4
|
* Write NOTICE.txt with license and author info for the given dependencies.
|
|
5
5
|
*/
|
|
6
|
-
export declare function writeNotice(dependencies: Dependency[], absOutDir: string): void;
|
|
6
|
+
export declare function writeNotice(dependencies: Dependency[], absOutDir: string, excludeFromNotice?: (dependency: Dependency) => boolean): void;
|
|
7
7
|
//# sourceMappingURL=writeNotice.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeNotice.d.ts","sourceRoot":"","sources":["../../src/license/writeNotice.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,eAAO,MAAM,cAAc,eAAe,CAAC;AAE3C;;GAEG;AACH,wBAAgB,WAAW,
|
|
1
|
+
{"version":3,"file":"writeNotice.d.ts","sourceRoot":"","sources":["../../src/license/writeNotice.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,eAAO,MAAM,cAAc,eAAe,CAAC;AAE3C;;GAEG;AACH,wBAAgB,WAAW,CACzB,YAAY,EAAE,UAAU,EAAE,EAC1B,SAAS,EAAE,MAAM,EACjB,iBAAiB,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,OAAO,GACtD,IAAI,CA8BN"}
|
|
@@ -4,12 +4,15 @@ export const noticeFilename = 'NOTICE.txt';
|
|
|
4
4
|
/**
|
|
5
5
|
* Write NOTICE.txt with license and author info for the given dependencies.
|
|
6
6
|
*/
|
|
7
|
-
export function writeNotice(dependencies, absOutDir) {
|
|
7
|
+
export function writeNotice(dependencies, absOutDir, excludeFromNotice) {
|
|
8
8
|
if (!dependencies.length)
|
|
9
9
|
return;
|
|
10
|
+
const filteredDependencies = excludeFromNotice ? dependencies.filter((dep) => !excludeFromNotice(dep)) : dependencies;
|
|
11
|
+
if (!filteredDependencies.length)
|
|
12
|
+
return;
|
|
10
13
|
const noticeText = [
|
|
11
14
|
`NOTICES\n\nThis package incorporates material as listed below or described in the code.`,
|
|
12
|
-
...
|
|
15
|
+
...filteredDependencies.map((dep) => {
|
|
13
16
|
const shortLicense = dep.license ? (/^see license/i.test(dep.license) ? '' : dep.license) : 'unknown license';
|
|
14
17
|
return [
|
|
15
18
|
`${dep.name} ${dep.version}${shortLicense ? ` - ${shortLicense}` : ''}${dep.url ? `\n${dep.url}` : ''}`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeNotice.js","sourceRoot":"","sources":["../../src/license/writeNotice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CAAC;AAE3C;;GAEG;AACH,MAAM,UAAU,WAAW,
|
|
1
|
+
{"version":3,"file":"writeNotice.js","sourceRoot":"","sources":["../../src/license/writeNotice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CAAC;AAE3C;;GAEG;AACH,MAAM,UAAU,WAAW,CACzB,YAA0B,EAC1B,SAAiB,EACjB,iBAAuD;IAEvD,IAAI,CAAC,YAAY,CAAC,MAAM;QAAE,OAAO;IAEjC,MAAM,oBAAoB,GAAG,iBAAiB,CAAC,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC;IACtH,IAAI,CAAC,oBAAoB,CAAC,MAAM;QAAE,OAAO;IAEzC,MAAM,UAAU,GAAG;QACjB,yFAAyF;QACzF,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YAClC,MAAM,YAAY,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC;YAC9G,OAAO;gBACL,GAAG,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,OAAO,GAAG,YAAY,CAAC,CAAC,CAAC,MAAM,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE;gBACvG,uFAAuF;gBACvF,GAAG,CAAC,MAAM,IAAI,WAAW,GAAG,CAAC,MAAM,EAAE;gBACrC,GAAG,CAAC,WAAW,IAAI,iBAAiB,GAAG,CAAC,WAAW,EAAE;gBACrD,GAAG,CAAC,YAAY,IAAI,kBAAkB,GAAG,CAAC,YAAY,EAAE;gBACxD,oEAAoE;gBACpE,GAAG,CAAC,WAAW;gBACf,+DAA+D;gBAC/D,GAAG,CAAC,UAAU,IAAI,eAAe,GAAG,CAAC,UAAU,EAAE;aAClD;iBACE,MAAM,CAAC,OAAO,CAAC;iBACf,IAAI,CAAC,MAAM,CAAC,CAAC;QAClB,CAAC,CAAC;KACH,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAEvB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IACrD,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,CAAC,4BAA4B,OAAO,IAAI,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport type { Dependency } from './types.ts';\n\nexport const noticeFilename = 'NOTICE.txt';\n\n/**\n * Write NOTICE.txt with license and author info for the given dependencies.\n */\nexport function writeNotice(\n dependencies: Dependency[],\n absOutDir: string,\n excludeFromNotice?: (dependency: Dependency) => boolean,\n): void {\n if (!dependencies.length) return;\n\n const filteredDependencies = excludeFromNotice ? dependencies.filter((dep) => !excludeFromNotice(dep)) : dependencies;\n if (!filteredDependencies.length) return;\n\n const noticeText = [\n `NOTICES\\n\\nThis package incorporates material as listed below or described in the code.`,\n ...filteredDependencies.map((dep) => {\n const shortLicense = dep.license ? (/^see license/i.test(dep.license) ? '' : dep.license) : 'unknown license';\n return [\n `${dep.name} ${dep.version}${shortLicense ? ` - ${shortLicense}` : ''}${dep.url ? `\\n${dep.url}` : ''}`,\n // Unclear which author/maintainer/contributor info is required, so include all of them\n dep.author && `Author: ${dep.author}`,\n dep.maintainers && `Maintainers:\\n${dep.maintainers}`,\n dep.contributors && `Contributors:\\n${dep.contributors}`,\n // The license text typically includes the official copyright notice\n dep.licenseText,\n // As of writing we don't use any packages that publish NOTICES\n dep.noticeText && `NOTICES:\\n\\n${dep.noticeText}`,\n ]\n .filter(Boolean)\n .join('\\n\\n');\n }),\n ].join('\\n\\n----\\n\\n');\n\n const outFile = path.join(absOutDir, noticeFilename);\n fs.mkdirSync(absOutDir, { recursive: true });\n fs.writeFileSync(outFile, noticeText, 'utf8');\n console.log(`Wrote license notices to ${outFile}\\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.2",
|
|
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.5",
|
|
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.5",
|
|
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",
|