@rushstack/webpack-embedded-dependencies-plugin 0.2.111 → 0.3.0
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/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/webpack-embedded-dependencies-plugin",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.3.0",
|
|
6
|
+
"tag": "@rushstack/webpack-embedded-dependencies-plugin_v0.3.0",
|
|
7
|
+
"date": "Fri, 03 Oct 2025 20:10:00 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"minor": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Normalize import of builtin modules to use the `node:` protocol."
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"dependency": [
|
|
15
|
+
{
|
|
16
|
+
"comment": "Updating dependency \"@rushstack/node-core-library\" to `5.16.0`"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"comment": "Updating dependency \"@rushstack/webpack-plugin-utilities\" to `0.5.0`"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"comment": "Updating dependency \"@rushstack/heft\" to `1.1.0`"
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
},
|
|
4
27
|
{
|
|
5
28
|
"version": "0.2.111",
|
|
6
29
|
"tag": "@rushstack/webpack-embedded-dependencies-plugin_v0.2.111",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
# Change Log - @rushstack/webpack-embedded-dependencies-plugin
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Fri, 03 Oct 2025 20:10:00 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.3.0
|
|
6
|
+
Fri, 03 Oct 2025 20:10:00 GMT
|
|
7
|
+
|
|
8
|
+
### Minor changes
|
|
9
|
+
|
|
10
|
+
- Normalize import of builtin modules to use the `node:` protocol.
|
|
4
11
|
|
|
5
12
|
## 0.2.111
|
|
6
13
|
Tue, 30 Sep 2025 23:57:45 GMT
|
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmbeddedDependenciesWebpackPlugin.d.ts","sourceRoot":"","sources":["../src/EmbeddedDependenciesWebpackPlugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EmbeddedDependenciesWebpackPlugin.d.ts","sourceRoot":"","sources":["../src/EmbeddedDependenciesWebpackPlugin.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAe,qBAAqB,EAAiC,MAAM,SAAS,CAAC;AAG3G,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AA0BjE;;;;GAIG;AACH,MAAM,WAAW,YAAa,SAAQ,YAAY;IAChD;;OAEG;IACH,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACpC;;OAEG;IACH,QAAQ,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAE3C;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,WAAW,yCAAyC;IACxD;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;OAEG;IACH,2BAA2B,CAAC,EAAE,4BAA4B,CAAC;IAC3D;;OAEG;IACH,wBAAwB,CAAC,EAAE,eAAe,CAAC;IAE3C;;;OAGG;IACH,sBAAsB,CAAC,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;CACnF;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,4BAA4B,GAAG,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,MAAM,CAAC;AAEhF;;;;;;;;;;GAUG;AACH,MAAM,MAAM,eAAe,GAAG,GAAG,MAAM,IAAI,MAAM,GAAG,IAAI,GAAG,KAAK,EAAE,CAAC;AASnE;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,iCAAkC,YAAW,qBAAqB;IACrF,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAU;IAC/C,OAAO,CAAC,QAAQ,CAAC,4BAA4B,CAA+B;IAC5E,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAAkB;IAC5D,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAA2D;gBAE/E,OAAO,CAAC,EAAE,yCAAyC;IAStE;;;;;;OAMG;IACI,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAgGtC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,OAAO,CAAC,iBAAiB;IAqBzB;;OAEG;YACW,wBAAwB;IA6BtC;;OAEG;IACH,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,4BAA4B;CAUrC"}
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
6
|
};
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
const
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
9
|
const node_core_library_1 = require("@rushstack/node-core-library");
|
|
10
10
|
const regexpUtils_1 = require("./regexpUtils");
|
|
11
11
|
const PLUGIN_NAME = 'EmbeddedDependenciesWebpackPlugin';
|
|
@@ -158,7 +158,7 @@ class EmbeddedDependenciesWebpackPlugin {
|
|
|
158
158
|
for (const file of files) {
|
|
159
159
|
if (file.isFile() && regexpUtils_1.LICENSE_FILES_REGEXP.test(file.name)) {
|
|
160
160
|
// Grabbing the first license file if multiple are found
|
|
161
|
-
return
|
|
161
|
+
return node_path_1.default.join(modulePath, file.name);
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmbeddedDependenciesWebpackPlugin.js","sourceRoot":"","sources":["../src/EmbeddedDependenciesWebpackPlugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;AAE3D,gDAAwB;AACxB,oEAAuF;AAKvF,+CAAsE;AAEtE,MAAM,WAAW,GAAwC,mCAAmC,CAAC;AAC7F,MAAM,mBAAmB,GAAW,wCAAwC,CAAC;AAC7E,MAAM,mCAAmC,GAA+B,0BAA0B,CAAC;AACnG,MAAM,uCAAuC,GAAiC,4BAA4B,CAAC;AAC3G,MAAM,+BAA+B,GAA6D,GAAG,EAAE,CAAC,IAAI,CAAC;AAoI7G;;;;GAIG;AACH,MAAqB,iCAAiC;IAOpD,YAAmB,OAAmD;QACpE,IAAI,CAAC,eAAe,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,cAAc,KAAI,uCAAuC,CAAC;QAC1F,IAAI,CAAC,oBAAoB,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,mBAAmB,KAAI,KAAK,CAAC;QAClE,IAAI,CAAC,4BAA4B;YAC/B,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,2BAA2B,KAAI,IAAI,CAAC,4BAA4B,CAAC;QAC5E,IAAI,CAAC,yBAAyB,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,wBAAwB,KAAI,mCAAmC,CAAC;QAC1G,IAAI,CAAC,sBAAsB,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP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IACzC,OAAO,OAAO,CAAC,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAA,CAAC,CAAC,MAAM,0CAAE,IAAI,CAAC;AAClE,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport path from 'path';\nimport { Async, Sort, LegacyAdapters, FileSystem } from '@rushstack/node-core-library';\n\nimport type { Compiler, Compilation, WebpackPluginInstance, WebpackError, InputFileSystem } from 'webpack';\nimport type { IPackageJson } from '@rushstack/node-core-library';\n\nimport { LICENSE_FILES_REGEXP, COPYRIGHT_REGEX } from './regexpUtils';\n\nconst PLUGIN_NAME: 'EmbeddedDependenciesWebpackPlugin' = 'EmbeddedDependenciesWebpackPlugin';\nconst PLUGIN_ERROR_PREFIX: string = '[embedded-dependencies-webpack-plugin]';\nconst DEFAULT_GENERATED_LICENSE_FILE_NAME: 'THIRD-PARTY-NOTICES.html' = 'THIRD-PARTY-NOTICES.html';\nconst DEFAULT_EMBEDDED_DEPENDENCIES_FILE_NAME: 'embedded-dependencies.json' = 'embedded-dependencies.json';\nconst DEFAULT_PACKAGE_FILTER_FUNCTION: (packageJson: IPackageData, filePath: string) => boolean = () => true;\n\ninterface IEmbeddedDependenciesFile {\n name?: string;\n version?: string;\n embeddedDependencies: IPackageData[];\n}\n\ninterface IResourceResolveData {\n descriptionFileData?: IPackageData;\n descriptionFileRoot?: string;\n relativePath?: string;\n}\n\ninterface IWebpackModuleCreateData {\n resourceResolveData?: IResourceResolveData;\n}\n\n/**\n * @beta\n * Data type for a package.json file. This is a superset of the full package.json file and includes additional fields\n * that are generated by the plugin, including licenseSource, licenses, copyright, and author.\n */\nexport interface IPackageData extends IPackageJson {\n /**\n * A small string subset which is used for copyright extraction from a licenseSource file.\n */\n copyright: string | undefined;\n /**\n * The author of the package. This is a superset of the full package.json author field.\n * Grabs either the author field or author.name field from package.json.\n */\n author?: string | { name?: string };\n /**\n * Additional license metadata if present. May contain information about a project which has multiple licenses.\n */\n licenses?: { type: string; url: string }[];\n\n /**\n * The source of the license file itself used for generating THIRD-PARTY-NOTICES.html or custom license files.\n */\n licenseSource?: string;\n}\n\n/**\n * @beta\n * Plugin options for EmbeddedDependenciesWebpackPlugin\n *\n * @param outputFileName - Name of the file to be generated. Defaults to embedded-dependencies.json\n * @param generateLicenseFile - Whether to generate a license file. Defaults to false and will only generate the embedded-dependencies.json file\n * @param generateLicenseFileFunction - Function that generates the license file. Defaults to the plugin's internal default generator function but allows you to override it\n * @param generatedLicenseFilename - Name of the generated license file. Defaults to THIRD-PARTY-NOTICES.html\n *\n * @example\n * ```ts\n * // webpack.config.js\n * plugins: [\n * new EmbeddedDependenciesWebpackPlugin({\n * outputFileName: 'custom-file-name.json',\n * generateLicenseFile: true,\n * generateLicenseFileFunction: (packages: IPackageData[]) => {\n * return packages\n * .map((pkg) => {\n * return `<h2>${pkg.name}</h2><p>${pkg.license}</p>`;\n * }).join('');\n * },\n * generatedLicenseFilename: 'custom-license-file-name.html'\n * })\n * ]\n * ```\n */\nexport interface IEmbeddedDependenciesWebpackPluginOptions {\n /**\n * Name of the file to be generated. Defaults to embedded-dependencies.json\n */\n outputFileName?: string;\n /**\n * Whether to generate a license file. Defaults to false and will only generate the embedded-dependencies.json file\n */\n generateLicenseFile?: boolean;\n /**\n * Function that generates the license file. Defaults to the plugin's internal default generator function but allows you to override it\n */\n generateLicenseFileFunction?: LicenseFileGeneratorFunction;\n /**\n * Name of the generated license file. Defaults to THIRD-PARTY-NOTICES.html\n */\n generatedLicenseFilename?: LicenseFileName;\n\n /**\n * Predicate function that determines whether a package should be included in the embedded\n * dependencies file or the generated license file.\n */\n packageFilterPredicate?: (packageJson: IPackageData, filePath: string) => boolean;\n}\n\n/**\n * @beta\n * Function type that generates the license file.\n *\n * @example\n * ```ts\n * const licenseFileGenerator: LicenseFileGeneratorFunction = (packages: IPackageData[]): string => {\n * return packages\n * .map((pkg) => {\n * return `<h2>${pkg.name}</h2><p>${pkg.license}</p>`;\n * }).join('');\n * }\n * ```\n */\nexport type LicenseFileGeneratorFunction = (packages: IPackageData[]) => string;\n\n/**\n * @beta\n * Loose string type that represents the name of the generated license file.\n *\n * @example\n * ```ts\n * const licenseFileName: LicenseFileName = 'custom-license-file-name.html';\n * const licenseMarkdownFileName: LicenseFileName = 'custom-license-file-name.md';\n * const licenseTextFileName: LicenseFileName = 'custom-license-file-name.txt';\n * ```\n */\nexport type LicenseFileName = `${string}.${'html' | 'md' | 'txt'}`;\n\ntype PackageNameAndVersion = `${string}@${string}`;\ntype ThirdPartyPackageMap = Map<\n PackageNameAndVersion,\n { packageFolderPath: string; packageJsonData: IPackageData }\n>;\ntype DefaultLicenseTemplate = `<hr />${string}<br /><br />${string}`;\n\n/**\n * @beta\n * Webpack plugin that generates a file with the list of embedded dependencies\n * and their licenses.\n */\nexport default class EmbeddedDependenciesWebpackPlugin implements WebpackPluginInstance {\n private readonly _outputFileName: string;\n private readonly _generateLicenseFile: boolean;\n private readonly _generateLicenseFileFunction: LicenseFileGeneratorFunction;\n private readonly _generatedLicenseFilename: LicenseFileName;\n private readonly _packageFilterFunction: (packageJson: IPackageData, filePath: string) => boolean;\n\n public constructor(options?: IEmbeddedDependenciesWebpackPluginOptions) {\n this._outputFileName = options?.outputFileName || DEFAULT_EMBEDDED_DEPENDENCIES_FILE_NAME;\n this._generateLicenseFile = options?.generateLicenseFile || false;\n this._generateLicenseFileFunction =\n options?.generateLicenseFileFunction || this._defaultLicenseFileGenerator;\n this._generatedLicenseFilename = options?.generatedLicenseFilename || DEFAULT_GENERATED_LICENSE_FILE_NAME;\n this._packageFilterFunction = options?.packageFilterPredicate || DEFAULT_PACKAGE_FILTER_FUNCTION;\n }\n\n /**\n * @beta\n * Webpack plugin apply method. This method is called by the webpack compiler to apply the plugin, however it not usually\n * needed to be invoked manually by the developer in a webpack configuration. However, if you are calling this plugin (applying it from another plugin)\n * you can call `plugin.apply(compiler)` to apply the plugin and invoke it.\n * @param compiler - The webpack compiler instance.\n */\n public apply(compiler: Compiler): void {\n const { sources, Compilation } = compiler.webpack;\n // Tap into compilation so we can tap into compilation.hooks.processAssets\n compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation, { normalModuleFactory }) => {\n const thirdPartyPackages: ThirdPartyPackageMap = new Map();\n\n normalModuleFactory.hooks.module.tap(\n PLUGIN_NAME,\n (module, moduleCreateData: IWebpackModuleCreateData, resolveData) => {\n const { resourceResolveData } = moduleCreateData;\n const pkg: IPackageData | undefined = resourceResolveData?.descriptionFileData;\n const filePath: string | undefined = resourceResolveData?.descriptionFileRoot;\n\n if (\n pkg &&\n filePath &&\n this._packageFilterFunction(pkg, filePath) &&\n filePath?.includes('node_modules')\n ) {\n const key: PackageNameAndVersion = makePackageMapKeyForPackage(pkg);\n thirdPartyPackages.set(key, { packageFolderPath: filePath, packageJsonData: pkg });\n }\n\n return module;\n }\n );\n\n compilation.hooks.processAssets.tapPromise(\n { name: PLUGIN_NAME, stage: Compilation.PROCESS_ASSETS_STAGE_REPORT },\n async (assets) => {\n const packages: IPackageData[] = [];\n\n try {\n await Async.forEachAsync(\n thirdPartyPackages,\n async ([, { packageFolderPath: dir, packageJsonData: data }]) => {\n const { name, version } = data;\n let licenseSource: string | undefined;\n const license: string | undefined = parseLicense(data);\n const licensePath: string | undefined = await this._getLicenseFilePathAsync(dir, compiler);\n if (licensePath) {\n licenseSource = await FileSystem.readFileAsync(licensePath);\n\n const copyright: string | undefined =\n this._parseCopyright(licenseSource) || parsePackageAuthor(data);\n\n packages.push({\n name,\n version,\n license,\n licenseSource,\n copyright\n });\n } else {\n // If there is no license file path, we still should populate the other required fields\n const copyright: string | undefined = parsePackageAuthor(data);\n\n packages.push({\n name,\n version,\n license,\n copyright\n });\n }\n }\n );\n } catch (error) {\n this._emitWebpackError(compilation, 'Failed to process embedded dependencies', error);\n } finally {\n Sort.sortBy(packages, (pkg) => pkg.name);\n }\n\n const dataToStringify: IEmbeddedDependenciesFile = {\n embeddedDependencies: packages\n };\n\n compilation.emitAsset(this._outputFileName, new sources.RawSource(JSON.stringify(dataToStringify)));\n\n if (this._generateLicenseFile) {\n // We should try catch here because generator function can be output from user config\n try {\n compilation.emitAsset(\n this._generatedLicenseFilename,\n new sources.RawSource(this._generateLicenseFileFunction(packages))\n );\n } catch (error: unknown) {\n this._emitWebpackError(compilation, 'Failed to generate license file', error);\n }\n }\n\n return;\n }\n );\n });\n }\n\n /**\n * Default error handler for try/catch blocks in the plugin\n * try/catches emit errors of type `unknown` and we need to handle them based on what\n * type the error is. This function provides a convenient way to handle errors and then\n * propagate them to webpack as WebpackError objects on `compilation.errors` array.\n *\n * @remarks\n * _If we need to push errors to `compilation.warnings` array, we should just create a companion function\n * that does the same thing but pushes to `compilation.warnings` array instead._\n *\n * @example\n * ```typescript\n * try {\n * // do some operation\n * FileSystem.readFile('some-file');\n * } catch (error: unknown) {\n * this._emitWebpackError(compilation, 'Failed to do some operation', error);\n * }\n * ```\n */\n private _emitWebpackError(compilation: Compilation, errorMessage: string, error: unknown): void {\n let emittedError: WebpackError;\n const { WebpackError } = compilation.compiler.webpack;\n // If the error is a string, we can just emit it as is with message prefix and error message\n if (typeof error === 'string') {\n emittedError = new WebpackError(`${PLUGIN_ERROR_PREFIX}: ${errorMessage}: ${error}`);\n // If error is an instance of Error, we can emit it with message prefix, error message and stack trace\n } else if (error instanceof Error) {\n emittedError = new WebpackError(\n `${PLUGIN_ERROR_PREFIX}: ${errorMessage}: ${error.message}\\n${error.stack || ''}`\n );\n // If error is not a string or an instance of Error, we can emit it with message prefix and error message and JSON.stringify it\n } else {\n emittedError = new WebpackError(\n `${PLUGIN_ERROR_PREFIX}: ${errorMessage}: ${JSON.stringify(error || '')}`\n );\n }\n\n compilation.errors.push(emittedError);\n }\n\n /**\n * Searches a third party package directory for a license file.\n */\n private async _getLicenseFilePathAsync(\n modulePath: string,\n compiler: Compiler\n ): Promise<string | undefined> {\n type InputFileSystemReadDirResults = Parameters<Parameters<InputFileSystem['readdir']>[2]>[1];\n\n const { inputFileSystem } = compiler;\n if (!inputFileSystem) {\n throw new Error(`Compiler.inputFileSystem is not defined`);\n }\n\n const files: InputFileSystemReadDirResults = await LegacyAdapters.convertCallbackToPromise(\n inputFileSystem.readdir,\n modulePath,\n { withFileTypes: true }\n );\n\n if (!files) {\n return;\n }\n\n for (const file of files) {\n if (file.isFile() && LICENSE_FILES_REGEXP.test(file.name)) {\n // Grabbing the first license file if multiple are found\n return path.join(modulePath, file.name);\n }\n }\n }\n\n /**\n * Given a module path, try to parse the module's copyright attribution.\n */\n private _parseCopyright(licenseSource: string): string | undefined {\n const match: RegExpMatchArray | null = licenseSource.match(COPYRIGHT_REGEX);\n\n if (match) {\n return match[0];\n }\n\n return undefined;\n }\n\n private _defaultLicenseFileGenerator(packages: IPackageData[]): string {\n const licenseContent = (pkg: IPackageData): string =>\n pkg.licenseSource || pkg.copyright || 'License or Copyright not found';\n\n const licenseTemplateForPackage = (pkg: IPackageData): DefaultLicenseTemplate => {\n return `<hr />${pkg.name} - ${pkg.version}<br /><br />${licenseContent(pkg)}`;\n };\n\n return packages.map(licenseTemplateForPackage).join('\\n');\n }\n}\n\nfunction makePackageMapKeyForPackage(pkg: IPackageData): PackageNameAndVersion {\n return `${pkg.name}@${pkg.version}`;\n}\n\n/**\n * Returns the license type\n */\nfunction parseLicense(packageData: IPackageData): string | undefined {\n if (packageData.license) {\n return packageData.license;\n } else if (typeof packageData.licenses === 'string') {\n return packageData.licenses;\n } else if (packageData.licenses?.length) {\n return packageData.licenses.length === 1\n ? packageData.licenses[0].type\n : `(${packageData.licenses\n .map((license: { type: string; url: string }) => license.type)\n .join(' OR ')})`;\n }\n\n return undefined;\n}\n\nfunction parsePackageAuthor(p: IPackageData): string | undefined {\n return typeof p.author === 'string' ? p.author : p.author?.name;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"EmbeddedDependenciesWebpackPlugin.js","sourceRoot":"","s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F,OAAO,QAAQ,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC;CACF;AAvND,oDAuNC;AAED,SAAS,2BAA2B,CAAC,GAAiB;IACpD,OAAO,GAAG,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,SAAS,YAAY,CAAC,WAAyB;;IAC7C,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;QACxB,OAAO,WAAW,CAAC,OAAO,CAAC;IAC7B,CAAC;SAAM,IAAI,OAAO,WAAW,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACpD,OAAO,WAAW,CAAC,QAAQ,CAAC;IAC9B,CAAC;SAAM,IAAI,MAAA,WAAW,CAAC,QAAQ,0CAAE,MAAM,EAAE,CAAC;QACxC,OAAO,WAAW,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC;YACtC,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI;YAC9B,CAAC,CAAC,IAAI,WAAW,CAAC,QAAQ;iBACrB,GAAG,CAAC,CAAC,OAAsC,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;iBAC7D,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;IACzB,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,kBAAkB,CAAC,CAAe;;IACzC,OAAO,OAAO,CAAC,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAA,CAAC,CAAC,MAAM,0CAAE,IAAI,CAAC;AAClE,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport path from 'node:path';\n\nimport type { Compiler, Compilation, WebpackPluginInstance, WebpackError, InputFileSystem } from 'webpack';\n\nimport { Async, Sort, LegacyAdapters, FileSystem } from '@rushstack/node-core-library';\nimport type { IPackageJson } from '@rushstack/node-core-library';\n\nimport { LICENSE_FILES_REGEXP, COPYRIGHT_REGEX } from './regexpUtils';\n\nconst PLUGIN_NAME: 'EmbeddedDependenciesWebpackPlugin' = 'EmbeddedDependenciesWebpackPlugin';\nconst PLUGIN_ERROR_PREFIX: string = '[embedded-dependencies-webpack-plugin]';\nconst DEFAULT_GENERATED_LICENSE_FILE_NAME: 'THIRD-PARTY-NOTICES.html' = 'THIRD-PARTY-NOTICES.html';\nconst DEFAULT_EMBEDDED_DEPENDENCIES_FILE_NAME: 'embedded-dependencies.json' = 'embedded-dependencies.json';\nconst DEFAULT_PACKAGE_FILTER_FUNCTION: (packageJson: IPackageData, filePath: string) => boolean = () => true;\n\ninterface IEmbeddedDependenciesFile {\n name?: string;\n version?: string;\n embeddedDependencies: IPackageData[];\n}\n\ninterface IResourceResolveData {\n descriptionFileData?: IPackageData;\n descriptionFileRoot?: string;\n relativePath?: string;\n}\n\ninterface IWebpackModuleCreateData {\n resourceResolveData?: IResourceResolveData;\n}\n\n/**\n * @beta\n * Data type for a package.json file. This is a superset of the full package.json file and includes additional fields\n * that are generated by the plugin, including licenseSource, licenses, copyright, and author.\n */\nexport interface IPackageData extends IPackageJson {\n /**\n * A small string subset which is used for copyright extraction from a licenseSource file.\n */\n copyright: string | undefined;\n /**\n * The author of the package. This is a superset of the full package.json author field.\n * Grabs either the author field or author.name field from package.json.\n */\n author?: string | { name?: string };\n /**\n * Additional license metadata if present. May contain information about a project which has multiple licenses.\n */\n licenses?: { type: string; url: string }[];\n\n /**\n * The source of the license file itself used for generating THIRD-PARTY-NOTICES.html or custom license files.\n */\n licenseSource?: string;\n}\n\n/**\n * @beta\n * Plugin options for EmbeddedDependenciesWebpackPlugin\n *\n * @param outputFileName - Name of the file to be generated. Defaults to embedded-dependencies.json\n * @param generateLicenseFile - Whether to generate a license file. Defaults to false and will only generate the embedded-dependencies.json file\n * @param generateLicenseFileFunction - Function that generates the license file. Defaults to the plugin's internal default generator function but allows you to override it\n * @param generatedLicenseFilename - Name of the generated license file. Defaults to THIRD-PARTY-NOTICES.html\n *\n * @example\n * ```ts\n * // webpack.config.js\n * plugins: [\n * new EmbeddedDependenciesWebpackPlugin({\n * outputFileName: 'custom-file-name.json',\n * generateLicenseFile: true,\n * generateLicenseFileFunction: (packages: IPackageData[]) => {\n * return packages\n * .map((pkg) => {\n * return `<h2>${pkg.name}</h2><p>${pkg.license}</p>`;\n * }).join('');\n * },\n * generatedLicenseFilename: 'custom-license-file-name.html'\n * })\n * ]\n * ```\n */\nexport interface IEmbeddedDependenciesWebpackPluginOptions {\n /**\n * Name of the file to be generated. Defaults to embedded-dependencies.json\n */\n outputFileName?: string;\n /**\n * Whether to generate a license file. Defaults to false and will only generate the embedded-dependencies.json file\n */\n generateLicenseFile?: boolean;\n /**\n * Function that generates the license file. Defaults to the plugin's internal default generator function but allows you to override it\n */\n generateLicenseFileFunction?: LicenseFileGeneratorFunction;\n /**\n * Name of the generated license file. Defaults to THIRD-PARTY-NOTICES.html\n */\n generatedLicenseFilename?: LicenseFileName;\n\n /**\n * Predicate function that determines whether a package should be included in the embedded\n * dependencies file or the generated license file.\n */\n packageFilterPredicate?: (packageJson: IPackageData, filePath: string) => boolean;\n}\n\n/**\n * @beta\n * Function type that generates the license file.\n *\n * @example\n * ```ts\n * const licenseFileGenerator: LicenseFileGeneratorFunction = (packages: IPackageData[]): string => {\n * return packages\n * .map((pkg) => {\n * return `<h2>${pkg.name}</h2><p>${pkg.license}</p>`;\n * }).join('');\n * }\n * ```\n */\nexport type LicenseFileGeneratorFunction = (packages: IPackageData[]) => string;\n\n/**\n * @beta\n * Loose string type that represents the name of the generated license file.\n *\n * @example\n * ```ts\n * const licenseFileName: LicenseFileName = 'custom-license-file-name.html';\n * const licenseMarkdownFileName: LicenseFileName = 'custom-license-file-name.md';\n * const licenseTextFileName: LicenseFileName = 'custom-license-file-name.txt';\n * ```\n */\nexport type LicenseFileName = `${string}.${'html' | 'md' | 'txt'}`;\n\ntype PackageNameAndVersion = `${string}@${string}`;\ntype ThirdPartyPackageMap = Map<\n PackageNameAndVersion,\n { packageFolderPath: string; packageJsonData: IPackageData }\n>;\ntype DefaultLicenseTemplate = `<hr />${string}<br /><br />${string}`;\n\n/**\n * @beta\n * Webpack plugin that generates a file with the list of embedded dependencies\n * and their licenses.\n */\nexport default class EmbeddedDependenciesWebpackPlugin implements WebpackPluginInstance {\n private readonly _outputFileName: string;\n private readonly _generateLicenseFile: boolean;\n private readonly _generateLicenseFileFunction: LicenseFileGeneratorFunction;\n private readonly _generatedLicenseFilename: LicenseFileName;\n private readonly _packageFilterFunction: (packageJson: IPackageData, filePath: string) => boolean;\n\n public constructor(options?: IEmbeddedDependenciesWebpackPluginOptions) {\n this._outputFileName = options?.outputFileName || DEFAULT_EMBEDDED_DEPENDENCIES_FILE_NAME;\n this._generateLicenseFile = options?.generateLicenseFile || false;\n this._generateLicenseFileFunction =\n options?.generateLicenseFileFunction || this._defaultLicenseFileGenerator;\n this._generatedLicenseFilename = options?.generatedLicenseFilename || DEFAULT_GENERATED_LICENSE_FILE_NAME;\n this._packageFilterFunction = options?.packageFilterPredicate || DEFAULT_PACKAGE_FILTER_FUNCTION;\n }\n\n /**\n * @beta\n * Webpack plugin apply method. This method is called by the webpack compiler to apply the plugin, however it not usually\n * needed to be invoked manually by the developer in a webpack configuration. However, if you are calling this plugin (applying it from another plugin)\n * you can call `plugin.apply(compiler)` to apply the plugin and invoke it.\n * @param compiler - The webpack compiler instance.\n */\n public apply(compiler: Compiler): void {\n const { sources, Compilation } = compiler.webpack;\n // Tap into compilation so we can tap into compilation.hooks.processAssets\n compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation, { normalModuleFactory }) => {\n const thirdPartyPackages: ThirdPartyPackageMap = new Map();\n\n normalModuleFactory.hooks.module.tap(\n PLUGIN_NAME,\n (module, moduleCreateData: IWebpackModuleCreateData, resolveData) => {\n const { resourceResolveData } = moduleCreateData;\n const pkg: IPackageData | undefined = resourceResolveData?.descriptionFileData;\n const filePath: string | undefined = resourceResolveData?.descriptionFileRoot;\n\n if (\n pkg &&\n filePath &&\n this._packageFilterFunction(pkg, filePath) &&\n filePath?.includes('node_modules')\n ) {\n const key: PackageNameAndVersion = makePackageMapKeyForPackage(pkg);\n thirdPartyPackages.set(key, { packageFolderPath: filePath, packageJsonData: pkg });\n }\n\n return module;\n }\n );\n\n compilation.hooks.processAssets.tapPromise(\n { name: PLUGIN_NAME, stage: Compilation.PROCESS_ASSETS_STAGE_REPORT },\n async (assets) => {\n const packages: IPackageData[] = [];\n\n try {\n await Async.forEachAsync(\n thirdPartyPackages,\n async ([, { packageFolderPath: dir, packageJsonData: data }]) => {\n const { name, version } = data;\n let licenseSource: string | undefined;\n const license: string | undefined = parseLicense(data);\n const licensePath: string | undefined = await this._getLicenseFilePathAsync(dir, compiler);\n if (licensePath) {\n licenseSource = await FileSystem.readFileAsync(licensePath);\n\n const copyright: string | undefined =\n this._parseCopyright(licenseSource) || parsePackageAuthor(data);\n\n packages.push({\n name,\n version,\n license,\n licenseSource,\n copyright\n });\n } else {\n // If there is no license file path, we still should populate the other required fields\n const copyright: string | undefined = parsePackageAuthor(data);\n\n packages.push({\n name,\n version,\n license,\n copyright\n });\n }\n }\n );\n } catch (error) {\n this._emitWebpackError(compilation, 'Failed to process embedded dependencies', error);\n } finally {\n Sort.sortBy(packages, (pkg) => pkg.name);\n }\n\n const dataToStringify: IEmbeddedDependenciesFile = {\n embeddedDependencies: packages\n };\n\n compilation.emitAsset(this._outputFileName, new sources.RawSource(JSON.stringify(dataToStringify)));\n\n if (this._generateLicenseFile) {\n // We should try catch here because generator function can be output from user config\n try {\n compilation.emitAsset(\n this._generatedLicenseFilename,\n new sources.RawSource(this._generateLicenseFileFunction(packages))\n );\n } catch (error: unknown) {\n this._emitWebpackError(compilation, 'Failed to generate license file', error);\n }\n }\n\n return;\n }\n );\n });\n }\n\n /**\n * Default error handler for try/catch blocks in the plugin\n * try/catches emit errors of type `unknown` and we need to handle them based on what\n * type the error is. This function provides a convenient way to handle errors and then\n * propagate them to webpack as WebpackError objects on `compilation.errors` array.\n *\n * @remarks\n * _If we need to push errors to `compilation.warnings` array, we should just create a companion function\n * that does the same thing but pushes to `compilation.warnings` array instead._\n *\n * @example\n * ```typescript\n * try {\n * // do some operation\n * FileSystem.readFile('some-file');\n * } catch (error: unknown) {\n * this._emitWebpackError(compilation, 'Failed to do some operation', error);\n * }\n * ```\n */\n private _emitWebpackError(compilation: Compilation, errorMessage: string, error: unknown): void {\n let emittedError: WebpackError;\n const { WebpackError } = compilation.compiler.webpack;\n // If the error is a string, we can just emit it as is with message prefix and error message\n if (typeof error === 'string') {\n emittedError = new WebpackError(`${PLUGIN_ERROR_PREFIX}: ${errorMessage}: ${error}`);\n // If error is an instance of Error, we can emit it with message prefix, error message and stack trace\n } else if (error instanceof Error) {\n emittedError = new WebpackError(\n `${PLUGIN_ERROR_PREFIX}: ${errorMessage}: ${error.message}\\n${error.stack || ''}`\n );\n // If error is not a string or an instance of Error, we can emit it with message prefix and error message and JSON.stringify it\n } else {\n emittedError = new WebpackError(\n `${PLUGIN_ERROR_PREFIX}: ${errorMessage}: ${JSON.stringify(error || '')}`\n );\n }\n\n compilation.errors.push(emittedError);\n }\n\n /**\n * Searches a third party package directory for a license file.\n */\n private async _getLicenseFilePathAsync(\n modulePath: string,\n compiler: Compiler\n ): Promise<string | undefined> {\n type InputFileSystemReadDirResults = Parameters<Parameters<InputFileSystem['readdir']>[2]>[1];\n\n const { inputFileSystem } = compiler;\n if (!inputFileSystem) {\n throw new Error(`Compiler.inputFileSystem is not defined`);\n }\n\n const files: InputFileSystemReadDirResults = await LegacyAdapters.convertCallbackToPromise(\n inputFileSystem.readdir,\n modulePath,\n { withFileTypes: true }\n );\n\n if (!files) {\n return;\n }\n\n for (const file of files) {\n if (file.isFile() && LICENSE_FILES_REGEXP.test(file.name)) {\n // Grabbing the first license file if multiple are found\n return path.join(modulePath, file.name);\n }\n }\n }\n\n /**\n * Given a module path, try to parse the module's copyright attribution.\n */\n private _parseCopyright(licenseSource: string): string | undefined {\n const match: RegExpMatchArray | null = licenseSource.match(COPYRIGHT_REGEX);\n\n if (match) {\n return match[0];\n }\n\n return undefined;\n }\n\n private _defaultLicenseFileGenerator(packages: IPackageData[]): string {\n const licenseContent = (pkg: IPackageData): string =>\n pkg.licenseSource || pkg.copyright || 'License or Copyright not found';\n\n const licenseTemplateForPackage = (pkg: IPackageData): DefaultLicenseTemplate => {\n return `<hr />${pkg.name} - ${pkg.version}<br /><br />${licenseContent(pkg)}`;\n };\n\n return packages.map(licenseTemplateForPackage).join('\\n');\n }\n}\n\nfunction makePackageMapKeyForPackage(pkg: IPackageData): PackageNameAndVersion {\n return `${pkg.name}@${pkg.version}`;\n}\n\n/**\n * Returns the license type\n */\nfunction parseLicense(packageData: IPackageData): string | undefined {\n if (packageData.license) {\n return packageData.license;\n } else if (typeof packageData.licenses === 'string') {\n return packageData.licenses;\n } else if (packageData.licenses?.length) {\n return packageData.licenses.length === 1\n ? packageData.licenses[0].type\n : `(${packageData.licenses\n .map((license: { type: string; url: string }) => license.type)\n .join(' OR ')})`;\n }\n\n return undefined;\n}\n\nfunction parsePackageAuthor(p: IPackageData): string | undefined {\n return typeof p.author === 'string' ? p.author : p.author?.name;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/webpack-embedded-dependencies-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "This plugin analyzes bundled dependencies from Node Modules for use with Component Governance and License Scanning.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "dist/webpack-embedded-dependencies-plugin.d.ts",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"directory": "webpack/webpack-embedded-dependencies-plugin"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@rushstack/node-core-library": "5.
|
|
14
|
+
"@rushstack/node-core-library": "5.16.0"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"webpack": "^5.35.1"
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"eslint": "~9.25.1",
|
|
26
26
|
"webpack": "~5.98.0",
|
|
27
27
|
"memfs": "4.12.0",
|
|
28
|
-
"@rushstack/webpack-plugin-utilities": "0.
|
|
29
|
-
"@rushstack/heft": "1.
|
|
28
|
+
"@rushstack/webpack-plugin-utilities": "0.5.0",
|
|
29
|
+
"@rushstack/heft": "1.1.0",
|
|
30
30
|
"local-node-rig": "1.0.0"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|