source: frontend/node_modules/webpack/lib/node/NodeEnvironmentPlugin.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const { CachedInputFileSystem } = require("enhanced-resolve");
9const fs = require("graceful-fs");
10const createConsoleLogger = require("../logging/createConsoleLogger");
11const NodeWatchFileSystem = require("./NodeWatchFileSystem");
12const 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/**
19 * Defines the node environment plugin options type used by this module.
20 * @typedef {object} NodeEnvironmentPluginOptions
21 * @property {InfrastructureLogging} infrastructureLogging infrastructure logging options
22 */
23
24const PLUGIN_NAME = "NodeEnvironmentPlugin";
25
26class NodeEnvironmentPlugin {
27 /**
28 * Creates an instance of NodeEnvironmentPlugin.
29 * @param {NodeEnvironmentPluginOptions} options options
30 */
31 constructor(options) {
32 /** @type {NodeEnvironmentPluginOptions} */
33 this.options = options;
34 }
35
36 /**
37 * Applies the plugin by registering its hooks on the compiler.
38 * @param {Compiler} compiler the compiler instance
39 * @returns {void}
40 */
41 apply(compiler) {
42 const { infrastructureLogging } = this.options;
43 compiler.infrastructureLogger = createConsoleLogger({
44 level: infrastructureLogging.level || "info",
45 debug: infrastructureLogging.debug || false,
46 console:
47 infrastructureLogging.console ||
48 nodeConsole({
49 colors: infrastructureLogging.colors,
50 appendOnly: infrastructureLogging.appendOnly,
51 stream:
52 /** @type {NodeJS.WritableStream} */
53 (infrastructureLogging.stream),
54 compiler
55 })
56 });
57 // @ts-expect-error need to fix on enhanced-resolve side
58 compiler.inputFileSystem = new CachedInputFileSystem(fs, 60000);
59 const inputFileSystem =
60 /** @type {InputFileSystem} */
61 (compiler.inputFileSystem);
62 compiler.outputFileSystem = fs;
63 compiler.intermediateFileSystem = fs;
64 compiler.watchFileSystem = new NodeWatchFileSystem(inputFileSystem);
65 compiler.hooks.beforeRun.tap(PLUGIN_NAME, (compiler) => {
66 if (
67 compiler.inputFileSystem === inputFileSystem &&
68 inputFileSystem.purge
69 ) {
70 compiler.fsStartTime = Date.now();
71 inputFileSystem.purge();
72 }
73 });
74 }
75}
76
77module.exports = NodeEnvironmentPlugin;
Note: See TracBrowser for help on using the repository browser.