Skip to content

Commit

Permalink
Merge pull request #11316 from petermetz/master
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Jan 21, 2021
2 parents f85f0d5 + 7002681 commit a07a126
Show file tree
Hide file tree
Showing 27 changed files with 1,730 additions and 424 deletions.
143 changes: 123 additions & 20 deletions declarations/WebpackOptions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,24 @@ export type RuleSetUseItem =
* A list of rules.
*/
export type RuleSetRules = ("..." | RuleSetRule)[];
/**
* Specify options for each generator.
*/
export type GeneratorOptionsByModuleType = GeneratorOptionsByModuleTypeKnown &
GeneratorOptionsByModuleTypeUnknown;
/**
* Don't parse files matching. It's matched against the full resolved request.
*/
export type NoParse =
| (RegExp | string | Function)[]
| RegExp
| string
| Function;
/**
* Specify options for each parser.
*/
export type ParserOptionsByModuleType = ParserOptionsByModuleTypeKnown &
ParserOptionsByModuleTypeUnknown;
/**
* Name of the configuration. Used when loading multiple configurations.
*/
Expand Down Expand Up @@ -1105,71 +1123,71 @@ export interface ModuleOptions {
*/
exprContextCritical?: boolean;
/**
* Enable recursive directory lookup for full dynamic dependencies.
* Enable recursive directory lookup for full dynamic dependencies. Deprecated: This option has moved to 'module.parser.javascript.exprContextRecursive'.
*/
exprContextRecursive?: boolean;
/**
* Sets the default regular expression for full dynamic dependencies.
* Sets the default regular expression for full dynamic dependencies. Deprecated: This option has moved to 'module.parser.javascript.exprContextRegExp'.
*/
exprContextRegExp?: RegExp | boolean;
/**
* Set the default request for full dynamic dependencies.
* Set the default request for full dynamic dependencies. Deprecated: This option has moved to 'module.parser.javascript.exprContextRequest'.
*/
exprContextRequest?: string;
/**
* Specify options for each generator.
*/
generator?: ModuleOptionsGeneratorKnown & ModuleOptionsGeneratorUnknown;
generator?: GeneratorOptionsByModuleType;
/**
* Don't parse files matching. It's matched against the full resolved request.
*/
noParse?: (RegExp | string | Function)[] | RegExp | string | Function;
noParse?: NoParse;
/**
* Specify options for each parser.
*/
parser?: ModuleOptionsParserKnown & ModuleOptionsParserUnknown;
parser?: ParserOptionsByModuleType;
/**
* An array of rules applied for modules.
*/
rules?: RuleSetRules;
/**
* Emit errors instead of warnings when imported names don't exist in imported module.
* Emit errors instead of warnings when imported names don't exist in imported module. Deprecated: This option has moved to 'module.parser.javascript.strictExportPresence'.
*/
strictExportPresence?: boolean;
/**
* Handle the this context correctly according to the spec for namespace objects.
* Handle the this context correctly according to the spec for namespace objects. Deprecated: This option has moved to 'module.parser.javascript.strictThisContextOnImports'.
*/
strictThisContextOnImports?: boolean;
/**
* Enable warnings when using the require function in a not statically analyse-able way.
* Enable warnings when using the require function in a not statically analyse-able way. Deprecated: This option has moved to 'module.parser.javascript.unknownContextCritical'.
*/
unknownContextCritical?: boolean;
/**
* Enable recursive directory lookup when using the require function in a not statically analyse-able way.
* Enable recursive directory lookup when using the require function in a not statically analyse-able way. Deprecated: This option has moved to 'module.parser.javascript.unknownContextRecursive'.
*/
unknownContextRecursive?: boolean;
/**
* Sets the regular expression when using the require function in a not statically analyse-able way.
* Sets the regular expression when using the require function in a not statically analyse-able way. Deprecated: This option has moved to 'module.parser.javascript.unknownContextRegExp'.
*/
unknownContextRegExp?: RegExp | boolean;
/**
* Sets the request when using the require function in a not statically analyse-able way.
* Sets the request when using the require function in a not statically analyse-able way. Deprecated: This option has moved to 'module.parser.javascript.unknownContextRequest'.
*/
unknownContextRequest?: string;
/**
* Cache the resolving of module requests.
*/
unsafeCache?: boolean | Function;
/**
* Enable warnings for partial dynamic dependencies.
* Enable warnings for partial dynamic dependencies. Deprecated: This option has moved to 'module.parser.javascript.wrappedContextCritical'.
*/
wrappedContextCritical?: boolean;
/**
* Enable recursive directory lookup for partial dynamic dependencies.
* Enable recursive directory lookup for partial dynamic dependencies. Deprecated: This option has moved to 'module.parser.javascript.wrappedContextRecursive'.
*/
wrappedContextRecursive?: boolean;
/**
* Set the inner regular expression for partial dynamic dependencies.
* Set the inner regular expression for partial dynamic dependencies. Deprecated: This option has moved to 'module.parser.javascript.wrappedContextRegExp'.
*/
wrappedContextRegExp?: RegExp;
}
Expand Down Expand Up @@ -2560,6 +2578,26 @@ export interface JavascriptParserOptions {
* Enable/disable parsing of CommonJs syntax.
*/
commonjs?: boolean;
/**
* Enable/disable parsing of magic comments in CommonJs syntax.
*/
commonjsMagicComments?: boolean;
/**
* Enable warnings for full dynamic dependencies.
*/
exprContextCritical?: boolean;
/**
* Enable recursive directory lookup for full dynamic dependencies.
*/
exprContextRecursive?: boolean;
/**
* Sets the default regular expression for full dynamic dependencies.
*/
exprContextRegExp?: RegExp | boolean;
/**
* Set the default request for full dynamic dependencies.
*/
exprContextRequest?: string;
/**
* Enable/disable parsing of EcmaScript Modules syntax.
*/
Expand Down Expand Up @@ -2588,10 +2626,34 @@ export interface JavascriptParserOptions {
* Enable/disable parsing of require.js special syntax like require.config, requirejs.config, require.version and requirejs.onError.
*/
requireJs?: boolean;
/**
* Emit errors instead of warnings when imported names don't exist in imported module.
*/
strictExportPresence?: boolean;
/**
* Handle the this context correctly according to the spec for namespace objects.
*/
strictThisContextOnImports?: boolean;
/**
* Enable/disable parsing of System.js special syntax like System.import, System.get, System.set and System.register.
*/
system?: boolean;
/**
* Enable warnings when using the require function in a not statically analyse-able way.
*/
unknownContextCritical?: boolean;
/**
* Enable recursive directory lookup when using the require function in a not statically analyse-able way.
*/
unknownContextRecursive?: boolean;
/**
* Sets the regular expression when using the require function in a not statically analyse-able way.
*/
unknownContextRegExp?: RegExp | boolean;
/**
* Sets the request when using the require function in a not statically analyse-able way.
*/
unknownContextRequest?: string;
/**
* Enable/disable parsing of new URL() syntax.
*/
Expand All @@ -2600,8 +2662,49 @@ export interface JavascriptParserOptions {
* Disable or configure parsing of WebWorker syntax like new Worker() or navigator.serviceWorker.register().
*/
worker?: string[] | boolean;
/**
* Enable warnings for partial dynamic dependencies.
*/
wrappedContextCritical?: boolean;
/**
* Enable recursive directory lookup for partial dynamic dependencies.
*/
wrappedContextRecursive?: boolean;
/**
* Set the inner regular expression for partial dynamic dependencies.
*/
wrappedContextRegExp?: RegExp;
[k: string]: any;
}
/**
* Options affecting the normal modules (`NormalModuleFactory`).
*/
export interface ModuleOptionsNormalized {
/**
* An array of rules applied by default for modules.
*/
defaultRules: RuleSetRules;
/**
* Specify options for each generator.
*/
generator: GeneratorOptionsByModuleType;
/**
* Don't parse files matching. It's matched against the full resolved request.
*/
noParse?: NoParse;
/**
* Specify options for each parser.
*/
parser: ParserOptionsByModuleType;
/**
* An array of rules applied for modules.
*/
rules: RuleSetRules;
/**
* Cache the resolving of module requests.
*/
unsafeCache?: boolean | Function;
}
/**
* Normalized options affecting the output of the compilation. `output` options tell webpack how to write the compiled files to disk.
*/
Expand Down Expand Up @@ -2846,7 +2949,7 @@ export interface WebpackOptionsNormalized {
/**
* Options affecting the normal modules (`NormalModuleFactory`).
*/
module: ModuleOptions;
module: ModuleOptionsNormalized;
/**
* Name of the configuration. Used when loading multiple configurations.
*/
Expand Down Expand Up @@ -2938,7 +3041,7 @@ export interface ExternalItemObjectUnknown {
/**
* Specify options for each generator.
*/
export interface ModuleOptionsGeneratorKnown {
export interface GeneratorOptionsByModuleTypeKnown {
/**
* Generator options for asset modules.
*/
Expand Down Expand Up @@ -2971,7 +3074,7 @@ export interface ModuleOptionsGeneratorKnown {
/**
* Specify options for each generator.
*/
export interface ModuleOptionsGeneratorUnknown {
export interface GeneratorOptionsByModuleTypeUnknown {
/**
* Options for generating.
*/
Expand All @@ -2982,7 +3085,7 @@ export interface ModuleOptionsGeneratorUnknown {
/**
* Specify options for each parser.
*/
export interface ModuleOptionsParserKnown {
export interface ParserOptionsByModuleTypeKnown {
/**
* Parser options for asset modules.
*/
Expand Down Expand Up @@ -3019,7 +3122,7 @@ export interface ModuleOptionsParserKnown {
/**
* Specify options for each parser.
*/
export interface ModuleOptionsParserUnknown {
export interface ParserOptionsByModuleTypeUnknown {
/**
* Options for parsing.
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/Compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ ${other}`);
context: this.options.context,
fs: this.inputFileSystem,
resolverFactory: this.resolverFactory,
options: this.options.module || {},
options: this.options.module,
associatedObjectForCache: this.root,
layers: this.options.experiments.layers
});
Expand Down
2 changes: 1 addition & 1 deletion lib/NormalModuleFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const { cachedCleverMerge, cachedSetProperty } = require("./util/cleverMerge");
const { join } = require("./util/fs");
const { parseResource } = require("./util/identifier");

/** @typedef {import("../declarations/WebpackOptions").ModuleOptions} ModuleOptions */
/** @typedef {import("../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
/** @typedef {import("./Generator")} Generator */
/** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
/** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
Expand Down
9 changes: 4 additions & 5 deletions lib/WebpackOptionsApply.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,15 @@ class WebpackOptionsApply extends OptionsApply {

new CompatibilityPlugin().apply(compiler);
new HarmonyModulesPlugin({
module: options.module,
topLevelAwait: options.experiments.topLevelAwait
}).apply(compiler);
if (options.amd !== false) {
const AMDPlugin = require("./dependencies/AMDPlugin");
const RequireJsStuffPlugin = require("./RequireJsStuffPlugin");
new AMDPlugin(options.module, options.amd || {}).apply(compiler);
new AMDPlugin(options.amd || {}).apply(compiler);
new RequireJsStuffPlugin().apply(compiler);
}
new CommonJsPlugin(options.module).apply(compiler);
new CommonJsPlugin().apply(compiler);
new LoaderPlugin().apply(compiler);
if (options.node !== false) {
const NodeStuffPlugin = require("./NodeStuffPlugin");
Expand All @@ -279,8 +278,8 @@ class WebpackOptionsApply extends OptionsApply {
new RequireIncludePlugin().apply(compiler);
new RequireEnsurePlugin().apply(compiler);
new RequireContextPlugin().apply(compiler);
new ImportPlugin(options.module).apply(compiler);
new SystemPlugin(options.module).apply(compiler);
new ImportPlugin().apply(compiler);
new SystemPlugin().apply(compiler);
new ImportMetaPlugin().apply(compiler);
new URLPlugin().apply(compiler);

Expand Down
36 changes: 18 additions & 18 deletions lib/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const {
/** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
/** @typedef {import("../../declarations/WebpackOptions").Loader} Loader */
/** @typedef {import("../../declarations/WebpackOptions").Mode} Mode */
/** @typedef {import("../../declarations/WebpackOptions").ModuleOptions} ModuleOptions */
/** @typedef {import("../../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
/** @typedef {import("../../declarations/WebpackOptions").Node} WebpackNode */
/** @typedef {import("../../declarations/WebpackOptions").Optimization} Optimization */
/** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} Output */
Expand Down Expand Up @@ -347,10 +347,25 @@ const applySnapshotDefaults = (snapshot, { production }) => {
};

/**
* @param {JavascriptParserOptions} options options
* @param {JavascriptParserOptions} parserOptions parser options
* @returns {void}
*/
const applyJavascriptParserOptionsDefaults = options => {};
const applyJavascriptParserOptionsDefaults = parserOptions => {
D(parserOptions, "unknownContextRequest", ".");
D(parserOptions, "unknownContextRegExp", false);
D(parserOptions, "unknownContextRecursive", true);
D(parserOptions, "unknownContextCritical", true);
D(parserOptions, "exprContextRequest", ".");
D(parserOptions, "exprContextRegExp", false);
D(parserOptions, "exprContextRecursive", true);
D(parserOptions, "exprContextCritical", true);
D(parserOptions, "wrappedContextRegExp", /.*/);
D(parserOptions, "wrappedContextRecursive", true);
D(parserOptions, "wrappedContextCritical", false);

D(parserOptions, "strictExportPresence", false);
D(parserOptions, "strictThisContextOnImports", false);
};

/**
* @param {ModuleOptions} module options
Expand All @@ -364,21 +379,6 @@ const applyModuleDefaults = (
module,
{ cache, syncWebAssembly, asyncWebAssembly }
) => {
D(module, "unknownContextRequest", ".");
D(module, "unknownContextRegExp", false);
D(module, "unknownContextRecursive", true);
D(module, "unknownContextCritical", true);
D(module, "exprContextRequest", ".");
D(module, "exprContextRegExp", false);
D(module, "exprContextRecursive", true);
D(module, "exprContextCritical", true);
D(module, "wrappedContextRegExp", /.*/);
D(module, "wrappedContextRecursive", true);
D(module, "wrappedContextCritical", false);

D(module, "strictExportPresence", false);
D(module, "strictThisContextOnImports", false);

if (cache) {
D(module, "unsafeCache", module => {
const name = module.nameForCondition();
Expand Down

0 comments on commit a07a126

Please sign in to comment.