adnbn 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/bundler/layers.d.ts +3 -3
- package/dist/cli/bundler/layers.js +6 -7
- package/dist/cli/bundler/layers.js.map +1 -1
- package/dist/cli/bundler/plugins/build-assets-map/BuildAssetsMapPlugin.js +42 -14
- package/dist/cli/bundler/plugins/build-assets-map/BuildAssetsMapPlugin.js.map +1 -1
- package/dist/cli/bundler/plugins/build-assets-map/normalize.d.ts +3 -0
- package/dist/cli/bundler/plugins/build-assets-map/normalize.js +24 -0
- package/dist/cli/bundler/plugins/build-assets-map/normalize.js.map +1 -0
- package/dist/cli/bundler/plugins/build-assets-map/templates/runtime.template.d.ts +2 -0
- package/dist/cli/bundler/plugins/build-assets-map/templates.d.ts +9 -0
- package/dist/cli/bundler/plugins/build-assets-map/templates.js +32 -0
- package/dist/cli/bundler/plugins/entrypoint/EntrypointPlugin.js +11 -0
- package/dist/cli/bundler/plugins/entrypoint/EntrypointPlugin.js.map +1 -1
- package/dist/cli/bundler/plugins/isolated-styles/IsolatedStylesPlugin.d.ts +1 -1
- package/dist/cli/bundler/plugins/isolated-styles/IsolatedStylesPlugin.js +38 -13
- package/dist/cli/bundler/plugins/isolated-styles/IsolatedStylesPlugin.js.map +1 -1
- package/dist/cli/bundler/plugins/isolated-styles/chunks.d.ts +5 -1
- package/dist/cli/bundler/plugins/isolated-styles/chunks.js +17 -16
- package/dist/cli/bundler/plugins/isolated-styles/chunks.js.map +1 -1
- package/dist/cli/bundler/plugins/isolated-styles/split-chunks.d.ts +4 -0
- package/dist/cli/bundler/plugins/isolated-styles/split-chunks.js +51 -0
- package/dist/cli/bundler/plugins/isolated-styles/split-chunks.js.map +1 -0
- package/dist/cli/bundler/plugins/isolated-styles/templates.js +36 -6
- package/dist/cli/plugins/content/bundler.d.ts +0 -3
- package/dist/cli/plugins/content/bundler.js +4 -20
- package/dist/cli/plugins/content/bundler.js.map +1 -1
- package/dist/cli/plugins/content/index.js +2 -3
- package/dist/cli/plugins/content/index.js.map +1 -1
- package/dist/cli/plugins/locale/Locale.js +5 -2
- package/dist/cli/plugins/locale/Locale.js.map +1 -1
- package/dist/cli/plugins/style/index.d.ts +1 -2
- package/dist/cli/plugins/style/index.js +19 -30
- package/dist/cli/plugins/style/index.js.map +1 -1
- package/dist/cli/resolvers/config.js +1 -2
- package/dist/cli/resolvers/config.js.map +1 -1
- package/dist/entry/content/adapters/react/Builder.d.ts +4 -2
- package/dist/entry/content/adapters/react/Builder.js +11 -5
- package/dist/entry/content/adapters/react/Builder.js.map +1 -1
- package/dist/entry/content/adapters/react/Node.js +2 -2
- package/dist/entry/content/adapters/react/Node.js.map +1 -1
- package/dist/entry/content/adapters/react/definition.d.ts +2 -0
- package/dist/entry/content/adapters/react/{resolvers/definition.js → definition.js} +1 -1
- package/dist/entry/content/adapters/react/definition.js.map +1 -0
- package/dist/entry/content/adapters/react/index.d.ts +1 -1
- package/dist/entry/content/adapters/react/index.js +1 -1
- package/dist/entry/content/adapters/react/index.js.map +1 -1
- package/dist/entry/content/adapters/vanilla/Builder.d.ts +4 -2
- package/dist/entry/content/adapters/vanilla/Builder.js +14 -5
- package/dist/entry/content/adapters/vanilla/Builder.js.map +1 -1
- package/dist/entry/content/adapters/vanilla/definition.d.ts +2 -0
- package/dist/entry/content/adapters/vanilla/{resolvers/definition.js → definition.js} +2 -2
- package/dist/entry/content/adapters/vanilla/definition.js.map +1 -0
- package/dist/entry/content/adapters/vanilla/index.d.ts +1 -1
- package/dist/entry/content/adapters/vanilla/index.js +1 -1
- package/dist/entry/content/adapters/vanilla/index.js.map +1 -1
- package/dist/entry/content/adapters/vanilla/utils.d.ts +1 -0
- package/dist/entry/content/adapters/vanilla/utils.js +7 -0
- package/dist/entry/content/adapters/vanilla/utils.js.map +1 -0
- package/dist/entry/content/lifecycle/Builder.d.ts +10 -4
- package/dist/entry/content/lifecycle/Builder.js +102 -60
- package/dist/entry/content/lifecycle/Builder.js.map +1 -1
- package/dist/entry/content/lifecycle/MountBuilder.d.ts +6 -3
- package/dist/entry/content/lifecycle/MountBuilder.js +32 -16
- package/dist/entry/content/lifecycle/MountBuilder.js.map +1 -1
- package/dist/entry/content/lifecycle/context/ContainerRegistry.d.ts +7 -0
- package/dist/entry/content/lifecycle/context/ContainerRegistry.js +45 -0
- package/dist/entry/content/lifecycle/context/ContainerRegistry.js.map +1 -0
- package/dist/entry/content/lifecycle/context/Context.d.ts +6 -3
- package/dist/entry/content/lifecycle/context/Context.js +21 -6
- package/dist/entry/content/lifecycle/context/Context.js.map +1 -1
- package/dist/entry/content/lifecycle/context/ManagedContext.d.ts +4 -1
- package/dist/entry/content/lifecycle/context/ManagedContext.js +7 -0
- package/dist/entry/content/lifecycle/context/ManagedContext.js.map +1 -1
- package/dist/entry/content/lifecycle/context/index.d.ts +1 -0
- package/dist/entry/content/lifecycle/context/index.js +6 -4
- package/dist/entry/content/lifecycle/context/index.js.map +1 -1
- package/dist/entry/content/lifecycle/markers/AttributeMarker.js +3 -1
- package/dist/entry/content/lifecycle/markers/AttributeMarker.js.map +1 -1
- package/dist/entry/content/lifecycle/nodes/EventNode.d.ts +4 -2
- package/dist/entry/content/lifecycle/nodes/EventNode.js +7 -2
- package/dist/entry/content/lifecycle/nodes/EventNode.js.map +1 -1
- package/dist/entry/content/lifecycle/nodes/FrameNode.d.ts +2 -1
- package/dist/entry/content/lifecycle/nodes/FrameNode.js +3 -0
- package/dist/entry/content/lifecycle/nodes/FrameNode.js.map +1 -1
- package/dist/entry/content/lifecycle/nodes/MarkerNode.d.ts +1 -1
- package/dist/entry/content/lifecycle/nodes/MarkerNode.js.map +1 -1
- package/dist/entry/content/lifecycle/nodes/MountNode.d.ts +7 -3
- package/dist/entry/content/lifecycle/nodes/MountNode.js +47 -12
- package/dist/entry/content/lifecycle/nodes/MountNode.js.map +1 -1
- package/dist/entry/content/lifecycle/nodes/Node.d.ts +1 -1
- package/dist/entry/content/lifecycle/nodes/Node.js.map +1 -1
- package/dist/entry/content/lifecycle/nodes/RenderNode.d.ts +13 -4
- package/dist/entry/content/lifecycle/nodes/RenderNode.js +71 -6
- package/dist/entry/content/lifecycle/nodes/RenderNode.js.map +1 -1
- package/dist/entry/content/lifecycle/nodes/ShadowNode.d.ts +2 -1
- package/dist/entry/content/lifecycle/nodes/ShadowNode.js +3 -0
- package/dist/entry/content/lifecycle/nodes/ShadowNode.js.map +1 -1
- package/dist/entry/content/lifecycle/types.d.ts +28 -0
- package/dist/entry/content/resolvers/watch.d.ts +1 -1
- package/dist/entry/content/resolvers/watch.js +29 -14
- package/dist/entry/content/resolvers/watch.js.map +1 -1
- package/dist/entry/relay/index.js.map +1 -1
- package/dist/shared/locale/index.d.ts +1 -1
- package/dist/shared/locale/index.js +3 -1
- package/dist/shared/locale/index.js.map +1 -1
- package/dist/shared/locale/messages.d.ts +4 -0
- package/dist/shared/locale/messages.js +12 -0
- package/dist/shared/locale/messages.js.map +1 -1
- package/dist/types/content/common.d.ts +8 -0
- package/dist/types/content/common.js.map +1 -1
- package/dist/types/content/definition.d.ts +5 -0
- package/dist/types/locale.d.ts +3 -0
- package/dist/types/locale.js.map +1 -1
- package/package.json +1 -3
- package/types/client.d.ts +3 -3
- package/dist/cli/plugins/style/types.d.ts +0 -5
- package/dist/entry/content/adapters/react/resolvers/definition.d.ts +0 -2
- package/dist/entry/content/adapters/react/resolvers/definition.js.map +0 -1
- package/dist/entry/content/adapters/react/resolvers/render.d.ts +0 -2
- package/dist/entry/content/adapters/react/resolvers/render.js +0 -9
- package/dist/entry/content/adapters/react/resolvers/render.js.map +0 -1
- package/dist/entry/content/adapters/vanilla/resolvers/definition.d.ts +0 -2
- package/dist/entry/content/adapters/vanilla/resolvers/definition.js.map +0 -1
- package/dist/entry/content/adapters/vanilla/resolvers/render.d.ts +0 -3
- package/dist/entry/content/adapters/vanilla/resolvers/render.js +0 -15
- package/dist/entry/content/adapters/vanilla/resolvers/render.js.map +0 -1
- /package/dist/{cli/plugins/style → entry/content/lifecycle}/types.js +0 -0
- /package/dist/{cli/plugins/style → entry/content/lifecycle}/types.js.map +0 -0
|
@@ -2,7 +2,8 @@ import { RuntimeGlobals, RuntimeModule } from "@rspack/core";
|
|
|
2
2
|
import { CssContentHashType, filenameRequiresFullHash, resolveChunkFilename } from "./../../../../cli/bundler/utils/chunk-filename.js";
|
|
3
3
|
import { getManifestHooks } from "../utils/manifest-hooks.js";
|
|
4
4
|
import { renderIsolatedStylesCssLoader, renderIsolatedStylesRuntime } from "./templates.js";
|
|
5
|
-
import {
|
|
5
|
+
import { getStylesFiles, isIsolatedStylesChunk } from "./chunks.js";
|
|
6
|
+
import { createStylesCacheGroup, DocumentStylesCacheGroup } from "./split-chunks.js";
|
|
6
7
|
const PluginName = "IsolatedStylesPlugin";
|
|
7
8
|
const CssLoadingRuntimeIdentifier = "webpack/runtime/css loading";
|
|
8
9
|
const CssRuntimeBoundary = "// object to store loaded CSS chunks";
|
|
@@ -25,7 +26,9 @@ class IsolatedStylesRuntimeModule extends RuntimeModule {
|
|
|
25
26
|
cssChunkFilename;
|
|
26
27
|
generate() {
|
|
27
28
|
const compilation = this.compilation;
|
|
28
|
-
if (!compilation)
|
|
29
|
+
if (!compilation) {
|
|
30
|
+
throw new Error("Isolated styles runtime is not attached to a compilation");
|
|
31
|
+
}
|
|
29
32
|
const initialStyles = initialStyleChunks(compilation, this.entry, this.cssFilename, this.cssChunkFilename).map(
|
|
30
33
|
({ chunk, filename }) => resolveChunkFilename(compilation, chunk, filename, CssContentHashType)
|
|
31
34
|
);
|
|
@@ -40,9 +43,10 @@ class IsolatedStylesRuntimeModule extends RuntimeModule {
|
|
|
40
43
|
}
|
|
41
44
|
const initialStyleChunks = (compilation, entry, cssFilename, cssChunkFilename) => {
|
|
42
45
|
const entrypoint = compilation.entrypoints.get(entry);
|
|
43
|
-
if (!entrypoint)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
if (!entrypoint) {
|
|
47
|
+
throw new Error(`Isolated styles entrypoint "${entry}" is unavailable`);
|
|
48
|
+
}
|
|
49
|
+
return Array.from(entrypoint.chunks).filter((chunk) => isIsolatedStylesChunk(compilation, chunk)).map((chunk) => ({ chunk, filename: chunk.canBeInitial() ? cssFilename : cssChunkFilename }));
|
|
46
50
|
};
|
|
47
51
|
const hasAsyncCss = (chunk) => {
|
|
48
52
|
return Array.from(chunk.getAllAsyncChunks()).some((candidate) => {
|
|
@@ -56,14 +60,31 @@ class IsolatedStylesPlugin {
|
|
|
56
60
|
options;
|
|
57
61
|
originalRuntimeSources = /* @__PURE__ */ new WeakMap();
|
|
58
62
|
apply(compiler) {
|
|
63
|
+
const cacheGroup = createStylesCacheGroup(compiler, this.options.test);
|
|
64
|
+
compiler.hooks.afterEnvironment.tap(PluginName, () => {
|
|
65
|
+
const splitChunks = compiler.options.optimization.splitChunks;
|
|
66
|
+
if (splitChunks) {
|
|
67
|
+
splitChunks.cacheGroups = {
|
|
68
|
+
[DocumentStylesCacheGroup]: cacheGroup,
|
|
69
|
+
...splitChunks.cacheGroups
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
});
|
|
59
73
|
compiler.hooks.compilation.tap(PluginName, (compilation) => {
|
|
60
74
|
getManifestHooks(compilation).prepareDependencies.tap(PluginName, (dependencies) => {
|
|
61
|
-
|
|
75
|
+
var _a;
|
|
62
76
|
for (const [entry, dependency] of dependencies) {
|
|
63
|
-
if (!this.options.test(entry))
|
|
77
|
+
if (!this.options.test(entry)) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const files = getStylesFiles(compilation, ((_a = compilation.entrypoints.get(entry)) == null ? void 0 : _a.chunks) ?? []);
|
|
64
81
|
for (const file of dependency.css) {
|
|
65
|
-
if (!
|
|
66
|
-
|
|
82
|
+
if (!files.defaults.has(file)) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (!files.document.has(file)) {
|
|
86
|
+
dependency.css.delete(file);
|
|
87
|
+
}
|
|
67
88
|
dependency.assets.add(file);
|
|
68
89
|
}
|
|
69
90
|
}
|
|
@@ -127,7 +148,7 @@ class IsolatedStylesPlugin {
|
|
|
127
148
|
}
|
|
128
149
|
source.source = renderIsolatedStylesCssLoader({
|
|
129
150
|
isolatedChunks: Object.fromEntries(
|
|
130
|
-
[...
|
|
151
|
+
[...chunk.getAllReferencedChunks()].filter((candidate) => isIsolatedStylesChunk(compilation, candidate)).map((candidate) => [candidate.id, true])
|
|
131
152
|
),
|
|
132
153
|
originalLoader: originalSource.slice(0, boundary),
|
|
133
154
|
cssFilenameExpression: filenameExpression,
|
|
@@ -149,16 +170,20 @@ class IsolatedStylesPlugin {
|
|
|
149
170
|
...entrypoint.getEntrypointChunk().getAllReferencedChunks()
|
|
150
171
|
]);
|
|
151
172
|
for (const candidate of referenced) {
|
|
152
|
-
const destination = isIsolatedStylesChunk(compilation, candidate) ? isolated : document;
|
|
173
|
+
const destination = this.options.test(entry) && isIsolatedStylesChunk(compilation, candidate) ? isolated : document;
|
|
153
174
|
for (const file of candidate.files) {
|
|
154
|
-
if (file.endsWith(".css"))
|
|
175
|
+
if (file.endsWith(".css")) {
|
|
176
|
+
destination.add(file);
|
|
177
|
+
}
|
|
155
178
|
}
|
|
156
179
|
}
|
|
157
180
|
const warnings = this.options.validate(entry, {
|
|
158
181
|
document: [...document].sort(),
|
|
159
182
|
isolated: [...isolated].sort()
|
|
160
183
|
});
|
|
161
|
-
for (const message of warnings ?? [])
|
|
184
|
+
for (const message of warnings ?? []) {
|
|
185
|
+
compilation.warnings.push(new Error(message));
|
|
186
|
+
}
|
|
162
187
|
}
|
|
163
188
|
if (chunk && chunk.name !== void 0 && this.options.test(chunk.name) && hasAsyncCss(entrypoint.getEntrypointChunk()) && !patched.has(chunk)) {
|
|
164
189
|
throw new Error(`CSS loading runtime for isolated entrypoint "${chunk.name}" was not replaced`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/cli/bundler/plugins/isolated-styles/IsolatedStylesPlugin.ts"],"sourcesContent":["import {type Chunk, type Compilation, type Compiler, type Filename, RuntimeGlobals, RuntimeModule} from \"@rspack/core\";\n\nimport {CssContentHashType, filenameRequiresFullHash, resolveChunkFilename} from \"@cli/bundler/utils/chunk-filename\";\nimport type {RuntimePropertyOptions} from \"../types\";\nimport {getManifestHooks} from \"../utils/manifest-hooks\";\n\nimport {renderIsolatedStylesCssLoader, renderIsolatedStylesRuntime} from \"./templates\";\nimport {getIsolatedStylesFiles, isIsolatedStylesChunk} from \"./chunks\";\n\nconst PluginName = \"IsolatedStylesPlugin\";\nconst CssLoadingRuntimeIdentifier = \"webpack/runtime/css loading\";\nconst CssRuntimeBoundary = \"// object to store loaded CSS chunks\";\nconst CssFilenameExpression = /var href = (.+?)\\(chunkId\\);/;\n\nexport interface IsolatedStylesPluginOptions extends RuntimePropertyOptions {\n cssFilename: Filename;\n cssChunkFilename: Filename;\n test: (entry: string) => boolean;\n timeout?: number;\n /** Inspects every entry's initial, shared and async CSS, independently of test. Throw to reject; return warning messages to report without changing delivery. */\n validate?: (entry: string, files: IsolatedStylesPluginFiles) => void | readonly string[];\n}\n\n/** CSS destinations in one entrypoint's complete dependency graph, for build diagnostics only. */\nexport interface IsolatedStylesPluginFiles {\n readonly document: readonly string[];\n readonly isolated: readonly string[];\n}\n\nclass IsolatedStylesRuntimeModule extends RuntimeModule {\n public constructor(\n private readonly entry: string,\n private readonly property: string,\n private readonly timeout: number,\n private readonly cssFilename: Filename,\n private readonly cssChunkFilename: Filename,\n fullHash: boolean\n ) {\n super(`isolated styles ${entry}`, RuntimeModule.STAGE_ATTACH);\n this.dependentHash = true;\n this.fullHash = fullHash;\n }\n\n public generate(): string {\n const compilation = this.compilation;\n if (!compilation) throw new Error(\"Isolated styles runtime is not attached to a compilation\");\n\n const initialStyles = initialStyleChunks(compilation, this.entry, this.cssFilename, this.cssChunkFilename).map(\n ({chunk, filename}) => resolveChunkFilename(compilation, chunk, filename, CssContentHashType)\n );\n\n return renderIsolatedStylesRuntime({\n entry: this.entry,\n require: RuntimeGlobals.require,\n property: this.property,\n timeout: this.timeout,\n initialStyles,\n });\n }\n}\n\nconst initialStyleChunks = (\n compilation: Compilation,\n entry: string,\n cssFilename: Filename,\n cssChunkFilename: Filename\n): {chunk: Chunk; filename: Filename}[] => {\n const entrypoint = compilation.entrypoints.get(entry);\n if (!entrypoint) throw new Error(`Isolated styles entrypoint \"${entry}\" is unavailable`);\n\n const entryChunk = entrypoint.getEntrypointChunk();\n return Array.from(entrypoint.chunks)\n .filter(chunk => isIsolatedStylesChunk(compilation, chunk))\n .map(chunk => ({chunk, filename: chunk === entryChunk ? cssFilename : cssChunkFilename}));\n};\n\nconst hasAsyncCss = (chunk: Chunk): boolean => {\n return Array.from(chunk.getAllAsyncChunks()).some(candidate => {\n return [...candidate.files, ...candidate.auxiliaryFiles].some(file => file.endsWith(\".css\"));\n });\n};\n\nexport default class IsolatedStylesPlugin {\n private readonly originalRuntimeSources = new WeakMap<RuntimeModule, string>();\n\n public constructor(private readonly options: IsolatedStylesPluginOptions) {}\n\n public apply(compiler: Compiler): void {\n compiler.hooks.compilation.tap(PluginName, compilation => {\n getManifestHooks(compilation).prepareDependencies.tap(PluginName, dependencies => {\n const isolatedFiles = getIsolatedStylesFiles(compilation);\n for (const [entry, dependency] of dependencies) {\n if (!this.options.test(entry)) continue;\n\n for (const file of dependency.css) {\n if (!isolatedFiles.has(file)) continue;\n dependency.css.delete(file);\n dependency.assets.add(file);\n }\n }\n });\n });\n\n const timeout = this.options.timeout ?? compiler.options.output.chunkLoadTimeout ?? 120_000;\n\n compiler.hooks.thisCompilation.tap(PluginName, compilation => {\n const injected = new Set<Chunk>();\n const patched = new Set<Chunk>();\n\n compilation.hooks.additionalTreeRuntimeRequirements.tap(PluginName, (chunk, requirements) => {\n if (chunk.name === undefined || !this.options.test(chunk.name) || injected.has(chunk)) {\n return;\n }\n\n requirements.add(RuntimeGlobals.require);\n requirements.add(RuntimeGlobals.publicPath);\n injected.add(chunk);\n const fullHash = initialStyleChunks(\n compilation,\n chunk.name,\n this.options.cssFilename,\n this.options.cssChunkFilename\n ).some(({chunk, filename}) =>\n filenameRequiresFullHash(compilation, chunk, filename, CssContentHashType)\n );\n compilation.addRuntimeModule(\n chunk,\n new IsolatedStylesRuntimeModule(\n chunk.name,\n this.options.property,\n timeout,\n this.options.cssFilename,\n this.options.cssChunkFilename,\n fullHash\n )\n );\n });\n\n compilation.hooks.runtimeModule.tap(PluginName, (runtimeModule, chunk) => {\n if (chunk.name === undefined || runtimeModule.identifier() !== CssLoadingRuntimeIdentifier) {\n return;\n }\n\n const source = runtimeModule.source;\n\n if (!source || typeof source.source !== \"string\") {\n throw new Error(\n `CSS loading runtime source for isolated entrypoint \"${chunk.name}\" is unavailable`\n );\n }\n\n if (source.source.length === 0) {\n return;\n }\n\n const originalSource = this.originalRuntimeSources.get(runtimeModule) ?? source.source;\n this.originalRuntimeSources.set(runtimeModule, originalSource);\n source.source = originalSource;\n\n if (!this.options.test(chunk.name)) {\n return;\n }\n\n const boundary = originalSource.indexOf(CssRuntimeBoundary);\n const filenameExpression = originalSource.match(CssFilenameExpression)?.[1];\n\n if (boundary < 0 || !filenameExpression) {\n throw new Error(`CSS loading runtime seam for isolated entrypoint \"${chunk.name}\" is unavailable`);\n }\n\n source.source = renderIsolatedStylesCssLoader({\n isolatedChunks: Object.fromEntries(\n [...compilation.chunks]\n .filter(candidate => isIsolatedStylesChunk(compilation, candidate))\n .map(candidate => [candidate.id, true])\n ),\n originalLoader: originalSource.slice(0, boundary),\n cssFilenameExpression: filenameExpression,\n originalRuntime: originalSource.slice(boundary),\n publicPath: RuntimeGlobals.publicPath,\n require: RuntimeGlobals.require,\n property: this.options.property,\n });\n patched.add(chunk);\n });\n\n compilation.hooks.afterSeal.tap(PluginName, () => {\n for (const [entry, entrypoint] of compilation.entrypoints) {\n const chunk = entrypoint.getRuntimeChunk();\n\n if (this.options.validate) {\n const document = new Set<string>();\n const isolated = new Set<string>();\n const referenced = new Set([\n ...entrypoint.chunks,\n ...entrypoint.getEntrypointChunk().getAllReferencedChunks(),\n ]);\n for (const candidate of referenced) {\n const destination = isIsolatedStylesChunk(compilation, candidate) ? isolated : document;\n for (const file of candidate.files) {\n if (file.endsWith(\".css\")) destination.add(file);\n }\n }\n const warnings = this.options.validate(entry, {\n document: [...document].sort(),\n isolated: [...isolated].sort(),\n });\n for (const message of warnings ?? []) compilation.warnings.push(new Error(message));\n }\n\n if (\n chunk &&\n chunk.name !== undefined &&\n this.options.test(chunk.name) &&\n hasAsyncCss(entrypoint.getEntrypointChunk()) &&\n !patched.has(chunk)\n ) {\n throw new Error(`CSS loading runtime for isolated entrypoint \"${chunk.name}\" was not replaced`);\n }\n }\n });\n });\n }\n}\n"],"mappings":"AAAA,SAAoE,gBAAgB,qBAAoB;AAExG,SAAQ,oBAAoB,0BAA0B,4BAA2B;AAEjF,SAAQ,wBAAuB;AAE/B,SAAQ,+BAA+B,mCAAkC;AACzE,SAAQ,wBAAwB,6BAA4B;AAE5D,MAAM,aAAa;AACnB,MAAM,8BAA8B;AACpC,MAAM,qBAAqB;AAC3B,MAAM,wBAAwB;AAiB9B,MAAM,oCAAoC,cAAc;AAAA,EAC7C,YACc,OACA,UACA,SACA,aACA,kBACjB,UACF;AACE,UAAM,mBAAmB,KAAK,IAAI,cAAc,YAAY;AAP3C;AACA;AACA;AACA;AACA;AAIjB,SAAK,gBAAgB;AACrB,SAAK,WAAW;AAAA,EACpB;AAAA,EAVqB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAQd,WAAmB;AACtB,UAAM,cAAc,KAAK;AACzB,QAAI,CAAC,YAAa,OAAM,IAAI,MAAM,0DAA0D;AAE5F,UAAM,gBAAgB,mBAAmB,aAAa,KAAK,OAAO,KAAK,aAAa,KAAK,gBAAgB,EAAE;AAAA,MACvG,CAAC,EAAC,OAAO,SAAQ,MAAM,qBAAqB,aAAa,OAAO,UAA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AC;AACD,uBAAW,aAAa,YAAY;AAChC,oBAAM,cAAc,sBAAsB,aAAa,SAAS,IAAI,WAAW;AAC/E,yBAAW,QAAQ,UAAU,OAAO;AAChC,oBAAI,KAAK,SAAS,MAAM,EAAG,aAAY,IAAI,IAAI;AAAA,cACnD;AAAA,YACJ;AACA,kBAAM,WAAW,KAAK,QAAQ,SAAS,OAAO;AAAA,cAC1C,UAAU,CAAC,GAAG,QAAQ,EAAE,KAAK;AAAA,cAC7B,UAAU,CAAC,GAAG,QAAQ,EAAE,KAAK;AAAA,YACjC,CAAC;AACD,uBAAW,WAAW,YAAY,CAAC,EAAG,aAAY,SAAS,KAAK,IAAI,MAAM,OAAO,CAAC;AAAA,UACtF;AAEA,cACI,SACA,MAAM,SAAS,UACf,KAAK,QAAQ,KAAK,MAAM,IAAI,KAC5B,YAAY,WAAW,mBAAmB,CAAC,KAC3C,CAAC,QAAQ,IAAI,KAAK,GACpB;AACE,kBAAM,IAAI,MAAM,gDAAgD,MAAM,IAAI,oBAAoB;AAAA,UAClG;AAAA,QACJ;AAAA,MACJ,CAAC;AAAA,IACL,CAAC;AAAA,EACL;AACJ;","names":["chunk"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/cli/bundler/plugins/isolated-styles/IsolatedStylesPlugin.ts"],"sourcesContent":["import {type Chunk, type Compilation, type Compiler, type Filename, RuntimeGlobals, RuntimeModule} from \"@rspack/core\";\n\nimport {CssContentHashType, filenameRequiresFullHash, resolveChunkFilename} from \"@cli/bundler/utils/chunk-filename\";\nimport type {RuntimePropertyOptions} from \"../types\";\nimport {getManifestHooks} from \"../utils/manifest-hooks\";\n\nimport {renderIsolatedStylesCssLoader, renderIsolatedStylesRuntime} from \"./templates\";\nimport {getStylesFiles, isIsolatedStylesChunk} from \"./chunks\";\nimport {createStylesCacheGroup, DocumentStylesCacheGroup} from \"./split-chunks\";\n\nconst PluginName = \"IsolatedStylesPlugin\";\nconst CssLoadingRuntimeIdentifier = \"webpack/runtime/css loading\";\nconst CssRuntimeBoundary = \"// object to store loaded CSS chunks\";\nconst CssFilenameExpression = /var href = (.+?)\\(chunkId\\);/;\n\nexport interface IsolatedStylesPluginOptions extends RuntimePropertyOptions {\n cssFilename: Filename;\n cssChunkFilename: Filename;\n test: (entry: string) => boolean;\n timeout?: number;\n /** Inspects every entry's initial, shared and async CSS using its delivery policy. Throw to reject; return warning messages without changing delivery. */\n validate?: (entry: string, files: IsolatedStylesPluginFiles) => void | readonly string[];\n}\n\n/** CSS destinations in one entrypoint's complete dependency graph, for build diagnostics only. */\nexport interface IsolatedStylesPluginFiles {\n readonly document: readonly string[];\n readonly isolated: readonly string[];\n}\n\nclass IsolatedStylesRuntimeModule extends RuntimeModule {\n public constructor(\n private readonly entry: string,\n private readonly property: string,\n private readonly timeout: number,\n private readonly cssFilename: Filename,\n private readonly cssChunkFilename: Filename,\n fullHash: boolean\n ) {\n super(`isolated styles ${entry}`, RuntimeModule.STAGE_ATTACH);\n this.dependentHash = true;\n this.fullHash = fullHash;\n }\n\n public generate(): string {\n const compilation = this.compilation;\n\n if (!compilation) {\n throw new Error(\"Isolated styles runtime is not attached to a compilation\");\n }\n\n const initialStyles = initialStyleChunks(compilation, this.entry, this.cssFilename, this.cssChunkFilename).map(\n ({chunk, filename}) => resolveChunkFilename(compilation, chunk, filename, CssContentHashType)\n );\n\n return renderIsolatedStylesRuntime({\n entry: this.entry,\n require: RuntimeGlobals.require,\n property: this.property,\n timeout: this.timeout,\n initialStyles,\n });\n }\n}\n\nconst initialStyleChunks = (\n compilation: Compilation,\n entry: string,\n cssFilename: Filename,\n cssChunkFilename: Filename\n): {chunk: Chunk; filename: Filename}[] => {\n const entrypoint = compilation.entrypoints.get(entry);\n\n if (!entrypoint) {\n throw new Error(`Isolated styles entrypoint \"${entry}\" is unavailable`);\n }\n\n return Array.from(entrypoint.chunks)\n .filter(chunk => isIsolatedStylesChunk(compilation, chunk))\n .map(chunk => ({chunk, filename: chunk.canBeInitial() ? cssFilename : cssChunkFilename}));\n};\n\nconst hasAsyncCss = (chunk: Chunk): boolean => {\n return Array.from(chunk.getAllAsyncChunks()).some(candidate => {\n return [...candidate.files, ...candidate.auxiliaryFiles].some(file => file.endsWith(\".css\"));\n });\n};\n\nexport default class IsolatedStylesPlugin {\n private readonly originalRuntimeSources = new WeakMap<RuntimeModule, string>();\n\n public constructor(private readonly options: IsolatedStylesPluginOptions) {}\n\n public apply(compiler: Compiler): void {\n const cacheGroup = createStylesCacheGroup(compiler, this.options.test);\n\n // Defaults are resolved before this hook; SplitChunksPlugin is configured afterwards.\n compiler.hooks.afterEnvironment.tap(PluginName, () => {\n const splitChunks = compiler.options.optimization.splitChunks;\n\n if (splitChunks) {\n splitChunks.cacheGroups = {\n [DocumentStylesCacheGroup]: cacheGroup,\n ...splitChunks.cacheGroups,\n };\n }\n });\n\n compiler.hooks.compilation.tap(PluginName, compilation => {\n getManifestHooks(compilation).prepareDependencies.tap(PluginName, dependencies => {\n for (const [entry, dependency] of dependencies) {\n if (!this.options.test(entry)) {\n continue;\n }\n\n const files = getStylesFiles(compilation, compilation.entrypoints.get(entry)?.chunks ?? []);\n\n for (const file of dependency.css) {\n if (!files.defaults.has(file)) {\n continue;\n }\n\n // Identical CSS can have the same contenthash filename in both destinations.\n if (!files.document.has(file)) {\n dependency.css.delete(file);\n }\n\n dependency.assets.add(file);\n }\n }\n });\n });\n\n const timeout = this.options.timeout ?? compiler.options.output.chunkLoadTimeout ?? 120_000;\n\n compiler.hooks.thisCompilation.tap(PluginName, compilation => {\n const injected = new Set<Chunk>();\n const patched = new Set<Chunk>();\n\n compilation.hooks.additionalTreeRuntimeRequirements.tap(PluginName, (chunk, requirements) => {\n if (chunk.name === undefined || !this.options.test(chunk.name) || injected.has(chunk)) {\n return;\n }\n\n requirements.add(RuntimeGlobals.require);\n requirements.add(RuntimeGlobals.publicPath);\n injected.add(chunk);\n\n const fullHash = initialStyleChunks(\n compilation,\n chunk.name,\n this.options.cssFilename,\n this.options.cssChunkFilename\n ).some(({chunk, filename}) =>\n filenameRequiresFullHash(compilation, chunk, filename, CssContentHashType)\n );\n\n compilation.addRuntimeModule(\n chunk,\n new IsolatedStylesRuntimeModule(\n chunk.name,\n this.options.property,\n timeout,\n this.options.cssFilename,\n this.options.cssChunkFilename,\n fullHash\n )\n );\n });\n\n compilation.hooks.runtimeModule.tap(PluginName, (runtimeModule, chunk) => {\n if (chunk.name === undefined || runtimeModule.identifier() !== CssLoadingRuntimeIdentifier) {\n return;\n }\n\n const source = runtimeModule.source;\n\n if (!source || typeof source.source !== \"string\") {\n throw new Error(\n `CSS loading runtime source for isolated entrypoint \"${chunk.name}\" is unavailable`\n );\n }\n\n if (source.source.length === 0) {\n return;\n }\n\n const originalSource = this.originalRuntimeSources.get(runtimeModule) ?? source.source;\n this.originalRuntimeSources.set(runtimeModule, originalSource);\n source.source = originalSource;\n\n if (!this.options.test(chunk.name)) {\n return;\n }\n\n const boundary = originalSource.indexOf(CssRuntimeBoundary);\n const filenameExpression = originalSource.match(CssFilenameExpression)?.[1];\n\n if (boundary < 0 || !filenameExpression) {\n throw new Error(`CSS loading runtime seam for isolated entrypoint \"${chunk.name}\" is unavailable`);\n }\n\n source.source = renderIsolatedStylesCssLoader({\n isolatedChunks: Object.fromEntries(\n [...chunk.getAllReferencedChunks()]\n .filter(candidate => isIsolatedStylesChunk(compilation, candidate))\n .map(candidate => [candidate.id, true])\n ),\n originalLoader: originalSource.slice(0, boundary),\n cssFilenameExpression: filenameExpression,\n originalRuntime: originalSource.slice(boundary),\n publicPath: RuntimeGlobals.publicPath,\n require: RuntimeGlobals.require,\n property: this.options.property,\n });\n\n patched.add(chunk);\n });\n\n compilation.hooks.afterSeal.tap(PluginName, () => {\n for (const [entry, entrypoint] of compilation.entrypoints) {\n const chunk = entrypoint.getRuntimeChunk();\n\n if (this.options.validate) {\n const document = new Set<string>();\n const isolated = new Set<string>();\n\n const referenced = new Set([\n ...entrypoint.chunks,\n ...entrypoint.getEntrypointChunk().getAllReferencedChunks(),\n ]);\n\n for (const candidate of referenced) {\n const destination =\n this.options.test(entry) && isIsolatedStylesChunk(compilation, candidate)\n ? isolated\n : document;\n\n for (const file of candidate.files) {\n if (file.endsWith(\".css\")) {\n destination.add(file);\n }\n }\n }\n\n const warnings = this.options.validate(entry, {\n document: [...document].sort(),\n isolated: [...isolated].sort(),\n });\n\n for (const message of warnings ?? []) {\n compilation.warnings.push(new Error(message));\n }\n }\n\n if (\n chunk &&\n chunk.name !== undefined &&\n this.options.test(chunk.name) &&\n hasAsyncCss(entrypoint.getEntrypointChunk()) &&\n !patched.has(chunk)\n ) {\n throw new Error(`CSS loading runtime for isolated entrypoint \"${chunk.name}\" was not replaced`);\n }\n }\n });\n });\n }\n}\n"],"mappings":"AAAA,SAAoE,gBAAgB,qBAAoB;AAExG,SAAQ,oBAAoB,0BAA0B,4BAA2B;AAEjF,SAAQ,wBAAuB;AAE/B,SAAQ,+BAA+B,mCAAkC;AACzE,SAAQ,gBAAgB,6BAA4B;AACpD,SAAQ,wBAAwB,gCAA+B;AAE/D,MAAM,aAAa;AACnB,MAAM,8BAA8B;AACpC,MAAM,qBAAqB;AAC3B,MAAM,wBAAwB;AAiB9B,MAAM,oCAAoC,cAAc;AAAA,EAC7C,YACc,OACA,UACA,SACA,aACA,kBACjB,UACF;AACE,UAAM,mBAAmB,KAAK,IAAI,cAAc,YAAY;AAP3C;AACA;AACA;AACA;AACA;AAIjB,SAAK,gBAAgB;AACrB,SAAK,WAAW;AAAA,EACpB;AAAA,EAVqB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAQd,WAAmB;AACtB,UAAM,cAAc,KAAK;AAEzB,QAAI,CAAC,aAAa;AACd,YAAM,IAAI,MAAM,0DAA0D;AAAA,IAC9E;AAEA,UAAM,gBAAgB,mBAAmB,aAAa,KAAK,OAAO,KAAK,aAAa,KAAK,gBAAgB,EAAE;AAAA,MACvG,CAAC,EAAC,OAAO,SAAQ,MAAM,qBAAqB,aAAa,OA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names":["chunk"]}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import type { Chunk, Compilation } from "@rspack/core";
|
|
2
|
+
/** Only call for chunks reachable by an entry with isolated delivery. Other entries may mix CSS categories. */
|
|
2
3
|
export declare const isIsolatedStylesChunk: (compilation: Compilation, chunk: Chunk) => boolean;
|
|
3
|
-
export declare const
|
|
4
|
+
export declare const getStylesFiles: (compilation: Compilation, chunks: Iterable<Chunk>) => {
|
|
5
|
+
document: ReadonlySet<string>;
|
|
6
|
+
defaults: ReadonlySet<string>;
|
|
7
|
+
};
|
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { DocumentStylesLayer } from "./../../../../cli/bundler/layers.js";
|
|
2
|
+
import { DocumentStylesCacheGroup } from "./split-chunks.js";
|
|
3
|
+
const isDocumentStylesModule = (module) => module.layer === DocumentStylesLayer;
|
|
3
4
|
const isIsolatedStylesChunk = (compilation, chunk) => {
|
|
4
5
|
const modules = [...compilation.chunkGraph.getChunkModulesIterable(chunk)].filter(
|
|
5
6
|
(module) => module.type === "css/mini-extract"
|
|
6
7
|
);
|
|
7
|
-
const
|
|
8
|
-
if (
|
|
8
|
+
const document = modules.some(isDocumentStylesModule);
|
|
9
|
+
if (document && !modules.every(isDocumentStylesModule)) {
|
|
9
10
|
throw new Error(
|
|
10
|
-
`CSS chunk "${chunk.name ?? chunk.id}" mixes document and
|
|
11
|
+
`CSS chunk "${chunk.name ?? chunk.id}" mixes document and default styles for isolated delivery. Preserve the ${DocumentStylesCacheGroup} CSS cache group in your bundler configuration.`
|
|
11
12
|
);
|
|
12
13
|
}
|
|
13
|
-
return
|
|
14
|
+
return modules.length > 0 && !document;
|
|
14
15
|
};
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
const getStylesFiles = (compilation, chunks) => {
|
|
17
|
+
const document = /* @__PURE__ */ new Set();
|
|
18
|
+
const defaults = /* @__PURE__ */ new Set();
|
|
19
|
+
for (const chunk of chunks) {
|
|
20
|
+
const files = isIsolatedStylesChunk(compilation, chunk) ? defaults : document;
|
|
21
|
+
for (const file of chunk.files) {
|
|
22
|
+
if (file.endsWith(".css")) {
|
|
23
|
+
files.add(file);
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
|
-
return
|
|
27
|
+
return { document, defaults };
|
|
27
28
|
};
|
|
28
29
|
export {
|
|
29
|
-
|
|
30
|
+
getStylesFiles,
|
|
30
31
|
isIsolatedStylesChunk
|
|
31
32
|
};
|
|
32
33
|
//# sourceMappingURL=chunks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/cli/bundler/plugins/isolated-styles/chunks.ts"],"sourcesContent":["import type {Chunk, Compilation, Module} from \"@rspack/core\";\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/cli/bundler/plugins/isolated-styles/chunks.ts"],"sourcesContent":["import type {Chunk, Compilation, Module} from \"@rspack/core\";\n\nimport {DocumentStylesLayer} from \"@cli/bundler/layers\";\nimport {DocumentStylesCacheGroup} from \"./split-chunks\";\n\nconst isDocumentStylesModule = (module: Module): boolean => module.layer === DocumentStylesLayer;\n\n/** Only call for chunks reachable by an entry with isolated delivery. Other entries may mix CSS categories. */\nexport const isIsolatedStylesChunk = (compilation: Compilation, chunk: Chunk): boolean => {\n const modules = [...compilation.chunkGraph.getChunkModulesIterable(chunk)].filter(\n module => module.type === \"css/mini-extract\"\n );\n\n const document = modules.some(isDocumentStylesModule);\n\n if (document && !modules.every(isDocumentStylesModule)) {\n throw new Error(\n `CSS chunk \"${chunk.name ?? chunk.id}\" mixes document and default styles for isolated delivery. Preserve the ${DocumentStylesCacheGroup} CSS cache group in your bundler configuration.`\n );\n }\n\n return modules.length > 0 && !document;\n};\n\nexport const getStylesFiles = (\n compilation: Compilation,\n chunks: Iterable<Chunk>\n): {document: ReadonlySet<string>; defaults: ReadonlySet<string>} => {\n const document = new Set<string>();\n const defaults = new Set<string>();\n\n for (const chunk of chunks) {\n const files = isIsolatedStylesChunk(compilation, chunk) ? defaults : document;\n\n for (const file of chunk.files) {\n if (file.endsWith(\".css\")) {\n files.add(file);\n }\n }\n }\n\n return {document, defaults};\n};\n"],"mappings":"AAEA,SAAQ,2BAA0B;AAClC,SAAQ,gCAA+B;AAEvC,MAAM,yBAAyB,CAAC,WAA4B,OAAO,UAAU;AAGtE,MAAM,wBAAwB,CAAC,aAA0B,UAA0B;AACtF,QAAM,UAAU,CAAC,GAAG,YAAY,WAAW,wBAAwB,KAAK,CAAC,EAAE;AAAA,IACvE,YAAU,OAAO,SAAS;AAAA,EAC9B;AAEA,QAAM,WAAW,QAAQ,KAAK,sBAAsB;AAEpD,MAAI,YAAY,CAAC,QAAQ,MAAM,sBAAsB,GAAG;AACpD,UAAM,IAAI;AAAA,MACN,cAAc,MAAM,QAAQ,MAAM,EAAE,2EAA2E,wBAAwB;AAAA,IAC3I;AAAA,EACJ;AAEA,SAAO,QAAQ,SAAS,KAAK,CAAC;AAClC;AAEO,MAAM,iBAAiB,CAC1B,aACA,WACiE;AACjE,QAAM,WAAW,oBAAI,IAAY;AACjC,QAAM,WAAW,oBAAI,IAAY;AAEjC,aAAW,SAAS,QAAQ;AACxB,UAAM,QAAQ,sBAAsB,aAAa,KAAK,IAAI,WAAW;AAErE,eAAW,QAAQ,MAAM,OAAO;AAC5B,UAAI,KAAK,SAAS,MAAM,GAAG;AACvB,cAAM,IAAI,IAAI;AAAA,MAClB;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO,EAAC,UAAU,SAAQ;AAC9B;","names":[]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Compiler, OptimizationSplitChunksCacheGroup } from "@rspack/core";
|
|
2
|
+
export declare const DocumentStylesCacheGroup = "adnbnDocumentStyles";
|
|
3
|
+
/** Partition CSS only where an entry needs separate document and isolated delivery. */
|
|
4
|
+
export declare const createStylesCacheGroup: (compiler: Compiler, test: (entry: string) => boolean) => OptimizationSplitChunksCacheGroup;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { DocumentStylesLayer } from "./../../../../cli/bundler/layers.js";
|
|
2
|
+
const DocumentStylesCacheGroup = "adnbnDocumentStyles";
|
|
3
|
+
const createStylesCacheGroup = (compiler, test) => {
|
|
4
|
+
let compilation;
|
|
5
|
+
let selectedGroups = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
compiler.hooks.thisCompilation.tap("IsolatedStylesPlugin", (current) => {
|
|
7
|
+
compilation = current;
|
|
8
|
+
selectedGroups = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
});
|
|
10
|
+
const selected = (group) => {
|
|
11
|
+
const cached = selectedGroups.get(group);
|
|
12
|
+
if (cached !== void 0) {
|
|
13
|
+
return cached;
|
|
14
|
+
}
|
|
15
|
+
const pending = [group];
|
|
16
|
+
const visited = /* @__PURE__ */ new Set();
|
|
17
|
+
while (pending.length) {
|
|
18
|
+
const parent = pending.pop();
|
|
19
|
+
if (visited.has(parent)) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
visited.add(parent);
|
|
23
|
+
if (parent.isInitial() && parent.name !== void 0 && test(parent.name)) {
|
|
24
|
+
selectedGroups.set(group, true);
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
pending.push(...parent.getParents());
|
|
28
|
+
}
|
|
29
|
+
selectedGroups.set(group, false);
|
|
30
|
+
return false;
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
type: "css/mini-extract",
|
|
34
|
+
layer: DocumentStylesLayer,
|
|
35
|
+
chunks: (chunk) => {
|
|
36
|
+
const modules = compilation.chunkGraph.getChunkModulesIterable(chunk);
|
|
37
|
+
if (![...modules].some((module) => module.type === "css/mini-extract")) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return [...chunk.groupsIterable].some(selected);
|
|
41
|
+
},
|
|
42
|
+
enforce: true,
|
|
43
|
+
name: false,
|
|
44
|
+
priority: 100
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export {
|
|
48
|
+
DocumentStylesCacheGroup,
|
|
49
|
+
createStylesCacheGroup
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=split-chunks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/cli/bundler/plugins/isolated-styles/split-chunks.ts"],"sourcesContent":["import type {Chunk, ChunkGroup, Compilation, Compiler, OptimizationSplitChunksCacheGroup} from \"@rspack/core\";\n\nimport {DocumentStylesLayer} from \"@cli/bundler/layers\";\n\nexport const DocumentStylesCacheGroup = \"adnbnDocumentStyles\";\n\n/** Partition CSS only where an entry needs separate document and isolated delivery. */\nexport const createStylesCacheGroup = (\n compiler: Compiler,\n test: (entry: string) => boolean\n): OptimizationSplitChunksCacheGroup => {\n let compilation: Compilation;\n let selectedGroups = new WeakMap<ChunkGroup, boolean>();\n\n compiler.hooks.thisCompilation.tap(\"IsolatedStylesPlugin\", current => {\n compilation = current;\n selectedGroups = new WeakMap();\n });\n\n const selected = (group: ChunkGroup): boolean => {\n const cached = selectedGroups.get(group);\n\n if (cached !== undefined) {\n return cached;\n }\n\n const pending = [group];\n const visited = new Set<ChunkGroup>();\n\n while (pending.length) {\n const parent = pending.pop()!;\n\n if (visited.has(parent)) {\n continue;\n }\n\n visited.add(parent);\n\n if (parent.isInitial() && parent.name !== undefined && test(parent.name)) {\n selectedGroups.set(group, true);\n\n return true;\n }\n\n pending.push(...parent.getParents());\n }\n\n selectedGroups.set(group, false);\n\n return false;\n };\n\n return {\n type: \"css/mini-extract\",\n layer: DocumentStylesLayer,\n chunks: (chunk: Chunk): boolean => {\n const modules = compilation.chunkGraph.getChunkModulesIterable(chunk);\n\n if (![...modules].some(module => module.type === \"css/mini-extract\")) {\n return false;\n }\n\n return [...chunk.groupsIterable].some(selected);\n },\n enforce: true,\n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root, url, retry) {
|
|
|
25
25
|
|
|
26
26
|
if (existing) return existing.promise;
|
|
27
27
|
|
|
28
|
+
rootState.order.add(url);
|
|
29
|
+
|
|
28
30
|
var resolveStyle;
|
|
29
31
|
var rejectStyle;
|
|
30
32
|
var promise = new Promise(function (resolve, reject) {
|
|
@@ -52,6 +54,7 @@ var attachStyle = function (root, url, retry) {
|
|
|
52
54
|
if (error) {
|
|
53
55
|
rootState.styles.delete(url);
|
|
54
56
|
record.link.remove();
|
|
57
|
+
console.error(error);
|
|
55
58
|
rejectStyle(error);
|
|
56
59
|
} else {
|
|
57
60
|
resolveStyle();
|
|
@@ -78,8 +81,26 @@ var attachStyle = function (root, url, retry) {
|
|
|
78
81
|
settle(createStyleError(url, type));
|
|
79
82
|
}
|
|
80
83
|
};
|
|
81
|
-
//
|
|
82
|
-
|
|
84
|
+
// A failed link may be retried after later styles succeeded. Preserve its original position.
|
|
85
|
+
var next = previous || rootState.target;
|
|
86
|
+
var after = false;
|
|
87
|
+
|
|
88
|
+
if (!previous) {
|
|
89
|
+
for (var file of rootState.order) {
|
|
90
|
+
if (file === url) {
|
|
91
|
+
after = true;
|
|
92
|
+
} else if (after) {
|
|
93
|
+
var following = rootState.styles.get(file);
|
|
94
|
+
|
|
95
|
+
if (following && following.link) {
|
|
96
|
+
next = following.link;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
root.insertBefore(link, next);
|
|
83
104
|
if (previous) previous.remove();
|
|
84
105
|
};
|
|
85
106
|
// One budget for both attempts, never another timer for the retry.
|
|
@@ -101,14 +122,23 @@ __ADNBN_REQUIRE__[__ADNBN_PROPERTY__] = {
|
|
|
101
122
|
if (!isolatedInitialStyles)
|
|
102
123
|
throw new Error('Isolated stylesheet URLs for entrypoint "' + isolatedStyleEntry + '" are not initialized');
|
|
103
124
|
|
|
104
|
-
isolatedStyleRoots.set(root, {target: target, styles: new Map()});
|
|
125
|
+
isolatedStyleRoots.set(root, {target: target, styles: new Map(), order: new Set()});
|
|
105
126
|
|
|
106
127
|
isolatedInitialStyles.concat(Array.from(isolatedRequestedStyles)).forEach(function (url) {
|
|
107
|
-
attachStyle(root, url, retry).catch(function (
|
|
108
|
-
console.error(error);
|
|
109
|
-
});
|
|
128
|
+
attachStyle(root, url, retry).catch(function () {});
|
|
110
129
|
});
|
|
111
130
|
},
|
|
131
|
+
ready: function (root) {
|
|
132
|
+
if (!isolatedStyleRoots.has(root)) {
|
|
133
|
+
return Promise.resolve();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return Promise.all(
|
|
137
|
+
isolatedInitialStyles.concat(Array.from(isolatedRequestedStyles)).map(function (url) {
|
|
138
|
+
return attachStyle(root, url);
|
|
139
|
+
})
|
|
140
|
+
).then(function () {});
|
|
141
|
+
},
|
|
112
142
|
delete: function (root) {
|
|
113
143
|
var rootState = isolatedStyleRoots.get(root);
|
|
114
144
|
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import type { ResourceAccessPluginRequirement } from "../../bundler/plugins/resource-access/index.js";
|
|
2
|
-
import type { IsolatedStylesPluginFiles } from "../../bundler/plugins/isolated-styles/index.js";
|
|
3
2
|
import { ContentScriptWorld, type ContentScriptEntrypointOptions } from "../../../types/content/index.js";
|
|
4
|
-
/** Reject unavailable destinations and warn about likely missing query flags without changing CSS routing. */
|
|
5
|
-
export declare const validateContentStyles: (entry: string, options: ContentScriptEntrypointOptions | undefined, files: IsolatedStylesPluginFiles) => readonly string[];
|
|
6
3
|
export declare const createPageAccessRequirements: (entries: ReadonlyMap<string, ContentScriptEntrypointOptions>, pages: ReadonlyMap<string, string>) => ResourceAccessPluginRequirement[];
|
|
7
4
|
export declare const getContentChunkName: (world: ContentScriptWorld) => string;
|
|
@@ -1,28 +1,13 @@
|
|
|
1
|
-
import { isContentScriptFrameNavigation } from "./../../../shared/content/index.js";
|
|
2
|
-
import { hasIsolatedTarget } from "./utils.js";
|
|
3
1
|
import { ContentScriptMatches, ContentScriptWorld } from "./../../../types/content/index.js";
|
|
4
2
|
import { EntrypointType } from "./../../../types/entrypoint.js";
|
|
5
|
-
const validateContentStyles = (entry, options, files) => {
|
|
6
|
-
var _a;
|
|
7
|
-
if (!options) return [];
|
|
8
|
-
if (files.isolated.length > 0 && isContentScriptFrameNavigation(options.isolation)) {
|
|
9
|
-
throw new Error(
|
|
10
|
-
`Entrypoint "${entry}" uses ?isolation CSS with isolation.page/isolation.src, but has no local render target. Import these styles in the embedded page instead.`
|
|
11
|
-
);
|
|
12
|
-
}
|
|
13
|
-
if (hasIsolatedTarget(options) && files.document.length > 0 && files.isolated.length === 0) {
|
|
14
|
-
return [
|
|
15
|
-
`[adnbn:missing-isolation-css] Entrypoint "${entry}" uses isolation: "${(_a = options.isolation) == null ? void 0 : _a.type}", but has no CSS marked with ?isolation. Imported CSS will be delivered to the page document. If these styles belong to the isolated UI, import them with ?isolation. Document-only styles are valid; this warning can be suppressed with bundler ignoreWarnings.`
|
|
16
|
-
];
|
|
17
|
-
}
|
|
18
|
-
return [];
|
|
19
|
-
};
|
|
20
3
|
const createPageAccessRequirements = (entries, pages) => {
|
|
21
4
|
var _a;
|
|
22
5
|
const requirements = [];
|
|
23
6
|
for (const [entry, options] of entries) {
|
|
24
7
|
const alias = (_a = options.isolation) == null ? void 0 : _a.page;
|
|
25
|
-
if (alias === void 0)
|
|
8
|
+
if (alias === void 0) {
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
26
11
|
const resource = pages.get(alias);
|
|
27
12
|
if (!resource) {
|
|
28
13
|
throw new Error(`Content entrypoint "${entry}" references unknown page "${alias}"`);
|
|
@@ -41,7 +26,6 @@ const getContentChunkName = (world) => {
|
|
|
41
26
|
};
|
|
42
27
|
export {
|
|
43
28
|
createPageAccessRequirements,
|
|
44
|
-
getContentChunkName
|
|
45
|
-
validateContentStyles
|
|
29
|
+
getContentChunkName
|
|
46
30
|
};
|
|
47
31
|
//# sourceMappingURL=bundler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/cli/plugins/content/bundler.ts"],"sourcesContent":["import type {ResourceAccessPluginRequirement} from \"@cli/bundler/plugins/resource-access\";\
|
|
1
|
+
{"version":3,"sources":["../../../../src/cli/plugins/content/bundler.ts"],"sourcesContent":["import type {ResourceAccessPluginRequirement} from \"@cli/bundler/plugins/resource-access\";\n\nimport {ContentScriptMatches, ContentScriptWorld, type ContentScriptEntrypointOptions} from \"@typing/content\";\nimport {EntrypointType} from \"@typing/entrypoint\";\n\nexport const createPageAccessRequirements = (\n entries: ReadonlyMap<string, ContentScriptEntrypointOptions>,\n pages: ReadonlyMap<string, string>\n): ResourceAccessPluginRequirement[] => {\n const requirements: ResourceAccessPluginRequirement[] = [];\n\n for (const [entry, options] of entries) {\n const alias = options.isolation?.page;\n\n if (alias === undefined) {\n continue;\n }\n\n const resource = pages.get(alias);\n\n if (!resource) {\n throw new Error(`Content entrypoint \"${entry}\" references unknown page \"${alias}\"`);\n }\n\n requirements.push({\n resource,\n matches: options.matches ?? ContentScriptMatches,\n issuer: `Content entrypoint \"${entry}\" embedding page \"${alias}\"`,\n hint: \"add matches to the page or narrow the content matches\",\n });\n }\n\n return requirements;\n};\n\nexport const getContentChunkName = (world: ContentScriptWorld): string => {\n return `${world === ContentScriptWorld.Main ? \"common-main\" : \"common\"}.${EntrypointType.ContentScript}`;\n};\n"],"mappings":"AAEA,SAAQ,sBAAsB,0BAA8D;AAC5F,SAAQ,sBAAqB;AAEtB,MAAM,+BAA+B,CACxC,SACA,UACoC;AARxC;AASI,QAAM,eAAkD,CAAC;AAEzD,aAAW,CAAC,OAAO,OAAO,KAAK,SAAS;AACpC,UAAM,SAAQ,aAAQ,cAAR,mBAAmB;AAEjC,QAAI,UAAU,QAAW;AACrB;AAAA,IACJ;AAEA,UAAM,WAAW,MAAM,IAAI,KAAK;AAEhC,QAAI,CAAC,UAAU;AACX,YAAM,IAAI,MAAM,uBAAuB,KAAK,8BAA8B,KAAK,GAAG;AAAA,IACtF;AAEA,iBAAa,KAAK;AAAA,MACd;AAAA,MACA,SAAS,QAAQ,WAAW;AAAA,MAC5B,QAAQ,uBAAuB,KAAK,qBAAqB,KAAK;AAAA,MAC9D,MAAM;AAAA,IACV,CAAC;AAAA,EACL;AAEA,SAAO;AACX;AAEO,MAAM,sBAAsB,CAAC,UAAsC;AACtE,SAAO,GAAG,UAAU,mBAAmB,OAAO,gBAAgB,QAAQ,IAAI,eAAe,aAAa;AAC1G;","names":[]}
|
|
@@ -3,7 +3,7 @@ import Content from "./Content.js";
|
|
|
3
3
|
import Relay from "./Relay.js";
|
|
4
4
|
import RelayDeclaration from "./RelayDeclaration.js";
|
|
5
5
|
import { hasIsolatedTarget } from "./utils.js";
|
|
6
|
-
import { createPageAccessRequirements, getContentChunkName
|
|
6
|
+
import { createPageAccessRequirements, getContentChunkName } from "./bundler.js";
|
|
7
7
|
import { createRelayModule, RelayModuleName } from "./relay-module.js";
|
|
8
8
|
import { definePlugin } from "./../../../main/plugin.js";
|
|
9
9
|
import { PageFinder } from "./../../../cli/entrypoint/index.js";
|
|
@@ -124,8 +124,7 @@ var content_default = definePlugin(() => {
|
|
|
124
124
|
test: (entry) => {
|
|
125
125
|
const options = entryOptionsByName.get(entry);
|
|
126
126
|
return options !== void 0 && hasIsolatedTarget(options);
|
|
127
|
-
}
|
|
128
|
-
validate: (entry, files) => validateContentStyles(entry, entryOptionsByName.get(entry), files)
|
|
127
|
+
}
|
|
129
128
|
}),
|
|
130
129
|
...basePlugins
|
|
131
130
|
],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/cli/plugins/content/index.ts"],"sourcesContent":["import type {Chunk, Configuration as RspackConfig, NormalModule, Plugins} from \"@rspack/core\";\n\nimport ContentManager from \"./ContentManager\";\nimport Content from \"./Content\";\nimport Relay from \"./Relay\";\nimport RelayDeclaration from \"./RelayDeclaration\";\nimport {hasIsolatedTarget} from \"./utils\";\nimport {createPageAccessRequirements, getContentChunkName, validateContentStyles} from \"./bundler\";\nimport {createRelayModule, RelayModuleName} from \"./relay-module\";\n\nimport {definePlugin} from \"@main/plugin\";\nimport {PageFinder} from \"@cli/entrypoint/index.js\";\nimport {getContentLayer} from \"@cli/bundler/layers\";\n\nimport {\n appFilenameResolver,\n ChunkLoaderPlugin,\n EntrypointPlugin,\n onlyViaTopLevelEntry,\n IsolatedStylesPlugin,\n ResourceAccessPlugin,\n GenerateModulePlugin,\n} from \"@cli/bundler\";\n\nimport {Command} from \"@typing/app\";\nimport {ContentScriptStylesRuntimeProperty, ContentScriptWorld} from \"@typing/content\";\n\nexport default definePlugin(() => {\n let contentProvider: Content;\n let relayProvider: Relay;\n let contentManager: ContentManager;\n let relayDeclaration: RelayDeclaration;\n\n return {\n name: \"adnbn:content\",\n startup: ({config}) => {\n contentProvider = new Content(config);\n relayProvider = new Relay(config);\n\n // prettier-ignore\n contentManager = new ContentManager(config)\n .provider(contentProvider)\n .provider(relayProvider);\n\n relayDeclaration = new RelayDeclaration(config);\n },\n content: () => contentProvider.files(),\n relay: () => relayProvider.files(),\n bundler: async ({config}) => {\n relayDeclaration.dictionary(await relayProvider.dictionary()).build();\n\n let entryOptionsByName = await contentManager.entryOptions();\n\n const getModules = async () => ({\n [RelayModuleName]: createRelayModule(await relayProvider.getOptionsMap()),\n });\n const modulePlugin = new GenerateModulePlugin(await getModules());\n\n if (config.command === Command.Watch) {\n modulePlugin.watch(getModules);\n }\n\n const basePlugins: Plugins = [\n modulePlugin,\n new ResourceAccessPlugin({\n requirements: async () => {\n if (\n !Array.from(entryOptionsByName.values()).some(\n options => options.isolation?.page !== undefined\n )\n ) {\n return [];\n }\n\n const views = await new PageFinder(config).views();\n const pages = new Map(Array.from(views.values(), view => [view.alias, view.filename]));\n return createPageAccessRequirements(entryOptionsByName, pages);\n },\n }),\n ];\n\n if (await contentManager.empty()) {\n if (config.debug) {\n console.warn(\"Content script or relay entries not found\");\n }\n\n return {plugins: basePlugins};\n }\n\n const entries = await contentManager.entries();\n const getEntryWorld = (name: string): ContentScriptWorld => {\n const options = entryOptionsByName.get(name);\n\n if (!options) {\n throw new Error(`Execution world for content entrypoint \"${name}\" is unavailable`);\n }\n\n return options.world === ContentScriptWorld.Main\n ? ContentScriptWorld.Main\n : ContentScriptWorld.Isolated;\n };\n\n // prettier-ignore\n const entrypointPlugin = EntrypointPlugin.from(entries)\n .virtual(file => contentManager.virtual(file))\n .entryOptions(name => {\n const world = getEntryWorld(name);\n\n return {\n // MAIN cannot resolve an installed extension URL without crossing contexts.\n // ISOLATED keeps physical async chunks and resolves them through the extension API.\n asyncChunks: world === ContentScriptWorld.Isolated,\n layer: getContentLayer(world),\n publicPath: \"\",\n };\n });\n\n if (config.command === Command.Watch) {\n entrypointPlugin.watch(async () => {\n contentManager.clear();\n\n relayDeclaration.dictionary(await relayProvider.dictionary()).build();\n\n const entries = await contentManager.entries();\n entryOptionsByName = await contentManager.entryOptions();\n\n return entries;\n });\n }\n\n const isContentModule = onlyViaTopLevelEntry([\"content\", \"relay\"]);\n\n const createCacheGroup = (world: ContentScriptWorld) => ({\n minChunks: 2,\n name: getContentChunkName(world),\n test: (\n module: Parameters<typeof isContentModule>[0],\n context: Parameters<typeof isContentModule>[1]\n ) => {\n const normalModule = module as NormalModule;\n\n if (!normalModule.resource) {\n return false;\n }\n\n return isContentModule(module, context);\n },\n chunks: (chunk: Chunk): boolean =>\n chunk.name !== undefined &&\n entryOptionsByName.has(chunk.name) &&\n getEntryWorld(chunk.name) === world,\n enforce: false,\n reuseExistingChunk: false,\n priority: 20,\n });\n\n return {\n plugins: [\n entrypointPlugin,\n new ChunkLoaderPlugin({\n test: entry =>\n entryOptionsByName.has(entry) && getEntryWorld(entry) === ContentScriptWorld.Isolated,\n }),\n new IsolatedStylesPlugin({\n cssFilename: appFilenameResolver(config.app, config.cssFilename, config.cssDir),\n cssChunkFilename: appFilenameResolver(config.app, config.cssFilename, config.cssDir),\n property: ContentScriptStylesRuntimeProperty,\n test: entry => {\n const options = entryOptionsByName.get(entry);\n return options !== undefined && hasIsolatedTarget(options);\n },\n validate: (entry, files) => validateContentStyles(entry, entryOptionsByName.get(entry), files),\n }),\n ...basePlugins,\n ],\n optimization: config.commonChunks\n ? {\n splitChunks: {\n cacheGroups: {\n adnbnContentIsolated: createCacheGroup(ContentScriptWorld.Isolated),\n adnbnContentMain: createCacheGroup(ContentScriptWorld.Main),\n },\n },\n }\n : undefined,\n } satisfies RspackConfig;\n },\n manifest: async ({manifest}) => {\n // prettier-ignore\n manifest\n .setContentScripts(await contentManager.manifest())\n .appendHostPermissions(await contentManager.hostPermissions())\n .appendOptionalHostPermissions(await contentManager.optionalHostPermissions())\n .appendPermissions(await contentManager.permissions())\n .appendOptionalPermissions(await contentManager.optionalPermissions());\n },\n };\n});\n"],"mappings":"AAEA,OAAO,oBAAoB;AAC3B,OAAO,aAAa;AACpB,OAAO,WAAW;AAClB,OAAO,sBAAsB;AAC7B,SAAQ,yBAAwB;AAChC,SAAQ,8BAA8B,qBAAqB,6BAA4B;AACvF,SAAQ,mBAAmB,uBAAsB;AAEjD,SAAQ,oBAAmB;AAC3B,SAAQ,kBAAiB;AACzB,SAAQ,uBAAsB;AAE9B;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,SAAQ,eAAc;AACtB,SAAQ,oCAAoC,0BAAyB;AAErE,IAAO,kBAAQ,aAAa,MAAM;AAC9B,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI;AAEJ,SAAO;AAAA,IACH,MAAM;AAAA,IACN,SAAS,CAAC,EAAC,OAAM,MAAM;AACnB,wBAAkB,IAAI,QAAQ,MAAM;AACpC,sBAAgB,IAAI,MAAM,MAAM;AAGhC,uBAAiB,IAAI,eAAe,MAAM,EACrC,SAAS,eAAe,EACxB,SAAS,aAAa;AAE3B,yBAAmB,IAAI,iBAAiB,MAAM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AI,KAAK,KAAK,cAAc,KAAK,MAAM,mBAAmB;AAAA,UACrF,CAAC;AAAA,UACD,IAAI,qBAAqB;AAAA,YACrB,aAAa,oBAAoB,OAAO,KAAK,OAAO,aAAa,OAAO,MAAM;AAAA,YAC9E,kBAAkB,oBAAoB,OAAO,KAAK,OAAO,aAAa,OAAO,MAAM;AAAA,YACnF,UAAU;AAAA,YACV,MAAM,WAAS;AACX,oBAAM,UAAU,mBAAmB,IAAI,KAAK;AAC5C,qBAAO,YAAY,UAAa,kBAAkB,OAAO;AAAA,YAC7D;AAAA,YACA,UAAU,CAAC,OAAO,UAAU,sBAAsB,OAAO,mBAAmB,IAAI,KAAK,GAAG,KAAK;AAAA,UACjG,CAAC;AAAA,UACD,GAAG;AAAA,QACP;AAAA,QACA,cAAc,OAAO,eACf;AAAA,UACI,aAAa;AAAA,YACT,aAAa;AAAA,cACT,sBAAsB,iBAAiB,mBAAmB,QAAQ;AAAA,cAClE,kBAAkB,iBAAiB,mBAAmB,IAAI;AAAA,YAC9D;AAAA,UACJ;AAAA,QACJ,IACA;AAAA,MACV;AAAA,IACJ;AAAA,IACA,UAAU,OAAO,EAAC,SAAQ,MAAM;AAE5B,eACK,kBAAkB,MAAM,eAAe,SAAS,CAAC,EACjD,sBAAsB,MAAM,eAAe,gBAAgB,CAAC,EAC5D,8BAA8B,MAAM,eAAe,wBAAwB,CAAC,EAC5E,kBAAkB,MAAM,eAAe,YAAY,CAAC,EACpD,0BAA0B,MAAM,eAAe,oBAAoB,CAAC;AAAA,IAC7E;AAAA,EACJ;AACJ,CAAC;","names":["entries"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/cli/plugins/content/index.ts"],"sourcesContent":["import type {Chunk, Configuration as RspackConfig, NormalModule, Plugins} from \"@rspack/core\";\n\nimport ContentManager from \"./ContentManager\";\nimport Content from \"./Content\";\nimport Relay from \"./Relay\";\nimport RelayDeclaration from \"./RelayDeclaration\";\nimport {hasIsolatedTarget} from \"./utils\";\nimport {createPageAccessRequirements, getContentChunkName} from \"./bundler\";\nimport {createRelayModule, RelayModuleName} from \"./relay-module\";\n\nimport {definePlugin} from \"@main/plugin\";\nimport {PageFinder} from \"@cli/entrypoint/index.js\";\nimport {getContentLayer} from \"@cli/bundler/layers\";\n\nimport {\n appFilenameResolver,\n ChunkLoaderPlugin,\n EntrypointPlugin,\n onlyViaTopLevelEntry,\n IsolatedStylesPlugin,\n ResourceAccessPlugin,\n GenerateModulePlugin,\n} from \"@cli/bundler\";\n\nimport {Command} from \"@typing/app\";\nimport {ContentScriptStylesRuntimeProperty, ContentScriptWorld} from \"@typing/content\";\n\nexport default definePlugin(() => {\n let contentProvider: Content;\n let relayProvider: Relay;\n let contentManager: ContentManager;\n let relayDeclaration: RelayDeclaration;\n\n return {\n name: \"adnbn:content\",\n startup: ({config}) => {\n contentProvider = new Content(config);\n relayProvider = new Relay(config);\n\n // prettier-ignore\n contentManager = new ContentManager(config)\n .provider(contentProvider)\n .provider(relayProvider);\n\n relayDeclaration = new RelayDeclaration(config);\n },\n content: () => contentProvider.files(),\n relay: () => relayProvider.files(),\n bundler: async ({config}) => {\n relayDeclaration.dictionary(await relayProvider.dictionary()).build();\n\n let entryOptionsByName = await contentManager.entryOptions();\n\n const getModules = async () => ({\n [RelayModuleName]: createRelayModule(await relayProvider.getOptionsMap()),\n });\n\n const modulePlugin = new GenerateModulePlugin(await getModules());\n\n if (config.command === Command.Watch) {\n modulePlugin.watch(getModules);\n }\n\n const basePlugins: Plugins = [\n modulePlugin,\n new ResourceAccessPlugin({\n requirements: async () => {\n if (\n !Array.from(entryOptionsByName.values()).some(\n options => options.isolation?.page !== undefined\n )\n ) {\n return [];\n }\n\n const views = await new PageFinder(config).views();\n const pages = new Map(Array.from(views.values(), view => [view.alias, view.filename]));\n\n return createPageAccessRequirements(entryOptionsByName, pages);\n },\n }),\n ];\n\n if (await contentManager.empty()) {\n if (config.debug) {\n console.warn(\"Content script or relay entries not found\");\n }\n\n return {plugins: basePlugins};\n }\n\n const entries = await contentManager.entries();\n\n const getEntryWorld = (name: string): ContentScriptWorld => {\n const options = entryOptionsByName.get(name);\n\n if (!options) {\n throw new Error(`Execution world for content entrypoint \"${name}\" is unavailable`);\n }\n\n return options.world === ContentScriptWorld.Main\n ? ContentScriptWorld.Main\n : ContentScriptWorld.Isolated;\n };\n\n // prettier-ignore\n const entrypointPlugin = EntrypointPlugin.from(entries)\n .virtual(file => contentManager.virtual(file))\n .entryOptions(name => {\n const world = getEntryWorld(name);\n\n return {\n // MAIN cannot resolve an installed extension URL without crossing contexts.\n // ISOLATED keeps physical async chunks and resolves them through the extension API.\n asyncChunks: world === ContentScriptWorld.Isolated,\n layer: getContentLayer(world),\n publicPath: \"\",\n };\n });\n\n if (config.command === Command.Watch) {\n entrypointPlugin.watch(async () => {\n contentManager.clear();\n\n relayDeclaration.dictionary(await relayProvider.dictionary()).build();\n\n const entries = await contentManager.entries();\n entryOptionsByName = await contentManager.entryOptions();\n\n return entries;\n });\n }\n\n const isContentModule = onlyViaTopLevelEntry([\"content\", \"relay\"]);\n\n const createCacheGroup = (world: ContentScriptWorld) => ({\n minChunks: 2,\n name: getContentChunkName(world),\n test: (\n module: Parameters<typeof isContentModule>[0],\n context: Parameters<typeof isContentModule>[1]\n ) => {\n const normalModule = module as NormalModule;\n\n if (!normalModule.resource) {\n return false;\n }\n\n return isContentModule(module, context);\n },\n chunks: (chunk: Chunk): boolean =>\n chunk.name !== undefined &&\n entryOptionsByName.has(chunk.name) &&\n getEntryWorld(chunk.name) === world,\n enforce: false,\n reuseExistingChunk: false,\n priority: 20,\n });\n\n return {\n plugins: [\n entrypointPlugin,\n new ChunkLoaderPlugin({\n test: entry =>\n entryOptionsByName.has(entry) && getEntryWorld(entry) === ContentScriptWorld.Isolated,\n }),\n new IsolatedStylesPlugin({\n cssFilename: appFilenameResolver(config.app, config.cssFilename, config.cssDir),\n cssChunkFilename: appFilenameResolver(config.app, config.cssFilename, config.cssDir),\n property: ContentScriptStylesRuntimeProperty,\n test: entry => {\n const options = entryOptionsByName.get(entry);\n\n return options !== undefined && hasIsolatedTarget(options);\n },\n }),\n ...basePlugins,\n ],\n optimization: config.commonChunks\n ? {\n splitChunks: {\n cacheGroups: {\n adnbnContentIsolated: createCacheGroup(ContentScriptWorld.Isolated),\n adnbnContentMain: createCacheGroup(ContentScriptWorld.Main),\n },\n },\n }\n : undefined,\n } satisfies RspackConfig;\n },\n manifest: async ({manifest}) => {\n // prettier-ignore\n manifest\n .setContentScripts(await contentManager.manifest())\n .appendHostPermissions(await contentManager.hostPermissions())\n .appendOptionalHostPermissions(await contentManager.optionalHostPermissions())\n .appendPermissions(await contentManager.permissions())\n .appendOptionalPermissions(await contentManager.optionalPermissions());\n },\n };\n});\n"],"mappings":"AAEA,OAAO,oBAAoB;AAC3B,OAAO,aAAa;AACpB,OAAO,WAAW;AAClB,OAAO,sBAAsB;AAC7B,SAAQ,yBAAwB;AAChC,SAAQ,8BAA8B,2BAA0B;AAChE,SAAQ,mBAAmB,uBAAsB;AAEjD,SAAQ,oBAAmB;AAC3B,SAAQ,kBAAiB;AACzB,SAAQ,uBAAsB;AAE9B;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,SAAQ,eAAc;AACtB,SAAQ,oCAAoC,0BAAyB;AAErE,IAAO,kBAAQ,aAAa,MAAM;AAC9B,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI;AAEJ,SAAO;AAAA,IACH,MAAM;AAAA,IACN,SAAS,CAAC,EAAC,OAAM,MAAM;AACnB,wBAAkB,IAAI,QAAQ,MAAM;AACpC,sBAAgB,IAAI,MAAM,MAAM;AAGhC,uBAAiB,IAAI,eAAe,MAAM,EACrC,SAAS,eAAe,EACxB,SAAS,aAAa;AAE3B,yBAAmB,IAAI,iBAAiB,MAAM;AAAA,IAClD;AAAA,IACA,SAAS,MAAM,gBAAgB,MAAM;AAAA,IACrC,OAAO,MAA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IAAI,qBAAqB;AAAA,YACrB,aAAa,oBAAoB,OAAO,KAAK,OAAO,aAAa,OAAO,MAAM;AAAA,YAC9E,kBAAkB,oBAAoB,OAAO,KAAK,OAAO,aAAa,OAAO,MAAM;AAAA,YACnF,UAAU;AAAA,YACV,MAAM,WAAS;AACX,oBAAM,UAAU,mBAAmB,IAAI,KAAK;AAE5C,qBAAO,YAAY,UAAa,kBAAkB,OAAO;AAAA,YAC7D;AAAA,UACJ,CAAC;AAAA,UACD,GAAG;AAAA,QACP;AAAA,QACA,cAAc,OAAO,eACf;AAAA,UACI,aAAa;AAAA,YACT,aAAa;AAAA,cACT,sBAAsB,iBAAiB,mBAAmB,QAAQ;AAAA,cAClE,kBAAkB,iBAAiB,mBAAmB,IAAI;AAAA,YAC9D;AAAA,UACJ;AAAA,QACJ,IACA;AAAA,MACV;AAAA,IACJ;AAAA,IACA,UAAU,OAAO,EAAC,SAAQ,MAAM;AAE5B,eACK,kBAAkB,MAAM,eAAe,SAAS,CAAC,EACjD,sBAAsB,MAAM,eAAe,gBAAgB,CAAC,EAC5D,8BAA8B,MAAM,eAAe,wBAAwB,CAAC,EAC5E,kBAAkB,MAAM,eAAe,YAAY,CAAC,EACpD,0BAA0B,MAAM,eAAe,oBAAoB,CAAC;AAAA,IAC7E;AAAA,EACJ;AACJ,CAAC;","names":["entries"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { LocaleFinder } from "./../../../cli/entrypoint/index.js";
|
|
3
3
|
import { getSourcePath, getSharedPath, getAppPath, getAppSourcePath } from "./../../../cli/resolvers/path.js";
|
|
4
|
-
import { flattenLocaleMessages, getLocaleFilename } from "./../../../shared/locale/index.js";
|
|
4
|
+
import { escapeLocaleMessages, flattenLocaleMessages, getLocaleFilename } from "./../../../shared/locale/index.js";
|
|
5
5
|
class Locale extends LocaleFinder {
|
|
6
6
|
_messages;
|
|
7
7
|
async dependencies() {
|
|
@@ -18,7 +18,10 @@ class Locale extends LocaleFinder {
|
|
|
18
18
|
}
|
|
19
19
|
async json() {
|
|
20
20
|
return Object.fromEntries(
|
|
21
|
-
[...await this.messages()].map(([lang, messages]) => [
|
|
21
|
+
[...await this.messages()].map(([lang, messages]) => [
|
|
22
|
+
getLocaleFilename(lang),
|
|
23
|
+
escapeLocaleMessages(messages)
|
|
24
|
+
])
|
|
22
25
|
);
|
|
23
26
|
}
|
|
24
27
|
async catalogue() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/cli/plugins/locale/Locale.ts"],"sourcesContent":["import path from \"path\";\nimport {LocaleFinder} from \"@cli/entrypoint/index.js\";\nimport type {GenerateJsonPluginData, GenerateModulePluginDependencies} from \"@cli/bundler\";\nimport {getSourcePath, getSharedPath, getAppPath, getAppSourcePath} from \"@cli/resolvers/path\";\n\nimport {flattenLocaleMessages, getLocaleFilename} from \"@shared/locale\";\n\nimport type {Language, LocaleCatalogue, LocaleMessages} from \"@typing/locale\";\n\nexport default class Locale extends LocaleFinder {\n private _messages?: Promise<Map<Language, LocaleMessages>>;\n\n public async dependencies(): Promise<GenerateModulePluginDependencies> {\n const files = [...(await this.plugin().files())].map(({file}) => file);\n const directory = this.getDirectory();\n const directories = new Set([\n getSourcePath(this.config, directory),\n getSharedPath(this.config, directory),\n getAppPath(this.config, directory),\n getAppSourcePath(this.config, directory),\n ...files.map(file => path.dirname(file)),\n ]);\n\n return {files, directories};\n }\n\n public async json(): Promise<GenerateJsonPluginData> {\n return Object.fromEntries(\n [...(await this.messages())].map(([lang, messages]) => [getLocaleFilename(lang)
|
|
1
|
+
{"version":3,"sources":["../../../../src/cli/plugins/locale/Locale.ts"],"sourcesContent":["import path from \"path\";\nimport {LocaleFinder} from \"@cli/entrypoint/index.js\";\nimport type {GenerateJsonPluginData, GenerateModulePluginDependencies} from \"@cli/bundler\";\nimport {getSourcePath, getSharedPath, getAppPath, getAppSourcePath} from \"@cli/resolvers/path\";\n\nimport {escapeLocaleMessages, flattenLocaleMessages, getLocaleFilename} from \"@shared/locale\";\n\nimport type {Language, LocaleCatalogue, LocaleMessages} from \"@typing/locale\";\n\nexport default class Locale extends LocaleFinder {\n private _messages?: Promise<Map<Language, LocaleMessages>>;\n\n public async dependencies(): Promise<GenerateModulePluginDependencies> {\n const files = [...(await this.plugin().files())].map(({file}) => file);\n const directory = this.getDirectory();\n const directories = new Set([\n getSourcePath(this.config, directory),\n getSharedPath(this.config, directory),\n getAppPath(this.config, directory),\n getAppSourcePath(this.config, directory),\n ...files.map(file => path.dirname(file)),\n ]);\n\n return {files, directories};\n }\n\n public async json(): Promise<GenerateJsonPluginData> {\n return Object.fromEntries(\n [...(await this.messages())].map(([lang, messages]) => [\n getLocaleFilename(lang),\n escapeLocaleMessages(messages),\n ])\n );\n }\n\n public async catalogue(): Promise<LocaleCatalogue> {\n return Object.fromEntries(\n [...(await this.messages())].map(([lang, messages]) => [lang, flattenLocaleMessages(messages)])\n );\n }\n\n private messages(): Promise<Map<Language, LocaleMessages>> {\n return (this._messages ??= this.createMessages());\n }\n\n private async createMessages(): Promise<Map<Language, LocaleMessages>> {\n await this.validate();\n\n const data = new Map<Language, LocaleMessages>();\n\n const builders = await this.builders();\n const defaultBuilder = this.getValidator().getDefaultBuilder(builders);\n const defaultMessages = defaultBuilder?.build() ?? {};\n\n for (const builder of builders.values()) {\n // Builders already include this app's layers and browser overrides.\n // Every target plural has been validated; only ordinary gaps remain.\n const messages = builder === defaultBuilder ? defaultMessages : builder.build();\n\n data.set(builder.lang(), {...defaultMessages, ...messages});\n }\n\n return data;\n }\n\n public clear(): this {\n this._messages = undefined;\n\n return super.clear();\n }\n}\n"],"mappings":"AAAA,OAAO,UAAU;AACjB,SAAQ,oBAAmB;AAE3B,SAAQ,eAAe,eAAe,YAAY,wBAAuB;AAEzE,SAAQ,sBAAsB,uBAAuB,yBAAwB;AAI7E,MAAO,eAA6B,aAAa;AAAA,EACrC;AAAA,EAER,MAAa,eAA0D;AACnE,UAAM,QAAQ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,QAAQ,MAAM;AAE9E,WAAK,IAAI,QAAQ,KAAK,GAAG,EAAC,GAAG,iBAAiB,GAAG,SAAQ,CAAC;AAAA,IAC9D;AAEA,WAAO;AAAA,EACX;AAAA,EAEO,QAAc;AACjB,SAAK,YAAY;AAEjB,WAAO,MAAM,MAAM;AAAA,EACvB;AACJ;","names":[]}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
declare const _default: import("../../../main/plugin.js").PluginDefinition<[(StylePluginOptions | undefined)?]>;
|
|
1
|
+
declare const _default: import("../../../main/plugin.js").PluginDefinition<[]>;
|
|
3
2
|
export default _default;
|