elegance-js 2.1.37 → 3.0.1
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 +90 -4
- package/bin/bootstrap.js +18 -0
- package/bin/run.js +2 -0
- package/dist/build/common.d.ts +147 -0
- package/dist/build/common.d.ts.map +1 -0
- package/dist/build/common.js +599 -0
- package/dist/build/dev.d.ts +2 -0
- package/dist/build/dev.d.ts.map +1 -0
- package/dist/build/dev.js +234 -0
- package/dist/build/prod.d.ts +2 -0
- package/dist/build/prod.d.ts.map +1 -0
- package/dist/build/prod.js +212 -0
- package/dist/build/render.d.ts +29 -0
- package/dist/build/render.d.ts.map +1 -0
- package/dist/build/render.js +234 -0
- package/dist/client.d.ts +13 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +677 -0
- package/dist/config.d.ts +7 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +80 -0
- package/dist/constants.d.ts +10 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +20 -0
- package/dist/elements.d.ts +2 -0
- package/dist/elements.d.ts.map +1 -0
- package/dist/elements.js +14 -0
- package/dist/error.d.ts +20 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +123 -0
- package/dist/globals.d.ts +6 -0
- package/dist/globals.d.ts.map +1 -0
- package/dist/globals.js +106 -0
- package/dist/logger.d.ts +32 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +72 -0
- package/dist/page-tools.d.ts +19 -0
- package/dist/page-tools.d.ts.map +1 -0
- package/dist/page-tools.js +141 -0
- package/dist/processing/oxc.d.ts +17 -0
- package/dist/processing/oxc.d.ts.map +1 -0
- package/dist/processing/oxc.js +938 -0
- package/dist/processing/taglist.d.ts +2 -0
- package/dist/processing/taglist.d.ts.map +1 -0
- package/dist/processing/taglist.js +215 -0
- package/dist/processing/tsx.d.ts +2 -0
- package/dist/processing/tsx.d.ts.map +1 -0
- package/dist/processing/tsx.js +131 -0
- package/dist/run.d.ts +3 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +147 -0
- package/dist/server/dev.d.ts +2 -0
- package/dist/server/dev.d.ts.map +1 -0
- package/dist/server/dev.js +10 -0
- package/dist/server/prod.d.ts +2 -0
- package/dist/server/prod.d.ts.map +1 -0
- package/dist/server/prod.js +42 -0
- package/dist/server/security.d.ts +64 -0
- package/dist/server/security.d.ts.map +1 -0
- package/dist/server/security.js +120 -0
- package/dist/server/server.d.ts +73 -99
- package/dist/server/server.d.ts.map +1 -0
- package/dist/server/server.js +830 -680
- package/dist/types/component.d.ts +85 -0
- package/dist/types/component.d.ts.map +1 -0
- package/dist/types/component.js +0 -0
- package/dist/types/config.d.ts +12 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +0 -0
- package/dist/types/elements.d.ts +412 -0
- package/dist/types/elements.d.ts.map +1 -0
- package/dist/types/elements.js +0 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/jsx.d.ts +976 -0
- package/dist/types/jsx.d.ts.map +1 -0
- package/dist/types/jsx.js +0 -0
- package/dist/types/server-actions.d.ts +60 -0
- package/dist/types/server-actions.d.ts.map +1 -0
- package/dist/types/server-actions.js +0 -0
- package/dist/user-utils.d.ts +23 -0
- package/dist/user-utils.d.ts.map +1 -0
- package/dist/user-utils.js +61 -0
- package/package.json +48 -27
- package/dist/client/effect.d.ts +0 -27
- package/dist/client/effect.js +0 -37
- package/dist/client/eventListener.d.ts +0 -39
- package/dist/client/eventListener.js +0 -52
- package/dist/client/loadHook.d.ts +0 -34
- package/dist/client/loadHook.js +0 -52
- package/dist/client/observer.d.ts +0 -36
- package/dist/client/observer.js +0 -66
- package/dist/client/runtime.d.ts +0 -105
- package/dist/client/runtime.js +0 -624
- package/dist/client/state.d.ts +0 -40
- package/dist/client/state.js +0 -110
- package/dist/compilation/compiler.d.ts +0 -163
- package/dist/compilation/compiler.js +0 -1164
- package/dist/components/ClientComponent.d.ts +0 -22
- package/dist/components/ClientComponent.js +0 -55
- package/dist/components/Link.d.ts +0 -16
- package/dist/components/Link.js +0 -21
- package/dist/components/Portal.d.ts +0 -2
- package/dist/components/Portal.js +0 -2
- package/dist/elements/element.d.ts +0 -87
- package/dist/elements/element.js +0 -33
- package/dist/elements/element_list.d.ts +0 -7
- package/dist/elements/element_list.js +0 -65
- package/dist/elements/raw.d.ts +0 -14
- package/dist/elements/raw.js +0 -78
- package/dist/elements/specific_props.d.ts +0 -750
- package/dist/elements/specific_props.js +0 -1
- package/dist/global.d.ts +0 -229
- package/dist/global.js +0 -1
- package/dist/index.d.ts +0 -16
- package/dist/index.js +0 -12
- package/dist/server/layout.d.ts +0 -34
- package/dist/server/layout.js +0 -6
- package/dist/server/log.d.ts +0 -12
- package/dist/server/log.js +0 -64
- package/dist/server/page.d.ts +0 -32
- package/dist/server/page.js +0 -6
- package/dist/server/runtime.d.ts +0 -6
- package/dist/server/runtime.js +0 -92
- package/scripts/bootstrap.js +0 -95
- package/scripts/bootstrap_files/elegance.txt +0 -40
- package/scripts/bootstrap_files/index.txt +0 -3
- package/scripts/bootstrap_files/layout.txt +0 -46
- package/scripts/bootstrap_files/middleware.txt +0 -18
- package/scripts/bootstrap_files/page.txt +0 -123
- package/scripts/bootstrap_files/route.txt +0 -6
- package/scripts/elegance_dev.ts +0 -42
- package/scripts/elegance_prod.ts +0 -42
- package/scripts/elegance_static.ts +0 -26
- package/scripts/prod.js +0 -13
- package/scripts/run.js +0 -13
- package/scripts/static.js +0 -13
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const ALL_TAGS: readonly ["html", "head", "title", "base", "link", "meta", "style", "body", "article", "section", "nav", "aside", "h1", "h2", "h3", "h4", "h5", "h6", "header", "footer", "address", "main", "p", "hr", "pre", "blockquote", "ol", "ul", "li", "dl", "dt", "dd", "figure", "figcaption", "div", "a", "em", "strong", "small", "s", "cite", "q", "dfn", "abbr", "ruby", "rt", "rp", "data", "time", "code", "kbd", "samp", "sub", "sup", "i", "b", "u", "mark", "bdi", "bdo", "span", "br", "wbr", "ins", "del", "picture", "source", "img", "iframe", "embed", "object", "param", "video", "audio", "trackEl", "map", "area", "table", "caption", "colgroup", "col", "tbody", "thead", "tfoot", "tr", "td", "th", "form", "label", "input", "button", "select", "datalist", "optgroup", "option", "textarea", "output", "progress", "meter", "fieldset", "legend", "details", "summary", "dialog", "script", "noscript", "template", "slot", "canvas", "svg", "g", "defs", "desc", "title", "symbol", "use", "image", "switchEl", "path", "rect", "circle", "ellipse", "line", "polyline", "polygon", "text", "tspan", "textPath", "marker", "pattern", "mask", "clipPath", "linearGradient", "radialGradient", "stopEl", "filter", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence", "foreignObject", "view", "animate", "animateMotion", "animateTransform", "set", "mpath", "math", "maction", "maligngroup", "malignmark", "menclose", "merror", "mfenced", "mfrac", "mglyph", "mi", "mlabeledtr", "mlongdiv", "mmultiscripts", "mn", "mo", "mover", "mpadded", "mphantom", "mroot", "mrow", "ms", "mscarries", "mscarry", "msgroup", "msline", "mspace", "msqrt", "msrow", "mstack", "mstyle", "msub", "msubsup", "msup", "mtable", "mtd", "mtext", "mtr", "munder", "munderover", "semantics", "annotation", "annotation-xml"];
|
|
2
|
+
//# sourceMappingURL=taglist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"taglist.d.ts","sourceRoot":"","sources":["../../src/processing/taglist.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,+iEAwCX,CAAC"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
const ALL_TAGS = [
|
|
2
|
+
"html",
|
|
3
|
+
"head",
|
|
4
|
+
"title",
|
|
5
|
+
"base",
|
|
6
|
+
"link",
|
|
7
|
+
"meta",
|
|
8
|
+
"style",
|
|
9
|
+
"body",
|
|
10
|
+
"article",
|
|
11
|
+
"section",
|
|
12
|
+
"nav",
|
|
13
|
+
"aside",
|
|
14
|
+
"h1",
|
|
15
|
+
"h2",
|
|
16
|
+
"h3",
|
|
17
|
+
"h4",
|
|
18
|
+
"h5",
|
|
19
|
+
"h6",
|
|
20
|
+
"header",
|
|
21
|
+
"footer",
|
|
22
|
+
"address",
|
|
23
|
+
"main",
|
|
24
|
+
"p",
|
|
25
|
+
"hr",
|
|
26
|
+
"pre",
|
|
27
|
+
"blockquote",
|
|
28
|
+
"ol",
|
|
29
|
+
"ul",
|
|
30
|
+
"li",
|
|
31
|
+
"dl",
|
|
32
|
+
"dt",
|
|
33
|
+
"dd",
|
|
34
|
+
"figure",
|
|
35
|
+
"figcaption",
|
|
36
|
+
"div",
|
|
37
|
+
"a",
|
|
38
|
+
"em",
|
|
39
|
+
"strong",
|
|
40
|
+
"small",
|
|
41
|
+
"s",
|
|
42
|
+
"cite",
|
|
43
|
+
"q",
|
|
44
|
+
"dfn",
|
|
45
|
+
"abbr",
|
|
46
|
+
"ruby",
|
|
47
|
+
"rt",
|
|
48
|
+
"rp",
|
|
49
|
+
"data",
|
|
50
|
+
"time",
|
|
51
|
+
"code",
|
|
52
|
+
"kbd",
|
|
53
|
+
"samp",
|
|
54
|
+
"sub",
|
|
55
|
+
"sup",
|
|
56
|
+
"i",
|
|
57
|
+
"b",
|
|
58
|
+
"u",
|
|
59
|
+
"mark",
|
|
60
|
+
"bdi",
|
|
61
|
+
"bdo",
|
|
62
|
+
"span",
|
|
63
|
+
"br",
|
|
64
|
+
"wbr",
|
|
65
|
+
"ins",
|
|
66
|
+
"del",
|
|
67
|
+
"picture",
|
|
68
|
+
"source",
|
|
69
|
+
"img",
|
|
70
|
+
"iframe",
|
|
71
|
+
"embed",
|
|
72
|
+
"object",
|
|
73
|
+
"param",
|
|
74
|
+
"video",
|
|
75
|
+
"audio",
|
|
76
|
+
"trackEl",
|
|
77
|
+
"map",
|
|
78
|
+
"area",
|
|
79
|
+
"table",
|
|
80
|
+
"caption",
|
|
81
|
+
"colgroup",
|
|
82
|
+
"col",
|
|
83
|
+
"tbody",
|
|
84
|
+
"thead",
|
|
85
|
+
"tfoot",
|
|
86
|
+
"tr",
|
|
87
|
+
"td",
|
|
88
|
+
"th",
|
|
89
|
+
"form",
|
|
90
|
+
"label",
|
|
91
|
+
"input",
|
|
92
|
+
"button",
|
|
93
|
+
"select",
|
|
94
|
+
"datalist",
|
|
95
|
+
"optgroup",
|
|
96
|
+
"option",
|
|
97
|
+
"textarea",
|
|
98
|
+
"output",
|
|
99
|
+
"progress",
|
|
100
|
+
"meter",
|
|
101
|
+
"fieldset",
|
|
102
|
+
"legend",
|
|
103
|
+
"details",
|
|
104
|
+
"summary",
|
|
105
|
+
"dialog",
|
|
106
|
+
"script",
|
|
107
|
+
"noscript",
|
|
108
|
+
"template",
|
|
109
|
+
"slot",
|
|
110
|
+
"canvas",
|
|
111
|
+
"svg",
|
|
112
|
+
"g",
|
|
113
|
+
"defs",
|
|
114
|
+
"desc",
|
|
115
|
+
"title",
|
|
116
|
+
"symbol",
|
|
117
|
+
"use",
|
|
118
|
+
"image",
|
|
119
|
+
"switchEl",
|
|
120
|
+
"path",
|
|
121
|
+
"rect",
|
|
122
|
+
"circle",
|
|
123
|
+
"ellipse",
|
|
124
|
+
"line",
|
|
125
|
+
"polyline",
|
|
126
|
+
"polygon",
|
|
127
|
+
"text",
|
|
128
|
+
"tspan",
|
|
129
|
+
"textPath",
|
|
130
|
+
"marker",
|
|
131
|
+
"pattern",
|
|
132
|
+
"mask",
|
|
133
|
+
"clipPath",
|
|
134
|
+
"linearGradient",
|
|
135
|
+
"radialGradient",
|
|
136
|
+
"stopEl",
|
|
137
|
+
"filter",
|
|
138
|
+
"feBlend",
|
|
139
|
+
"feColorMatrix",
|
|
140
|
+
"feComponentTransfer",
|
|
141
|
+
"feComposite",
|
|
142
|
+
"feConvolveMatrix",
|
|
143
|
+
"feDiffuseLighting",
|
|
144
|
+
"feDisplacementMap",
|
|
145
|
+
"feDistantLight",
|
|
146
|
+
"feDropShadow",
|
|
147
|
+
"feFlood",
|
|
148
|
+
"feFuncA",
|
|
149
|
+
"feFuncB",
|
|
150
|
+
"feFuncG",
|
|
151
|
+
"feFuncR",
|
|
152
|
+
"feGaussianBlur",
|
|
153
|
+
"feImage",
|
|
154
|
+
"feMerge",
|
|
155
|
+
"feMergeNode",
|
|
156
|
+
"feMorphology",
|
|
157
|
+
"feOffset",
|
|
158
|
+
"fePointLight",
|
|
159
|
+
"feSpecularLighting",
|
|
160
|
+
"feSpotLight",
|
|
161
|
+
"feTile",
|
|
162
|
+
"feTurbulence",
|
|
163
|
+
"foreignObject",
|
|
164
|
+
"view",
|
|
165
|
+
"animate",
|
|
166
|
+
"animateMotion",
|
|
167
|
+
"animateTransform",
|
|
168
|
+
"set",
|
|
169
|
+
"mpath",
|
|
170
|
+
"math",
|
|
171
|
+
"maction",
|
|
172
|
+
"maligngroup",
|
|
173
|
+
"malignmark",
|
|
174
|
+
"menclose",
|
|
175
|
+
"merror",
|
|
176
|
+
"mfenced",
|
|
177
|
+
"mfrac",
|
|
178
|
+
"mglyph",
|
|
179
|
+
"mi",
|
|
180
|
+
"mlabeledtr",
|
|
181
|
+
"mlongdiv",
|
|
182
|
+
"mmultiscripts",
|
|
183
|
+
"mn",
|
|
184
|
+
"mo",
|
|
185
|
+
"mover",
|
|
186
|
+
"mpadded",
|
|
187
|
+
"mphantom",
|
|
188
|
+
"mroot",
|
|
189
|
+
"mrow",
|
|
190
|
+
"ms",
|
|
191
|
+
"mscarries",
|
|
192
|
+
"mscarry",
|
|
193
|
+
"msgroup",
|
|
194
|
+
"msline",
|
|
195
|
+
"mspace",
|
|
196
|
+
"msqrt",
|
|
197
|
+
"msrow",
|
|
198
|
+
"mstack",
|
|
199
|
+
"mstyle",
|
|
200
|
+
"msub",
|
|
201
|
+
"msubsup",
|
|
202
|
+
"msup",
|
|
203
|
+
"mtable",
|
|
204
|
+
"mtd",
|
|
205
|
+
"mtext",
|
|
206
|
+
"mtr",
|
|
207
|
+
"munder",
|
|
208
|
+
"munderover",
|
|
209
|
+
"semantics",
|
|
210
|
+
"annotation",
|
|
211
|
+
"annotation-xml"
|
|
212
|
+
];
|
|
213
|
+
export {
|
|
214
|
+
ALL_TAGS
|
|
215
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tsx.d.ts","sourceRoot":"","sources":["../../src/processing/tsx.ts"],"names":[],"mappings":"AAwHA,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAqBrE"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { parseSync } from "oxc-parser";
|
|
2
|
+
import { applyEdits, forEachChild } from "./oxc.js";
|
|
3
|
+
function getTagName(nameNode, src) {
|
|
4
|
+
if (nameNode.type === "JSXIdentifier") return nameNode.name;
|
|
5
|
+
if (nameNode.type === "JSXNamespacedName") return `${nameNode.namespace.name}_${nameNode.name.name}`;
|
|
6
|
+
return src.slice(nameNode.start, nameNode.end);
|
|
7
|
+
}
|
|
8
|
+
function processJSXText(raw) {
|
|
9
|
+
const trimmed = raw.split("\n").map((l) => l.trim()).filter(Boolean).join(" ");
|
|
10
|
+
return trimmed || null;
|
|
11
|
+
}
|
|
12
|
+
function convertJSXNode(node, src) {
|
|
13
|
+
if (node.type === "JSXFragment") {
|
|
14
|
+
const kids = convertJSXChildren(node.children, src);
|
|
15
|
+
if (kids.length === 0) return "null";
|
|
16
|
+
if (kids.length === 1) return kids[0];
|
|
17
|
+
return `[${kids.join(", ")}]`;
|
|
18
|
+
}
|
|
19
|
+
return convertJSXElement(node, src);
|
|
20
|
+
}
|
|
21
|
+
function convertExpr(node, src) {
|
|
22
|
+
if (node.type === "JSXElement" || node.type === "JSXFragment") return convertJSXNode(node, src);
|
|
23
|
+
const edits = [];
|
|
24
|
+
function collect(n) {
|
|
25
|
+
if (n.type === "JSXElement" || n.type === "JSXFragment") {
|
|
26
|
+
edits.push({ start: n.start, end: n.end, replacement: convertJSXNode(n, src) });
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
forEachChild(n, collect);
|
|
30
|
+
}
|
|
31
|
+
collect(node);
|
|
32
|
+
if (edits.length === 0) return src.slice(node.start, node.end);
|
|
33
|
+
let out = "", cursor = node.start;
|
|
34
|
+
for (const e of edits.sort((a, b) => a.start - b.start)) {
|
|
35
|
+
out += src.slice(cursor, e.start) + e.replacement;
|
|
36
|
+
cursor = e.end;
|
|
37
|
+
}
|
|
38
|
+
return out + src.slice(cursor, node.end);
|
|
39
|
+
}
|
|
40
|
+
function convertJSXElement(node, src) {
|
|
41
|
+
const opening = node.openingElement;
|
|
42
|
+
const tagName = getTagName(opening.name, src);
|
|
43
|
+
const isComponent = /^[A-Z]/.test(tagName) || tagName.includes(".");
|
|
44
|
+
const args = [];
|
|
45
|
+
if (opening.attributes.length > 0) {
|
|
46
|
+
const parts = [];
|
|
47
|
+
for (const attr of opening.attributes) {
|
|
48
|
+
if (attr.type === "JSXSpreadAttribute") {
|
|
49
|
+
parts.push(`...${convertExpr(attr.argument, src)}`);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const rawName = src.slice(attr.name.start, attr.name.end);
|
|
53
|
+
const key = /[-:]/.test(rawName) ? `"${rawName}"` : rawName;
|
|
54
|
+
if (attr.value === null) {
|
|
55
|
+
parts.push(`${key}: true`);
|
|
56
|
+
} else if (attr.value.type === "StringLiteral" || attr.value.type === "Literal") {
|
|
57
|
+
parts.push(`${key}: ${src.slice(attr.value.start, attr.value.end)}`);
|
|
58
|
+
} else if (attr.value.type === "JSXExpressionContainer") {
|
|
59
|
+
const expr = attr.value.expression;
|
|
60
|
+
if (expr.type !== "JSXEmptyExpression") parts.push(`${key}: ${convertExpr(expr, src)}`);
|
|
61
|
+
} else if (attr.value.type === "JSXElement" || attr.value.type === "JSXFragment") {
|
|
62
|
+
parts.push(`${key}: ${convertJSXNode(attr.value, src)}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (parts.length > 0) args.push(`{ ${parts.join(", ")} }`);
|
|
66
|
+
}
|
|
67
|
+
if (!opening.selfClosing) {
|
|
68
|
+
const kids = convertJSXChildren(node.children, src);
|
|
69
|
+
if (kids.length > 0) {
|
|
70
|
+
if (isComponent && args.length === 0) args.push("{}");
|
|
71
|
+
args.push(`[${kids.join(", ")}]`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return `${tagName}(${args.join(", ")})`;
|
|
75
|
+
}
|
|
76
|
+
function convertJSXChildren(children, src) {
|
|
77
|
+
const result = [];
|
|
78
|
+
for (const child of children) {
|
|
79
|
+
switch (child.type) {
|
|
80
|
+
case "JSXText": {
|
|
81
|
+
const text = processJSXText(child.value);
|
|
82
|
+
if (text !== null) result.push(JSON.stringify(text));
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
case "JSXExpressionContainer": {
|
|
86
|
+
const expr = child.expression;
|
|
87
|
+
if (expr.type !== "JSXEmptyExpression") result.push(convertExpr(expr, src));
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case "JSXSpreadChild":
|
|
91
|
+
result.push(`...(${convertExpr(child.expression, src)})`);
|
|
92
|
+
break;
|
|
93
|
+
case "JSXElement":
|
|
94
|
+
result.push(convertJSXElement(child, src));
|
|
95
|
+
break;
|
|
96
|
+
case "JSXFragment": {
|
|
97
|
+
const kids = convertJSXChildren(child.children, src);
|
|
98
|
+
if (kids.length === 0) break;
|
|
99
|
+
if (kids.length === 1) {
|
|
100
|
+
result.push(kids[0]);
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
result.push(`[${kids.join(", ")}]`);
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
function transformJSX(source, filePath) {
|
|
111
|
+
if (!source.includes("<")) return source;
|
|
112
|
+
let ast;
|
|
113
|
+
try {
|
|
114
|
+
ast = parseSync(filePath, source, { sourceType: "module" });
|
|
115
|
+
} catch {
|
|
116
|
+
return source;
|
|
117
|
+
}
|
|
118
|
+
const edits = [];
|
|
119
|
+
function collect(node) {
|
|
120
|
+
if (node.type === "JSXElement" || node.type === "JSXFragment") {
|
|
121
|
+
edits.push({ start: node.start, end: node.end, replacement: convertJSXNode(node, source) });
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
forEachChild(node, collect);
|
|
125
|
+
}
|
|
126
|
+
collect(ast.program);
|
|
127
|
+
return edits.length === 0 ? source : applyEdits(source, edits);
|
|
128
|
+
}
|
|
129
|
+
export {
|
|
130
|
+
transformJSX
|
|
131
|
+
};
|
package/dist/run.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":""}
|
package/dist/run.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createServer, ServerResponse } from "node:http";
|
|
3
|
+
import { spawn, ChildProcess } from "node:child_process";
|
|
4
|
+
import { join, dirname } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { watch } from "node:fs";
|
|
7
|
+
import { logger } from "./logger.js";
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = dirname(__filename);
|
|
10
|
+
const PAGES_DIR = join(process.cwd(), "pages");
|
|
11
|
+
const BUILD_DEV_ENTRY = join(__dirname, "build", "dev.js");
|
|
12
|
+
const BUILD_PROD_ENTRY = join(__dirname, "build", "prod.js");
|
|
13
|
+
const SERVER_DEV_ENTRY = join(__dirname, "server", "dev.js");
|
|
14
|
+
const SERVER_PROD_ENTRY = join(__dirname, "server", "prod.js");
|
|
15
|
+
const MODE = process.argv.includes("-prod") ? "prod" : "dev";
|
|
16
|
+
const IS_DEV = MODE === "dev";
|
|
17
|
+
let serverProcess = null;
|
|
18
|
+
let rebuildTimeout = null;
|
|
19
|
+
let cycling = false;
|
|
20
|
+
let firstBuildDone = false;
|
|
21
|
+
const sseClients = /* @__PURE__ */ new Set();
|
|
22
|
+
function sendReloadToClients() {
|
|
23
|
+
for (const client of sseClients) {
|
|
24
|
+
client.write("data: reload\n\n");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function startHotReloadServer() {
|
|
28
|
+
const hotReloadPort = 4e3;
|
|
29
|
+
const sseServer = createServer((req, res) => {
|
|
30
|
+
if (req.url !== "/__reload") {
|
|
31
|
+
res.writeHead(404);
|
|
32
|
+
res.end();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
res.writeHead(200, {
|
|
36
|
+
"Content-Type": "text/event-stream",
|
|
37
|
+
"Cache-Control": "no-cache",
|
|
38
|
+
Connection: "keep-alive",
|
|
39
|
+
"Access-Control-Allow-Origin": "http://192.168.100.53:3000"
|
|
40
|
+
});
|
|
41
|
+
res.write("data: connected\n\n");
|
|
42
|
+
sseClients.add(res);
|
|
43
|
+
req.on("close", () => sseClients.delete(res));
|
|
44
|
+
return;
|
|
45
|
+
});
|
|
46
|
+
sseServer.listen(hotReloadPort, "0.0.0.0");
|
|
47
|
+
}
|
|
48
|
+
function spawnTs(entry, extraEnv = {}) {
|
|
49
|
+
return spawn("node", ["--import", "ts-arc/register", entry], {
|
|
50
|
+
stdio: ["inherit", "inherit", "inherit", "ipc"],
|
|
51
|
+
env: {
|
|
52
|
+
...process.env,
|
|
53
|
+
ELEGANCE_DEV_MODE: MODE,
|
|
54
|
+
ARGS: JSON.stringify(process.argv.slice(2)),
|
|
55
|
+
...extraEnv
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function spawnBuild() {
|
|
60
|
+
if (IS_DEV) {
|
|
61
|
+
return spawnTs(BUILD_DEV_ENTRY, {
|
|
62
|
+
ELEGANCE_BUILD_MODE: firstBuildDone ? "incremental" : "full"
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return spawnTs(BUILD_PROD_ENTRY);
|
|
66
|
+
}
|
|
67
|
+
function spawnServer() {
|
|
68
|
+
return spawnTs(IS_DEV ? SERVER_DEV_ENTRY : SERVER_PROD_ENTRY);
|
|
69
|
+
}
|
|
70
|
+
function runBuild() {
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
const build = spawnBuild();
|
|
73
|
+
build.once("exit", (code) => {
|
|
74
|
+
if (code === 0 || code === null) resolve();
|
|
75
|
+
else reject(new Error(`Build process exited with code ${code}`));
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async function startServer() {
|
|
80
|
+
logger.info("Starting Server..");
|
|
81
|
+
if (serverProcess && !serverProcess.killed) {
|
|
82
|
+
serverProcess.kill("SIGTERM");
|
|
83
|
+
await new Promise((resolve) => serverProcess.once("exit", resolve));
|
|
84
|
+
serverProcess = null;
|
|
85
|
+
}
|
|
86
|
+
serverProcess = spawnServer();
|
|
87
|
+
serverProcess.on("exit", () => {
|
|
88
|
+
serverProcess = null;
|
|
89
|
+
});
|
|
90
|
+
return new Promise((resolve) => {
|
|
91
|
+
const cleanup = () => {
|
|
92
|
+
serverProcess?.off("message", onMessage);
|
|
93
|
+
serverProcess?.off("exit", onExit);
|
|
94
|
+
};
|
|
95
|
+
const onMessage = (msg) => {
|
|
96
|
+
if (msg?.type === "ready") {
|
|
97
|
+
cleanup();
|
|
98
|
+
resolve();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const onExit = () => {
|
|
102
|
+
cleanup();
|
|
103
|
+
resolve();
|
|
104
|
+
};
|
|
105
|
+
serverProcess?.on("message", onMessage);
|
|
106
|
+
serverProcess?.once("exit", onExit);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
async function cycle() {
|
|
110
|
+
process.stdout.write("\x1Bc");
|
|
111
|
+
if (serverProcess && !serverProcess.killed) {
|
|
112
|
+
serverProcess.kill("SIGTERM");
|
|
113
|
+
await new Promise((resolve) => serverProcess.once("exit", resolve));
|
|
114
|
+
serverProcess = null;
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
await runBuild();
|
|
118
|
+
await startServer();
|
|
119
|
+
} catch {
|
|
120
|
+
}
|
|
121
|
+
sendReloadToClients();
|
|
122
|
+
}
|
|
123
|
+
async function scheduleRebuild() {
|
|
124
|
+
if (rebuildTimeout) clearTimeout(rebuildTimeout);
|
|
125
|
+
rebuildTimeout = setTimeout(async () => {
|
|
126
|
+
if (cycling) return;
|
|
127
|
+
cycling = true;
|
|
128
|
+
logger.info("Rebuilding..");
|
|
129
|
+
try {
|
|
130
|
+
await cycle();
|
|
131
|
+
firstBuildDone = true;
|
|
132
|
+
} catch (err) {
|
|
133
|
+
} finally {
|
|
134
|
+
cycling = false;
|
|
135
|
+
}
|
|
136
|
+
}, 300);
|
|
137
|
+
}
|
|
138
|
+
(async () => {
|
|
139
|
+
if (IS_DEV) {
|
|
140
|
+
startHotReloadServer();
|
|
141
|
+
watch(PAGES_DIR, { recursive: true }, (_, filename) => {
|
|
142
|
+
if (filename) scheduleRebuild();
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
await cycle();
|
|
146
|
+
firstBuildDone = true;
|
|
147
|
+
})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/server/dev.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prod.d.ts","sourceRoot":"","sources":["../../src/server/prod.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import cluster from "node:cluster";
|
|
2
|
+
import { cpus } from "node:os";
|
|
3
|
+
import { serve } from "./server.js";
|
|
4
|
+
import { c, logger } from "../logger.js";
|
|
5
|
+
import { isRichError, printError } from "../error.js";
|
|
6
|
+
const PROCESS_ARGS = JSON.parse(process.env.ARGS ?? "[]");
|
|
7
|
+
(async () => {
|
|
8
|
+
if (!cluster.isPrimary) {
|
|
9
|
+
await serve().catch((err) => {
|
|
10
|
+
if (isRichError(err)) {
|
|
11
|
+
printError(err);
|
|
12
|
+
} else {
|
|
13
|
+
console.error(err);
|
|
14
|
+
}
|
|
15
|
+
process.exit(1);
|
|
16
|
+
});
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const workersArg = PROCESS_ARGS.find((a) => a.startsWith("-w="));
|
|
20
|
+
const workerCount = workersArg ? parseInt(workersArg.split("=")[1]) : cpus().length;
|
|
21
|
+
logger.info(`Primary ${process.pid}, forking ${c.bold}${workerCount}${c.reset} workers`);
|
|
22
|
+
let readyCount = 0;
|
|
23
|
+
for (let i = 0; i < workerCount; i++) {
|
|
24
|
+
const worker = cluster.fork();
|
|
25
|
+
worker.once("message", (msg) => {
|
|
26
|
+
if (msg?.type !== "ready") return;
|
|
27
|
+
readyCount++;
|
|
28
|
+
if (readyCount === 1 && process.send) process.send({ type: "ready" });
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
cluster.on("exit", (worker, code, signal) => {
|
|
32
|
+
logger.error(`Worker ${worker.process.pid} exited (${signal ?? code}) unexpectedly.`);
|
|
33
|
+
if (readyCount === 0) {
|
|
34
|
+
for (const worker2 of Object.values(cluster.workers)) {
|
|
35
|
+
worker2?.destroy();
|
|
36
|
+
}
|
|
37
|
+
logger.error("No workers were ready when this worker errored; exiting..");
|
|
38
|
+
process.exit(0);
|
|
39
|
+
}
|
|
40
|
+
cluster.fork();
|
|
41
|
+
});
|
|
42
|
+
})();
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
type CSPSourceValue = "'self'" | "'none'" | "'unsafe-inline'" | "'unsafe-eval'" | "'strict-dynamic'" | "'unsafe-hashes'" | "'report-sample'" | "'unsafe-allow-redirects'" | `'nonce-${string}'` | `'sha256-${string}'` | `'sha384-${string}'` | `'sha512-${string}'` | string;
|
|
2
|
+
type CSPOptions = {
|
|
3
|
+
defaultSrc?: CSPSourceValue[];
|
|
4
|
+
childSrc?: CSPSourceValue[];
|
|
5
|
+
connectSrc?: CSPSourceValue[];
|
|
6
|
+
fontSrc?: CSPSourceValue[];
|
|
7
|
+
frameSrc?: CSPSourceValue[];
|
|
8
|
+
imgSrc?: CSPSourceValue[];
|
|
9
|
+
manifestSrc?: CSPSourceValue[];
|
|
10
|
+
mediaSrc?: CSPSourceValue[];
|
|
11
|
+
objectSrc?: CSPSourceValue[];
|
|
12
|
+
prefetchSrc?: CSPSourceValue[];
|
|
13
|
+
scriptSrc?: CSPSourceValue[];
|
|
14
|
+
scriptSrcElem?: CSPSourceValue[];
|
|
15
|
+
scriptSrcAttr?: CSPSourceValue[];
|
|
16
|
+
styleSrc?: CSPSourceValue[];
|
|
17
|
+
styleSrcElem?: CSPSourceValue[];
|
|
18
|
+
styleSrcAttr?: CSPSourceValue[];
|
|
19
|
+
workerSrc?: CSPSourceValue[];
|
|
20
|
+
baseUri?: CSPSourceValue[];
|
|
21
|
+
sandbox?: string[];
|
|
22
|
+
formAction?: CSPSourceValue[];
|
|
23
|
+
frameAncestors?: CSPSourceValue[];
|
|
24
|
+
navigateTo?: CSPSourceValue[];
|
|
25
|
+
reportUri?: string[];
|
|
26
|
+
reportTo?: string;
|
|
27
|
+
requireTrustedTypesFor?: ("'script'" | string)[];
|
|
28
|
+
trustedTypes?: (string | "'none'" | "'allow-duplicates'" | "'*'")[];
|
|
29
|
+
upgradeInsecureRequests?: boolean;
|
|
30
|
+
blockAllMixedContent?: boolean;
|
|
31
|
+
};
|
|
32
|
+
type StrictTransportSecurityOptions = {
|
|
33
|
+
maxAge: number;
|
|
34
|
+
includeSubDomains?: boolean;
|
|
35
|
+
preload?: boolean;
|
|
36
|
+
};
|
|
37
|
+
type XFrameOptionsValue = 'DENY' | 'SAMEORIGIN' | `ALLOW-FROM ${string}`;
|
|
38
|
+
type ReferrerPolicyValue = 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url' | '';
|
|
39
|
+
type PermissionsPolicyOptions = Record<string, string[]>;
|
|
40
|
+
type CrossOriginEmbedderPolicyValue = 'unsafe-none' | 'require-corp' | 'credentialless';
|
|
41
|
+
type CrossOriginOpenerPolicyValue = 'unsafe-none' | 'same-origin-allow-popups' | 'same-origin';
|
|
42
|
+
type CrossOriginResourcePolicyValue = 'same-site' | 'same-origin' | 'cross-origin';
|
|
43
|
+
type XDNSPrefetchControlValue = 'on' | 'off';
|
|
44
|
+
type XXSSProtectionOptions = {
|
|
45
|
+
enable: boolean;
|
|
46
|
+
mode?: 'block';
|
|
47
|
+
report?: string;
|
|
48
|
+
};
|
|
49
|
+
export type SecurityHeadersOptions = {
|
|
50
|
+
contentSecurityPolicy?: CSPOptions;
|
|
51
|
+
strictTransportSecurity?: StrictTransportSecurityOptions;
|
|
52
|
+
xFrameOptions?: XFrameOptionsValue;
|
|
53
|
+
xContentTypeOptions?: boolean;
|
|
54
|
+
referrerPolicy?: ReferrerPolicyValue;
|
|
55
|
+
permissionsPolicy?: PermissionsPolicyOptions;
|
|
56
|
+
crossOriginEmbedderPolicy?: CrossOriginEmbedderPolicyValue;
|
|
57
|
+
crossOriginOpenerPolicy?: CrossOriginOpenerPolicyValue;
|
|
58
|
+
crossOriginResourcePolicy?: CrossOriginResourcePolicyValue;
|
|
59
|
+
xDnsPrefetchControl?: XDNSPrefetchControlValue;
|
|
60
|
+
xXssProtection?: XXSSProtectionOptions;
|
|
61
|
+
};
|
|
62
|
+
export declare function createSecurityHeaders(opts: SecurityHeadersOptions): Record<string, string>;
|
|
63
|
+
export {};
|
|
64
|
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