UNPKG

5.55 kBJavaScriptView Raw
1"use strict";
2/* -----------------------------------------------------------------------------
3| Copyright (c) Jupyter Development Team.
4| Distributed under the terms of the Modified BSD License.
5|----------------------------------------------------------------------------*/
6var __importStar = (this && this.__importStar) || function (mod) {
7 if (mod && mod.__esModule) return mod;
8 var result = {};
9 if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
10 result["default"] = mod;
11 return result;
12};
13Object.defineProperty(exports, "__esModule", { value: true });
14const DuplicatePackageCheckerPlugin = require("duplicate-package-checker-webpack-plugin");
15const fs = __importStar(require("fs-extra"));
16const webpack = __importStar(require("webpack"));
17var WPPlugin;
18(function (WPPlugin) {
19 /**
20 * A WebPack Plugin that copies the assets to the static directory
21 */
22 class FrontEndPlugin {
23 constructor(buildDir, staticDir) {
24 this.buildDir = buildDir;
25 this.staticDir = staticDir;
26 this._first = true;
27 }
28 apply(compiler) {
29 compiler.hooks.afterEmit.tap('FrontEndPlugin', () => {
30 // bail if no staticDir
31 if (!this.staticDir) {
32 return;
33 }
34 // ensure a clean static directory on the first emit
35 if (this._first && fs.existsSync(this.staticDir)) {
36 fs.removeSync(this.staticDir);
37 }
38 this._first = false;
39 fs.copySync(this.buildDir, this.staticDir);
40 });
41 }
42 }
43 WPPlugin.FrontEndPlugin = FrontEndPlugin;
44 /**
45 * A WebPack Plugin that ignores files that are filtered by a callback
46 */
47 class FilterIgnorePlugin extends webpack.IgnorePlugin {
48 constructor(ignored) {
49 super({});
50 // ignored should be a callback function that filters the build files
51 this.ignored = ignored;
52 }
53 checkIgnore(result) {
54 if (!result) {
55 return result;
56 }
57 return this.ignored(result.resource) ? result : null;
58 }
59 }
60 WPPlugin.FilterIgnorePlugin = FilterIgnorePlugin;
61 /**
62 * A helper class for the WatchIgnoreFilterPlugin. This is a close copy of
63 * (the non-exported) webpack.IgnoringWatchFileSystem
64 */
65 class FilterIgnoringWatchFileSystem {
66 constructor(wfs, ignored) {
67 this.wfs = wfs;
68 // ignored should be a callback function that filters the build files
69 this.ignored = ignored;
70 }
71 watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) {
72 const notIgnored = (path) => !this.ignored(path);
73 const ignoredFiles = files.filter(this.ignored);
74 const ignoredDirs = dirs.filter(this.ignored);
75 const watcher = this.wfs.watch(files.filter(notIgnored), dirs.filter(notIgnored), missing, startTime, options, (err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps, removedFiles) => {
76 if (err) {
77 return callback(err);
78 }
79 for (const path of ignoredFiles) {
80 fileTimestamps.set(path, 1);
81 }
82 for (const path of ignoredDirs) {
83 dirTimestamps.set(path, 1);
84 }
85 callback(err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps, removedFiles);
86 }, callbackUndelayed);
87 return {
88 close: () => watcher.close(),
89 pause: () => watcher.pause(),
90 getContextTimestamps: () => {
91 const dirTimestamps = watcher.getContextTimestamps();
92 for (const path of ignoredDirs) {
93 dirTimestamps.set(path, 1);
94 }
95 return dirTimestamps;
96 },
97 getFileTimestamps: () => {
98 const fileTimestamps = watcher.getFileTimestamps();
99 for (const path of ignoredFiles) {
100 fileTimestamps.set(path, 1);
101 }
102 return fileTimestamps;
103 }
104 };
105 }
106 }
107 /**
108 * A WebPack Plugin that ignores files files that are filtered
109 * by a callback during a `--watch` build
110 */
111 class FilterWatchIgnorePlugin {
112 constructor(ignored) {
113 this.ignored = ignored;
114 }
115 apply(compiler) {
116 compiler.hooks.afterEnvironment.tap('FilterWatchIgnorePlugin', () => {
117 compiler.watchFileSystem = new FilterIgnoringWatchFileSystem(compiler.watchFileSystem, this.ignored);
118 });
119 }
120 }
121 WPPlugin.FilterWatchIgnorePlugin = FilterWatchIgnorePlugin;
122 class NowatchDuplicatePackageCheckerPlugin extends DuplicatePackageCheckerPlugin {
123 apply(compiler) {
124 const options = this.options;
125 compiler.hooks.run.tap('NowatchDuplicatePackageCheckerPlugin', (compiler) => {
126 const p = new DuplicatePackageCheckerPlugin(options);
127 p.apply(compiler);
128 });
129 }
130 }
131 WPPlugin.NowatchDuplicatePackageCheckerPlugin = NowatchDuplicatePackageCheckerPlugin;
132})(WPPlugin = exports.WPPlugin || (exports.WPPlugin = {}));
133//# sourceMappingURL=webpack-plugins.js.map
\No newline at end of file