[79a0317] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | Author Tobias Koppers @sokra
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | "use strict";
|
---|
| 7 |
|
---|
| 8 | const CachedInputFileSystem = require("enhanced-resolve").CachedInputFileSystem;
|
---|
| 9 | const fs = require("graceful-fs");
|
---|
| 10 | const createConsoleLogger = require("../logging/createConsoleLogger");
|
---|
| 11 | const NodeWatchFileSystem = require("./NodeWatchFileSystem");
|
---|
| 12 | const nodeConsole = require("./nodeConsole");
|
---|
| 13 |
|
---|
| 14 | /** @typedef {import("../../declarations/WebpackOptions").InfrastructureLogging} InfrastructureLogging */
|
---|
| 15 | /** @typedef {import("../Compiler")} Compiler */
|
---|
| 16 | /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
|
---|
| 17 |
|
---|
| 18 | class NodeEnvironmentPlugin {
|
---|
| 19 | /**
|
---|
| 20 | * @param {object} options options
|
---|
| 21 | * @param {InfrastructureLogging} options.infrastructureLogging infrastructure logging options
|
---|
| 22 | */
|
---|
| 23 | constructor(options) {
|
---|
| 24 | this.options = options;
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | /**
|
---|
| 28 | * Apply the plugin
|
---|
| 29 | * @param {Compiler} compiler the compiler instance
|
---|
| 30 | * @returns {void}
|
---|
| 31 | */
|
---|
| 32 | apply(compiler) {
|
---|
| 33 | const { infrastructureLogging } = this.options;
|
---|
| 34 | compiler.infrastructureLogger = createConsoleLogger({
|
---|
| 35 | level: infrastructureLogging.level || "info",
|
---|
| 36 | debug: infrastructureLogging.debug || false,
|
---|
| 37 | console:
|
---|
| 38 | infrastructureLogging.console ||
|
---|
| 39 | nodeConsole({
|
---|
| 40 | colors: infrastructureLogging.colors,
|
---|
| 41 | appendOnly: infrastructureLogging.appendOnly,
|
---|
| 42 | stream:
|
---|
| 43 | /** @type {NodeJS.WritableStream} */
|
---|
| 44 | (infrastructureLogging.stream)
|
---|
| 45 | })
|
---|
| 46 | });
|
---|
| 47 | compiler.inputFileSystem = new CachedInputFileSystem(fs, 60000);
|
---|
| 48 | const inputFileSystem =
|
---|
| 49 | /** @type {InputFileSystem} */
|
---|
| 50 | (compiler.inputFileSystem);
|
---|
| 51 | compiler.outputFileSystem = fs;
|
---|
| 52 | compiler.intermediateFileSystem = fs;
|
---|
| 53 | compiler.watchFileSystem = new NodeWatchFileSystem(inputFileSystem);
|
---|
| 54 | compiler.hooks.beforeRun.tap("NodeEnvironmentPlugin", compiler => {
|
---|
| 55 | if (
|
---|
| 56 | compiler.inputFileSystem === inputFileSystem &&
|
---|
| 57 | inputFileSystem.purge
|
---|
| 58 | ) {
|
---|
| 59 | compiler.fsStartTime = Date.now();
|
---|
| 60 | inputFileSystem.purge();
|
---|
| 61 | }
|
---|
| 62 | });
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | module.exports = NodeEnvironmentPlugin;
|
---|