Standardize settings file naming and relocate documentation files Fix code quality violations from rsx:check Reorganize user_management directory into logical subdirectories Move Quill Bundle to core and align with Tom Select pattern Simplify Site Settings page to focus on core site information Complete Phase 5: Multi-tenant authentication with login flow and site selection Add route query parameter rule and synchronize filename validation logic Fix critical bug in UpdateNpmCommand causing missing JavaScript stubs Implement filename convention rule and resolve VS Code auto-rename conflict Implement js-sanitizer RPC server to eliminate 900+ Node.js process spawns Implement RPC server architecture for JavaScript parsing WIP: Add RPC server infrastructure for JS parsing (partial implementation) Update jqhtml terminology from destroy to stop, fix datagrid DOM preservation Add JQHTML-CLASS-01 rule and fix redundant class names Improve code quality rules and resolve violations Remove legacy fatal error format in favor of unified 'fatal' error type Filter internal keys from window.rsxapp output Update button styling and comprehensive form/modal documentation Add conditional fly-in animation for modals Fix non-deterministic bundle compilation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
239 lines
7.6 KiB
JavaScript
Executable File
239 lines
7.6 KiB
JavaScript
Executable File
/*
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
const RuntimeModule = require("../RuntimeModule");
|
|
const Template = require("../Template");
|
|
const {
|
|
generateJavascriptHMR
|
|
} = require("../hmr/JavascriptHotModuleReplacementHelper");
|
|
const {
|
|
chunkHasJs,
|
|
getChunkFilenameTemplate
|
|
} = require("../javascript/JavascriptModulesPlugin");
|
|
const { getInitialChunkIds } = require("../javascript/StartupHelpers");
|
|
const compileBooleanMatcher = require("../util/compileBooleanMatcher");
|
|
const { getUndoPath } = require("../util/identifier");
|
|
|
|
/** @typedef {import("../Chunk")} Chunk */
|
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
|
/** @typedef {import("../Compilation")} Compilation */
|
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
|
/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
|
|
|
class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
|
/**
|
|
* @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
|
|
*/
|
|
constructor(runtimeRequirements) {
|
|
super("require chunk loading", RuntimeModule.STAGE_ATTACH);
|
|
this.runtimeRequirements = runtimeRequirements;
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* @param {Chunk} chunk chunk
|
|
* @param {string} rootOutputDir root output directory
|
|
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
|
* @returns {string} generated code
|
|
*/
|
|
_generateBaseUri(chunk, rootOutputDir, runtimeTemplate) {
|
|
const options = chunk.getEntryOptions();
|
|
if (options && options.baseUri) {
|
|
return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
|
|
}
|
|
|
|
return `${RuntimeGlobals.baseURI} = require(${runtimeTemplate.renderNodePrefixForCoreModule("url")}).pathToFileURL(${
|
|
rootOutputDir !== "./"
|
|
? `__dirname + ${JSON.stringify(`/${rootOutputDir}`)}`
|
|
: "__filename"
|
|
});`;
|
|
}
|
|
|
|
/**
|
|
* @returns {string | null} runtime code
|
|
*/
|
|
generate() {
|
|
const compilation = /** @type {Compilation} */ (this.compilation);
|
|
const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
|
|
const chunk = /** @type {Chunk} */ (this.chunk);
|
|
const { runtimeTemplate } = compilation;
|
|
const fn = RuntimeGlobals.ensureChunkHandlers;
|
|
const withBaseURI = this.runtimeRequirements.has(RuntimeGlobals.baseURI);
|
|
const withExternalInstallChunk = this.runtimeRequirements.has(
|
|
RuntimeGlobals.externalInstallChunk
|
|
);
|
|
const withOnChunkLoad = this.runtimeRequirements.has(
|
|
RuntimeGlobals.onChunksLoaded
|
|
);
|
|
const withLoading = this.runtimeRequirements.has(
|
|
RuntimeGlobals.ensureChunkHandlers
|
|
);
|
|
const withHmr = this.runtimeRequirements.has(
|
|
RuntimeGlobals.hmrDownloadUpdateHandlers
|
|
);
|
|
const withHmrManifest = this.runtimeRequirements.has(
|
|
RuntimeGlobals.hmrDownloadManifest
|
|
);
|
|
const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs);
|
|
const hasJsMatcher = compileBooleanMatcher(conditionMap);
|
|
const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
|
|
|
|
const outputName = compilation.getPath(
|
|
getChunkFilenameTemplate(chunk, compilation.outputOptions),
|
|
{
|
|
chunk,
|
|
contentHashType: "javascript"
|
|
}
|
|
);
|
|
const rootOutputDir = getUndoPath(
|
|
outputName,
|
|
compilation.outputOptions.path,
|
|
true
|
|
);
|
|
|
|
const stateExpression = withHmr
|
|
? `${RuntimeGlobals.hmrRuntimeStatePrefix}_require`
|
|
: undefined;
|
|
|
|
return Template.asString([
|
|
withBaseURI
|
|
? this._generateBaseUri(chunk, rootOutputDir, runtimeTemplate)
|
|
: "// no baseURI",
|
|
"",
|
|
"// object to store loaded chunks",
|
|
'// "1" means "loaded", otherwise not loaded yet',
|
|
`var installedChunks = ${
|
|
stateExpression ? `${stateExpression} = ${stateExpression} || ` : ""
|
|
}{`,
|
|
Template.indent(
|
|
Array.from(initialChunkIds, (id) => `${JSON.stringify(id)}: 1`).join(
|
|
",\n"
|
|
)
|
|
),
|
|
"};",
|
|
"",
|
|
withOnChunkLoad
|
|
? `${
|
|
RuntimeGlobals.onChunksLoaded
|
|
}.require = ${runtimeTemplate.returningFunction(
|
|
"installedChunks[chunkId]",
|
|
"chunkId"
|
|
)};`
|
|
: "// no on chunks loaded",
|
|
"",
|
|
withLoading || withExternalInstallChunk
|
|
? `var installChunk = ${runtimeTemplate.basicFunction("chunk", [
|
|
"var moreModules = chunk.modules, chunkIds = chunk.ids, runtime = chunk.runtime;",
|
|
"for(var moduleId in moreModules) {",
|
|
Template.indent([
|
|
`if(${RuntimeGlobals.hasOwnProperty}(moreModules, moduleId)) {`,
|
|
Template.indent([
|
|
`${RuntimeGlobals.moduleFactories}[moduleId] = moreModules[moduleId];`
|
|
]),
|
|
"}"
|
|
]),
|
|
"}",
|
|
`if(runtime) runtime(${RuntimeGlobals.require});`,
|
|
"for(var i = 0; i < chunkIds.length; i++)",
|
|
Template.indent("installedChunks[chunkIds[i]] = 1;"),
|
|
withOnChunkLoad ? `${RuntimeGlobals.onChunksLoaded}();` : ""
|
|
])};`
|
|
: "// no chunk install function needed",
|
|
"",
|
|
withLoading
|
|
? Template.asString([
|
|
"// require() chunk loading for javascript",
|
|
`${fn}.require = ${runtimeTemplate.basicFunction(
|
|
"chunkId, promises",
|
|
hasJsMatcher !== false
|
|
? [
|
|
'// "1" is the signal for "already loaded"',
|
|
"if(!installedChunks[chunkId]) {",
|
|
Template.indent([
|
|
hasJsMatcher === true
|
|
? "if(true) { // all chunks have JS"
|
|
: `if(${hasJsMatcher("chunkId")}) {`,
|
|
Template.indent([
|
|
// The require function loads and runs a chunk. When the chunk is being run,
|
|
// it can call __webpack_require__.C to directly complete installed.
|
|
`var installedChunk = require(${JSON.stringify(
|
|
rootOutputDir
|
|
)} + ${
|
|
RuntimeGlobals.getChunkScriptFilename
|
|
}(chunkId));`,
|
|
"if (!installedChunks[chunkId]) {",
|
|
Template.indent(["installChunk(installedChunk);"]),
|
|
"}"
|
|
]),
|
|
"} else installedChunks[chunkId] = 1;",
|
|
""
|
|
]),
|
|
"}"
|
|
]
|
|
: "installedChunks[chunkId] = 1;"
|
|
)};`
|
|
])
|
|
: "// no chunk loading",
|
|
"",
|
|
withExternalInstallChunk
|
|
? Template.asString([
|
|
`module.exports = ${RuntimeGlobals.require};`,
|
|
`${RuntimeGlobals.externalInstallChunk} = installChunk;`
|
|
])
|
|
: "// no external install chunk",
|
|
"",
|
|
withHmr
|
|
? Template.asString([
|
|
"function loadUpdateChunk(chunkId, updatedModulesList) {",
|
|
Template.indent([
|
|
`var update = require(${JSON.stringify(rootOutputDir)} + ${
|
|
RuntimeGlobals.getChunkUpdateScriptFilename
|
|
}(chunkId));`,
|
|
"var updatedModules = update.modules;",
|
|
"var runtime = update.runtime;",
|
|
"for(var moduleId in updatedModules) {",
|
|
Template.indent([
|
|
`if(${RuntimeGlobals.hasOwnProperty}(updatedModules, moduleId)) {`,
|
|
Template.indent([
|
|
"currentUpdate[moduleId] = updatedModules[moduleId];",
|
|
"if(updatedModulesList) updatedModulesList.push(moduleId);"
|
|
]),
|
|
"}"
|
|
]),
|
|
"}",
|
|
"if(runtime) currentUpdateRuntime.push(runtime);"
|
|
]),
|
|
"}",
|
|
"",
|
|
generateJavascriptHMR("require")
|
|
])
|
|
: "// no HMR",
|
|
"",
|
|
withHmrManifest
|
|
? Template.asString([
|
|
`${RuntimeGlobals.hmrDownloadManifest} = function() {`,
|
|
Template.indent([
|
|
"return Promise.resolve().then(function() {",
|
|
Template.indent([
|
|
`return require(${JSON.stringify(rootOutputDir)} + ${
|
|
RuntimeGlobals.getUpdateManifestFilename
|
|
}());`
|
|
]),
|
|
`}).catch(${runtimeTemplate.basicFunction("err", [
|
|
"if(['MODULE_NOT_FOUND', 'ENOENT'].includes(err.code)) return;",
|
|
"throw err;"
|
|
])});`
|
|
]),
|
|
"}"
|
|
])
|
|
: "// no HMR manifest"
|
|
]);
|
|
}
|
|
}
|
|
|
|
module.exports = RequireChunkLoadingRuntimeModule;
|