1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
7 | if (k2 === undefined) k2 = k;
|
8 | var desc = Object.getOwnPropertyDescriptor(m, k);
|
9 | if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
10 | desc = { enumerable: true, get: function() { return m[k]; } };
|
11 | }
|
12 | Object.defineProperty(o, k2, desc);
|
13 | }) : (function(o, m, k, k2) {
|
14 | if (k2 === undefined) k2 = k;
|
15 | o[k2] = m[k];
|
16 | }));
|
17 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
18 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
19 | }) : function(o, v) {
|
20 | o["default"] = v;
|
21 | });
|
22 | var __importStar = (this && this.__importStar) || function (mod) {
|
23 | if (mod && mod.__esModule) return mod;
|
24 | var result = {};
|
25 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
26 | __setModuleDefault(result, mod);
|
27 | return result;
|
28 | };
|
29 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
30 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
31 | };
|
32 | Object.defineProperty(exports, "__esModule", { value: true });
|
33 | exports.WPPlugin = void 0;
|
34 | const duplicate_package_checker_webpack_plugin_1 = __importDefault(require("duplicate-package-checker-webpack-plugin"));
|
35 | const fs = __importStar(require("fs-extra"));
|
36 | const license_webpack_plugin_1 = require("license-webpack-plugin");
|
37 |
|
38 |
|
39 | const IGNORE_TIME_ENTRY = 'ignore';
|
40 | var WPPlugin;
|
41 | (function (WPPlugin) {
|
42 | |
43 |
|
44 |
|
45 | class FrontEndPlugin {
|
46 | constructor(buildDir, staticDir) {
|
47 | this.buildDir = buildDir;
|
48 | this.staticDir = staticDir;
|
49 | this._first = true;
|
50 | }
|
51 | apply(compiler) {
|
52 | compiler.hooks.afterEmit.tap('FrontEndPlugin', () => {
|
53 |
|
54 | if (!this.staticDir) {
|
55 | return;
|
56 | }
|
57 |
|
58 | if (this._first && fs.existsSync(this.staticDir)) {
|
59 | fs.removeSync(this.staticDir);
|
60 | }
|
61 | this._first = false;
|
62 | fs.copySync(this.buildDir, this.staticDir);
|
63 | });
|
64 | }
|
65 | }
|
66 | WPPlugin.FrontEndPlugin = FrontEndPlugin;
|
67 | |
68 |
|
69 |
|
70 |
|
71 | class FilterIgnoringWatchFileSystem {
|
72 | constructor(wfs, ignored) {
|
73 | this.wfs = wfs;
|
74 |
|
75 | this.ignored = ignored;
|
76 | }
|
77 | watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) {
|
78 | files = Array.from(files);
|
79 | dirs = Array.from(dirs);
|
80 | const notIgnored = (path) => !this.ignored(path);
|
81 | const ignoredFiles = files.filter(this.ignored);
|
82 | const ignoredDirs = dirs.filter(this.ignored);
|
83 | const watcher = this.wfs.watch(files.filter(notIgnored), dirs.filter(notIgnored), missing, startTime, options, (err, fileTimestamps, dirTimestamps, changedFiles, removedFiles) => {
|
84 | if (err)
|
85 | return callback(err);
|
86 | for (const path of ignoredFiles) {
|
87 | fileTimestamps.set(path, IGNORE_TIME_ENTRY);
|
88 | }
|
89 | for (const path of ignoredDirs) {
|
90 | dirTimestamps.set(path, IGNORE_TIME_ENTRY);
|
91 | }
|
92 | callback(err, fileTimestamps, dirTimestamps, changedFiles, removedFiles);
|
93 | }, callbackUndelayed);
|
94 | return {
|
95 | close: () => watcher.close(),
|
96 | pause: () => watcher.pause(),
|
97 | getContextTimeInfoEntries: () => {
|
98 | const dirTimestamps = watcher.getContextTimeInfoEntries();
|
99 | for (const path of ignoredDirs) {
|
100 | dirTimestamps.set(path, IGNORE_TIME_ENTRY);
|
101 | }
|
102 | return dirTimestamps;
|
103 | },
|
104 | getFileTimeInfoEntries: () => {
|
105 | const fileTimestamps = watcher.getFileTimeInfoEntries();
|
106 | for (const path of ignoredFiles) {
|
107 | fileTimestamps.set(path, IGNORE_TIME_ENTRY);
|
108 | }
|
109 | return fileTimestamps;
|
110 | }
|
111 | };
|
112 | }
|
113 | }
|
114 | |
115 |
|
116 |
|
117 |
|
118 | class FilterWatchIgnorePlugin {
|
119 | constructor(ignored) {
|
120 | this.ignored = ignored;
|
121 | }
|
122 | apply(compiler) {
|
123 | compiler.hooks.afterEnvironment.tap('FilterWatchIgnorePlugin', () => {
|
124 | compiler.watchFileSystem = new FilterIgnoringWatchFileSystem(compiler.watchFileSystem, this.ignored);
|
125 | });
|
126 | }
|
127 | }
|
128 | WPPlugin.FilterWatchIgnorePlugin = FilterWatchIgnorePlugin;
|
129 | class NowatchDuplicatePackageCheckerPlugin extends duplicate_package_checker_webpack_plugin_1.default {
|
130 | apply(compiler) {
|
131 | const options = this.options;
|
132 | compiler.hooks.run.tap('NowatchDuplicatePackageCheckerPlugin', compiler => {
|
133 | const p = new duplicate_package_checker_webpack_plugin_1.default(options);
|
134 | p.apply(compiler);
|
135 | });
|
136 | }
|
137 | }
|
138 | WPPlugin.NowatchDuplicatePackageCheckerPlugin = NowatchDuplicatePackageCheckerPlugin;
|
139 | |
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 | WPPlugin.DEFAULT_LICENSE_REPORT_FILENAME = 'third-party-licenses.json';
|
151 | |
152 |
|
153 |
|
154 |
|
155 | class JSONLicenseWebpackPlugin extends license_webpack_plugin_1.LicenseWebpackPlugin {
|
156 | constructor(pluginOptions = {}) {
|
157 | super({
|
158 | outputFilename: WPPlugin.DEFAULT_LICENSE_REPORT_FILENAME,
|
159 | ...pluginOptions,
|
160 | renderLicenses: modules => this.renderLicensesJSON(modules),
|
161 | perChunkOutput: false
|
162 | });
|
163 | }
|
164 |
|
165 | renderLicensesJSON(modules) {
|
166 | const report = { packages: [] };
|
167 | modules.sort((left, right) => (left.name < right.name ? -1 : 1));
|
168 | for (const mod of modules) {
|
169 | report.packages.push({
|
170 | name: mod.name || '',
|
171 | versionInfo: mod.packageJson.version || '',
|
172 | licenseId: mod.licenseId || '',
|
173 | extractedText: mod.licenseText || ''
|
174 | });
|
175 | }
|
176 | return JSON.stringify(report, null, 2);
|
177 | }
|
178 | }
|
179 | WPPlugin.JSONLicenseWebpackPlugin = JSONLicenseWebpackPlugin;
|
180 | })(WPPlugin = exports.WPPlugin || (exports.WPPlugin = {}));
|
181 |
|
\ | No newline at end of file |