generate-license-file-webpack-plugin
Version:
Webpack plugin to generate a text file asset containing all of the licenses for your production third-party dependencies.
43 lines • 1.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.asyncProcessAssetTapFactory = void 0;
const generate_license_file_1 = require("generate-license-file");
const posix_1 = require("path/posix");
const webpack_1 = require("webpack");
const devImplementation_1 = require("./devImplementation");
const licenseFilePlugin_1 = require("./licenseFilePlugin");
const unknownError = "Unknown Error! Check for error output above.";
const asyncProcessAssetTapFactory = (options, compiler, compilation) => {
const pluginName = licenseFilePlugin_1.LicenseFilePlugin.name;
const { outputFileName, outputFolder, isDev, pathToPackageJson, lineEnding, append, exclude, replace, } = options;
const getLicenseFileTextOptions = {
lineEnding,
append,
exclude,
replace,
};
const RawSource = compiler.webpack.sources.RawSource;
return (_, resolve) => {
const implementation = resolveImplementation(isDev);
implementation(pathToPackageJson, getLicenseFileTextOptions)
.then(text => {
const outputPath = (0, posix_1.join)(outputFolder, outputFileName);
compilation.emitAsset(outputPath, new RawSource(text));
resolve();
})
.catch(error => {
const errorMessage = `${pluginName}: ${error !== null && error !== void 0 ? error : unknownError}`;
const webpackError = new webpack_1.WebpackError(errorMessage);
compilation.errors.push(webpackError);
resolve(webpackError);
});
};
};
exports.asyncProcessAssetTapFactory = asyncProcessAssetTapFactory;
const resolveImplementation = (isDev) => {
if (isDev) {
return devImplementation_1.devImplementation;
}
return generate_license_file_1.getLicenseFileText;
};
//# sourceMappingURL=asyncProcessAssetTapFactory.js.map