Deployed the page to Github Pages.

This commit is contained in:
Batuhan Berk Başoğlu 2024-11-03 21:30:09 -05:00
parent 1d79754e93
commit 2c89899458
Signed by: batuhan-basoglu
SSH key fingerprint: SHA256:kEsnuHX+qbwhxSAXPUQ4ox535wFHu/hIRaa53FzxRpo
62797 changed files with 6551425 additions and 15279 deletions

View file

@ -0,0 +1,9 @@
import { WebpackChunk } from './WebpackChunk';
import { WebpackCompilation } from './WebpackCompilation';
import { LicenseIdentifiedModule } from './LicenseIdentifiedModule';
interface AssetManager {
writeChunkLicenses(modules: LicenseIdentifiedModule[], compilation: WebpackCompilation, chunk: WebpackChunk): void;
writeChunkBanners(modules: LicenseIdentifiedModule[], compilation: WebpackCompilation, chunk: WebpackChunk): void;
writeAllLicenses(modules: LicenseIdentifiedModule[], compilation: WebpackCompilation): void;
}
export { AssetManager };

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,7 @@
import { IncludeExcludeTest } from './IncludeExcludeTest';
declare class ChunkIncludeExcludeTester {
private includeExcludeTest;
constructor(includeExcludeTest: IncludeExcludeTest);
isIncluded(chunkName: string): boolean;
}
export { ChunkIncludeExcludeTester };

View file

@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChunkIncludeExcludeTester = void 0;
var ChunkIncludeExcludeTester = /** @class */ (function () {
function ChunkIncludeExcludeTester(includeExcludeTest) {
this.includeExcludeTest = includeExcludeTest;
}
ChunkIncludeExcludeTester.prototype.isIncluded = function (chunkName) {
if (typeof this.includeExcludeTest === 'function') {
return this.includeExcludeTest(chunkName);
}
// only include
if (this.includeExcludeTest.include && !this.includeExcludeTest.exclude) {
return this.includeExcludeTest.include.indexOf(chunkName) > -1;
}
// only exclude
if (this.includeExcludeTest.exclude && !this.includeExcludeTest.include) {
// included as long as it's not excluded
return !(this.includeExcludeTest.exclude.indexOf(chunkName) > -1);
}
// include and exclude together
if (this.includeExcludeTest.include && this.includeExcludeTest.exclude) {
return (!(this.includeExcludeTest.exclude.indexOf(chunkName) > -1) &&
this.includeExcludeTest.include.indexOf(chunkName) > -1);
}
return true;
};
return ChunkIncludeExcludeTester;
}());
exports.ChunkIncludeExcludeTester = ChunkIncludeExcludeTester;

View file

@ -0,0 +1,43 @@
import { LicenseTest } from './LicenseTest';
import { LicenseIdentifiedModule } from './LicenseIdentifiedModule';
import { IncludeExcludeTest } from './IncludeExcludeTest';
import { Module } from './Module';
import { ConstructedStats } from './ConstructedStats';
interface ConstructedOptions {
buildRoot: string;
licenseInclusionTest: LicenseTest;
unacceptableLicenseTest: LicenseTest;
handleUnacceptableLicense: (packageName: string, licenseType: string) => void;
handleMissingLicenseText: (packageName: string, licenseType: string | null) => string | null;
perChunkOutput: boolean;
licenseTemplateDir?: string;
licenseFileOverrides: {
[key: string]: string;
};
licenseTextOverrides: {
[key: string]: string;
};
licenseTypeOverrides: {
[key: string]: string;
};
renderLicenses: (modules: LicenseIdentifiedModule[]) => string;
renderBanner: (filename: string, modules: LicenseIdentifiedModule[]) => string;
outputFilename: string;
addBanner: boolean;
chunkIncludeExcludeTest: IncludeExcludeTest;
modulesDirectories: string[] | null;
additionalChunkModules: {
[chunkName: string]: Module[];
};
additionalModules: Module[];
preferredLicenseTypes: string[];
handleLicenseAmbiguity: (packageName: string, licenses: {
type: string;
url: string;
}[]) => string;
handleMissingLicenseType: (packageName: string) => string | null;
excludedPackageTest: (packageName: string) => boolean;
stats: ConstructedStats;
skipChildCompilers: boolean;
}
export { ConstructedOptions };

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,5 @@
interface ConstructedStats {
warnings: boolean;
errors: boolean;
}
export { ConstructedStats };

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,8 @@
import { LicenseIdentifiedModule } from './LicenseIdentifiedModule';
interface FileHandler {
getModule(filename: string | null | undefined): LicenseIdentifiedModule | null;
isBuildRoot(filename: string): boolean;
isInModuleDirectory(filename: string): boolean;
excludedPackageTest(filename: string): boolean;
}
export { FileHandler };

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,11 @@
interface FileSystem {
pathSeparator: string;
pathExists(filename: string): boolean;
isFileInDirectory(filename: string, directory: string): boolean;
readFileAsUtf8(filename: string): string;
join(...paths: string[]): string;
resolvePath(path: string): string;
listPaths(dir: string): string[];
isDirectory(dir: string): boolean;
}
export { FileSystem };

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,5 @@
declare type IncludeExcludeTest = {
include?: string[];
exclude?: string[];
} | ((chunkName: string) => boolean);
export { IncludeExcludeTest };

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,4 @@
declare type LicenseFileOverrides = {
[key: string]: string;
};
export { LicenseFileOverrides };

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,8 @@
import { Module } from './Module';
import { PackageJson } from './PackageJson';
interface LicenseIdentifiedModule extends Module {
packageJson?: PackageJson;
licenseId?: string | null;
licenseText?: string | null;
}
export { LicenseIdentifiedModule };

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,7 @@
interface LicensePolicy {
isLicenseWrittenFor(licenseType: string | null): boolean;
isLicenseUnacceptableFor(licenseType: string | null): boolean;
handleUnacceptableLicense(packageName: string, licenseType: string | null): void;
handleMissingLicenseText(packageName: string, licenseType: string | null): void;
}
export { LicensePolicy };

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,2 @@
declare type LicenseTest = (licenseName: string) => boolean;
export { LicenseTest };

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,4 @@
interface LicenseTestRunner {
test(licenseId: string): boolean;
}
export { LicenseTestRunner };

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,4 @@
declare type LicenseTextOverrides = {
[key: string]: string;
};
export { LicenseTextOverrides };

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,19 @@
import { LicenseTextOverrides } from './LicenseTextOverrides';
import { FileSystem } from './FileSystem';
import { Module } from './Module';
import { LicenseFileOverrides } from './LicenseFilesOverrides';
import { WebpackCompilation } from './WebpackCompilation';
import { Logger } from './Logger';
declare class LicenseTextReader {
private logger;
private fileSystem;
private fileOverrides;
private textOverrides;
private templateDir;
private handleMissingLicenseText;
constructor(logger: Logger, fileSystem: FileSystem, fileOverrides: LicenseFileOverrides, textOverrides: LicenseTextOverrides, templateDir: string | undefined, handleMissingLicenseText: (packageName: string, licenseType: string | null) => string | null);
readLicense(compilation: WebpackCompilation, module: Module, licenseType: string | null): string | null;
readText(directory: string, filename: string): string;
private guessLicenseFilename;
}
export { LicenseTextReader };

View file

@ -0,0 +1,81 @@
"use strict";
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LicenseTextReader = void 0;
var LicenseTextReader = /** @class */ (function () {
function LicenseTextReader(logger, fileSystem, fileOverrides, textOverrides, templateDir, handleMissingLicenseText) {
this.logger = logger;
this.fileSystem = fileSystem;
this.fileOverrides = fileOverrides;
this.textOverrides = textOverrides;
this.templateDir = templateDir;
this.handleMissingLicenseText = handleMissingLicenseText;
}
LicenseTextReader.prototype.readLicense = function (compilation, module, licenseType) {
if (this.textOverrides[module.name]) {
return this.textOverrides[module.name];
}
if (this.fileOverrides[module.name]) {
return this.readText(module.directory, this.fileOverrides[module.name]);
}
if (licenseType && licenseType.indexOf('SEE LICENSE IN ') === 0) {
var filename = licenseType.split(' ')[3];
return this.fileSystem.isFileInDirectory(filename, module.directory)
? this.readText(module.directory, filename)
: null;
}
var pathsInModuleDirectory = this.fileSystem.listPaths(module.directory);
var guessedLicenseFilename = this.guessLicenseFilename(pathsInModuleDirectory, module.directory);
if (guessedLicenseFilename !== null) {
return this.readText(module.directory, guessedLicenseFilename);
}
if (this.templateDir) {
var templateFilename = licenseType + ".txt";
var templateFilePath = this.fileSystem.join(this.templateDir, templateFilename);
if (this.fileSystem.isFileInDirectory(templateFilePath, this.templateDir)) {
return this.fileSystem
.readFileAsUtf8(templateFilePath)
.replace(/\r\n/g, '\n');
}
}
this.logger.warn(compilation, "could not find any license file for " + module.name + ". Use the licenseTextOverrides option to add the license text if desired.");
return this.handleMissingLicenseText(module.name, licenseType);
};
LicenseTextReader.prototype.readText = function (directory, filename) {
return this.fileSystem
.readFileAsUtf8(this.fileSystem.join(directory, filename))
.replace(/\r\n/g, '\n');
};
LicenseTextReader.prototype.guessLicenseFilename = function (paths, modulePath) {
var e_1, _a;
try {
for (var paths_1 = __values(paths), paths_1_1 = paths_1.next(); !paths_1_1.done; paths_1_1 = paths_1.next()) {
var path = paths_1_1.value;
var filePath = this.fileSystem.join(modulePath, path);
if (/^licen[cs]e/i.test(path) && !this.fileSystem.isDirectory(filePath)) {
return path;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (paths_1_1 && !paths_1_1.done && (_a = paths_1.return)) _a.call(paths_1);
}
finally { if (e_1) throw e_1.error; }
}
return null;
};
return LicenseTextReader;
}());
exports.LicenseTextReader = LicenseTextReader;

View file

@ -0,0 +1,6 @@
import { PackageJson } from './PackageJson';
import { WebpackCompilation } from './WebpackCompilation';
interface LicenseTypeIdentifier {
findLicenseIdentifier(compilation: WebpackCompilation, packageName: string, packageJson: PackageJson): string | null;
}
export { LicenseTypeIdentifier };

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,4 @@
declare type LicenseTypeOverrides = {
[key: string]: string;
} | null;
export { LicenseTypeOverrides };

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,9 @@
import { WebpackCompiler } from './WebpackCompiler';
import { WebpackPlugin } from './WebpackPlugin';
import { PluginOptions } from './PluginOptions';
declare class LicenseWebpackPlugin implements WebpackPlugin {
private pluginOptions;
constructor(pluginOptions?: PluginOptions);
apply(compiler: WebpackCompiler): void;
}
export { LicenseWebpackPlugin };

View file

@ -0,0 +1,44 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LicenseWebpackPlugin = void 0;
var ChunkIncludeExcludeTester_1 = require("./ChunkIncludeExcludeTester");
var PluginChunkReadHandler_1 = require("./PluginChunkReadHandler");
var PluginFileHandler_1 = require("./PluginFileHandler");
var WebpackFileSystem_1 = require("./WebpackFileSystem");
var PluginLicenseTypeIdentifier_1 = require("./PluginLicenseTypeIdentifier");
var LicenseTextReader_1 = require("./LicenseTextReader");
var WebpackCompilerHandler_1 = require("./WebpackCompilerHandler");
var PluginModuleCache_1 = require("./PluginModuleCache");
var WebpackAssetManager_1 = require("./WebpackAssetManager");
var PluginLicensesRenderer_1 = require("./PluginLicensesRenderer");
var PluginLicensePolicy_1 = require("./PluginLicensePolicy");
var PluginLicenseTestRunner_1 = require("./PluginLicenseTestRunner");
var PluginOptionsReader_1 = require("./PluginOptionsReader");
var Logger_1 = require("./Logger");
var LicenseWebpackPlugin = /** @class */ (function () {
function LicenseWebpackPlugin(pluginOptions) {
if (pluginOptions === void 0) { pluginOptions = {}; }
this.pluginOptions = pluginOptions;
}
LicenseWebpackPlugin.prototype.apply = function (compiler) {
var fileSystem = new WebpackFileSystem_1.WebpackFileSystem(compiler.inputFileSystem);
var optionsReader = new PluginOptionsReader_1.PluginOptionsReader(compiler.context);
var options = optionsReader.readOptions(this.pluginOptions);
var logger = new Logger_1.Logger(options.stats);
var fileHandler = new PluginFileHandler_1.PluginFileHandler(fileSystem, options.buildRoot, options.modulesDirectories, options.excludedPackageTest);
var licenseTypeIdentifier = new PluginLicenseTypeIdentifier_1.PluginLicenseTypeIdentifier(logger, options.licenseTypeOverrides, options.preferredLicenseTypes, options.handleLicenseAmbiguity, options.handleMissingLicenseType);
var licenseTextReader = new LicenseTextReader_1.LicenseTextReader(logger, fileSystem, options.licenseFileOverrides, options.licenseTextOverrides, options.licenseTemplateDir, options.handleMissingLicenseText);
var licenseTestRunner = new PluginLicenseTestRunner_1.PluginLicenseTestRunner(options.licenseInclusionTest);
var unacceptableLicenseTestRunner = new PluginLicenseTestRunner_1.PluginLicenseTestRunner(options.unacceptableLicenseTest);
var policy = new PluginLicensePolicy_1.PluginLicensePolicy(licenseTestRunner, unacceptableLicenseTestRunner, options.handleUnacceptableLicense, options.handleMissingLicenseText);
var readHandler = new PluginChunkReadHandler_1.PluginChunkReadHandler(logger, fileHandler, licenseTypeIdentifier, licenseTextReader, policy, fileSystem);
var licenseRenderer = new PluginLicensesRenderer_1.PluginLicensesRenderer(options.renderLicenses, options.renderBanner);
var moduleCache = new PluginModuleCache_1.PluginModuleCache();
var assetManager = new WebpackAssetManager_1.WebpackAssetManager(options.outputFilename, licenseRenderer);
var chunkIncludeExcludeTester = new ChunkIncludeExcludeTester_1.ChunkIncludeExcludeTester(options.chunkIncludeExcludeTest);
var handler = new WebpackCompilerHandler_1.WebpackCompilerHandler(chunkIncludeExcludeTester, readHandler, assetManager, moduleCache, options.addBanner, options.perChunkOutput, options.additionalChunkModules, options.additionalModules, options.skipChildCompilers);
handler.handleCompiler(compiler);
};
return LicenseWebpackPlugin;
}());
exports.LicenseWebpackPlugin = LicenseWebpackPlugin;

View file

@ -0,0 +1,6 @@
import { LicenseIdentifiedModule } from './LicenseIdentifiedModule';
interface LicensesRenderer {
renderLicenses(modules: LicenseIdentifiedModule[]): string;
renderBanner(filename: string, modules: LicenseIdentifiedModule[]): string;
}
export { LicensesRenderer };

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

10
node_modules/license-webpack-plugin/dist/Logger.d.ts generated vendored Normal file
View file

@ -0,0 +1,10 @@
import { ConstructedStats } from './ConstructedStats';
import { WebpackCompilation } from './WebpackCompilation';
declare class Logger {
private stats;
private static LOG_PREFIX;
constructor(stats: ConstructedStats);
warn(compilation: WebpackCompilation, message: string): void;
error(compilation: WebpackCompilation, message: string): void;
}
export { Logger };

21
node_modules/license-webpack-plugin/dist/Logger.js generated vendored Normal file
View file

@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
var Logger = /** @class */ (function () {
function Logger(stats) {
this.stats = stats;
}
Logger.prototype.warn = function (compilation, message) {
if (this.stats.warnings) {
compilation.warnings.push("" + Logger.LOG_PREFIX + message);
}
};
Logger.prototype.error = function (compilation, message) {
if (this.stats.errors) {
compilation.errors.push("" + Logger.LOG_PREFIX + message);
}
};
Logger.LOG_PREFIX = 'license-webpack-plugin: ';
return Logger;
}());
exports.Logger = Logger;

5
node_modules/license-webpack-plugin/dist/Module.d.ts generated vendored Normal file
View file

@ -0,0 +1,5 @@
interface Module {
name: string;
directory: string;
}
export { Module };

2
node_modules/license-webpack-plugin/dist/Module.js generated vendored Normal file
View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,10 @@
import { LicenseIdentifiedModule } from './LicenseIdentifiedModule';
interface ModuleCache {
registerModule(chunkName: string, module: LicenseIdentifiedModule): void;
markSeenForChunk(chunkName: string, packageName: string): void;
alreadySeenForChunk(chunkName: string, packageName: string): boolean;
getModule(packageName: string): LicenseIdentifiedModule | null;
getAllModulesForChunk(chunkName: string): LicenseIdentifiedModule[];
getAllModules(): LicenseIdentifiedModule[];
}
export { ModuleCache };

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,13 @@
interface PackageJson {
name: string;
license?: string | {
type: string;
url: string;
};
licenses?: {
type: string;
url: string;
}[];
version: string;
}
export { PackageJson };

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,28 @@
import { WebpackChunkHandler } from './WebpackChunkHandler';
import { WebpackChunk } from './WebpackChunk';
import { FileHandler } from './FileHandler';
import { LicenseTypeIdentifier } from './LicenseTypeIdentifier';
import { FileSystem } from './FileSystem';
import { LicenseTextReader } from './LicenseTextReader';
import { ModuleCache } from './ModuleCache';
import { LicensePolicy } from './LicensePolicy';
import { LicenseIdentifiedModule } from './LicenseIdentifiedModule';
import { WebpackCompilation } from './WebpackCompilation';
import { Logger } from './Logger';
import { WebpackStats } from './WebpackStats';
declare class PluginChunkReadHandler implements WebpackChunkHandler {
private logger;
private fileHandler;
private licenseTypeIdentifier;
private licenseTextReader;
private licensePolicy;
private fileSystem;
private moduleIterator;
private innerModuleIterator;
constructor(logger: Logger, fileHandler: FileHandler, licenseTypeIdentifier: LicenseTypeIdentifier, licenseTextReader: LicenseTextReader, licensePolicy: LicensePolicy, fileSystem: FileSystem);
processChunk(compilation: WebpackCompilation, chunk: WebpackChunk, moduleCache: ModuleCache, stats: WebpackStats | undefined): void;
private extractIdentifiedModule;
private getPackageJson;
processModule(compilation: WebpackCompilation, chunk: WebpackChunk, moduleCache: ModuleCache, module: LicenseIdentifiedModule): void;
}
export { PluginChunkReadHandler };

View file

@ -0,0 +1,86 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PluginChunkReadHandler = void 0;
var WebpackChunkModuleIterator_1 = require("./WebpackChunkModuleIterator");
var WebpackInnerModuleIterator_1 = require("./WebpackInnerModuleIterator");
var PluginChunkReadHandler = /** @class */ (function () {
function PluginChunkReadHandler(logger, fileHandler, licenseTypeIdentifier, licenseTextReader, licensePolicy, fileSystem) {
this.logger = logger;
this.fileHandler = fileHandler;
this.licenseTypeIdentifier = licenseTypeIdentifier;
this.licenseTextReader = licenseTextReader;
this.licensePolicy = licensePolicy;
this.fileSystem = fileSystem;
this.moduleIterator = new WebpackChunkModuleIterator_1.WebpackChunkModuleIterator();
this.innerModuleIterator = new WebpackInnerModuleIterator_1.WebpackInnerModuleIterator(require.resolve);
}
PluginChunkReadHandler.prototype.processChunk = function (compilation, chunk, moduleCache, stats) {
var _this = this;
this.moduleIterator.iterateModules(compilation, chunk, stats, function (chunkModule) {
_this.innerModuleIterator.iterateModules(chunkModule, function (module) {
var identifiedModule = _this.extractIdentifiedModule(module) ||
_this.fileHandler.getModule(module.resource);
if (identifiedModule) {
_this.processModule(compilation, chunk, moduleCache, identifiedModule);
}
});
});
};
PluginChunkReadHandler.prototype.extractIdentifiedModule = function (module) {
var resolved = module.resourceResolveData;
if (!resolved)
return undefined;
var directory = resolved.descriptionFileRoot, packageJson = resolved.descriptionFileData;
if (
// if missing data, fall back to fs module hunting
directory &&
packageJson &&
packageJson.name &&
// user checks to decide if we should include the module
this.fileHandler.isInModuleDirectory(directory) &&
!this.fileHandler.isBuildRoot(directory) &&
!this.fileHandler.excludedPackageTest(packageJson.name)) {
return {
directory: directory,
packageJson: packageJson,
name: packageJson.name
};
}
return undefined;
};
PluginChunkReadHandler.prototype.getPackageJson = function (directory) {
var filename = "" + directory + this.fileSystem.pathSeparator + "package.json";
return JSON.parse(this.fileSystem.readFileAsUtf8(filename));
};
PluginChunkReadHandler.prototype.processModule = function (compilation, chunk, moduleCache, module) {
var _a;
if (!moduleCache.alreadySeenForChunk(chunk.name, module.name)) {
var alreadyIncludedModule = moduleCache.getModule(module.name);
if (alreadyIncludedModule !== null) {
moduleCache.registerModule(chunk.name, alreadyIncludedModule);
}
else {
// module not yet in cache
var packageJson = (_a = module.packageJson) !== null && _a !== void 0 ? _a : this.getPackageJson(module.directory);
var licenseType = this.licenseTypeIdentifier.findLicenseIdentifier(compilation, module.name, packageJson);
if (this.licensePolicy.isLicenseUnacceptableFor(licenseType)) {
this.logger.error(compilation, "unacceptable license found for " + module.name + ": " + licenseType);
this.licensePolicy.handleUnacceptableLicense(module.name, licenseType);
}
if (this.licensePolicy.isLicenseWrittenFor(licenseType)) {
var licenseText = this.licenseTextReader.readLicense(compilation, module, licenseType);
moduleCache.registerModule(chunk.name, {
licenseText: licenseText,
packageJson: packageJson,
name: module.name,
directory: module.directory,
licenseId: licenseType
});
}
}
moduleCache.markSeenForChunk(chunk.name, module.name);
}
};
return PluginChunkReadHandler;
}());
exports.PluginChunkReadHandler = PluginChunkReadHandler;

View file

@ -0,0 +1,20 @@
import { FileHandler } from './FileHandler';
import { FileSystem } from './FileSystem';
import { LicenseIdentifiedModule } from './LicenseIdentifiedModule';
declare class PluginFileHandler implements FileHandler {
private fileSystem;
private buildRoot;
private modulesDirectories;
excludedPackageTest: (packageName: string) => boolean;
private cache;
constructor(fileSystem: FileSystem, buildRoot: string, modulesDirectories: string[] | null, excludedPackageTest: (packageName: string) => boolean);
static PACKAGE_JSON: string;
getModule(filename: string): LicenseIdentifiedModule | null;
isInModuleDirectory(filename: string): boolean;
isBuildRoot(filename: string): boolean;
private getModuleInternal;
private findModuleDir;
private parsePackageJson;
private dirContainsValidPackageJson;
}
export { PluginFileHandler };

View file

@ -0,0 +1,105 @@
"use strict";
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PluginFileHandler = void 0;
var PluginFileHandler = /** @class */ (function () {
function PluginFileHandler(fileSystem, buildRoot, modulesDirectories, excludedPackageTest) {
this.fileSystem = fileSystem;
this.buildRoot = buildRoot;
this.modulesDirectories = modulesDirectories;
this.excludedPackageTest = excludedPackageTest;
this.cache = {};
}
PluginFileHandler.prototype.getModule = function (filename) {
return this.cache[filename] === undefined
? (this.cache[filename] = this.getModuleInternal(filename))
: this.cache[filename];
};
PluginFileHandler.prototype.isInModuleDirectory = function (filename) {
var e_1, _a;
if (this.modulesDirectories === null)
return true;
if (filename === null || filename === undefined)
return false;
var foundInModuleDirectory = false;
var resolvedPath = this.fileSystem.resolvePath(filename);
try {
for (var _b = __values(this.modulesDirectories), _c = _b.next(); !_c.done; _c = _b.next()) {
var modulesDirectory = _c.value;
if (resolvedPath.startsWith(this.fileSystem.resolvePath(modulesDirectory))) {
foundInModuleDirectory = true;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
return foundInModuleDirectory;
};
PluginFileHandler.prototype.isBuildRoot = function (filename) {
return this.buildRoot === filename;
};
PluginFileHandler.prototype.getModuleInternal = function (filename) {
if (filename === null || filename === undefined)
return null;
if (!this.isInModuleDirectory(filename))
return null;
var module = this.findModuleDir(filename);
if (module !== null && this.excludedPackageTest(module.name)) {
return null;
}
return module;
};
PluginFileHandler.prototype.findModuleDir = function (filename) {
var pathSeparator = this.fileSystem.pathSeparator;
var dirOfModule = filename.substring(0, filename.lastIndexOf(pathSeparator));
var oldDirOfModule = null;
while (!this.dirContainsValidPackageJson(dirOfModule)) {
// check parent directory
oldDirOfModule = dirOfModule;
dirOfModule = this.fileSystem.resolvePath("" + dirOfModule + pathSeparator + ".." + pathSeparator);
// reached filesystem root
if (oldDirOfModule === dirOfModule) {
return null;
}
}
if (this.isBuildRoot(dirOfModule)) {
return null;
}
var packageJson = this.parsePackageJson(dirOfModule);
return {
packageJson: packageJson,
name: packageJson.name,
directory: dirOfModule
};
};
PluginFileHandler.prototype.parsePackageJson = function (dirOfModule) {
var packageJsonText = this.fileSystem.readFileAsUtf8(this.fileSystem.join(dirOfModule, PluginFileHandler.PACKAGE_JSON));
var packageJson = JSON.parse(packageJsonText);
return packageJson;
};
PluginFileHandler.prototype.dirContainsValidPackageJson = function (dirOfModule) {
if (!this.fileSystem.pathExists(this.fileSystem.join(dirOfModule, PluginFileHandler.PACKAGE_JSON))) {
return false;
}
var packageJson = this.parsePackageJson(dirOfModule);
return !!packageJson.name;
};
PluginFileHandler.PACKAGE_JSON = 'package.json';
return PluginFileHandler;
}());
exports.PluginFileHandler = PluginFileHandler;

View file

@ -0,0 +1,14 @@
import { LicensePolicy } from './LicensePolicy';
import { LicenseTestRunner } from './LicenseTestRunner';
declare class PluginLicensePolicy implements LicensePolicy {
private licenseTester;
private unacceptableLicenseTester;
private unacceptableLicenseHandler;
private missingLicenseTextHandler;
constructor(licenseTester: LicenseTestRunner, unacceptableLicenseTester: LicenseTestRunner, unacceptableLicenseHandler: (packageName: string, licenseType: string) => void, missingLicenseTextHandler: (packageName: string, licenseType: string) => void);
isLicenseWrittenFor(licenseType: string): boolean;
isLicenseUnacceptableFor(licenseType: string): boolean;
handleUnacceptableLicense(packageName: string, licenseType: string): void;
handleMissingLicenseText(packageName: string, licenseType: string): void;
}
export { PluginLicensePolicy };

View file

@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PluginLicensePolicy = void 0;
var PluginLicensePolicy = /** @class */ (function () {
function PluginLicensePolicy(licenseTester, unacceptableLicenseTester, unacceptableLicenseHandler, missingLicenseTextHandler) {
this.licenseTester = licenseTester;
this.unacceptableLicenseTester = unacceptableLicenseTester;
this.unacceptableLicenseHandler = unacceptableLicenseHandler;
this.missingLicenseTextHandler = missingLicenseTextHandler;
}
PluginLicensePolicy.prototype.isLicenseWrittenFor = function (licenseType) {
return this.licenseTester.test(licenseType);
};
PluginLicensePolicy.prototype.isLicenseUnacceptableFor = function (licenseType) {
return this.unacceptableLicenseTester.test(licenseType);
};
PluginLicensePolicy.prototype.handleUnacceptableLicense = function (packageName, licenseType) {
this.unacceptableLicenseHandler(packageName, licenseType);
};
PluginLicensePolicy.prototype.handleMissingLicenseText = function (packageName, licenseType) {
this.missingLicenseTextHandler(packageName, licenseType);
};
return PluginLicensePolicy;
}());
exports.PluginLicensePolicy = PluginLicensePolicy;

View file

@ -0,0 +1,8 @@
import { LicenseTest } from './LicenseTest';
import { LicenseTestRunner } from './LicenseTestRunner';
declare class PluginLicenseTestRunner implements LicenseTestRunner {
private licenseTest;
constructor(licenseTest: LicenseTest);
test(licenseId: string): boolean;
}
export { PluginLicenseTestRunner };

View file

@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PluginLicenseTestRunner = void 0;
var PluginLicenseTestRunner = /** @class */ (function () {
function PluginLicenseTestRunner(licenseTest) {
this.licenseTest = licenseTest;
}
PluginLicenseTestRunner.prototype.test = function (licenseId) {
return this.licenseTest(licenseId);
};
return PluginLicenseTestRunner;
}());
exports.PluginLicenseTestRunner = PluginLicenseTestRunner;

View file

@ -0,0 +1,19 @@
import { LicenseTypeIdentifier } from './LicenseTypeIdentifier';
import { PackageJson } from './PackageJson';
import { LicenseTypeOverrides } from './LicenseTypeOverrides';
import { WebpackCompilation } from './WebpackCompilation';
import { Logger } from './Logger';
declare class PluginLicenseTypeIdentifier implements LicenseTypeIdentifier {
private logger;
private licenseTypeOverrides;
private preferredLicenseTypes;
private handleLicenseAmbiguity;
private handleMissingLicenseType;
constructor(logger: Logger, licenseTypeOverrides: LicenseTypeOverrides, preferredLicenseTypes: string[], handleLicenseAmbiguity: (packageName: string, licenses: {
type: string;
url: string;
}[]) => string, handleMissingLicenseType: (packageName: string) => string | null);
findLicenseIdentifier(compilation: WebpackCompilation, packageName: string, packageJson: PackageJson): string | null;
private findPreferredLicense;
}
export { PluginLicenseTypeIdentifier };

View file

@ -0,0 +1,86 @@
"use strict";
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PluginLicenseTypeIdentifier = void 0;
var PluginLicenseTypeIdentifier = /** @class */ (function () {
function PluginLicenseTypeIdentifier(logger, licenseTypeOverrides, preferredLicenseTypes, handleLicenseAmbiguity, handleMissingLicenseType) {
this.logger = logger;
this.licenseTypeOverrides = licenseTypeOverrides;
this.preferredLicenseTypes = preferredLicenseTypes;
this.handleLicenseAmbiguity = handleLicenseAmbiguity;
this.handleMissingLicenseType = handleMissingLicenseType;
}
PluginLicenseTypeIdentifier.prototype.findLicenseIdentifier = function (compilation, packageName, packageJson) {
if (this.licenseTypeOverrides && this.licenseTypeOverrides[packageName]) {
return this.licenseTypeOverrides[packageName];
}
var licensePropValue = packageJson.license;
if (licensePropValue) {
return typeof licensePropValue === 'string'
? licensePropValue
: licensePropValue.type;
}
// handle deprecated "licenses" field in package.json
if (Array.isArray(packageJson.licenses) &&
packageJson.licenses.length > 0) {
if (packageJson.licenses.length === 1) {
return packageJson.licenses[0].type;
}
// handle multiple licenses when we have a preferred license type
var licenseTypes = packageJson.licenses.map(function (x) { return x.type; });
var licenseType = this.findPreferredLicense(licenseTypes, this.preferredLicenseTypes);
if (licenseType !== null) {
// found preferred license
return licenseType;
}
var resolvedLicenseType = this.handleLicenseAmbiguity(packageName, packageJson.licenses);
this.logger.warn(compilation, packageName + " specifies multiple licenses: " + licenseTypes + ". Automatically selected " + resolvedLicenseType + ". Use the preferredLicenseTypes or the licenseTypeOverrides option to resolve this warning.");
return resolvedLicenseType;
}
this.logger.warn(compilation, "could not find any license type for " + packageName + " in its package.json");
return this.handleMissingLicenseType(packageName);
};
PluginLicenseTypeIdentifier.prototype.findPreferredLicense = function (licenseTypes, preferredLicenseTypes) {
var e_1, _a, e_2, _b;
try {
for (var preferredLicenseTypes_1 = __values(preferredLicenseTypes), preferredLicenseTypes_1_1 = preferredLicenseTypes_1.next(); !preferredLicenseTypes_1_1.done; preferredLicenseTypes_1_1 = preferredLicenseTypes_1.next()) {
var preferredLicenseType = preferredLicenseTypes_1_1.value;
try {
for (var licenseTypes_1 = (e_2 = void 0, __values(licenseTypes)), licenseTypes_1_1 = licenseTypes_1.next(); !licenseTypes_1_1.done; licenseTypes_1_1 = licenseTypes_1.next()) {
var licenseType = licenseTypes_1_1.value;
if (preferredLicenseType === licenseType) {
return preferredLicenseType;
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (licenseTypes_1_1 && !licenseTypes_1_1.done && (_b = licenseTypes_1.return)) _b.call(licenseTypes_1);
}
finally { if (e_2) throw e_2.error; }
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (preferredLicenseTypes_1_1 && !preferredLicenseTypes_1_1.done && (_a = preferredLicenseTypes_1.return)) _a.call(preferredLicenseTypes_1);
}
finally { if (e_1) throw e_1.error; }
}
return null;
};
return PluginLicenseTypeIdentifier;
}());
exports.PluginLicenseTypeIdentifier = PluginLicenseTypeIdentifier;

View file

@ -0,0 +1,8 @@
import { LicensesRenderer } from './LicensesRenderer';
import { LicenseIdentifiedModule } from './LicenseIdentifiedModule';
declare class PluginLicensesRenderer implements LicensesRenderer {
renderLicenses: (modules: LicenseIdentifiedModule[]) => string;
renderBanner: (filename: string, modules: LicenseIdentifiedModule[]) => string;
constructor(renderLicenses: (modules: LicenseIdentifiedModule[]) => string, renderBanner: (filename: string, modules: LicenseIdentifiedModule[]) => string);
}
export { PluginLicensesRenderer };

View file

@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PluginLicensesRenderer = void 0;
var PluginLicensesRenderer = /** @class */ (function () {
function PluginLicensesRenderer(renderLicenses, renderBanner) {
this.renderLicenses = renderLicenses;
this.renderBanner = renderBanner;
}
return PluginLicensesRenderer;
}());
exports.PluginLicensesRenderer = PluginLicensesRenderer;

View file

@ -0,0 +1,14 @@
import { ModuleCache } from './ModuleCache';
import { LicenseIdentifiedModule } from './LicenseIdentifiedModule';
declare class PluginModuleCache implements ModuleCache {
private totalCache;
private chunkCache;
private chunkSeenCache;
registerModule(chunkName: string, module: LicenseIdentifiedModule): void;
getModule(packageName: string): LicenseIdentifiedModule | null;
markSeenForChunk(chunkName: string, packageName: string): void;
alreadySeenForChunk(chunkName: string, packageName: string): boolean;
getAllModulesForChunk(chunkName: string): LicenseIdentifiedModule[];
getAllModules(): LicenseIdentifiedModule[];
}
export { PluginModuleCache };

View file

@ -0,0 +1,50 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PluginModuleCache = void 0;
var PluginModuleCache = /** @class */ (function () {
function PluginModuleCache() {
this.totalCache = {};
this.chunkCache = {};
this.chunkSeenCache = {};
}
PluginModuleCache.prototype.registerModule = function (chunkName, module) {
this.totalCache[module.name] = module;
if (!this.chunkCache[chunkName]) {
this.chunkCache[chunkName] = {};
}
this.chunkCache[chunkName][module.name] = module;
};
PluginModuleCache.prototype.getModule = function (packageName) {
return this.totalCache[packageName] || null;
};
PluginModuleCache.prototype.markSeenForChunk = function (chunkName, packageName) {
if (!this.chunkSeenCache[chunkName]) {
this.chunkSeenCache[chunkName] = {};
}
this.chunkSeenCache[chunkName][packageName] = true;
};
PluginModuleCache.prototype.alreadySeenForChunk = function (chunkName, packageName) {
return !!(this.chunkSeenCache[chunkName] &&
this.chunkSeenCache[chunkName][packageName]);
};
PluginModuleCache.prototype.getAllModulesForChunk = function (chunkName) {
var modules = [];
var cache = this.chunkCache[chunkName];
if (cache) {
Object.keys(cache).forEach(function (key) {
modules.push(cache[key]);
});
}
return modules;
};
PluginModuleCache.prototype.getAllModules = function () {
var _this = this;
var modules = [];
Object.keys(this.totalCache).forEach(function (key) {
modules.push(_this.totalCache[key]);
});
return modules;
};
return PluginModuleCache;
}());
exports.PluginModuleCache = PluginModuleCache;

View file

@ -0,0 +1,42 @@
import { LicenseTest } from './LicenseTest';
import { LicenseIdentifiedModule } from './LicenseIdentifiedModule';
import { IncludeExcludeTest } from './IncludeExcludeTest';
import { Module } from './Module';
import { PluginStats } from './PluginStats';
interface PluginOptions {
licenseInclusionTest?: LicenseTest;
unacceptableLicenseTest?: LicenseTest;
handleUnacceptableLicense?: (packageName: string, licenseType: string) => void;
handleMissingLicenseText?: (packageName: string, licenseType: string | null) => string | null;
perChunkOutput?: boolean;
licenseTemplateDir?: string;
licenseTextOverrides?: {
[key: string]: string;
};
licenseFileOverrides?: {
[key: string]: string;
};
licenseTypeOverrides?: {
[key: string]: string;
};
renderLicenses?: (modules: LicenseIdentifiedModule[]) => string;
renderBanner?: (filename: string, modules: LicenseIdentifiedModule[]) => string;
outputFilename?: string;
addBanner?: boolean;
chunkIncludeExcludeTest?: IncludeExcludeTest;
modulesDirectories?: string[];
additionalChunkModules?: {
[chunkName: string]: Module[];
};
additionalModules?: Module[];
preferredLicenseTypes?: string[];
handleLicenseAmbiguity?: (packageName: string, licenses: {
type: string;
url: string;
}[]) => string;
handleMissingLicenseType?: (packageName: string) => string | null;
excludedPackageTest?: (packageName: string) => boolean;
stats?: PluginStats;
skipChildCompilers?: boolean;
}
export { PluginOptions };

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,8 @@
import { ConstructedOptions } from './ConstructedOptions';
import { PluginOptions } from './PluginOptions';
declare class PluginOptionsReader {
private context;
constructor(context: string);
readOptions(options: PluginOptions): ConstructedOptions;
}
export { PluginOptionsReader };

View file

@ -0,0 +1,86 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PluginOptionsReader = void 0;
var PluginOptionsReader = /** @class */ (function () {
function PluginOptionsReader(context) {
this.context = context;
}
PluginOptionsReader.prototype.readOptions = function (options) {
var licenseInclusionTest = options.licenseInclusionTest || (function () { return true; });
var unacceptableLicenseTest = options.unacceptableLicenseTest || (function () { return false; });
var perChunkOutput = options.perChunkOutput === undefined || options.perChunkOutput;
var licenseTemplateDir = options.licenseTemplateDir;
var licenseTextOverrides = options.licenseTextOverrides || {};
var licenseTypeOverrides = options.licenseTypeOverrides || {};
var handleUnacceptableLicense = options.handleUnacceptableLicense || (function () { });
var handleMissingLicenseText = options.handleMissingLicenseText || (function () { return null; });
var renderLicenses = options.renderLicenses ||
(function (modules) {
return modules
.sort(function (left, right) {
return left.name < right.name ? -1 : 1;
})
.reduce(function (file, module) {
return "" + file + module.name + (module.licenseId ? "\n" + module.licenseId : '') + (module.licenseText ? "\n" + module.licenseText : '') + "\n\n";
}, '')
.trim() + "\n";
});
var renderBanner = options.renderBanner ||
(function (filename) {
return "/*! License information is available at " + filename + " */";
});
var outputFilename = options.outputFilename ||
(perChunkOutput ? '[name].licenses.txt' : 'licenses.txt');
var addBanner = options.addBanner === undefined ? false : options.addBanner;
var chunkIncludeExcludeTest = options.chunkIncludeExcludeTest || (function () { return true; });
var modulesDirectories = options.modulesDirectories || null;
var additionalChunkModules = options.additionalChunkModules || {};
var additionalModules = options.additionalModules || [];
var preferredLicenseTypes = options.preferredLicenseTypes || [];
var handleLicenseAmbiguity = options.handleLicenseAmbiguity ||
(function (_packageName, licenses) {
return licenses[0].type;
});
var handleMissingLicenseType = options.handleMissingLicenseType || (function () { return null; });
var licenseFileOverrides = options.licenseFileOverrides || {};
var excludedPackageTest = options.excludedPackageTest || (function () { return false; });
var stats = {
warnings: options.stats && options.stats.warnings !== undefined
? options.stats.warnings
: true,
errors: options.stats && options.stats.errors !== undefined
? options.stats.errors
: true
};
var skipChildCompilers = !!options.skipChildCompilers;
var constructedOptions = {
licenseInclusionTest: licenseInclusionTest,
unacceptableLicenseTest: unacceptableLicenseTest,
perChunkOutput: perChunkOutput,
licenseTemplateDir: licenseTemplateDir,
licenseTextOverrides: licenseTextOverrides,
licenseFileOverrides: licenseFileOverrides,
licenseTypeOverrides: licenseTypeOverrides,
handleUnacceptableLicense: handleUnacceptableLicense,
handleMissingLicenseText: handleMissingLicenseText,
renderLicenses: renderLicenses,
renderBanner: renderBanner,
outputFilename: outputFilename,
addBanner: addBanner,
chunkIncludeExcludeTest: chunkIncludeExcludeTest,
modulesDirectories: modulesDirectories,
additionalChunkModules: additionalChunkModules,
additionalModules: additionalModules,
preferredLicenseTypes: preferredLicenseTypes,
handleLicenseAmbiguity: handleLicenseAmbiguity,
handleMissingLicenseType: handleMissingLicenseType,
excludedPackageTest: excludedPackageTest,
stats: stats,
skipChildCompilers: skipChildCompilers,
buildRoot: this.context
};
return constructedOptions;
};
return PluginOptionsReader;
}());
exports.PluginOptionsReader = PluginOptionsReader;

View file

@ -0,0 +1,5 @@
interface PluginStats {
warnings?: boolean;
errors?: boolean;
}
export { PluginStats };

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,14 @@
import { AssetManager } from './AssetManager';
import { WebpackCompilation } from './WebpackCompilation';
import { WebpackChunk } from './WebpackChunk';
import { LicensesRenderer } from './LicensesRenderer';
import { LicenseIdentifiedModule } from './LicenseIdentifiedModule';
declare class WebpackAssetManager implements AssetManager {
private outputFilename;
private licensesRenderer;
constructor(outputFilename: string, licensesRenderer: LicensesRenderer);
writeChunkLicenses(modules: LicenseIdentifiedModule[], compilation: WebpackCompilation, chunk: WebpackChunk): void;
writeChunkBanners(modules: LicenseIdentifiedModule[], compilation: WebpackCompilation, chunk: WebpackChunk): void;
writeAllLicenses(modules: LicenseIdentifiedModule[], compilation: WebpackCompilation): void;
}
export { WebpackAssetManager };

View file

@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebpackAssetManager = void 0;
var webpack_sources_1 = require("webpack-sources");
var WebpackAssetManager = /** @class */ (function () {
function WebpackAssetManager(outputFilename, licensesRenderer) {
this.outputFilename = outputFilename;
this.licensesRenderer = licensesRenderer;
}
WebpackAssetManager.prototype.writeChunkLicenses = function (modules, compilation, chunk) {
var text = this.licensesRenderer.renderLicenses(modules);
if (text && text.trim()) {
var filename = compilation.getPath(this.outputFilename, { chunk: chunk });
compilation.assets[filename] = new webpack_sources_1.RawSource(text);
}
};
WebpackAssetManager.prototype.writeChunkBanners = function (modules, compilation, chunk) {
var filename = compilation.getPath(this.outputFilename, { chunk: chunk });
var text = this.licensesRenderer.renderBanner(filename, modules);
if (text && text.trim()) {
var files = chunk.files instanceof Set ? Array.from(chunk.files) : chunk.files;
files
.filter(function (file) { return /\.js$/.test(file); })
.forEach(function (file) {
compilation.assets[file] = new webpack_sources_1.ConcatSource(text, compilation.assets[file]);
});
}
};
WebpackAssetManager.prototype.writeAllLicenses = function (modules, compilation) {
var text = this.licensesRenderer.renderLicenses(modules);
if (text) {
var filename = compilation.getPath(this.outputFilename, compilation);
compilation.assets[filename] = new webpack_sources_1.RawSource(text);
}
};
return WebpackAssetManager;
}());
exports.WebpackAssetManager = WebpackAssetManager;

View file

@ -0,0 +1,9 @@
import { WebpackChunkModule } from './WebpackChunkModule';
export interface WebpackChunk {
name: string;
modulesIterable?: IterableIterator<WebpackChunkModule>;
forEachModule?: (callback: (module: WebpackChunkModule) => void) => void;
modules?: WebpackChunkModule[];
entryModule?: WebpackChunkModule;
files: string[] | Set<string>;
}

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,10 @@
import { WebpackChunk } from './WebpackChunk';
import { ModuleCache } from './ModuleCache';
import { LicenseIdentifiedModule } from './LicenseIdentifiedModule';
import { WebpackCompilation } from './WebpackCompilation';
import { WebpackStats } from './WebpackStats';
interface WebpackChunkHandler {
processChunk(compilation: WebpackCompilation, chunk: WebpackChunk, moduleCache: ModuleCache, stats: WebpackStats | undefined): void;
processModule(compilation: WebpackCompilation, chunk: WebpackChunk, moduleCache: ModuleCache, module: LicenseIdentifiedModule): void;
}
export { WebpackChunkHandler };

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,16 @@
import { PackageJson } from './PackageJson';
export interface WebpackChunkModule {
resource?: string;
rootModule?: {
resource?: string;
};
originModule?: {
resource?: string;
};
fileDependencies?: string[];
dependencies?: WebpackChunkModule[];
resourceResolveData?: {
descriptionFileRoot: string;
descriptionFileData: PackageJson;
};
}

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,9 @@
import { WebpackChunk } from './WebpackChunk';
import { WebpackChunkModule } from './WebpackChunkModule';
import { WebpackCompilation } from './WebpackCompilation';
import { WebpackStats } from './WebpackStats';
declare class WebpackChunkModuleIterator {
private statsIterator;
iterateModules(compilation: WebpackCompilation, chunk: WebpackChunk, stats: WebpackStats | undefined, callback: (module: WebpackChunkModule) => void): void;
}
export { WebpackChunkModuleIterator };

View file

@ -0,0 +1,95 @@
"use strict";
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebpackChunkModuleIterator = void 0;
var WebpackStatsIterator_1 = require("./WebpackStatsIterator");
var WebpackChunkModuleIterator = /** @class */ (function () {
function WebpackChunkModuleIterator() {
this.statsIterator = new WebpackStatsIterator_1.WebpackStatsIterator();
}
WebpackChunkModuleIterator.prototype.iterateModules = function (compilation, chunk, stats, callback) {
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
if (typeof compilation.chunkGraph !== 'undefined' &&
typeof stats !== 'undefined') {
try {
// webpack v5
for (var _e = __values(compilation.chunkGraph.getChunkModulesIterable(chunk)), _f = _e.next(); !_f.done; _f = _e.next()) {
var module_1 = _f.value;
callback(module_1);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
}
finally { if (e_1) throw e_1.error; }
}
var statsModules = this.statsIterator.collectModules(stats, chunk.name);
try {
for (var statsModules_1 = __values(statsModules), statsModules_1_1 = statsModules_1.next(); !statsModules_1_1.done; statsModules_1_1 = statsModules_1.next()) {
var module_2 = statsModules_1_1.value;
callback(module_2);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (statsModules_1_1 && !statsModules_1_1.done && (_b = statsModules_1.return)) _b.call(statsModules_1);
}
finally { if (e_2) throw e_2.error; }
}
}
else if (typeof chunk.modulesIterable !== 'undefined') {
try {
for (var _g = __values(chunk.modulesIterable), _h = _g.next(); !_h.done; _h = _g.next()) {
var module_3 = _h.value;
callback(module_3);
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (_h && !_h.done && (_c = _g.return)) _c.call(_g);
}
finally { if (e_3) throw e_3.error; }
}
}
else if (typeof chunk.forEachModule === 'function') {
chunk.forEachModule(callback);
}
else if (Array.isArray(chunk.modules)) {
chunk.modules.forEach(callback);
}
if (typeof compilation.chunkGraph !== 'undefined') {
try {
for (var _j = __values(compilation.chunkGraph.getChunkEntryModulesIterable(chunk)), _k = _j.next(); !_k.done; _k = _j.next()) {
var module_4 = _k.value;
callback(module_4);
}
}
catch (e_4_1) { e_4 = { error: e_4_1 }; }
finally {
try {
if (_k && !_k.done && (_d = _j.return)) _d.call(_j);
}
finally { if (e_4) throw e_4.error; }
}
}
else if (chunk.entryModule) {
callback(chunk.entryModule);
}
};
return WebpackChunkModuleIterator;
}());
exports.WebpackChunkModuleIterator = WebpackChunkModuleIterator;

View file

@ -0,0 +1,46 @@
import { WebpackChunk } from './WebpackChunk';
import { Source } from 'webpack-sources';
import { ChunkGraph } from './ChunkGraph';
import { WebpackCompiler } from './WebpackCompiler';
import { WebpackStats } from './WebpackStats';
export interface WebpackCompilation {
hash: string;
chunks: IterableIterator<WebpackChunk>;
assets: {
[key: string]: Source;
};
errors: any[];
warnings: any[];
getPath(filename: string, data: {
hash?: any;
chunk?: any;
filename?: string;
basename?: string;
query?: any;
}): string;
hooks: {
optimizeChunkAssets: {
tap: (pluginName: string, handler: (chunks: IterableIterator<WebpackChunk>) => void) => void;
};
processAssets: {
tap: (options: {
name: string;
stage: number;
}, handler: () => void) => void;
};
};
plugin?: (phase: string, callback: Function) => void;
chunkGraph?: ChunkGraph;
compiler: WebpackCompiler;
getStats: () => {
toJson: (options?: WebpackStatsOptions) => WebpackStats;
};
}
export interface WebpackStatsOptions {
all?: boolean;
chunks?: boolean;
chunkModules?: boolean;
nestedModules?: boolean;
dependentModules?: boolean;
cachedModules?: boolean;
}

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,18 @@
import { WebpackCompilation } from './WebpackCompilation';
export interface WebpackCompiler {
hooks: {
thisCompilation: {
tap: (pluginName: string, handler: (compilation: WebpackCompilation) => void) => void;
};
compilation: {
tap: (pluginName: string, handler: (compilation: WebpackCompilation) => void) => void;
};
emit: {
tap: (pluginName: string, handler: (compilation: WebpackCompilation) => void) => void;
};
};
context: string;
inputFileSystem: any;
plugin?: (phase: string, callback: Function) => void;
isChild: () => boolean;
}

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,26 @@
import { WebpackChunkHandler } from './WebpackChunkHandler';
import { WebpackCompiler } from './WebpackCompiler';
import { ChunkIncludeExcludeTester } from './ChunkIncludeExcludeTester';
import { ModuleCache } from './ModuleCache';
import { AssetManager } from './AssetManager';
import { Module } from './Module';
declare class WebpackCompilerHandler {
private chunkIncludeTester;
private chunkHandler;
private assetManager;
private moduleCache;
private addBanner;
private perChunkOutput;
private additionalChunkModules;
private additionalModules;
private skipChildCompilers;
static PROCESS_ASSETS_STAGE_ADDITIONS: number;
static PROCESS_ASSETS_STAGE_REPORT: number;
constructor(chunkIncludeTester: ChunkIncludeExcludeTester, chunkHandler: WebpackChunkHandler, assetManager: AssetManager, moduleCache: ModuleCache, addBanner: boolean, perChunkOutput: boolean, additionalChunkModules: {
[chunkName: string]: Module[];
}, additionalModules: Module[], skipChildCompilers: boolean);
handleCompiler(compiler: WebpackCompiler): void;
private iterateChunksForBanner;
private iterateChunks;
}
export { WebpackCompilerHandler };

View file

@ -0,0 +1,176 @@
"use strict";
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebpackCompilerHandler = void 0;
var WebpackCompilerHandler = /** @class */ (function () {
function WebpackCompilerHandler(chunkIncludeTester, chunkHandler, assetManager, moduleCache, addBanner, perChunkOutput, additionalChunkModules, additionalModules, skipChildCompilers) {
this.chunkIncludeTester = chunkIncludeTester;
this.chunkHandler = chunkHandler;
this.assetManager = assetManager;
this.moduleCache = moduleCache;
this.addBanner = addBanner;
this.perChunkOutput = perChunkOutput;
this.additionalChunkModules = additionalChunkModules;
this.additionalModules = additionalModules;
this.skipChildCompilers = skipChildCompilers;
}
WebpackCompilerHandler.prototype.handleCompiler = function (compiler) {
var _this = this;
if (typeof compiler.hooks !== 'undefined') {
var hookType = this.skipChildCompilers
? 'thisCompilation'
: 'compilation';
compiler.hooks[hookType].tap('LicenseWebpackPlugin', function (compilation) {
if (typeof compilation.hooks.processAssets !== 'undefined') {
// webpack v5
compilation.hooks.processAssets.tap({
name: 'LicenseWebpackPlugin',
stage: WebpackCompilerHandler.PROCESS_ASSETS_STAGE_REPORT
}, function () {
// the chunk graph does not contain ES modules
// use stats instead to find the ES module imports
var stats = compilation.getStats().toJson({
all: false,
chunks: true,
chunkModules: true,
nestedModules: true,
dependentModules: true,
cachedModules: true
});
_this.iterateChunks(compilation, compilation.chunks, stats);
});
}
else {
// webpack v4
compilation.hooks.optimizeChunkAssets.tap('LicenseWebpackPlugin', function (chunks) {
_this.iterateChunks(compilation, chunks);
});
}
if (_this.addBanner) {
_this.iterateChunksForBanner(compilation);
}
});
if (!this.perChunkOutput) {
compiler.hooks[hookType].tap('LicenseWebpackPlugin', function (compilation) {
if (!compilation.compiler.isChild()) {
// Select only root compiler to avoid writing license file multiple times per compilation
if (typeof compilation.hooks.processAssets !== 'undefined') {
// webpack v5
compilation.hooks.processAssets.tap({
name: 'LicenseWebpackPlugin',
stage: WebpackCompilerHandler.PROCESS_ASSETS_STAGE_REPORT + 1
}, function () {
_this.assetManager.writeAllLicenses(_this.moduleCache.getAllModules(), compilation);
});
}
else {
// webpack v4
compilation.hooks.optimizeChunkAssets.tap('LicenseWebpackPlugin', function () {
_this.assetManager.writeAllLicenses(_this.moduleCache.getAllModules(), compilation);
});
}
}
});
}
}
else if (typeof compiler.plugin !== 'undefined') {
compiler.plugin('compilation', function (compilation) {
if (typeof compilation.plugin !== 'undefined') {
compilation.plugin('optimize-chunk-assets', function (chunks, callback) {
_this.iterateChunks(compilation, chunks);
callback();
});
}
});
}
};
WebpackCompilerHandler.prototype.iterateChunksForBanner = function (compilation) {
var _this = this;
// for webpack v4 we write banners in iterateChunks.
// because of plugin hook ordering issues, it is done separately here for webpack v5.
// it is important to note that renderBanner will not receive any modules in the second
// argument due to plugin hook ordering issues in webpack v5.
// For the banner to work in webpack v5 production mode, TerserPlugin must be configured in a specific way.
// Please check the documentation of License Webpack Plugin for more details.
if (typeof compilation.hooks.processAssets !== 'undefined') {
// webpack v5
compilation.hooks.processAssets.tap({
name: 'LicenseWebpackPlugin',
stage: WebpackCompilerHandler.PROCESS_ASSETS_STAGE_ADDITIONS
}, function () {
var e_1, _a;
try {
for (var _b = __values(compilation.chunks), _c = _b.next(); !_c.done; _c = _b.next()) {
var chunk = _c.value;
if (_this.chunkIncludeTester.isIncluded(chunk.name)) {
_this.assetManager.writeChunkBanners(_this.moduleCache.getAllModulesForChunk(chunk.name), compilation, chunk);
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
});
}
};
WebpackCompilerHandler.prototype.iterateChunks = function (compilation, chunks, stats) {
var e_2, _a;
var _this = this;
var _loop_1 = function (chunk) {
if (this_1.chunkIncludeTester.isIncluded(chunk.name)) {
this_1.chunkHandler.processChunk(compilation, chunk, this_1.moduleCache, stats);
if (this_1.additionalChunkModules[chunk.name]) {
this_1.additionalChunkModules[chunk.name].forEach(function (module) {
return _this.chunkHandler.processModule(compilation, chunk, _this.moduleCache, module);
});
}
if (this_1.additionalModules.length > 0) {
this_1.additionalModules.forEach(function (module) {
return _this.chunkHandler.processModule(compilation, chunk, _this.moduleCache, module);
});
}
if (this_1.perChunkOutput) {
this_1.assetManager.writeChunkLicenses(this_1.moduleCache.getAllModulesForChunk(chunk.name), compilation, chunk);
}
if (this_1.addBanner &&
typeof compilation.hooks.processAssets === 'undefined') {
// webpack v4
this_1.assetManager.writeChunkBanners(this_1.moduleCache.getAllModulesForChunk(chunk.name), compilation, chunk);
}
}
};
var this_1 = this;
try {
for (var chunks_1 = __values(chunks), chunks_1_1 = chunks_1.next(); !chunks_1_1.done; chunks_1_1 = chunks_1.next()) {
var chunk = chunks_1_1.value;
_loop_1(chunk);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (chunks_1_1 && !chunks_1_1.done && (_a = chunks_1.return)) _a.call(chunks_1);
}
finally { if (e_2) throw e_2.error; }
}
};
// copied from webpack/lib/Compilation.js
WebpackCompilerHandler.PROCESS_ASSETS_STAGE_ADDITIONS = -100;
WebpackCompilerHandler.PROCESS_ASSETS_STAGE_REPORT = 5000;
return WebpackCompilerHandler;
}());
exports.WebpackCompilerHandler = WebpackCompilerHandler;

View file

@ -0,0 +1,14 @@
import { FileSystem } from './FileSystem';
declare class WebpackFileSystem implements FileSystem {
private fs;
pathSeparator: string;
constructor(fs: any);
isFileInDirectory(filename: string, directory: string): boolean;
pathExists(filename: string): boolean;
readFileAsUtf8(filename: string): string;
join(...paths: string[]): string;
resolvePath(pathInput: string): string;
listPaths(dir: string): string[];
isDirectory(dir: string): boolean;
}
export { WebpackFileSystem };

View file

@ -0,0 +1,90 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebpackFileSystem = void 0;
var path = __importStar(require("path"));
var WebpackFileSystem = /** @class */ (function () {
function WebpackFileSystem(fs) {
this.fs = fs;
this.pathSeparator = path.sep;
}
WebpackFileSystem.prototype.isFileInDirectory = function (filename, directory) {
var normalizedFile = this.resolvePath(filename);
var normalizedDirectory = this.resolvePath(directory);
return (!this.isDirectory(normalizedFile) &&
normalizedFile.indexOf(normalizedDirectory) === 0);
};
WebpackFileSystem.prototype.pathExists = function (filename) {
try {
var stat = this.fs.statSync(filename, { throwIfNoEntry: false });
return !!stat;
}
catch (e) {
return false;
}
};
WebpackFileSystem.prototype.readFileAsUtf8 = function (filename) {
return this.fs.readFileSync(filename).toString('utf8');
};
WebpackFileSystem.prototype.join = function () {
var paths = [];
for (var _i = 0; _i < arguments.length; _i++) {
paths[_i] = arguments[_i];
}
return path.join.apply(path, __spread(paths));
};
WebpackFileSystem.prototype.resolvePath = function (pathInput) {
return path.resolve(pathInput);
};
WebpackFileSystem.prototype.listPaths = function (dir) {
return this.fs.readdirSync(dir);
};
WebpackFileSystem.prototype.isDirectory = function (dir) {
var isDir = false;
try {
isDir = this.fs.statSync(dir, { throwIfNoEntry: false }).isDirectory();
}
catch (e) { }
return isDir;
};
return WebpackFileSystem;
}());
exports.WebpackFileSystem = WebpackFileSystem;

View file

@ -0,0 +1,4 @@
import { WebpackCompiler } from './WebpackCompiler';
export interface WebpackPlugin {
apply(compiler: WebpackCompiler): void;
}

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

2
node_modules/license-webpack-plugin/dist/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,2 @@
import { LicenseWebpackPlugin } from './LicenseWebpackPlugin';
export { LicenseWebpackPlugin };

5
node_modules/license-webpack-plugin/dist/index.js generated vendored Normal file
View file

@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LicenseWebpackPlugin = void 0;
var LicenseWebpackPlugin_1 = require("./LicenseWebpackPlugin");
Object.defineProperty(exports, "LicenseWebpackPlugin", { enumerable: true, get: function () { return LicenseWebpackPlugin_1.LicenseWebpackPlugin; } });