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>
89 lines
2.5 KiB
JavaScript
89 lines
2.5 KiB
JavaScript
/*
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
Author Tobias Koppers @sokra
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
const { STAGE_BASIC } = require("../OptimizationStages");
|
|
|
|
/** @typedef {import("../Chunk")} Chunk */
|
|
/** @typedef {import("../ChunkGroup")} ChunkGroup */
|
|
/** @typedef {import("../Compiler")} Compiler */
|
|
|
|
const PLUGIN_NAME = "EnsureChunkConditionsPlugin";
|
|
|
|
class EnsureChunkConditionsPlugin {
|
|
/**
|
|
* Apply the plugin
|
|
* @param {Compiler} compiler the compiler instance
|
|
* @returns {void}
|
|
*/
|
|
apply(compiler) {
|
|
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
/**
|
|
* @param {Iterable<Chunk>} chunks the chunks
|
|
*/
|
|
const handler = (chunks) => {
|
|
const chunkGraph = compilation.chunkGraph;
|
|
// These sets are hoisted here to save memory
|
|
// They are cleared at the end of every loop
|
|
/** @type {Set<Chunk>} */
|
|
const sourceChunks = new Set();
|
|
/** @type {Set<ChunkGroup>} */
|
|
const chunkGroups = new Set();
|
|
for (const module of compilation.modules) {
|
|
if (!module.hasChunkCondition()) continue;
|
|
for (const chunk of chunkGraph.getModuleChunksIterable(module)) {
|
|
if (!module.chunkCondition(chunk, compilation)) {
|
|
sourceChunks.add(chunk);
|
|
for (const group of chunk.groupsIterable) {
|
|
chunkGroups.add(group);
|
|
}
|
|
}
|
|
}
|
|
if (sourceChunks.size === 0) continue;
|
|
/** @type {Set<Chunk>} */
|
|
const targetChunks = new Set();
|
|
chunkGroupLoop: for (const chunkGroup of chunkGroups) {
|
|
// Can module be placed in a chunk of this group?
|
|
for (const chunk of chunkGroup.chunks) {
|
|
if (module.chunkCondition(chunk, compilation)) {
|
|
targetChunks.add(chunk);
|
|
continue chunkGroupLoop;
|
|
}
|
|
}
|
|
// We reached the entrypoint: fail
|
|
if (chunkGroup.isInitial()) {
|
|
throw new Error(
|
|
`Cannot fulfil chunk condition of ${module.identifier()}`
|
|
);
|
|
}
|
|
// Try placing in all parents
|
|
for (const group of chunkGroup.parentsIterable) {
|
|
chunkGroups.add(group);
|
|
}
|
|
}
|
|
for (const sourceChunk of sourceChunks) {
|
|
chunkGraph.disconnectChunkAndModule(sourceChunk, module);
|
|
}
|
|
for (const targetChunk of targetChunks) {
|
|
chunkGraph.connectChunkAndModule(targetChunk, module);
|
|
}
|
|
sourceChunks.clear();
|
|
chunkGroups.clear();
|
|
}
|
|
};
|
|
compilation.hooks.optimizeChunks.tap(
|
|
{
|
|
name: PLUGIN_NAME,
|
|
stage: STAGE_BASIC
|
|
},
|
|
handler
|
|
);
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = EnsureChunkConditionsPlugin;
|