Files
rspade_system/node_modules/webpack/lib/ids/DeterministicModuleIdsPlugin.js
root 9ebcc359ae Fix code quality violations and enhance ROUTE-EXISTS-01 rule
Implement JQHTML function cache ID system and fix bundle compilation
Implement underscore prefix for system tables
Fix JS syntax linter to support decorators and grant exception to Task system
SPA: Update planning docs and wishlists with remaining features
SPA: Document Navigation API abandonment and future enhancements
Implement SPA browser integration with History API (Phase 1)
Convert contacts view page to SPA action
Convert clients pages to SPA actions and document conversion procedure
SPA: Merge GET parameters and update documentation
Implement SPA route URL generation in JavaScript and PHP
Implement SPA bootstrap controller architecture
Add SPA routing manual page (rsx:man spa)
Add SPA routing documentation to CLAUDE.md
Phase 4 Complete: Client-side SPA routing implementation
Update get_routes() consumers for unified route structure
Complete SPA Phase 3: PHP-side route type detection and is_spa flag
Restore unified routes structure and Manifest_Query class
Refactor route indexing and add SPA infrastructure
Phase 3 Complete: SPA route registration in manifest
Implement SPA Phase 2: Extract router code and test decorators
Rename Jqhtml_Component to Component and complete SPA foundation setup

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-19 17:48:15 +00:00

98 lines
3.0 KiB
JavaScript

/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Florent Cailhol @ooflorent
*/
"use strict";
const {
compareModulesByPreOrderIndexOrIdentifier
} = require("../util/comparators");
const {
assignDeterministicIds,
getFullModuleName,
getUsedModuleIdsAndModules
} = require("./IdHelpers");
/** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../Module")} Module */
/**
* @typedef {object} DeterministicModuleIdsPluginOptions
* @property {string=} context context relative to which module identifiers are computed
* @property {((module: Module) => boolean)=} test selector function for modules
* @property {number=} maxLength maximum id length in digits (used as starting point)
* @property {number=} salt hash salt for ids
* @property {boolean=} fixedLength do not increase the maxLength to find an optimal id space size
* @property {boolean=} failOnConflict throw an error when id conflicts occur (instead of rehashing)
*/
const PLUGIN_NAME = "DeterministicModuleIdsPlugin";
class DeterministicModuleIdsPlugin {
/**
* @param {DeterministicModuleIdsPluginOptions=} options options
*/
constructor(options = {}) {
this.options = options;
}
/**
* Apply the plugin
* @param {Compiler} compiler the compiler instance
* @returns {void}
*/
apply(compiler) {
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
compilation.hooks.moduleIds.tap(PLUGIN_NAME, () => {
const chunkGraph = compilation.chunkGraph;
const context = this.options.context
? this.options.context
: compiler.context;
const maxLength = this.options.maxLength || 3;
const failOnConflict = this.options.failOnConflict || false;
const fixedLength = this.options.fixedLength || false;
const salt = this.options.salt || 0;
let conflicts = 0;
const [usedIds, modules] = getUsedModuleIdsAndModules(
compilation,
this.options.test
);
assignDeterministicIds(
modules,
(module) => getFullModuleName(module, context, compiler.root),
failOnConflict
? () => 0
: compareModulesByPreOrderIndexOrIdentifier(
compilation.moduleGraph
),
(module, id) => {
const size = usedIds.size;
usedIds.add(`${id}`);
if (size === usedIds.size) {
conflicts++;
return false;
}
chunkGraph.setModuleId(module, id);
return true;
},
[10 ** maxLength],
fixedLength ? 0 : 10,
usedIds.size,
salt
);
if (failOnConflict && conflicts) {
throw new Error(
`Assigning deterministic module ids has lead to ${conflicts} conflict${
conflicts > 1 ? "s" : ""
}.\nIncrease the 'maxLength' to increase the id space and make conflicts less likely (recommended when there are many conflicts or application is expected to grow), or add an 'salt' number to try another hash starting value in the same id space (recommended when there is only a single conflict).`
);
}
});
});
}
}
module.exports = DeterministicModuleIdsPlugin;