boss-css 0.0.1 → 0.0.3
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,379 @@
|
|
|
1
|
+
import { parseJson } from "../shared/json.mjs";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
//#region src/detect-fw/index.ts
|
|
6
|
+
const jsxFrameworks = [
|
|
7
|
+
{
|
|
8
|
+
id: "react",
|
|
9
|
+
name: "react",
|
|
10
|
+
label: "React",
|
|
11
|
+
fileType: "jsx",
|
|
12
|
+
className: "className",
|
|
13
|
+
jsx: {
|
|
14
|
+
importSource: "react",
|
|
15
|
+
runtimeModule: "react/jsx-runtime",
|
|
16
|
+
typesModule: "react",
|
|
17
|
+
typesNamespace: "JSX",
|
|
18
|
+
elementType: "BossJSX.ElementType",
|
|
19
|
+
componentProps: "BossJSX.ComponentPropsWithoutRef<C>"
|
|
20
|
+
},
|
|
21
|
+
detect: {
|
|
22
|
+
dependencies: [
|
|
23
|
+
"react",
|
|
24
|
+
"react-dom",
|
|
25
|
+
"react-native"
|
|
26
|
+
],
|
|
27
|
+
importSources: ["react"]
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: "preact",
|
|
32
|
+
name: "preact",
|
|
33
|
+
label: "Preact",
|
|
34
|
+
fileType: "jsx",
|
|
35
|
+
className: "className",
|
|
36
|
+
jsx: {
|
|
37
|
+
importSource: "preact",
|
|
38
|
+
runtimeModule: "preact/jsx-runtime",
|
|
39
|
+
typesModule: "preact",
|
|
40
|
+
typesNamespace: "JSX"
|
|
41
|
+
},
|
|
42
|
+
detect: {
|
|
43
|
+
dependencies: ["preact"],
|
|
44
|
+
importSources: ["preact"]
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: "solid",
|
|
49
|
+
name: "solid",
|
|
50
|
+
label: "Solid",
|
|
51
|
+
fileType: "jsx",
|
|
52
|
+
className: "class",
|
|
53
|
+
jsx: {
|
|
54
|
+
importSource: "solid-js",
|
|
55
|
+
runtimeModule: "solid-js/jsx-runtime",
|
|
56
|
+
typesModule: "solid-js",
|
|
57
|
+
typesNamespace: "JSX",
|
|
58
|
+
elementType: "BossJSX.ValidComponent",
|
|
59
|
+
componentProps: "BossJSX.ComponentProps<C>"
|
|
60
|
+
},
|
|
61
|
+
detect: {
|
|
62
|
+
dependencies: ["solid-js"],
|
|
63
|
+
importSources: ["solid-js"]
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: "qwik",
|
|
68
|
+
name: "qwik",
|
|
69
|
+
label: "Qwik",
|
|
70
|
+
fileType: "jsx",
|
|
71
|
+
className: "class",
|
|
72
|
+
jsx: {
|
|
73
|
+
importSource: "@builder.io/qwik",
|
|
74
|
+
runtimeModule: "@builder.io/qwik/jsx-runtime",
|
|
75
|
+
typesModule: "@builder.io/qwik",
|
|
76
|
+
typesNamespace: "JSX"
|
|
77
|
+
},
|
|
78
|
+
detect: {
|
|
79
|
+
dependencies: ["@builder.io/qwik", "@builder.io/qwik-city"],
|
|
80
|
+
importSources: ["@builder.io/qwik"]
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: "stencil",
|
|
85
|
+
name: "stencil",
|
|
86
|
+
label: "Stencil",
|
|
87
|
+
fileType: "jsx",
|
|
88
|
+
className: "class",
|
|
89
|
+
jsx: {
|
|
90
|
+
importSource: "@stencil/core",
|
|
91
|
+
runtimeModule: "@stencil/core/internal",
|
|
92
|
+
typesModule: "@stencil/core",
|
|
93
|
+
typesNamespace: "JSX"
|
|
94
|
+
},
|
|
95
|
+
detect: {
|
|
96
|
+
dependencies: ["@stencil/core"],
|
|
97
|
+
importSources: ["@stencil/core"]
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
];
|
|
101
|
+
const sfcFrameworks = [];
|
|
102
|
+
const frameworkById = new Map(jsxFrameworks.map((entry) => [entry.id, entry]));
|
|
103
|
+
const frameworkByImportSource = new Map(jsxFrameworks.flatMap((entry) => (entry.detect.importSources ?? []).map((source) => [source, entry])));
|
|
104
|
+
const defaultFramework = frameworkById.get("react");
|
|
105
|
+
const defaultElementType = "keyof BossIntrinsicElements | ((props: any) => any) | (new (props: any) => any)";
|
|
106
|
+
const defaultComponentProps = "C extends keyof BossIntrinsicElements ? BossIntrinsicElements[C] : any";
|
|
107
|
+
const stripJsonComments = (input) => {
|
|
108
|
+
let output = "";
|
|
109
|
+
let inString = false;
|
|
110
|
+
let stringChar = "";
|
|
111
|
+
let escaped = false;
|
|
112
|
+
let inLineComment = false;
|
|
113
|
+
let inBlockComment = false;
|
|
114
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
115
|
+
const char = input[index];
|
|
116
|
+
const next = input[index + 1];
|
|
117
|
+
if (inLineComment) {
|
|
118
|
+
if (char === "\n") {
|
|
119
|
+
inLineComment = false;
|
|
120
|
+
output += char;
|
|
121
|
+
}
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (inBlockComment) {
|
|
125
|
+
if (char === "*" && next === "/") {
|
|
126
|
+
inBlockComment = false;
|
|
127
|
+
index += 1;
|
|
128
|
+
}
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (inString) {
|
|
132
|
+
output += char;
|
|
133
|
+
if (escaped) {
|
|
134
|
+
escaped = false;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (char === "\\") {
|
|
138
|
+
escaped = true;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (char === stringChar) {
|
|
142
|
+
inString = false;
|
|
143
|
+
stringChar = "";
|
|
144
|
+
}
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (char === "\"" || char === "'") {
|
|
148
|
+
inString = true;
|
|
149
|
+
stringChar = char;
|
|
150
|
+
output += char;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (char === "/" && next === "/") {
|
|
154
|
+
inLineComment = true;
|
|
155
|
+
index += 1;
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (char === "/" && next === "*") {
|
|
159
|
+
inBlockComment = true;
|
|
160
|
+
index += 1;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
output += char;
|
|
164
|
+
}
|
|
165
|
+
return output;
|
|
166
|
+
};
|
|
167
|
+
const stripTrailingCommas = (input) => {
|
|
168
|
+
let output = "";
|
|
169
|
+
let inString = false;
|
|
170
|
+
let stringChar = "";
|
|
171
|
+
let escaped = false;
|
|
172
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
173
|
+
const char = input[index];
|
|
174
|
+
if (inString) {
|
|
175
|
+
output += char;
|
|
176
|
+
if (escaped) {
|
|
177
|
+
escaped = false;
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
if (char === "\\") {
|
|
181
|
+
escaped = true;
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (char === stringChar) {
|
|
185
|
+
inString = false;
|
|
186
|
+
stringChar = "";
|
|
187
|
+
}
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (char === "\"" || char === "'") {
|
|
191
|
+
inString = true;
|
|
192
|
+
stringChar = char;
|
|
193
|
+
output += char;
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if (char === ",") {
|
|
197
|
+
let lookahead = index + 1;
|
|
198
|
+
while (lookahead < input.length && /\s/.test(input[lookahead])) lookahead += 1;
|
|
199
|
+
const nextChar = input[lookahead];
|
|
200
|
+
if (nextChar === "}" || nextChar === "]") continue;
|
|
201
|
+
}
|
|
202
|
+
output += char;
|
|
203
|
+
}
|
|
204
|
+
return output;
|
|
205
|
+
};
|
|
206
|
+
const parseJsonLoose = (raw, filePath) => {
|
|
207
|
+
return parseJson(stripTrailingCommas(stripJsonComments(raw)), {
|
|
208
|
+
filePath,
|
|
209
|
+
allowTrailingCommas: true
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
const readPackageJson = async (cwd) => {
|
|
213
|
+
const filePath = path.join(cwd, "package.json");
|
|
214
|
+
const raw = await fs.readFile(filePath, "utf8").catch(() => null);
|
|
215
|
+
if (!raw) return null;
|
|
216
|
+
try {
|
|
217
|
+
return parseJson(raw, {
|
|
218
|
+
filePath,
|
|
219
|
+
allowTrailingCommas: true
|
|
220
|
+
});
|
|
221
|
+
} catch {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
const readTsconfig = async (cwd, preferredPath) => {
|
|
226
|
+
const candidates = preferredPath ? [preferredPath] : [
|
|
227
|
+
"tsconfig.json",
|
|
228
|
+
"tsconfig.app.json",
|
|
229
|
+
"tsconfig.base.json"
|
|
230
|
+
];
|
|
231
|
+
for (const candidate of candidates) {
|
|
232
|
+
const filePath = path.isAbsolute(candidate) ? candidate : path.join(cwd, candidate);
|
|
233
|
+
const raw = await fs.readFile(filePath, "utf8").catch(() => null);
|
|
234
|
+
if (!raw) continue;
|
|
235
|
+
try {
|
|
236
|
+
return parseJsonLoose(raw, filePath);
|
|
237
|
+
} catch {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return null;
|
|
242
|
+
};
|
|
243
|
+
const collectDependencies = (packageJson) => {
|
|
244
|
+
const fields = [
|
|
245
|
+
"dependencies",
|
|
246
|
+
"devDependencies",
|
|
247
|
+
"peerDependencies",
|
|
248
|
+
"optionalDependencies"
|
|
249
|
+
];
|
|
250
|
+
const deps = /* @__PURE__ */ new Set();
|
|
251
|
+
for (const field of fields) {
|
|
252
|
+
const value = packageJson[field];
|
|
253
|
+
if (!value || typeof value !== "object") continue;
|
|
254
|
+
for (const name of Object.keys(value)) deps.add(name);
|
|
255
|
+
}
|
|
256
|
+
return deps;
|
|
257
|
+
};
|
|
258
|
+
const createDescriptorFromImportSource = (importSource) => {
|
|
259
|
+
const match = frameworkByImportSource.get(importSource);
|
|
260
|
+
if (match) return match;
|
|
261
|
+
return {
|
|
262
|
+
id: "custom",
|
|
263
|
+
name: importSource,
|
|
264
|
+
label: importSource,
|
|
265
|
+
fileType: "jsx",
|
|
266
|
+
className: "className",
|
|
267
|
+
jsx: {
|
|
268
|
+
importSource,
|
|
269
|
+
runtimeModule: `${importSource}/jsx-runtime`,
|
|
270
|
+
typesModule: `${importSource}/jsx-runtime`,
|
|
271
|
+
typesNamespace: "JSX"
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
const applyFrameworkOverrides = (base, override) => {
|
|
276
|
+
if (!override) return base;
|
|
277
|
+
const next = { ...base };
|
|
278
|
+
if (override.className) next.className = override.className;
|
|
279
|
+
if (override.fileType) next.fileType = override.fileType;
|
|
280
|
+
if (override.jsx) next.jsx = {
|
|
281
|
+
importSource: override.jsx.importSource ?? next.jsx?.importSource ?? "",
|
|
282
|
+
runtimeModule: override.jsx.runtimeModule ?? next.jsx?.runtimeModule ?? "",
|
|
283
|
+
typesModule: override.jsx.typesModule ?? next.jsx?.typesModule ?? "",
|
|
284
|
+
typesNamespace: override.jsx.typesNamespace ?? next.jsx?.typesNamespace ?? "JSX",
|
|
285
|
+
elementType: override.jsx.elementType ?? next.jsx?.elementType ?? void 0,
|
|
286
|
+
componentProps: override.jsx.componentProps ?? next.jsx?.componentProps ?? void 0
|
|
287
|
+
};
|
|
288
|
+
return next;
|
|
289
|
+
};
|
|
290
|
+
const resolveFrameworkFromConfig = (config) => {
|
|
291
|
+
if (!config?.framework) return null;
|
|
292
|
+
const raw = config.framework;
|
|
293
|
+
if (typeof raw === "string") {
|
|
294
|
+
if (raw === "auto") return null;
|
|
295
|
+
const match = frameworkById.get(raw);
|
|
296
|
+
if (match) return match;
|
|
297
|
+
return createDescriptorFromImportSource(raw);
|
|
298
|
+
}
|
|
299
|
+
if (raw.name && raw.name !== "auto") {
|
|
300
|
+
const match = frameworkById.get(raw.name);
|
|
301
|
+
if (match) return applyFrameworkOverrides(match, raw);
|
|
302
|
+
return applyFrameworkOverrides(createDescriptorFromImportSource(raw.name), raw);
|
|
303
|
+
}
|
|
304
|
+
if (raw.jsx?.importSource || raw.jsx?.typesModule) return applyFrameworkOverrides(createDescriptorFromImportSource(raw.jsx.importSource ?? "custom-jsx-runtime"), raw);
|
|
305
|
+
if (raw.fileType) return applyFrameworkOverrides({
|
|
306
|
+
id: "unknown",
|
|
307
|
+
name: "unknown",
|
|
308
|
+
label: "Unknown",
|
|
309
|
+
fileType: raw.fileType,
|
|
310
|
+
className: "className"
|
|
311
|
+
}, raw);
|
|
312
|
+
return null;
|
|
313
|
+
};
|
|
314
|
+
const resolveFrameworkFromTsconfig = (tsconfig) => {
|
|
315
|
+
const compilerOptions = tsconfig?.compilerOptions;
|
|
316
|
+
if (!compilerOptions || typeof compilerOptions !== "object") return null;
|
|
317
|
+
const jsxImportSource = compilerOptions.jsxImportSource;
|
|
318
|
+
if (typeof jsxImportSource !== "string" || !jsxImportSource.trim()) return null;
|
|
319
|
+
return createDescriptorFromImportSource(jsxImportSource);
|
|
320
|
+
};
|
|
321
|
+
const resolveFrameworkFromPackageJson = (packageJson) => {
|
|
322
|
+
if (!packageJson) return null;
|
|
323
|
+
const deps = collectDependencies(packageJson);
|
|
324
|
+
for (const entry of jsxFrameworks) if (entry.detect.dependencies.some((dep) => deps.has(dep))) return entry;
|
|
325
|
+
for (const entry of sfcFrameworks) if (entry.detect.dependencies.some((dep) => deps.has(dep))) return entry;
|
|
326
|
+
return null;
|
|
327
|
+
};
|
|
328
|
+
const getJsxTypes = (framework) => {
|
|
329
|
+
const jsx = framework.jsx ?? defaultFramework.jsx;
|
|
330
|
+
return {
|
|
331
|
+
...jsx,
|
|
332
|
+
elementType: jsx?.elementType ?? defaultElementType,
|
|
333
|
+
componentProps: jsx?.componentProps ?? defaultComponentProps
|
|
334
|
+
};
|
|
335
|
+
};
|
|
336
|
+
const detectFramework = async (options = {}) => {
|
|
337
|
+
const cwd = options.cwd ?? process.cwd();
|
|
338
|
+
const notes = [];
|
|
339
|
+
const configMatch = resolveFrameworkFromConfig(options.config);
|
|
340
|
+
if (configMatch) return {
|
|
341
|
+
...configMatch,
|
|
342
|
+
source: "config",
|
|
343
|
+
notes
|
|
344
|
+
};
|
|
345
|
+
const tsconfigMatch = resolveFrameworkFromTsconfig(await readTsconfig(cwd, options.tsconfigPath));
|
|
346
|
+
if (tsconfigMatch) {
|
|
347
|
+
notes.push("tsconfig jsxImportSource");
|
|
348
|
+
return {
|
|
349
|
+
...tsconfigMatch,
|
|
350
|
+
source: "tsconfig",
|
|
351
|
+
notes
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
const packageMatch = resolveFrameworkFromPackageJson(options.packageJson ?? await readPackageJson(cwd));
|
|
355
|
+
if (packageMatch) {
|
|
356
|
+
notes.push("package.json dependencies");
|
|
357
|
+
return {
|
|
358
|
+
...packageMatch,
|
|
359
|
+
source: "package.json",
|
|
360
|
+
notes
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
return {
|
|
364
|
+
...defaultFramework,
|
|
365
|
+
source: "default",
|
|
366
|
+
notes
|
|
367
|
+
};
|
|
368
|
+
};
|
|
369
|
+
const listFrameworks = () => jsxFrameworks.map((entry) => ({
|
|
370
|
+
id: entry.id,
|
|
371
|
+
name: entry.name,
|
|
372
|
+
label: entry.label,
|
|
373
|
+
fileType: entry.fileType,
|
|
374
|
+
className: entry.className,
|
|
375
|
+
jsx: entry.jsx
|
|
376
|
+
}));
|
|
377
|
+
|
|
378
|
+
//#endregion
|
|
379
|
+
export { detectFramework, getJsxTypes, listFrameworks };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/dev/client.ts
|
|
3
|
+
const DEVTOOLS_ATTR = "data-boss-devtools";
|
|
4
|
+
const ROOT_ID = "boss-devtools-root";
|
|
5
|
+
function startDevClient({ port }) {
|
|
6
|
+
if (typeof window === "undefined") return;
|
|
7
|
+
const nextPort = Number(port);
|
|
8
|
+
if (!Number.isFinite(nextPort)) return;
|
|
9
|
+
const container = ensureRoot();
|
|
10
|
+
loadDevtools().then((mount) => {
|
|
11
|
+
if (!mount) return;
|
|
12
|
+
mount(container, nextPort);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function ensureRoot() {
|
|
16
|
+
let container = document.getElementById(ROOT_ID);
|
|
17
|
+
if (!container) {
|
|
18
|
+
container = document.createElement("div");
|
|
19
|
+
container.id = ROOT_ID;
|
|
20
|
+
container.setAttribute(DEVTOOLS_ATTR, "true");
|
|
21
|
+
document.body.appendChild(container);
|
|
22
|
+
}
|
|
23
|
+
return container;
|
|
24
|
+
}
|
|
25
|
+
async function loadDevtools() {
|
|
26
|
+
const globalMount = globalThis.__bossDevtoolsApp?.mountDevtoolsApp;
|
|
27
|
+
if (typeof globalMount === "function") return globalMount;
|
|
28
|
+
try {
|
|
29
|
+
const module = await import("boss-css/devtools-app");
|
|
30
|
+
if (typeof module.mountDevtoolsApp === "function") return module.mountDevtoolsApp;
|
|
31
|
+
const fallback = globalThis.__bossDevtoolsApp?.mountDevtoolsApp;
|
|
32
|
+
return typeof fallback === "function" ? fallback : null;
|
|
33
|
+
} catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
exports.startDevClient = startDevClient;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/dev/client.ts
|
|
2
|
+
const DEVTOOLS_ATTR = "data-boss-devtools";
|
|
3
|
+
const ROOT_ID = "boss-devtools-root";
|
|
4
|
+
function startDevClient({ port }) {
|
|
5
|
+
if (typeof window === "undefined") return;
|
|
6
|
+
const nextPort = Number(port);
|
|
7
|
+
if (!Number.isFinite(nextPort)) return;
|
|
8
|
+
const container = ensureRoot();
|
|
9
|
+
loadDevtools().then((mount) => {
|
|
10
|
+
if (!mount) return;
|
|
11
|
+
mount(container, nextPort);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function ensureRoot() {
|
|
15
|
+
let container = document.getElementById(ROOT_ID);
|
|
16
|
+
if (!container) {
|
|
17
|
+
container = document.createElement("div");
|
|
18
|
+
container.id = ROOT_ID;
|
|
19
|
+
container.setAttribute(DEVTOOLS_ATTR, "true");
|
|
20
|
+
document.body.appendChild(container);
|
|
21
|
+
}
|
|
22
|
+
return container;
|
|
23
|
+
}
|
|
24
|
+
async function loadDevtools() {
|
|
25
|
+
const globalMount = globalThis.__bossDevtoolsApp?.mountDevtoolsApp;
|
|
26
|
+
if (typeof globalMount === "function") return globalMount;
|
|
27
|
+
try {
|
|
28
|
+
const module = await import("boss-css/devtools-app");
|
|
29
|
+
if (typeof module.mountDevtoolsApp === "function") return module.mountDevtoolsApp;
|
|
30
|
+
const fallback = globalThis.__bossDevtoolsApp?.mountDevtoolsApp;
|
|
31
|
+
return typeof fallback === "function" ? fallback : null;
|
|
32
|
+
} catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { startDevClient };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/dev/plugin/browser.ts
|
|
3
|
+
const name = "devtools";
|
|
4
|
+
const onBrowserObjectStart = (api, { output = {}, contexts = [] }) => {
|
|
5
|
+
if (contexts.length) return;
|
|
6
|
+
output["data-boss"] = "true";
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
exports.name = name;
|
|
11
|
+
exports.onBrowserObjectStart = onBrowserObjectStart;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_shared = require('../shared.cjs');
|
|
3
|
+
const require_dev_server = require('../server.cjs');
|
|
4
|
+
const require_port = require('../port.cjs');
|
|
5
|
+
|
|
6
|
+
//#region src/dev/plugin/server.ts
|
|
7
|
+
var server_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
8
|
+
name: () => name,
|
|
9
|
+
onBoot: () => onBoot,
|
|
10
|
+
onSession: () => onSession
|
|
11
|
+
});
|
|
12
|
+
const name = "devtools";
|
|
13
|
+
let devServer = null;
|
|
14
|
+
let starting = null;
|
|
15
|
+
let handlersInstalled = false;
|
|
16
|
+
const onBoot = async (api) => {
|
|
17
|
+
if (process.env.NODE_ENV === "production") return;
|
|
18
|
+
api.file.js.import({ from: "boss-css/dev/runtime" });
|
|
19
|
+
api.file.js.importAndConfig({
|
|
20
|
+
name: "onBrowserObjectStart",
|
|
21
|
+
from: "boss-css/dev/plugin/browser"
|
|
22
|
+
});
|
|
23
|
+
const hostApiVar = api.file.js.import({
|
|
24
|
+
name: "api",
|
|
25
|
+
from: "boss-css/api/browser"
|
|
26
|
+
});
|
|
27
|
+
api.file.js.set("body", "devtools:globalThis", `globalThis.host$$ = ${hostApiVar}`);
|
|
28
|
+
const port = Number(api.devServer?.port);
|
|
29
|
+
if (Number.isFinite(port) && port !== require_shared.DEFAULT_DEV_PORT) api.file.js.config({
|
|
30
|
+
from: "boss-css/dev/plugin",
|
|
31
|
+
config: { devServer: { port } }
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const ensureDevServer = async (api, session) => {
|
|
35
|
+
if (devServer) return devServer;
|
|
36
|
+
if (starting) return starting;
|
|
37
|
+
const basePort = Number.isFinite(Number(api.devServer?.port)) ? Number(api.devServer?.port) : require_shared.DEFAULT_DEV_PORT;
|
|
38
|
+
starting = require_dev_server.startDevServer({
|
|
39
|
+
port: basePort,
|
|
40
|
+
maxPort: basePort + 49
|
|
41
|
+
}).catch((err) => {
|
|
42
|
+
starting = null;
|
|
43
|
+
throw err;
|
|
44
|
+
});
|
|
45
|
+
devServer = await starting;
|
|
46
|
+
starting = null;
|
|
47
|
+
const shouldInsert = devServer.port !== require_shared.DEFAULT_DEV_PORT;
|
|
48
|
+
if (session?.configPath) await require_port.updateDevPort(session.configPath, devServer.port, shouldInsert);
|
|
49
|
+
if (session?.runtimePath) await require_port.updateRuntimePort(session.runtimePath, devServer.port);
|
|
50
|
+
if (!handlersInstalled) {
|
|
51
|
+
handlersInstalled = true;
|
|
52
|
+
const closeServer = () => {
|
|
53
|
+
if (!devServer) return;
|
|
54
|
+
devServer.server.close();
|
|
55
|
+
devServer = null;
|
|
56
|
+
};
|
|
57
|
+
process.once("exit", closeServer);
|
|
58
|
+
process.once("SIGINT", () => {
|
|
59
|
+
closeServer();
|
|
60
|
+
process.exit();
|
|
61
|
+
});
|
|
62
|
+
process.once("SIGTERM", () => {
|
|
63
|
+
closeServer();
|
|
64
|
+
process.exit();
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return devServer;
|
|
68
|
+
};
|
|
69
|
+
const onSession = async (api, session) => {
|
|
70
|
+
if (process.env.NODE_ENV === "production") return;
|
|
71
|
+
if (!session || session.phase !== "start") return;
|
|
72
|
+
if (session.kind !== "watch" && session.kind !== "postcss") return;
|
|
73
|
+
if (api?.devServer?.autoStart === false) return;
|
|
74
|
+
await ensureDevServer(api, session);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
exports.name = name;
|
|
79
|
+
exports.onBoot = onBoot;
|
|
80
|
+
exports.onSession = onSession;
|
|
81
|
+
Object.defineProperty(exports, 'server_exports', {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
get: function () {
|
|
84
|
+
return server_exports;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { __exportAll } from "../../_virtual/rolldown_runtime.mjs";
|
|
2
|
+
import { DEFAULT_DEV_PORT } from "../shared.mjs";
|
|
3
|
+
import { startDevServer } from "../server.mjs";
|
|
4
|
+
import { updateDevPort, updateRuntimePort } from "../port.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/dev/plugin/server.ts
|
|
7
|
+
var server_exports = /* @__PURE__ */ __exportAll({
|
|
8
|
+
name: () => name,
|
|
9
|
+
onBoot: () => onBoot,
|
|
10
|
+
onSession: () => onSession
|
|
11
|
+
});
|
|
12
|
+
const name = "devtools";
|
|
13
|
+
let devServer = null;
|
|
14
|
+
let starting = null;
|
|
15
|
+
let handlersInstalled = false;
|
|
16
|
+
const onBoot = async (api) => {
|
|
17
|
+
if (process.env.NODE_ENV === "production") return;
|
|
18
|
+
api.file.js.import({ from: "boss-css/dev/runtime" });
|
|
19
|
+
api.file.js.importAndConfig({
|
|
20
|
+
name: "onBrowserObjectStart",
|
|
21
|
+
from: "boss-css/dev/plugin/browser"
|
|
22
|
+
});
|
|
23
|
+
const hostApiVar = api.file.js.import({
|
|
24
|
+
name: "api",
|
|
25
|
+
from: "boss-css/api/browser"
|
|
26
|
+
});
|
|
27
|
+
api.file.js.set("body", "devtools:globalThis", `globalThis.host$$ = ${hostApiVar}`);
|
|
28
|
+
const port = Number(api.devServer?.port);
|
|
29
|
+
if (Number.isFinite(port) && port !== DEFAULT_DEV_PORT) api.file.js.config({
|
|
30
|
+
from: "boss-css/dev/plugin",
|
|
31
|
+
config: { devServer: { port } }
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const ensureDevServer = async (api, session) => {
|
|
35
|
+
if (devServer) return devServer;
|
|
36
|
+
if (starting) return starting;
|
|
37
|
+
const basePort = Number.isFinite(Number(api.devServer?.port)) ? Number(api.devServer?.port) : DEFAULT_DEV_PORT;
|
|
38
|
+
starting = startDevServer({
|
|
39
|
+
port: basePort,
|
|
40
|
+
maxPort: basePort + 49
|
|
41
|
+
}).catch((err) => {
|
|
42
|
+
starting = null;
|
|
43
|
+
throw err;
|
|
44
|
+
});
|
|
45
|
+
devServer = await starting;
|
|
46
|
+
starting = null;
|
|
47
|
+
const shouldInsert = devServer.port !== DEFAULT_DEV_PORT;
|
|
48
|
+
if (session?.configPath) await updateDevPort(session.configPath, devServer.port, shouldInsert);
|
|
49
|
+
if (session?.runtimePath) await updateRuntimePort(session.runtimePath, devServer.port);
|
|
50
|
+
if (!handlersInstalled) {
|
|
51
|
+
handlersInstalled = true;
|
|
52
|
+
const closeServer = () => {
|
|
53
|
+
if (!devServer) return;
|
|
54
|
+
devServer.server.close();
|
|
55
|
+
devServer = null;
|
|
56
|
+
};
|
|
57
|
+
process.once("exit", closeServer);
|
|
58
|
+
process.once("SIGINT", () => {
|
|
59
|
+
closeServer();
|
|
60
|
+
process.exit();
|
|
61
|
+
});
|
|
62
|
+
process.once("SIGTERM", () => {
|
|
63
|
+
closeServer();
|
|
64
|
+
process.exit();
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return devServer;
|
|
68
|
+
};
|
|
69
|
+
const onSession = async (api, session) => {
|
|
70
|
+
if (process.env.NODE_ENV === "production") return;
|
|
71
|
+
if (!session || session.phase !== "start") return;
|
|
72
|
+
if (session.kind !== "watch" && session.kind !== "postcss") return;
|
|
73
|
+
if (api?.devServer?.autoStart === false) return;
|
|
74
|
+
await ensureDevServer(api, session);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
export { name, onBoot, onSession, server_exports };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let node_fs_promises = require("node:fs/promises");
|
|
3
|
+
node_fs_promises = require_rolldown_runtime.__toESM(node_fs_promises);
|
|
4
|
+
|
|
5
|
+
//#region src/dev/port.ts
|
|
6
|
+
const updateDevPort = async (configPath, port, allowInsert) => {
|
|
7
|
+
const raw = await node_fs_promises.default.readFile(configPath, "utf8");
|
|
8
|
+
const portPattern = /(devServer\s*:\s*{[^}]*port\s*:\s*)(\d+)/m;
|
|
9
|
+
if (portPattern.test(raw)) {
|
|
10
|
+
const next = raw.replace(portPattern, `$1${port}`);
|
|
11
|
+
await node_fs_promises.default.writeFile(configPath, next);
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
if (!allowInsert) return true;
|
|
15
|
+
const folderLine = raw.match(/^[ \t]*folder\s*:[^\n]*$/m);
|
|
16
|
+
if (folderLine) {
|
|
17
|
+
const insert = `${folderLine[0].match(/^[ \t]*/)?.[0] ?? " "}devServer: { port: ${port} },\n`;
|
|
18
|
+
const next = raw.replace(folderLine[0], `${folderLine[0]}\n${insert}`);
|
|
19
|
+
await node_fs_promises.default.writeFile(configPath, next);
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
const defaultExport = raw.match(/export default\s*{\s*/m);
|
|
23
|
+
if (defaultExport) {
|
|
24
|
+
const insert = `export default {\n devServer: { port: ${port} },\n`;
|
|
25
|
+
const next = raw.replace(defaultExport[0], insert);
|
|
26
|
+
await node_fs_promises.default.writeFile(configPath, next);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
};
|
|
31
|
+
const updateRuntimePort = async (runtimePath, port) => {
|
|
32
|
+
try {
|
|
33
|
+
const raw = await node_fs_promises.default.readFile(runtimePath, "utf8");
|
|
34
|
+
const markerPattern = /port:\s*\d+(?=[^\n]*boss-dev-port)/;
|
|
35
|
+
if (!markerPattern.test(raw)) return false;
|
|
36
|
+
const next = raw.replace(markerPattern, `port: ${port}`);
|
|
37
|
+
await node_fs_promises.default.writeFile(runtimePath, next);
|
|
38
|
+
return true;
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
exports.updateDevPort = updateDevPort;
|
|
46
|
+
exports.updateRuntimePort = updateRuntimePort;
|