-
Notifications
You must be signed in to change notification settings - Fork 53
/
LicenseWebpackPlugin.ts
105 lines (101 loc) · 3.73 KB
/
LicenseWebpackPlugin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { WebpackCompiler } from './WebpackCompiler';
import { WebpackPlugin } from './WebpackPlugin';
import { ChunkIncludeExcludeTester } from './ChunkIncludeExcludeTester';
import { WebpackChunkHandler } from './WebpackChunkHandler';
import { PluginChunkReadHandler } from './PluginChunkReadHandler';
import { PluginFileHandler } from './PluginFileHandler';
import { FileHandler } from './FileHandler';
import { WebpackFileSystem } from './WebpackFileSystem';
import { PluginLicenseTypeIdentifier } from './PluginLicenseTypeIdentifier';
import { LicenseTextReader } from './LicenseTextReader';
import { LicensePolicy } from './LicensePolicy';
import { WebpackCompilerHandler } from './WebpackCompilerHandler';
import { PluginModuleCache } from './PluginModuleCache';
import { ModuleCache } from './ModuleCache';
import { WebpackAssetManager } from './WebpackAssetManager';
import { PluginLicensesRenderer } from './PluginLicensesRenderer';
import { ConstructedOptions } from './ConstructedOptions';
import { PluginLicensePolicy } from './PluginLicensePolicy';
import { PluginLicenseTestRunner } from './PluginLicenseTestRunner';
import { PluginOptionsReader } from './PluginOptionsReader';
import { PluginOptions } from './PluginOptions';
import { Logger } from './Logger';
class LicenseWebpackPlugin implements WebpackPlugin {
constructor(private pluginOptions: PluginOptions = {}) {}
apply(compiler: WebpackCompiler) {
const fileSystem = new WebpackFileSystem(compiler.inputFileSystem);
const optionsReader: PluginOptionsReader = new PluginOptionsReader(
compiler.context
);
const options: ConstructedOptions = optionsReader.readOptions(
this.pluginOptions
);
const logger: Logger = new Logger(options.stats);
const fileHandler: FileHandler = new PluginFileHandler(
fileSystem,
options.buildRoot,
options.modulesDirectories,
options.excludedPackageTest
);
const licenseTypeIdentifier = new PluginLicenseTypeIdentifier(
logger,
options.licenseTypeOverrides,
options.preferredLicenseTypes,
options.handleLicenseAmbiguity,
options.handleMissingLicenseType
);
const licenseTextReader = new LicenseTextReader(
logger,
fileSystem,
options.licenseFileOverrides,
options.licenseTextOverrides,
options.licenseTemplateDir,
options.handleMissingLicenseText
);
const licenseTestRunner = new PluginLicenseTestRunner(
options.licenseInclusionTest
);
const unacceptableLicenseTestRunner = new PluginLicenseTestRunner(
options.unacceptableLicenseTest
);
const policy: LicensePolicy = new PluginLicensePolicy(
licenseTestRunner,
unacceptableLicenseTestRunner,
options.handleUnacceptableLicense,
options.handleMissingLicenseText
);
const readHandler: WebpackChunkHandler = new PluginChunkReadHandler(
logger,
fileHandler,
licenseTypeIdentifier,
licenseTextReader,
policy,
fileSystem
);
const licenseRenderer = new PluginLicensesRenderer(
options.renderLicenses,
options.renderBanner
);
const moduleCache: ModuleCache = new PluginModuleCache();
const assetManager = new WebpackAssetManager(
options.outputFilename,
licenseRenderer
);
const chunkIncludeExcludeTester = new ChunkIncludeExcludeTester(
options.chunkIncludeExcludeTest
);
const handler = new WebpackCompilerHandler(
chunkIncludeExcludeTester,
readHandler,
assetManager,
moduleCache,
options.addBanner,
options.perChunkOutput,
options.additionalChunkModules,
options.additionalModules,
options.skipChildCompilers
);
handler.handleCompiler(compiler);
}
}
export { LicenseWebpackPlugin };