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