Skip to content

Commit

Permalink
Deprecate moduleIds=hashed in favor of moduleIds=deterministic
Browse files Browse the repository at this point in the history
Also remove moduleIds=total-size
  • Loading branch information
ooflorent committed Oct 12, 2018
1 parent c453f39 commit 7669104
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 25 deletions.
13 changes: 3 additions & 10 deletions declarations/WebpackOptions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,16 +780,9 @@ export interface OptimizationOptions {
*/
minimizer?: (WebpackPluginInstance | WebpackPluginFunction)[];
/**
* Define the algorithm to choose module ids (natural: numeric ids in order of usage, named: readable ids for better debugging, hashed: short hashes as ids for better long term caching, deterministic: numeric hash ids for better long term caching, size: numeric ids focused on minimal initial download size, total-size: numeric ids focused on minimal total download size, false: no algorithm used, as custom one can be provided via plugin)
*/
moduleIds?:
| "natural"
| "named"
| "hashed"
| "deterministic"
| "size"
| "total-size"
| false;
* Define the algorithm to choose module ids (natural: numeric ids in order of usage, named: readable ids for better debugging, hashed: (deprecated) short hashes as ids for better long term caching, deterministic: numeric hash ids for better long term caching, size: numeric ids focused on minimal initial download size, false: no algorithm used, as custom one can be provided via plugin)
*/
moduleIds?: "natural" | "named" | "hashed" | "deterministic" | "size" | false;
/**
* Avoid emitting assets when errors occur
*/
Expand Down
43 changes: 43 additions & 0 deletions lib/WarnDeprecatedOptionPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Florent Cailhol @ooflorent
*/

"use strict";

const WebpackError = require("./WebpackError");

class WarnDeprecatedOptionPlugin {
constructor(option, value, suggestion) {
this.option = option;
this.value = value;
this.suggestion = suggestion;
}

apply(compiler) {
compiler.hooks.thisCompilation.tap(
"WarnDeprecatedOptionPlugin",
compilation => {
compilation.warnings.push(
new DeprecatedOptionWarning(this.option, this.value, this.suggestion)
);
}
);
}
}

class DeprecatedOptionWarning extends WebpackError {
constructor(option, value, suggestion) {
super();

this.name = "DeprecatedOptionWarning";
this.message =
"configuration\n" +
`The value '${value}' for option '${option}' is deprecated. ` +
`Use '${suggestion}' instead.`;

Error.captureStackTrace(this, this.constructor);
}
}

module.exports = WarnDeprecatedOptionPlugin;
11 changes: 6 additions & 5 deletions lib/WebpackOptionsApply.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const RequireEnsurePlugin = require("./dependencies/RequireEnsurePlugin");
const RequireIncludePlugin = require("./dependencies/RequireIncludePlugin");
const SystemPlugin = require("./dependencies/SystemPlugin");

const WarnDeprecatedOptionPlugin = require("./WarnDeprecatedOptionPlugin");
const WarnNoModeSetPlugin = require("./WarnNoModeSetPlugin");

const DeterministicModuleIdsPlugin = require("./ids/DeterministicModuleIdsPlugin");
Expand Down Expand Up @@ -381,6 +382,11 @@ class WebpackOptionsApply extends OptionsApply {
new NamedModuleIdsPlugin().apply(compiler);
break;
case "hashed":
new WarnDeprecatedOptionPlugin(
"optimization.moduleIds",
"hashed",
"deterministic"
).apply(compiler);
new HashedModuleIdsPlugin().apply(compiler);
break;
case "deterministic":
Expand All @@ -393,11 +399,6 @@ class WebpackOptionsApply extends OptionsApply {
prioritiseInitial: true
}).apply(compiler);
break;
case "total-size":
new OccurrenceModuleIdsPlugin({
prioritiseInitial: false
}).apply(compiler);
break;
default:
throw new Error(
`webpack bug: moduleIds: ${moduleIds} is not implemented`
Expand Down
12 changes: 2 additions & 10 deletions schemas/WebpackOptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -443,16 +443,8 @@
}
},
"moduleIds": {
"description": "Define the algorithm to choose module ids (natural: numeric ids in order of usage, named: readable ids for better debugging, hashed: short hashes as ids for better long term caching, deterministic: numeric hash ids for better long term caching, size: numeric ids focused on minimal initial download size, total-size: numeric ids focused on minimal total download size, false: no algorithm used, as custom one can be provided via plugin)",
"enum": [
"natural",
"named",
"hashed",
"deterministic",
"size",
"total-size",
false
]
"description": "Define the algorithm to choose module ids (natural: numeric ids in order of usage, named: readable ids for better debugging, hashed: (deprecated) short hashes as ids for better long term caching, deterministic: numeric hash ids for better long term caching, size: numeric ids focused on minimal initial download size, false: no algorithm used, as custom one can be provided via plugin)",
"enum": ["natural", "named", "hashed", "deterministic", "size", false]
},
"noEmitOnErrors": {
"description": "Avoid emitting assets when errors occur",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = [
[/hashed/, /deprecated/]
];
3 changes: 3 additions & 0 deletions test/configCases/delegated-hash/simple/warnings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = [
[/hashed/, /deprecated/]
];
3 changes: 3 additions & 0 deletions test/configCases/dll-plugin/3-use-dll-with-hashid/warnings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = [
[/hashed/, /deprecated/]
];
3 changes: 3 additions & 0 deletions test/configCases/optimization/hashed-module-ids/warnings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = [
[/hashed/, /deprecated/]
];

0 comments on commit 7669104

Please sign in to comment.