@wix/origami-site-runtime 1.0.5 → 1.0.7
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/README.md +2 -0
- package/package.json +4 -4
- package/src/cssPlugins/mixins.js +45 -5
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Wix import site runtime
|
|
2
2
|
|
|
3
|
+
Before local tests, run `pnpm -r run build` from the repository root to build workspace dependencies in order.
|
|
4
|
+
|
|
3
5
|
Static routes come from item folders under `src/pages`. The home page is the page folder in parentheses, e.g. `src/pages/(home)`; a folder in parentheses is left out of the URL. Each document loads its item's `_generated/index.jsx`; `pages/error404` supplies an optional custom 404 page.
|
|
4
6
|
|
|
5
7
|
## Routing roadmap
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/origami-site-runtime",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Vite development and build helpers for wix-import static sites",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "rm -rf dist tsconfig.tsbuildinfo && tsc -b .",
|
|
11
11
|
"lint": "oxlint .",
|
|
12
|
-
"test": "
|
|
12
|
+
"test": "node --test test/*.spec.js",
|
|
13
13
|
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
14
14
|
"test:browser": "node test/spx.browser.mjs && node test/semanticContainer.browser.mjs"
|
|
15
15
|
},
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@babel/types": "^7.25.2",
|
|
20
20
|
"@wix/builder-error-pages": "^1.1.6",
|
|
21
21
|
"@wix/builder-piler-components": "^1.6.7",
|
|
22
|
-
"@wix/origami-runtime": "0.
|
|
22
|
+
"@wix/origami-runtime": "0.11.0",
|
|
23
23
|
"postcss": "^8.5.3",
|
|
24
24
|
"postcss-custom-media": "^12.0.1",
|
|
25
25
|
"react": "^18.3.1",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"./default-error-404": "./src/default-error-404.jsx"
|
|
65
65
|
},
|
|
66
66
|
"type": "module",
|
|
67
|
-
"falconPackageHash": "
|
|
67
|
+
"falconPackageHash": "e9e3b817c585e6457e3d38733cf7c652e682ac829c1f238836f89c53"
|
|
68
68
|
}
|
package/src/cssPlugins/mixins.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import postcss from 'postcss'
|
|
2
|
+
|
|
3
|
+
const MAX_EXPANSION_DEPTH = 64
|
|
4
|
+
const MAX_CLONED_NODES = 100_000
|
|
5
|
+
const MAX_CLONED_BYTES = 10 * 1024 * 1024
|
|
6
|
+
|
|
1
7
|
/** @param {import('postcss').AtRule} atRule */
|
|
2
8
|
const mixinName = atRule => atRule.params.trim().replace(/\(\)$/, '')
|
|
3
9
|
|
|
@@ -14,10 +20,44 @@ export const mixinsPlugin = {
|
|
|
14
20
|
bodies.set(mixinName(atRule), body.nodes ?? [])
|
|
15
21
|
atRule.remove()
|
|
16
22
|
})
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
23
|
+
// Share budgets across all call sites, including intermediate bodies that are later replaced.
|
|
24
|
+
// Count descendants too: cloning a rule also clones its entire subtree.
|
|
25
|
+
let clonedNodes = 0
|
|
26
|
+
let clonedBytes = 0
|
|
27
|
+
/** @param {import('postcss').Root} container
|
|
28
|
+
* @param {string[]} stack */
|
|
29
|
+
const expand = (container, stack) => {
|
|
30
|
+
container.walkAtRules('apply', atRule => {
|
|
31
|
+
const name = mixinName(atRule)
|
|
32
|
+
const body = bodies.get(name)
|
|
33
|
+
if (!body) throw new Error(`@apply ${atRule.params} has no @mixin definition`)
|
|
34
|
+
if (stack.includes(name)) throw new Error(`Cyclic @apply: ${[...stack, name].join(' -> ')}`)
|
|
35
|
+
if (stack.length >= MAX_EXPANSION_DEPTH) {
|
|
36
|
+
throw new Error(`@apply ${name} exceeds maximum expansion depth (${MAX_EXPANSION_DEPTH})`)
|
|
37
|
+
}
|
|
38
|
+
const pending = [...body]
|
|
39
|
+
while (pending.length) {
|
|
40
|
+
const node = pending.pop()
|
|
41
|
+
if (++clonedNodes > MAX_CLONED_NODES) {
|
|
42
|
+
throw new Error(`@apply ${name} exceeds stylesheet cloned-node budget (${MAX_CLONED_NODES})`)
|
|
43
|
+
}
|
|
44
|
+
if (node && 'nodes' in node && node.nodes) {
|
|
45
|
+
for (const child of node.nodes) pending.push(child)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
for (const node of body) {
|
|
49
|
+
clonedBytes += Buffer.byteLength((node.raws.before ?? '') + node.toString(), 'utf8')
|
|
50
|
+
if (clonedBytes > MAX_CLONED_BYTES) {
|
|
51
|
+
throw new Error(`@apply ${name} exceeds stylesheet cloned-CSS byte budget (${MAX_CLONED_BYTES})`)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// PostCSS does not revisit nodes inserted in place of the current at-rule.
|
|
55
|
+
// Expand a clone first so nested uses resolve without changing the definition.
|
|
56
|
+
const expanded = postcss.root({ nodes: body.map(node => node.clone()) })
|
|
57
|
+
expand(expanded, [...stack, name])
|
|
58
|
+
atRule.replaceWith(...expanded.nodes)
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
expand(root, [])
|
|
22
62
|
},
|
|
23
63
|
}
|