tw-framework 2.0.3 → 2.0.5
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/CHANGELOG.md +108 -0
- package/dist/testing.cjs +560 -189
- package/dist/tw-server.mjs +529 -157
- package/dist/tw.mjs +1017 -478
- package/package.json +1 -1
package/dist/testing.cjs
CHANGED
|
@@ -151715,9 +151715,9 @@ ${lanes.join("\n")}
|
|
|
151715
151715
|
/*ignoreCase*/
|
|
151716
151716
|
false
|
|
151717
151717
|
)) {
|
|
151718
|
-
const
|
|
151719
|
-
if (
|
|
151720
|
-
const name = removeSuffix(removePrefix(
|
|
151718
|
+
const basename4 = getBaseFileName(a.fileName);
|
|
151719
|
+
if (basename4 === "lib.d.ts" || basename4 === "lib.es6.d.ts") return 0;
|
|
151720
|
+
const name = removeSuffix(removePrefix(basename4, "lib."), ".d.ts");
|
|
151721
151721
|
const index = libs.indexOf(name);
|
|
151722
151722
|
if (index !== -1) return index + 1;
|
|
151723
151723
|
}
|
|
@@ -215313,8 +215313,8 @@ ${options.prefix}` : "\n" : options.prefix
|
|
|
215313
215313
|
}
|
|
215314
215314
|
};
|
|
215315
215315
|
for (const file of files) {
|
|
215316
|
-
const
|
|
215317
|
-
if (
|
|
215316
|
+
const basename4 = getBaseFileName(file);
|
|
215317
|
+
if (basename4 === "package.json" || basename4 === "bower.json") {
|
|
215318
215318
|
createProjectWatcher(
|
|
215319
215319
|
file,
|
|
215320
215320
|
"FileWatcher"
|
|
@@ -218982,8 +218982,8 @@ All files are: ${JSON.stringify(names)}`,
|
|
|
218982
218982
|
var _a;
|
|
218983
218983
|
const fileOrDirectoryPath = removeIgnoredPath(this.toPath(fileOrDirectory));
|
|
218984
218984
|
if (!fileOrDirectoryPath) return;
|
|
218985
|
-
const
|
|
218986
|
-
if (((_a = result.affectedModuleSpecifierCacheProjects) == null ? void 0 : _a.size) && (
|
|
218985
|
+
const basename4 = getBaseFileName(fileOrDirectoryPath);
|
|
218986
|
+
if (((_a = result.affectedModuleSpecifierCacheProjects) == null ? void 0 : _a.size) && (basename4 === "package.json" || basename4 === "node_modules")) {
|
|
218987
218987
|
result.affectedModuleSpecifierCacheProjects.forEach((project) => {
|
|
218988
218988
|
var _a2;
|
|
218989
218989
|
(_a2 = project.getModuleSpecifierCache()) == null ? void 0 : _a2.clear();
|
|
@@ -226947,7 +226947,51 @@ function parseStatements(cursor, errors, opts) {
|
|
|
226947
226947
|
"cols",
|
|
226948
226948
|
"rows",
|
|
226949
226949
|
"wrap",
|
|
226950
|
-
"datetime"
|
|
226950
|
+
"datetime",
|
|
226951
|
+
// SVG attributes. `path d "M4 7h16"` was read as text "path" plus a
|
|
226952
|
+
// <d> element, because `d` was not a known attribute name -- so an
|
|
226953
|
+
// inline icon could not be written at all.
|
|
226954
|
+
"d",
|
|
226955
|
+
"cx",
|
|
226956
|
+
"cy",
|
|
226957
|
+
"r",
|
|
226958
|
+
"rx",
|
|
226959
|
+
"ry",
|
|
226960
|
+
"x",
|
|
226961
|
+
"y",
|
|
226962
|
+
"x1",
|
|
226963
|
+
"y1",
|
|
226964
|
+
"x2",
|
|
226965
|
+
"y2",
|
|
226966
|
+
"points",
|
|
226967
|
+
"viewBox",
|
|
226968
|
+
"fill",
|
|
226969
|
+
"stroke",
|
|
226970
|
+
"stroke-width",
|
|
226971
|
+
"stroke-linecap",
|
|
226972
|
+
"stroke-linejoin",
|
|
226973
|
+
"stroke-dasharray",
|
|
226974
|
+
"stroke-dashoffset",
|
|
226975
|
+
"fill-rule",
|
|
226976
|
+
"clip-rule",
|
|
226977
|
+
"clip-path",
|
|
226978
|
+
"transform",
|
|
226979
|
+
"opacity",
|
|
226980
|
+
"fill-opacity",
|
|
226981
|
+
"stroke-opacity",
|
|
226982
|
+
"stop-color",
|
|
226983
|
+
"offset",
|
|
226984
|
+
"gradientUnits",
|
|
226985
|
+
"gradientTransform",
|
|
226986
|
+
"preserveAspectRatio",
|
|
226987
|
+
"text-anchor",
|
|
226988
|
+
"dominant-baseline",
|
|
226989
|
+
"font-size",
|
|
226990
|
+
"font-family",
|
|
226991
|
+
"marker-end",
|
|
226992
|
+
"marker-start",
|
|
226993
|
+
"mask",
|
|
226994
|
+
"xmlns"
|
|
226951
226995
|
]);
|
|
226952
226996
|
const isSelector = nextTok && (nextTok.type === "DOT" || nextTok.type === "HASH" || nextTok.type === "LBRACE" || nextTok.type === "STRING" || // `width 800` — a bare IDENT followed by a NUMBER is a prop/value
|
|
226953
226997
|
// pair (builtin component props accept numbers), not text content.
|
|
@@ -227514,6 +227558,15 @@ function parseElement(cursor, errors, state, parseBody) {
|
|
|
227514
227558
|
const tagToken = cursor.advance();
|
|
227515
227559
|
if (!tagToken) return null;
|
|
227516
227560
|
const tag2 = tagToken.value;
|
|
227561
|
+
if (tag2 && /^[A-Za-z][A-Za-z0-9-]*$/.test(tag2)) {
|
|
227562
|
+
errors.add(new CompilerError(
|
|
227563
|
+
"raw HTML is not supported in .tw -- write it in TW syntax: " + tag2 + ' { ... }. For an inline icon use svg/path/circle with attributes on the tag line; for a script body use script type "..." { ... }; for markup that comes from data use {@html expr}',
|
|
227564
|
+
tagToken.pos.line,
|
|
227565
|
+
tagToken.pos.col,
|
|
227566
|
+
"TW123",
|
|
227567
|
+
"error"
|
|
227568
|
+
));
|
|
227569
|
+
}
|
|
227517
227570
|
const controlFlowTags = {
|
|
227518
227571
|
"if": "if",
|
|
227519
227572
|
"for": "for",
|
|
@@ -236171,7 +236224,7 @@ var init_types4 = __esm({
|
|
|
236171
236224
|
var TW_VERSION, TW_GENERATOR_META;
|
|
236172
236225
|
var init_version = __esm({
|
|
236173
236226
|
"../../packages/compiler/tw/codegen/version.ts"() {
|
|
236174
|
-
TW_VERSION = "2.0.
|
|
236227
|
+
TW_VERSION = "2.0.5";
|
|
236175
236228
|
TW_GENERATOR_META = `<meta name="generator" content="TW Framework ${TW_VERSION}">`;
|
|
236176
236229
|
}
|
|
236177
236230
|
});
|
|
@@ -237770,6 +237823,39 @@ function validatePlainCss(src, filePath) {
|
|
|
237770
237823
|
checkDecl();
|
|
237771
237824
|
return src;
|
|
237772
237825
|
}
|
|
237826
|
+
function collapseWhitespace(text) {
|
|
237827
|
+
let out = "";
|
|
237828
|
+
let quote = null;
|
|
237829
|
+
let pendingSpace = false;
|
|
237830
|
+
for (let i = 0; i < text.length; i++) {
|
|
237831
|
+
const ch = text[i];
|
|
237832
|
+
if (quote) {
|
|
237833
|
+
out += ch;
|
|
237834
|
+
if (ch === "\\" && i + 1 < text.length) {
|
|
237835
|
+
out += text[i + 1];
|
|
237836
|
+
i++;
|
|
237837
|
+
continue;
|
|
237838
|
+
}
|
|
237839
|
+
if (ch === quote) quote = null;
|
|
237840
|
+
continue;
|
|
237841
|
+
}
|
|
237842
|
+
if (ch === '"' || ch === "'") {
|
|
237843
|
+
if (pendingSpace && out) out += " ";
|
|
237844
|
+
pendingSpace = false;
|
|
237845
|
+
quote = ch;
|
|
237846
|
+
out += ch;
|
|
237847
|
+
continue;
|
|
237848
|
+
}
|
|
237849
|
+
if (/\s/.test(ch)) {
|
|
237850
|
+
pendingSpace = true;
|
|
237851
|
+
continue;
|
|
237852
|
+
}
|
|
237853
|
+
if (pendingSpace && out) out += " ";
|
|
237854
|
+
pendingSpace = false;
|
|
237855
|
+
out += ch;
|
|
237856
|
+
}
|
|
237857
|
+
return out;
|
|
237858
|
+
}
|
|
237773
237859
|
function compileDecl(decl) {
|
|
237774
237860
|
const trimmed = decl.trim();
|
|
237775
237861
|
if (!trimmed) return "";
|
|
@@ -237777,10 +237863,10 @@ function compileDecl(decl) {
|
|
|
237777
237863
|
if (cssForm) return trimmed.replace(/^([-\w]+)\s*:\s*/, "$1: ");
|
|
237778
237864
|
const spaceIdx = trimmed.search(/[\s]/);
|
|
237779
237865
|
if (spaceIdx === -1) {
|
|
237780
|
-
return
|
|
237866
|
+
return "";
|
|
237781
237867
|
}
|
|
237782
237868
|
const prop = trimmed.slice(0, spaceIdx);
|
|
237783
|
-
const value = trimmed.slice(spaceIdx).trim();
|
|
237869
|
+
const value = collapseWhitespace(trimmed.slice(spaceIdx).trim());
|
|
237784
237870
|
const full = TSS_SHORTHANDS2[prop] ?? prop;
|
|
237785
237871
|
return `${full}: ${value}`;
|
|
237786
237872
|
}
|
|
@@ -237938,26 +238024,47 @@ function __twCompileTSSInner(source) {
|
|
|
237938
238024
|
if (!changed) break;
|
|
237939
238025
|
}
|
|
237940
238026
|
}
|
|
237941
|
-
const
|
|
238027
|
+
const root = [];
|
|
237942
238028
|
const stack = [];
|
|
237943
|
-
const declsByLevel = [];
|
|
237944
238029
|
let buf = "";
|
|
237945
|
-
const
|
|
237946
|
-
|
|
237947
|
-
|
|
237948
|
-
for (let i2 = wrapStack.length - 1; i2 >= 0; i2--) {
|
|
237949
|
-
if (wrapStack[i2].startsWith("@")) rule = `${wrapStack[i2]} { ${rule} }`;
|
|
237950
|
-
}
|
|
237951
|
-
rules.push(rule);
|
|
237952
|
-
};
|
|
238030
|
+
const current2 = () => stack.length ? stack[stack.length - 1] : null;
|
|
238031
|
+
const statements = [];
|
|
238032
|
+
const isStatementAtRule = (t3) => /^@(import|charset|namespace|layer)\b/.test(t3);
|
|
237953
238033
|
const pushDecl = (text) => {
|
|
237954
|
-
const
|
|
237955
|
-
if (
|
|
238034
|
+
const raw = text.trim();
|
|
238035
|
+
if (!raw) return;
|
|
238036
|
+
if (isStatementAtRule(raw)) {
|
|
238037
|
+
statements.push(raw.endsWith(";") ? raw : raw + ";");
|
|
238038
|
+
return;
|
|
238039
|
+
}
|
|
238040
|
+
const d = compileDecl(raw);
|
|
238041
|
+
if (!d) return;
|
|
238042
|
+
const node = current2();
|
|
238043
|
+
if (node) node.decls.push(d);
|
|
238044
|
+
else root.push({ kind: "rule", selector: "*", decls: [d], children: [] });
|
|
237956
238045
|
};
|
|
237957
|
-
const isDeclLine = (l) => /^[
|
|
238046
|
+
const isDeclLine = (l) => /^(--[A-Za-z][\w-]*|-?[A-Za-z][\w-]*)(\s|:)/.test(l) && !/^[>+~]/.test(l);
|
|
237958
238047
|
let i = 0;
|
|
238048
|
+
let quote = null;
|
|
237959
238049
|
while (i < src.length) {
|
|
237960
238050
|
const ch = src[i];
|
|
238051
|
+
if (quote) {
|
|
238052
|
+
buf += ch;
|
|
238053
|
+
if (ch === "\\" && i + 1 < src.length) {
|
|
238054
|
+
buf += src[i + 1];
|
|
238055
|
+
i += 2;
|
|
238056
|
+
continue;
|
|
238057
|
+
}
|
|
238058
|
+
if (ch === quote) quote = null;
|
|
238059
|
+
i++;
|
|
238060
|
+
continue;
|
|
238061
|
+
}
|
|
238062
|
+
if (ch === '"' || ch === "'") {
|
|
238063
|
+
quote = ch;
|
|
238064
|
+
buf += ch;
|
|
238065
|
+
i++;
|
|
238066
|
+
continue;
|
|
238067
|
+
}
|
|
237961
238068
|
if (ch === "{") {
|
|
237962
238069
|
let sel = buf.trim();
|
|
237963
238070
|
buf = "";
|
|
@@ -237970,53 +238077,38 @@ function __twCompileTSSInner(source) {
|
|
|
237970
238077
|
const last = lines[lines.length - 1];
|
|
237971
238078
|
const prior = lines.slice(0, -1);
|
|
237972
238079
|
const priorComplete = !/[(,]\s*$/.test(prior[prior.length - 1] ?? "");
|
|
237973
|
-
if (priorComplete && prior.every(isDeclLine)
|
|
238080
|
+
if (priorComplete && prior.every(isDeclLine)) {
|
|
237974
238081
|
for (const p of prior) pushDecl(p);
|
|
237975
238082
|
sel = last;
|
|
237976
238083
|
}
|
|
237977
238084
|
}
|
|
237978
|
-
const parent =
|
|
237979
|
-
let full;
|
|
238085
|
+
const parent = current2();
|
|
237980
238086
|
if (sel.startsWith("@")) {
|
|
237981
|
-
|
|
237982
|
-
|
|
237983
|
-
|
|
238087
|
+
const node = { kind: "at", head: sel, decls: [], children: [] };
|
|
238088
|
+
(parent ? parent.children : root).push(node);
|
|
238089
|
+
stack.push(node);
|
|
237984
238090
|
} else {
|
|
237985
|
-
full = sel;
|
|
238091
|
+
const full = parent && parent.kind === "rule" ? combineSelector(parent.selector, sel) : sel;
|
|
238092
|
+
const node = { kind: "rule", selector: full, decls: [], children: [] };
|
|
238093
|
+
(parent ? parent.children : root).push(node);
|
|
238094
|
+
stack.push(node);
|
|
237986
238095
|
}
|
|
237987
|
-
stack.push(full);
|
|
237988
|
-
declsByLevel.push([]);
|
|
237989
238096
|
i++;
|
|
237990
238097
|
} else if (ch === "}") {
|
|
237991
238098
|
if (buf.trim()) {
|
|
237992
238099
|
const blines = buf.split(/\n+/).map((l) => l.trim()).filter(Boolean);
|
|
237993
|
-
|
|
238100
|
+
const valueContinues = blines.some((l) => /[(,]\s*$/.test(l));
|
|
238101
|
+
if (blines.length > 1 && !valueContinues) {
|
|
237994
238102
|
for (const l of blines) pushDecl(l);
|
|
237995
238103
|
} else {
|
|
237996
238104
|
pushDecl(buf);
|
|
237997
238105
|
}
|
|
237998
238106
|
}
|
|
237999
238107
|
buf = "";
|
|
238000
|
-
|
|
238001
|
-
const decls = declsByLevel.pop() ?? [];
|
|
238002
|
-
if (level) {
|
|
238003
|
-
if (level.startsWith("@") && decls.length > 0) {
|
|
238004
|
-
let realSel = null;
|
|
238005
|
-
for (let j = stack.length - 1; j >= 0; j--) {
|
|
238006
|
-
if (!stack[j].startsWith("@")) {
|
|
238007
|
-
realSel = stack[j];
|
|
238008
|
-
break;
|
|
238009
|
-
}
|
|
238010
|
-
}
|
|
238011
|
-
if (realSel) emit4(realSel, decls, [...stack, level]);
|
|
238012
|
-
else emit4(level, decls, stack);
|
|
238013
|
-
} else {
|
|
238014
|
-
emit4(level, decls, stack);
|
|
238015
|
-
}
|
|
238016
|
-
}
|
|
238108
|
+
stack.pop();
|
|
238017
238109
|
i++;
|
|
238018
238110
|
} else if (ch === ";") {
|
|
238019
|
-
pushDecl(buf);
|
|
238111
|
+
if (buf.trim()) pushDecl(buf);
|
|
238020
238112
|
buf = "";
|
|
238021
238113
|
i++;
|
|
238022
238114
|
} else {
|
|
@@ -238024,11 +238116,24 @@ function __twCompileTSSInner(source) {
|
|
|
238024
238116
|
i++;
|
|
238025
238117
|
}
|
|
238026
238118
|
}
|
|
238027
|
-
if (buf.trim())
|
|
238028
|
-
|
|
238029
|
-
if (
|
|
238030
|
-
|
|
238031
|
-
|
|
238119
|
+
if (buf.trim()) pushDecl(buf);
|
|
238120
|
+
const ser = (node, parentSel) => {
|
|
238121
|
+
if (node.kind === "rule") {
|
|
238122
|
+
const lines = [];
|
|
238123
|
+
if (node.decls.length) lines.push(node.selector + " { " + node.decls.join("; ") + " }");
|
|
238124
|
+
for (const c of node.children) lines.push(...ser(c, node.selector));
|
|
238125
|
+
return lines;
|
|
238126
|
+
}
|
|
238127
|
+
const inner = [];
|
|
238128
|
+
if (node.decls.length) {
|
|
238129
|
+
inner.push(parentSel ? parentSel + " { " + node.decls.join("; ") + " }" : node.decls.join("; "));
|
|
238130
|
+
}
|
|
238131
|
+
for (const c of node.children) inner.push(...ser(c, parentSel));
|
|
238132
|
+
return [node.head + " { " + inner.join(" ") + " }"];
|
|
238133
|
+
};
|
|
238134
|
+
const out = [...statements];
|
|
238135
|
+
for (const node of root) out.push(...ser(node, ""));
|
|
238136
|
+
return out.join("\n");
|
|
238032
238137
|
}
|
|
238033
238138
|
var TSS_SHORTHANDS2;
|
|
238034
238139
|
var init_tss = __esm({
|
|
@@ -238072,6 +238177,12 @@ var init_tss = __esm({
|
|
|
238072
238177
|
"br-t": "border-top-left-radius",
|
|
238073
238178
|
bxsh: "box-shadow",
|
|
238074
238179
|
bxz: "box-sizing",
|
|
238180
|
+
// Documented in docs/tss-syntax.md but never implemented, so `br-tl 4px`
|
|
238181
|
+
// emitted the literal property name `br-tl` and the corner stayed square.
|
|
238182
|
+
"br-tl": "border-top-left-radius",
|
|
238183
|
+
"br-tr": "border-top-right-radius",
|
|
238184
|
+
"br-bl": "border-bottom-left-radius",
|
|
238185
|
+
"br-br": "border-bottom-right-radius",
|
|
238075
238186
|
// `box` is the documented box-sizing shorthand (docs/tss-syntax.md).
|
|
238076
238187
|
box: "box-sizing",
|
|
238077
238188
|
// typography
|
|
@@ -238113,7 +238224,13 @@ var init_tss = __esm({
|
|
|
238113
238224
|
tr: "transition",
|
|
238114
238225
|
tf: "transform",
|
|
238115
238226
|
us: "user-select",
|
|
238116
|
-
pe: "pointer-events"
|
|
238227
|
+
pe: "pointer-events",
|
|
238228
|
+
// Also documented, also missing.
|
|
238229
|
+
fl: "float",
|
|
238230
|
+
cl: "clear",
|
|
238231
|
+
dir: "direction",
|
|
238232
|
+
ww: "word-wrap",
|
|
238233
|
+
va: "vertical-align"
|
|
238117
238234
|
};
|
|
238118
238235
|
}
|
|
238119
238236
|
});
|
|
@@ -239251,7 +239368,9 @@ function generateElement(el, ctx) {
|
|
|
239251
239368
|
if (el.children.length === 0 && el.selfClosing) {
|
|
239252
239369
|
return `<${tag2}${attrPrefix}></${tag2}>`;
|
|
239253
239370
|
}
|
|
239254
|
-
const
|
|
239371
|
+
const isRawText = tag2 === "script" || tag2 === "style";
|
|
239372
|
+
const childCtx = isRawText ? { ...ctx, rawText: true } : ctx;
|
|
239373
|
+
const childrenHTML = el.children.map((c) => generateNode(c, childCtx)).join("");
|
|
239255
239374
|
return `<${tag2}${attrPrefix}>${childrenHTML}</${tag2}>`;
|
|
239256
239375
|
}
|
|
239257
239376
|
function renderAttrs(el, ctx) {
|
|
@@ -239382,10 +239501,30 @@ function wrapInterpolations(rendered, raw) {
|
|
|
239382
239501
|
}
|
|
239383
239502
|
return out;
|
|
239384
239503
|
}
|
|
239504
|
+
function generateTrustedHtml(text, ctx) {
|
|
239505
|
+
const src = text.isInterpolated ? `{${text.value}}` : String(text.value ?? "");
|
|
239506
|
+
let out = "";
|
|
239507
|
+
let i = 0;
|
|
239508
|
+
const re = /\{@html\s+([^}]*)\}/g;
|
|
239509
|
+
let m;
|
|
239510
|
+
while (m = re.exec(src)) {
|
|
239511
|
+
out += escapeHTML(interpolate2(src.slice(i, m.index), ctx.stateVars));
|
|
239512
|
+
out += String(interpolate2(`{${m[1]}}`, ctx.stateVars));
|
|
239513
|
+
i = m.index + m[0].length;
|
|
239514
|
+
}
|
|
239515
|
+
out += escapeHTML(interpolate2(src.slice(i), ctx.stateVars));
|
|
239516
|
+
return out;
|
|
239517
|
+
}
|
|
239385
239518
|
function generateText(text, ctx) {
|
|
239386
239519
|
ctx_global_interactive = ctx.interactive === true;
|
|
239387
239520
|
ctx_global_inhead = ctx.inHead === true;
|
|
239388
239521
|
lastStateVars = ctx.stateVars;
|
|
239522
|
+
if (text.value && String(text.value).includes("@html")) return generateTrustedHtml(text, ctx);
|
|
239523
|
+
if (ctx.rawText) {
|
|
239524
|
+
if (text.isInterpolated) return String(interpolate2(`{${text.value}}`, ctx.stateVars));
|
|
239525
|
+
if (text.value && /\{[^}]+\}/.test(text.value)) return String(interpolate2(text.value, ctx.stateVars));
|
|
239526
|
+
return text.value ?? "";
|
|
239527
|
+
}
|
|
239389
239528
|
if (text.isInterpolated) {
|
|
239390
239529
|
if (ctx.interactive && ctx.inHead !== true) {
|
|
239391
239530
|
return `<span data-tw-i="${escapeHTML(text.value)}"${dataTwSFor(text.value)}>${escapeHTML(interpolate2(`{${text.value}}`, ctx.stateVars))}</span>`;
|
|
@@ -240688,7 +240827,7 @@ function minifyHTML2(html, options) {
|
|
|
240688
240827
|
result = removeComments(result);
|
|
240689
240828
|
}
|
|
240690
240829
|
if (opts.collapseWhitespace) {
|
|
240691
|
-
result =
|
|
240830
|
+
result = collapseWhitespace2(result);
|
|
240692
240831
|
}
|
|
240693
240832
|
if (opts.removeRedundantAttrs) {
|
|
240694
240833
|
result = removeRedundantAttrs(result);
|
|
@@ -240711,7 +240850,7 @@ function removeComments(html) {
|
|
|
240711
240850
|
if (html.indexOf("<!--") === -1) return html;
|
|
240712
240851
|
return html.replace(/<!--(?!\[if\s)[\s\S]*?-->/g, "");
|
|
240713
240852
|
}
|
|
240714
|
-
function
|
|
240853
|
+
function collapseWhitespace2(html) {
|
|
240715
240854
|
const result = [];
|
|
240716
240855
|
let pos = 0;
|
|
240717
240856
|
let inPreserved = false;
|
|
@@ -243339,6 +243478,15 @@ function generateWithLayout(layoutProgram, pageProgram, stateVars) {
|
|
|
243339
243478
|
function generateWithLayoutChain(layoutPrograms, pageProgram, stateVars) {
|
|
243340
243479
|
const seedCtx = (ctx2) => {
|
|
243341
243480
|
if (stateVars) ctx2.stateVars = { ...stateVars };
|
|
243481
|
+
for (const lp of layoutPrograms ?? []) {
|
|
243482
|
+
for (const dir of lp.directives || []) {
|
|
243483
|
+
if (dir.type === "StateDirective") {
|
|
243484
|
+
for (const decl of dir.declarations || []) {
|
|
243485
|
+
ctx2.stateVars[decl.name] = stateLiteralForRender(decl.value);
|
|
243486
|
+
}
|
|
243487
|
+
}
|
|
243488
|
+
}
|
|
243489
|
+
}
|
|
243342
243490
|
for (const dir of pageProgram.directives || []) {
|
|
243343
243491
|
if (dir.type === "StateDirective") {
|
|
243344
243492
|
for (const decl of dir.declarations || []) {
|
|
@@ -243961,7 +244109,7 @@ var init_codes = __esm({
|
|
|
243961
244109
|
TW105: { message: "Server blocks in layouts are not supported yet", severity: "error", category: "semantic" },
|
|
243962
244110
|
TW106: { message: "Request context (headers/cookies/query/params) is not available in a static server block", severity: "error", category: "semantic" },
|
|
243963
244111
|
TW107: { message: "getSession()/requireUser() are not available in a static page's server block", severity: "error", category: "semantic" },
|
|
243964
|
-
TW108: { message: "redirect()
|
|
244112
|
+
TW108: { message: "redirect() is not available in a static page's server block", severity: "error", category: "semantic" },
|
|
243965
244113
|
TW109: { message: "redirect() target must be a same-origin internal path", severity: "error", category: "semantic" },
|
|
243966
244114
|
TW110: { message: "A cached fetch must not set an Authorization, Proxy-Authorization or Cookie header", severity: "error", category: "semantic" },
|
|
243967
244115
|
TW111: { message: "A cached page's server block cannot read headers, cookies, getSession() or requireUser()", severity: "error", category: "semantic" },
|
|
@@ -243975,6 +244123,8 @@ var init_codes = __esm({
|
|
|
243975
244123
|
TW119: { message: "A deferred server block cannot be used on a cached page -- cache { } serves one HTML to every request", severity: "error", category: "semantic" },
|
|
243976
244124
|
TW121: { message: "The same name is declared by more than one state { } block (the earlier one wins)", severity: "warning", category: "semantic" },
|
|
243977
244125
|
TW122: { message: "More than one default slot in the same component -- a caller's default content has no defined destination", severity: "warning", category: "semantic" },
|
|
244126
|
+
TW123: { message: "Raw HTML is not supported in .tw -- write the element in TW syntax", severity: "error", category: "syntax" },
|
|
244127
|
+
TW125: { message: "An import's local name is also a server-block built-in, so the import would be silently overwritten", severity: "error", category: "semantic" },
|
|
243978
244128
|
// Codes thrown outside the rule engine. TW303 comes from the stylesheet
|
|
243979
244129
|
// parser (codegen/tss.ts); TW000 is the generic fallback used when an error
|
|
243980
244130
|
// carries no code of its own.
|
|
@@ -244175,8 +244325,17 @@ function checkPerformance(program, filePath, diags) {
|
|
|
244175
244325
|
]));
|
|
244176
244326
|
}
|
|
244177
244327
|
if (isElement(node) && node.tag.toLowerCase() === "img") {
|
|
244328
|
+
const attr = (n) => node.attrs.find((a) => a.name === n)?.value;
|
|
244178
244329
|
const hasLazy = node.attrs.some((a) => a.name === "loading" && a.value === "lazy");
|
|
244179
|
-
|
|
244330
|
+
const isEager = String(attr("loading") ?? "") === "eager" || String(attr("fetchpriority") ?? "") === "high";
|
|
244331
|
+
const px = (v) => {
|
|
244332
|
+
const n = parseFloat(String(v ?? ""));
|
|
244333
|
+
return Number.isFinite(n) ? n : null;
|
|
244334
|
+
};
|
|
244335
|
+
const w = px(attr("width"));
|
|
244336
|
+
const h3 = px(attr("height"));
|
|
244337
|
+
const isSmallIcon = w !== null && h3 !== null && w <= 32 && h3 <= 32;
|
|
244338
|
+
if (!hasLazy && !isEager && !isSmallIcon) {
|
|
244180
244339
|
diags.push(createDiagnostic("TW054", node.line, node.col, filePath, void 0, [
|
|
244181
244340
|
'Add loading="lazy" for below-fold images'
|
|
244182
244341
|
]));
|
|
@@ -244649,9 +244808,97 @@ var init_rules = __esm({
|
|
|
244649
244808
|
"noframes",
|
|
244650
244809
|
"area",
|
|
244651
244810
|
"map",
|
|
244652
|
-
"marquee"
|
|
244811
|
+
"marquee",
|
|
244812
|
+
// Inline text tags. `b` and `i` were missing, so breadcrumbs and emphasis
|
|
244813
|
+
// collected a TW003 per tag on markup that renders perfectly well.
|
|
244814
|
+
"b",
|
|
244815
|
+
"i",
|
|
244816
|
+
"em",
|
|
244817
|
+
"strong",
|
|
244818
|
+
"small",
|
|
244819
|
+
"u",
|
|
244820
|
+
"s",
|
|
244821
|
+
"ins",
|
|
244822
|
+
"del",
|
|
244823
|
+
"sub",
|
|
244824
|
+
"sup",
|
|
244825
|
+
"nobr",
|
|
244826
|
+
"big",
|
|
244827
|
+
"tt",
|
|
244828
|
+
// SVG children -- the same warning fired on inline icons.
|
|
244829
|
+
"circle",
|
|
244830
|
+
"path",
|
|
244831
|
+
"rect",
|
|
244832
|
+
"line",
|
|
244833
|
+
"polyline",
|
|
244834
|
+
"polygon",
|
|
244835
|
+
"g",
|
|
244836
|
+
"defs",
|
|
244837
|
+
"use",
|
|
244838
|
+
"text",
|
|
244839
|
+
"ellipse",
|
|
244840
|
+
"tspan",
|
|
244841
|
+
"clippath",
|
|
244842
|
+
"lineargradient",
|
|
244843
|
+
"radialgradient",
|
|
244844
|
+
"stop",
|
|
244845
|
+
"mask",
|
|
244846
|
+
"pattern",
|
|
244847
|
+
"symbol",
|
|
244848
|
+
"marker",
|
|
244849
|
+
"filter",
|
|
244850
|
+
"foreignobject"
|
|
244653
244851
|
]);
|
|
244654
244852
|
HTML_ATTRIBUTES2 = /* @__PURE__ */ new Set([
|
|
244853
|
+
// SVG attributes. This rule keeps its own copy of the list, and it was missing
|
|
244854
|
+
// every SVG name, so an inline icon raised a TW006 per attribute.
|
|
244855
|
+
"d",
|
|
244856
|
+
"cx",
|
|
244857
|
+
"cy",
|
|
244858
|
+
"r",
|
|
244859
|
+
"rx",
|
|
244860
|
+
"ry",
|
|
244861
|
+
"x",
|
|
244862
|
+
"y",
|
|
244863
|
+
"x1",
|
|
244864
|
+
"y1",
|
|
244865
|
+
"x2",
|
|
244866
|
+
"y2",
|
|
244867
|
+
"points",
|
|
244868
|
+
"viewBox",
|
|
244869
|
+
"fill",
|
|
244870
|
+
"stroke",
|
|
244871
|
+
"stroke-width",
|
|
244872
|
+
"stroke-linecap",
|
|
244873
|
+
"stroke-linejoin",
|
|
244874
|
+
"stroke-dasharray",
|
|
244875
|
+
"stroke-dashoffset",
|
|
244876
|
+
"stroke-opacity",
|
|
244877
|
+
"fill-opacity",
|
|
244878
|
+
"fill-rule",
|
|
244879
|
+
"clip-rule",
|
|
244880
|
+
"clip-path",
|
|
244881
|
+
"opacity",
|
|
244882
|
+
"transform",
|
|
244883
|
+
"preserveAspectRatio",
|
|
244884
|
+
"xmlns",
|
|
244885
|
+
"gradientUnits",
|
|
244886
|
+
"gradientTransform",
|
|
244887
|
+
"offset",
|
|
244888
|
+
"stop-color",
|
|
244889
|
+
"stop-opacity",
|
|
244890
|
+
"text-anchor",
|
|
244891
|
+
"dominant-baseline",
|
|
244892
|
+
"font-family",
|
|
244893
|
+
"font-size",
|
|
244894
|
+
"font-weight",
|
|
244895
|
+
"font-style",
|
|
244896
|
+
"letter-spacing",
|
|
244897
|
+
"marker-start",
|
|
244898
|
+
"marker-mid",
|
|
244899
|
+
"marker-end",
|
|
244900
|
+
"mask",
|
|
244901
|
+
"pathLength",
|
|
244655
244902
|
"accept",
|
|
244656
244903
|
"accept-charset",
|
|
244657
244904
|
"accesskey",
|
|
@@ -247855,17 +248102,32 @@ var node_import_exports = {};
|
|
|
247855
248102
|
__export(node_import_exports, {
|
|
247856
248103
|
twImportTs: () => twImportTs
|
|
247857
248104
|
});
|
|
247858
|
-
async function twImportTs(tsPath, bust) {
|
|
248105
|
+
async function twImportTs(tsPath, bust, opts) {
|
|
247859
248106
|
const q = bust ? "?v=" + bust : "";
|
|
248107
|
+
const override = opts?.source;
|
|
247860
248108
|
if (!globalThis.__TW_NODE) {
|
|
247861
|
-
return import(tsPath + q);
|
|
248109
|
+
if (override === void 0) return import(tsPath + q);
|
|
248110
|
+
const ext = (0, import_node_path14.extname)(tsPath) || ".ts";
|
|
248111
|
+
const unique = process.pid + "-" + (overrideSeq++).toString(36) + "-" + Math.random().toString(36).slice(2, 8);
|
|
248112
|
+
const tmpPath = (0, import_node_path14.join)((0, import_node_path14.dirname)(tsPath), "." + (0, import_node_path14.basename)(tsPath, ext) + ".tw-override-" + unique + ext);
|
|
248113
|
+
(0, import_node_fs8.writeFileSync)(tmpPath, override, "utf-8");
|
|
248114
|
+
try {
|
|
248115
|
+
return await import(tmpPath + q);
|
|
248116
|
+
} finally {
|
|
248117
|
+
try {
|
|
248118
|
+
(0, import_node_fs8.rmSync)(tmpPath, { force: true });
|
|
248119
|
+
} catch {
|
|
248120
|
+
}
|
|
248121
|
+
}
|
|
247862
248122
|
}
|
|
247863
248123
|
const esbuildMain = globalThis.__TW_ESBUILD_MODULE;
|
|
247864
248124
|
const esbuild = await (esbuildMain ? import(esbuildMain) : import("esbuild"));
|
|
247865
248125
|
const safe = tsPath.replace(/[^a-zA-Z0-9]/g, "_").slice(-120);
|
|
247866
248126
|
const cachePath = (0, import_node_path14.join)((0, import_node_os2.tmpdir)(), "tw-" + safe + (bust ? "-" + bust : "") + ".mjs");
|
|
247867
248127
|
await esbuild.build({
|
|
247868
|
-
|
|
248128
|
+
// stdin + resolveDir keeps relative imports resolving from the original
|
|
248129
|
+
// file's directory, and sourcefile keeps error locations on the real file.
|
|
248130
|
+
...override === void 0 ? { entryPoints: [tsPath] } : { stdin: { contents: override, resolveDir: (0, import_node_path14.dirname)(tsPath), sourcefile: tsPath, loader: (0, import_node_path14.extname)(tsPath) === ".js" ? "js" : "ts" } },
|
|
247869
248131
|
bundle: true,
|
|
247870
248132
|
format: "esm",
|
|
247871
248133
|
platform: "node",
|
|
@@ -247875,12 +248137,14 @@ async function twImportTs(tsPath, bust) {
|
|
|
247875
248137
|
});
|
|
247876
248138
|
return import((0, import_node_url2.pathToFileURL)(cachePath).href + q);
|
|
247877
248139
|
}
|
|
247878
|
-
var import_node_path14, import_node_os2, import_node_url2;
|
|
248140
|
+
var import_node_path14, import_node_os2, import_node_url2, import_node_fs8, overrideSeq;
|
|
247879
248141
|
var init_node_import = __esm({
|
|
247880
248142
|
"../../packages/shared/tw/node-import.ts"() {
|
|
247881
248143
|
import_node_path14 = require("node:path");
|
|
247882
248144
|
import_node_os2 = require("node:os");
|
|
247883
248145
|
import_node_url2 = require("node:url");
|
|
248146
|
+
import_node_fs8 = require("node:fs");
|
|
248147
|
+
overrideSeq = 0;
|
|
247884
248148
|
}
|
|
247885
248149
|
});
|
|
247886
248150
|
|
|
@@ -248141,41 +248405,45 @@ function withTimeout2(p, ms, label) {
|
|
|
248141
248405
|
});
|
|
248142
248406
|
});
|
|
248143
248407
|
}
|
|
248144
|
-
function
|
|
248145
|
-
const
|
|
248146
|
-
const s = stmt.replace(/^import\s+(type\s+)?/, "");
|
|
248408
|
+
function importBindings(stmt) {
|
|
248409
|
+
const out = [];
|
|
248410
|
+
const s = stmt.replace(/^import\s+(type\s+)?/, "").trim();
|
|
248147
248411
|
const fromIdx = s.lastIndexOf(" from ");
|
|
248148
|
-
if (fromIdx < 0) return
|
|
248412
|
+
if (fromIdx < 0) return out;
|
|
248149
248413
|
const clause = s.slice(0, fromIdx).trim();
|
|
248150
|
-
if (clause.startsWith("{")) {
|
|
248151
|
-
|
|
248414
|
+
if (!clause.startsWith("{") && !clause.startsWith("*")) {
|
|
248415
|
+
const first = clause.split(",")[0].trim();
|
|
248416
|
+
if (first && /^[A-Za-z_$]/.test(first)) out.push({ local: first, imported: "default", kind: "default" });
|
|
248417
|
+
}
|
|
248418
|
+
const ns = clause.match(/\*\s+as\s+([A-Za-z_$][\w$]*)/);
|
|
248419
|
+
if (ns) out.push({ local: ns[1], imported: "*", kind: "namespace" });
|
|
248420
|
+
const braces = clause.match(/\{([\s\S]*)\}/);
|
|
248421
|
+
if (braces) {
|
|
248422
|
+
for (const part of braces[1].split(",")) {
|
|
248152
248423
|
const t3 = part.trim();
|
|
248153
248424
|
if (!t3) continue;
|
|
248154
|
-
const
|
|
248155
|
-
|
|
248425
|
+
const parts = t3.split(/\s+as\s+/);
|
|
248426
|
+
const imported = parts[0].trim();
|
|
248427
|
+
const local = (parts[1] ?? parts[0]).trim();
|
|
248428
|
+
if (local) out.push({ local, imported, kind: "named" });
|
|
248156
248429
|
}
|
|
248157
|
-
} else if (clause.startsWith("*")) {
|
|
248158
|
-
const as = clause.split(/\s+as\s+/);
|
|
248159
|
-
if (as[1]) names.push(as[1].trim());
|
|
248160
|
-
} else {
|
|
248161
|
-
const first = clause.split(",")[0].trim();
|
|
248162
|
-
if (first && /^[A-Za-z_$]/.test(first)) names.push(first);
|
|
248163
248430
|
}
|
|
248164
|
-
return
|
|
248431
|
+
return out;
|
|
248165
248432
|
}
|
|
248166
248433
|
async function resolveServerImports(block, pageFile, opts = {}) {
|
|
248167
248434
|
if (!block.imports.length) return {};
|
|
248168
248435
|
const out = {};
|
|
248169
248436
|
const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
248170
|
-
const { dirname:
|
|
248437
|
+
const { dirname: dirname11, resolve: resolve4 } = await import("node:path");
|
|
248171
248438
|
const { statSync: statSync7 } = await import("node:fs");
|
|
248172
248439
|
for (const imp of block.imports) {
|
|
248173
248440
|
if (!imp.specifier) continue;
|
|
248174
248441
|
const spec = imp.specifier;
|
|
248442
|
+
if (spec === "@tw/server-only" || spec === "@tw/client-safe") continue;
|
|
248175
248443
|
let mod;
|
|
248176
248444
|
if (spec.startsWith("./") || spec.startsWith("../") || spec.startsWith("@./")) {
|
|
248177
248445
|
const rel = spec.startsWith("@./") ? spec.slice(2) : spec;
|
|
248178
|
-
const abs = resolve4(
|
|
248446
|
+
const abs = resolve4(dirname11(pageFile), rel);
|
|
248179
248447
|
let bust;
|
|
248180
248448
|
if (opts.dev) {
|
|
248181
248449
|
try {
|
|
@@ -248183,12 +248451,49 @@ async function resolveServerImports(block, pageFile, opts = {}) {
|
|
|
248183
248451
|
} catch {
|
|
248184
248452
|
}
|
|
248185
248453
|
}
|
|
248186
|
-
|
|
248454
|
+
let override;
|
|
248455
|
+
try {
|
|
248456
|
+
let realAbs = abs;
|
|
248457
|
+
if (!(0, import_node_fs9.existsSync)(realAbs)) {
|
|
248458
|
+
for (const ext of [".js", ".mjs", ".cjs", ".ts", ".mts", ".cts"]) {
|
|
248459
|
+
if ((0, import_node_fs9.existsSync)(realAbs + ext)) {
|
|
248460
|
+
realAbs = realAbs + ext;
|
|
248461
|
+
break;
|
|
248462
|
+
}
|
|
248463
|
+
}
|
|
248464
|
+
}
|
|
248465
|
+
const raw = (0, import_node_fs9.readFileSync)(realAbs, "utf-8");
|
|
248466
|
+
if (MARKER_IMPORT_RE.test(raw)) {
|
|
248467
|
+
MARKER_IMPORT_RE.lastIndex = 0;
|
|
248468
|
+
override = raw.replace(MARKER_IMPORT_RE, "");
|
|
248469
|
+
}
|
|
248470
|
+
} catch {
|
|
248471
|
+
}
|
|
248472
|
+
mod = override === void 0 ? await twImportTs2(abs, bust) : await twImportTs2(abs, bust, { source: override });
|
|
248187
248473
|
} else {
|
|
248188
248474
|
mod = await import(spec);
|
|
248189
248475
|
}
|
|
248190
|
-
const
|
|
248191
|
-
|
|
248476
|
+
for (const bind of importBindings(imp.source)) {
|
|
248477
|
+
if (bind.kind === "namespace") out[bind.local] = mod;
|
|
248478
|
+
else if (bind.kind === "default") out[bind.local] = mod?.default ?? mod?.[bind.imported];
|
|
248479
|
+
else out[bind.local] = mod?.[bind.imported] ?? mod?.default;
|
|
248480
|
+
}
|
|
248481
|
+
}
|
|
248482
|
+
return out;
|
|
248483
|
+
}
|
|
248484
|
+
function serverImportCollisions(source) {
|
|
248485
|
+
const out = [];
|
|
248486
|
+
const re = /^[ \t]*import\s+([\s\S]*?)\s+from\s+["']([^"']+)["'][ \t]*;?/gm;
|
|
248487
|
+
let m;
|
|
248488
|
+
while (m = re.exec(source)) {
|
|
248489
|
+
const stmt = m[0];
|
|
248490
|
+
const specifier = m[2];
|
|
248491
|
+
const line = source.slice(0, m.index).split("\n").length;
|
|
248492
|
+
for (const b of importBindings(stmt)) {
|
|
248493
|
+
if (RESERVED_BLOCK_BINDINGS.includes(b.local)) {
|
|
248494
|
+
out.push({ name: b.local, specifier, line, col: 1 });
|
|
248495
|
+
}
|
|
248496
|
+
}
|
|
248192
248497
|
}
|
|
248193
248498
|
return out;
|
|
248194
248499
|
}
|
|
@@ -248227,7 +248532,7 @@ function checkServerBlocks(program, opts = {}) {
|
|
|
248227
248532
|
}
|
|
248228
248533
|
const calls = scanRuntimeCalls(b.source);
|
|
248229
248534
|
if (calls.getSession || calls.requireUser) push("TW107", "getSession()/requireUser() are not available in a static page's server block", b.line, b.col);
|
|
248230
|
-
if (calls.redirect
|
|
248535
|
+
if (calls.redirect) push("TW108", "redirect() is not available in a static page's server block -- a static page is built before the request, so there is nothing to redirect", b.line, b.col);
|
|
248231
248536
|
}
|
|
248232
248537
|
}
|
|
248233
248538
|
for (const b of blocks) {
|
|
@@ -248378,12 +248683,13 @@ function parsePageCache(source) {
|
|
|
248378
248683
|
const rv = revalidate ?? 60;
|
|
248379
248684
|
return { revalidate: rv, expire: expire ?? rv, tag: tagM ? tagM[1] : void 0 };
|
|
248380
248685
|
}
|
|
248381
|
-
var ts3, REQUEST_IDENTIFIERS, SERVER_REDIRECT_BRAND, SERVER_NOT_FOUND_BRAND, ServerRedirect, ServerNotFound, isServerRedirect, isServerNotFound, DEFAULT_SERVER_BLOCK_TIMEOUT_MS;
|
|
248686
|
+
var ts3, import_node_fs9, REQUEST_IDENTIFIERS, SERVER_REDIRECT_BRAND, SERVER_NOT_FOUND_BRAND, ServerRedirect, ServerNotFound, isServerRedirect, isServerNotFound, DEFAULT_SERVER_BLOCK_TIMEOUT_MS, MARKER_IMPORT_RE, RESERVED_BLOCK_BINDINGS;
|
|
248382
248687
|
var init_server_blocks = __esm({
|
|
248383
248688
|
"../../packages/compiler/tw/server-blocks/index.ts"() {
|
|
248384
248689
|
init_codes();
|
|
248385
248690
|
init_serialize();
|
|
248386
248691
|
ts3 = __toESM(require_typescript(), 1);
|
|
248692
|
+
import_node_fs9 = require("node:fs");
|
|
248387
248693
|
REQUEST_IDENTIFIERS = /* @__PURE__ */ new Set(["headers", "cookies", "query", "params"]);
|
|
248388
248694
|
SERVER_REDIRECT_BRAND = Symbol.for("tw.serverRedirect");
|
|
248389
248695
|
SERVER_NOT_FOUND_BRAND = Symbol.for("tw.serverNotFound");
|
|
@@ -248405,6 +248711,19 @@ var init_server_blocks = __esm({
|
|
|
248405
248711
|
isServerRedirect = (e) => !!(e && e[SERVER_REDIRECT_BRAND]);
|
|
248406
248712
|
isServerNotFound = (e) => !!(e && e[SERVER_NOT_FOUND_BRAND]);
|
|
248407
248713
|
DEFAULT_SERVER_BLOCK_TIMEOUT_MS = 1e4;
|
|
248714
|
+
MARKER_IMPORT_RE = /^[ \t]*import\s*["']@tw\/(?:server-only|client-safe)["'][ \t]*;?[ \t]*\r?\n?/gm;
|
|
248715
|
+
RESERVED_BLOCK_BINDINGS = [
|
|
248716
|
+
"params",
|
|
248717
|
+
"query",
|
|
248718
|
+
"headers",
|
|
248719
|
+
"cookies",
|
|
248720
|
+
"env",
|
|
248721
|
+
"fetch",
|
|
248722
|
+
"getSession",
|
|
248723
|
+
"requireUser",
|
|
248724
|
+
"redirect",
|
|
248725
|
+
"notFound"
|
|
248726
|
+
];
|
|
248408
248727
|
}
|
|
248409
248728
|
});
|
|
248410
248729
|
|
|
@@ -249860,24 +250179,24 @@ var init_memory = __esm({
|
|
|
249860
250179
|
});
|
|
249861
250180
|
|
|
249862
250181
|
// ../../packages/compiler/tw/cache/disk.ts
|
|
249863
|
-
var
|
|
250182
|
+
var import_node_fs10, import_node_path15, DiskCache;
|
|
249864
250183
|
var init_disk = __esm({
|
|
249865
250184
|
"../../packages/compiler/tw/cache/disk.ts"() {
|
|
249866
|
-
|
|
250185
|
+
import_node_fs10 = require("node:fs");
|
|
249867
250186
|
import_node_path15 = require("node:path");
|
|
249868
250187
|
init_tw();
|
|
249869
250188
|
DiskCache = class {
|
|
249870
250189
|
constructor(cacheDir) {
|
|
249871
250190
|
this.cacheDir = cacheDir;
|
|
249872
|
-
if (!(0,
|
|
249873
|
-
(0,
|
|
250191
|
+
if (!(0, import_node_fs10.existsSync)(cacheDir)) {
|
|
250192
|
+
(0, import_node_fs10.mkdirSync)(cacheDir, { recursive: true });
|
|
249874
250193
|
}
|
|
249875
250194
|
}
|
|
249876
250195
|
get(key2) {
|
|
249877
250196
|
const path = this.keyToPath(key2);
|
|
249878
|
-
if (!(0,
|
|
250197
|
+
if (!(0, import_node_fs10.existsSync)(path)) return null;
|
|
249879
250198
|
try {
|
|
249880
|
-
const data = JSON.parse((0,
|
|
250199
|
+
const data = JSON.parse((0, import_node_fs10.readFileSync)(path, "utf-8"));
|
|
249881
250200
|
return data.value;
|
|
249882
250201
|
} catch {
|
|
249883
250202
|
return null;
|
|
@@ -249885,27 +250204,27 @@ var init_disk = __esm({
|
|
|
249885
250204
|
}
|
|
249886
250205
|
set(key2, value, hash2) {
|
|
249887
250206
|
const path = this.keyToPath(key2);
|
|
249888
|
-
(0,
|
|
250207
|
+
(0, import_node_fs10.mkdirSync)((0, import_node_path15.dirname)(path), { recursive: true });
|
|
249889
250208
|
const entry = { key: key2, value, hash: hash2, createdAt: Date.now() };
|
|
249890
|
-
(0,
|
|
250209
|
+
(0, import_node_fs10.writeFileSync)(path, JSON.stringify(entry));
|
|
249891
250210
|
}
|
|
249892
250211
|
has(key2) {
|
|
249893
|
-
return (0,
|
|
250212
|
+
return (0, import_node_fs10.existsSync)(this.keyToPath(key2));
|
|
249894
250213
|
}
|
|
249895
250214
|
delete(key2) {
|
|
249896
250215
|
const path = this.keyToPath(key2);
|
|
249897
250216
|
try {
|
|
249898
|
-
(0,
|
|
250217
|
+
(0, import_node_fs10.unlinkSync)(path);
|
|
249899
250218
|
} catch {
|
|
249900
250219
|
}
|
|
249901
250220
|
}
|
|
249902
250221
|
clear() {
|
|
249903
250222
|
try {
|
|
249904
|
-
const files = (0,
|
|
250223
|
+
const files = (0, import_node_fs10.readdirSync)(this.cacheDir);
|
|
249905
250224
|
for (const f of files) {
|
|
249906
250225
|
if (f.endsWith(".json")) {
|
|
249907
250226
|
try {
|
|
249908
|
-
(0,
|
|
250227
|
+
(0, import_node_fs10.unlinkSync)((0, import_node_path15.join)(this.cacheDir, f));
|
|
249909
250228
|
} catch {
|
|
249910
250229
|
}
|
|
249911
250230
|
}
|
|
@@ -249915,7 +250234,7 @@ var init_disk = __esm({
|
|
|
249915
250234
|
}
|
|
249916
250235
|
keys() {
|
|
249917
250236
|
try {
|
|
249918
|
-
return (0,
|
|
250237
|
+
return (0, import_node_fs10.readdirSync)(this.cacheDir).filter((f) => f.endsWith(".json")).map((f) => f.replace(".json", ""));
|
|
249919
250238
|
} catch {
|
|
249920
250239
|
return [];
|
|
249921
250240
|
}
|
|
@@ -250411,7 +250730,7 @@ function findRustBinary() {
|
|
|
250411
250730
|
}
|
|
250412
250731
|
for (const candidate of candidates) {
|
|
250413
250732
|
if (candidate.includes("/") || candidate.includes("\\")) {
|
|
250414
|
-
if ((0,
|
|
250733
|
+
if ((0, import_node_fs11.existsSync)(candidate)) {
|
|
250415
250734
|
cachedBinaryPath = candidate;
|
|
250416
250735
|
return candidate;
|
|
250417
250736
|
}
|
|
@@ -250500,11 +250819,11 @@ function destroyPool() {
|
|
|
250500
250819
|
pool?.destroy();
|
|
250501
250820
|
pool = null;
|
|
250502
250821
|
}
|
|
250503
|
-
var import_node_child_process3,
|
|
250822
|
+
var import_node_child_process3, import_node_fs11, import_node_path16, cachedBinaryPath, POOL_SIZE, pool, ProcessPool;
|
|
250504
250823
|
var init_child_process = __esm({
|
|
250505
250824
|
"../../packages/compiler/tw/native/child-process.ts"() {
|
|
250506
250825
|
import_node_child_process3 = require("node:child_process");
|
|
250507
|
-
|
|
250826
|
+
import_node_fs11 = require("node:fs");
|
|
250508
250827
|
import_node_path16 = require("node:path");
|
|
250509
250828
|
cachedBinaryPath = void 0;
|
|
250510
250829
|
POOL_SIZE = 1;
|
|
@@ -255032,6 +255351,7 @@ __export(tw_exports2, {
|
|
|
255032
255351
|
PropParser: () => PropParser,
|
|
255033
255352
|
RENDER_MODE_ALIASES: () => RENDER_MODE_ALIASES,
|
|
255034
255353
|
RENDER_MODE_NAMES: () => RENDER_MODE_NAMES,
|
|
255354
|
+
RESERVED_BLOCK_BINDINGS: () => RESERVED_BLOCK_BINDINGS,
|
|
255035
255355
|
RESERVED_WORDS: () => RESERVED_WORDS,
|
|
255036
255356
|
RuleEngine: () => RuleEngine,
|
|
255037
255357
|
RulesEngine: () => RulesEngine,
|
|
@@ -255675,6 +255995,7 @@ __export(tw_exports2, {
|
|
|
255675
255995
|
secretEnvValues: () => secretEnvValues,
|
|
255676
255996
|
separateByType: () => separateByType,
|
|
255677
255997
|
serializeCache: () => serializeCache,
|
|
255998
|
+
serverImportCollisions: () => serverImportCollisions,
|
|
255678
255999
|
serverRouteParamCollisions: () => serverRouteParamCollisions,
|
|
255679
256000
|
serverStateCollisions: () => serverStateCollisions,
|
|
255680
256001
|
setBackend: () => setBackend,
|
|
@@ -257290,7 +257611,7 @@ var init_layout_chain = __esm({
|
|
|
257290
257611
|
|
|
257291
257612
|
// ../../packages/server/tw/routing/scanner.ts
|
|
257292
257613
|
function scanRouteTree(opts) {
|
|
257293
|
-
if (!(0,
|
|
257614
|
+
if (!(0, import_node_fs12.existsSync)(opts.homeDir)) return null;
|
|
257294
257615
|
const root = {
|
|
257295
257616
|
segment: "",
|
|
257296
257617
|
relativePath: "",
|
|
@@ -257308,7 +257629,7 @@ function scanRouteTree(opts) {
|
|
|
257308
257629
|
function scanDirectory(dirPath, urlPath, groups, parentNode, opts) {
|
|
257309
257630
|
let entries;
|
|
257310
257631
|
try {
|
|
257311
|
-
entries = (0,
|
|
257632
|
+
entries = (0, import_node_fs12.readdirSync)(dirPath);
|
|
257312
257633
|
} catch {
|
|
257313
257634
|
console.warn(`[scanner] Cannot read directory: ${dirPath}`);
|
|
257314
257635
|
return;
|
|
@@ -257319,7 +257640,7 @@ function scanDirectory(dirPath, urlPath, groups, parentNode, opts) {
|
|
|
257319
257640
|
if (!ROUTE_EXTENSIONS.has(ext)) continue;
|
|
257320
257641
|
let stat;
|
|
257321
257642
|
try {
|
|
257322
|
-
stat = (0,
|
|
257643
|
+
stat = (0, import_node_fs12.statSync)(fullPath);
|
|
257323
257644
|
} catch {
|
|
257324
257645
|
continue;
|
|
257325
257646
|
}
|
|
@@ -257342,7 +257663,7 @@ function scanDirectory(dirPath, urlPath, groups, parentNode, opts) {
|
|
|
257342
257663
|
const fullPath = (0, import_node_path17.join)(dirPath, entry);
|
|
257343
257664
|
let stat;
|
|
257344
257665
|
try {
|
|
257345
|
-
stat = (0,
|
|
257666
|
+
stat = (0, import_node_fs12.statSync)(fullPath);
|
|
257346
257667
|
} catch {
|
|
257347
257668
|
continue;
|
|
257348
257669
|
}
|
|
@@ -257633,10 +257954,10 @@ function printNode(node, prefix, isLast, lines) {
|
|
|
257633
257954
|
printNode(node.children[i], childPrefix, i === node.children.length - 1, lines);
|
|
257634
257955
|
}
|
|
257635
257956
|
}
|
|
257636
|
-
var
|
|
257957
|
+
var import_node_fs12, import_node_path17;
|
|
257637
257958
|
var init_scanner = __esm({
|
|
257638
257959
|
"../../packages/server/tw/routing/scanner.ts"() {
|
|
257639
|
-
|
|
257960
|
+
import_node_fs12 = require("node:fs");
|
|
257640
257961
|
import_node_path17 = require("node:path");
|
|
257641
257962
|
init_tw();
|
|
257642
257963
|
}
|
|
@@ -257714,10 +258035,10 @@ function getCacheProfiles(rootDir) {
|
|
|
257714
258035
|
function createRenderPipeline(opts) {
|
|
257715
258036
|
return new RenderPipeline(opts);
|
|
257716
258037
|
}
|
|
257717
|
-
var
|
|
258038
|
+
var import_node_fs13, import_node_path18, __profilesCache, RenderPipeline;
|
|
257718
258039
|
var init_render_pipeline = __esm({
|
|
257719
258040
|
"../../packages/server/tw/routing/render-pipeline.ts"() {
|
|
257720
|
-
|
|
258041
|
+
import_node_fs13 = require("node:fs");
|
|
257721
258042
|
import_node_path18 = require("node:path");
|
|
257722
258043
|
init_tw7();
|
|
257723
258044
|
init_tw();
|
|
@@ -257731,6 +258052,32 @@ var init_render_pipeline = __esm({
|
|
|
257731
258052
|
init_tw9();
|
|
257732
258053
|
__profilesCache = null;
|
|
257733
258054
|
RenderPipeline = class {
|
|
258055
|
+
/**
|
|
258056
|
+
* A dynamic route with a sibling `params.twm` is an enumerated route: the
|
|
258057
|
+
* static build only writes the generated slugs, so a static host 404s an
|
|
258058
|
+
* unknown one. The server matched `[slug]` for anything and rendered the
|
|
258059
|
+
* page's fallback branch with status 200, so search engines indexed those as
|
|
258060
|
+
* real pages. Return true when the requested params are not in `generate()`.
|
|
258061
|
+
*/
|
|
258062
|
+
async isUnenumeratedParam(pageFile, params) {
|
|
258063
|
+
if (!/\[[^\]]+\]/.test(pageFile)) return false;
|
|
258064
|
+
const paramsTwm = (0, import_node_path18.dirname)(pageFile) + "/params.twm";
|
|
258065
|
+
if (!(0, import_node_fs13.existsSync)(paramsTwm)) return false;
|
|
258066
|
+
try {
|
|
258067
|
+
const { loadTWMModule: loadTWMModule2 } = await Promise.resolve().then(() => (init_twm_loader(), twm_loader_exports));
|
|
258068
|
+
const pmod = await loadTWMModule2(paramsTwm, this.rootDir);
|
|
258069
|
+
if (typeof pmod?.generate !== "function") return false;
|
|
258070
|
+
const arr2 = await pmod.generate();
|
|
258071
|
+
if (!Array.isArray(arr2) || arr2.length === 0) return false;
|
|
258072
|
+
const keys = Object.keys(params);
|
|
258073
|
+
if (keys.length === 0) return false;
|
|
258074
|
+
const sets = arr2.map((x) => x && typeof x === "object" ? x : { [keys[0]]: String(x) });
|
|
258075
|
+
const found = sets.some((set) => keys.every((k) => String(set[k] ?? "") === String(params[k] ?? "")));
|
|
258076
|
+
return !found;
|
|
258077
|
+
} catch {
|
|
258078
|
+
return false;
|
|
258079
|
+
}
|
|
258080
|
+
}
|
|
257734
258081
|
rootDir;
|
|
257735
258082
|
homeDir;
|
|
257736
258083
|
enableCache;
|
|
@@ -257806,10 +258153,10 @@ var init_render_pipeline = __esm({
|
|
|
257806
258153
|
/** Read a route file, memoised outside dev. See `sourceCache`. */
|
|
257807
258154
|
readSource(file) {
|
|
257808
258155
|
const key2 = file.absolutePath;
|
|
257809
|
-
if (this.dev) return (0,
|
|
258156
|
+
if (this.dev) return (0, import_node_fs13.readFileSync)(key2, "utf-8");
|
|
257810
258157
|
const hit = this.sourceCache.get(key2);
|
|
257811
258158
|
if (hit !== void 0) return hit;
|
|
257812
|
-
const src = (0,
|
|
258159
|
+
const src = (0, import_node_fs13.readFileSync)(key2, "utf-8");
|
|
257813
258160
|
this.sourceCache.set(key2, src);
|
|
257814
258161
|
return src;
|
|
257815
258162
|
}
|
|
@@ -257834,6 +258181,17 @@ var init_render_pipeline = __esm({
|
|
|
257834
258181
|
const ctx = match ? resolveLayoutChain2(match) : null;
|
|
257835
258182
|
const pageFile = ctx?.page?.absolutePath;
|
|
257836
258183
|
if (!pageFile) return this.render(pathname);
|
|
258184
|
+
try {
|
|
258185
|
+
if (await this.isUnenumeratedParam(pageFile, match?.params ?? {})) {
|
|
258186
|
+
this.__forceNotFound = true;
|
|
258187
|
+
try {
|
|
258188
|
+
return this.render(pathname);
|
|
258189
|
+
} finally {
|
|
258190
|
+
this.__forceNotFound = false;
|
|
258191
|
+
}
|
|
258192
|
+
}
|
|
258193
|
+
} catch {
|
|
258194
|
+
}
|
|
257837
258195
|
let blocks = [];
|
|
257838
258196
|
let src = "";
|
|
257839
258197
|
try {
|
|
@@ -258109,7 +258467,7 @@ var init_render_pipeline = __esm({
|
|
|
258109
258467
|
if (!tree) {
|
|
258110
258468
|
return this.renderError("home/ directory not found", 500, startTime);
|
|
258111
258469
|
}
|
|
258112
|
-
const match = matchRoute(tree, pathname);
|
|
258470
|
+
const match = this.__forceNotFound ? null : matchRoute(tree, pathname);
|
|
258113
258471
|
if (!match) {
|
|
258114
258472
|
const rootNotFound = findNearestNotFound(tree, pathname.split("/").filter(Boolean));
|
|
258115
258473
|
if (rootNotFound) {
|
|
@@ -258258,9 +258616,9 @@ ${bodyHTML}`;
|
|
|
258258
258616
|
try {
|
|
258259
258617
|
const headCandidates = [];
|
|
258260
258618
|
const globalHead = join16(this.rootDir, "home", "head.tw");
|
|
258261
|
-
if ((0,
|
|
258619
|
+
if ((0, import_node_fs13.existsSync)(globalHead)) headCandidates.push(globalHead);
|
|
258262
258620
|
const siblingHead = join16((0, import_node_path18.dirname)(ctx.page.absolutePath), "head.tw");
|
|
258263
|
-
if (siblingHead !== globalHead && (0,
|
|
258621
|
+
if (siblingHead !== globalHead && (0, import_node_fs13.existsSync)(siblingHead)) headCandidates.push(siblingHead);
|
|
258264
258622
|
for (const hp of headCandidates) {
|
|
258265
258623
|
const headCompiled = this.compileFile({ absolutePath: hp, type: "head" });
|
|
258266
258624
|
const m = headCompiled.html.match(/<body>([\s\S]*)<\/body>/);
|
|
@@ -258394,7 +258752,7 @@ ${bodyHTML}`;
|
|
|
258394
258752
|
}
|
|
258395
258753
|
};
|
|
258396
258754
|
}
|
|
258397
|
-
if (!(0,
|
|
258755
|
+
if (!(0, import_node_fs13.existsSync)(file.absolutePath)) {
|
|
258398
258756
|
throw new Error(`Route file not found: ${file.absolutePath}`);
|
|
258399
258757
|
}
|
|
258400
258758
|
const source = this.readSource(file);
|
|
@@ -258788,7 +259146,7 @@ ${devScript}
|
|
|
258788
259146
|
*/
|
|
258789
259147
|
async runMiddleware(pathname, request) {
|
|
258790
259148
|
const middlewarePath = join16(this.rootDir, "middleware.twm");
|
|
258791
|
-
if (!(0,
|
|
259149
|
+
if (!(0, import_node_fs13.existsSync)(middlewarePath)) return;
|
|
258792
259150
|
const mod = await loadTWMModule(middlewarePath, this.rootDir);
|
|
258793
259151
|
if (mod.config?.matcher && !shouldMatchMiddleware(mod.config.matcher, pathname)) {
|
|
258794
259152
|
return;
|
|
@@ -258940,10 +259298,10 @@ var init_fs_compat = __esm({
|
|
|
258940
259298
|
});
|
|
258941
259299
|
|
|
258942
259300
|
// ../../packages/server/tw/router/index.ts
|
|
258943
|
-
var
|
|
259301
|
+
var import_node_fs14, import_node_path19, RouteRegistry;
|
|
258944
259302
|
var init_router = __esm({
|
|
258945
259303
|
"../../packages/server/tw/router/index.ts"() {
|
|
258946
|
-
|
|
259304
|
+
import_node_fs14 = require("node:fs");
|
|
258947
259305
|
init_fs_compat();
|
|
258948
259306
|
import_node_path19 = require("node:path");
|
|
258949
259307
|
RouteRegistry = class {
|
|
@@ -259009,7 +259367,7 @@ var init_router = __esm({
|
|
|
259009
259367
|
return [...this.routes];
|
|
259010
259368
|
}
|
|
259011
259369
|
loadFromDir(pagesDir, basePath = "/") {
|
|
259012
|
-
if (!(0,
|
|
259370
|
+
if (!(0, import_node_fs14.existsSync)(pagesDir)) return;
|
|
259013
259371
|
const files = [];
|
|
259014
259372
|
this.collectFiles(pagesDir, ".tw", files, "");
|
|
259015
259373
|
for (const file of files) {
|
|
@@ -259043,10 +259401,10 @@ var init_router = __esm({
|
|
|
259043
259401
|
}
|
|
259044
259402
|
}
|
|
259045
259403
|
collectFiles(dir, ext, results, relPath) {
|
|
259046
|
-
const entries = (0,
|
|
259404
|
+
const entries = (0, import_node_fs14.readdirSync)(dir);
|
|
259047
259405
|
for (const entry of entries) {
|
|
259048
259406
|
const fullPath = (0, import_node_path19.join)(dir, entry);
|
|
259049
|
-
const stat = (0,
|
|
259407
|
+
const stat = (0, import_node_fs14.statSync)(fullPath);
|
|
259050
259408
|
if (stat.isDirectory()) {
|
|
259051
259409
|
this.collectFiles(fullPath, ext, results, (0, import_node_path19.join)(relPath, entry));
|
|
259052
259410
|
} else if (entry.endsWith(ext)) {
|
|
@@ -260764,10 +261122,10 @@ var init_signal_transports = __esm({
|
|
|
260764
261122
|
});
|
|
260765
261123
|
|
|
260766
261124
|
// ../../packages/server/tw/static/index.ts
|
|
260767
|
-
var
|
|
261125
|
+
var import_node_fs15, import_node_path20, StaticHandler;
|
|
260768
261126
|
var init_static = __esm({
|
|
260769
261127
|
"../../packages/server/tw/static/index.ts"() {
|
|
260770
|
-
|
|
261128
|
+
import_node_fs15 = require("node:fs");
|
|
260771
261129
|
init_fs_compat();
|
|
260772
261130
|
import_node_path20 = require("node:path");
|
|
260773
261131
|
init_tw();
|
|
@@ -260805,31 +261163,31 @@ var init_static = __esm({
|
|
|
260805
261163
|
return new Response("Not Found", { status: 404, headers: { "Content-Type": "text/plain" } });
|
|
260806
261164
|
}
|
|
260807
261165
|
let filePath = (0, import_node_path20.join)(this.root, safePath);
|
|
260808
|
-
if ((0,
|
|
261166
|
+
if ((0, import_node_fs15.existsSync)(filePath) && (0, import_node_fs15.statSync)(filePath).isDirectory()) {
|
|
260809
261167
|
filePath = (0, import_node_path20.join)(filePath, this.indexFile);
|
|
260810
261168
|
}
|
|
260811
|
-
if (!(0,
|
|
261169
|
+
if (!(0, import_node_fs15.existsSync)(filePath)) {
|
|
260812
261170
|
filePath = (0, import_node_path20.join)(this.root, safePath + ".html");
|
|
260813
261171
|
}
|
|
260814
261172
|
let notFoundFallback = false;
|
|
260815
|
-
if (!(0,
|
|
261173
|
+
if (!(0, import_node_fs15.existsSync)(filePath)) {
|
|
260816
261174
|
filePath = (0, import_node_path20.join)(this.root, safePath, this.indexFile);
|
|
260817
261175
|
}
|
|
260818
|
-
if (!(0,
|
|
261176
|
+
if (!(0, import_node_fs15.existsSync)(filePath)) {
|
|
260819
261177
|
if (this.spa) {
|
|
260820
261178
|
filePath = (0, import_node_path20.join)(this.root, this.indexFile);
|
|
260821
|
-
if (!(0,
|
|
261179
|
+
if (!(0, import_node_fs15.existsSync)(filePath)) {
|
|
260822
261180
|
return new Response("Not Found", { status: 404 });
|
|
260823
261181
|
}
|
|
260824
261182
|
} else {
|
|
260825
261183
|
filePath = (0, import_node_path20.join)(this.root, "404.html");
|
|
260826
261184
|
notFoundFallback = true;
|
|
260827
|
-
if (!(0,
|
|
261185
|
+
if (!(0, import_node_fs15.existsSync)(filePath)) {
|
|
260828
261186
|
return new Response("Not Found", { status: 404, headers: { "Content-Type": "text/plain" } });
|
|
260829
261187
|
}
|
|
260830
261188
|
}
|
|
260831
261189
|
}
|
|
260832
|
-
const stat = (0,
|
|
261190
|
+
const stat = (0, import_node_fs15.statSync)(filePath);
|
|
260833
261191
|
const ext = (0, import_node_path20.extname)(filePath).toLowerCase();
|
|
260834
261192
|
const contentType = MIME_TYPES[ext] ?? "application/octet-stream";
|
|
260835
261193
|
const bytes = await readBytes(filePath);
|
|
@@ -263058,8 +263416,8 @@ var init_bot_detection = __esm({
|
|
|
263058
263416
|
|
|
263059
263417
|
// ../../packages/security/tw/content-security/protector.ts
|
|
263060
263418
|
function sanitizeFilename(filename) {
|
|
263061
|
-
const
|
|
263062
|
-
let clean =
|
|
263419
|
+
const basename4 = filename.replace(/^.*[\\/]/, "");
|
|
263420
|
+
let clean = basename4.replace(/\x00/g, "");
|
|
263063
263421
|
clean = clean.replace(/[<>:"|?*]/g, "_");
|
|
263064
263422
|
clean = clean.replace(/^\.+/, "");
|
|
263065
263423
|
if (clean.length > 255) {
|
|
@@ -269809,8 +270167,8 @@ function getCachedSSR(pathname) {
|
|
|
269809
270167
|
return { html: mem.html, etag: mem.etag };
|
|
269810
270168
|
}
|
|
269811
270169
|
const diskPath = (0, import_node_path21.join)(_diskCacheDir, pathname.replace(/[\/]/g, "_") + ".html");
|
|
269812
|
-
if ((0,
|
|
269813
|
-
const content = (0,
|
|
270170
|
+
if ((0, import_node_fs17.existsSync)(diskPath)) {
|
|
270171
|
+
const content = (0, import_node_fs16.readFileSync)(diskPath, "utf-8");
|
|
269814
270172
|
const etag = (0, import_node_crypto7.createHash)("sha256").update(content).digest("hex").slice(0, 16);
|
|
269815
270173
|
_ssrCache.set(pathname, { html: content, etag, expires: Date.now() + 6e4 });
|
|
269816
270174
|
return { html: content, etag };
|
|
@@ -269821,9 +270179,9 @@ function setCachedSSR(pathname, html) {
|
|
|
269821
270179
|
const etag = (0, import_node_crypto7.createHash)("sha256").update(html).digest("hex").slice(0, 16);
|
|
269822
270180
|
_ssrCache.set(pathname, { html, etag, expires: Date.now() + 6e4 });
|
|
269823
270181
|
try {
|
|
269824
|
-
if (!(0,
|
|
270182
|
+
if (!(0, import_node_fs17.existsSync)(_diskCacheDir)) (0, import_node_fs16.mkdirSync)(_diskCacheDir, { recursive: true });
|
|
269825
270183
|
const diskPath = (0, import_node_path21.join)(_diskCacheDir, pathname.replace(/[\/]/g, "_") + ".html");
|
|
269826
|
-
(0,
|
|
270184
|
+
(0, import_node_fs16.writeFileSync)(diskPath, html);
|
|
269827
270185
|
} catch {
|
|
269828
270186
|
}
|
|
269829
270187
|
return etag;
|
|
@@ -269850,15 +270208,15 @@ function generatePreloadHints(assets) {
|
|
|
269850
270208
|
}
|
|
269851
270209
|
return hints.join("\n");
|
|
269852
270210
|
}
|
|
269853
|
-
var
|
|
270211
|
+
var import_node_fs16, import_node_crypto7, import_node_path21, import_node_fs17, SSRRenderer, _ssrCache, _diskCacheDir;
|
|
269854
270212
|
var init_ssr = __esm({
|
|
269855
270213
|
"../../packages/server/tw/ssr/index.ts"() {
|
|
269856
|
-
|
|
270214
|
+
import_node_fs16 = require("node:fs");
|
|
269857
270215
|
init_fs_compat();
|
|
269858
270216
|
init_tw();
|
|
269859
270217
|
import_node_crypto7 = require("node:crypto");
|
|
269860
270218
|
import_node_path21 = require("node:path");
|
|
269861
|
-
|
|
270219
|
+
import_node_fs17 = require("node:fs");
|
|
269862
270220
|
SSRRenderer = class {
|
|
269863
270221
|
pagesDir;
|
|
269864
270222
|
cacheDir;
|
|
@@ -269930,9 +270288,9 @@ var init_ssr = __esm({
|
|
|
269930
270288
|
}
|
|
269931
270289
|
}
|
|
269932
270290
|
const filePath = this.resolveRoute(pathname);
|
|
269933
|
-
if (!filePath || !(0,
|
|
270291
|
+
if (!filePath || !(0, import_node_fs16.existsSync)(filePath)) return null;
|
|
269934
270292
|
try {
|
|
269935
|
-
const source = (0,
|
|
270293
|
+
const source = (0, import_node_fs16.readFileSync)(filePath, "utf-8");
|
|
269936
270294
|
return {
|
|
269937
270295
|
html: `<html><body>SSR sync not available</body></html>`,
|
|
269938
270296
|
css: "",
|
|
@@ -269967,35 +270325,35 @@ var init_ssr = __esm({
|
|
|
269967
270325
|
let currentDir = this.pagesDir;
|
|
269968
270326
|
if (segments.length === 0) {
|
|
269969
270327
|
const pagePath = (0, import_node_path21.join)(this.pagesDir, "page.tw");
|
|
269970
|
-
if ((0,
|
|
270328
|
+
if ((0, import_node_fs16.existsSync)(pagePath)) return pagePath;
|
|
269971
270329
|
const indexPath = (0, import_node_path21.join)(this.pagesDir, "index.tw");
|
|
269972
|
-
if ((0,
|
|
270330
|
+
if ((0, import_node_fs16.existsSync)(indexPath)) return indexPath;
|
|
269973
270331
|
return null;
|
|
269974
270332
|
}
|
|
269975
270333
|
for (let i = 0; i < segments.length; i++) {
|
|
269976
270334
|
const seg = segments[i];
|
|
269977
270335
|
const isLast = i === segments.length - 1;
|
|
269978
|
-
const entries = (0,
|
|
270336
|
+
const entries = (0, import_node_fs16.existsSync)(currentDir) ? require("node:fs").readdirSync(currentDir) : [];
|
|
269979
270337
|
if (isLast) {
|
|
269980
270338
|
const exactPath = (0, import_node_path21.join)(currentDir, seg + ".tw");
|
|
269981
|
-
if ((0,
|
|
270339
|
+
if ((0, import_node_fs16.existsSync)(exactPath)) return exactPath;
|
|
269982
270340
|
const dirPage = (0, import_node_path21.join)(currentDir, seg, "page.tw");
|
|
269983
|
-
if ((0,
|
|
270341
|
+
if ((0, import_node_fs16.existsSync)(dirPage)) return dirPage;
|
|
269984
270342
|
const paramFile = entries.find((e) => e.match(/^\[([^\]]+)\]\.tw$/));
|
|
269985
270343
|
if (paramFile) return (0, import_node_path21.join)(currentDir, paramFile);
|
|
269986
270344
|
const paramDir = entries.find((e) => e.match(/^\[([^\]]+)\]$/));
|
|
269987
270345
|
if (paramDir) {
|
|
269988
270346
|
const p = (0, import_node_path21.join)(currentDir, paramDir, "page.tw");
|
|
269989
|
-
if ((0,
|
|
270347
|
+
if ((0, import_node_fs16.existsSync)(p)) return p;
|
|
269990
270348
|
const pIdx = (0, import_node_path21.join)(currentDir, paramDir, "index.tw");
|
|
269991
|
-
if ((0,
|
|
270349
|
+
if ((0, import_node_fs16.existsSync)(pIdx)) return pIdx;
|
|
269992
270350
|
}
|
|
269993
270351
|
const idx = (0, import_node_path21.join)(currentDir, seg, "index.tw");
|
|
269994
|
-
if ((0,
|
|
270352
|
+
if ((0, import_node_fs16.existsSync)(idx)) return idx;
|
|
269995
270353
|
return null;
|
|
269996
270354
|
}
|
|
269997
270355
|
const dirPath = (0, import_node_path21.join)(currentDir, seg);
|
|
269998
|
-
if ((0,
|
|
270356
|
+
if ((0, import_node_fs16.existsSync)(dirPath) && require("node:fs").statSync(dirPath).isDirectory()) {
|
|
269999
270357
|
currentDir = dirPath;
|
|
270000
270358
|
} else {
|
|
270001
270359
|
const paramDir = entries.find((e) => e.match(/^\[([^\]]+)\]$/));
|
|
@@ -271547,7 +271905,7 @@ function applyRewrites(rewrites, pathname) {
|
|
|
271547
271905
|
}
|
|
271548
271906
|
return null;
|
|
271549
271907
|
}
|
|
271550
|
-
var import_node_path22,
|
|
271908
|
+
var import_node_path22, import_node_fs18, TWServer;
|
|
271551
271909
|
var init_tw9 = __esm({
|
|
271552
271910
|
"../../packages/server/tw/index.ts"() {
|
|
271553
271911
|
init_tw();
|
|
@@ -271556,7 +271914,7 @@ var init_tw9 = __esm({
|
|
|
271556
271914
|
init_websocket_manager();
|
|
271557
271915
|
init_routing2();
|
|
271558
271916
|
import_node_path22 = require("node:path");
|
|
271559
|
-
|
|
271917
|
+
import_node_fs18 = require("node:fs");
|
|
271560
271918
|
init_twm_rules();
|
|
271561
271919
|
init_router();
|
|
271562
271920
|
init_middleware2();
|
|
@@ -271709,6 +272067,19 @@ var init_tw9 = __esm({
|
|
|
271709
272067
|
const entries = Object.entries(cfgIn.rewrites);
|
|
271710
272068
|
cfgIn.rewrites = entries.map(([from, to]) => typeof to === "string" ? { from, to } : { from, ...to });
|
|
271711
272069
|
}
|
|
272070
|
+
if (Array.isArray(cfgIn.headers)) {
|
|
272071
|
+
const HEADER_ENTRY_KEYS = /* @__PURE__ */ new Set(["source", "headers"]);
|
|
272072
|
+
for (const h3 of cfgIn.headers) {
|
|
272073
|
+
if (!h3 || typeof h3 !== "object") continue;
|
|
272074
|
+
const unknown = Object.keys(h3).filter((k) => !HEADER_ENTRY_KEYS.has(k));
|
|
272075
|
+
if (unknown.length > 0) {
|
|
272076
|
+
console.warn("[tw] headers: unrecognized key" + (unknown.length > 1 ? "s" : "") + " " + unknown.join(", ") + " in entry -- accepted keys are source and headers" + (unknown.includes("path") ? " (did you mean 'source'?)" : ""));
|
|
272077
|
+
}
|
|
272078
|
+
if (h3.source === void 0 && h3.path !== void 0) {
|
|
272079
|
+
console.warn("[tw] headers: entry uses 'path' instead of 'source' -- it will not be applied");
|
|
272080
|
+
}
|
|
272081
|
+
}
|
|
272082
|
+
}
|
|
271712
272083
|
for (const h3 of cfgIn.headers ?? []) {
|
|
271713
272084
|
if (h3?.headers && typeof h3.headers === "object") {
|
|
271714
272085
|
for (const k of Object.keys(h3.headers)) {
|
|
@@ -271786,11 +272157,11 @@ var init_tw9 = __esm({
|
|
|
271786
272157
|
}
|
|
271787
272158
|
}
|
|
271788
272159
|
const staticDir = this.options.staticDir ?? (0, import_node_path22.join)(options.rootDir, ".tw");
|
|
271789
|
-
if ((0,
|
|
272160
|
+
if ((0, import_node_fs18.existsSync)(staticDir)) {
|
|
271790
272161
|
try {
|
|
271791
272162
|
const manifestPath = (0, import_node_path22.join)(staticDir, "routes.json");
|
|
271792
|
-
if ((0,
|
|
271793
|
-
const manifest = JSON.parse((0,
|
|
272163
|
+
if ((0, import_node_fs18.existsSync)(manifestPath)) {
|
|
272164
|
+
const manifest = JSON.parse((0, import_node_fs18.readFileSync)(manifestPath, "utf-8"));
|
|
271794
272165
|
for (const [route, secs] of Object.entries(manifest)) {
|
|
271795
272166
|
this.isrRoutes.set(route, secs);
|
|
271796
272167
|
}
|
|
@@ -271808,7 +272179,7 @@ var init_tw9 = __esm({
|
|
|
271808
272179
|
});
|
|
271809
272180
|
}
|
|
271810
272181
|
const homeDir = this.options.pagesDir ?? (0, import_node_path22.join)(options.rootDir, "home");
|
|
271811
|
-
if ((0,
|
|
272182
|
+
if ((0, import_node_fs18.existsSync)(homeDir)) {
|
|
271812
272183
|
this.ssr = new SSRRenderer({ pagesDir: homeDir, enableCache: true, cacheTTL: 6e4 });
|
|
271813
272184
|
}
|
|
271814
272185
|
}
|
|
@@ -271855,11 +272226,11 @@ var init_tw9 = __esm({
|
|
|
271855
272226
|
middlewarePath = null;
|
|
271856
272227
|
loadMiddleware() {
|
|
271857
272228
|
const middlewarePath = (0, import_node_path22.join)(this.options.rootDir, "middleware.twm");
|
|
271858
|
-
if ((0,
|
|
272229
|
+
if ((0, import_node_fs18.existsSync)(middlewarePath)) {
|
|
271859
272230
|
this.middlewarePath = middlewarePath;
|
|
271860
272231
|
console.log(" Middleware: middleware.twm loaded");
|
|
271861
272232
|
try {
|
|
271862
|
-
const src = (0,
|
|
272233
|
+
const src = (0, import_node_fs18.readFileSync)(middlewarePath, "utf-8");
|
|
271863
272234
|
const rules = parseRules(src, "middleware.twm");
|
|
271864
272235
|
for (const r of rules) {
|
|
271865
272236
|
const conds = [];
|
|
@@ -272350,7 +272721,7 @@ var init_tw9 = __esm({
|
|
|
272350
272721
|
return new Response("Bad Request", { status: 400 });
|
|
272351
272722
|
}
|
|
272352
272723
|
const homeDir = (0, import_node_path22.join)(this.options.rootDir, "home");
|
|
272353
|
-
if (!(0,
|
|
272724
|
+
if (!(0, import_node_fs18.existsSync)(homeDir)) return new Response("Not Found", { status: 404 });
|
|
272354
272725
|
try {
|
|
272355
272726
|
const { createRenderPipeline: createRenderPipeline2 } = await Promise.resolve().then(() => (init_routing2(), routing_exports));
|
|
272356
272727
|
if (!this.renderPipeline) {
|
|
@@ -272499,7 +272870,7 @@ var init_tw9 = __esm({
|
|
|
272499
272870
|
try {
|
|
272500
272871
|
const { createRenderPipeline: createRenderPipeline2 } = await Promise.resolve().then(() => (init_routing2(), routing_exports));
|
|
272501
272872
|
const homeDir = (0, import_node_path22.join)(this.options.rootDir, "home");
|
|
272502
|
-
if ((0,
|
|
272873
|
+
if ((0, import_node_fs18.existsSync)(homeDir)) {
|
|
272503
272874
|
const pipeline = createRenderPipeline2({
|
|
272504
272875
|
rootDir: this.options.rootDir,
|
|
272505
272876
|
homeDir,
|
|
@@ -272559,7 +272930,7 @@ ${err2.stack ?? ""}`);
|
|
|
272559
272930
|
try {
|
|
272560
272931
|
const { createRenderPipeline: createRenderPipeline2, setActivePipeline: setActivePipeline2 } = await Promise.resolve().then(() => (init_routing2(), routing_exports));
|
|
272561
272932
|
const homeDir = (0, import_node_path22.join)(this.options.rootDir, "home");
|
|
272562
|
-
if ((0,
|
|
272933
|
+
if ((0, import_node_fs18.existsSync)(homeDir)) {
|
|
272563
272934
|
if (!this.renderPipeline) {
|
|
272564
272935
|
this.renderPipeline = createRenderPipeline2({
|
|
272565
272936
|
rootDir: this.options.rootDir,
|
|
@@ -287334,7 +287705,7 @@ function clearTWMCache() {
|
|
|
287334
287705
|
function validateTWMSyntax(filePath) {
|
|
287335
287706
|
let source;
|
|
287336
287707
|
try {
|
|
287337
|
-
source = (0,
|
|
287708
|
+
source = (0, import_node_fs19.readFileSync)(filePath, "utf-8");
|
|
287338
287709
|
} catch (err2) {
|
|
287339
287710
|
return "cannot read: " + (err2?.message ?? err2);
|
|
287340
287711
|
}
|
|
@@ -287434,7 +287805,7 @@ async function loadLibModule(rootDir, name) {
|
|
|
287434
287805
|
const cacheKey = rootDir + "/" + rel;
|
|
287435
287806
|
if (libCache.has(cacheKey)) return libCache.get(cacheKey);
|
|
287436
287807
|
const libPath = (0, import_node_path23.join)(rootDir, "lib", rel + ".ts");
|
|
287437
|
-
if (!(0,
|
|
287808
|
+
if (!(0, import_node_fs19.existsSync)(libPath)) {
|
|
287438
287809
|
throw new Error("Module '" + name + "' not found. Create lib/" + name + ".ts");
|
|
287439
287810
|
}
|
|
287440
287811
|
try {
|
|
@@ -287476,10 +287847,10 @@ async function loadTWMModule(filePath, rootDir) {
|
|
|
287476
287847
|
const cacheKey = filePath;
|
|
287477
287848
|
const cached2 = moduleCache.get(cacheKey);
|
|
287478
287849
|
if (cached2) return cached2;
|
|
287479
|
-
if (!(0,
|
|
287850
|
+
if (!(0, import_node_fs19.existsSync)(filePath)) {
|
|
287480
287851
|
throw new Error("TWM module not found: " + filePath);
|
|
287481
287852
|
}
|
|
287482
|
-
const source = (0,
|
|
287853
|
+
const source = (0, import_node_fs19.readFileSync)(filePath, "utf-8");
|
|
287483
287854
|
const rd = rootDir || process.cwd();
|
|
287484
287855
|
if (isRuleDsl(source)) {
|
|
287485
287856
|
try {
|
|
@@ -288007,10 +288378,10 @@ function shouldMatchMiddleware(matchers, pathname) {
|
|
|
288007
288378
|
}
|
|
288008
288379
|
return false;
|
|
288009
288380
|
}
|
|
288010
|
-
var
|
|
288381
|
+
var import_node_fs19, import_node_path23, moduleCache, libCache, apiRuntime, routeCache, IMPURE_PATTERNS, NONDET_PATTERN, __twmProfiles, handlerCache, pendingHandlerRefresh;
|
|
288011
288382
|
var init_twm_loader = __esm({
|
|
288012
288383
|
"../../packages/server/tw/routing/twm-loader.ts"() {
|
|
288013
|
-
|
|
288384
|
+
import_node_fs19 = require("node:fs");
|
|
288014
288385
|
init_revalidate();
|
|
288015
288386
|
init_signal_stream();
|
|
288016
288387
|
import_node_path23 = require("node:path");
|
|
@@ -288051,15 +288422,15 @@ __export(testing_exports, {
|
|
|
288051
288422
|
});
|
|
288052
288423
|
module.exports = __toCommonJS(testing_exports);
|
|
288053
288424
|
var import_node_path24 = require("node:path");
|
|
288054
|
-
var
|
|
288425
|
+
var import_node_fs20 = require("node:fs");
|
|
288055
288426
|
var import_meta = {};
|
|
288056
288427
|
function resolveRouteFile(rootDir, pathname) {
|
|
288057
288428
|
const homeDir = (0, import_node_path24.join)(rootDir, "home");
|
|
288058
|
-
if (!(0,
|
|
288429
|
+
if (!(0, import_node_fs20.existsSync)(homeDir)) return null;
|
|
288059
288430
|
const segments = pathname.split("/").filter(Boolean).map(decodeURIComponent);
|
|
288060
288431
|
const isDir = (p) => {
|
|
288061
288432
|
try {
|
|
288062
|
-
return (0,
|
|
288433
|
+
return (0, import_node_fs20.existsSync)(p) && (0, import_node_fs20.statSync)(p).isDirectory();
|
|
288063
288434
|
} catch {
|
|
288064
288435
|
return false;
|
|
288065
288436
|
}
|
|
@@ -288067,7 +288438,7 @@ function resolveRouteFile(rootDir, pathname) {
|
|
|
288067
288438
|
function walk3(dir, i, params) {
|
|
288068
288439
|
if (i >= segments.length) {
|
|
288069
288440
|
const f = (0, import_node_path24.join)(dir, "route.twm");
|
|
288070
|
-
return (0,
|
|
288441
|
+
return (0, import_node_fs20.existsSync)(f) ? { file: f, params } : null;
|
|
288071
288442
|
}
|
|
288072
288443
|
const seg = segments[i];
|
|
288073
288444
|
const exact = (0, import_node_path24.join)(dir, seg);
|
|
@@ -288075,7 +288446,7 @@ function resolveRouteFile(rootDir, pathname) {
|
|
|
288075
288446
|
const r = walk3(exact, i + 1, params);
|
|
288076
288447
|
if (r) return r;
|
|
288077
288448
|
}
|
|
288078
|
-
for (const entry of (0,
|
|
288449
|
+
for (const entry of (0, import_node_fs20.readdirSync)(dir)) {
|
|
288079
288450
|
if (/^\(.*\)$/.test(entry) && isDir((0, import_node_path24.join)(dir, entry))) {
|
|
288080
288451
|
const r = walk3((0, import_node_path24.join)(dir, entry), i, params);
|
|
288081
288452
|
if (r) return r;
|
|
@@ -288088,7 +288459,7 @@ function resolveRouteFile(rootDir, pathname) {
|
|
|
288088
288459
|
const c = /^\[\.\.\.(.+)\]$/.exec(entry) || /^\[\[\.\.\.(.+)\]\]$/.exec(entry);
|
|
288089
288460
|
if (c && isDir((0, import_node_path24.join)(dir, entry))) {
|
|
288090
288461
|
const f = (0, import_node_path24.join)(dir, entry, "route.twm");
|
|
288091
|
-
if ((0,
|
|
288462
|
+
if ((0, import_node_fs20.existsSync)(f)) return { file: f, params: { ...params, [c[1]]: segments.slice(i).join("/") } };
|
|
288092
288463
|
}
|
|
288093
288464
|
}
|
|
288094
288465
|
return null;
|
|
@@ -288118,7 +288489,7 @@ async function testPage(rootDir, pathname) {
|
|
|
288118
288489
|
const segments = pathname.split("/").filter(Boolean);
|
|
288119
288490
|
const isDir = (p) => {
|
|
288120
288491
|
try {
|
|
288121
|
-
return (0,
|
|
288492
|
+
return (0, import_node_fs20.existsSync)(p) && (0, import_node_fs20.statSync)(p).isDirectory();
|
|
288122
288493
|
} catch {
|
|
288123
288494
|
return false;
|
|
288124
288495
|
}
|
|
@@ -288126,7 +288497,7 @@ async function testPage(rootDir, pathname) {
|
|
|
288126
288497
|
function walk3(dir, i, params) {
|
|
288127
288498
|
if (i >= segments.length) {
|
|
288128
288499
|
const f = (0, import_node_path24.join)(dir, "page.tw");
|
|
288129
|
-
return (0,
|
|
288500
|
+
return (0, import_node_fs20.existsSync)(f) ? { file: f, params } : null;
|
|
288130
288501
|
}
|
|
288131
288502
|
const seg = segments[i];
|
|
288132
288503
|
const exact = (0, import_node_path24.join)(dir, seg);
|
|
@@ -288134,7 +288505,7 @@ async function testPage(rootDir, pathname) {
|
|
|
288134
288505
|
const r = walk3(exact, i + 1, params);
|
|
288135
288506
|
if (r) return r;
|
|
288136
288507
|
}
|
|
288137
|
-
for (const entry of (0,
|
|
288508
|
+
for (const entry of (0, import_node_fs20.readdirSync)(dir)) {
|
|
288138
288509
|
if (/^\(.*\)$/.test(entry) && isDir((0, import_node_path24.join)(dir, entry))) {
|
|
288139
288510
|
const r = walk3((0, import_node_path24.join)(dir, entry), i, params);
|
|
288140
288511
|
if (r) return r;
|
|
@@ -288147,7 +288518,7 @@ async function testPage(rootDir, pathname) {
|
|
|
288147
288518
|
const c = /^\[\.\.\.(.+)\]$/.exec(entry);
|
|
288148
288519
|
if (c && isDir((0, import_node_path24.join)(dir, entry))) {
|
|
288149
288520
|
const f = (0, import_node_path24.join)(dir, entry, "page.tw");
|
|
288150
|
-
if ((0,
|
|
288521
|
+
if ((0, import_node_fs20.existsSync)(f)) return { file: f, params: { ...params, [c[1]]: segments.slice(i).join("/") } };
|
|
288151
288522
|
}
|
|
288152
288523
|
}
|
|
288153
288524
|
return null;
|
|
@@ -288157,28 +288528,28 @@ async function testPage(rootDir, pathname) {
|
|
|
288157
288528
|
const { compileSync: compileSync3, generateWithLayoutChain: generateWithLayoutChain2, registerComponentTemplate: registerComponentTemplate2, clearComponentRegistry: clearComponentRegistry2 } = await findCompiler();
|
|
288158
288529
|
clearComponentRegistry2();
|
|
288159
288530
|
const compDir = (0, import_node_path24.join)(rootDir, "components");
|
|
288160
|
-
if ((0,
|
|
288161
|
-
for (const f of (0,
|
|
288531
|
+
if ((0, import_node_fs20.existsSync)(compDir)) {
|
|
288532
|
+
for (const f of (0, import_node_fs20.readdirSync)(compDir).filter((f2) => f2.endsWith(".tw"))) {
|
|
288162
288533
|
const fp = (0, import_node_path24.join)(compDir, f);
|
|
288163
|
-
const r = compileSync3((0,
|
|
288534
|
+
const r = compileSync3((0, import_node_fs20.readFileSync)(fp, "utf-8"), { filePath: fp, transforms: false, diagnostics: false });
|
|
288164
288535
|
if (r.ast) registerComponentTemplate2(f.replace(/\.tw$/, ""), r.ast);
|
|
288165
288536
|
}
|
|
288166
288537
|
}
|
|
288167
|
-
const result = compileSync3((0,
|
|
288538
|
+
const result = compileSync3((0, import_node_fs20.readFileSync)(resolved.file, "utf-8"), { filePath: resolved.file, stateVars: resolved.params });
|
|
288168
288539
|
let html = result.html;
|
|
288169
288540
|
const pageProgram = result.ast;
|
|
288170
288541
|
const layouts = [];
|
|
288171
288542
|
let d = (0, import_node_path24.dirname)(resolved.file);
|
|
288172
288543
|
while (true) {
|
|
288173
288544
|
const lp = (0, import_node_path24.join)(d, "layout.tw");
|
|
288174
|
-
if ((0,
|
|
288545
|
+
if ((0, import_node_fs20.existsSync)(lp) && d.startsWith(homeDir)) layouts.unshift(lp);
|
|
288175
288546
|
if (d === homeDir || !d.startsWith(homeDir)) break;
|
|
288176
288547
|
const parent = (0, import_node_path24.dirname)(d);
|
|
288177
288548
|
if (parent === d) break;
|
|
288178
288549
|
d = parent;
|
|
288179
288550
|
}
|
|
288180
288551
|
if (layouts.length > 0) {
|
|
288181
|
-
const progs = layouts.map((lp) => compileSync3((0,
|
|
288552
|
+
const progs = layouts.map((lp) => compileSync3((0, import_node_fs20.readFileSync)(lp, "utf-8"), { filePath: lp }).ast).filter(Boolean);
|
|
288182
288553
|
if (progs.length > 0 && generateWithLayoutChain2) {
|
|
288183
288554
|
html = generateWithLayoutChain2(progs, pageProgram, resolved.params);
|
|
288184
288555
|
}
|
|
@@ -288193,7 +288564,7 @@ async function findCompiler() {
|
|
|
288193
288564
|
(0, import_node_path24.join)(rootDirGlobal, "packages/compiler/tw/index.ts"),
|
|
288194
288565
|
process.env.TW_COMPILER_PATH ?? ""
|
|
288195
288566
|
].filter(Boolean);
|
|
288196
|
-
for (const c of candidates) if ((0,
|
|
288567
|
+
for (const c of candidates) if ((0, import_node_fs20.existsSync)(c)) return import(c);
|
|
288197
288568
|
const selfDir = import_meta.dir ?? (typeof __dirname !== "undefined" ? __dirname : "");
|
|
288198
288569
|
return import((0, import_node_path24.join)(selfDir, "../../../compiler/tw/index.ts"));
|
|
288199
288570
|
}
|