boss-css 0.0.1 → 0.0.2
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 +1 -0
- package/dist/_virtual/rolldown_runtime.cjs +43 -0
- package/dist/_virtual/rolldown_runtime.mjs +20 -0
- package/dist/api/browser.cjs +54 -0
- package/dist/api/browser.mjs +48 -0
- package/dist/api/config.cjs +94 -0
- package/dist/api/config.mjs +91 -0
- package/dist/api/css.cjs +304 -0
- package/dist/api/css.mjs +303 -0
- package/dist/api/dictionary.cjs +218 -0
- package/dist/api/dictionary.mjs +215 -0
- package/dist/api/file/dts.cjs +21 -0
- package/dist/api/file/dts.mjs +21 -0
- package/dist/api/file/file.cjs +123 -0
- package/dist/api/file/file.mjs +120 -0
- package/dist/api/file/js.cjs +118 -0
- package/dist/api/file/js.mjs +116 -0
- package/dist/api/names.cjs +52 -0
- package/dist/api/names.mjs +46 -0
- package/dist/api/noopCss.cjs +37 -0
- package/dist/api/noopCss.mjs +36 -0
- package/dist/api/propTree.cjs +54 -0
- package/dist/api/propTree.mjs +48 -0
- package/dist/api/server.cjs +112 -0
- package/dist/api/server.mjs +106 -0
- package/dist/cli/build.cjs +1 -0
- package/dist/cli/build.mjs +3 -0
- package/dist/cli/index.cjs +30 -0
- package/dist/cli/index.mjs +29 -0
- package/dist/cli/tasks/build.cjs +24 -0
- package/dist/cli/tasks/build.mjs +23 -0
- package/dist/cli/tasks/choose.cjs +47 -0
- package/dist/cli/tasks/choose.mjs +46 -0
- package/dist/cli/tasks/compile.cjs +68 -0
- package/dist/cli/tasks/compile.mjs +67 -0
- package/dist/cli/tasks/dev.cjs +51 -0
- package/dist/cli/tasks/dev.mjs +48 -0
- package/dist/cli/tasks/init.cjs +1835 -0
- package/dist/cli/tasks/init.mjs +1831 -0
- package/dist/cli/tasks/watch.cjs +38 -0
- package/dist/cli/tasks/watch.mjs +37 -0
- package/dist/cli/templates/init.cjs +82 -0
- package/dist/cli/templates/init.mjs +78 -0
- package/dist/cli/types.cjs +13 -0
- package/dist/cli/types.mjs +13 -0
- package/dist/cli/utils.cjs +43 -0
- package/dist/cli/utils.mjs +41 -0
- package/dist/compile/classname-strategy.cjs +79 -0
- package/dist/compile/classname-strategy.mjs +77 -0
- package/dist/compile/classname.cjs +366 -0
- package/dist/compile/classname.mjs +360 -0
- package/dist/compile/index.cjs +238 -0
- package/dist/compile/index.mjs +235 -0
- package/dist/compile/jsx.cjs +803 -0
- package/dist/compile/jsx.mjs +800 -0
- package/dist/compile/prepared.cjs +88 -0
- package/dist/compile/prepared.mjs +87 -0
- package/dist/compile/runtime.cjs +33 -0
- package/dist/compile/runtime.mjs +32 -0
- package/dist/compile/transform.cjs +371 -0
- package/dist/compile/transform.mjs +369 -0
- package/dist/cx/index.cjs +93 -0
- package/dist/cx/index.mjs +85 -0
- package/dist/detect-fw/index.cjs +384 -0
- package/dist/detect-fw/index.mjs +379 -0
- package/dist/dev/client.cjs +39 -0
- package/dist/dev/client.mjs +38 -0
- package/dist/dev/plugin/browser.cjs +11 -0
- package/dist/dev/plugin/browser.mjs +9 -0
- package/dist/dev/plugin/server.cjs +86 -0
- package/dist/dev/plugin/server.mjs +78 -0
- package/dist/dev/port.cjs +46 -0
- package/dist/dev/port.mjs +43 -0
- package/dist/dev/runtime.cjs +28 -0
- package/dist/dev/runtime.mjs +29 -0
- package/dist/dev/server.cjs +808 -0
- package/dist/dev/server.mjs +805 -0
- package/dist/dev/shared.cjs +6 -0
- package/dist/dev/shared.mjs +5 -0
- package/dist/eslint-plugin/index.cjs +66 -0
- package/dist/eslint-plugin/index.mjs +66 -0
- package/dist/eslint-plugin/rules/classnames-only.cjs +68 -0
- package/dist/eslint-plugin/rules/classnames-only.mjs +68 -0
- package/dist/eslint-plugin/rules/format-classnames.cjs +137 -0
- package/dist/eslint-plugin/rules/format-classnames.mjs +136 -0
- package/dist/eslint-plugin/rules/no-unknown-classes.cjs +119 -0
- package/dist/eslint-plugin/rules/no-unknown-classes.mjs +119 -0
- package/dist/eslint-plugin/rules/prefer-classnames.cjs +69 -0
- package/dist/eslint-plugin/rules/prefer-classnames.mjs +69 -0
- package/dist/eslint-plugin/rules/prefer-token-values.cjs +197 -0
- package/dist/eslint-plugin/rules/prefer-token-values.mjs +197 -0
- package/dist/eslint-plugin/rules/props-only.cjs +115 -0
- package/dist/eslint-plugin/rules/props-only.mjs +115 -0
- package/dist/eslint-plugin/rules/redundant-cx.cjs +66 -0
- package/dist/eslint-plugin/rules/redundant-cx.mjs +66 -0
- package/dist/eslint-plugin/rules/require-prop-functions.cjs +130 -0
- package/dist/eslint-plugin/rules/require-prop-functions.mjs +130 -0
- package/dist/eslint-plugin/utils/api.cjs +30 -0
- package/dist/eslint-plugin/utils/api.mjs +29 -0
- package/dist/eslint-plugin/utils/ast.cjs +119 -0
- package/dist/eslint-plugin/utils/ast.mjs +112 -0
- package/dist/eslint-plugin/utils/boss-classes.cjs +185 -0
- package/dist/eslint-plugin/utils/boss-classes.mjs +175 -0
- package/dist/eslint-plugin/utils/defaults.cjs +99 -0
- package/dist/eslint-plugin/utils/defaults.mjs +93 -0
- package/dist/eslint-plugin/utils/format.cjs +20 -0
- package/dist/eslint-plugin/utils/format.mjs +19 -0
- package/dist/eslint-plugin/utils/order.cjs +76 -0
- package/dist/eslint-plugin/utils/order.mjs +76 -0
- package/dist/eslint-plugin/utils/property-order.cjs +449 -0
- package/dist/eslint-plugin/utils/property-order.mjs +448 -0
- package/dist/eslint-plugin/utils/static.cjs +36 -0
- package/dist/eslint-plugin/utils/static.mjs +35 -0
- package/dist/fontsource/directory.cjs +39588 -0
- package/dist/fontsource/directory.mjs +39587 -0
- package/dist/fontsource/server.cjs +291 -0
- package/dist/fontsource/server.mjs +282 -0
- package/dist/index.cjs +10 -0
- package/dist/index.mjs +6 -0
- package/dist/log/browser.cjs +28 -0
- package/dist/log/browser.mjs +28 -0
- package/dist/log/server.cjs +32 -0
- package/dist/log/server.mjs +30 -0
- package/dist/merge/index.cjs +590 -0
- package/dist/merge/index.mjs +586 -0
- package/dist/native/browser.cjs +78 -0
- package/dist/native/browser.mjs +77 -0
- package/dist/native/server.cjs +180 -0
- package/dist/native/server.mjs +176 -0
- package/dist/native/styleTypes.cjs +168 -0
- package/dist/native/styleTypes.mjs +164 -0
- package/dist/parser/classname/server.cjs +239 -0
- package/dist/parser/classname/server.mjs +232 -0
- package/dist/parser/jsx/browser.cjs +66 -0
- package/dist/parser/jsx/browser.mjs +63 -0
- package/dist/parser/jsx/extractCode.cjs +99 -0
- package/dist/parser/jsx/extractCode.mjs +98 -0
- package/dist/parser/jsx/extractPrepared.cjs +123 -0
- package/dist/parser/jsx/extractPrepared.mjs +122 -0
- package/dist/parser/jsx/extractProps.cjs +234 -0
- package/dist/parser/jsx/extractProps.mjs +232 -0
- package/dist/parser/jsx/isDOMProp.cjs +17 -0
- package/dist/parser/jsx/isDOMProp.mjs +15 -0
- package/dist/parser/jsx/native.cjs +110 -0
- package/dist/parser/jsx/native.mjs +108 -0
- package/dist/parser/jsx/runtime.cjs +4 -0
- package/dist/parser/jsx/runtime.mjs +3 -0
- package/dist/parser/jsx/server.cjs +278 -0
- package/dist/parser/jsx/server.mjs +268 -0
- package/dist/postcss/index.cjs +16 -0
- package/dist/postcss/index.mjs +16 -0
- package/dist/prop/at/runtime-only.cjs +90 -0
- package/dist/prop/at/runtime-only.mjs +88 -0
- package/dist/prop/at/server.cjs +282 -0
- package/dist/prop/at/server.mjs +268 -0
- package/dist/prop/at/shared.cjs +153 -0
- package/dist/prop/at/shared.mjs +144 -0
- package/dist/prop/bosswind/browser.cjs +18 -0
- package/dist/prop/bosswind/browser.mjs +16 -0
- package/dist/prop/bosswind/runtime-only.cjs +18 -0
- package/dist/prop/bosswind/runtime-only.mjs +16 -0
- package/dist/prop/bosswind/server.cjs +81 -0
- package/dist/prop/bosswind/server.mjs +72 -0
- package/dist/prop/bosswind/shared.cjs +861 -0
- package/dist/prop/bosswind/shared.mjs +855 -0
- package/dist/prop/bosswind/tailwind-theme.cjs +703 -0
- package/dist/prop/bosswind/tailwind-theme.mjs +702 -0
- package/dist/prop/child/runtime-only.cjs +18 -0
- package/dist/prop/child/runtime-only.mjs +15 -0
- package/dist/prop/child/server.cjs +81 -0
- package/dist/prop/child/server.mjs +72 -0
- package/dist/prop/css/getDtsTemplate.cjs +65 -0
- package/dist/prop/css/getDtsTemplate.mjs +63 -0
- package/dist/prop/css/runtime-only.cjs +14 -0
- package/dist/prop/css/runtime-only.mjs +13 -0
- package/dist/prop/css/server.cjs +99 -0
- package/dist/prop/css/server.mjs +90 -0
- package/dist/prop/pseudo/runtime-only.cjs +23 -0
- package/dist/prop/pseudo/runtime-only.mjs +21 -0
- package/dist/prop/pseudo/server.cjs +91 -0
- package/dist/prop/pseudo/server.mjs +82 -0
- package/dist/prop/pseudo/shared.cjs +61 -0
- package/dist/prop/pseudo/shared.mjs +60 -0
- package/dist/reset/server.cjs +34 -0
- package/dist/reset/server.mjs +26 -0
- package/dist/runtime/index.cjs +119 -0
- package/dist/runtime/index.mjs +118 -0
- package/dist/runtime/preact.cjs +4 -0
- package/dist/runtime/preact.mjs +3 -0
- package/dist/runtime/qwik.cjs +21 -0
- package/dist/runtime/qwik.mjs +18 -0
- package/dist/runtime/react.cjs +4 -0
- package/dist/runtime/react.mjs +3 -0
- package/dist/runtime/solid.cjs +15 -0
- package/dist/runtime/solid.mjs +14 -0
- package/dist/runtime/stencil.cjs +25 -0
- package/dist/runtime/stencil.mjs +21 -0
- package/dist/runtime/style.cjs +14 -0
- package/dist/runtime/style.mjs +13 -0
- package/dist/shared/boundaries.cjs +288 -0
- package/dist/shared/boundaries.mjs +285 -0
- package/dist/shared/customCss.cjs +212 -0
- package/dist/shared/customCss.mjs +211 -0
- package/dist/shared/debug.cjs +76 -0
- package/dist/shared/debug.mjs +74 -0
- package/dist/shared/file.cjs +21 -0
- package/dist/shared/file.mjs +19 -0
- package/dist/shared/framework.cjs +10 -0
- package/dist/shared/framework.mjs +9 -0
- package/dist/shared/json.cjs +58 -0
- package/dist/shared/json.mjs +57 -0
- package/dist/shared/types.cjs +11 -0
- package/dist/shared/types.mjs +10 -0
- package/dist/strategy/classic/runtime-only.cjs +190 -0
- package/dist/strategy/classic/runtime-only.mjs +186 -0
- package/dist/strategy/classname-first/runtime-only.cjs +138 -0
- package/dist/strategy/classname-first/runtime-only.mjs +134 -0
- package/dist/strategy/classname-first/server.cjs +139 -0
- package/dist/strategy/classname-first/server.mjs +133 -0
- package/dist/strategy/classname-only/server.cjs +43 -0
- package/dist/strategy/classname-only/server.mjs +35 -0
- package/dist/strategy/inline-first/browser.cjs +61 -0
- package/dist/strategy/inline-first/browser.mjs +58 -0
- package/dist/strategy/inline-first/runtime-only.cjs +159 -0
- package/dist/strategy/inline-first/runtime-only.mjs +155 -0
- package/dist/strategy/inline-first/server.cjs +92 -0
- package/dist/strategy/inline-first/server.mjs +83 -0
- package/dist/strategy/runtime/runtime-only.cjs +24 -0
- package/dist/strategy/runtime/runtime-only.mjs +22 -0
- package/dist/strategy/runtime/server.cjs +72 -0
- package/dist/strategy/runtime/server.mjs +63 -0
- package/dist/strategy/runtime-only/css.cjs +183 -0
- package/dist/strategy/runtime-only/css.mjs +181 -0
- package/dist/tasks/build.cjs +88 -0
- package/dist/tasks/build.mjs +84 -0
- package/dist/tasks/compile.cjs +12 -0
- package/dist/tasks/compile.mjs +12 -0
- package/dist/tasks/postcss.cjs +116 -0
- package/dist/tasks/postcss.mjs +113 -0
- package/dist/tasks/session.cjs +46 -0
- package/dist/tasks/session.mjs +42 -0
- package/dist/tasks/watch.cjs +102 -0
- package/dist/tasks/watch.mjs +99 -0
- package/dist/transform/cache.cjs +24 -0
- package/dist/transform/cache.mjs +21 -0
- package/dist/transform/processFile.cjs +26 -0
- package/dist/transform/processFile.mjs +24 -0
- package/dist/use/token/browser.cjs +65 -0
- package/dist/use/token/browser.mjs +61 -0
- package/dist/use/token/runtime-only.cjs +245 -0
- package/dist/use/token/runtime-only.mjs +239 -0
- package/dist/use/token/server.cjs +325 -0
- package/dist/use/token/server.mjs +313 -0
- package/dist/use/token/vars.cjs +47 -0
- package/dist/use/token/vars.mjs +46 -0
- package/package.json +300 -4
- package/src/api/config.d.ts +1 -0
- package/src/fontsource/types.d.ts +50 -0
- package/src/packages/document-create-element/createElement.browser.js +3 -0
- package/src/packages/document-create-element/createElement.js +7 -0
- package/src/packages/document-create-element/package.json +17 -0
- package/src/packages/is-css-prop/browser.js +13 -0
- package/src/packages/is-css-prop/index.js +13 -0
- package/src/packages/is-css-prop/package-lock.json +52 -0
- package/src/packages/is-css-prop/package.json +17 -0
- package/src/prop/css/csstype.json +4387 -0
- package/src/prop/css/package.json +3 -0
- package/src/reset/reset.css +259 -0
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { parseSync, printSync } from "@swc/core";
|
|
2
|
+
|
|
3
|
+
//#region src/compile/classname.ts
|
|
4
|
+
const tokenPrefix = "$$.token.";
|
|
5
|
+
const rewriteClassNameTokens = (input) => {
|
|
6
|
+
if (!input.includes(tokenPrefix) && !input.includes("{")) return input;
|
|
7
|
+
return splitSelectors(input).flatMap((selector) => rewriteSelector(selector, { expandSingleGroup: false })).join(" ");
|
|
8
|
+
};
|
|
9
|
+
const rewriteClassNameTokensInText = (source, options = {}) => {
|
|
10
|
+
return rewriteQuotedSegments(source, ({ value, hasTemplateExpression }) => {
|
|
11
|
+
if (hasTemplateExpression) return null;
|
|
12
|
+
return rewriteClassNameTokensWithMap(value, options.mapToken);
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
const rewriteClassNameTokensInSource = (source, options) => {
|
|
16
|
+
const ext = options.filename.split(".").pop() ?? "";
|
|
17
|
+
const isTs = ext === "ts" || ext === "tsx";
|
|
18
|
+
const isJsx = [
|
|
19
|
+
"jsx",
|
|
20
|
+
"tsx",
|
|
21
|
+
"js",
|
|
22
|
+
"mjs",
|
|
23
|
+
"cjs"
|
|
24
|
+
].includes(ext);
|
|
25
|
+
const classNameProp = options.classNameProp ?? "className";
|
|
26
|
+
const mapToken = options.mapToken;
|
|
27
|
+
const parsed = parseSync(source, {
|
|
28
|
+
syntax: isTs ? "typescript" : "ecmascript",
|
|
29
|
+
tsx: isTs && isJsx,
|
|
30
|
+
jsx: !isTs && isJsx
|
|
31
|
+
});
|
|
32
|
+
const visit = (node, context = {}) => {
|
|
33
|
+
if (!node || typeof node !== "object") return;
|
|
34
|
+
if (Array.isArray(node)) {
|
|
35
|
+
node.forEach((child) => visit(child, context));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const current = node;
|
|
39
|
+
if (current.type === "JSXElement") rewriteClassNameTokensInElement(current, classNameProp, mapToken);
|
|
40
|
+
if (current.type === "CallExpression") rewriteClassNameTokensInCall(current, mapToken);
|
|
41
|
+
if (!context.inModuleSpecifier) {
|
|
42
|
+
if (current.type === "StringLiteral") {
|
|
43
|
+
const literal = current;
|
|
44
|
+
updateStringLiteral(literal, rewriteClassNameTokensWithMap(literal.value, mapToken));
|
|
45
|
+
}
|
|
46
|
+
if (current.type === "TemplateLiteral" && Array.isArray(current.expressions) && current.expressions.length === 0 && Array.isArray(current.quasis) && current.quasis.length) {
|
|
47
|
+
const firstQuasi = current.quasis[0];
|
|
48
|
+
if (firstQuasi) {
|
|
49
|
+
const rewritten = rewriteClassNameTokensWithMap(firstQuasi.cooked ?? "", mapToken);
|
|
50
|
+
firstQuasi.cooked = rewritten;
|
|
51
|
+
firstQuasi.raw = rewritten;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
for (const key of Object.keys(current)) {
|
|
56
|
+
const nextContext = (current.type === "ImportDeclaration" || current.type === "ExportAllDeclaration" || current.type === "ExportNamedDeclaration") && key === "source" ? {
|
|
57
|
+
...context,
|
|
58
|
+
inModuleSpecifier: true
|
|
59
|
+
} : context;
|
|
60
|
+
visit(current[key], nextContext);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
visit(parsed);
|
|
64
|
+
return printSync(parsed).code;
|
|
65
|
+
};
|
|
66
|
+
const rewriteClassNameTokensInCall = (expr, mapToken) => {
|
|
67
|
+
const callee = expr.callee;
|
|
68
|
+
if (callee.type !== "Identifier" || callee.value !== "$$") return;
|
|
69
|
+
if (expr.arguments.length !== 1) return;
|
|
70
|
+
const arg = expr.arguments[0].expression;
|
|
71
|
+
rewriteStringExpression(arg, mapToken);
|
|
72
|
+
};
|
|
73
|
+
const rewriteStringExpression = (expression, mapToken) => {
|
|
74
|
+
if (!expression) return;
|
|
75
|
+
if (expression.type === "StringLiteral") {
|
|
76
|
+
updateStringLiteral(expression, rewriteClassNameTokensWithMap(expression.value, mapToken));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (expression.type === "TemplateLiteral" && expression.expressions.length === 0 && expression.quasis.length) {
|
|
80
|
+
const firstQuasi = expression.quasis[0];
|
|
81
|
+
if (!firstQuasi) return;
|
|
82
|
+
const rewritten = rewriteClassNameTokensWithMap(firstQuasi.cooked ?? "", mapToken);
|
|
83
|
+
firstQuasi.cooked = rewritten;
|
|
84
|
+
firstQuasi.raw = rewritten;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const rewriteClassNameTokensInElement = (element, classNameProp = "className", mapToken) => {
|
|
88
|
+
const attributes = element.opening.attributes;
|
|
89
|
+
for (const attr of attributes) {
|
|
90
|
+
if (attr.type !== "JSXAttribute") continue;
|
|
91
|
+
if (!isClassAttribute(attr, classNameProp)) continue;
|
|
92
|
+
if (!attr.value) continue;
|
|
93
|
+
if (attr.value.type === "StringLiteral") {
|
|
94
|
+
updateStringLiteral(attr.value, rewriteClassNameTokensWithMap(attr.value.value, mapToken));
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (attr.value.type === "JSXExpressionContainer") {
|
|
98
|
+
const expression = attr.value.expression;
|
|
99
|
+
rewriteStringExpression(expression, mapToken);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
const isClassAttribute = (attr, classNameProp) => {
|
|
104
|
+
return attr.name.type === "Identifier" && attr.name.value === classNameProp;
|
|
105
|
+
};
|
|
106
|
+
const rewriteSelector = (selector, options) => {
|
|
107
|
+
const grouped = parseGroupedSelector(selector);
|
|
108
|
+
if (grouped) {
|
|
109
|
+
const nextEntries = grouped.entries.map((entry$1) => ({
|
|
110
|
+
name: entry$1.name,
|
|
111
|
+
rawValue: rewriteTokenValue(entry$1.rawValue)
|
|
112
|
+
}));
|
|
113
|
+
if (nextEntries.length > 1 || options.expandSingleGroup) return [...nextEntries].sort((a, b) => a.name.localeCompare(b.name)).map((entry$1) => `${grouped.prefix}:${entry$1.name}:${entry$1.rawValue}`);
|
|
114
|
+
const [entry] = nextEntries;
|
|
115
|
+
return [`${grouped.prefix}:{${entry.name}:${entry.rawValue}}`];
|
|
116
|
+
}
|
|
117
|
+
const fragments = splitFragments(selector);
|
|
118
|
+
if (fragments.length < 2) return [selector];
|
|
119
|
+
const rawValue = fragments.at(-1) ?? "";
|
|
120
|
+
const nextValue = rewriteTokenValue(rawValue);
|
|
121
|
+
if (nextValue === rawValue) return [selector];
|
|
122
|
+
return [`${fragments.slice(0, -1).join(":")}:${nextValue}`];
|
|
123
|
+
};
|
|
124
|
+
const rewriteClassNameTokensWithMap = (input, mapToken) => {
|
|
125
|
+
if (!mapToken) return rewriteClassNameTokens(input);
|
|
126
|
+
const selectors = splitSelectors(input).flatMap((selector) => rewriteSelector(selector, { expandSingleGroup: true }));
|
|
127
|
+
let didChange = selectors.join(" ") !== input;
|
|
128
|
+
const mapped = selectors.map((selector) => {
|
|
129
|
+
if (!mapToken) return selector;
|
|
130
|
+
const next = mapToken(selector);
|
|
131
|
+
if (next && next !== selector) {
|
|
132
|
+
didChange = true;
|
|
133
|
+
return next;
|
|
134
|
+
}
|
|
135
|
+
return selector;
|
|
136
|
+
});
|
|
137
|
+
if (!didChange) return input;
|
|
138
|
+
return mapped.join(" ");
|
|
139
|
+
};
|
|
140
|
+
const rewriteTokenValue = (rawValue) => {
|
|
141
|
+
if (!rawValue.startsWith(tokenPrefix)) return rawValue;
|
|
142
|
+
const fragments = rawValue.slice(9).split(".").filter(Boolean);
|
|
143
|
+
if (fragments.length < 2) return rawValue;
|
|
144
|
+
return fragments.slice(1).join(".");
|
|
145
|
+
};
|
|
146
|
+
const updateStringLiteral = (literal, nextValue) => {
|
|
147
|
+
literal.value = nextValue;
|
|
148
|
+
literal.raw = JSON.stringify(nextValue);
|
|
149
|
+
};
|
|
150
|
+
const splitSelectors = (input) => splitOutside(input, " ");
|
|
151
|
+
const splitFragments = (selector) => splitOutside(selector, ":");
|
|
152
|
+
const splitGroupedEntries = (body) => splitOutside(body, ";");
|
|
153
|
+
const splitGroupedEntry = (entry) => splitOnceOutside(entry, ":");
|
|
154
|
+
const parseGroupedSelector = (selector) => {
|
|
155
|
+
if (!selector.endsWith("}")) return null;
|
|
156
|
+
const groupStart = findGroupStart(selector);
|
|
157
|
+
if (groupStart === -1) return null;
|
|
158
|
+
const prefix = selector.slice(0, groupStart);
|
|
159
|
+
const entries = splitGroupedEntries(selector.slice(groupStart + 2, -1)).map((entry) => entry.trim()).filter((entry) => Boolean(entry)).map((entry) => {
|
|
160
|
+
const parts = splitGroupedEntry(entry);
|
|
161
|
+
if (!parts) return null;
|
|
162
|
+
const [name, rawValue] = parts;
|
|
163
|
+
return {
|
|
164
|
+
name: name.trim(),
|
|
165
|
+
rawValue: rawValue.trim()
|
|
166
|
+
};
|
|
167
|
+
}).filter((entry) => Boolean(entry));
|
|
168
|
+
if (!entries.length) return null;
|
|
169
|
+
return {
|
|
170
|
+
prefix,
|
|
171
|
+
entries
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
const splitOutside = (input, delimiter) => {
|
|
175
|
+
const results = [];
|
|
176
|
+
let current = "";
|
|
177
|
+
let braceDepth = 0;
|
|
178
|
+
let bracketDepth = 0;
|
|
179
|
+
for (const char of input) {
|
|
180
|
+
if (char === "{") braceDepth += 1;
|
|
181
|
+
if (char === "}") braceDepth = Math.max(0, braceDepth - 1);
|
|
182
|
+
if (char === "[") bracketDepth += 1;
|
|
183
|
+
if (char === "]") bracketDepth = Math.max(0, bracketDepth - 1);
|
|
184
|
+
if (char === delimiter && braceDepth === 0 && bracketDepth === 0) {
|
|
185
|
+
if (current) results.push(current);
|
|
186
|
+
current = "";
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
current += char;
|
|
190
|
+
}
|
|
191
|
+
if (current) results.push(current);
|
|
192
|
+
return results;
|
|
193
|
+
};
|
|
194
|
+
const splitOnceOutside = (input, delimiter) => {
|
|
195
|
+
let braceDepth = 0;
|
|
196
|
+
let bracketDepth = 0;
|
|
197
|
+
for (let i = 0; i < input.length; i += 1) {
|
|
198
|
+
const char = input[i];
|
|
199
|
+
if (char === "{") braceDepth += 1;
|
|
200
|
+
if (char === "}") braceDepth = Math.max(0, braceDepth - 1);
|
|
201
|
+
if (char === "[") bracketDepth += 1;
|
|
202
|
+
if (char === "]") bracketDepth = Math.max(0, bracketDepth - 1);
|
|
203
|
+
if (char === delimiter && braceDepth === 0 && bracketDepth === 0) return [input.slice(0, i), input.slice(i + 1)];
|
|
204
|
+
}
|
|
205
|
+
return null;
|
|
206
|
+
};
|
|
207
|
+
const findGroupStart = (selector) => {
|
|
208
|
+
let bracketDepth = 0;
|
|
209
|
+
for (let i = 0; i < selector.length - 1; i += 1) {
|
|
210
|
+
const char = selector[i];
|
|
211
|
+
if (char === "[") bracketDepth += 1;
|
|
212
|
+
if (char === "]") bracketDepth = Math.max(0, bracketDepth - 1);
|
|
213
|
+
if (bracketDepth === 0 && selector[i] === ":" && selector[i + 1] === "{") return i;
|
|
214
|
+
}
|
|
215
|
+
return -1;
|
|
216
|
+
};
|
|
217
|
+
const stripImportantSuffix = (fragment) => {
|
|
218
|
+
return fragment && fragment.endsWith("!") ? fragment.slice(0, -1) : fragment;
|
|
219
|
+
};
|
|
220
|
+
const getChildSelector = (fragment) => {
|
|
221
|
+
if (!fragment || !fragment.startsWith("[") || !fragment.endsWith("]")) return null;
|
|
222
|
+
return fragment.slice(1, -1);
|
|
223
|
+
};
|
|
224
|
+
const isSingleWordToken = (token) => /^[a-zA-Z]+$/.test(token);
|
|
225
|
+
const isBossSelectorToken = (selector, api) => {
|
|
226
|
+
if (isSingleWordToken(selector)) return false;
|
|
227
|
+
if (parseGroupedSelector(selector)) return true;
|
|
228
|
+
const rawFragments = splitFragments(selector);
|
|
229
|
+
if (!rawFragments.length) return false;
|
|
230
|
+
const resolveDescriptor = (fragment) => {
|
|
231
|
+
if (getChildSelector(fragment)) return api.dictionary.resolve("child");
|
|
232
|
+
return api.dictionary.resolve(fragment);
|
|
233
|
+
};
|
|
234
|
+
const firstDescriptor = resolveDescriptor(stripImportantSuffix(rawFragments[0])).descriptor;
|
|
235
|
+
if (!firstDescriptor) return false;
|
|
236
|
+
if (rawFragments.length === 1) return firstDescriptor.single === true;
|
|
237
|
+
const path = [];
|
|
238
|
+
for (const [index, fragment] of Object.entries(rawFragments)) {
|
|
239
|
+
const isLast = rawFragments.length === +index + 1;
|
|
240
|
+
if (path.length && isLast) continue;
|
|
241
|
+
const cleanedFragment = stripImportantSuffix(fragment);
|
|
242
|
+
const childSelector = getChildSelector(cleanedFragment);
|
|
243
|
+
if (childSelector) path.push("child", childSelector);
|
|
244
|
+
else path.push(cleanedFragment);
|
|
245
|
+
}
|
|
246
|
+
if (!path.length) return false;
|
|
247
|
+
const lastProp = path.at(-1);
|
|
248
|
+
const lastDescriptor = lastProp ? resolveDescriptor(lastProp).descriptor : null;
|
|
249
|
+
return Boolean(lastDescriptor?.isCSSProp);
|
|
250
|
+
};
|
|
251
|
+
const collectBossClassTokensInSource = (source, options) => {
|
|
252
|
+
const ext = options.filename.split(".").pop() ?? "";
|
|
253
|
+
const isTs = ext === "ts" || ext === "tsx";
|
|
254
|
+
const isJsx = [
|
|
255
|
+
"jsx",
|
|
256
|
+
"tsx",
|
|
257
|
+
"js",
|
|
258
|
+
"mjs",
|
|
259
|
+
"cjs"
|
|
260
|
+
].includes(ext);
|
|
261
|
+
const parsed = parseSync(source, {
|
|
262
|
+
syntax: isTs ? "typescript" : "ecmascript",
|
|
263
|
+
tsx: isTs && isJsx,
|
|
264
|
+
jsx: !isTs && isJsx
|
|
265
|
+
});
|
|
266
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
267
|
+
const visit = (node, context = {}) => {
|
|
268
|
+
if (!node || typeof node !== "object") return;
|
|
269
|
+
if (Array.isArray(node)) {
|
|
270
|
+
node.forEach((child) => visit(child, context));
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const current = node;
|
|
274
|
+
if (!context.inModuleSpecifier) {
|
|
275
|
+
if (current.type === "StringLiteral") splitSelectors(current.value).flatMap((selector) => rewriteSelector(selector, { expandSingleGroup: true })).forEach((selector) => {
|
|
276
|
+
if (isBossSelectorToken(selector, options.api)) tokens.add(selector);
|
|
277
|
+
});
|
|
278
|
+
if (current.type === "TemplateLiteral" && Array.isArray(current.expressions) && current.expressions.length === 0 && Array.isArray(current.quasis) && current.quasis.length) {
|
|
279
|
+
const firstQuasi = current.quasis[0];
|
|
280
|
+
if (firstQuasi?.cooked != null) splitSelectors(firstQuasi.cooked).flatMap((selector) => rewriteSelector(selector, { expandSingleGroup: true })).forEach((selector) => {
|
|
281
|
+
if (isBossSelectorToken(selector, options.api)) tokens.add(selector);
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
for (const key of Object.keys(current)) {
|
|
286
|
+
const nextContext = (current.type === "ImportDeclaration" || current.type === "ExportAllDeclaration" || current.type === "ExportNamedDeclaration") && key === "source" ? {
|
|
287
|
+
...context,
|
|
288
|
+
inModuleSpecifier: true
|
|
289
|
+
} : context;
|
|
290
|
+
visit(current[key], nextContext);
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
visit(parsed);
|
|
294
|
+
return tokens;
|
|
295
|
+
};
|
|
296
|
+
const collectBossClassTokensInText = (source, options) => {
|
|
297
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
298
|
+
rewriteQuotedSegments(source, ({ value, hasTemplateExpression }) => {
|
|
299
|
+
if (hasTemplateExpression) return null;
|
|
300
|
+
splitSelectors(value).flatMap((selector) => rewriteSelector(selector, { expandSingleGroup: true })).forEach((selector) => {
|
|
301
|
+
if (isBossSelectorToken(selector, options.api)) tokens.add(selector);
|
|
302
|
+
});
|
|
303
|
+
return null;
|
|
304
|
+
});
|
|
305
|
+
return tokens;
|
|
306
|
+
};
|
|
307
|
+
const rewriteQuotedSegments = (input, rewrite) => {
|
|
308
|
+
let output = "";
|
|
309
|
+
let index = 0;
|
|
310
|
+
const length = input.length;
|
|
311
|
+
while (index < length) {
|
|
312
|
+
const char = input[index];
|
|
313
|
+
if (char !== "\"" && char !== "'" && char !== "`") {
|
|
314
|
+
output += char;
|
|
315
|
+
index += 1;
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
const quote = char;
|
|
319
|
+
const start = index;
|
|
320
|
+
index += 1;
|
|
321
|
+
let value = "";
|
|
322
|
+
let escaped = false;
|
|
323
|
+
let hasTemplateExpression = false;
|
|
324
|
+
while (index < length) {
|
|
325
|
+
const current = input[index];
|
|
326
|
+
if (escaped) {
|
|
327
|
+
value += current;
|
|
328
|
+
escaped = false;
|
|
329
|
+
index += 1;
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
if (current === "\\") {
|
|
333
|
+
value += current;
|
|
334
|
+
escaped = true;
|
|
335
|
+
index += 1;
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
if (quote === "`" && current === "$" && input[index + 1] === "{") hasTemplateExpression = true;
|
|
339
|
+
if (current === quote) break;
|
|
340
|
+
value += current;
|
|
341
|
+
index += 1;
|
|
342
|
+
}
|
|
343
|
+
if (index >= length) {
|
|
344
|
+
output += input.slice(start);
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
const replacement = rewrite({
|
|
348
|
+
value,
|
|
349
|
+
quote,
|
|
350
|
+
hasTemplateExpression
|
|
351
|
+
});
|
|
352
|
+
if (replacement === null) output += quote + value + quote;
|
|
353
|
+
else output += quote + replacement + quote;
|
|
354
|
+
index += 1;
|
|
355
|
+
}
|
|
356
|
+
return output;
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
//#endregion
|
|
360
|
+
export { collectBossClassTokensInSource, collectBossClassTokensInText, rewriteClassNameTokensInElement, rewriteClassNameTokensInSource, rewriteClassNameTokensInText, rewriteClassNameTokensWithMap };
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_api_server = require('../api/server.cjs');
|
|
3
|
+
const require_file = require('../shared/file.cjs');
|
|
4
|
+
const require_boundaries = require('../shared/boundaries.cjs');
|
|
5
|
+
const require_session = require('../tasks/session.cjs');
|
|
6
|
+
const require_framework = require('../shared/framework.cjs');
|
|
7
|
+
const require_classname = require('./classname.cjs');
|
|
8
|
+
const require_classname_strategy = require('./classname-strategy.cjs');
|
|
9
|
+
const require_prepared = require('./prepared.cjs');
|
|
10
|
+
const require_transform = require('./transform.cjs');
|
|
11
|
+
let node_fs_promises = require("node:fs/promises");
|
|
12
|
+
node_fs_promises = require_rolldown_runtime.__toESM(node_fs_promises);
|
|
13
|
+
let node_path = require("node:path");
|
|
14
|
+
node_path = require_rolldown_runtime.__toESM(node_path);
|
|
15
|
+
let lightningcss = require("lightningcss");
|
|
16
|
+
|
|
17
|
+
//#region src/compile/index.ts
|
|
18
|
+
const supportedExtensions = new Set([
|
|
19
|
+
".js",
|
|
20
|
+
".jsx",
|
|
21
|
+
".ts",
|
|
22
|
+
".tsx",
|
|
23
|
+
".mjs",
|
|
24
|
+
".cjs"
|
|
25
|
+
]);
|
|
26
|
+
async function compileProject(options) {
|
|
27
|
+
const { config, prod } = options;
|
|
28
|
+
const compileConfig = {
|
|
29
|
+
stats: "quick",
|
|
30
|
+
...config.compile ?? {}
|
|
31
|
+
};
|
|
32
|
+
const content = config.content;
|
|
33
|
+
const baseDir = process.cwd();
|
|
34
|
+
if (!content) throw new Error("compile: config.content is required");
|
|
35
|
+
const root = baseDir;
|
|
36
|
+
const tempOutDir = compileConfig.tempOutDir;
|
|
37
|
+
if (!prod && !tempOutDir) throw new Error("compile.tempOutDir is required when not running in prod mode.");
|
|
38
|
+
const outputRoot = prod ? root : node_path.default.resolve(root, tempOutDir);
|
|
39
|
+
const inputPaths = (await require_file.resolveContentPaths(content)).sort();
|
|
40
|
+
const sourceCache = /* @__PURE__ */ new Map();
|
|
41
|
+
const preparedByFile = /* @__PURE__ */ new Map();
|
|
42
|
+
const preparedRegistry = /* @__PURE__ */ new Map();
|
|
43
|
+
const preparedUsages = [];
|
|
44
|
+
const api = await require_api_server.createApi(config, true);
|
|
45
|
+
api.baseDir = baseDir;
|
|
46
|
+
const classNameStrategy = compileConfig.classNameStrategy ?? false;
|
|
47
|
+
const classNameMapper = classNameStrategy ? require_classname_strategy.createClassNameMapper({
|
|
48
|
+
strategy: classNameStrategy,
|
|
49
|
+
prefix: api.selectorPrefix ?? ""
|
|
50
|
+
}) : null;
|
|
51
|
+
if (classNameMapper) {
|
|
52
|
+
const baseContextToClassName = api.contextToClassName;
|
|
53
|
+
api.contextToClassName = (name, value, contexts, escape = true, _prefix = "") => {
|
|
54
|
+
const raw = baseContextToClassName(name, value, contexts, false, "");
|
|
55
|
+
const mapped = classNameMapper.getOrCreate(raw);
|
|
56
|
+
if (!escape) return mapped;
|
|
57
|
+
return api.camelCaseToDash(api.escapeClassName(mapped));
|
|
58
|
+
};
|
|
59
|
+
const baseClassTokenToSelector = api.classTokenToSelector;
|
|
60
|
+
api.classTokenToSelector = (token) => baseClassTokenToSelector(classNameMapper.getOrCreate(token));
|
|
61
|
+
}
|
|
62
|
+
const sessionStart = await require_session.resolveSessionPayload(baseDir, config, "compile", "start");
|
|
63
|
+
await require_session.emitSession(api, sessionStart);
|
|
64
|
+
await require_session.emitSession(api, {
|
|
65
|
+
...sessionStart,
|
|
66
|
+
phase: "run"
|
|
67
|
+
});
|
|
68
|
+
const statsMode = compileConfig.stats ?? "quick";
|
|
69
|
+
const start = process.hrtime.bigint();
|
|
70
|
+
const fileResults = [];
|
|
71
|
+
for (const inputPath of inputPaths) {
|
|
72
|
+
if (!(await node_fs_promises.default.stat(inputPath).catch(() => null))?.isFile()) continue;
|
|
73
|
+
const ext = node_path.default.extname(inputPath);
|
|
74
|
+
const source = await node_fs_promises.default.readFile(inputPath, "utf8");
|
|
75
|
+
sourceCache.set(inputPath, source);
|
|
76
|
+
if (classNameMapper) (supportedExtensions.has(ext) ? require_classname.collectBossClassTokensInSource(source, {
|
|
77
|
+
filename: inputPath,
|
|
78
|
+
api
|
|
79
|
+
}) : require_classname.collectBossClassTokensInText(source, { api })).forEach((token) => classNameMapper.getOrCreate(token));
|
|
80
|
+
if (!supportedExtensions.has(ext)) continue;
|
|
81
|
+
const scan = require_prepared.scanPrepared(source, {
|
|
82
|
+
isTs: ext === ".ts" || ext === ".tsx",
|
|
83
|
+
isJsx: ext === ".jsx" || ext === ".tsx" || ext === ".js" || ext === ".mjs" || ext === ".cjs"
|
|
84
|
+
});
|
|
85
|
+
if (scan.definitions.length) {
|
|
86
|
+
const local = /* @__PURE__ */ new Map();
|
|
87
|
+
for (const definition of scan.definitions) {
|
|
88
|
+
local.set(definition.name, {
|
|
89
|
+
definition: definition.definition,
|
|
90
|
+
inlineable: definition.inlineable
|
|
91
|
+
});
|
|
92
|
+
preparedRegistry.set(definition.name, {
|
|
93
|
+
definition: definition.definition,
|
|
94
|
+
inlineable: definition.inlineable
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
preparedByFile.set(inputPath, local);
|
|
98
|
+
}
|
|
99
|
+
if (scan.usages.length) for (const usage of scan.usages) preparedUsages.push({
|
|
100
|
+
...usage,
|
|
101
|
+
file: inputPath
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
const preparedGlobal = /* @__PURE__ */ new Map();
|
|
105
|
+
for (const [name, entry] of preparedRegistry.entries()) if (entry.inlineable) preparedGlobal.set(name, entry.definition);
|
|
106
|
+
const preparedRuntime = /* @__PURE__ */ new Set();
|
|
107
|
+
for (const usage of preparedUsages) {
|
|
108
|
+
if (!compileConfig.spread && usage.hasSpread) {
|
|
109
|
+
preparedRuntime.add(usage.name);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (preparedByFile.get(usage.file)?.get(usage.name)) continue;
|
|
113
|
+
if (preparedRegistry.get(usage.name)?.inlineable) continue;
|
|
114
|
+
preparedRuntime.add(usage.name);
|
|
115
|
+
}
|
|
116
|
+
const processFile = async (inputPath) => {
|
|
117
|
+
if (!(await node_fs_promises.default.stat(inputPath).catch(() => null))?.isFile()) return;
|
|
118
|
+
const ext = node_path.default.extname(inputPath);
|
|
119
|
+
const relativePath = node_path.default.relative(root, inputPath);
|
|
120
|
+
const outputPath = prod ? inputPath : node_path.default.join(outputRoot, relativePath);
|
|
121
|
+
await node_fs_promises.default.mkdir(node_path.default.dirname(outputPath), { recursive: true });
|
|
122
|
+
const source = sourceCache.get(inputPath) ?? await node_fs_promises.default.readFile(inputPath, "utf8");
|
|
123
|
+
if (!supportedExtensions.has(ext)) {
|
|
124
|
+
const parseContent = require_classname.rewriteClassNameTokensInText(source, { mapToken: classNameMapper ? () => void 0 : void 0 });
|
|
125
|
+
await api.trigger("onParse", {
|
|
126
|
+
content: parseContent,
|
|
127
|
+
path: inputPath
|
|
128
|
+
}, (plugin) => plugin.name === "classname");
|
|
129
|
+
if (!prod) if (classNameMapper) {
|
|
130
|
+
const rewritten = require_classname.rewriteClassNameTokensInText(source, { mapToken: (token) => classNameMapper.get(token) });
|
|
131
|
+
await node_fs_promises.default.writeFile(outputPath, rewritten, "utf8");
|
|
132
|
+
} else await node_fs_promises.default.copyFile(inputPath, outputPath);
|
|
133
|
+
fileResults.push({
|
|
134
|
+
file: inputPath,
|
|
135
|
+
processed: false,
|
|
136
|
+
copied: !prod,
|
|
137
|
+
needsRuntime: false,
|
|
138
|
+
needsValueHelper: false,
|
|
139
|
+
replacedElements: 0
|
|
140
|
+
});
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const classNameSource = require_classname.rewriteClassNameTokensInSource(source, {
|
|
144
|
+
filename: inputPath,
|
|
145
|
+
classNameProp: require_framework.getClassNameProp(api.framework),
|
|
146
|
+
mapToken: classNameMapper ? () => void 0 : void 0
|
|
147
|
+
});
|
|
148
|
+
await api.trigger("onParse", {
|
|
149
|
+
content: classNameSource,
|
|
150
|
+
path: inputPath
|
|
151
|
+
}, (plugin) => plugin.name === "classname");
|
|
152
|
+
const transformed = await require_transform.transformSource(source, {
|
|
153
|
+
api,
|
|
154
|
+
compile: compileConfig,
|
|
155
|
+
filename: inputPath,
|
|
156
|
+
preparedGlobal,
|
|
157
|
+
preparedLocal: new Map(Array.from(preparedByFile.get(inputPath)?.entries() ?? []).map(([key, value]) => [key, value.definition])),
|
|
158
|
+
preparedRuntime,
|
|
159
|
+
classNameMapper
|
|
160
|
+
});
|
|
161
|
+
fileResults.push({
|
|
162
|
+
file: inputPath,
|
|
163
|
+
processed: true,
|
|
164
|
+
copied: false,
|
|
165
|
+
needsRuntime: transformed.needsRuntime,
|
|
166
|
+
needsValueHelper: transformed.needsValueHelper,
|
|
167
|
+
replacedElements: transformed.replacedElements
|
|
168
|
+
});
|
|
169
|
+
await node_fs_promises.default.writeFile(outputPath, transformed.code, "utf8");
|
|
170
|
+
};
|
|
171
|
+
if (classNameStrategy === "shortest" || classNameStrategy === "unicode") for (const inputPath of inputPaths) await processFile(inputPath);
|
|
172
|
+
else await Promise.all(inputPaths.map(processFile));
|
|
173
|
+
let cssBytes = 0;
|
|
174
|
+
let cssWritten = false;
|
|
175
|
+
let stylesheetPath = null;
|
|
176
|
+
if (!prod && api.css.text.trim()) {
|
|
177
|
+
const resolvedStylesheetPath = config.stylesheetPath ?? node_path.default.join(root, config.configDir ?? ".bo$$", "styles.css");
|
|
178
|
+
const outputs = (await require_boundaries.resolveBoundaryOutputs(api, {
|
|
179
|
+
rootDir: root,
|
|
180
|
+
stylesheetPath: resolvedStylesheetPath,
|
|
181
|
+
boundaries: config.css?.boundaries
|
|
182
|
+
})).outputs.map((output) => {
|
|
183
|
+
const relative = node_path.default.relative(root, output.path);
|
|
184
|
+
return {
|
|
185
|
+
path: node_path.default.join(outputRoot, relative),
|
|
186
|
+
text: output.text
|
|
187
|
+
};
|
|
188
|
+
});
|
|
189
|
+
const globalOutputPath = node_path.default.resolve(node_path.default.join(outputRoot, node_path.default.relative(root, resolvedStylesheetPath)));
|
|
190
|
+
const outputSizes = /* @__PURE__ */ new Map();
|
|
191
|
+
for (const output of outputs) {
|
|
192
|
+
const minified = (0, lightningcss.transform)({
|
|
193
|
+
code: Buffer.from(output.text),
|
|
194
|
+
filename: output.path,
|
|
195
|
+
minify: true
|
|
196
|
+
});
|
|
197
|
+
await node_fs_promises.default.mkdir(node_path.default.dirname(output.path), { recursive: true });
|
|
198
|
+
await node_fs_promises.default.writeFile(output.path, minified.code.toString(), "utf8");
|
|
199
|
+
outputSizes.set(node_path.default.resolve(output.path), minified.code.length);
|
|
200
|
+
}
|
|
201
|
+
const globalOutput = outputs.find((output) => node_path.default.resolve(output.path) === globalOutputPath);
|
|
202
|
+
cssBytes = globalOutput ? outputSizes.get(node_path.default.resolve(globalOutput.path)) ?? 0 : 0;
|
|
203
|
+
cssWritten = true;
|
|
204
|
+
stylesheetPath = globalOutput?.path ?? globalOutputPath;
|
|
205
|
+
}
|
|
206
|
+
const durationMs = Number(process.hrtime.bigint() - start) / 1e6;
|
|
207
|
+
const runtimeFiles = fileResults.filter((result$1) => result$1.needsRuntime).map((result$1) => result$1.file);
|
|
208
|
+
const valueHelperFiles = fileResults.filter((result$1) => result$1.needsValueHelper).map((result$1) => result$1.file);
|
|
209
|
+
const filesProcessed = fileResults.filter((result$1) => result$1.processed).length;
|
|
210
|
+
const filesCopied = fileResults.filter((result$1) => result$1.copied).length;
|
|
211
|
+
const filesTotal = fileResults.length;
|
|
212
|
+
const filesSkipped = filesTotal - filesProcessed - filesCopied;
|
|
213
|
+
const elementsReplaced = fileResults.reduce((total, result$1) => total + result$1.replacedElements, 0);
|
|
214
|
+
const result = {
|
|
215
|
+
statsMode,
|
|
216
|
+
stats: {
|
|
217
|
+
outputMode: prod ? "prod" : "temp",
|
|
218
|
+
outputDir: outputRoot,
|
|
219
|
+
runtimeFree: runtimeFiles.length === 0,
|
|
220
|
+
runtimeFiles: runtimeFiles.map((file) => node_path.default.relative(root, file)),
|
|
221
|
+
valueHelperFiles: valueHelperFiles.map((file) => node_path.default.relative(root, file)),
|
|
222
|
+
filesProcessed,
|
|
223
|
+
filesCopied,
|
|
224
|
+
filesSkipped,
|
|
225
|
+
filesTotal,
|
|
226
|
+
elementsReplaced,
|
|
227
|
+
durationMs,
|
|
228
|
+
cssBytes,
|
|
229
|
+
cssWritten,
|
|
230
|
+
stylesheetPath
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
await require_session.emitSession(api, await require_session.resolveSessionPayload(baseDir, config, "compile", "stop"));
|
|
234
|
+
return result;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
//#endregion
|
|
238
|
+
exports.compileProject = compileProject;
|