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