Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into chore-bump-webass…
Browse files Browse the repository at this point in the history
…emblyjs11
  • Loading branch information
xtuc committed Jul 25, 2018
2 parents 8214d56 + a28f44f commit 38c3403
Show file tree
Hide file tree
Showing 45 changed files with 912 additions and 328 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Expand Up @@ -35,7 +35,6 @@ module.exports = {
"prop": "property",
"memberof": "DONTUSE",
"class": "DONTUSE",
"extends": "DONTUSE",
"inheritdoc": "DONTUSE",
"description": "DONTUSE",
"readonly": "DONTUSE"
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Expand Up @@ -9,6 +9,7 @@
!buildin/*.js
!benchmark/**/*.js
!test/*.js
!tooling/*.js
!test/**/webpack.config.js
!examples/**/webpack.config.js
!schemas/**/*.js
Expand Down
42 changes: 32 additions & 10 deletions lib/Chunk.js
Expand Up @@ -8,6 +8,7 @@ const util = require("util");
const SortableSet = require("./util/SortableSet");
const intersect = require("./util/SetHelpers").intersect;
const GraphHelpers = require("./GraphHelpers");
const Entrypoint = require("./Entrypoint");
let debugId = 1000;
const ERR_CHUNK_ENTRY = "Chunk.entry was removed. Use hasRuntime()";
const ERR_CHUNK_INITIAL =
Expand Down Expand Up @@ -123,9 +124,6 @@ class Chunk {
this._modules = new SortableSet(undefined, sortByIdentifier);
/** @type {string?} */
this.filenameTemplate = undefined;

/** @private */
this._groups = new SortableSet(undefined, sortChunkGroupById);
/** @private @type {SortableSet<ChunkGroup>} */
this._groups = new SortableSet(undefined, sortChunkGroupById);
/** @type {string[]} */
Expand Down Expand Up @@ -185,7 +183,11 @@ class Chunk {
hasRuntime() {
for (const chunkGroup of this._groups) {
// We only need to check the first one
return chunkGroup.isInitial() && chunkGroup.getRuntimeChunk() === this;
return (
chunkGroup.isInitial() &&
chunkGroup instanceof Entrypoint &&
chunkGroup.getRuntimeChunk() === this
);
}
return false;
}
Expand Down Expand Up @@ -749,17 +751,37 @@ class Chunk {
// TODO remove in webpack 5
Object.defineProperty(Chunk.prototype, "forEachModule", {
configurable: false,
value: util.deprecate(function(fn) {
this._modules.forEach(fn);
}, "Chunk.forEachModule: Use for(const module of chunk.modulesIterable) instead")
value: util.deprecate(
/**
* @deprecated
* @this {Chunk}
* @typedef {function(any, any, Set<any>): void} ForEachModuleCallback
* @param {ForEachModuleCallback} fn Callback function
* @returns {void}
*/
function(fn) {
this._modules.forEach(fn);
},
"Chunk.forEachModule: Use for(const module of chunk.modulesIterable) instead"
)
});

// TODO remove in webpack 5
Object.defineProperty(Chunk.prototype, "mapModules", {
configurable: false,
value: util.deprecate(function(fn) {
return Array.from(this._modules, fn);
}, "Chunk.mapModules: Use Array.from(chunk.modulesIterable, fn) instead")
value: util.deprecate(
/**
* @deprecated
* @this {Chunk}
* @typedef {function(any, number): any} MapModulesCallback
* @param {MapModulesCallback} fn Callback function
* @returns {TODO[]} result of mapped modules
*/
function(fn) {
return Array.from(this._modules, fn);
},
"Chunk.mapModules: Use Array.from(chunk.modulesIterable, fn) instead"
)
});

// TODO remove in webpack 5
Expand Down
6 changes: 3 additions & 3 deletions lib/ChunkGroup.js
Expand Up @@ -11,7 +11,6 @@ const compareLocations = require("./compareLocations");
/** @typedef {import("./Module")} Module */
/** @typedef {import("./ModuleReason")} ModuleReason */

/** @typedef {{id: number}} HasId */
/** @typedef {{module: Module, loc: TODO, request: string}} OriginRecord */
/** @typedef {string|{name: string}} ChunkGroupOptions */

Expand All @@ -26,8 +25,8 @@ const getArray = set => Array.from(set);

/**
* A convenience method used to sort chunks based on their id's
* @param {HasId} a first sorting comparator
* @param {HasId} b second sorting comparator
* @param {ChunkGroup} a first sorting comparator
* @param {ChunkGroup} b second sorting comparator
* @returns {1|0|-1} a sorting index to determine order
*/
const sortById = (a, b) => {
Expand Down Expand Up @@ -63,6 +62,7 @@ class ChunkGroup {
/** @type {number} */
this.groupDebugId = debugId++;
this.options = options;
/** @type {SortableSet<ChunkGroup>} */
this._children = new SortableSet(undefined, sortById);
this._parents = new SortableSet(undefined, sortById);
this._blocks = new SortableSet();
Expand Down
49 changes: 38 additions & 11 deletions lib/Compilation.js
Expand Up @@ -2442,21 +2442,48 @@ class Compilation extends Tapable {
}

// TODO remove in webpack 5
Compilation.prototype.applyPlugins = util.deprecate(function(name, ...args) {
this.hooks[
name.replace(/[- ]([a-z])/g, match => match[1].toUpperCase())
].call(...args);
}, "Compilation.applyPlugins is deprecated. Use new API on `.hooks` instead");
Compilation.prototype.applyPlugins = util.deprecate(
/**
* @deprecated
* @param {string} name Name
* @param {any[]} args Other arguments
* @returns {void}
* @this {Compilation}
*/
function(name, ...args) {
this.hooks[
name.replace(/[- ]([a-z])/g, match => match[1].toUpperCase())
].call(...args);
},
"Compilation.applyPlugins is deprecated. Use new API on `.hooks` instead"
);

// TODO remove in webpack 5
Object.defineProperty(Compilation.prototype, "moduleTemplate", {
configurable: false,
get: util.deprecate(function() {
return this.moduleTemplates.javascript;
}, "Compilation.moduleTemplate: Use Compilation.moduleTemplates.javascript instead"),
set: util.deprecate(function(value) {
this.moduleTemplates.javascript = value;
}, "Compilation.moduleTemplate: Use Compilation.moduleTemplates.javascript instead.")
get: util.deprecate(
/**
* @deprecated
* @this {Compilation}
* @returns {TODO} module template
*/
function() {
return this.moduleTemplates.javascript;
},
"Compilation.moduleTemplate: Use Compilation.moduleTemplates.javascript instead"
),
set: util.deprecate(
/**
* @deprecated
* @param {ModuleTemplate} value Template value
* @this {Compilation}
* @returns {void}
*/
function(value) {
this.moduleTemplates.javascript = value;
},
"Compilation.moduleTemplate: Use Compilation.moduleTemplates.javascript instead."
)
});

module.exports = Compilation;
11 changes: 11 additions & 0 deletions lib/ContextExclusionPlugin.js
@@ -1,10 +1,21 @@
"use strict";

/** @typedef {import("./Compiler")} Compiler */
/** @typedef {import("./ContextModuleFactory")} ContextModuleFactory */

class ContextExclusionPlugin {
/**
* @param {RegExp} negativeMatcher Matcher regular expression
*/
constructor(negativeMatcher) {
this.negativeMatcher = negativeMatcher;
}

/**
* Apply the plugin
* @param {Compiler} compiler Webpack Compiler
* @returns {void}
*/
apply(compiler) {
compiler.hooks.contextModuleFactory.tap("ContextExclusionPlugin", cmf => {
cmf.hooks.contextModuleFiles.tap("ContextExclusionPlugin", files => {
Expand Down
146 changes: 116 additions & 30 deletions lib/ContextModule.js
Expand Up @@ -10,6 +10,7 @@ const AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
const Template = require("./Template");
const contextify = require("./util/identifier").contextify;

/** @typedef {"sync" | "eager" | "weak" | "async-weak" | "lazy" | "lazy-once"} ContextMode Context mode */
/** @typedef {import("./dependencies/ContextElementDependency")} ContextElementDependency */

/**
Expand Down Expand Up @@ -703,56 +704,141 @@ webpackEmptyAsyncContext.id = ${JSON.stringify(id)};`;
// TODO remove in webpack 5
Object.defineProperty(ContextModule.prototype, "recursive", {
configurable: false,
get: util.deprecate(function() {
return this.options.recursive;
}, "ContextModule.recursive has been moved to ContextModule.options.recursive"),
set: util.deprecate(function(value) {
this.options.recursive = value;
}, "ContextModule.recursive has been moved to ContextModule.options.recursive")
get: util.deprecate(
/**
* @deprecated
* @this {ContextModule}
* @returns {boolean} is recursive
*/
function() {
return this.options.recursive;
},
"ContextModule.recursive has been moved to ContextModule.options.recursive"
),
set: util.deprecate(
/**
* @deprecated
* @this {ContextModule}
* @param {boolean} value is recursive
* @returns {void}
*/
function(value) {
this.options.recursive = value;
},
"ContextModule.recursive has been moved to ContextModule.options.recursive"
)
});

// TODO remove in webpack 5
Object.defineProperty(ContextModule.prototype, "regExp", {
configurable: false,
get: util.deprecate(function() {
return this.options.regExp;
}, "ContextModule.regExp has been moved to ContextModule.options.regExp"),
set: util.deprecate(function(value) {
this.options.regExp = value;
}, "ContextModule.regExp has been moved to ContextModule.options.regExp")
get: util.deprecate(
/**
* @deprecated
* @this {ContextModule}
* @returns {RegExp} regular expression
*/
function() {
return this.options.regExp;
},
"ContextModule.regExp has been moved to ContextModule.options.regExp"
),
set: util.deprecate(
/**
* @deprecated
* @this {ContextModule}
* @param {RegExp} value Regular expression
* @returns {void}
*/
function(value) {
this.options.regExp = value;
},
"ContextModule.regExp has been moved to ContextModule.options.regExp"
)
});

// TODO remove in webpack 5
Object.defineProperty(ContextModule.prototype, "addon", {
configurable: false,
get: util.deprecate(function() {
return this.options.addon;
}, "ContextModule.addon has been moved to ContextModule.options.addon"),
set: util.deprecate(function(value) {
this.options.addon = value;
}, "ContextModule.addon has been moved to ContextModule.options.addon")
get: util.deprecate(
/**
* @deprecated
* @this {ContextModule}
* @returns {string} addon
*/
function() {
return this.options.addon;
},
"ContextModule.addon has been moved to ContextModule.options.addon"
),
set: util.deprecate(
/**
* @deprecated
* @this {ContextModule}
* @param {string} value addon
* @returns {void}
*/
function(value) {
this.options.addon = value;
},
"ContextModule.addon has been moved to ContextModule.options.addon"
)
});

// TODO remove in webpack 5
Object.defineProperty(ContextModule.prototype, "async", {
configurable: false,
get: util.deprecate(function() {
return this.options.mode;
}, "ContextModule.async has been moved to ContextModule.options.mode"),
set: util.deprecate(function(value) {
this.options.mode = value;
}, "ContextModule.async has been moved to ContextModule.options.mode")
get: util.deprecate(
/**
* @deprecated
* @this {ContextModule}
* @returns {boolean} is async
*/
function() {
return this.options.mode;
},
"ContextModule.async has been moved to ContextModule.options.mode"
),
set: util.deprecate(
/**
* @deprecated
* @this {ContextModule}
* @param {ContextMode} value Context mode
* @returns {void}
*/
function(value) {
this.options.mode = value;
},
"ContextModule.async has been moved to ContextModule.options.mode"
)
});

// TODO remove in webpack 5
Object.defineProperty(ContextModule.prototype, "chunkName", {
configurable: false,
get: util.deprecate(function() {
return this.options.chunkName;
}, "ContextModule.chunkName has been moved to ContextModule.options.chunkName"),
set: util.deprecate(function(value) {
this.options.chunkName = value;
}, "ContextModule.chunkName has been moved to ContextModule.options.chunkName")
get: util.deprecate(
/**
* @deprecated
* @this {ContextModule}
* @returns {string} chunk name
*/
function() {
return this.options.chunkName;
},
"ContextModule.chunkName has been moved to ContextModule.options.chunkName"
),
set: util.deprecate(
/**
* @deprecated
* @this {ContextModule}
* @param {string} value chunk name
* @returns {void}
*/
function(value) {
this.options.chunkName = value;
},
"ContextModule.chunkName has been moved to ContextModule.options.chunkName"
)
});

module.exports = ContextModule;

0 comments on commit 38c3403

Please sign in to comment.