mirror of https://github.com/webpack/webpack.git
fix: all filesystem types
This commit is contained in:
parent
94d874162a
commit
32717aae42
|
@ -89,8 +89,8 @@ const getDiffToFs = (fs, outputPath, currentAssets, callback) => {
|
||||||
}
|
}
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
for (const entry of entries) {
|
for (const entry of /** @type {string[]} */ (entries)) {
|
||||||
const file = /** @type {string} */ (entry);
|
const file = entry;
|
||||||
const filename = directory ? `${directory}/${file}` : file;
|
const filename = directory ? `${directory}/${file}` : file;
|
||||||
if (!directories.has(filename) && !currentAssets.has(filename)) {
|
if (!directories.has(filename) && !currentAssets.has(filename)) {
|
||||||
diff.add(filename);
|
diff.add(filename);
|
||||||
|
@ -207,7 +207,7 @@ const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {NonNullable<OutputFileSystem["readdir"]>} */
|
/** @type {NonNullable<OutputFileSystem["readdir"]>} */
|
||||||
(fs.readdir)(path, (err, entries) => {
|
(fs.readdir)(path, (err, _entries) => {
|
||||||
if (err) return handleError(err);
|
if (err) return handleError(err);
|
||||||
/** @type {Job} */
|
/** @type {Job} */
|
||||||
const deleteJob = {
|
const deleteJob = {
|
||||||
|
@ -215,6 +215,7 @@ const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
|
||||||
filename,
|
filename,
|
||||||
parent
|
parent
|
||||||
};
|
};
|
||||||
|
const entries = /** @type {string[]} */ (_entries);
|
||||||
if (entries.length === 0) {
|
if (entries.length === 0) {
|
||||||
push(deleteJob);
|
push(deleteJob);
|
||||||
} else {
|
} else {
|
||||||
|
@ -356,7 +357,7 @@ class CleanPlugin {
|
||||||
(compilation, callback) => {
|
(compilation, callback) => {
|
||||||
const hooks = CleanPlugin.getCompilationHooks(compilation);
|
const hooks = CleanPlugin.getCompilationHooks(compilation);
|
||||||
const logger = compilation.getLogger("webpack.CleanPlugin");
|
const logger = compilation.getLogger("webpack.CleanPlugin");
|
||||||
const fs = compiler.outputFileSystem;
|
const fs = /** @type {OutputFileSystem} */ (compiler.outputFileSystem);
|
||||||
|
|
||||||
if (!fs.readdir) {
|
if (!fs.readdir) {
|
||||||
return callback(
|
return callback(
|
||||||
|
|
|
@ -890,7 +890,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
||||||
/** @type {Compiler} */
|
/** @type {Compiler} */
|
||||||
this.compiler = compiler;
|
this.compiler = compiler;
|
||||||
this.resolverFactory = compiler.resolverFactory;
|
this.resolverFactory = compiler.resolverFactory;
|
||||||
this.inputFileSystem = compiler.inputFileSystem;
|
/** @type {InputFileSystem} */
|
||||||
|
this.inputFileSystem =
|
||||||
|
/** @type {InputFileSystem} */
|
||||||
|
(compiler.inputFileSystem);
|
||||||
this.fileSystemInfo = new FileSystemInfo(this.inputFileSystem, {
|
this.fileSystemInfo = new FileSystemInfo(this.inputFileSystem, {
|
||||||
unmanagedPaths: compiler.unmanagedPaths,
|
unmanagedPaths: compiler.unmanagedPaths,
|
||||||
managedPaths: compiler.managedPaths,
|
managedPaths: compiler.managedPaths,
|
||||||
|
|
|
@ -888,19 +888,18 @@ ${other}`);
|
||||||
// for a fast negative match file size is compared first
|
// for a fast negative match file size is compared first
|
||||||
if (content.length === stats.size) {
|
if (content.length === stats.size) {
|
||||||
compilation.comparedForEmitAssets.add(file);
|
compilation.comparedForEmitAssets.add(file);
|
||||||
return this.outputFileSystem.readFile(
|
return /** @type {OutputFileSystem} */ (
|
||||||
targetPath,
|
this.outputFileSystem
|
||||||
(err, existingContent) => {
|
).readFile(targetPath, (err, existingContent) => {
|
||||||
if (
|
if (
|
||||||
err ||
|
err ||
|
||||||
!content.equals(/** @type {Buffer} */ (existingContent))
|
!content.equals(/** @type {Buffer} */ (existingContent))
|
||||||
) {
|
) {
|
||||||
return doWrite(content);
|
return doWrite(content);
|
||||||
} else {
|
} else {
|
||||||
return alreadyWritten();
|
return alreadyWritten();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return doWrite(content);
|
return doWrite(content);
|
||||||
|
@ -926,17 +925,15 @@ ${other}`);
|
||||||
// (we assume one doesn't modify files while the Compiler is running, other then removing them)
|
// (we assume one doesn't modify files while the Compiler is running, other then removing them)
|
||||||
|
|
||||||
if (this._assetEmittingPreviousFiles.has(targetPath)) {
|
if (this._assetEmittingPreviousFiles.has(targetPath)) {
|
||||||
// We assume that assets from the last compilation say intact on disk (they are not removed)
|
const sizeOnlySource = /** @type {SizeOnlySource} */ (
|
||||||
compilation.updateAsset(
|
/** @type {CacheEntry} */ (cacheEntry).sizeOnlySource
|
||||||
file,
|
|
||||||
/** @type {CacheEntry} */ (cacheEntry).sizeOnlySource,
|
|
||||||
{
|
|
||||||
size:
|
|
||||||
/** @type {CacheEntry} */
|
|
||||||
(cacheEntry).sizeOnlySource.size()
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// We assume that assets from the last compilation say intact on disk (they are not removed)
|
||||||
|
compilation.updateAsset(file, sizeOnlySource, {
|
||||||
|
size: sizeOnlySource.size()
|
||||||
|
});
|
||||||
|
|
||||||
return callback();
|
return callback();
|
||||||
} else {
|
} else {
|
||||||
// Settings immutable will make it accept file content without comparing when file exist
|
// Settings immutable will make it accept file content without comparing when file exist
|
||||||
|
@ -953,7 +950,8 @@ ${other}`);
|
||||||
|
|
||||||
if (checkSimilarFile()) return;
|
if (checkSimilarFile()) return;
|
||||||
if (this.options.output.compareBeforeEmit) {
|
if (this.options.output.compareBeforeEmit) {
|
||||||
this.outputFileSystem.stat(targetPath, (err, stats) => {
|
/** @type {OutputFileSystem} */
|
||||||
|
(this.outputFileSystem).stat(targetPath, (err, stats) => {
|
||||||
const exists = !err && /** @type {IStats} */ (stats).isFile();
|
const exists = !err && /** @type {IStats} */ (stats).isFile();
|
||||||
|
|
||||||
if (exists) {
|
if (exists) {
|
||||||
|
@ -1261,7 +1259,7 @@ ${other}`);
|
||||||
this._cleanupLastNormalModuleFactory();
|
this._cleanupLastNormalModuleFactory();
|
||||||
const normalModuleFactory = new NormalModuleFactory({
|
const normalModuleFactory = new NormalModuleFactory({
|
||||||
context: this.options.context,
|
context: this.options.context,
|
||||||
fs: this.inputFileSystem,
|
fs: /** @type {InputFileSystem} */ (this.inputFileSystem),
|
||||||
resolverFactory: this.resolverFactory,
|
resolverFactory: this.resolverFactory,
|
||||||
options: this.options.module,
|
options: this.options.module,
|
||||||
associatedObjectForCache: this.root,
|
associatedObjectForCache: this.root,
|
||||||
|
|
|
@ -9,6 +9,7 @@ const ContextElementDependency = require("./dependencies/ContextElementDependenc
|
||||||
const { join } = require("./util/fs");
|
const { join } = require("./util/fs");
|
||||||
|
|
||||||
/** @typedef {import("./Compiler")} Compiler */
|
/** @typedef {import("./Compiler")} Compiler */
|
||||||
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
||||||
|
|
||||||
class ContextReplacementPlugin {
|
class ContextReplacementPlugin {
|
||||||
/**
|
/**
|
||||||
|
@ -104,7 +105,7 @@ class ContextReplacementPlugin {
|
||||||
result.resource = newContentResource;
|
result.resource = newContentResource;
|
||||||
} else {
|
} else {
|
||||||
result.resource = join(
|
result.resource = join(
|
||||||
compiler.inputFileSystem,
|
/** @type {InputFileSystem} */ (compiler.inputFileSystem),
|
||||||
result.resource,
|
result.resource,
|
||||||
newContentResource
|
newContentResource
|
||||||
);
|
);
|
||||||
|
@ -132,7 +133,7 @@ class ContextReplacementPlugin {
|
||||||
) {
|
) {
|
||||||
// When the function changed it to an relative path
|
// When the function changed it to an relative path
|
||||||
result.resource = join(
|
result.resource = join(
|
||||||
compiler.inputFileSystem,
|
/** @type {InputFileSystem} */ (compiler.inputFileSystem),
|
||||||
origResource,
|
origResource,
|
||||||
result.resource
|
result.resource
|
||||||
);
|
);
|
||||||
|
|
|
@ -17,6 +17,7 @@ const makePathsRelative = require("./util/identifier").makePathsRelative;
|
||||||
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptions} DllReferencePluginOptions */
|
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptions} DllReferencePluginOptions */
|
||||||
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptionsManifest} DllReferencePluginOptionsManifest */
|
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptionsManifest} DllReferencePluginOptionsManifest */
|
||||||
/** @typedef {import("./Compiler")} Compiler */
|
/** @typedef {import("./Compiler")} Compiler */
|
||||||
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
||||||
|
|
||||||
const validate = createSchemaValidation(
|
const validate = createSchemaValidation(
|
||||||
require("../schemas/plugins/DllReferencePlugin.check.js"),
|
require("../schemas/plugins/DllReferencePlugin.check.js"),
|
||||||
|
@ -60,7 +61,8 @@ class DllReferencePlugin {
|
||||||
if ("manifest" in this.options) {
|
if ("manifest" in this.options) {
|
||||||
const manifest = this.options.manifest;
|
const manifest = this.options.manifest;
|
||||||
if (typeof manifest === "string") {
|
if (typeof manifest === "string") {
|
||||||
compiler.inputFileSystem.readFile(manifest, (err, result) => {
|
/** @type {InputFileSystem} */
|
||||||
|
(compiler.inputFileSystem).readFile(manifest, (err, result) => {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
const data = {
|
const data = {
|
||||||
path: manifest,
|
path: manifest,
|
||||||
|
@ -70,7 +72,9 @@ class DllReferencePlugin {
|
||||||
// Catch errors parsing the manifest so that blank
|
// Catch errors parsing the manifest so that blank
|
||||||
// or malformed manifest files don't kill the process.
|
// or malformed manifest files don't kill the process.
|
||||||
try {
|
try {
|
||||||
data.data = parseJson(result.toString("utf-8"));
|
data.data = parseJson(
|
||||||
|
/** @type {Buffer} */ (result).toString("utf-8")
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Store the error in the params so that it can
|
// Store the error in the params so that it can
|
||||||
// be added as a compilation error later on.
|
// be added as a compilation error later on.
|
||||||
|
|
|
@ -32,6 +32,7 @@ const { parseResource } = require("./util/identifier");
|
||||||
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
||||||
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
||||||
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
|
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
|
||||||
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
||||||
|
|
||||||
const PLUGIN_NAME = "NodeStuffPlugin";
|
const PLUGIN_NAME = "NodeStuffPlugin";
|
||||||
|
|
||||||
|
@ -193,7 +194,11 @@ class NodeStuffPlugin {
|
||||||
break;
|
break;
|
||||||
case true:
|
case true:
|
||||||
setModuleConstant("__filename", module =>
|
setModuleConstant("__filename", module =>
|
||||||
relative(compiler.inputFileSystem, context, module.resource)
|
relative(
|
||||||
|
/** @type {InputFileSystem} */ (compiler.inputFileSystem),
|
||||||
|
context,
|
||||||
|
module.resource
|
||||||
|
)
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -227,7 +232,11 @@ class NodeStuffPlugin {
|
||||||
break;
|
break;
|
||||||
case true:
|
case true:
|
||||||
setModuleConstant("__dirname", module =>
|
setModuleConstant("__dirname", module =>
|
||||||
relative(compiler.inputFileSystem, context, module.context)
|
relative(
|
||||||
|
/** @type {InputFileSystem} */ (compiler.inputFileSystem),
|
||||||
|
context,
|
||||||
|
module.context
|
||||||
|
)
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
const { join, dirname } = require("./util/fs");
|
const { join, dirname } = require("./util/fs");
|
||||||
|
|
||||||
/** @typedef {import("./Compiler")} Compiler */
|
/** @typedef {import("./Compiler")} Compiler */
|
||||||
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
||||||
|
|
||||||
/** @typedef {function(import("./NormalModuleFactory").ResolveData): void} ModuleReplacer */
|
/** @typedef {function(import("./NormalModuleFactory").ResolveData): void} ModuleReplacer */
|
||||||
|
|
||||||
class NormalModuleReplacementPlugin {
|
class NormalModuleReplacementPlugin {
|
||||||
|
@ -49,7 +51,9 @@ class NormalModuleReplacementPlugin {
|
||||||
if (typeof newResource === "function") {
|
if (typeof newResource === "function") {
|
||||||
newResource(result);
|
newResource(result);
|
||||||
} else {
|
} else {
|
||||||
const fs = compiler.inputFileSystem;
|
const fs =
|
||||||
|
/** @type {InputFileSystem} */
|
||||||
|
(compiler.inputFileSystem);
|
||||||
if (
|
if (
|
||||||
newResource.startsWith("/") ||
|
newResource.startsWith("/") ||
|
||||||
(newResource.length > 1 && newResource[1] === ":")
|
(newResource.length > 1 && newResource[1] === ":")
|
||||||
|
|
|
@ -29,6 +29,7 @@ const { makePathsAbsolute } = require("./util/identifier");
|
||||||
/** @typedef {import("./Module")} Module */
|
/** @typedef {import("./Module")} Module */
|
||||||
/** @typedef {import("./NormalModule").SourceMap} SourceMap */
|
/** @typedef {import("./NormalModule").SourceMap} SourceMap */
|
||||||
/** @typedef {import("./util/Hash")} Hash */
|
/** @typedef {import("./util/Hash")} Hash */
|
||||||
|
/** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
|
||||||
|
|
||||||
const validate = createSchemaValidation(
|
const validate = createSchemaValidation(
|
||||||
require("../schemas/plugins/SourceMapDevToolPlugin.check.js"),
|
require("../schemas/plugins/SourceMapDevToolPlugin.check.js"),
|
||||||
|
@ -165,7 +166,9 @@ class SourceMapDevToolPlugin {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
const outputFs = compiler.outputFileSystem;
|
const outputFs = /** @type {OutputFileSystem} */ (
|
||||||
|
compiler.outputFileSystem
|
||||||
|
);
|
||||||
const sourceMapFilename = this.sourceMapFilename;
|
const sourceMapFilename = this.sourceMapFilename;
|
||||||
const sourceMappingURLComment = this.sourceMappingURLComment;
|
const sourceMappingURLComment = this.sourceMappingURLComment;
|
||||||
const moduleFilenameTemplate = this.moduleFilenameTemplate;
|
const moduleFilenameTemplate = this.moduleFilenameTemplate;
|
||||||
|
|
|
@ -57,6 +57,8 @@ const { cleverMerge } = require("./util/cleverMerge");
|
||||||
|
|
||||||
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
||||||
/** @typedef {import("./Compiler")} Compiler */
|
/** @typedef {import("./Compiler")} Compiler */
|
||||||
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
||||||
|
/** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
||||||
|
|
||||||
class WebpackOptionsApply extends OptionsApply {
|
class WebpackOptionsApply extends OptionsApply {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -652,7 +654,9 @@ class WebpackOptionsApply extends OptionsApply {
|
||||||
new IdleFileCachePlugin(
|
new IdleFileCachePlugin(
|
||||||
new PackFileCacheStrategy({
|
new PackFileCacheStrategy({
|
||||||
compiler,
|
compiler,
|
||||||
fs: compiler.intermediateFileSystem,
|
fs: /** @type {IntermediateFileSystem} */ (
|
||||||
|
compiler.intermediateFileSystem
|
||||||
|
),
|
||||||
context: options.context,
|
context: options.context,
|
||||||
cacheLocation: cacheOptions.cacheLocation,
|
cacheLocation: cacheOptions.cacheLocation,
|
||||||
version: cacheOptions.version,
|
version: cacheOptions.version,
|
||||||
|
@ -697,14 +701,18 @@ class WebpackOptionsApply extends OptionsApply {
|
||||||
.for("normal")
|
.for("normal")
|
||||||
.tap("WebpackOptionsApply", resolveOptions => {
|
.tap("WebpackOptionsApply", resolveOptions => {
|
||||||
resolveOptions = cleverMerge(options.resolve, resolveOptions);
|
resolveOptions = cleverMerge(options.resolve, resolveOptions);
|
||||||
resolveOptions.fileSystem = compiler.inputFileSystem;
|
resolveOptions.fileSystem =
|
||||||
|
/** @type {InputFileSystem} */
|
||||||
|
(compiler.inputFileSystem);
|
||||||
return resolveOptions;
|
return resolveOptions;
|
||||||
});
|
});
|
||||||
compiler.resolverFactory.hooks.resolveOptions
|
compiler.resolverFactory.hooks.resolveOptions
|
||||||
.for("context")
|
.for("context")
|
||||||
.tap("WebpackOptionsApply", resolveOptions => {
|
.tap("WebpackOptionsApply", resolveOptions => {
|
||||||
resolveOptions = cleverMerge(options.resolve, resolveOptions);
|
resolveOptions = cleverMerge(options.resolve, resolveOptions);
|
||||||
resolveOptions.fileSystem = compiler.inputFileSystem;
|
resolveOptions.fileSystem =
|
||||||
|
/** @type {InputFileSystem} */
|
||||||
|
(compiler.inputFileSystem);
|
||||||
resolveOptions.resolveToContext = true;
|
resolveOptions.resolveToContext = true;
|
||||||
return resolveOptions;
|
return resolveOptions;
|
||||||
});
|
});
|
||||||
|
@ -712,7 +720,9 @@ class WebpackOptionsApply extends OptionsApply {
|
||||||
.for("loader")
|
.for("loader")
|
||||||
.tap("WebpackOptionsApply", resolveOptions => {
|
.tap("WebpackOptionsApply", resolveOptions => {
|
||||||
resolveOptions = cleverMerge(options.resolveLoader, resolveOptions);
|
resolveOptions = cleverMerge(options.resolveLoader, resolveOptions);
|
||||||
resolveOptions.fileSystem = compiler.inputFileSystem;
|
resolveOptions.fileSystem =
|
||||||
|
/** @type {InputFileSystem} */
|
||||||
|
(compiler.inputFileSystem);
|
||||||
return resolveOptions;
|
return resolveOptions;
|
||||||
});
|
});
|
||||||
compiler.hooks.afterResolvers.call(compiler);
|
compiler.hooks.afterResolvers.call(compiler);
|
||||||
|
|
|
@ -1839,7 +1839,7 @@ declare class Compilation {
|
||||||
endTime?: number;
|
endTime?: number;
|
||||||
compiler: Compiler;
|
compiler: Compiler;
|
||||||
resolverFactory: ResolverFactory;
|
resolverFactory: ResolverFactory;
|
||||||
inputFileSystem: null | InputFileSystem;
|
inputFileSystem: InputFileSystem;
|
||||||
fileSystemInfo: FileSystemInfo;
|
fileSystemInfo: FileSystemInfo;
|
||||||
valueCacheVersions: Map<string, string | Set<string>>;
|
valueCacheVersions: Map<string, string | Set<string>>;
|
||||||
requestShortener: RequestShortener;
|
requestShortener: RequestShortener;
|
||||||
|
|
Loading…
Reference in New Issue