@sobagu/compiler 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +44 -2
- package/dist/extract.d.ts +6 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +1 -0
- package/dist/src-CpiKjLBU.js +298 -0
- package/dist/src-CpiKjLBU.js.map +1 -0
- package/dist/vite.d.ts +9 -0
- package/dist/vite.js +13 -0
- package/dist/vite.js.map +1 -0
- package/dist/webpack.d.ts +6 -0
- package/dist/webpack.js +10 -0
- package/dist/webpack.js.map +1 -0
- package/package.json +58 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sobagu contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @sobagu/compiler
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Build-time CSS for Sobagu. One plugin for Vite, Rollup, webpack (and Next.js), esbuild and Rspack
|
|
4
|
+
that finds the styles in your code and writes them to a real CSS file at build time, so the page is
|
|
5
|
+
styled on first paint and SSR needs no extra step. Values it can't see at build time still work:
|
|
6
|
+
the small runtime adds them, and never injects a class twice.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm i -D @sobagu/compiler
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Runs on Node 22.18+ or 24.11+.
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
// vite.config.ts
|
|
20
|
+
import sobagu from '@sobagu/compiler/vite'
|
|
21
|
+
|
|
22
|
+
export default { plugins: [sobagu()] }
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
// your entry file (main.tsx / main.ts)
|
|
27
|
+
import 'virtual:sobagu.css'
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
webpack, Next.js, Rspack, Rollup and esbuild:
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
import sobagu, { rspack, rollup, esbuild } from '@sobagu/compiler/webpack'
|
|
34
|
+
// webpack / Next.js: config.plugins.push(sobagu())
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Docs
|
|
38
|
+
|
|
39
|
+
- [Build-time CSS (compiler)](https://sobagucss.com/docs/compiler): what it finds, options and SSR
|
|
40
|
+
|
|
41
|
+
Sobagu is in 0.x: the API can still change between minor versions.
|
|
42
|
+
|
|
43
|
+
## Licence
|
|
44
|
+
|
|
45
|
+
MIT © 2026 Sobagu contributors
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type StyleObject } from '@sobagu/core';
|
|
2
|
+
/**
|
|
3
|
+
* Find every statically known Sobagu style in a source file.
|
|
4
|
+
* Dynamic values are skipped (the runtime still handles them); `a ? 'x' : 'y'` includes both.
|
|
5
|
+
*/
|
|
6
|
+
export declare function extract(code: string, filename: string): StyleObject[];
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { relative } from 'node:path';
|
|
2
|
+
import { type StyleObject } from '@sobagu/core';
|
|
3
|
+
export { extract } from './extract.js';
|
|
4
|
+
export interface SobaguCompilerOptions {
|
|
5
|
+
/** Project root (default: process.cwd()). */
|
|
6
|
+
root?: string;
|
|
7
|
+
/** Globs (relative to root) scanned at build start. */
|
|
8
|
+
include?: string[];
|
|
9
|
+
/** Globs to skip. node_modules and dist are always skipped. */
|
|
10
|
+
exclude?: string[];
|
|
11
|
+
/** Styles to always include, e.g. ones built from data at runtime: [{ bg: 'danger' }, { md: { cols: 3 } }] */
|
|
12
|
+
safelist?: StyleObject[];
|
|
13
|
+
}
|
|
14
|
+
/** Import this id once in your app entry: import 'virtual:sobagu.css' */
|
|
15
|
+
export declare const VIRTUAL_ID = "virtual:sobagu.css";
|
|
16
|
+
/** Generate the full stylesheet for a set of style objects: layers + theme + reset + utilities + marker. */
|
|
17
|
+
export declare function generateCss(styles: Iterable<StyleObject>): string;
|
|
18
|
+
export declare const sobagu: import("unplugin").UnpluginInstance<SobaguCompilerOptions | undefined, boolean>;
|
|
19
|
+
/** For tests and tools: the files the plugin scanned, relative to root. */
|
|
20
|
+
export declare const _internal: {
|
|
21
|
+
relative: typeof relative;
|
|
22
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as VIRTUAL_ID, n as _internal, a as extract, r as generateCss, i as sobagu } from "./src-CpiKjLBU.js";
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { globSync, readFileSync } from "node:fs";
|
|
2
|
+
import { relative, resolve } from "node:path";
|
|
3
|
+
import { createUnplugin } from "unplugin";
|
|
4
|
+
import { css, getCssText, isStyleProp, parseSb, resetStyles, setDevWarnings, staticMarkerCss } from "@sobagu/core";
|
|
5
|
+
import { parse, parseExpression } from "@babel/parser";
|
|
6
|
+
// sobagu/packages/compiler/src/extract.ts
|
|
7
|
+
/** Built-in components and the base styles they always add. */
|
|
8
|
+
var COMPONENTS = {
|
|
9
|
+
Box: void 0,
|
|
10
|
+
Stack: {
|
|
11
|
+
display: "flex",
|
|
12
|
+
flexDir: "col",
|
|
13
|
+
gap: "md"
|
|
14
|
+
},
|
|
15
|
+
Grid: {
|
|
16
|
+
display: "grid",
|
|
17
|
+
gap: "md"
|
|
18
|
+
},
|
|
19
|
+
Text: void 0
|
|
20
|
+
};
|
|
21
|
+
var DYNAMIC = Symbol("dynamic");
|
|
22
|
+
/** A value that may be one of several literals (from `a ? 'x' : 'y'`, `a && 'x'`, `a ?? 'x'`). */
|
|
23
|
+
var Alts = class {
|
|
24
|
+
options;
|
|
25
|
+
constructor(options) {
|
|
26
|
+
this.options = options;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/** Statically evaluate an expression. Unknown parts become DYNAMIC and are skipped. */
|
|
30
|
+
function evaluate(node) {
|
|
31
|
+
if (!node) return DYNAMIC;
|
|
32
|
+
switch (node.type) {
|
|
33
|
+
case "StringLiteral":
|
|
34
|
+
case "NumericLiteral":
|
|
35
|
+
case "BooleanLiteral": return node.value;
|
|
36
|
+
case "NullLiteral": return;
|
|
37
|
+
case "TemplateLiteral": {
|
|
38
|
+
const exprs = node.expressions;
|
|
39
|
+
const quasis = node.quasis;
|
|
40
|
+
return exprs.length === 0 ? quasis[0]?.value.cooked : DYNAMIC;
|
|
41
|
+
}
|
|
42
|
+
case "UnaryExpression": {
|
|
43
|
+
const v = evaluate(node.argument);
|
|
44
|
+
return node.operator === "-" && typeof v === "number" ? -v : DYNAMIC;
|
|
45
|
+
}
|
|
46
|
+
case "ObjectExpression": {
|
|
47
|
+
const out = {};
|
|
48
|
+
for (const p of node.properties) {
|
|
49
|
+
if (p.type !== "ObjectProperty" || p.computed) continue;
|
|
50
|
+
const k = p.key;
|
|
51
|
+
const key = k.type === "Identifier" ? k.name : k.type === "StringLiteral" ? k.value : void 0;
|
|
52
|
+
if (key === void 0) continue;
|
|
53
|
+
const v = evaluate(p.value);
|
|
54
|
+
if (v !== DYNAMIC) out[key] = v;
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
case "ArrayExpression": return node.elements.map((e) => evaluate(e));
|
|
59
|
+
case "ConditionalExpression": return new Alts([evaluate(node.consequent), evaluate(node.alternate)]);
|
|
60
|
+
case "LogicalExpression": return node.operator === "&&" ? new Alts([evaluate(node.right)]) : new Alts([evaluate(node.left), evaluate(node.right)]);
|
|
61
|
+
case "TSAsExpression":
|
|
62
|
+
case "TSSatisfiesExpression":
|
|
63
|
+
case "TSNonNullExpression":
|
|
64
|
+
case "ParenthesizedExpression": return evaluate(node.expression);
|
|
65
|
+
default: return DYNAMIC;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
var isPlain = (v) => typeof v === "object" && v !== null && !Array.isArray(v) && !(v instanceof Alts);
|
|
69
|
+
/** Every leaf of a (possibly branching) style value, each as its own small style object. */
|
|
70
|
+
function leaves(value, path = [], out = []) {
|
|
71
|
+
if (value === DYNAMIC || value === void 0) return out;
|
|
72
|
+
if (value instanceof Alts) {
|
|
73
|
+
for (const o of value.options) leaves(o, path, out);
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
if (isPlain(value)) {
|
|
77
|
+
for (const k of Object.keys(value)) leaves(value[k], [...path, k], out);
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
const style = {};
|
|
81
|
+
let cur = style;
|
|
82
|
+
path.forEach((k, i) => {
|
|
83
|
+
if (i === path.length - 1) cur[k] = value;
|
|
84
|
+
else cur = cur[k] = {};
|
|
85
|
+
});
|
|
86
|
+
out.push(style);
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
var camel = (s) => s.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
90
|
+
/** Style objects for one component usage: <Stack row gap="sm" hover={{…}}>. */
|
|
91
|
+
function componentStyles(name, attrs) {
|
|
92
|
+
const out = [];
|
|
93
|
+
const base = COMPONENTS[name];
|
|
94
|
+
if (base) out.push(base);
|
|
95
|
+
for (const [rawName, value] of attrs) {
|
|
96
|
+
let key = camel(rawName.replace(/^:/, ""));
|
|
97
|
+
if (key === "as" || key === "class" || key === "className") continue;
|
|
98
|
+
if (name === "Text" && key === "size") key = "text";
|
|
99
|
+
for (const leaf of leaves(value, [key])) if (isStyleProp(key, leaf[key])) out.push(leaf);
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
function walkAst(node, visit) {
|
|
104
|
+
if (!node || typeof node !== "object") return;
|
|
105
|
+
if (Array.isArray(node)) {
|
|
106
|
+
for (const item of node) if (item && typeof item === "object") walkAst(item, visit);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const n = node;
|
|
110
|
+
if (typeof n.type === "string") visit(n);
|
|
111
|
+
for (const key of Object.keys(n)) {
|
|
112
|
+
if (key === "loc" || key === "start" || key === "end" || key === "extra" || key === "comments") continue;
|
|
113
|
+
const child = n[key];
|
|
114
|
+
if (child && typeof child === "object") walkAst(child, visit);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function recipeStyles(config) {
|
|
118
|
+
if (!isPlain(config)) return [];
|
|
119
|
+
const out = [];
|
|
120
|
+
const add = (v) => out.push(...leaves(v));
|
|
121
|
+
const isSlot = Array.isArray(config.slots);
|
|
122
|
+
const addMaybeSlots = (v) => isSlot && isPlain(v) ? Object.values(v).forEach(add) : add(v);
|
|
123
|
+
addMaybeSlots(config.base);
|
|
124
|
+
if (isPlain(config.variants)) {
|
|
125
|
+
for (const group of Object.values(config.variants)) if (isPlain(group)) Object.values(group).forEach(addMaybeSlots);
|
|
126
|
+
}
|
|
127
|
+
if (Array.isArray(config.compoundVariants)) {
|
|
128
|
+
for (const cv of config.compoundVariants) if (isPlain(cv)) addMaybeSlots(cv.style);
|
|
129
|
+
}
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
function fromScript(code, jsx) {
|
|
133
|
+
const out = [];
|
|
134
|
+
let ast;
|
|
135
|
+
try {
|
|
136
|
+
ast = parse(code, {
|
|
137
|
+
sourceType: "module",
|
|
138
|
+
errorRecovery: true,
|
|
139
|
+
plugins: jsx ? ["jsx", "typescript"] : ["typescript"]
|
|
140
|
+
});
|
|
141
|
+
} catch {
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
walkAst(ast, (n) => {
|
|
145
|
+
if (n.type === "JSXOpeningElement") {
|
|
146
|
+
const nameNode = n.name;
|
|
147
|
+
const name = nameNode.type === "JSXIdentifier" ? nameNode.name : "";
|
|
148
|
+
if (!(name in COMPONENTS)) return;
|
|
149
|
+
const attrs = [];
|
|
150
|
+
for (const a of n.attributes) {
|
|
151
|
+
if (a.type !== "JSXAttribute") continue;
|
|
152
|
+
const an = a.name.name;
|
|
153
|
+
const v = a.value;
|
|
154
|
+
attrs.push([an, v === null ? true : v.type === "JSXExpressionContainer" ? evaluate(v.expression) : evaluate(v)]);
|
|
155
|
+
}
|
|
156
|
+
out.push(...componentStyles(name, attrs));
|
|
157
|
+
} else if (n.type === "CallExpression") {
|
|
158
|
+
const callee = n.callee;
|
|
159
|
+
const fn = callee.type === "Identifier" ? callee.name : "";
|
|
160
|
+
const args = n.arguments;
|
|
161
|
+
if (fn === "css") args.forEach((a) => out.push(...leaves(evaluate(a))));
|
|
162
|
+
else if (fn === "recipe" || fn === "slotRecipe") out.push(...recipeStyles(evaluate(args[0])));
|
|
163
|
+
else if (fn === "styled") out.push(...recipeStyles(evaluate(args[1])));
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
return out;
|
|
167
|
+
}
|
|
168
|
+
/** Attribute values in templates: "…" | '…' | {…} (one level of nested braces). */
|
|
169
|
+
var ATTR_RE = /([:@]?[\w:.\[\]-]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|\{((?:[^{}]|\{[^{}]*\})*)\}))?/g;
|
|
170
|
+
function expr(source) {
|
|
171
|
+
try {
|
|
172
|
+
return evaluate(parseExpression(source, { plugins: ["typescript"] }));
|
|
173
|
+
} catch {
|
|
174
|
+
return DYNAMIC;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/** Vue / Svelte / Astro / HTML templates: components, v-sb, use:sb and [sb]. */
|
|
178
|
+
function fromTemplate(code) {
|
|
179
|
+
const out = [];
|
|
180
|
+
for (const m of code.matchAll(/<(Box|Stack|Grid|Text)\b((?:[^>"'{]|"[^"]*"|'[^']*'|\{(?:[^{}]|\{[^{}]*\})*\})*)\/?>/g)) {
|
|
181
|
+
const attrs = [];
|
|
182
|
+
for (const a of m[2].matchAll(ATTR_RE)) {
|
|
183
|
+
const [, name, dq, sq, br] = a;
|
|
184
|
+
if (!name) continue;
|
|
185
|
+
const raw = dq ?? sq;
|
|
186
|
+
if (br !== void 0) attrs.push([name, expr(br)]);
|
|
187
|
+
else if (raw === void 0) attrs.push([name, true]);
|
|
188
|
+
else if (name.startsWith(":")) attrs.push([name, expr(raw)]);
|
|
189
|
+
else attrs.push([name, raw === "" ? true : /^-?\d+(\.\d+)?$/.test(raw) ? Number(raw) : raw]);
|
|
190
|
+
}
|
|
191
|
+
out.push(...componentStyles(m[1], attrs));
|
|
192
|
+
}
|
|
193
|
+
for (const m of code.matchAll(/(?:v-sb|\[sb\])\s*=\s*"([^"]*)"|use:sb=\{((?:[^{}]|\{[^{}]*\})*)\}/g)) out.push(...leaves(expr(m[1] ?? m[2])));
|
|
194
|
+
return out;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Find every statically known Sobagu style in a source file.
|
|
198
|
+
* Dynamic values are skipped (the runtime still handles them); `a ? 'x' : 'y'` includes both.
|
|
199
|
+
*/
|
|
200
|
+
function extract(code, filename) {
|
|
201
|
+
const out = [];
|
|
202
|
+
for (const m of code.matchAll(/(?<![\w:-])(?:data-)?sb\s*=\s*(["'])(.*?)\1/gs)) out.push(parseSb(m[2]));
|
|
203
|
+
const ext = filename.split("?")[0].split(".").pop() ?? "";
|
|
204
|
+
if ([
|
|
205
|
+
"js",
|
|
206
|
+
"jsx",
|
|
207
|
+
"ts",
|
|
208
|
+
"tsx",
|
|
209
|
+
"mjs",
|
|
210
|
+
"mts",
|
|
211
|
+
"cjs",
|
|
212
|
+
"cts"
|
|
213
|
+
].includes(ext)) out.push(...fromScript(code, ext !== "ts" && ext !== "mts" && ext !== "cts"));
|
|
214
|
+
else if ([
|
|
215
|
+
"vue",
|
|
216
|
+
"svelte",
|
|
217
|
+
"astro",
|
|
218
|
+
"html",
|
|
219
|
+
"mdx"
|
|
220
|
+
].includes(ext)) {
|
|
221
|
+
out.push(...fromTemplate(code));
|
|
222
|
+
for (const s of code.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script>|^---\n([\s\S]*?)\n---/gm)) out.push(...fromScript(s[1] ?? s[2], true));
|
|
223
|
+
if (ext === "mdx") out.push(...fromScript(code.replace(/^(?!import|export|<).*$/gm, ""), true));
|
|
224
|
+
}
|
|
225
|
+
return out;
|
|
226
|
+
}
|
|
227
|
+
// sobagu/packages/compiler/src/index.ts
|
|
228
|
+
/** Import this id once in your app entry: import 'virtual:sobagu.css' */
|
|
229
|
+
var VIRTUAL_ID = "virtual:sobagu.css";
|
|
230
|
+
var RESOLVED_ID = "/__sobagu.css";
|
|
231
|
+
var DEFAULT_INCLUDE = ["**/*.{js,jsx,ts,tsx,mjs,mts,vue,svelte,astro,html,mdx}"];
|
|
232
|
+
var SOURCE_RE = /\.(jsx?|tsx?|mjs|mts|vue|svelte|astro|html|mdx)($|\?)/;
|
|
233
|
+
var SKIP_RE = /[\\/](node_modules|dist|\.git|\.claude)[\\/]/;
|
|
234
|
+
/** Generate the full stylesheet for a set of style objects: layers + theme + reset + utilities + marker. */
|
|
235
|
+
function generateCss(styles) {
|
|
236
|
+
resetStyles();
|
|
237
|
+
setDevWarnings(false);
|
|
238
|
+
try {
|
|
239
|
+
for (const s of styles) css(s);
|
|
240
|
+
return `${getCssText()}\n${staticMarkerCss}\n`;
|
|
241
|
+
} finally {
|
|
242
|
+
setDevWarnings(true);
|
|
243
|
+
resetStyles();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
var sobagu = createUnplugin((options = {}) => {
|
|
247
|
+
const root = resolve(options.root ?? process.cwd());
|
|
248
|
+
const files = /* @__PURE__ */ new Map();
|
|
249
|
+
let onChange;
|
|
250
|
+
const scan = () => {
|
|
251
|
+
const found = globSync(options.include ?? DEFAULT_INCLUDE, {
|
|
252
|
+
cwd: root,
|
|
253
|
+
exclude: (p) => /(^|[\\/])(node_modules|dist|\.git|\.claude)([\\/]|$)/.test(typeof p === "string" ? p : String(p))
|
|
254
|
+
});
|
|
255
|
+
for (const rel of found) {
|
|
256
|
+
if (options.exclude?.some((g) => rel.includes(g))) continue;
|
|
257
|
+
const abs = resolve(root, rel);
|
|
258
|
+
try {
|
|
259
|
+
files.set(abs, extract(readFileSync(abs, "utf8"), abs));
|
|
260
|
+
} catch {}
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
const all = () => [...files.values()].flat().concat(options.safelist ?? []);
|
|
264
|
+
return {
|
|
265
|
+
name: "sobagu",
|
|
266
|
+
enforce: "pre",
|
|
267
|
+
buildStart() {
|
|
268
|
+
scan();
|
|
269
|
+
},
|
|
270
|
+
resolveId(id) {
|
|
271
|
+
return id === "virtual:sobagu.css" || id === RESOLVED_ID ? RESOLVED_ID : null;
|
|
272
|
+
},
|
|
273
|
+
loadInclude: (id) => id === RESOLVED_ID,
|
|
274
|
+
load(id) {
|
|
275
|
+
return id === RESOLVED_ID ? generateCss(all()) : null;
|
|
276
|
+
},
|
|
277
|
+
transformInclude: (id) => SOURCE_RE.test(id) && !SKIP_RE.test(id) && id !== RESOLVED_ID,
|
|
278
|
+
transform(code, id) {
|
|
279
|
+
const file = id.split("?")[0];
|
|
280
|
+
const next = extract(code, file);
|
|
281
|
+
const prev = files.get(file);
|
|
282
|
+
files.set(file, next);
|
|
283
|
+
if (onChange && JSON.stringify(prev) !== JSON.stringify(next)) onChange();
|
|
284
|
+
return null;
|
|
285
|
+
},
|
|
286
|
+
vite: { configureServer(server) {
|
|
287
|
+
onChange = () => {
|
|
288
|
+
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
289
|
+
if (mod) server.reloadModule(mod);
|
|
290
|
+
};
|
|
291
|
+
} }
|
|
292
|
+
};
|
|
293
|
+
});
|
|
294
|
+
/** For tests and tools: the files the plugin scanned, relative to root. */
|
|
295
|
+
var _internal = { relative };
|
|
296
|
+
export { extract as a, sobagu as i, _internal as n, generateCss as r, VIRTUAL_ID as t };
|
|
297
|
+
|
|
298
|
+
//# sourceMappingURL=src-CpiKjLBU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src-CpiKjLBU.js","names":[],"sources":["../src/extract.ts","../src/index.ts"],"sourcesContent":["import { parse, parseExpression } from '@babel/parser'\nimport { isStyleProp, parseSb, type StyleObject } from '@sobagu/core'\n\n/** Built-in components and the base styles they always add. */\nconst COMPONENTS: Record<string, StyleObject | undefined> = {\n Box: undefined,\n Stack: { display: 'flex', flexDir: 'col', gap: 'md' },\n Grid: { display: 'grid', gap: 'md' },\n Text: undefined,\n}\n\nconst DYNAMIC = Symbol('dynamic')\ntype Value = unknown\ntype Node = { type: string; [k: string]: unknown }\n\n/** A value that may be one of several literals (from `a ? 'x' : 'y'`, `a && 'x'`, `a ?? 'x'`). */\nclass Alts {\n constructor(public readonly options: Value[]) {}\n}\n\n/** Statically evaluate an expression. Unknown parts become DYNAMIC and are skipped. */\nfunction evaluate(node: Node | null | undefined): Value {\n if (!node) return DYNAMIC\n switch (node.type) {\n case 'StringLiteral':\n case 'NumericLiteral':\n case 'BooleanLiteral':\n return node.value\n case 'NullLiteral':\n return undefined\n case 'TemplateLiteral': {\n const exprs = node.expressions as Node[]\n const quasis = node.quasis as { value: { cooked: string } }[]\n return exprs.length === 0 ? quasis[0]?.value.cooked : DYNAMIC\n }\n case 'UnaryExpression': {\n const v = evaluate(node.argument as Node)\n return node.operator === '-' && typeof v === 'number' ? -v : DYNAMIC\n }\n case 'ObjectExpression': {\n const out: Record<string, Value> = {}\n for (const p of node.properties as Node[]) {\n if (p.type !== 'ObjectProperty' || p.computed) continue\n const k = p.key as Node\n const key = k.type === 'Identifier' ? (k.name as string) : k.type === 'StringLiteral' ? (k.value as string) : undefined\n if (key === undefined) continue\n const v = evaluate(p.value as Node)\n if (v !== DYNAMIC) out[key] = v\n }\n return out\n }\n case 'ArrayExpression':\n return (node.elements as (Node | null)[]).map((e) => evaluate(e))\n case 'ConditionalExpression':\n return new Alts([evaluate(node.consequent as Node), evaluate(node.alternate as Node)])\n case 'LogicalExpression':\n return node.operator === '&&'\n ? new Alts([evaluate(node.right as Node)])\n : new Alts([evaluate(node.left as Node), evaluate(node.right as Node)])\n case 'TSAsExpression':\n case 'TSSatisfiesExpression':\n case 'TSNonNullExpression':\n case 'ParenthesizedExpression':\n return evaluate(node.expression as Node)\n default:\n return DYNAMIC\n }\n}\n\nconst isPlain = (v: Value): v is Record<string, Value> => typeof v === 'object' && v !== null && !Array.isArray(v) && !(v instanceof Alts)\n\n/** Every leaf of a (possibly branching) style value, each as its own small style object. */\nfunction leaves(value: Value, path: string[] = [], out: StyleObject[] = []): StyleObject[] {\n if (value === DYNAMIC || value === undefined) return out\n if (value instanceof Alts) {\n for (const o of value.options) leaves(o, path, out)\n return out\n }\n if (isPlain(value)) {\n for (const k of Object.keys(value)) leaves(value[k], [...path, k], out)\n return out\n }\n // Rebuild { a: { b: leaf } } from the path.\n const style: Record<string, Value> = {}\n let cur = style\n path.forEach((k, i) => {\n if (i === path.length - 1) cur[k] = value\n else cur = (cur[k] = {}) as Record<string, Value>\n })\n out.push(style as StyleObject)\n return out\n}\n\nconst camel = (s: string) => s.replace(/-([a-z])/g, (_, c: string) => c.toUpperCase())\n\n/** Style objects for one component usage: <Stack row gap=\"sm\" hover={{…}}>. */\nfunction componentStyles(name: string, attrs: [string, Value][]): StyleObject[] {\n const out: StyleObject[] = []\n const base = COMPONENTS[name]\n if (base) out.push(base)\n for (const [rawName, value] of attrs) {\n let key = camel(rawName.replace(/^:/, ''))\n if (key === 'as' || key === 'class' || key === 'className') continue\n if (name === 'Text' && key === 'size') key = 'text'\n // Every leaf is { [key]: … }, so check its one top-level entry directly.\n for (const leaf of leaves(value, [key])) if (isStyleProp(key, (leaf as Record<string, Value>)[key])) out.push(leaf)\n }\n return out\n}\n\nfunction walkAst(node: unknown, visit: (n: Node) => void): void {\n if (!node || typeof node !== 'object') return\n if (Array.isArray(node)) {\n for (const item of node) if (item && typeof item === 'object') walkAst(item, visit)\n return\n }\n const n = node as Node\n if (typeof n.type === 'string') visit(n)\n for (const key of Object.keys(n)) {\n if (key === 'loc' || key === 'start' || key === 'end' || key === 'extra' || key === 'comments') continue\n // Only objects and arrays can hold nodes: skip strings, numbers and nulls without a call.\n const child = n[key]\n if (child && typeof child === 'object') walkAst(child, visit)\n }\n}\n\nfunction recipeStyles(config: Value): StyleObject[] {\n if (!isPlain(config)) return []\n const out: StyleObject[] = []\n const add = (v: Value) => out.push(...leaves(v))\n const isSlot = Array.isArray(config.slots)\n const addMaybeSlots = (v: Value) => (isSlot && isPlain(v) ? Object.values(v).forEach(add) : add(v))\n addMaybeSlots(config.base)\n if (isPlain(config.variants)) for (const group of Object.values(config.variants)) if (isPlain(group)) Object.values(group).forEach(addMaybeSlots)\n if (Array.isArray(config.compoundVariants)) for (const cv of config.compoundVariants) if (isPlain(cv)) addMaybeSlots(cv.style)\n return out\n}\n\nfunction fromScript(code: string, jsx: boolean): StyleObject[] {\n const out: StyleObject[] = []\n let ast: unknown\n try {\n ast = parse(code, { sourceType: 'module', errorRecovery: true, plugins: jsx ? ['jsx', 'typescript'] : ['typescript'] })\n } catch {\n return out\n }\n walkAst(ast, (n) => {\n if (n.type === 'JSXOpeningElement') {\n const nameNode = n.name as Node\n const name = nameNode.type === 'JSXIdentifier' ? (nameNode.name as string) : ''\n if (!(name in COMPONENTS)) return\n const attrs: [string, Value][] = []\n for (const a of n.attributes as Node[]) {\n if (a.type !== 'JSXAttribute') continue\n const an = (a.name as Node).name as string\n const v = a.value as Node | null\n attrs.push([an, v === null ? true : v.type === 'JSXExpressionContainer' ? evaluate(v.expression as Node) : evaluate(v)])\n }\n out.push(...componentStyles(name, attrs))\n } else if (n.type === 'CallExpression') {\n const callee = n.callee as Node\n const fn = callee.type === 'Identifier' ? (callee.name as string) : ''\n const args = n.arguments as Node[]\n if (fn === 'css') args.forEach((a) => out.push(...leaves(evaluate(a))))\n else if (fn === 'recipe' || fn === 'slotRecipe') out.push(...recipeStyles(evaluate(args[0])))\n else if (fn === 'styled') out.push(...recipeStyles(evaluate(args[1])))\n }\n })\n return out\n}\n\n/** Attribute values in templates: \"…\" | '…' | {…} (one level of nested braces). */\nconst ATTR_RE = /([:@]?[\\w:.\\[\\]-]+)(?:\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|\\{((?:[^{}]|\\{[^{}]*\\})*)\\}))?/g\n\nfunction expr(source: string): Value {\n try {\n return evaluate(parseExpression(source, { plugins: ['typescript'] }) as unknown as Node)\n } catch {\n return DYNAMIC\n }\n}\n\n/** Vue / Svelte / Astro / HTML templates: components, v-sb, use:sb and [sb]. */\nfunction fromTemplate(code: string): StyleObject[] {\n const out: StyleObject[] = []\n for (const m of code.matchAll(/<(Box|Stack|Grid|Text)\\b((?:[^>\"'{]|\"[^\"]*\"|'[^']*'|\\{(?:[^{}]|\\{[^{}]*\\})*\\})*)\\/?>/g)) {\n const attrs: [string, Value][] = []\n for (const a of m[2]!.matchAll(ATTR_RE)) {\n const [, name, dq, sq, br] = a\n if (!name) continue\n const raw = dq ?? sq\n if (br !== undefined) attrs.push([name, expr(br)])\n else if (raw === undefined) attrs.push([name, true])\n else if (name.startsWith(':')) attrs.push([name, expr(raw)])\n else attrs.push([name, raw === '' ? true : /^-?\\d+(\\.\\d+)?$/.test(raw) ? Number(raw) : raw])\n }\n out.push(...componentStyles(m[1]!, attrs))\n }\n for (const m of code.matchAll(/(?:v-sb|\\[sb\\])\\s*=\\s*\"([^\"]*)\"|use:sb=\\{((?:[^{}]|\\{[^{}]*\\})*)\\}/g)) {\n out.push(...leaves(expr((m[1] ?? m[2])!)))\n }\n return out\n}\n\n/**\n * Find every statically known Sobagu style in a source file.\n * Dynamic values are skipped (the runtime still handles them); `a ? 'x' : 'y'` includes both.\n */\nexport function extract(code: string, filename: string): StyleObject[] {\n const out: StyleObject[] = []\n for (const m of code.matchAll(/(?<![\\w:-])(?:data-)?sb\\s*=\\s*([\"'])(.*?)\\1/gs)) out.push(parseSb(m[2]!))\n const ext = filename.split('?')[0]!.split('.').pop() ?? ''\n if (['js', 'jsx', 'ts', 'tsx', 'mjs', 'mts', 'cjs', 'cts'].includes(ext)) out.push(...fromScript(code, ext !== 'ts' && ext !== 'mts' && ext !== 'cts'))\n else if (['vue', 'svelte', 'astro', 'html', 'mdx'].includes(ext)) {\n out.push(...fromTemplate(code))\n for (const s of code.matchAll(/<script\\b[^>]*>([\\s\\S]*?)<\\/script>|^---\\n([\\s\\S]*?)\\n---/gm)) out.push(...fromScript((s[1] ?? s[2])!, true))\n if (ext === 'mdx') out.push(...fromScript(code.replace(/^(?!import|export|<).*$/gm, ''), true))\n }\n return out\n}\n","import { globSync, readFileSync } from 'node:fs'\nimport { relative, resolve } from 'node:path'\nimport { createUnplugin } from 'unplugin'\nimport { css, getCssText, resetStyles, setDevWarnings, staticMarkerCss, type StyleObject } from '@sobagu/core'\nimport { extract } from './extract'\n\nexport { extract } from './extract'\n\nexport interface SobaguCompilerOptions {\n /** Project root (default: process.cwd()). */\n root?: string\n /** Globs (relative to root) scanned at build start. */\n include?: string[]\n /** Globs to skip. node_modules and dist are always skipped. */\n exclude?: string[]\n /** Styles to always include, e.g. ones built from data at runtime: [{ bg: 'danger' }, { md: { cols: 3 } }] */\n safelist?: StyleObject[]\n}\n\n/** Import this id once in your app entry: import 'virtual:sobagu.css' */\nexport const VIRTUAL_ID = 'virtual:sobagu.css'\nconst RESOLVED_ID = '/__sobagu.css'\n\nconst DEFAULT_INCLUDE = ['**/*.{js,jsx,ts,tsx,mjs,mts,vue,svelte,astro,html,mdx}']\nconst SOURCE_RE = /\\.(jsx?|tsx?|mjs|mts|vue|svelte|astro|html|mdx)($|\\?)/\nconst SKIP_RE = /[\\\\/](node_modules|dist|\\.git|\\.claude)[\\\\/]/\n\n/** Generate the full stylesheet for a set of style objects: layers + theme + reset + utilities + marker. */\nexport function generateCss(styles: Iterable<StyleObject>): string {\n resetStyles()\n setDevWarnings(false)\n try {\n for (const s of styles) css(s)\n return `${getCssText()}\\n${staticMarkerCss}\\n`\n } finally {\n setDevWarnings(true)\n resetStyles()\n }\n}\n\n// `| undefined` makes the options argument optional in the typed plugins: `sobagu()` in a config.\nexport const sobagu = createUnplugin<SobaguCompilerOptions | undefined>((options = {}) => {\n const root = resolve(options.root ?? process.cwd())\n const files = new Map<string, StyleObject[]>()\n let onChange: (() => void) | undefined\n\n const scan = () => {\n const found = globSync(options.include ?? DEFAULT_INCLUDE, {\n cwd: root,\n exclude: (p: string) => /(^|[\\\\/])(node_modules|dist|\\.git|\\.claude)([\\\\/]|$)/.test(typeof p === 'string' ? p : String(p)),\n })\n for (const rel of found) {\n if (options.exclude?.some((g) => rel.includes(g))) continue\n const abs = resolve(root, rel)\n try {\n files.set(abs, extract(readFileSync(abs, 'utf8'), abs))\n } catch {\n /* unreadable file: skip */\n }\n }\n }\n\n const all = () => [...files.values()].flat().concat(options.safelist ?? [])\n\n return {\n name: 'sobagu',\n enforce: 'pre',\n buildStart() {\n scan()\n },\n resolveId(id) {\n return id === VIRTUAL_ID || id === RESOLVED_ID ? RESOLVED_ID : null\n },\n loadInclude: (id) => id === RESOLVED_ID,\n load(id) {\n return id === RESOLVED_ID ? generateCss(all()) : null\n },\n transformInclude: (id) => SOURCE_RE.test(id) && !SKIP_RE.test(id) && id !== RESOLVED_ID,\n transform(code, id) {\n const file = id.split('?')[0]!\n const next = extract(code, file)\n const prev = files.get(file)\n files.set(file, next)\n if (onChange && JSON.stringify(prev) !== JSON.stringify(next)) onChange()\n return null\n },\n vite: {\n configureServer(server) {\n onChange = () => {\n const mod = server.moduleGraph.getModuleById(RESOLVED_ID)\n if (mod) void server.reloadModule(mod)\n }\n },\n },\n }\n})\n\n/** For tests and tools: the files the plugin scanned, relative to root. */\nexport const _internal = { relative }\n"],"mappings":";;;;;;;AAIA,IAAM,aAAsD;CAC1D,KAAK,KAAA;CACL,OAAO;EAAE,SAAS;EAAQ,SAAS;EAAO,KAAK;CAAK;CACpD,MAAM;EAAE,SAAS;EAAQ,KAAK;CAAK;CACnC,MAAM,KAAA;AACR;AAEA,IAAM,UAAU,OAAO,SAAS;;AAKhC,IAAM,OAAN,MAAW;CACmB;CAA5B,YAAY,SAAkC;EAAlB,KAAA,UAAA;CAAmB;AACjD;;AAGA,SAAS,SAAS,MAAsC;CACtD,IAAI,CAAC,MAAM,OAAO;CAClB,QAAQ,KAAK,MAAb;EACE,KAAK;EACL,KAAK;EACL,KAAK,kBACH,OAAO,KAAK;EACd,KAAK,eACH;EACF,KAAK,mBAAmB;GACtB,MAAM,QAAQ,KAAK;GACnB,MAAM,SAAS,KAAK;GACpB,OAAO,MAAM,WAAW,IAAI,OAAO,EAAE,EAAE,MAAM,SAAS;EACxD;EACA,KAAK,mBAAmB;GACtB,MAAM,IAAI,SAAS,KAAK,QAAgB;GACxC,OAAO,KAAK,aAAa,OAAO,OAAO,MAAM,WAAW,CAAC,IAAI;EAC/D;EACA,KAAK,oBAA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,GAAG,MAAM,GAAG,CAAC,CAAC;GAC3B,MAAM,OAAO,QAAQ,MAAM,IAAI;GAC/B,MAAM,OAAO,MAAM,IAAI,IAAI;GAC3B,MAAM,IAAI,MAAM,IAAI;GACpB,IAAI,YAAY,KAAK,UAAU,IAAI,MAAM,KAAK,UAAU,IAAI,GAAG,SAAS;GACxE,OAAO;EACT;EACA,MAAM,EACJ,gBAAgB,QAAQ;GACtB,iBAAiB;IACf,MAAM,MAAM,OAAO,YAAY,cAAc,WAAW;IACxD,IAAI,KAAK,OAAY,aAAa,GAAG;GACvC;EACF,EACF;CACF;AACF,CAAC;;AAGD,IAAa,YAAY,EAAE,SAAS"}
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vite.config.ts:
|
|
3
|
+
* import sobagu from '@sobagu/compiler/vite'
|
|
4
|
+
* export default { plugins: [sobagu()] }
|
|
5
|
+
* main.tsx:
|
|
6
|
+
* import 'virtual:sobagu.css'
|
|
7
|
+
*/
|
|
8
|
+
declare const _default: (options?: import("./index.js").SobaguCompilerOptions | undefined) => import("vite").Plugin<any>[] | import("vite").Plugin<any>;
|
|
9
|
+
export default _default;
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { i as sobagu } from "./src-CpiKjLBU.js";
|
|
2
|
+
// sobagu/packages/compiler/src/vite.ts
|
|
3
|
+
/**
|
|
4
|
+
* vite.config.ts:
|
|
5
|
+
* import sobagu from '@sobagu/compiler/vite'
|
|
6
|
+
* export default { plugins: [sobagu()] }
|
|
7
|
+
* main.tsx:
|
|
8
|
+
* import 'virtual:sobagu.css'
|
|
9
|
+
*/
|
|
10
|
+
var vite_default = sobagu.vite;
|
|
11
|
+
export { vite_default as default };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=vite.js.map
|
package/dist/vite.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import { sobagu } from './index'\n\n/**\n * vite.config.ts:\n * import sobagu from '@sobagu/compiler/vite'\n * export default { plugins: [sobagu()] }\n * main.tsx:\n * import 'virtual:sobagu.css'\n */\nexport default sobagu.vite\n"],"mappings":";;;;;;;;;AASA,IAAA,eAAe,OAAO"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** webpack / Next.js: config.plugins.push(sobagu()) and import 'virtual:sobagu.css' in your entry. */
|
|
2
|
+
declare const _default: (options?: import("./index.js").SobaguCompilerOptions | undefined) => WebpackPluginInstance;
|
|
3
|
+
export default _default;
|
|
4
|
+
export declare const rspack: (options?: import("./index.js").SobaguCompilerOptions | undefined) => RspackPluginInstance;
|
|
5
|
+
export declare const rollup: (options?: import("./index.js").SobaguCompilerOptions | undefined) => import("rollup").Plugin<any>[] | import("rollup").Plugin<any>;
|
|
6
|
+
export declare const esbuild: (options?: import("./index.js").SobaguCompilerOptions | undefined) => import("esbuild").Plugin;
|
package/dist/webpack.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { i as sobagu } from "./src-CpiKjLBU.js";
|
|
2
|
+
// sobagu/packages/compiler/src/webpack.ts
|
|
3
|
+
/** webpack / Next.js: config.plugins.push(sobagu()) and import 'virtual:sobagu.css' in your entry. */
|
|
4
|
+
var webpack_default = sobagu.webpack;
|
|
5
|
+
var rspack = sobagu.rspack;
|
|
6
|
+
var rollup = sobagu.rollup;
|
|
7
|
+
var esbuild = sobagu.esbuild;
|
|
8
|
+
export { webpack_default as default, esbuild, rollup, rspack };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=webpack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webpack.js","names":[],"sources":["../src/webpack.ts"],"sourcesContent":["import { sobagu } from './index'\n\n/** webpack / Next.js: config.plugins.push(sobagu()) and import 'virtual:sobagu.css' in your entry. */\nexport default sobagu.webpack\nexport const rspack = sobagu.rspack\nexport const rollup = sobagu.rollup\nexport const esbuild = sobagu.esbuild\n"],"mappings":";;;AAGA,IAAA,kBAAe,OAAO;AACtB,IAAa,SAAS,OAAO;AAC7B,IAAa,SAAS,OAAO;AAC7B,IAAa,UAAU,OAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sobagu/compiler",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Build-time CSS for Sobagu CSS: one plugin for Vite, Rollup, webpack, esbuild and Rspack",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"vite-plugin",
|
|
7
|
+
"webpack-plugin",
|
|
8
|
+
"rollup-plugin",
|
|
9
|
+
"esbuild-plugin",
|
|
10
|
+
"rspack",
|
|
11
|
+
"css",
|
|
12
|
+
"zero-runtime",
|
|
13
|
+
"atomic-css"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "Sobagu contributors",
|
|
17
|
+
"homepage": "https://sobagucss.com",
|
|
18
|
+
"type": "module",
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./vite": {
|
|
27
|
+
"types": "./dist/vite.d.ts",
|
|
28
|
+
"import": "./dist/vite.js",
|
|
29
|
+
"default": "./dist/vite.js"
|
|
30
|
+
},
|
|
31
|
+
"./webpack": {
|
|
32
|
+
"types": "./dist/webpack.d.ts",
|
|
33
|
+
"import": "./dist/webpack.js",
|
|
34
|
+
"default": "./dist/webpack.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"main": "./dist/index.js",
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"files": [
|
|
40
|
+
"dist",
|
|
41
|
+
"LICENSE",
|
|
42
|
+
"README.md"
|
|
43
|
+
],
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": "^22.18.0 || >=24.11.0"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"prepack": "node ../../scripts/pack-manifest.mjs strip",
|
|
49
|
+
"postpack": "node ../../scripts/pack-manifest.mjs restore"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@babel/parser": "^8.1.2",
|
|
53
|
+
"@sobagu/core": "0.1.0",
|
|
54
|
+
"unplugin": "^3.7.0"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public",
|
|
58
|
+
"provenance": false
|
|
59
|
+
}
|
|
60
|
+
}
|