Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/webpack/webpack into ns
Browse files Browse the repository at this point in the history
  • Loading branch information
bworline committed May 31, 2023
2 parents 5ab7e50 + e0cd928 commit 77c4deb
Show file tree
Hide file tree
Showing 56 changed files with 441 additions and 151 deletions.
4 changes: 3 additions & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

**Do you want to request a _feature_ or report a _bug_?**

<!-- Please ask questions on StackOverflow or the webpack Gitter (https://gitter.im/webpack/webpack). -->
<!-- Please ask questions on StackOverflow or the GitHub Discussions. -->
<!-- https://github.com/webpack/webpack/discussions -->
<!-- https://stackoverflow.com/questions/ask?tags=webpack -->
<!-- Issues which contain questions or support requests will be closed. -->

**What is the current behavior?**
Expand Down
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/Bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ about: Create a report to help us improve

# Bug report

<!-- Please ask questions on StackOverflow or the webpack Gitter. -->
<!-- Please ask questions on StackOverflow or the GitHub Discussions. -->
<!-- https://github.com/webpack/webpack/discussions -->
<!-- https://stackoverflow.com/questions/ask?tags=webpack -->
<!-- https://gitter.im/webpack/webpack -->
<!-- Issues which contain questions or support requests will be closed. -->

**What is the current behavior?**
Expand Down
4 changes: 3 additions & 1 deletion .github/ISSUE_TEMPLATE/Other.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ about: Something else
---

<!-- Bug reports and Feature requests must use other templates, or will be closed -->
<!-- Please ask questions on StackOverflow or the webpack Gitter (https://gitter.im/webpack/webpack). -->
<!-- Please ask questions on StackOverflow or the GitHub Discussions. -->
<!-- https://github.com/webpack/webpack/discussions -->
<!-- https://stackoverflow.com/questions/ask?tags=webpack -->
<!-- Issues which contain questions or support requests will be closed. -->
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@
"xxhash",
"xxhashjs",
"Yann",
"readonly",
"commithash"
],
"ignoreRegExpList": [
Expand Down
4 changes: 4 additions & 0 deletions declarations/WebpackOptions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,10 @@ export interface FileCacheOptions {
* Track and log detailed timing information for individual cache items.
*/
profile?: boolean;
/**
* Enable/disable readonly mode.
*/
readonly?: boolean;
/**
* When to store data to the filesystem. (pack: Store data when compiler is idle in a single file).
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/AsyncDependenciesBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ class AsyncDependenciesBlock extends DependenciesBlock {
}

/**
* @returns {string} The name of the chunk
* @returns {string | undefined} The name of the chunk
*/
get chunkName() {
return this.groupOptions.name;
}

/**
* @param {string} value The new chunk name
* @param {string | undefined} value The new chunk name
* @returns {void}
*/
set chunkName(value) {
Expand Down
1 change: 1 addition & 0 deletions lib/AutomaticPrefetchPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class AutomaticPrefetchPlugin {
);
}
);
/** @type {{context: string, request: string}[] | null} */
let lastModules = null;
compiler.hooks.afterCompile.tap("AutomaticPrefetchPlugin", compilation => {
lastModules = [];
Expand Down
4 changes: 4 additions & 0 deletions lib/BannerPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const validate = createSchemaValidation(
}
);

/**
* @param {string} str string to wrap
* @returns {string} wrapped string
*/
const wrapComment = str => {
if (!str.includes("\n")) {
return Template.toComment(str);
Expand Down
2 changes: 1 addition & 1 deletion lib/CompatibilityPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class CompatibilityPlugin {
return true;
});
parser.hooks.pattern
.for("__webpack_exports__")
.for(RuntimeGlobals.exports)
.tap(PLUGIN_NAME, pattern => {
parser.tagVariable(pattern.name, nestedWebpackIdentifierTag, {
name: "__nested_webpack_exports__",
Expand Down
4 changes: 2 additions & 2 deletions lib/Module.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ const deprecatedNeedRebuild = util.deprecate(

class Module extends DependenciesBlock {
/**
* @param {ModuleTypes | ""} type the module type, when deserializing the type is not known and is an empty string
* @param {ModuleTypes} type the module type, when deserializing the type is not known and is an empty string
* @param {string=} context an optional context
* @param {string=} layer an optional layer in which the module is
*/
constructor(type, context = null, layer = null) {
super();

/** @type {ModuleTypes | ""} */
/** @type {ModuleTypes} */
this.type = type;
/** @type {string | null} */
this.context = context;
Expand Down
3 changes: 2 additions & 1 deletion lib/ModuleTypeConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ const WEBPACK_MODULE_TYPE_LAZY_COMPILATION_PROXY = "lazy-compilation-proxy";
/** @typedef {"css" | "css/global" | "css/module"} CSSModuleTypes */
/** @typedef {"asset" | "asset/inline" | "asset/resource" | "asset/source" | "asset/raw-data-url"} AssetModuleTypes */
/** @typedef {"runtime" | "fallback-module" | "remote-module" | "provide-module" | "consume-shared-module" | "lazy-compilation-proxy"} WebpackModuleTypes */
/** @typedef {JavaScriptModuleTypes | JSONModuleType | WebAssemblyModuleTypes | CSSModuleTypes | AssetModuleTypes | WebpackModuleTypes} ModuleTypes */
/** @typedef {string} UnknownModuleTypes */
/** @typedef {JavaScriptModuleTypes | JSONModuleType | WebAssemblyModuleTypes | CSSModuleTypes | AssetModuleTypes | WebpackModuleTypes | UnknownModuleTypes} ModuleTypes */

exports.ASSET_MODULE_TYPE = ASSET_MODULE_TYPE;
exports.ASSET_MODULE_TYPE_RAW_DATA_URL = ASSET_MODULE_TYPE_RAW_DATA_URL;
Expand Down
4 changes: 2 additions & 2 deletions lib/RuntimeTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -794,10 +794,10 @@ class RuntimeTemplate {
* @param {Module} options.originModule the origin module
* @param {boolean|undefined} options.asiSafe true, if location is safe for ASI, a bracket can be emitted
* @param {boolean} options.isCall true, if expression will be called
* @param {boolean} options.callContext when false, call context will not be preserved
* @param {boolean | null} options.callContext when false, call context will not be preserved
* @param {boolean} options.defaultInterop when true and accessing the default exports, interop code will be generated
* @param {string} options.importVar the identifier name of the import variable
* @param {InitFragment[]} options.initFragments init fragments will be added here
* @param {InitFragment<TODO>[]} options.initFragments init fragments will be added here
* @param {RuntimeSpec} options.runtime runtime for which this code will be generated
* @param {Set<string>} options.runtimeRequirements if set, will be filled with runtime requirements
* @returns {string} expression
Expand Down
3 changes: 2 additions & 1 deletion lib/WebpackOptionsApply.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,8 @@ class WebpackOptionsApply extends OptionsApply {
maxAge: cacheOptions.maxAge,
profile: cacheOptions.profile,
allowCollectingMemory: cacheOptions.allowCollectingMemory,
compression: cacheOptions.compression
compression: cacheOptions.compression,
readonly: cacheOptions.readonly
}),
cacheOptions.idleTimeout,
cacheOptions.idleTimeoutForInitialStore,
Expand Down
8 changes: 7 additions & 1 deletion lib/cache/PackFileCacheStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@ class PackFileCacheStrategy {
* @param {boolean} options.profile track and log detailed timing information for individual cache items
* @param {boolean} options.allowCollectingMemory allow to collect unused memory created during deserialization
* @param {false | "gzip" | "brotli"} options.compression compression used
* @param {boolean} options.readonly disable storing cache into filesystem
*/
constructor({
compiler,
Expand All @@ -993,7 +994,8 @@ class PackFileCacheStrategy {
maxAge,
profile,
allowCollectingMemory,
compression
compression,
readonly
}) {
this.fileSerializer = createFileSerializer(
fs,
Expand All @@ -1012,6 +1014,7 @@ class PackFileCacheStrategy {
this.logger = logger;
this.maxAge = maxAge;
this.profile = profile;
this.readonly = readonly;
this.allowCollectingMemory = allowCollectingMemory;
this.compression = compression;
this._extension =
Expand Down Expand Up @@ -1213,6 +1216,8 @@ class PackFileCacheStrategy {
* @returns {Promise<void>} promise
*/
store(identifier, etag, data) {
if (this.readonly) return Promise.resolve();

return this._getPack().then(pack => {
pack.set(identifier, etag === null ? null : etag.toString(), data);
});
Expand All @@ -1239,6 +1244,7 @@ class PackFileCacheStrategy {
}

storeBuildDependencies(dependencies) {
if (this.readonly) return;
this.newBuildDependencies.addAll(dependencies);
}

Expand Down
6 changes: 4 additions & 2 deletions lib/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const {
JAVASCRIPT_MODULE_TYPE_ESM,
JAVASCRIPT_MODULE_TYPE_DYNAMIC,
WEBASSEMBLY_MODULE_TYPE_SYNC,
ASSET_MODULE_TYPE
ASSET_MODULE_TYPE,
CSS_MODULE_TYPE
} = require("../ModuleTypeConstants");
const Template = require("../Template");
const { cleverMerge } = require("../util/cleverMerge");
Expand Down Expand Up @@ -414,6 +415,7 @@ const applyCacheDefaults = (
D(cache, "maxAge", 1000 * 60 * 60 * 24 * 60); // 1 month
D(cache, "allowCollectingMemory", development);
D(cache, "memoryCacheUnaffected", development && cacheUnaffected);
D(cache, "readonly", false);
D(
/** @type {NonNullable<FileCacheOptions["buildDependencies"]>} */
(cache.buildDependencies),
Expand Down Expand Up @@ -703,7 +705,7 @@ const applyModuleDefaults = (
}
if (css) {
const cssRule = {
type: "css",
type: CSS_MODULE_TYPE,
resolve: {
fullySpecified: true,
preferRelative: true
Expand Down
3 changes: 2 additions & 1 deletion lib/config/normalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ const getNormalizedWebpackOptions = config => {
cache.idleTimeoutAfterLargeChanges,
name: cache.name,
store: cache.store,
version: cache.version
version: cache.version,
readonly: cache.readonly
};
case undefined:
case "memory":
Expand Down
26 changes: 14 additions & 12 deletions lib/dependencies/CommonJsPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ class CommonJsPlugin {
)
);
parser.hooks.expression
.for("module.loaded")
.for(RuntimeGlobals.moduleLoaded)
.tap(PLUGIN_NAME, expr => {
parser.state.module.buildInfo.moduleConcatenationBailout =
"module.loaded";
RuntimeGlobals.moduleLoaded;
const dep = new RuntimeRequirementsDependency([
RuntimeGlobals.moduleLoaded
]);
Expand All @@ -209,16 +209,18 @@ class CommonJsPlugin {
return true;
});

parser.hooks.expression.for("module.id").tap(PLUGIN_NAME, expr => {
parser.state.module.buildInfo.moduleConcatenationBailout =
"module.id";
const dep = new RuntimeRequirementsDependency([
RuntimeGlobals.moduleId
]);
dep.loc = expr.loc;
parser.state.module.addPresentationalDependency(dep);
return true;
});
parser.hooks.expression
.for(RuntimeGlobals.moduleId)
.tap(PLUGIN_NAME, expr => {
parser.state.module.buildInfo.moduleConcatenationBailout =
RuntimeGlobals.moduleId;
const dep = new RuntimeRequirementsDependency([
RuntimeGlobals.moduleId
]);
dep.loc = expr.loc;
parser.state.module.addPresentationalDependency(dep);
return true;
});

parser.hooks.evaluateIdentifier.for("module.hot").tap(
PLUGIN_NAME,
Expand Down
4 changes: 3 additions & 1 deletion lib/dependencies/HarmonyExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

"use strict";

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

/** @typedef {import("../Parser").ParserState} ParserState */

/** @type {WeakMap<ParserState, boolean>} */
Expand All @@ -22,7 +24,7 @@ exports.enable = (parserState, isStrictHarmony) => {
if (value !== true) {
parserState.module.buildMeta.exportsType = "namespace";
parserState.module.buildInfo.strict = true;
parserState.module.buildInfo.exportsArgument = "__webpack_exports__";
parserState.module.buildInfo.exportsArgument = RuntimeGlobals.exports;
if (isStrictHarmony) {
parserState.module.buildMeta.strictHarmonyModule = true;
parserState.module.buildInfo.moduleArgument = "__webpack_module__";
Expand Down
2 changes: 1 addition & 1 deletion lib/esm/ModuleChunkFormatPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class ModuleChunkFormatPlugin {
}
startupSource.add(
`${
final ? "var __webpack_exports__ = " : ""
final ? `var ${RuntimeGlobals.exports} = ` : ""
}__webpack_exec__(${JSON.stringify(moduleId)});\n`
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/javascript/ArrayPushCallbackChunkFormatPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class ArrayPushCallbackChunkFormatPlugin {
.getChunkRuntimeRequirements(chunk)
.has(RuntimeGlobals.returnExportsFromRuntime)
) {
runtime.add("return __webpack_exports__;\n");
runtime.add(`return ${RuntimeGlobals.exports};\n`);
}
}
runtime.add("}\n");
Expand Down
Loading

0 comments on commit 77c4deb

Please sign in to comment.