mirror of https://github.com/webpack/webpack.git
refactor filesystem interfaces
add Compiler.intermediateFileSystem avoid using `path` and `fs` module when possible move `join`, `mkdirp` and `dirname` into utils join and dirname is optional in FileSystem interface remove mkdirp from Filesystem interface
This commit is contained in:
parent
224daec09d
commit
e9c0d068dd
|
@ -61,7 +61,7 @@ const cli = {
|
||||||
|
|
||||||
if (!cli.installed) {
|
if (!cli.installed) {
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("graceful-fs");
|
||||||
const readLine = require("readline");
|
const readLine = require("readline");
|
||||||
|
|
||||||
const notify =
|
const notify =
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
const parseJson = require("json-parse-better-errors");
|
const parseJson = require("json-parse-better-errors");
|
||||||
const asyncLib = require("neo-async");
|
const asyncLib = require("neo-async");
|
||||||
const path = require("path");
|
|
||||||
const {
|
const {
|
||||||
SyncHook,
|
SyncHook,
|
||||||
SyncBailHook,
|
SyncBailHook,
|
||||||
|
@ -25,6 +24,7 @@ const RequestShortener = require("./RequestShortener");
|
||||||
const ResolverFactory = require("./ResolverFactory");
|
const ResolverFactory = require("./ResolverFactory");
|
||||||
const Stats = require("./Stats");
|
const Stats = require("./Stats");
|
||||||
const Watching = require("./Watching");
|
const Watching = require("./Watching");
|
||||||
|
const { join, dirname, mkdirp } = require("./util/fs");
|
||||||
const { makePathsRelative } = require("./util/identifier");
|
const { makePathsRelative } = require("./util/identifier");
|
||||||
|
|
||||||
/** @typedef {import("webpack-sources").Source} Source */
|
/** @typedef {import("webpack-sources").Source} Source */
|
||||||
|
@ -36,6 +36,9 @@ const { makePathsRelative } = require("./util/identifier");
|
||||||
/** @typedef {import("./Chunk")} Chunk */
|
/** @typedef {import("./Chunk")} Chunk */
|
||||||
/** @typedef {import("./FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
|
/** @typedef {import("./FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
|
||||||
/** @typedef {import("./Module")} Module */
|
/** @typedef {import("./Module")} Module */
|
||||||
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
||||||
|
/** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
||||||
|
/** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} CompilationParams
|
* @typedef {Object} CompilationParams
|
||||||
|
@ -151,7 +154,11 @@ class Compiler {
|
||||||
/** @type {string} */
|
/** @type {string} */
|
||||||
this.outputPath = "";
|
this.outputPath = "";
|
||||||
|
|
||||||
|
/** @type {OutputFileSystem} */
|
||||||
this.outputFileSystem = null;
|
this.outputFileSystem = null;
|
||||||
|
/** @type {IntermediateFileSystem} */
|
||||||
|
this.intermediateFileSystem = null;
|
||||||
|
/** @type {InputFileSystem} */
|
||||||
this.inputFileSystem = null;
|
this.inputFileSystem = null;
|
||||||
this.watchFileSystem = null;
|
this.watchFileSystem = null;
|
||||||
|
|
||||||
|
@ -353,7 +360,8 @@ class Compiler {
|
||||||
|
|
||||||
const writeOut = err => {
|
const writeOut = err => {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
const targetPath = this.outputFileSystem.join(
|
const targetPath = join(
|
||||||
|
this.outputFileSystem,
|
||||||
outputPath,
|
outputPath,
|
||||||
targetFile
|
targetFile
|
||||||
);
|
);
|
||||||
|
@ -424,11 +432,9 @@ class Compiler {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (targetFile.match(/\/|\\/)) {
|
if (targetFile.match(/\/|\\/)) {
|
||||||
const dir = path.dirname(targetFile);
|
const fs = this.outputFileSystem;
|
||||||
this.outputFileSystem.mkdirp(
|
const dir = dirname(fs, join(fs, outputPath, targetFile));
|
||||||
this.outputFileSystem.join(outputPath, dir),
|
mkdirp(fs, dir, writeOut);
|
||||||
writeOut
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
writeOut();
|
writeOut();
|
||||||
}
|
}
|
||||||
|
@ -448,7 +454,7 @@ class Compiler {
|
||||||
this.hooks.emit.callAsync(compilation, err => {
|
this.hooks.emit.callAsync(compilation, err => {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
outputPath = compilation.getPath(this.outputPath, {});
|
outputPath = compilation.getPath(this.outputPath, {});
|
||||||
this.outputFileSystem.mkdirp(outputPath, emitFiles);
|
mkdirp(this.outputFileSystem, outputPath, emitFiles);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -458,14 +464,6 @@ class Compiler {
|
||||||
*/
|
*/
|
||||||
emitRecords(callback) {
|
emitRecords(callback) {
|
||||||
if (!this.recordsOutputPath) return callback();
|
if (!this.recordsOutputPath) return callback();
|
||||||
const idx1 = this.recordsOutputPath.lastIndexOf("/");
|
|
||||||
const idx2 = this.recordsOutputPath.lastIndexOf("\\");
|
|
||||||
let recordsOutputPathDirectory = null;
|
|
||||||
if (idx1 > idx2) {
|
|
||||||
recordsOutputPathDirectory = this.recordsOutputPath.substr(0, idx1);
|
|
||||||
} else if (idx1 < idx2) {
|
|
||||||
recordsOutputPathDirectory = this.recordsOutputPath.substr(0, idx2);
|
|
||||||
}
|
|
||||||
|
|
||||||
const writeFile = () => {
|
const writeFile = () => {
|
||||||
this.outputFileSystem.writeFile(
|
this.outputFileSystem.writeFile(
|
||||||
|
@ -491,10 +489,14 @@ class Compiler {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const recordsOutputPathDirectory = dirname(
|
||||||
|
this.outputFileSystem,
|
||||||
|
this.recordsOutputPath
|
||||||
|
);
|
||||||
if (!recordsOutputPathDirectory) {
|
if (!recordsOutputPathDirectory) {
|
||||||
return writeFile();
|
return writeFile();
|
||||||
}
|
}
|
||||||
this.outputFileSystem.mkdirp(recordsOutputPathDirectory, err => {
|
mkdirp(this.outputFileSystem, recordsOutputPathDirectory, err => {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
writeFile();
|
writeFile();
|
||||||
});
|
});
|
||||||
|
@ -630,11 +632,12 @@ class Compiler {
|
||||||
}
|
}
|
||||||
|
|
||||||
createNormalModuleFactory() {
|
createNormalModuleFactory() {
|
||||||
const normalModuleFactory = new NormalModuleFactory(
|
const normalModuleFactory = new NormalModuleFactory({
|
||||||
this.options.context,
|
context: this.options.context,
|
||||||
this.resolverFactory,
|
fs: this.inputFileSystem,
|
||||||
this.options.module || {}
|
resolverFactory: this.resolverFactory,
|
||||||
);
|
options: this.options.module || {}
|
||||||
|
});
|
||||||
this.hooks.normalModuleFactory.call(normalModuleFactory);
|
this.hooks.normalModuleFactory.call(normalModuleFactory);
|
||||||
return normalModuleFactory;
|
return normalModuleFactory;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,11 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const asyncLib = require("neo-async");
|
const asyncLib = require("neo-async");
|
||||||
const path = require("path");
|
|
||||||
|
|
||||||
const { AsyncSeriesWaterfallHook, SyncWaterfallHook } = require("tapable");
|
const { AsyncSeriesWaterfallHook, SyncWaterfallHook } = require("tapable");
|
||||||
const ContextModule = require("./ContextModule");
|
const ContextModule = require("./ContextModule");
|
||||||
const ModuleFactory = require("./ModuleFactory");
|
const ModuleFactory = require("./ModuleFactory");
|
||||||
const ContextElementDependency = require("./dependencies/ContextElementDependency");
|
const ContextElementDependency = require("./dependencies/ContextElementDependency");
|
||||||
|
const { join } = require("./util/fs");
|
||||||
|
|
||||||
/** @typedef {import("./Module")} Module */
|
/** @typedef {import("./Module")} Module */
|
||||||
/** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
|
/** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
|
||||||
|
@ -195,7 +194,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
||||||
asyncLib.map(
|
asyncLib.map(
|
||||||
files.filter(p => p.indexOf(".") !== 0),
|
files.filter(p => p.indexOf(".") !== 0),
|
||||||
(segment, callback) => {
|
(segment, callback) => {
|
||||||
const subResource = path.join(directory, segment);
|
const subResource = join(fs, directory, segment);
|
||||||
|
|
||||||
if (!exclude || !subResource.match(exclude)) {
|
if (!exclude || !subResource.match(exclude)) {
|
||||||
fs.stat(subResource, (err, stat) => {
|
fs.stat(subResource, (err, stat) => {
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const path = require("path");
|
|
||||||
const ContextElementDependency = require("./dependencies/ContextElementDependency");
|
const ContextElementDependency = require("./dependencies/ContextElementDependency");
|
||||||
|
const { join } = require("./util/fs");
|
||||||
|
|
||||||
class ContextReplacementPlugin {
|
class ContextReplacementPlugin {
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -84,7 +84,18 @@ class ContextReplacementPlugin {
|
||||||
if (!result) return;
|
if (!result) return;
|
||||||
if (resourceRegExp.test(result.resource)) {
|
if (resourceRegExp.test(result.resource)) {
|
||||||
if (newContentResource !== undefined) {
|
if (newContentResource !== undefined) {
|
||||||
result.resource = path.resolve(result.resource, newContentResource);
|
if (
|
||||||
|
newContentResource.startsWith("/") ||
|
||||||
|
(newContentResource.length > 1 && newContentResource[1] === ":")
|
||||||
|
) {
|
||||||
|
result.resource = newContentResource;
|
||||||
|
} else {
|
||||||
|
result.resource = join(
|
||||||
|
compiler.inputFileSystem,
|
||||||
|
result.resource,
|
||||||
|
newContentResource
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (newContentRecursive !== undefined) {
|
if (newContentRecursive !== undefined) {
|
||||||
result.recursive = newContentRecursive;
|
result.recursive = newContentRecursive;
|
||||||
|
@ -100,8 +111,17 @@ class ContextReplacementPlugin {
|
||||||
if (typeof newContentCallback === "function") {
|
if (typeof newContentCallback === "function") {
|
||||||
const origResource = result.resource;
|
const origResource = result.resource;
|
||||||
newContentCallback(result);
|
newContentCallback(result);
|
||||||
if (result.resource !== origResource) {
|
if (
|
||||||
result.resource = path.resolve(origResource, result.resource);
|
result.resource !== origResource &&
|
||||||
|
!result.resource.startsWith("/") &&
|
||||||
|
(result.resource.length <= 1 || result.resource[1] !== ":")
|
||||||
|
) {
|
||||||
|
// When the function changed it to an relative path
|
||||||
|
result.resource = join(
|
||||||
|
compiler.inputFileSystem,
|
||||||
|
origResource,
|
||||||
|
result.resource
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (const d of result.dependencies) {
|
for (const d of result.dependencies) {
|
||||||
|
|
|
@ -5,20 +5,10 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const path = require("path");
|
|
||||||
|
|
||||||
const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
||||||
const UnsupportedFeatureWarning = require("./UnsupportedFeatureWarning");
|
const UnsupportedFeatureWarning = require("./UnsupportedFeatureWarning");
|
||||||
const ConstDependency = require("./dependencies/ConstDependency");
|
const ConstDependency = require("./dependencies/ConstDependency");
|
||||||
|
|
||||||
exports.getModulePath = (context, pathToModule) => {
|
|
||||||
let moduleJsPath = path.relative(context, pathToModule);
|
|
||||||
if (!/^[A-Z]:/i.test(moduleJsPath)) {
|
|
||||||
moduleJsPath = "./" + moduleJsPath.replace(/\\/g, "/");
|
|
||||||
}
|
|
||||||
return moduleJsPath;
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.toConstantDependency = (parser, value, runtimeRequirements) => {
|
exports.toConstantDependency = (parser, value, runtimeRequirements) => {
|
||||||
return function constDependency(expr) {
|
return function constDependency(expr) {
|
||||||
const dep = new ConstDependency(value, expr.range, runtimeRequirements);
|
const dep = new ConstDependency(value, expr.range, runtimeRequirements);
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const asyncLib = require("neo-async");
|
const asyncLib = require("neo-async");
|
||||||
const path = require("path");
|
|
||||||
const EntryDependency = require("./dependencies/EntryDependency");
|
const EntryDependency = require("./dependencies/EntryDependency");
|
||||||
const { compareModulesById } = require("./util/comparators");
|
const { compareModulesById } = require("./util/comparators");
|
||||||
|
const { dirname, mkdirp } = require("./util/fs");
|
||||||
|
|
||||||
/** @typedef {import("./Compiler")} Compiler */
|
/** @typedef {import("./Compiler")} Compiler */
|
||||||
|
|
||||||
|
@ -99,14 +99,18 @@ class LibManifestPlugin {
|
||||||
? JSON.stringify(manifest, null, 2)
|
? JSON.stringify(manifest, null, 2)
|
||||||
: JSON.stringify(manifest);
|
: JSON.stringify(manifest);
|
||||||
const content = Buffer.from(manifestContent, "utf8");
|
const content = Buffer.from(manifestContent, "utf8");
|
||||||
compiler.outputFileSystem.mkdirp(path.dirname(targetPath), err => {
|
mkdirp(
|
||||||
|
compiler.intermediateFileSystem,
|
||||||
|
dirname(compiler.intermediateFileSystem, targetPath),
|
||||||
|
err => {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
compiler.outputFileSystem.writeFile(
|
compiler.intermediateFileSystem.writeFile(
|
||||||
targetPath,
|
targetPath,
|
||||||
content,
|
content,
|
||||||
callback
|
callback
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
callback
|
callback
|
||||||
);
|
);
|
||||||
|
|
|
@ -17,6 +17,9 @@ const MultiWatching = require("./MultiWatching");
|
||||||
/** @typedef {import("./Compiler")} Compiler */
|
/** @typedef {import("./Compiler")} Compiler */
|
||||||
/** @typedef {import("./Stats")} Stats */
|
/** @typedef {import("./Stats")} Stats */
|
||||||
/** @typedef {import("./Watching")} Watching */
|
/** @typedef {import("./Watching")} Watching */
|
||||||
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
||||||
|
/** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
||||||
|
/** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
|
||||||
|
|
||||||
/** @typedef {number} CompilerStatus */
|
/** @typedef {number} CompilerStatus */
|
||||||
|
|
||||||
|
@ -117,18 +120,37 @@ module.exports = class MultiCompiler {
|
||||||
throw new Error("Cannot read outputFileSystem of a MultiCompiler");
|
throw new Error("Cannot read outputFileSystem of a MultiCompiler");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get intermediateFileSystem() {
|
||||||
|
throw new Error("Cannot read outputFileSystem of a MultiCompiler");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {InputFileSystem} value the new input file system
|
||||||
|
*/
|
||||||
set inputFileSystem(value) {
|
set inputFileSystem(value) {
|
||||||
for (const compiler of this.compilers) {
|
for (const compiler of this.compilers) {
|
||||||
compiler.inputFileSystem = value;
|
compiler.inputFileSystem = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {OutputFileSystem} value the new output file system
|
||||||
|
*/
|
||||||
set outputFileSystem(value) {
|
set outputFileSystem(value) {
|
||||||
for (const compiler of this.compilers) {
|
for (const compiler of this.compilers) {
|
||||||
compiler.outputFileSystem = value;
|
compiler.outputFileSystem = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {IntermediateFileSystem} value the new intermediate file system
|
||||||
|
*/
|
||||||
|
set intermediateFileSystem(value) {
|
||||||
|
for (const compiler of this.compilers) {
|
||||||
|
compiler.intermediateFileSystem = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Compiler} compiler the child compiler
|
* @param {Compiler} compiler the child compiler
|
||||||
* @param {string[]} dependencies its dependencies
|
* @param {string[]} dependencies its dependencies
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const path = require("path");
|
|
||||||
const {
|
const {
|
||||||
evaluateToString,
|
evaluateToString,
|
||||||
expressionIsUnsupported
|
expressionIsUnsupported
|
||||||
} = require("./JavascriptParserHelpers");
|
} = require("./JavascriptParserHelpers");
|
||||||
const CachedConstDependency = require("./dependencies/CachedConstDependency");
|
const CachedConstDependency = require("./dependencies/CachedConstDependency");
|
||||||
|
const { relative } = require("./util/fs");
|
||||||
|
|
||||||
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
||||||
/** @typedef {import("./Compiler")} Compiler */
|
/** @typedef {import("./Compiler")} Compiler */
|
||||||
|
@ -65,7 +65,7 @@ class NodeStuffPlugin {
|
||||||
setConstant("__filename", "/index.js");
|
setConstant("__filename", "/index.js");
|
||||||
} else {
|
} else {
|
||||||
setModuleConstant("__filename", module =>
|
setModuleConstant("__filename", module =>
|
||||||
path.relative(context, module.resource)
|
relative(compiler.inputFileSystem, context, module.resource)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
parser.hooks.evaluateIdentifier
|
parser.hooks.evaluateIdentifier
|
||||||
|
@ -84,7 +84,7 @@ class NodeStuffPlugin {
|
||||||
setConstant("__dirname", "/");
|
setConstant("__dirname", "/");
|
||||||
} else {
|
} else {
|
||||||
setModuleConstant("__dirname", module =>
|
setModuleConstant("__dirname", module =>
|
||||||
path.relative(context, module.context)
|
relative(compiler.inputFileSystem, context, module.context)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
parser.hooks.evaluateIdentifier
|
parser.hooks.evaluateIdentifier
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const asyncLib = require("neo-async");
|
const asyncLib = require("neo-async");
|
||||||
const path = require("path");
|
|
||||||
const {
|
const {
|
||||||
AsyncSeriesBailHook,
|
AsyncSeriesBailHook,
|
||||||
SyncWaterfallHook,
|
SyncWaterfallHook,
|
||||||
|
@ -23,6 +22,7 @@ const BasicMatcherRulePlugin = require("./rules/BasicMatcherRulePlugin");
|
||||||
const RuleSetCompiler = require("./rules/RuleSetCompiler");
|
const RuleSetCompiler = require("./rules/RuleSetCompiler");
|
||||||
const UseEffectRulePlugin = require("./rules/UseEffectRulePlugin");
|
const UseEffectRulePlugin = require("./rules/UseEffectRulePlugin");
|
||||||
const { cachedCleverMerge } = require("./util/cleverMerge");
|
const { cachedCleverMerge } = require("./util/cleverMerge");
|
||||||
|
const { join } = require("./util/fs");
|
||||||
|
|
||||||
/** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
|
/** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
|
||||||
/** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
|
/** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
|
||||||
|
@ -123,7 +123,7 @@ const ruleSetCompiler = new RuleSetCompiler([
|
||||||
]);
|
]);
|
||||||
|
|
||||||
class NormalModuleFactory extends ModuleFactory {
|
class NormalModuleFactory extends ModuleFactory {
|
||||||
constructor(context, resolverFactory, options) {
|
constructor({ context, fs, resolverFactory, options }) {
|
||||||
super();
|
super();
|
||||||
this.hooks = Object.freeze({
|
this.hooks = Object.freeze({
|
||||||
/** @type {AsyncSeriesBailHook<[ResolveData], TODO>} */
|
/** @type {AsyncSeriesBailHook<[ResolveData], TODO>} */
|
||||||
|
@ -162,6 +162,7 @@ class NormalModuleFactory extends ModuleFactory {
|
||||||
? options.unsafeCache
|
? options.unsafeCache
|
||||||
: () => true;
|
: () => true;
|
||||||
this.context = context || "";
|
this.context = context || "";
|
||||||
|
this.fs = fs;
|
||||||
this.parserCache = Object.create(null);
|
this.parserCache = Object.create(null);
|
||||||
this.generatorCache = Object.create(null);
|
this.generatorCache = Object.create(null);
|
||||||
this.hooks.factorize.tapAsync(
|
this.hooks.factorize.tapAsync(
|
||||||
|
@ -250,7 +251,7 @@ class NormalModuleFactory extends ModuleFactory {
|
||||||
(secondChar === 46 && matchResource.charCodeAt(2) === 47)
|
(secondChar === 46 && matchResource.charCodeAt(2) === 47)
|
||||||
) {
|
) {
|
||||||
// if matchResources startsWith ../ or ./
|
// if matchResources startsWith ../ or ./
|
||||||
matchResource = path.join(context, matchResource);
|
matchResource = join(this.fs, context, matchResource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
requestWithoutMatchResource = request.substr(
|
requestWithoutMatchResource = request.substr(
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const path = require("path");
|
const { join, dirname } = require("./util/fs");
|
||||||
|
|
||||||
/** @typedef {import("./Compiler")} Compiler */
|
/** @typedef {import("./Compiler")} Compiler */
|
||||||
/** @typedef {function(TODO): void} ModuleReplacer */
|
/** @typedef {function(TODO): void} ModuleReplacer */
|
||||||
|
@ -48,12 +48,21 @@ class NormalModuleReplacementPlugin {
|
||||||
if (typeof newResource === "function") {
|
if (typeof newResource === "function") {
|
||||||
newResource(result);
|
newResource(result);
|
||||||
} else {
|
} else {
|
||||||
createData.resource = path.resolve(
|
const fs = compiler.inputFileSystem;
|
||||||
path.dirname(createData.resource),
|
if (
|
||||||
|
newResource.startsWith("/") ||
|
||||||
|
(newResource.length > 1 && newResource[1] === ":")
|
||||||
|
) {
|
||||||
|
createData.resource = newResource;
|
||||||
|
} else {
|
||||||
|
createData.resource = join(
|
||||||
|
fs,
|
||||||
|
dirname(fs, createData.resource),
|
||||||
newResource
|
newResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const path = require("path");
|
const { join, dirname: fsDirname } = require("./util/fs");
|
||||||
|
|
||||||
const NORMALIZE_SLASH_DIRECTION_REGEXP = /\\/g;
|
const NORMALIZE_SLASH_DIRECTION_REGEXP = /\\/g;
|
||||||
const PATH_CHARS_REGEXP = /[-[\]{}()*+?.,\\^$|#\s]/g;
|
const PATH_CHARS_REGEXP = /[-[\]{}()*+?.,\\^$|#\s]/g;
|
||||||
|
@ -54,7 +54,7 @@ class RequestShortener {
|
||||||
this.currentDirectoryRegExp = createRegExpForPath(directory);
|
this.currentDirectoryRegExp = createRegExpForPath(directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
const dirname = path.dirname(directory);
|
const dirname = fsDirname(undefined, directory);
|
||||||
const endsWithSeparator = SEPARATOR_REGEXP.test(dirname);
|
const endsWithSeparator = SEPARATOR_REGEXP.test(dirname);
|
||||||
const parentDirectory = endsWithSeparator
|
const parentDirectory = endsWithSeparator
|
||||||
? dirname.substr(0, dirname.length - 1)
|
? dirname.substr(0, dirname.length - 1)
|
||||||
|
@ -65,7 +65,9 @@ class RequestShortener {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (__dirname.length >= 2) {
|
if (__dirname.length >= 2) {
|
||||||
const buildins = normalizeBackSlashDirection(path.join(__dirname, ".."));
|
const buildins = normalizeBackSlashDirection(
|
||||||
|
join(undefined, __dirname, "..")
|
||||||
|
);
|
||||||
const buildinsAsModule =
|
const buildinsAsModule =
|
||||||
this.currentDirectoryRegExp &&
|
this.currentDirectoryRegExp &&
|
||||||
this.currentDirectoryRegExp.test(buildins);
|
this.currentDirectoryRegExp.test(buildins);
|
||||||
|
|
|
@ -5,13 +5,13 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const path = require("path");
|
|
||||||
const validateOptions = require("schema-utils");
|
const validateOptions = require("schema-utils");
|
||||||
const { ConcatSource, RawSource } = require("webpack-sources");
|
const { ConcatSource, RawSource } = require("webpack-sources");
|
||||||
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
||||||
const ProgressPlugin = require("./ProgressPlugin");
|
const ProgressPlugin = require("./ProgressPlugin");
|
||||||
const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
|
const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
|
||||||
const createHash = require("./util/createHash");
|
const createHash = require("./util/createHash");
|
||||||
|
const { relative, dirname } = require("./util/fs");
|
||||||
|
|
||||||
const schema = require("../schemas/plugins/SourceMapDevToolPlugin.json");
|
const schema = require("../schemas/plugins/SourceMapDevToolPlugin.json");
|
||||||
|
|
||||||
|
@ -80,6 +80,7 @@ class SourceMapDevToolPlugin {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
|
const outputFs = 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;
|
||||||
|
@ -249,17 +250,23 @@ class SourceMapDevToolPlugin {
|
||||||
let sourceMapFile = compilation.getPath(sourceMapFilename, {
|
let sourceMapFile = compilation.getPath(sourceMapFilename, {
|
||||||
chunk,
|
chunk,
|
||||||
filename: options.fileContext
|
filename: options.fileContext
|
||||||
? path.relative(options.fileContext, filename)
|
? relative(
|
||||||
|
outputFs,
|
||||||
|
`/${options.fileContext}`,
|
||||||
|
`/${filename}`
|
||||||
|
)
|
||||||
: filename,
|
: filename,
|
||||||
contentHash: createHash("md4")
|
contentHash: createHash("md4")
|
||||||
.update(sourceMapString)
|
.update(sourceMapString)
|
||||||
.digest("hex")
|
.digest("hex")
|
||||||
});
|
});
|
||||||
const sourceMapUrl = options.publicPath
|
const sourceMapUrl = options.publicPath
|
||||||
? options.publicPath + sourceMapFile.replace(/\\/g, "/")
|
? options.publicPath + sourceMapFile
|
||||||
: path
|
: relative(
|
||||||
.relative(path.dirname(file), sourceMapFile)
|
outputFs,
|
||||||
.replace(/\\/g, "/");
|
dirname(outputFs, `/${file}`),
|
||||||
|
`/${sourceMapFile}`
|
||||||
|
);
|
||||||
if (currentSourceMappingURLComment !== false) {
|
if (currentSourceMappingURLComment !== false) {
|
||||||
assets[file] = compilation.assets[file] = new ConcatSource(
|
assets[file] = compilation.assets[file] = new ConcatSource(
|
||||||
new RawSource(source),
|
new RawSource(source),
|
||||||
|
|
|
@ -550,6 +550,7 @@ class WebpackOptionsApply extends OptionsApply {
|
||||||
const SeparateFilesCacheStrategy = require("./cache/SeparateFilesCacheStrategy");
|
const SeparateFilesCacheStrategy = require("./cache/SeparateFilesCacheStrategy");
|
||||||
new InstantFileCachePlugin(
|
new InstantFileCachePlugin(
|
||||||
new SeparateFilesCacheStrategy({
|
new SeparateFilesCacheStrategy({
|
||||||
|
fs: compiler.intermediateFileSystem,
|
||||||
cacheLocation: cacheOptions.cacheLocation,
|
cacheLocation: cacheOptions.cacheLocation,
|
||||||
version: cacheOptions.version,
|
version: cacheOptions.version,
|
||||||
hashAlgorithm: cacheOptions.hashAlgorithm,
|
hashAlgorithm: cacheOptions.hashAlgorithm,
|
||||||
|
@ -563,6 +564,7 @@ class WebpackOptionsApply extends OptionsApply {
|
||||||
const SeparateFilesCacheStrategy = require("./cache/SeparateFilesCacheStrategy");
|
const SeparateFilesCacheStrategy = require("./cache/SeparateFilesCacheStrategy");
|
||||||
new BackgroundFileCachePlugin(
|
new BackgroundFileCachePlugin(
|
||||||
new SeparateFilesCacheStrategy({
|
new SeparateFilesCacheStrategy({
|
||||||
|
fs: compiler.intermediateFileSystem,
|
||||||
cacheLocation: cacheOptions.cacheLocation,
|
cacheLocation: cacheOptions.cacheLocation,
|
||||||
version: cacheOptions.version,
|
version: cacheOptions.version,
|
||||||
hashAlgorithm: cacheOptions.hashAlgorithm,
|
hashAlgorithm: cacheOptions.hashAlgorithm,
|
||||||
|
@ -576,6 +578,7 @@ class WebpackOptionsApply extends OptionsApply {
|
||||||
const SeparateFilesCacheStrategy = require("./cache/SeparateFilesCacheStrategy");
|
const SeparateFilesCacheStrategy = require("./cache/SeparateFilesCacheStrategy");
|
||||||
new IdleFileCachePlugin(
|
new IdleFileCachePlugin(
|
||||||
new SeparateFilesCacheStrategy({
|
new SeparateFilesCacheStrategy({
|
||||||
|
fs: compiler.intermediateFileSystem,
|
||||||
cacheLocation: cacheOptions.cacheLocation,
|
cacheLocation: cacheOptions.cacheLocation,
|
||||||
version: cacheOptions.version,
|
version: cacheOptions.version,
|
||||||
hashAlgorithm: cacheOptions.hashAlgorithm,
|
hashAlgorithm: cacheOptions.hashAlgorithm,
|
||||||
|
@ -589,6 +592,7 @@ class WebpackOptionsApply extends OptionsApply {
|
||||||
const PackFileCacheStrategy = require("./cache/PackFileCacheStrategy");
|
const PackFileCacheStrategy = require("./cache/PackFileCacheStrategy");
|
||||||
new IdleFileCachePlugin(
|
new IdleFileCachePlugin(
|
||||||
new PackFileCacheStrategy({
|
new PackFileCacheStrategy({
|
||||||
|
fs: compiler.intermediateFileSystem,
|
||||||
cacheLocation: cacheOptions.cacheLocation,
|
cacheLocation: cacheOptions.cacheLocation,
|
||||||
version: cacheOptions.version,
|
version: cacheOptions.version,
|
||||||
loglevel: cacheOptions.loglevel
|
loglevel: cacheOptions.loglevel
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
const makeSerializable = require("../util/makeSerializable");
|
const makeSerializable = require("../util/makeSerializable");
|
||||||
const {
|
const {
|
||||||
fileSerializer,
|
createFileSerializer,
|
||||||
NOT_SERIALIZABLE,
|
NOT_SERIALIZABLE,
|
||||||
MEASURE_START_OPERATION,
|
MEASURE_START_OPERATION,
|
||||||
MEASURE_END_OPERATION
|
MEASURE_END_OPERATION
|
||||||
|
@ -202,13 +202,14 @@ makeSerializable(
|
||||||
);
|
);
|
||||||
|
|
||||||
class PackFileCacheStrategy {
|
class PackFileCacheStrategy {
|
||||||
constructor({ cacheLocation, version, loglevel }) {
|
constructor({ fs, cacheLocation, version, loglevel }) {
|
||||||
|
this.fileSerializer = createFileSerializer(fs);
|
||||||
this.cacheLocation = cacheLocation;
|
this.cacheLocation = cacheLocation;
|
||||||
const log = loglevel
|
const log = loglevel
|
||||||
? { debug: 4, verbose: 3, info: 2, warning: 1 }[loglevel]
|
? { debug: 4, verbose: 3, info: 2, warning: 1 }[loglevel]
|
||||||
: 0;
|
: 0;
|
||||||
this.log = log;
|
this.log = log;
|
||||||
this.packPromise = fileSerializer
|
this.packPromise = this.fileSerializer
|
||||||
.deserialize({ filename: `${cacheLocation}.pack` })
|
.deserialize({ filename: `${cacheLocation}.pack` })
|
||||||
.then(cacheEntry => {
|
.then(cacheEntry => {
|
||||||
if (cacheEntry) {
|
if (cacheEntry) {
|
||||||
|
@ -279,7 +280,7 @@ class PackFileCacheStrategy {
|
||||||
// which are still referenced, but serializing the pack memorizes
|
// which are still referenced, but serializing the pack memorizes
|
||||||
// all data in the pack and makes it no longer need the backing file
|
// all data in the pack and makes it no longer need the backing file
|
||||||
// So it's safe to replace the pack file
|
// So it's safe to replace the pack file
|
||||||
return fileSerializer
|
return this.fileSerializer
|
||||||
.serialize(pack, {
|
.serialize(pack, {
|
||||||
filename: `${this.cacheLocation}.pack`
|
filename: `${this.cacheLocation}.pack`
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,12 +5,14 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const path = require("path");
|
|
||||||
const createHash = require("../util/createHash");
|
const createHash = require("../util/createHash");
|
||||||
const { fileSerializer } = require("../util/serialization");
|
const { join } = require("../util/fs");
|
||||||
|
const { createFileSerializer } = require("../util/serialization");
|
||||||
|
|
||||||
class SeparateFilesCacheStrategy {
|
class SeparateFilesCacheStrategy {
|
||||||
constructor({ cacheLocation, version, hashAlgorithm, loglevel }) {
|
constructor({ fs, cacheLocation, version, hashAlgorithm, loglevel }) {
|
||||||
|
this.fs = fs;
|
||||||
|
this.fileSerializer = createFileSerializer(fs);
|
||||||
this.cacheLocation = cacheLocation;
|
this.cacheLocation = cacheLocation;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.log = loglevel
|
this.log = loglevel
|
||||||
|
@ -32,8 +34,8 @@ class SeparateFilesCacheStrategy {
|
||||||
version: this.version
|
version: this.version
|
||||||
};
|
};
|
||||||
const relativeFilename = this.toHash(identifier) + ".data";
|
const relativeFilename = this.toHash(identifier) + ".data";
|
||||||
const filename = path.join(this.cacheLocation, relativeFilename);
|
const filename = join(this.fs, this.cacheLocation, relativeFilename);
|
||||||
return fileSerializer
|
return this.fileSerializer
|
||||||
.serialize(entry, { filename })
|
.serialize(entry, { filename })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (this.log >= 2) {
|
if (this.log >= 2) {
|
||||||
|
@ -53,8 +55,8 @@ class SeparateFilesCacheStrategy {
|
||||||
|
|
||||||
restore(identifier, etag) {
|
restore(identifier, etag) {
|
||||||
const relativeFilename = this.toHash(identifier) + ".data";
|
const relativeFilename = this.toHash(identifier) + ".data";
|
||||||
const filename = path.join(this.cacheLocation, relativeFilename);
|
const filename = join(this.fs, this.cacheLocation, relativeFilename);
|
||||||
return fileSerializer
|
return this.fileSerializer
|
||||||
.deserialize({ filename })
|
.deserialize({ filename })
|
||||||
.then(cacheEntry => {
|
.then(cacheEntry => {
|
||||||
if (cacheEntry === undefined) {
|
if (cacheEntry === undefined) {
|
||||||
|
|
|
@ -5,13 +5,12 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const { Tracer } = require("chrome-trace-event");
|
const { Tracer } = require("chrome-trace-event");
|
||||||
const fs = require("fs");
|
|
||||||
const mkdirp = require("mkdirp");
|
|
||||||
const path = require("path");
|
|
||||||
const validateOptions = require("schema-utils");
|
const validateOptions = require("schema-utils");
|
||||||
const schema = require("../../schemas/plugins/debug/ProfilingPlugin.json");
|
const schema = require("../../schemas/plugins/debug/ProfilingPlugin.json");
|
||||||
|
const { dirname, mkdirpSync } = require("../util/fs");
|
||||||
|
|
||||||
/** @typedef {import("../../declarations/plugins/debug/ProfilingPlugin").ProfilingPluginOptions} ProfilingPluginOptions */
|
/** @typedef {import("../../declarations/plugins/debug/ProfilingPlugin").ProfilingPluginOptions} ProfilingPluginOptions */
|
||||||
|
/** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
||||||
|
|
||||||
let inspector = undefined;
|
let inspector = undefined;
|
||||||
|
|
||||||
|
@ -93,17 +92,18 @@ class Profiler {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param {IntermediateFileSystem} fs filesystem used for output
|
||||||
* @param {string} outputPath The location where to write the log.
|
* @param {string} outputPath The location where to write the log.
|
||||||
* @returns {Trace} The trace object
|
* @returns {Trace} The trace object
|
||||||
*/
|
*/
|
||||||
const createTrace = outputPath => {
|
const createTrace = (fs, outputPath) => {
|
||||||
const trace = new Tracer({
|
const trace = new Tracer({
|
||||||
noStream: true
|
noStream: true
|
||||||
});
|
});
|
||||||
const profiler = new Profiler(inspector);
|
const profiler = new Profiler(inspector);
|
||||||
if (/\/|\\/.test(outputPath)) {
|
if (/\/|\\/.test(outputPath)) {
|
||||||
const dirPath = path.dirname(outputPath);
|
const dirPath = dirname(fs, outputPath);
|
||||||
mkdirp.sync(dirPath);
|
mkdirpSync(fs, dirPath);
|
||||||
}
|
}
|
||||||
const fsStream = fs.createWriteStream(outputPath);
|
const fsStream = fs.createWriteStream(outputPath);
|
||||||
|
|
||||||
|
@ -170,7 +170,10 @@ class ProfilingPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
const tracer = createTrace(this.outputPath);
|
const tracer = createTrace(
|
||||||
|
compiler.intermediateFileSystem,
|
||||||
|
this.outputPath
|
||||||
|
);
|
||||||
tracer.profiler.startProfiling();
|
tracer.profiler.startProfiling();
|
||||||
|
|
||||||
// Compiler Hooks
|
// Compiler Hooks
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
const CachedInputFileSystem = require("enhanced-resolve/lib/CachedInputFileSystem");
|
const CachedInputFileSystem = require("enhanced-resolve/lib/CachedInputFileSystem");
|
||||||
const NodeJsInputFileSystem = require("enhanced-resolve/lib/NodeJsInputFileSystem");
|
const NodeJsInputFileSystem = require("enhanced-resolve/lib/NodeJsInputFileSystem");
|
||||||
const NodeOutputFileSystem = require("./NodeOutputFileSystem");
|
const fs = require("graceful-fs");
|
||||||
const NodeWatchFileSystem = require("./NodeWatchFileSystem");
|
const NodeWatchFileSystem = require("./NodeWatchFileSystem");
|
||||||
|
|
||||||
/** @typedef {import("../Compiler")} Compiler */
|
/** @typedef {import("../Compiler")} Compiler */
|
||||||
|
@ -23,7 +23,8 @@ class NodeEnvironmentPlugin {
|
||||||
60000
|
60000
|
||||||
);
|
);
|
||||||
const inputFileSystem = compiler.inputFileSystem;
|
const inputFileSystem = compiler.inputFileSystem;
|
||||||
compiler.outputFileSystem = new NodeOutputFileSystem();
|
compiler.outputFileSystem = fs;
|
||||||
|
compiler.intermediateFileSystem = fs;
|
||||||
compiler.watchFileSystem = new NodeWatchFileSystem(
|
compiler.watchFileSystem = new NodeWatchFileSystem(
|
||||||
compiler.inputFileSystem
|
compiler.inputFileSystem
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
/*
|
|
||||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
||||||
Author Tobias Koppers @sokra
|
|
||||||
*/
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
const fs = require("fs");
|
|
||||||
const mkdirp = require("mkdirp");
|
|
||||||
const path = require("path");
|
|
||||||
|
|
||||||
class NodeOutputFileSystem {
|
|
||||||
constructor() {
|
|
||||||
this.mkdirp = mkdirp;
|
|
||||||
this.mkdir = fs.mkdir.bind(fs);
|
|
||||||
this.rmdir = fs.rmdir.bind(fs);
|
|
||||||
this.unlink = fs.unlink.bind(fs);
|
|
||||||
this.writeFile = fs.writeFile.bind(fs);
|
|
||||||
this.join = path.join.bind(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = NodeOutputFileSystem;
|
|
|
@ -4,10 +4,8 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const fs = require("fs");
|
|
||||||
const mkdirp = require("mkdirp");
|
|
||||||
const path = require("path");
|
|
||||||
const Queue = require("../util/Queue");
|
const Queue = require("../util/Queue");
|
||||||
|
const { dirname, mkdirp } = require("../util/fs");
|
||||||
const memorize = require("../util/memorize");
|
const memorize = require("../util/memorize");
|
||||||
const SerializerMiddleware = require("./SerializerMiddleware");
|
const SerializerMiddleware = require("./SerializerMiddleware");
|
||||||
|
|
||||||
|
@ -96,7 +94,8 @@ class Section {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class FileManager {
|
class FileManager {
|
||||||
constructor() {
|
constructor(fs) {
|
||||||
|
this.fs = fs;
|
||||||
/** @type {Map<string, Queue<FileJob>>} */
|
/** @type {Map<string, Queue<FileJob>>} */
|
||||||
this.jobs = new Map();
|
this.jobs = new Map();
|
||||||
this.processing = new Map();
|
this.processing = new Map();
|
||||||
|
@ -161,7 +160,7 @@ class FileManager {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
const closeFile = next => {
|
const closeFile = next => {
|
||||||
fs.close(fileHandle, err => {
|
this.fs.close(fileHandle, err => {
|
||||||
if (err) return handleError(err);
|
if (err) return handleError(err);
|
||||||
fileHandle = undefined;
|
fileHandle = undefined;
|
||||||
next();
|
next();
|
||||||
|
@ -174,7 +173,7 @@ class FileManager {
|
||||||
const openFile = () => {
|
const openFile = () => {
|
||||||
if (fileHandle === undefined) {
|
if (fileHandle === undefined) {
|
||||||
write = currentJob.write;
|
write = currentJob.write;
|
||||||
fs.open(filename, write ? "w" : "r", (err, file) => {
|
this.fs.open(filename, write ? "w" : "r", (err, file) => {
|
||||||
if (err) return handleError(err);
|
if (err) return handleError(err);
|
||||||
fileHandle = file;
|
fileHandle = file;
|
||||||
process();
|
process();
|
||||||
|
@ -210,20 +209,37 @@ class FileManager {
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const fileManager = new FileManager();
|
|
||||||
|
|
||||||
const createPointer = (filename, offset, size) => {
|
const fileManagers = new WeakMap();
|
||||||
|
|
||||||
|
const getFileManager = fs => {
|
||||||
|
const fm = fileManagers.get(fs);
|
||||||
|
if (fm !== undefined) return fm;
|
||||||
|
const fileManager = new FileManager(fs);
|
||||||
|
fileManagers.set(fs, fileManager);
|
||||||
|
return fileManager;
|
||||||
|
};
|
||||||
|
|
||||||
|
const createPointer = (fs, fileManager, filename, offset, size) => {
|
||||||
return memorize(() => {
|
return memorize(() => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fileManager.addJob(
|
fileManager.addJob(
|
||||||
filename,
|
filename,
|
||||||
false,
|
false,
|
||||||
(file, callback) => {
|
(file, callback) => {
|
||||||
readSection(filename, file, offset, size, (err, parts) => {
|
readSection(
|
||||||
|
fs,
|
||||||
|
fileManager,
|
||||||
|
filename,
|
||||||
|
file,
|
||||||
|
offset,
|
||||||
|
size,
|
||||||
|
(err, parts) => {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
resolve(parts);
|
resolve(parts);
|
||||||
callback();
|
callback();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
reject
|
reject
|
||||||
);
|
);
|
||||||
|
@ -231,7 +247,14 @@ const createPointer = (filename, offset, size) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const readFileSectionToBuffer = (fd, buffer, offset, position, callback) => {
|
const readFileSectionToBuffer = (
|
||||||
|
fs,
|
||||||
|
fd,
|
||||||
|
buffer,
|
||||||
|
offset,
|
||||||
|
position,
|
||||||
|
callback
|
||||||
|
) => {
|
||||||
const remaining = buffer.length - offset;
|
const remaining = buffer.length - offset;
|
||||||
fs.read(fd, buffer, offset, remaining, position, (err, bytesRead) => {
|
fs.read(fd, buffer, offset, remaining, position, (err, bytesRead) => {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
|
@ -244,6 +267,7 @@ const readFileSectionToBuffer = (fd, buffer, offset, position, callback) => {
|
||||||
}
|
}
|
||||||
if (bytesRead < remaining) {
|
if (bytesRead < remaining) {
|
||||||
return readFileSectionToBuffer(
|
return readFileSectionToBuffer(
|
||||||
|
fs,
|
||||||
fd,
|
fd,
|
||||||
buffer,
|
buffer,
|
||||||
offset + bytesRead,
|
offset + bytesRead,
|
||||||
|
@ -255,9 +279,17 @@ const readFileSectionToBuffer = (fd, buffer, offset, position, callback) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const readSection = (filename, file, offset, size, callback) => {
|
const readSection = (
|
||||||
|
fs,
|
||||||
|
fileManager,
|
||||||
|
filename,
|
||||||
|
file,
|
||||||
|
offset,
|
||||||
|
size,
|
||||||
|
callback
|
||||||
|
) => {
|
||||||
const buffer = Buffer.allocUnsafe(size);
|
const buffer = Buffer.allocUnsafe(size);
|
||||||
readFileSectionToBuffer(file, buffer, 0, offset, err => {
|
readFileSectionToBuffer(fs, file, buffer, 0, offset, err => {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
|
|
||||||
const result = [];
|
const result = [];
|
||||||
|
@ -270,7 +302,7 @@ const readSection = (filename, file, offset, size, callback) => {
|
||||||
pos += 4;
|
pos += 4;
|
||||||
const pSize = buffer.readUInt32LE(pos);
|
const pSize = buffer.readUInt32LE(pos);
|
||||||
pos += 4;
|
pos += 4;
|
||||||
result.push(createPointer(filename, pOffset, pSize));
|
result.push(createPointer(fs, fileManager, filename, pOffset, pSize));
|
||||||
} else {
|
} else {
|
||||||
const buf = buffer.slice(pos, pos + len);
|
const buf = buffer.slice(pos, pos + len);
|
||||||
pos += len;
|
pos += len;
|
||||||
|
@ -281,7 +313,7 @@ const readSection = (filename, file, offset, size, callback) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const writeBuffers = (fileHandle, buffers, callback) => {
|
const writeBuffers = (fs, fileHandle, buffers, callback) => {
|
||||||
const stream = fs.createWriteStream(null, {
|
const stream = fs.createWriteStream(null, {
|
||||||
fd: fileHandle,
|
fd: fileHandle,
|
||||||
autoClose: false
|
autoClose: false
|
||||||
|
@ -309,10 +341,15 @@ const writeBuffers = (fileHandle, buffers, callback) => {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {BufferSerializableType[]} DeserializedType
|
* @typedef {BufferSerializableType[]} DeserializedType
|
||||||
* @typedef {undefined} SerializedType
|
* @typedef {true} SerializedType
|
||||||
* @extends {SerializerMiddleware<DeserializedType, SerializedType>}
|
* @extends {SerializerMiddleware<DeserializedType, SerializedType>}
|
||||||
*/
|
*/
|
||||||
class FileMiddleware extends SerializerMiddleware {
|
class FileMiddleware extends SerializerMiddleware {
|
||||||
|
constructor(fs) {
|
||||||
|
super();
|
||||||
|
this.fs = fs;
|
||||||
|
this.fileManager = getFileManager(fs);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @param {DeserializedType} data data
|
* @param {DeserializedType} data data
|
||||||
* @param {Object} context context object
|
* @param {Object} context context object
|
||||||
|
@ -350,10 +387,10 @@ class FileMiddleware extends SerializerMiddleware {
|
||||||
|
|
||||||
// write to file
|
// write to file
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
mkdirp(path.dirname(filename), err => {
|
mkdirp(this.fs, dirname(this.fs, filename), err => {
|
||||||
if (err) return reject(err);
|
if (err) return reject(err);
|
||||||
fileManager.addJob(filename, true, (file, callback) => {
|
this.fileManager.addJob(filename, true, (file, callback) => {
|
||||||
writeBuffers(file, buffers, err => {
|
writeBuffers(this.fs, file, buffers, err => {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
resolve(true);
|
resolve(true);
|
||||||
callback();
|
callback();
|
||||||
|
@ -371,22 +408,30 @@ class FileMiddleware extends SerializerMiddleware {
|
||||||
*/
|
*/
|
||||||
deserialize(data, { filename }) {
|
deserialize(data, { filename }) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fileManager.addJob(
|
this.fileManager.addJob(
|
||||||
filename,
|
filename,
|
||||||
false,
|
false,
|
||||||
(file, callback) => {
|
(file, callback) => {
|
||||||
const sizeBuf = Buffer.allocUnsafe(4);
|
const sizeBuf = Buffer.allocUnsafe(4);
|
||||||
readFileSectionToBuffer(file, sizeBuf, 0, 0, err => {
|
readFileSectionToBuffer(this.fs, file, sizeBuf, 0, 0, err => {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
|
|
||||||
const rootSize = sizeBuf.readUInt32LE(0);
|
const rootSize = sizeBuf.readUInt32LE(0);
|
||||||
|
|
||||||
readSection(filename, file, 4, rootSize, (err, parts) => {
|
readSection(
|
||||||
|
this.fs,
|
||||||
|
this.fileManager,
|
||||||
|
filename,
|
||||||
|
file,
|
||||||
|
4,
|
||||||
|
rootSize,
|
||||||
|
(err, parts) => {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
|
|
||||||
resolve(parts);
|
resolve(parts);
|
||||||
callback();
|
callback();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
reject
|
reject
|
||||||
|
|
|
@ -0,0 +1,174 @@
|
||||||
|
/*
|
||||||
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||||
|
Author Tobias Koppers @sokra
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
/** @typedef {function(NodeJS.ErrnoException=): void} Callback */
|
||||||
|
/** @typedef {function(NodeJS.ErrnoException=, Buffer=): void} BufferCallback */
|
||||||
|
/** @typedef {function(NodeJS.ErrnoException=, import("fs").Stats=): void} StatsCallback */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} OutputFileSystem
|
||||||
|
* @property {function(string, Buffer|string, Callback): void} writeFile
|
||||||
|
* @property {function(string, Callback): void} mkdir
|
||||||
|
* @property {(function(string, string): string)=} join
|
||||||
|
* @property {(function(string, string): string)=} relative
|
||||||
|
* @property {(function(string): string)=} dirname
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} IntermediateFileSystemExtras
|
||||||
|
* @property {function(string): void} mkdirSync
|
||||||
|
* @property {function(string): import("fs").WriteStream} createWriteStream
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @typedef {OutputFileSystem & IntermediateFileSystemExtras} IntermediateFileSystem */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} InputFileSystem
|
||||||
|
* @property {function(string, BufferCallback): void} readFile
|
||||||
|
* @property {function(string, StatsCallback): void} stat
|
||||||
|
* @property {(function(string=): void)=} purge
|
||||||
|
* @property {(function(string, string): string)=} join
|
||||||
|
* @property {(function(string, string): string)=} relative
|
||||||
|
* @property {(function(string): string)=} dirname
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {(InputFileSystem|OutputFileSystem)=} fs a file system
|
||||||
|
* @param {string} rootPath the root path
|
||||||
|
* @param {string} targetPath the target path
|
||||||
|
* @returns {string} location of targetPath relative to rootPath
|
||||||
|
*/
|
||||||
|
const relative = (fs, rootPath, targetPath) => {
|
||||||
|
if (fs && fs.relative) {
|
||||||
|
return fs.relative(rootPath, targetPath);
|
||||||
|
} else if (rootPath.startsWith("/")) {
|
||||||
|
return path.posix.relative(rootPath, targetPath);
|
||||||
|
} else if (rootPath.length > 1 && rootPath[1] === ":") {
|
||||||
|
return path.win32.relative(rootPath, targetPath);
|
||||||
|
} else {
|
||||||
|
throw new Error(
|
||||||
|
`${rootPath} is neither a posix nor a windows path, and there is no 'relative' method defined in the file system`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
exports.relative = relative;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {(InputFileSystem|OutputFileSystem)=} fs a file system
|
||||||
|
* @param {string} rootPath a path
|
||||||
|
* @param {string} filename a filename
|
||||||
|
* @returns {string} the joined path
|
||||||
|
*/
|
||||||
|
const join = (fs, rootPath, filename) => {
|
||||||
|
if (fs && fs.join) {
|
||||||
|
return fs.join(rootPath, filename);
|
||||||
|
} else if (rootPath.startsWith("/")) {
|
||||||
|
return path.posix.join(rootPath, filename);
|
||||||
|
} else if (rootPath.length > 1 && rootPath[1] === ":") {
|
||||||
|
return path.win32.join(rootPath, filename);
|
||||||
|
} else {
|
||||||
|
throw new Error(
|
||||||
|
`${rootPath} is neither a posix nor a windows path, and there is no 'join' method defined in the file system`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
exports.join = join;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {(InputFileSystem|OutputFileSystem)=} fs a file system
|
||||||
|
* @param {string} absPath an absolute path
|
||||||
|
* @returns {string} the parent directory of the absolute path
|
||||||
|
*/
|
||||||
|
const dirname = (fs, absPath) => {
|
||||||
|
if (fs && fs.dirname) {
|
||||||
|
return fs.dirname(absPath);
|
||||||
|
} else if (absPath.startsWith("/")) {
|
||||||
|
return path.posix.dirname(absPath);
|
||||||
|
} else if (absPath.length > 1 && absPath[1] === ":") {
|
||||||
|
return path.win32.dirname(absPath);
|
||||||
|
} else {
|
||||||
|
throw new Error(
|
||||||
|
`${absPath} is neither a posix nor a windows path, and there is no 'dirname' method defined in the file system`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
exports.dirname = dirname;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {OutputFileSystem} fs a file system
|
||||||
|
* @param {string} p an absolute path
|
||||||
|
* @param {function(Error=): void} callback callback function for the error
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
const mkdirp = (fs, p, callback) => {
|
||||||
|
fs.mkdir(p, err => {
|
||||||
|
if (err) {
|
||||||
|
if (err.code === "ENOENT") {
|
||||||
|
const dir = dirname(fs, p);
|
||||||
|
if (dir === p) {
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mkdirp(fs, dir, err => {
|
||||||
|
if (err) {
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fs.mkdir(p, err => {
|
||||||
|
if (err) {
|
||||||
|
if (err.code === "EEXIST") {
|
||||||
|
callback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
} else if (err.code === "EEXIST") {
|
||||||
|
callback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
exports.mkdirp = mkdirp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {IntermediateFileSystem} fs a file system
|
||||||
|
* @param {string} p an absolute path
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
const mkdirpSync = (fs, p) => {
|
||||||
|
try {
|
||||||
|
fs.mkdirSync(p);
|
||||||
|
} catch (err) {
|
||||||
|
if (err) {
|
||||||
|
if (err.code === "ENOENT") {
|
||||||
|
const dir = dirname(fs, p);
|
||||||
|
if (dir === p) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
mkdirpSync(fs, dir);
|
||||||
|
fs.mkdirSync(p);
|
||||||
|
return;
|
||||||
|
} else if (err.code === "EEXIST") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
exports.mkdirpSync = mkdirpSync;
|
|
@ -22,11 +22,12 @@ exports.registerNotSerializable = registerNotSerializable;
|
||||||
exports.NOT_SERIALIZABLE = ObjectMiddleware.NOT_SERIALIZABLE;
|
exports.NOT_SERIALIZABLE = ObjectMiddleware.NOT_SERIALIZABLE;
|
||||||
exports.MEASURE_START_OPERATION = BinaryMiddleware.MEASURE_START_OPERATION;
|
exports.MEASURE_START_OPERATION = BinaryMiddleware.MEASURE_START_OPERATION;
|
||||||
exports.MEASURE_END_OPERATION = BinaryMiddleware.MEASURE_END_OPERATION;
|
exports.MEASURE_END_OPERATION = BinaryMiddleware.MEASURE_END_OPERATION;
|
||||||
exports.fileSerializer = new Serializer([
|
exports.createFileSerializer = fs =>
|
||||||
|
new Serializer([
|
||||||
new SingleItemMiddleware(),
|
new SingleItemMiddleware(),
|
||||||
new ObjectMiddleware(),
|
new ObjectMiddleware(),
|
||||||
new BinaryMiddleware(),
|
new BinaryMiddleware(),
|
||||||
new FileMiddleware()
|
new FileMiddleware(fs)
|
||||||
]);
|
]);
|
||||||
exports.buffersSerializer = new Serializer([
|
exports.buffersSerializer = new Serializer([
|
||||||
new SingleItemMiddleware(),
|
new SingleItemMiddleware(),
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
"events": "^3.0.0",
|
"events": "^3.0.0",
|
||||||
"find-cache-dir": "^2.1.0",
|
"find-cache-dir": "^2.1.0",
|
||||||
"glob-to-regexp": "^0.4.1",
|
"glob-to-regexp": "^0.4.1",
|
||||||
|
"graceful-fs": "^4.1.15",
|
||||||
"json-parse-better-errors": "^1.0.2",
|
"json-parse-better-errors": "^1.0.2",
|
||||||
"loader-runner": "3.0.0",
|
"loader-runner": "3.0.0",
|
||||||
"loader-utils": "^1.1.0",
|
"loader-utils": "^1.1.0",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("graceful-fs");
|
||||||
const asyncLib = require("neo-async");
|
const asyncLib = require("neo-async");
|
||||||
const Benchmark = require("benchmark");
|
const Benchmark = require("benchmark");
|
||||||
const { remove } = require("./helpers/remove");
|
const { remove } = require("./helpers/remove");
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("graceful-fs");
|
||||||
const rimraf = require("rimraf");
|
const rimraf = require("rimraf");
|
||||||
|
|
||||||
const webpack = require("..");
|
const webpack = require("..");
|
||||||
|
@ -24,19 +24,18 @@ describe("Compiler (caching)", () => {
|
||||||
options.output.filename = "bundle.js";
|
options.output.filename = "bundle.js";
|
||||||
options.output.pathinfo = true;
|
options.output.pathinfo = true;
|
||||||
const logs = {
|
const logs = {
|
||||||
mkdirp: [],
|
mkdir: [],
|
||||||
writeFile: []
|
writeFile: []
|
||||||
};
|
};
|
||||||
|
|
||||||
const c = webpack(options);
|
const c = webpack(options);
|
||||||
const files = {};
|
const files = {};
|
||||||
c.outputFileSystem = {
|
c.outputFileSystem = {
|
||||||
join() {
|
mkdir(path, callback) {
|
||||||
return [].join.call(arguments, "/").replace(/\/+/g, "/");
|
logs.mkdir.push(path);
|
||||||
},
|
const err = new Error();
|
||||||
mkdirp(path, callback) {
|
err.code = "EEXIST";
|
||||||
logs.mkdirp.push(path);
|
callback(err);
|
||||||
callback();
|
|
||||||
},
|
},
|
||||||
writeFile(name, content, callback) {
|
writeFile(name, content, callback) {
|
||||||
logs.writeFile.push(name, content);
|
logs.writeFile.push(name, content);
|
||||||
|
|
|
@ -22,19 +22,18 @@ describe("Compiler", () => {
|
||||||
minimize: false
|
minimize: false
|
||||||
};
|
};
|
||||||
const logs = {
|
const logs = {
|
||||||
mkdirp: [],
|
mkdir: [],
|
||||||
writeFile: []
|
writeFile: []
|
||||||
};
|
};
|
||||||
|
|
||||||
const c = webpack(options);
|
const c = webpack(options);
|
||||||
const files = {};
|
const files = {};
|
||||||
c.outputFileSystem = {
|
c.outputFileSystem = {
|
||||||
join() {
|
mkdir(path, callback) {
|
||||||
return [].join.call(arguments, "/").replace(/\/+/g, "/");
|
logs.mkdir.push(path);
|
||||||
},
|
const err = new Error();
|
||||||
mkdirp(path, callback) {
|
err.code = "EEXIST";
|
||||||
logs.mkdirp.push(path);
|
callback(err);
|
||||||
callback();
|
|
||||||
},
|
},
|
||||||
writeFile(name, content, callback) {
|
writeFile(name, content, callback) {
|
||||||
logs.writeFile.push(name, content);
|
logs.writeFile.push(name, content);
|
||||||
|
@ -76,7 +75,7 @@ describe("Compiler", () => {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(stats, files) => {
|
(stats, files) => {
|
||||||
expect(stats.logs.mkdirp).toEqual(["/what", "/what/the"]);
|
expect(stats.logs.mkdir).toEqual(["/what", "/what/the"]);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
/* globals describe expect it */
|
/* globals describe expect it */
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("graceful-fs");
|
||||||
const vm = require("vm");
|
const vm = require("vm");
|
||||||
const mkdirp = require("mkdirp");
|
const mkdirp = require("mkdirp");
|
||||||
const rimraf = require("rimraf");
|
const rimraf = require("rimraf");
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const fs = require("fs");
|
const fs = require("graceful-fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const lockfile = require("@yarnpkg/lockfile");
|
const lockfile = require("@yarnpkg/lockfile");
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
/*globals describe it */
|
/*globals describe it */
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("graceful-fs");
|
||||||
const webpack = require("..");
|
const webpack = require("..");
|
||||||
const prettyFormat = require("pretty-format");
|
const prettyFormat = require("pretty-format");
|
||||||
|
|
||||||
|
@ -81,8 +81,7 @@ const defaults = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
outputFileSystem: {
|
outputFileSystem: {
|
||||||
join: path.join.bind(path),
|
mkdir(dir, callback) {
|
||||||
mkdirp(dir, callback) {
|
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
writeFile(file, content, callback) {
|
writeFile(file, content, callback) {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
/* globals describe it */
|
/* globals describe it */
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("graceful-fs");
|
||||||
const webpack = require("..");
|
const webpack = require("..");
|
||||||
|
|
||||||
describe("Examples", () => {
|
describe("Examples", () => {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("graceful-fs");
|
||||||
const mkdirp = require("mkdirp");
|
const mkdirp = require("mkdirp");
|
||||||
|
|
||||||
const webpack = require("..");
|
const webpack = require("..");
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
/* globals expect */
|
/* globals expect */
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("graceful-fs");
|
||||||
const vm = require("vm");
|
const vm = require("vm");
|
||||||
const checkArrayExpectation = require("./checkArrayExpectation");
|
const checkArrayExpectation = require("./checkArrayExpectation");
|
||||||
const createLazyTestEnv = require("./helpers/createLazyTestEnv");
|
const createLazyTestEnv = require("./helpers/createLazyTestEnv");
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("graceful-fs");
|
||||||
const webpack = require("../");
|
const webpack = require("../");
|
||||||
const rimraf = require("rimraf");
|
const rimraf = require("rimraf");
|
||||||
|
|
||||||
|
@ -9,12 +9,15 @@ describe("Profiling Plugin", function() {
|
||||||
jest.setTimeout(15000);
|
jest.setTimeout(15000);
|
||||||
|
|
||||||
it("should handle output path with folder creation", done => {
|
it("should handle output path with folder creation", done => {
|
||||||
const finalPath = "test/js/profilingPath/events.json";
|
const outputPath = path.join(__dirname, "js/profilingPath");
|
||||||
const outputPath = path.join(__dirname, "/js/profilingPath");
|
const finalPath = path.join(outputPath, "events.json");
|
||||||
rimraf(outputPath, () => {
|
rimraf(outputPath, () => {
|
||||||
const compiler = webpack({
|
const compiler = webpack({
|
||||||
context: "/",
|
context: __dirname,
|
||||||
entry: "./fixtures/a.js",
|
entry: "./fixtures/a.js",
|
||||||
|
output: {
|
||||||
|
path: path.join(__dirname, "js/profilingOut")
|
||||||
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.debug.ProfilingPlugin({
|
new webpack.debug.ProfilingPlugin({
|
||||||
outputPath: finalPath
|
outputPath: finalPath
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const MemoryFs = require("memory-fs");
|
const MemoryFs = require("memory-fs");
|
||||||
const webpack = require("..");
|
const webpack = require("..");
|
||||||
const fs = require("fs");
|
const fs = require("graceful-fs");
|
||||||
const rimraf = require("rimraf");
|
const rimraf = require("rimraf");
|
||||||
|
|
||||||
const createCompiler = config => {
|
const createCompiler = config => {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const fs = require("fs");
|
const fs = require("graceful-fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const glob = require("glob");
|
const glob = require("glob");
|
||||||
const rootDir = path.resolve(__dirname, "..");
|
const rootDir = path.resolve(__dirname, "..");
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("graceful-fs");
|
||||||
|
|
||||||
const webpack = require("..");
|
const webpack = require("..");
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("graceful-fs");
|
||||||
const vm = require("vm");
|
const vm = require("vm");
|
||||||
const mkdirp = require("mkdirp");
|
const mkdirp = require("mkdirp");
|
||||||
const rimraf = require("rimraf");
|
const rimraf = require("rimraf");
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
/*globals describe it */
|
/*globals describe it */
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("graceful-fs");
|
||||||
const MemoryFs = require("memory-fs");
|
const MemoryFs = require("memory-fs");
|
||||||
|
|
||||||
const webpack = require("..");
|
const webpack = require("..");
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("graceful-fs");
|
||||||
const vm = require("vm");
|
const vm = require("vm");
|
||||||
const mkdirp = require("mkdirp");
|
const mkdirp = require("mkdirp");
|
||||||
const rimraf = require("rimraf");
|
const rimraf = require("rimraf");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
const fs = require("fs");
|
const fs = require("graceful-fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
const check = (expected, actual) => {
|
const check = (expected, actual) => {
|
||||||
|
@ -26,7 +26,7 @@ const explain = object => {
|
||||||
value = JSON.stringify(value);
|
value = JSON.stringify(value);
|
||||||
}
|
}
|
||||||
let msg = `${key} = ${value}`;
|
let msg = `${key} = ${value}`;
|
||||||
if (msg.length > 100) msg = msg.slice(0, 97) + "...";
|
if (key !== "stack" && msg.length > 100) msg = msg.slice(0, 97) + "...";
|
||||||
return msg;
|
return msg;
|
||||||
})
|
})
|
||||||
.join("; ");
|
.join("; ");
|
||||||
|
|
Loading…
Reference in New Issue