@ikas/component-cli 1.4.0-beta.15 → 1.4.0-beta.150
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/build-tools.d.ts +11 -0
- package/dist/build-tools.d.ts.map +1 -0
- package/dist/build-tools.js +11 -0
- package/dist/build-tools.js.map +1 -0
- package/dist/commands/add-sections-to-page.d.ts +3 -0
- package/dist/commands/add-sections-to-page.d.ts.map +1 -0
- package/dist/commands/add-sections-to-page.js +39 -0
- package/dist/commands/add-sections-to-page.js.map +1 -0
- package/dist/commands/add.d.ts.map +1 -1
- package/dist/commands/add.js +10 -1
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/build.d.ts.map +1 -1
- package/dist/commands/build.js +5 -165
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/config.d.ts +35 -0
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +831 -116
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/create-design-tokens.d.ts +24 -0
- package/dist/commands/create-design-tokens.d.ts.map +1 -0
- package/dist/commands/create-design-tokens.js +327 -0
- package/dist/commands/create-design-tokens.js.map +1 -0
- package/dist/commands/create-global-variable.d.ts +3 -0
- package/dist/commands/create-global-variable.d.ts.map +1 -0
- package/dist/commands/create-global-variable.js +53 -0
- package/dist/commands/create-global-variable.js.map +1 -0
- package/dist/commands/create-page.d.ts +3 -0
- package/dist/commands/create-page.d.ts.map +1 -0
- package/dist/commands/create-page.js +31 -0
- package/dist/commands/create-page.js.map +1 -0
- package/dist/commands/create.d.ts +4 -0
- package/dist/commands/create.d.ts.map +1 -0
- package/dist/commands/create.js +878 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/delete-theme-globals.d.ts +4 -0
- package/dist/commands/delete-theme-globals.d.ts.map +1 -0
- package/dist/commands/delete-theme-globals.js +48 -0
- package/dist/commands/delete-theme-globals.js.map +1 -0
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +82 -12
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/get-component-props.d.ts +3 -0
- package/dist/commands/get-component-props.d.ts.map +1 -0
- package/dist/commands/get-component-props.js +32 -0
- package/dist/commands/get-component-props.js.map +1 -0
- package/dist/commands/get-page-by-type.d.ts +3 -0
- package/dist/commands/get-page-by-type.d.ts.map +1 -0
- package/dist/commands/get-page-by-type.js +25 -0
- package/dist/commands/get-page-by-type.js.map +1 -0
- package/dist/commands/get-section-values.d.ts +3 -0
- package/dist/commands/get-section-values.d.ts.map +1 -0
- package/dist/commands/get-section-values.js +39 -0
- package/dist/commands/get-section-values.js.map +1 -0
- package/dist/commands/list-entities.d.ts +3 -0
- package/dist/commands/list-entities.d.ts.map +1 -0
- package/dist/commands/list-entities.js +32 -0
- package/dist/commands/list-entities.js.map +1 -0
- package/dist/commands/list-page-sections.d.ts +3 -0
- package/dist/commands/list-page-sections.d.ts.map +1 -0
- package/dist/commands/list-page-sections.js +25 -0
- package/dist/commands/list-page-sections.js.map +1 -0
- package/dist/commands/list-theme-globals.d.ts +3 -0
- package/dist/commands/list-theme-globals.d.ts.map +1 -0
- package/dist/commands/list-theme-globals.js +22 -0
- package/dist/commands/list-theme-globals.js.map +1 -0
- package/dist/commands/publish-theme.d.ts +3 -0
- package/dist/commands/publish-theme.d.ts.map +1 -0
- package/dist/commands/publish-theme.js +29 -0
- package/dist/commands/publish-theme.js.map +1 -0
- package/dist/commands/publish.d.ts.map +1 -1
- package/dist/commands/publish.js +24 -2
- package/dist/commands/publish.js.map +1 -1
- package/dist/commands/search-products.d.ts +3 -0
- package/dist/commands/search-products.d.ts.map +1 -0
- package/dist/commands/search-products.js +40 -0
- package/dist/commands/search-products.js.map +1 -0
- package/dist/commands/update-global-variable.d.ts +3 -0
- package/dist/commands/update-global-variable.d.ts.map +1 -0
- package/dist/commands/update-global-variable.js +47 -0
- package/dist/commands/update-global-variable.js.map +1 -0
- package/dist/commands/update-page-sections.d.ts +3 -0
- package/dist/commands/update-page-sections.d.ts.map +1 -0
- package/dist/commands/update-page-sections.js +39 -0
- package/dist/commands/update-page-sections.js.map +1 -0
- package/dist/commands/update-section-prop.d.ts +3 -0
- package/dist/commands/update-section-prop.d.ts.map +1 -0
- package/dist/commands/update-section-prop.js +76 -0
- package/dist/commands/update-section-prop.js.map +1 -0
- package/dist/commands/upload-image.d.ts +3 -0
- package/dist/commands/upload-image.d.ts.map +1 -0
- package/dist/commands/upload-image.js +38 -0
- package/dist/commands/upload-image.js.map +1 -0
- package/dist/commands/upload-images.d.ts +3 -0
- package/dist/commands/upload-images.d.ts.map +1 -0
- package/dist/commands/upload-images.js +48 -0
- package/dist/commands/upload-images.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +48 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +17 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/compile.d.ts +4 -1
- package/dist/utils/compile.d.ts.map +1 -1
- package/dist/utils/compile.js +630 -102
- package/dist/utils/compile.js.map +1 -1
- package/dist/utils/component-helpers.d.ts +69 -2
- package/dist/utils/component-helpers.d.ts.map +1 -1
- package/dist/utils/component-helpers.js +193 -25
- package/dist/utils/component-helpers.js.map +1 -1
- package/dist/utils/editor-action-client.d.ts +1 -1
- package/dist/utils/editor-action-client.d.ts.map +1 -1
- package/dist/utils/editor-action-client.js +23 -8
- package/dist/utils/editor-action-client.js.map +1 -1
- package/dist/utils/forbid-deep-imports.d.ts +3 -0
- package/dist/utils/forbid-deep-imports.d.ts.map +1 -0
- package/dist/utils/forbid-deep-imports.js +54 -0
- package/dist/utils/forbid-deep-imports.js.map +1 -0
- package/dist/utils/forbid-external-packages.d.ts +16 -0
- package/dist/utils/forbid-external-packages.d.ts.map +1 -0
- package/dist/utils/forbid-external-packages.js +89 -0
- package/dist/utils/forbid-external-packages.js.map +1 -0
- package/dist/utils/load-image.d.ts +16 -0
- package/dist/utils/load-image.d.ts.map +1 -0
- package/dist/utils/load-image.js +50 -0
- package/dist/utils/load-image.js.map +1 -0
- package/dist/utils/websocket-server.d.ts +13 -4
- package/dist/utils/websocket-server.d.ts.map +1 -1
- package/dist/utils/websocket-server.js +1 -1
- package/dist/utils/websocket-server.js.map +1 -1
- package/package.json +13 -1
- package/templates/add/section.css +11 -0
package/dist/utils/compile.js
CHANGED
|
@@ -4,34 +4,64 @@ import * as os from "os";
|
|
|
4
4
|
import * as path from "path";
|
|
5
5
|
import { resolveCssImports } from "./css-import-resolver.js";
|
|
6
6
|
import { ikasComponentUtilsPlugin } from "./observer-runtime.js";
|
|
7
|
+
import { forbidDeepStorefrontImportsPlugin } from "./forbid-deep-imports.js";
|
|
8
|
+
import { forbidExternalPackagesPlugin } from "./forbid-external-packages.js";
|
|
7
9
|
/**
|
|
8
|
-
* Shim
|
|
9
|
-
*
|
|
10
|
-
*
|
|
10
|
+
* Shim that provides the JSX factory/fragment under collision-proof names.
|
|
11
|
+
*
|
|
12
|
+
* The classic JSX pragma must be a bare identifier in scope. Using `h`/`Fragment`
|
|
13
|
+
* directly means any user-authored local named `h` or `Fragment` (e.g. a `.map`
|
|
14
|
+
* callback param) shadows the factory, so JSX in that scope compiles to a call on
|
|
15
|
+
* the local value → runtime "x is not a function". Aliasing to `__ikas_h` /
|
|
16
|
+
* `__ikas_Fragment` (names users won't write) eliminates that shadowing footgun.
|
|
17
|
+
*
|
|
18
|
+
* Unlike `banner` (appended after minification), `inject` is processed during
|
|
19
|
+
* compilation so the minifier will never reuse these names. The bundled import
|
|
20
|
+
* still references preact's `h`/`Fragment`, so the canvas esm-transform keying off
|
|
21
|
+
* those source export names is unaffected.
|
|
11
22
|
*/
|
|
12
23
|
const PREACT_JSX_SHIM = path.join(os.tmpdir(), "ikas-preact-jsx-shim.mjs");
|
|
13
|
-
fs.writeFileSync(PREACT_JSX_SHIM, 'export{h,Fragment}from"preact";\n');
|
|
24
|
+
fs.writeFileSync(PREACT_JSX_SHIM, 'export{h as __ikas_h,Fragment as __ikas_Fragment}from"preact";\n');
|
|
14
25
|
/**
|
|
15
|
-
* External dependencies - these will be provided by the generated storefront
|
|
26
|
+
* External dependencies - these will be provided by the generated storefront.
|
|
27
|
+
*
|
|
28
|
+
* The `@ikas/bp-storefront*` packages are intentionally NOT listed here: they are externalized
|
|
29
|
+
* by `forbidDeepStorefrontImportsPlugin()` instead, which externalizes the allowed ROOT import
|
|
30
|
+
* and rejects private deep subpaths. (esbuild applies this `external` array before plugin
|
|
31
|
+
* onResolve, so keeping them here would let `/dist/...` deep imports slip through unchecked.)
|
|
16
32
|
*/
|
|
17
33
|
const SERVER_EXTERNALS = [
|
|
18
34
|
"preact",
|
|
19
35
|
"preact/hooks",
|
|
20
36
|
"preact-render-to-string",
|
|
21
|
-
"mobx"
|
|
22
|
-
"@ikas/bp-storefront",
|
|
23
|
-
"@ikas/bp-storefront-models",
|
|
24
|
-
"@ikas/bp-storefront-config",
|
|
25
|
-
"@ikas/bp-storefront-api"
|
|
37
|
+
"mobx"
|
|
26
38
|
];
|
|
27
39
|
const CLIENT_EXTERNALS = [
|
|
28
40
|
"preact",
|
|
29
41
|
"preact/hooks",
|
|
30
|
-
"mobx"
|
|
31
|
-
"@ikas/bp-storefront",
|
|
32
|
-
"@ikas/bp-storefront-models",
|
|
33
|
-
"@ikas/bp-storefront-config"
|
|
42
|
+
"mobx"
|
|
34
43
|
];
|
|
44
|
+
/**
|
|
45
|
+
* The server and client builds MUST compile with the SAME esbuild `target` so
|
|
46
|
+
* syntax is lowered identically and code-split shared chunks come out
|
|
47
|
+
* byte-identical (same content hash) on both sides.
|
|
48
|
+
*
|
|
49
|
+
* If the targets diverge (previously server=node18 vs client=es2020), esbuild
|
|
50
|
+
* lowers modern syntax differently: e.g. a class field (`x = 1`, ES2022) stays
|
|
51
|
+
* native on node18 but is down-leveled into a `__publicField` helper on es2020.
|
|
52
|
+
* That helper lands in the shared runtime-helper chunk, so the helper chunk's
|
|
53
|
+
* hash differs between builds — and every chunk that imports it by hashed name
|
|
54
|
+
* (`./chunk-<hash>.js`) diverges too. The result is "server-only" shared chunks
|
|
55
|
+
* with no client twin, which the client-derived `usedSharedModuleIds` never
|
|
56
|
+
* lists, so they get pruned/dropped downstream ("Could not resolve
|
|
57
|
+
* ./chunk-XXXX.js" at SSR build).
|
|
58
|
+
*
|
|
59
|
+
* es2020 is the floor the browser build needs; node18 executes es2020 fine, so
|
|
60
|
+
* both builds use es2020 and produce identical shared chunks. Keep this the
|
|
61
|
+
* single source of truth for both `platform: node` and `platform: browser`
|
|
62
|
+
* builds — do not set per-build `target` overrides.
|
|
63
|
+
*/
|
|
64
|
+
const SHARED_BUILD_TARGET = "es2020";
|
|
35
65
|
/**
|
|
36
66
|
* Compile a single component's TSX and CSS
|
|
37
67
|
*/
|
|
@@ -43,10 +73,14 @@ export async function compileComponent(entryPath, stylesPath, componentId) {
|
|
|
43
73
|
entryPoints: [path.resolve(process.cwd(), entryPath)],
|
|
44
74
|
format: "esm",
|
|
45
75
|
platform: "node",
|
|
46
|
-
target:
|
|
76
|
+
target: SHARED_BUILD_TARGET,
|
|
47
77
|
write: false,
|
|
48
78
|
external: SERVER_EXTERNALS,
|
|
49
|
-
plugins: [
|
|
79
|
+
plugins: [
|
|
80
|
+
forbidDeepStorefrontImportsPlugin(),
|
|
81
|
+
forbidExternalPackagesPlugin(),
|
|
82
|
+
ikasComponentUtilsPlugin(),
|
|
83
|
+
],
|
|
50
84
|
});
|
|
51
85
|
// Build client bundle (for hydration)
|
|
52
86
|
const clientResult = await esbuild.build({
|
|
@@ -54,10 +88,14 @@ export async function compileComponent(entryPath, stylesPath, componentId) {
|
|
|
54
88
|
entryPoints: [path.resolve(process.cwd(), entryPath)],
|
|
55
89
|
format: "esm",
|
|
56
90
|
platform: "browser",
|
|
57
|
-
target:
|
|
91
|
+
target: SHARED_BUILD_TARGET,
|
|
58
92
|
write: false,
|
|
59
93
|
external: CLIENT_EXTERNALS,
|
|
60
|
-
plugins: [
|
|
94
|
+
plugins: [
|
|
95
|
+
forbidDeepStorefrontImportsPlugin(),
|
|
96
|
+
forbidExternalPackagesPlugin(),
|
|
97
|
+
ikasComponentUtilsPlugin(),
|
|
98
|
+
],
|
|
61
99
|
});
|
|
62
100
|
// Read CSS (with import resolution)
|
|
63
101
|
const cssPath = path.resolve(process.cwd(), stylesPath);
|
|
@@ -86,11 +124,15 @@ export async function compileComponent(entryPath, stylesPath, componentId) {
|
|
|
86
124
|
}
|
|
87
125
|
}
|
|
88
126
|
/**
|
|
89
|
-
* Scope CSS selectors with a component-specific class prefix
|
|
127
|
+
* Scope CSS selectors with a component-specific class prefix, then namespace any
|
|
128
|
+
* document-global CSS identifiers (`@keyframes`, `@font-face` font-family,
|
|
129
|
+
* `@counter-style`) DEFINED in this component so two components — or the host theme —
|
|
130
|
+
* declaring the same name can't collide in the page's global namespace.
|
|
90
131
|
*/
|
|
91
132
|
export function scopeCSS(css, componentId) {
|
|
92
133
|
const scopeClass = `cc_${componentId.replace(/[^a-zA-Z0-9]/g, "_")}`;
|
|
93
|
-
|
|
134
|
+
const scoped = scopeCSSWithClasses(css, [scopeClass]);
|
|
135
|
+
return renameCollidingGlobals(scoped, `${scopeClass}_`);
|
|
94
136
|
}
|
|
95
137
|
/**
|
|
96
138
|
* Scope CSS selectors with multiple class prefixes (for shared chunks).
|
|
@@ -100,63 +142,519 @@ export function scopeCSSMulti(css, componentIds) {
|
|
|
100
142
|
const scopeClasses = componentIds.map(id => `cc_${id.replace(/[^a-zA-Z0-9]/g, "_")}`);
|
|
101
143
|
return scopeCSSWithClasses(css, scopeClasses);
|
|
102
144
|
}
|
|
145
|
+
// Conditional group at-rules whose blocks nest normal style rules and must be
|
|
146
|
+
// scoped recursively. This is an ALLOWLIST on purpose: at-rules NOT listed here
|
|
147
|
+
// (@keyframes, @font-face, @page, @property, @counter-style, ...) have non-selector
|
|
148
|
+
// bodies — e.g. @keyframes contains `0%`/`from` keyframe selectors that must NOT be
|
|
149
|
+
// prefixed — so their bodies are copied through untouched. Vendor-prefixed conditional
|
|
150
|
+
// rules (@-moz-document) match via the optional prefix group; @-webkit-keyframes does
|
|
151
|
+
// NOT match (the alternation excludes "keyframes"), which is what we want.
|
|
152
|
+
//
|
|
153
|
+
// NOTE: This scoper is duplicated in editor-models/src/helpers/code-component-css-scope.ts
|
|
154
|
+
// (the editor-preview / code-generator path). The CLI ships standalone to npm and cannot
|
|
155
|
+
// import that private package, so the two intentionally diverge. Keep parsing fixes in sync.
|
|
156
|
+
const NESTING_AT_RULES = /^@(?:-\w+-)?(media|supports|container|layer|document|scope|starting-style)\b/i;
|
|
103
157
|
/**
|
|
104
|
-
* Internal: scope CSS selectors with one or more scope class prefixes
|
|
158
|
+
* Internal: scope CSS selectors with one or more scope class prefixes.
|
|
159
|
+
*
|
|
160
|
+
* Character-based walker, NOT line-based: a rule's selector list is everything up
|
|
161
|
+
* to its opening `{`, so lists written across multiple lines (`.a,\n.b { ... }`)
|
|
162
|
+
* are scoped as a whole. The previous line-based implementation only scoped the
|
|
163
|
+
* selector fragment sharing a line with `{`, leaving the other selectors unscoped
|
|
164
|
+
* (they either lost the cascade to scoped rules or leaked into other components).
|
|
165
|
+
*
|
|
166
|
+
* Comments, string literals, and `\` escapes are treated as inert spans (via
|
|
167
|
+
* `skipInertSpan`) by every structural scanner, so a `{`, `}`, `;`, or `,` that
|
|
168
|
+
* appears inside a comment / string / escape can never be mistaken for real
|
|
169
|
+
* structure (which would otherwise drop the scope prefix and leak styles globally).
|
|
105
170
|
*/
|
|
106
171
|
function scopeCSSWithClasses(css, scopeClasses) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
172
|
+
let out = "";
|
|
173
|
+
for (let i = 0; i < css.length;) {
|
|
174
|
+
const ch = css[i];
|
|
175
|
+
// Copy comments verbatim
|
|
176
|
+
if (ch === "/" && css[i + 1] === "*") {
|
|
177
|
+
const end = css.indexOf("*/", i + 2);
|
|
178
|
+
if (end === -1)
|
|
179
|
+
return out + css.slice(i);
|
|
180
|
+
out += css.slice(i, end + 2);
|
|
181
|
+
i = end + 2;
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
// Copy whitespace and stray closing braces
|
|
185
|
+
if (/\s/.test(ch) || ch === "}") {
|
|
186
|
+
out += ch;
|
|
187
|
+
i++;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (ch === "@") {
|
|
191
|
+
const headerEnd = findAtRuleHeaderEnd(css, i);
|
|
192
|
+
// Block-less at-rule (@import, @charset, @layer a;, ...) — copy through
|
|
193
|
+
if (headerEnd >= css.length || css[headerEnd] === ";") {
|
|
194
|
+
out += css.slice(i, Math.min(headerEnd + 1, css.length));
|
|
195
|
+
i = headerEnd + 1;
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const header = css.slice(i, headerEnd);
|
|
199
|
+
const blockEnd = findBlockEnd(css, headerEnd + 1);
|
|
200
|
+
const body = css.slice(headerEnd + 1, blockEnd);
|
|
201
|
+
const transformed = NESTING_AT_RULES.test(header.trim())
|
|
202
|
+
? scopeCSSWithClasses(body, scopeClasses)
|
|
203
|
+
: body;
|
|
204
|
+
// Always emit the closing brace: when the source block is unterminated
|
|
205
|
+
// (blockEnd === css.length) this repairs it, so concatenated component CSS
|
|
206
|
+
// can't leak one component's block over the next.
|
|
207
|
+
out += `${header}{${transformed}}`;
|
|
208
|
+
i = blockEnd + 1;
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
// Normal style rule: selector list runs up to the rule's opening `{`
|
|
212
|
+
const selEnd = findSelectorListEnd(css, i);
|
|
213
|
+
if (selEnd >= css.length) {
|
|
214
|
+
// Trailing content with no block (e.g. a dangling declaration at EOF) — copy through
|
|
215
|
+
out += css.slice(i);
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
if (css[selEnd] === ";") {
|
|
219
|
+
// A stray top-level `;` (or a stray declaration fragment ending in `;`) — not a rule.
|
|
220
|
+
// DROP it. Copying it through is not enough: per the CSS syntax spec a browser folds a
|
|
221
|
+
// stray `;` into the NEXT rule's prelude when consuming a qualified rule, which makes
|
|
222
|
+
// that selector invalid and drops the whole following rule. Dropping the stray token
|
|
223
|
+
// keeps the next rule valid and correctly scoped.
|
|
224
|
+
i = selEnd + 1;
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if (css[selEnd] === "}") {
|
|
228
|
+
// Content before a stray closing brace — copy through verbatim and let the main loop
|
|
229
|
+
// emit the `}`.
|
|
230
|
+
out += css.slice(i, selEnd);
|
|
231
|
+
i = selEnd;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
const selectorList = css.slice(i, selEnd);
|
|
235
|
+
const blockEnd = findBlockEnd(css, selEnd + 1);
|
|
236
|
+
const body = css.slice(selEnd + 1, blockEnd);
|
|
237
|
+
const scopedSelector = splitSelectorList(selectorList)
|
|
238
|
+
.map(s => s.trim())
|
|
239
|
+
.filter(Boolean)
|
|
240
|
+
.flatMap(s => scopeClasses.map(cls => `.${cls} ${s}`))
|
|
241
|
+
.join(", ");
|
|
242
|
+
// Always emit the closing brace (see at-rule branch above for rationale).
|
|
243
|
+
out += `${scopedSelector} {${body}}`;
|
|
244
|
+
i = blockEnd + 1;
|
|
245
|
+
}
|
|
246
|
+
return out;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* If an inert span — a `/* ... *\/` comment, a `"..."` / `'...'` string literal, an
|
|
250
|
+
* unquoted `url(...)` token, or a `\x` escape — starts at `s[i]`, return the index just
|
|
251
|
+
* past it; otherwise return -1.
|
|
252
|
+
*
|
|
253
|
+
* Every structural scanner below funnels through this so that delimiters (`{ } ; , ( )`)
|
|
254
|
+
* living inside comments, strings, urls, or escapes are never treated as structure. String
|
|
255
|
+
* scanning honors `\` escapes and stops at a raw newline, matching CSS "bad-string" error
|
|
256
|
+
* recovery (an unterminated string ends at the line break) so a missing quote can't
|
|
257
|
+
* swallow every rule that follows it.
|
|
258
|
+
*/
|
|
259
|
+
function skipInertSpan(s, i) {
|
|
260
|
+
const c = s[i];
|
|
261
|
+
if (c === "/" && s[i + 1] === "*") {
|
|
262
|
+
const end = s.indexOf("*/", i + 2);
|
|
263
|
+
return end === -1 ? s.length : end + 2;
|
|
264
|
+
}
|
|
265
|
+
if (c === '"' || c === "'") {
|
|
266
|
+
for (let j = i + 1; j < s.length; j++) {
|
|
267
|
+
const d = s[j];
|
|
268
|
+
if (d === "\\") {
|
|
269
|
+
j++; // escape: skip the next char
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
if (d === c)
|
|
273
|
+
return j + 1; // closing quote
|
|
274
|
+
if (d === "\n" || d === "\r" || d === "\f")
|
|
275
|
+
return j; // bad-string ends at newline
|
|
276
|
+
}
|
|
277
|
+
return s.length;
|
|
278
|
+
}
|
|
279
|
+
// Unquoted url(...) token: per the CSS tokenizer its content is opaque, so braces,
|
|
280
|
+
// semicolons, and parens inside it must NOT be read as structure (an unbalanced `}` in
|
|
281
|
+
// `url(x}y.png)` or `{` in an inline SVG data-uri would otherwise mis-terminate the
|
|
282
|
+
// enclosing block). A QUOTED url (`url("...")`) is a normal function + string and is left
|
|
283
|
+
// to the string branch above. `url` must be a standalone ident, not the tail of a longer
|
|
284
|
+
// identifier like `myurl(`.
|
|
285
|
+
if ((c === "u" || c === "U") && /^url\(/i.test(s.slice(i, i + 4))) {
|
|
286
|
+
const prev = i > 0 ? s[i - 1] : "";
|
|
287
|
+
if (!/[A-Za-z0-9_-]/.test(prev)) {
|
|
288
|
+
let j = i + 4;
|
|
289
|
+
while (j < s.length && /\s/.test(s[j]))
|
|
290
|
+
j++; // optional leading whitespace
|
|
291
|
+
if (s[j] !== '"' && s[j] !== "'") {
|
|
292
|
+
for (; j < s.length; j++) {
|
|
293
|
+
if (s[j] === "\\") {
|
|
294
|
+
j++; // escaped char inside the url (e.g. `url(foo\)bar)`)
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
if (s[j] === ")")
|
|
298
|
+
return j + 1; // end of url token
|
|
299
|
+
}
|
|
300
|
+
return s.length; // unterminated url() — consume to EOF (bad-url)
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
if (c === "\\")
|
|
305
|
+
return i + 2; // escaped char outside a string (e.g. `.a\,b`)
|
|
306
|
+
return -1;
|
|
307
|
+
}
|
|
308
|
+
/** Find the first top-level `{` or `;` that ends an at-rule's header. Respects `()` / `[]`
|
|
309
|
+
* and inert spans (strings/comments/escapes). */
|
|
310
|
+
function findAtRuleHeaderEnd(css, start) {
|
|
311
|
+
let pDepth = 0;
|
|
312
|
+
for (let j = start; j < css.length;) {
|
|
313
|
+
const skip = skipInertSpan(css, j);
|
|
314
|
+
if (skip !== -1) {
|
|
315
|
+
j = skip;
|
|
115
316
|
continue;
|
|
116
317
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
318
|
+
const c = css[j];
|
|
319
|
+
if (c === "(" || c === "[")
|
|
320
|
+
pDepth++;
|
|
321
|
+
else if (c === ")" || c === "]")
|
|
322
|
+
pDepth--;
|
|
323
|
+
else if (pDepth === 0 && (c === "{" || c === ";"))
|
|
324
|
+
return j;
|
|
325
|
+
j++;
|
|
326
|
+
}
|
|
327
|
+
return css.length;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Find the matching `}` for the block whose body starts at `blockStart` (char after `{`).
|
|
331
|
+
* Inert spans are skipped so braces inside `content: "}"`, comments, or escapes don't
|
|
332
|
+
* terminate the block early.
|
|
333
|
+
*/
|
|
334
|
+
function findBlockEnd(css, blockStart) {
|
|
335
|
+
let depth = 1;
|
|
336
|
+
for (let j = blockStart; j < css.length;) {
|
|
337
|
+
const skip = skipInertSpan(css, j);
|
|
338
|
+
if (skip !== -1) {
|
|
339
|
+
j = skip;
|
|
120
340
|
continue;
|
|
121
341
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
342
|
+
const c = css[j];
|
|
343
|
+
if (c === "{")
|
|
344
|
+
depth++;
|
|
345
|
+
else if (c === "}") {
|
|
346
|
+
depth--;
|
|
347
|
+
if (depth === 0)
|
|
348
|
+
return j;
|
|
349
|
+
}
|
|
350
|
+
j++;
|
|
351
|
+
}
|
|
352
|
+
return css.length;
|
|
353
|
+
}
|
|
354
|
+
/** Find the `{`, `}`, or `;` that terminates a selector list. A `}` or `;` here means the
|
|
355
|
+
* run was not a real style rule. Respects `()` / `[]` and inert spans. */
|
|
356
|
+
function findSelectorListEnd(css, start) {
|
|
357
|
+
let pDepth = 0;
|
|
358
|
+
for (let j = start; j < css.length;) {
|
|
359
|
+
const skip = skipInertSpan(css, j);
|
|
360
|
+
if (skip !== -1) {
|
|
361
|
+
j = skip;
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
const c = css[j];
|
|
365
|
+
if (c === "(" || c === "[")
|
|
366
|
+
pDepth++;
|
|
367
|
+
else if (c === ")" || c === "]")
|
|
368
|
+
pDepth--;
|
|
369
|
+
else if (pDepth === 0 && (c === "{" || c === "}" || c === ";"))
|
|
370
|
+
return j;
|
|
371
|
+
j++;
|
|
372
|
+
}
|
|
373
|
+
return css.length;
|
|
374
|
+
}
|
|
375
|
+
/** Split a selector list on top-level commas. Respects `()` / `[]` and inert spans, so a
|
|
376
|
+
* comma inside a comment, string, or `\` escape (e.g. `.a\,b`) does not split the list. */
|
|
377
|
+
function splitSelectorList(s) {
|
|
378
|
+
const result = [];
|
|
379
|
+
let depth = 0;
|
|
380
|
+
let start = 0;
|
|
381
|
+
for (let i = 0; i < s.length;) {
|
|
382
|
+
const skip = skipInertSpan(s, i);
|
|
383
|
+
if (skip !== -1) {
|
|
384
|
+
i = skip;
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
const ch = s[i];
|
|
388
|
+
if (ch === "(" || ch === "[")
|
|
389
|
+
depth++;
|
|
390
|
+
else if (ch === ")" || ch === "]")
|
|
391
|
+
depth--;
|
|
392
|
+
else if (ch === "," && depth === 0) {
|
|
393
|
+
result.push(s.slice(start, i));
|
|
394
|
+
start = i + 1;
|
|
395
|
+
}
|
|
396
|
+
i++;
|
|
397
|
+
}
|
|
398
|
+
result.push(s.slice(start));
|
|
399
|
+
return result;
|
|
400
|
+
}
|
|
401
|
+
/* ============================================================================
|
|
402
|
+
* Global-identifier namespacing.
|
|
403
|
+
*
|
|
404
|
+
* `@keyframes`, `@font-face` font-family names, and `@counter-style` names live in a
|
|
405
|
+
* DOCUMENT-GLOBAL namespace — scoping selectors with `.cc_<id>` does not isolate them, so
|
|
406
|
+
* two components (or the theme) defining the same name would collide (last definition wins
|
|
407
|
+
* document-wide). `renameCollidingGlobals` prefixes every such name DEFINED in this CSS,
|
|
408
|
+
* plus its references within the SAME CSS, with the component's scope prefix.
|
|
409
|
+
*
|
|
410
|
+
* Only names defined in THIS css are renamed — a reference to a name defined elsewhere
|
|
411
|
+
* (global.css, a shared chunk, the theme) is left untouched, so cross-file references keep
|
|
412
|
+
* resolving. Shared-chunk CSS (scopeCSSMulti) is intentionally NOT renamed, to avoid
|
|
413
|
+
* breaking a chunk-defined keyframe referenced from a consuming component's own CSS.
|
|
414
|
+
*
|
|
415
|
+
* NOTE: ported from packages/editor-models/src/helpers/code-component-css-scope.ts
|
|
416
|
+
* (renameCollidingGlobals + helpers, the global.css path's `cc_<projectId>_` variant).
|
|
417
|
+
* Keep parsing/rename fixes in sync between the two.
|
|
418
|
+
* ============================================================================ */
|
|
419
|
+
// Declarations whose VALUE may reference a global identifier of the given type.
|
|
420
|
+
const KEYFRAME_REF_PROPS = new Set(["animation", "animation-name"]);
|
|
421
|
+
const FONT_FAMILY_REF_PROPS = new Set(["font", "font-family"]);
|
|
422
|
+
const COUNTER_STYLE_REF_PROPS = new Set(["list-style", "list-style-type"]);
|
|
423
|
+
function renameCollidingGlobals(css, prefix) {
|
|
424
|
+
// Comment/string/url-masked copy: defining-site regex scans run against this so a name
|
|
425
|
+
// inside a comment or `content: "..."` string can't contribute a rename or be rewritten.
|
|
426
|
+
const scanCss = maskInertSpans(css);
|
|
427
|
+
const keyframeNames = new Set();
|
|
428
|
+
const fontFamilyNames = new Set();
|
|
429
|
+
const counterStyleNames = new Set();
|
|
430
|
+
let out = css;
|
|
431
|
+
out = out.replace(/@keyframes(\s+)([\w-]+)/g, (m, ws, name, offset) => {
|
|
432
|
+
if (scanCss.substr(offset, 10) !== "@keyframes")
|
|
433
|
+
return m;
|
|
434
|
+
keyframeNames.add(name);
|
|
435
|
+
return `@keyframes${ws}${prefix}${name}`;
|
|
436
|
+
});
|
|
437
|
+
out = out.replace(/@counter-style(\s+)([\w-]+)/g, (m, ws, name, offset) => {
|
|
438
|
+
if (scanCss.substr(offset, 14) !== "@counter-style")
|
|
439
|
+
return m;
|
|
440
|
+
counterStyleNames.add(name);
|
|
441
|
+
return `@counter-style${ws}${prefix}${name}`;
|
|
442
|
+
});
|
|
443
|
+
out = rewriteFontFaceBlocks(out, fontFamilyNames, prefix);
|
|
444
|
+
if (keyframeNames.size === 0 && fontFamilyNames.size === 0 && counterStyleNames.size === 0) {
|
|
445
|
+
return out;
|
|
446
|
+
}
|
|
447
|
+
return rewriteDeclarationReferences(out, keyframeNames, fontFamilyNames, counterStyleNames, prefix);
|
|
448
|
+
}
|
|
449
|
+
/** Replace every inert span (comment / string / url() / escape) with equal-length spaces so
|
|
450
|
+
* position-based regex scans still align but can't match tokens hidden inside them. */
|
|
451
|
+
function maskInertSpans(css) {
|
|
452
|
+
let out = "";
|
|
453
|
+
for (let i = 0; i < css.length;) {
|
|
454
|
+
const skip = skipInertSpan(css, i);
|
|
455
|
+
if (skip !== -1) {
|
|
456
|
+
out += " ".repeat(skip - i);
|
|
457
|
+
i = skip;
|
|
125
458
|
continue;
|
|
126
459
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
460
|
+
out += css[i];
|
|
461
|
+
i++;
|
|
462
|
+
}
|
|
463
|
+
return out;
|
|
464
|
+
}
|
|
465
|
+
function rewriteFontFaceBlocks(css, collect, prefix) {
|
|
466
|
+
const matches = [];
|
|
467
|
+
css.replace(/@font-face\s*\{/g, (m, offset) => {
|
|
468
|
+
matches.push({ index: offset, length: m.length });
|
|
469
|
+
return m;
|
|
470
|
+
});
|
|
471
|
+
if (matches.length === 0)
|
|
472
|
+
return css;
|
|
473
|
+
let out = "";
|
|
474
|
+
let lastIdx = 0;
|
|
475
|
+
for (const match of matches) {
|
|
476
|
+
const openBraceIdx = match.index + match.length - 1;
|
|
477
|
+
if (openBraceIdx < lastIdx)
|
|
478
|
+
continue;
|
|
479
|
+
const endIdx = findBlockEnd(css, openBraceIdx + 1);
|
|
480
|
+
const before = css.slice(lastIdx, openBraceIdx + 1);
|
|
481
|
+
const body = css.slice(openBraceIdx + 1, endIdx);
|
|
482
|
+
const rewrittenBody = body.replace(/(font-family\s*:\s*)(?:"([^"]+)"|'([^']+)'|([\w-]+))/i, (_m, pre, dq, sq, bare) => {
|
|
483
|
+
const name = dq || sq || bare;
|
|
484
|
+
if (!name)
|
|
485
|
+
return _m;
|
|
486
|
+
collect.add(name);
|
|
487
|
+
const prefixed = `${prefix}${name}`;
|
|
488
|
+
if (dq)
|
|
489
|
+
return `${pre}"${prefixed}"`;
|
|
490
|
+
if (sq)
|
|
491
|
+
return `${pre}'${prefixed}'`;
|
|
492
|
+
return `${pre}${prefixed}`;
|
|
493
|
+
});
|
|
494
|
+
out += before + rewrittenBody + "}";
|
|
495
|
+
lastIdx = endIdx + 1;
|
|
496
|
+
}
|
|
497
|
+
out += css.slice(lastIdx);
|
|
498
|
+
return out;
|
|
499
|
+
}
|
|
500
|
+
function rewriteDeclarationReferences(css, keyframeNames, fontFamilyNames, counterStyleNames, prefix) {
|
|
501
|
+
const keyframeRe = buildBareIdentRegex(keyframeNames);
|
|
502
|
+
const fontFamilyRe = buildFontFamilyValueRegex(fontFamilyNames);
|
|
503
|
+
const counterStyleRe = buildBareIdentRegex(counterStyleNames);
|
|
504
|
+
// counter(<name>, <style>?) / counters(<name>, <string>, <style>?) — the counter-style
|
|
505
|
+
// identifier, when present, is always the LAST optional argument.
|
|
506
|
+
const counterFnRe = counterStyleNames.size > 0
|
|
507
|
+
? new RegExp(`(\\bcounters?\\([^)]*?,\\s*)(${bareUnion(counterStyleNames)})(\\s*\\))`, "gi")
|
|
508
|
+
: null;
|
|
509
|
+
return mapRuleBlocks(css, block => {
|
|
510
|
+
return mapDeclarations(block, (prop, value) => {
|
|
511
|
+
let v = value;
|
|
512
|
+
const lower = prop.toLowerCase();
|
|
513
|
+
if (keyframeRe && KEYFRAME_REF_PROPS.has(lower)) {
|
|
514
|
+
v = v.replace(keyframeRe, m => `${prefix}${m}`);
|
|
515
|
+
}
|
|
516
|
+
if (fontFamilyRe && FONT_FAMILY_REF_PROPS.has(lower)) {
|
|
517
|
+
v = v.replace(fontFamilyRe, (m, dq, sq, bare) => {
|
|
518
|
+
const name = dq || sq || bare;
|
|
519
|
+
if (!name || !fontFamilyNames.has(name))
|
|
520
|
+
return m;
|
|
521
|
+
if (dq !== undefined)
|
|
522
|
+
return `"${prefix}${name}"`;
|
|
523
|
+
if (sq !== undefined)
|
|
524
|
+
return `'${prefix}${name}'`;
|
|
525
|
+
return `${prefix}${name}`;
|
|
526
|
+
});
|
|
134
527
|
}
|
|
135
|
-
|
|
528
|
+
if (counterStyleRe && COUNTER_STYLE_REF_PROPS.has(lower)) {
|
|
529
|
+
v = v.replace(counterStyleRe, m => `${prefix}${m}`);
|
|
530
|
+
}
|
|
531
|
+
if (counterFnRe) {
|
|
532
|
+
v = v.replace(counterFnRe, (_m, pre, name, post) => `${pre}${prefix}${name}${post}`);
|
|
533
|
+
}
|
|
534
|
+
return v;
|
|
535
|
+
});
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
function bareUnion(names) {
|
|
539
|
+
return Array.from(names).map(escapeRegex).join("|");
|
|
540
|
+
}
|
|
541
|
+
function buildBareIdentRegex(names) {
|
|
542
|
+
if (names.size === 0)
|
|
543
|
+
return null;
|
|
544
|
+
return new RegExp(`(?<![\\w-])(?:${bareUnion(names)})(?![\\w-])`, "g");
|
|
545
|
+
}
|
|
546
|
+
function buildFontFamilyValueRegex(names) {
|
|
547
|
+
if (names.size === 0)
|
|
548
|
+
return null;
|
|
549
|
+
const u = bareUnion(names);
|
|
550
|
+
return new RegExp(`"(${u})"|'(${u})'|(?<![\\w-])(${u})(?![\\w-])`, "g");
|
|
551
|
+
}
|
|
552
|
+
function escapeRegex(s) {
|
|
553
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Walk every top-level rule block `{ ... }` (recursing into nested at-rule contents) and
|
|
557
|
+
* pass the block body through `transform`. Inert spans are skipped so a `{` inside a string
|
|
558
|
+
* or `url(a{b)` is not mistaken for a block. At-rule preambles and inter-rule whitespace
|
|
559
|
+
* are left untouched.
|
|
560
|
+
*/
|
|
561
|
+
function mapRuleBlocks(css, transform) {
|
|
562
|
+
let out = "";
|
|
563
|
+
for (let i = 0; i < css.length;) {
|
|
564
|
+
const skip = skipInertSpan(css, i);
|
|
565
|
+
if (skip !== -1) {
|
|
566
|
+
out += css.slice(i, skip);
|
|
567
|
+
i = skip;
|
|
568
|
+
continue;
|
|
569
|
+
}
|
|
570
|
+
if (css[i] === "{") {
|
|
571
|
+
const blockEnd = findBlockEnd(css, i + 1);
|
|
572
|
+
const body = css.slice(i + 1, blockEnd);
|
|
573
|
+
const processed = hasTopLevelBrace(body) ? mapRuleBlocks(body, transform) : transform(body);
|
|
574
|
+
out += "{" + processed + "}";
|
|
575
|
+
i = blockEnd + 1;
|
|
136
576
|
continue;
|
|
137
577
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
578
|
+
out += css[i];
|
|
579
|
+
i++;
|
|
580
|
+
}
|
|
581
|
+
return out;
|
|
582
|
+
}
|
|
583
|
+
/** Inert-span-aware: true iff a real `{` appears outside comments/strings/url()/escapes. */
|
|
584
|
+
function hasTopLevelBrace(s) {
|
|
585
|
+
for (let i = 0; i < s.length;) {
|
|
586
|
+
const skip = skipInertSpan(s, i);
|
|
587
|
+
if (skip !== -1) {
|
|
588
|
+
i = skip;
|
|
141
589
|
continue;
|
|
142
590
|
}
|
|
143
|
-
if (
|
|
144
|
-
|
|
591
|
+
if (s[i] === "{")
|
|
592
|
+
return true;
|
|
593
|
+
i++;
|
|
594
|
+
}
|
|
595
|
+
return false;
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Split a rule block body into `prop: value` declarations on top-level `;`, apply
|
|
599
|
+
* `transform(prop, value)` to each, and rejoin preserving separators. Inert spans are
|
|
600
|
+
* skipped so a `;` inside a string or `url(a;b)` doesn't split a declaration.
|
|
601
|
+
*/
|
|
602
|
+
function mapDeclarations(body, transform) {
|
|
603
|
+
const parts = [];
|
|
604
|
+
let start = 0;
|
|
605
|
+
let pDepth = 0;
|
|
606
|
+
for (let i = 0; i < body.length;) {
|
|
607
|
+
const skip = skipInertSpan(body, i);
|
|
608
|
+
if (skip !== -1) {
|
|
609
|
+
i = skip;
|
|
145
610
|
continue;
|
|
146
611
|
}
|
|
147
|
-
const
|
|
148
|
-
if (
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
612
|
+
const c = body[i];
|
|
613
|
+
if (c === "(" || c === "[" || c === "{")
|
|
614
|
+
pDepth++;
|
|
615
|
+
else if (c === ")" || c === "]" || c === "}")
|
|
616
|
+
pDepth--;
|
|
617
|
+
else if (c === ";" && pDepth === 0) {
|
|
618
|
+
parts.push(body.slice(start, i));
|
|
619
|
+
start = i + 1;
|
|
154
620
|
}
|
|
155
|
-
|
|
156
|
-
|
|
621
|
+
i++;
|
|
622
|
+
}
|
|
623
|
+
parts.push(body.slice(start));
|
|
624
|
+
return parts
|
|
625
|
+
.map((part, idx) => {
|
|
626
|
+
const isLast = idx === parts.length - 1;
|
|
627
|
+
const colonIdx = findTopLevelColon(part);
|
|
628
|
+
if (colonIdx === -1)
|
|
629
|
+
return part + (isLast ? "" : ";");
|
|
630
|
+
const valueRaw = part.slice(colonIdx + 1);
|
|
631
|
+
const leading = valueRaw.match(/^\s*/)?.[0] ?? "";
|
|
632
|
+
const trailing = valueRaw.match(/\s*$/)?.[0] ?? "";
|
|
633
|
+
const prop = part.slice(0, colonIdx).trim();
|
|
634
|
+
const value = valueRaw.slice(leading.length, valueRaw.length - trailing.length);
|
|
635
|
+
const transformed = transform(prop, value);
|
|
636
|
+
return part.slice(0, colonIdx) + ":" + leading + transformed + trailing + (isLast ? "" : ";");
|
|
637
|
+
})
|
|
638
|
+
.join("");
|
|
639
|
+
}
|
|
640
|
+
function findTopLevelColon(s) {
|
|
641
|
+
let pDepth = 0;
|
|
642
|
+
for (let i = 0; i < s.length;) {
|
|
643
|
+
const skip = skipInertSpan(s, i);
|
|
644
|
+
if (skip !== -1) {
|
|
645
|
+
i = skip;
|
|
646
|
+
continue;
|
|
157
647
|
}
|
|
648
|
+
const c = s[i];
|
|
649
|
+
if (c === "(" || c === "[")
|
|
650
|
+
pDepth++;
|
|
651
|
+
else if (c === ")" || c === "]")
|
|
652
|
+
pDepth--;
|
|
653
|
+
else if (c === ":" && pDepth === 0)
|
|
654
|
+
return i;
|
|
655
|
+
i++;
|
|
158
656
|
}
|
|
159
|
-
return
|
|
657
|
+
return -1;
|
|
160
658
|
}
|
|
161
659
|
/**
|
|
162
660
|
* Common esbuild options shared between server and client builds
|
|
@@ -165,14 +663,14 @@ function commonBuildOptions() {
|
|
|
165
663
|
return {
|
|
166
664
|
bundle: true,
|
|
167
665
|
jsx: "transform",
|
|
168
|
-
jsxFactory: "
|
|
169
|
-
jsxFragment: "
|
|
666
|
+
jsxFactory: "__ikas_h",
|
|
667
|
+
jsxFragment: "__ikas_Fragment",
|
|
170
668
|
inject: [PREACT_JSX_SHIM],
|
|
171
669
|
tsconfigRaw: {
|
|
172
670
|
compilerOptions: {
|
|
173
671
|
jsx: "react",
|
|
174
|
-
jsxFactory: "
|
|
175
|
-
jsxFragmentFactory: "
|
|
672
|
+
jsxFactory: "__ikas_h",
|
|
673
|
+
jsxFragmentFactory: "__ikas_Fragment"
|
|
176
674
|
}
|
|
177
675
|
},
|
|
178
676
|
minify: true,
|
|
@@ -206,19 +704,24 @@ export async function compileAllComponents(components, globalStylesPath) {
|
|
|
206
704
|
entryPoints[comp.id] = path.resolve(process.cwd(), comp.entryPath);
|
|
207
705
|
}
|
|
208
706
|
try {
|
|
209
|
-
// Server build with code splitting
|
|
210
|
-
await esbuild.build({
|
|
707
|
+
// Server build with code splitting (metafile enabled for dependency tracking)
|
|
708
|
+
const serverBuildResult = await esbuild.build({
|
|
211
709
|
...commonBuildOptions(),
|
|
212
710
|
entryPoints,
|
|
213
711
|
format: "esm",
|
|
214
712
|
platform: "node",
|
|
215
|
-
target:
|
|
713
|
+
target: SHARED_BUILD_TARGET,
|
|
216
714
|
external: SERVER_EXTERNALS,
|
|
217
|
-
plugins: [
|
|
715
|
+
plugins: [
|
|
716
|
+
forbidDeepStorefrontImportsPlugin(),
|
|
717
|
+
forbidExternalPackagesPlugin(),
|
|
718
|
+
ikasComponentUtilsPlugin(),
|
|
719
|
+
],
|
|
218
720
|
splitting: true,
|
|
219
721
|
outdir: serverDir,
|
|
220
722
|
entryNames: "[name]",
|
|
221
723
|
chunkNames: "chunk-[hash]",
|
|
724
|
+
metafile: true,
|
|
222
725
|
});
|
|
223
726
|
// Client build with code splitting (metafile enabled for dependency tracking)
|
|
224
727
|
const clientBuildResult = await esbuild.build({
|
|
@@ -226,9 +729,13 @@ export async function compileAllComponents(components, globalStylesPath) {
|
|
|
226
729
|
entryPoints,
|
|
227
730
|
format: "esm",
|
|
228
731
|
platform: "browser",
|
|
229
|
-
target:
|
|
732
|
+
target: SHARED_BUILD_TARGET,
|
|
230
733
|
external: CLIENT_EXTERNALS,
|
|
231
|
-
plugins: [
|
|
734
|
+
plugins: [
|
|
735
|
+
forbidDeepStorefrontImportsPlugin(),
|
|
736
|
+
forbidExternalPackagesPlugin(),
|
|
737
|
+
ikasComponentUtilsPlugin(),
|
|
738
|
+
],
|
|
232
739
|
splitting: true,
|
|
233
740
|
outdir: clientDir,
|
|
234
741
|
entryNames: "[name]",
|
|
@@ -269,17 +776,29 @@ export async function compileAllComponents(components, globalStylesPath) {
|
|
|
269
776
|
chunks.set(key, { serverJs, clientJs });
|
|
270
777
|
}
|
|
271
778
|
}
|
|
272
|
-
// Build dependency maps from
|
|
273
|
-
|
|
779
|
+
// Build dependency maps from BOTH the server and client metafiles.
|
|
780
|
+
//
|
|
781
|
+
// Only the client metafile used to be consulted here. But SERVER_EXTERNALS
|
|
782
|
+
// differs from CLIENT_EXTERNALS (e.g. preact-render-to-string is external on
|
|
783
|
+
// the server only), so esbuild splits the two builds differently and emits
|
|
784
|
+
// server-only shared chunks whose names have no client twin. Those chunks are
|
|
785
|
+
// written to disk and captured in `chunks` above, yet — with a client-only
|
|
786
|
+
// graph — they never entered any component's chunk closure, so publish pruned
|
|
787
|
+
// them as orphaned. The result: `compiledServerJs` went missing on the shared
|
|
788
|
+
// module and the server bundle imported a `./chunk-XXXX.js` that was never
|
|
789
|
+
// emitted ("Could not resolve ./chunk-XXXX.js"). Merging both graphs keeps
|
|
790
|
+
// server and client chunk closures symmetric.
|
|
791
|
+
const clientMetafile = clientBuildResult.metafile;
|
|
792
|
+
const serverMetafile = serverBuildResult.metafile;
|
|
274
793
|
const entryDirSet = new Map(); // entryId → absolute dir of entry file
|
|
275
794
|
for (const comp of components) {
|
|
276
795
|
entryDirSet.set(comp.id, path.dirname(path.resolve(process.cwd(), comp.entryPath)));
|
|
277
796
|
}
|
|
278
|
-
//
|
|
797
|
+
// CSS is a browser-only concern, so entry/chunk input source maps are derived
|
|
798
|
+
// from the CLIENT metafile only (they feed the CSS collection passes below).
|
|
279
799
|
const entryInputs = new Map(); // entryId → list of input paths
|
|
280
800
|
const chunkInputs = new Map(); // chunkId → list of input paths
|
|
281
|
-
const
|
|
282
|
-
for (const [outputPath, outputMeta] of Object.entries(metafile.outputs)) {
|
|
801
|
+
for (const [outputPath, outputMeta] of Object.entries(clientMetafile.outputs)) {
|
|
283
802
|
const baseName = path.basename(outputPath, ".js");
|
|
284
803
|
const inputPaths = Object.keys(outputMeta.inputs || {});
|
|
285
804
|
if (entryIds.has(baseName)) {
|
|
@@ -289,40 +808,49 @@ export async function compileAllComponents(components, globalStylesPath) {
|
|
|
289
808
|
chunkInputs.set(baseName, inputPaths);
|
|
290
809
|
}
|
|
291
810
|
}
|
|
292
|
-
//
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
continue;
|
|
297
|
-
const imports = outputMeta.imports || [];
|
|
298
|
-
for (const imp of imports) {
|
|
299
|
-
const impBaseName = path.basename(imp.path, ".js");
|
|
300
|
-
if (chunkInputs.has(impBaseName)) {
|
|
301
|
-
if (!chunkConsumers.has(impBaseName)) {
|
|
302
|
-
chunkConsumers.set(impBaseName, []);
|
|
303
|
-
}
|
|
304
|
-
chunkConsumers.get(impBaseName).push(baseName);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
// Build chunk→chunk dependency graph and topologically sort chunks
|
|
309
|
-
// so that chunks are evaluated in dependency-first order
|
|
811
|
+
// Recognize any emitted chunk — server OR client — by its output basename.
|
|
812
|
+
// `chunks` was populated above from both the server and client output dirs.
|
|
813
|
+
const allChunkIds = new Set(chunks.keys());
|
|
814
|
+
const chunkConsumers = new Map(); // chunkId → list of entry IDs that import it
|
|
310
815
|
const chunkDeps = new Map(); // chunkId → list of chunk IDs it depends on
|
|
311
|
-
for (const chunkId of
|
|
816
|
+
for (const chunkId of allChunkIds) {
|
|
312
817
|
chunkDeps.set(chunkId, []);
|
|
313
818
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
819
|
+
// Fold one metafile's output graph into the shared consumer/dependency maps.
|
|
820
|
+
// Called for both builds so server-only chunks are tracked alongside client ones.
|
|
821
|
+
const ingestMetafile = (mf) => {
|
|
822
|
+
for (const [outputPath, outputMeta] of Object.entries(mf.outputs)) {
|
|
823
|
+
const baseName = path.basename(outputPath, ".js");
|
|
824
|
+
const imports = outputMeta.imports || [];
|
|
825
|
+
if (entryIds.has(baseName)) {
|
|
826
|
+
// entry → chunk consumer edges
|
|
827
|
+
for (const imp of imports) {
|
|
828
|
+
const impBaseName = path.basename(imp.path, ".js");
|
|
829
|
+
if (!allChunkIds.has(impBaseName))
|
|
830
|
+
continue;
|
|
831
|
+
if (!chunkConsumers.has(impBaseName)) {
|
|
832
|
+
chunkConsumers.set(impBaseName, []);
|
|
833
|
+
}
|
|
834
|
+
const consumers = chunkConsumers.get(impBaseName);
|
|
835
|
+
if (!consumers.includes(baseName))
|
|
836
|
+
consumers.push(baseName);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
else if (allChunkIds.has(baseName)) {
|
|
840
|
+
// chunk → chunk dependency edges
|
|
841
|
+
for (const imp of imports) {
|
|
842
|
+
const impBaseName = path.basename(imp.path, ".js");
|
|
843
|
+
if (allChunkIds.has(impBaseName) && impBaseName !== baseName) {
|
|
844
|
+
const deps = chunkDeps.get(baseName);
|
|
845
|
+
if (!deps.includes(impBaseName))
|
|
846
|
+
deps.push(impBaseName);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
323
849
|
}
|
|
324
850
|
}
|
|
325
|
-
}
|
|
851
|
+
};
|
|
852
|
+
ingestMetafile(clientMetafile);
|
|
853
|
+
ingestMetafile(serverMetafile);
|
|
326
854
|
// Kahn's algorithm for topological sort
|
|
327
855
|
const inDegree = new Map();
|
|
328
856
|
for (const chunkId of chunkDeps.keys()) {
|