mirror of https://github.com/webpack/webpack.git
Merge pull request #7598 from webpack/refactor/remove_deprecated_api
Remove deprecated APIs
This commit is contained in:
commit
2b61228501
|
|
@ -28,14 +28,6 @@ module.exports = class AsyncDependenciesBlock extends DependenciesBlock {
|
|||
this.groupOptions.name = value;
|
||||
}
|
||||
|
||||
get chunks() {
|
||||
throw new Error("Moved to AsyncDependenciesBlock.chunkGroup");
|
||||
}
|
||||
|
||||
set chunks(value) {
|
||||
throw new Error("Moved to AsyncDependenciesBlock.chunkGroup");
|
||||
}
|
||||
|
||||
updateHash(hash) {
|
||||
hash.update(JSON.stringify(this.groupOptions));
|
||||
hash.update(
|
||||
|
|
|
|||
101
lib/Chunk.js
101
lib/Chunk.js
|
|
@ -4,14 +4,11 @@ Author Tobias Koppers @sokra
|
|||
*/
|
||||
"use strict";
|
||||
|
||||
const util = require("util");
|
||||
const SortableSet = require("./util/SortableSet");
|
||||
const intersect = require("./util/SetHelpers").intersect;
|
||||
const GraphHelpers = require("./GraphHelpers");
|
||||
|
||||
let debugId = 1000;
|
||||
const ERR_CHUNK_ENTRY = "Chunk.entry was removed. Use hasRuntime()";
|
||||
const ERR_CHUNK_INITIAL =
|
||||
"Chunk.initial was removed. Use canBeInitial/isOnlyInitial()";
|
||||
|
||||
/** @typedef {import("./Module.js")} Module */
|
||||
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
||||
|
|
@ -133,40 +130,6 @@ class Chunk {
|
|||
this.removedModules = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Chunk.entry has been deprecated. Please use .hasRuntime() instead
|
||||
* @returns {never} Throws an error trying to access this property
|
||||
*/
|
||||
get entry() {
|
||||
throw new Error(ERR_CHUNK_ENTRY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated .entry has been deprecated. Please use .hasRuntime() instead
|
||||
* @param {never} data The data that was attempting to be set
|
||||
* @returns {never} Throws an error trying to access this property
|
||||
*/
|
||||
set entry(data) {
|
||||
throw new Error(ERR_CHUNK_ENTRY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Chunk.initial was removed. Use canBeInitial/isOnlyInitial()
|
||||
* @returns {never} Throws an error trying to access this property
|
||||
*/
|
||||
get initial() {
|
||||
throw new Error(ERR_CHUNK_INITIAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Chunk.initial was removed. Use canBeInitial/isOnlyInitial()
|
||||
* @param {never} data The data attempting to be set
|
||||
* @returns {never} Throws an error trying to access this property
|
||||
*/
|
||||
set initial(data) {
|
||||
throw new Error(ERR_CHUNK_INITIAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean} whether or not the Chunk will have a runtime
|
||||
*/
|
||||
|
|
@ -696,66 +659,4 @@ 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")
|
||||
});
|
||||
|
||||
// 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")
|
||||
});
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(Chunk.prototype, "chunks", {
|
||||
configurable: false,
|
||||
get() {
|
||||
throw new Error("Chunk.chunks: Use ChunkGroup.getChildren() instead");
|
||||
},
|
||||
set() {
|
||||
throw new Error("Chunk.chunks: Use ChunkGroup.add/removeChild() instead");
|
||||
}
|
||||
});
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(Chunk.prototype, "parents", {
|
||||
configurable: false,
|
||||
get() {
|
||||
throw new Error("Chunk.parents: Use ChunkGroup.getParents() instead");
|
||||
},
|
||||
set() {
|
||||
throw new Error("Chunk.parents: Use ChunkGroup.add/removeParent() instead");
|
||||
}
|
||||
});
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(Chunk.prototype, "blocks", {
|
||||
configurable: false,
|
||||
get() {
|
||||
throw new Error("Chunk.blocks: Use ChunkGroup.getBlocks() instead");
|
||||
},
|
||||
set() {
|
||||
throw new Error("Chunk.blocks: Use ChunkGroup.add/removeBlock() instead");
|
||||
}
|
||||
});
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(Chunk.prototype, "entrypoints", {
|
||||
configurable: false,
|
||||
get() {
|
||||
throw new Error(
|
||||
"Chunk.entrypoints: Use Chunks.groupsIterable and filter by instanceof Entrypoint instead"
|
||||
);
|
||||
},
|
||||
set() {
|
||||
throw new Error("Chunk.entrypoints: Use Chunks.addGroup instead");
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = Chunk;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
"use strict";
|
||||
|
||||
const asyncLib = require("neo-async");
|
||||
const util = require("util");
|
||||
const { CachedSource } = require("webpack-sources");
|
||||
const {
|
||||
SyncHook,
|
||||
|
|
@ -1915,22 +1914,4 @@ class Compilation {
|
|||
}
|
||||
}
|
||||
|
||||
// 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");
|
||||
|
||||
// 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.")
|
||||
});
|
||||
|
||||
module.exports = Compilation;
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
const util = require("util");
|
||||
const { OriginalSource, RawSource } = require("webpack-sources");
|
||||
const Module = require("./Module");
|
||||
const AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
|
||||
|
|
@ -693,59 +693,4 @@ 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")
|
||||
});
|
||||
|
||||
// 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")
|
||||
});
|
||||
|
||||
// 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")
|
||||
});
|
||||
|
||||
// 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")
|
||||
});
|
||||
|
||||
// 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")
|
||||
});
|
||||
|
||||
module.exports = ContextModule;
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@
|
|||
*/
|
||||
"use strict";
|
||||
|
||||
const util = require("util");
|
||||
|
||||
const DependenciesBlock = require("./DependenciesBlock");
|
||||
const ModuleReason = require("./ModuleReason");
|
||||
const SortableSet = require("./util/SortableSet");
|
||||
|
|
@ -322,54 +320,8 @@ class Module extends DependenciesBlock {
|
|||
this.buildInfo = undefined;
|
||||
this.disconnect();
|
||||
}
|
||||
|
||||
get arguments() {
|
||||
throw new Error("Module.arguments was removed, there is no replacement.");
|
||||
}
|
||||
|
||||
set arguments(value) {
|
||||
throw new Error("Module.arguments was removed, there is no replacement.");
|
||||
}
|
||||
}
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(Module.prototype, "forEachChunk", {
|
||||
configurable: false,
|
||||
value: util.deprecate(function(fn) {
|
||||
this._chunks.forEach(fn);
|
||||
}, "Module.forEachChunk: Use for(const chunk of module.chunksIterable) instead")
|
||||
});
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(Module.prototype, "mapChunks", {
|
||||
configurable: false,
|
||||
value: util.deprecate(function(fn) {
|
||||
return Array.from(this._chunks, fn);
|
||||
}, "Module.mapChunks: Use Array.from(module.chunksIterable, fn) instead")
|
||||
});
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(Module.prototype, "entry", {
|
||||
configurable: false,
|
||||
get() {
|
||||
throw new Error("Module.entry was removed. Use Chunk.entryModule");
|
||||
},
|
||||
set() {
|
||||
throw new Error("Module.entry was removed. Use Chunk.entryModule");
|
||||
}
|
||||
});
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(Module.prototype, "meta", {
|
||||
configurable: false,
|
||||
get: util.deprecate(function() {
|
||||
return this.buildMeta;
|
||||
}, "Module.meta was renamed to Module.buildMeta"),
|
||||
set: util.deprecate(function(value) {
|
||||
this.buildMeta = value;
|
||||
}, "Module.meta was renamed to Module.buildMeta")
|
||||
});
|
||||
|
||||
/** @type {function(): string} */
|
||||
Module.prototype.identifier = null;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
const acorn = require("acorn-dynamic-import").default;
|
||||
const { SyncBailHook, HookMap } = require("tapable");
|
||||
const util = require("util");
|
||||
const vm = require("vm");
|
||||
const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
||||
const StackedSetMap = require("./util/StackedSetMap");
|
||||
|
|
@ -2137,12 +2136,4 @@ class Parser {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(Parser.prototype, "getCommentOptions", {
|
||||
configurable: false,
|
||||
value: util.deprecate(function(range) {
|
||||
return this.parseCommentOptions(range).options;
|
||||
}, "Parser.getCommentOptions: Use Parser.parseCommentOptions(range) instead")
|
||||
});
|
||||
|
||||
module.exports = Parser;
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
const WebpackError = require("./WebpackError");
|
||||
|
||||
module.exports = class RemovedPluginError extends WebpackError {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
};
|
||||
|
|
@ -50,19 +50,4 @@ class ContextDependency extends Dependency {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(ContextDependency.prototype, "async", {
|
||||
configurable: false,
|
||||
get() {
|
||||
throw new Error(
|
||||
"ContextDependency.async was removed. Use ContextDependency.options.mode instead."
|
||||
);
|
||||
},
|
||||
set() {
|
||||
throw new Error(
|
||||
"ContextDependency.async was removed. Pass options.mode to constructor instead"
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = ContextDependency;
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@
|
|||
*/
|
||||
"use strict";
|
||||
|
||||
const util = require("util");
|
||||
|
||||
const TOMBSTONE = {};
|
||||
const UNDEFINED_MARKER = {};
|
||||
|
||||
|
|
@ -117,19 +115,6 @@ class StackedSetMap {
|
|||
createChild() {
|
||||
return new StackedSetMap(this.stack);
|
||||
}
|
||||
|
||||
get length() {
|
||||
throw new Error("This is no longer an Array");
|
||||
}
|
||||
|
||||
set length(value) {
|
||||
throw new Error("This is no longer an Array");
|
||||
}
|
||||
}
|
||||
|
||||
// TODO remove in webpack 5
|
||||
StackedSetMap.prototype.push = util.deprecate(function(item) {
|
||||
this.add(item);
|
||||
}, "This is no longer an Array: Use add instead.");
|
||||
|
||||
module.exports = StackedSetMap;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ const WebpackOptionsDefaulter = require("./WebpackOptionsDefaulter");
|
|||
const validateSchema = require("./validateSchema");
|
||||
const WebpackOptionsValidationError = require("./WebpackOptionsValidationError");
|
||||
const webpackOptionsSchema = require("../schemas/WebpackOptions.json");
|
||||
const RemovedPluginError = require("./RemovedPluginError");
|
||||
const version = require("../package.json").version;
|
||||
|
||||
const webpack = (options, callback) => {
|
||||
|
|
@ -157,27 +156,3 @@ exportPlugins((exports.debug = {}), {
|
|||
exportPlugins((exports.util = {}), {
|
||||
createHash: () => require("./util/createHash")
|
||||
});
|
||||
|
||||
const defineMissingPluginError = (namespace, pluginName, errorMessage) => {
|
||||
Object.defineProperty(namespace, pluginName, {
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
get() {
|
||||
throw new RemovedPluginError(errorMessage);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// TODO remove in webpack 5
|
||||
defineMissingPluginError(
|
||||
exports.optimize,
|
||||
"UglifyJsPlugin",
|
||||
"webpack.optimize.UglifyJsPlugin has been removed, please use config.optimization.minimize instead."
|
||||
);
|
||||
|
||||
// TODO remove in webpack 5
|
||||
defineMissingPluginError(
|
||||
exports.optimize,
|
||||
"CommonsChunkPlugin",
|
||||
"webpack.optimize.CommonsChunkPlugin has been removed, please use config.optimization.splitChunks instead."
|
||||
);
|
||||
|
|
|
|||
|
|
@ -22,34 +22,6 @@ describe("Chunk", () => {
|
|||
expect(ChunkInstance.canBeInitial()).toBe(false);
|
||||
});
|
||||
|
||||
describe("entry", () => {
|
||||
it("returns an error if get entry", () => {
|
||||
expect(() => {
|
||||
ChunkInstance.entry;
|
||||
}).toThrow("Chunk.entry was removed. Use hasRuntime()");
|
||||
});
|
||||
|
||||
it("returns an error if set an entry", () => {
|
||||
expect(() => {
|
||||
ChunkInstance.entry = 10;
|
||||
}).toThrow("Chunk.entry was removed. Use hasRuntime()");
|
||||
});
|
||||
});
|
||||
|
||||
describe("initial", () => {
|
||||
it("returns an error if get initial", () => {
|
||||
expect(() => {
|
||||
ChunkInstance.initial;
|
||||
}).toThrow("Chunk.initial was removed. Use canBeInitial/isOnlyInitial()");
|
||||
});
|
||||
|
||||
it("returns an error if set an initial", () => {
|
||||
expect(() => {
|
||||
ChunkInstance.initial = 10;
|
||||
}).toThrow("Chunk.initial was removed. Use canBeInitial/isOnlyInitial()");
|
||||
});
|
||||
});
|
||||
|
||||
describe("hasRuntime", () => {
|
||||
it("returns false", () => {
|
||||
expect(ChunkInstance.hasRuntime()).toBe(false);
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
const webpack = require("../lib/webpack");
|
||||
const RemovedPluginError = require("../lib/RemovedPluginError");
|
||||
|
||||
describe("removed plugin errors", () => {
|
||||
it("should error when accessing removed plugins", () => {
|
||||
expect(() => webpack.optimize.UglifyJsPlugin).toThrow(RemovedPluginError);
|
||||
expect(
|
||||
() => webpack.optimize.UglifyJsPlugin
|
||||
).toThrowErrorMatchingSnapshot();
|
||||
|
||||
expect(() => webpack.optimize.CommonsChunkPlugin).toThrow(
|
||||
RemovedPluginError
|
||||
);
|
||||
expect(
|
||||
() => webpack.optimize.CommonsChunkPlugin
|
||||
).toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`removed plugin errors should error when accessing removed plugins 1`] = `"webpack.optimize.UglifyJsPlugin has been removed, please use config.optimization.minimize instead."`;
|
||||
|
||||
exports[`removed plugin errors should error when accessing removed plugins 2`] = `"webpack.optimize.CommonsChunkPlugin has been removed, please use config.optimization.splitChunks instead."`;
|
||||
Loading…
Reference in New Issue