tw-framework 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +69 -0
- package/dist/hydration-runtime.js +35 -4
- package/dist/testing.cjs +156 -7
- package/dist/tw-runtime-client.mjs +45 -2
- package/dist/tw-server.mjs +156 -7
- package/dist/tw.mjs +230 -36
- package/package.json +3 -2
package/dist/tw.mjs
CHANGED
|
@@ -1542,10 +1542,10 @@ var init_request_context = __esm({
|
|
|
1542
1542
|
throw new Error(`Environment variable ${name} is not valid JSON`);
|
|
1543
1543
|
}
|
|
1544
1544
|
}
|
|
1545
|
-
list(name,
|
|
1545
|
+
list(name, sep3 = ",") {
|
|
1546
1546
|
const v = this.source[name];
|
|
1547
1547
|
if (!v) return [];
|
|
1548
|
-
return v.split(
|
|
1548
|
+
return v.split(sep3).map((s) => s.trim()).filter(Boolean);
|
|
1549
1549
|
}
|
|
1550
1550
|
/**
|
|
1551
1551
|
* Validate a whole set at once -- call it at startup and every problem is
|
|
@@ -3332,10 +3332,10 @@ function printTable(headers, rows) {
|
|
|
3332
3332
|
return Math.max(h3.length, maxRowLen);
|
|
3333
3333
|
});
|
|
3334
3334
|
const formatRow = (cells) => " " + cells.map((cell, i) => String(cell).padEnd(widths[i])).join(" ") + " ";
|
|
3335
|
-
const
|
|
3335
|
+
const sep3 = "-".repeat(widths.reduce((a, b) => a + b + 2, 0) + 1);
|
|
3336
3336
|
process.stderr.write(`${ANSI.bold}${formatRow(headers)}${ANSI.reset}
|
|
3337
3337
|
`);
|
|
3338
|
-
process.stderr.write(`${ANSI.dim}${
|
|
3338
|
+
process.stderr.write(`${ANSI.dim}${sep3}${ANSI.reset}
|
|
3339
3339
|
`);
|
|
3340
3340
|
for (const row of rows) {
|
|
3341
3341
|
process.stderr.write(formatRow(row.map(String)) + "\n");
|
|
@@ -63414,11 +63414,11 @@ ${lanes.join("\n")}
|
|
|
63414
63414
|
if (i < rootLength) {
|
|
63415
63415
|
return void 0;
|
|
63416
63416
|
}
|
|
63417
|
-
const
|
|
63418
|
-
if (
|
|
63417
|
+
const sep3 = directory.lastIndexOf(directorySeparator, i - 1);
|
|
63418
|
+
if (sep3 === -1) {
|
|
63419
63419
|
return void 0;
|
|
63420
63420
|
}
|
|
63421
|
-
return directory.substr(0, Math.max(
|
|
63421
|
+
return directory.substr(0, Math.max(sep3, rootLength));
|
|
63422
63422
|
}
|
|
63423
63423
|
}
|
|
63424
63424
|
}
|
|
@@ -227222,7 +227222,7 @@ function parseTWSelector(cursor, errors, state, parseBody) {
|
|
|
227222
227222
|
const after2 = cursor.peek(1);
|
|
227223
227223
|
if (after2 && after2.type === "COLON") break;
|
|
227224
227224
|
}
|
|
227225
|
-
if (ct.type === "IDENT" && !prevWasMinus && classVal.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
227225
|
+
if ((ct.type === "IDENT" || ct.type === "KEYWORD") && !prevWasMinus && classVal.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
227226
227226
|
break;
|
|
227227
227227
|
}
|
|
227228
227228
|
if (ct.type === "IDENT" || ct.type === "TEXT" || ct.type === "KEYWORD") {
|
|
@@ -227254,7 +227254,7 @@ function parseTWSelector(cursor, errors, state, parseBody) {
|
|
|
227254
227254
|
const after2 = cursor.peek(1);
|
|
227255
227255
|
if (after2 && after2.type === "COLON") break;
|
|
227256
227256
|
}
|
|
227257
|
-
if (ct.type === "IDENT" && !nextPrevMinus && nextClass.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
227257
|
+
if ((ct.type === "IDENT" || ct.type === "KEYWORD") && !nextPrevMinus && nextClass.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
227258
227258
|
break;
|
|
227259
227259
|
}
|
|
227260
227260
|
if (ct.type === "IDENT" || ct.type === "TEXT" || ct.type === "KEYWORD") {
|
|
@@ -233652,8 +233652,8 @@ var init_constant_folding = __esm({
|
|
|
233652
233652
|
return { type: "string", value: str2.substring(start, end) };
|
|
233653
233653
|
}
|
|
233654
233654
|
case "split": {
|
|
233655
|
-
const
|
|
233656
|
-
const parts =
|
|
233655
|
+
const sep3 = args[0]?.type === "string" ? args[0].value : "";
|
|
233656
|
+
const parts = sep3 ? str2.split(sep3) : [str2];
|
|
233657
233657
|
return { type: "array", elements: parts.map((p) => ({ type: "string", value: p })) };
|
|
233658
233658
|
}
|
|
233659
233659
|
case "replace": {
|
|
@@ -233721,8 +233721,8 @@ var init_constant_folding = __esm({
|
|
|
233721
233721
|
case "length":
|
|
233722
233722
|
return { type: "number", value: elements.length };
|
|
233723
233723
|
case "join": {
|
|
233724
|
-
const
|
|
233725
|
-
return { type: "string", value: elements.map((e) => this.constToJSString(e)).join(
|
|
233724
|
+
const sep3 = args[0]?.type === "string" ? args[0].value : ",";
|
|
233725
|
+
return { type: "string", value: elements.map((e) => this.constToJSString(e)).join(sep3) };
|
|
233726
233726
|
}
|
|
233727
233727
|
case "indexOf": {
|
|
233728
233728
|
if (!args[0]) return null;
|
|
@@ -236327,7 +236327,7 @@ var init_types4 = __esm({
|
|
|
236327
236327
|
var TW_VERSION, TW_GENERATOR_META;
|
|
236328
236328
|
var init_version = __esm({
|
|
236329
236329
|
"../../packages/compiler/tw/codegen/version.ts"() {
|
|
236330
|
-
TW_VERSION = "2.0.
|
|
236330
|
+
TW_VERSION = "2.0.3";
|
|
236331
236331
|
TW_GENERATOR_META = `<meta name="generator" content="TW Framework ${TW_VERSION}">`;
|
|
236332
236332
|
}
|
|
236333
236333
|
});
|
|
@@ -239421,6 +239421,11 @@ function generateElement(el, ctx) {
|
|
|
239421
239421
|
}
|
|
239422
239422
|
function renderAttrs(el, ctx) {
|
|
239423
239423
|
const parts = [];
|
|
239424
|
+
const classAttrs = el.attrs.filter((a) => a.name === "class" && !a.isInterpolated && typeof a.value === "string");
|
|
239425
|
+
if (classAttrs.length > 1) {
|
|
239426
|
+
const merged = classAttrs.map((a) => String(a.value).trim()).filter(Boolean).join(" ");
|
|
239427
|
+
el = { ...el, attrs: el.attrs.filter((a) => a.name !== "class").concat([{ ...classAttrs[0], value: merged }]) };
|
|
239428
|
+
}
|
|
239424
239429
|
for (let attr of el.attrs) {
|
|
239425
239430
|
if (attr.name === "class" && typeof attr.value === "string" && !attr.isInterpolated) {
|
|
239426
239431
|
const scoped = ctx.scopedClasses;
|
|
@@ -239720,7 +239725,7 @@ function generateFor(node, ctx) {
|
|
|
239720
239725
|
tplSource = node.body.map((c) => generateNode(c, childCtx)).join("");
|
|
239721
239726
|
}
|
|
239722
239727
|
const listExpr = String(node.iterable ?? "").replace(/^\{/, "").replace(/\}$/, "");
|
|
239723
|
-
const tpl = tplSource.replace(/"/g, """);
|
|
239728
|
+
const tpl = tplSource.replace(/&/g, "&").replace(/"/g, """);
|
|
239724
239729
|
return `<tw-for data-tw-var="${node.varName}"${node.indexName ? ` data-tw-index="${node.indexName}"` : ""} data-tw-list="${listExpr}" data-tw-tpl="${tpl}">${html}</tw-for>`;
|
|
239725
239730
|
}
|
|
239726
239731
|
return html;
|
|
@@ -244130,6 +244135,8 @@ var init_codes = __esm({
|
|
|
244130
244135
|
TW117: { message: "fetch() with a request-derived URL (SSRF lint)", severity: "warning", category: "semantic" },
|
|
244131
244136
|
TW118: { message: "A deferred server block cannot redirect() or notFound() -- the response has already begun", severity: "error", category: "semantic" },
|
|
244132
244137
|
TW119: { message: "A deferred server block cannot be used on a cached page -- cache { } serves one HTML to every request", severity: "error", category: "semantic" },
|
|
244138
|
+
TW121: { message: "The same name is declared by more than one state { } block (the earlier one wins)", severity: "warning", category: "semantic" },
|
|
244139
|
+
TW122: { message: "More than one default slot in the same component -- a caller's default content has no defined destination", severity: "warning", category: "semantic" },
|
|
244133
244140
|
// Codes thrown outside the rule engine. TW303 comes from the stylesheet
|
|
244134
244141
|
// parser (codegen/tss.ts); TW000 is the generic fallback used when an error
|
|
244135
244142
|
// carries no code of its own.
|
|
@@ -244523,6 +244530,14 @@ function checkUnknownStateVars(program, filePath, diags) {
|
|
|
244523
244530
|
if (d && d.type === "ServerBlock" && Array.isArray(d.declaredNames)) {
|
|
244524
244531
|
for (const n of d.declaredNames) known.add(n);
|
|
244525
244532
|
}
|
|
244533
|
+
if (d && d.type === "ImportDirective" && !d.isTypeOnly) {
|
|
244534
|
+
if (d.defaultImport) known.add(String(d.defaultImport));
|
|
244535
|
+
if (d.namespaceImport) known.add(String(d.namespaceImport));
|
|
244536
|
+
for (const it of d.items ?? []) {
|
|
244537
|
+
const nm = String(it).split(/\s+as\s+/).pop()?.trim();
|
|
244538
|
+
if (nm) known.add(nm);
|
|
244539
|
+
}
|
|
244540
|
+
}
|
|
244526
244541
|
}
|
|
244527
244542
|
const texts = [];
|
|
244528
244543
|
forEachNode(program, (node) => {
|
|
@@ -244665,6 +244680,27 @@ function checkDeprecatedImports(program, filePath, diags) {
|
|
|
244665
244680
|
}
|
|
244666
244681
|
}
|
|
244667
244682
|
}
|
|
244683
|
+
function checkDuplicateDefaultSlots(program, filePath, diags) {
|
|
244684
|
+
let count = 0;
|
|
244685
|
+
let first = null;
|
|
244686
|
+
forEachNode(program, (node) => {
|
|
244687
|
+
if (!node || node.type !== "Slot") return;
|
|
244688
|
+
const name = String(node.name ?? "default");
|
|
244689
|
+
if (name !== "default") return;
|
|
244690
|
+
count++;
|
|
244691
|
+
if (!first) first = node;
|
|
244692
|
+
});
|
|
244693
|
+
if (count > 1 && first) {
|
|
244694
|
+
diags.push(createDiagnostic(
|
|
244695
|
+
"TW122",
|
|
244696
|
+
first.line ?? 1,
|
|
244697
|
+
first.col ?? 1,
|
|
244698
|
+
filePath,
|
|
244699
|
+
`${count} default slots`,
|
|
244700
|
+
["Keep one default slot -- a caller's default content has no defined destination with two"]
|
|
244701
|
+
));
|
|
244702
|
+
}
|
|
244703
|
+
}
|
|
244668
244704
|
var HTML_ELEMENTS2, HTML_ATTRIBUTES2, GLOBAL_ATTRIBUTES2, CSS_PROPERTIES2, CSS_ALIASES2, EVENT_TYPES2, ARIA_ROLES2, ARIA_ATTRIBUTES2, BUILTIN_COMPONENT_TAGS, DEPRECATED_IMPORTS;
|
|
244669
244705
|
var init_rules = __esm({
|
|
244670
244706
|
"../../packages/compiler/tw/diagnostics/rules.ts"() {
|
|
@@ -245573,6 +245609,7 @@ function diagnose(program, filePath) {
|
|
|
245573
245609
|
checkLoopIterables(program, filePath, diagnostics);
|
|
245574
245610
|
checkUnknownStateVars(program, filePath, diagnostics);
|
|
245575
245611
|
checkWhileComparisons(program, filePath, diagnostics);
|
|
245612
|
+
checkDuplicateDefaultSlots(program, filePath, diagnostics);
|
|
245576
245613
|
return diagnostics;
|
|
245577
245614
|
}
|
|
245578
245615
|
var RuleEngine;
|
|
@@ -247929,6 +247966,28 @@ function lintSsrf(body) {
|
|
|
247929
247966
|
while (m = re.exec(body)) out.push("fetch(<dynamic url>)");
|
|
247930
247967
|
const concat = /fetch\s*\(\s*[^,)]*\b(params|query|headers|cookies)\b[^,)]*\+/g;
|
|
247931
247968
|
while (m = concat.exec(body)) out.push("fetch(<concatenated url>)");
|
|
247969
|
+
const TAINTED_ROOT = /\b(params|query|headers|cookies)\b/;
|
|
247970
|
+
const tainted = /* @__PURE__ */ new Set();
|
|
247971
|
+
for (let pass = 0; pass < 5; pass++) {
|
|
247972
|
+
let grew = false;
|
|
247973
|
+
const assign = /(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*([^;\n]+)/g;
|
|
247974
|
+
let a;
|
|
247975
|
+
while (a = assign.exec(body)) {
|
|
247976
|
+
const [, name, rhs] = a;
|
|
247977
|
+
if (tainted.has(name)) continue;
|
|
247978
|
+
const fromRoot = TAINTED_ROOT.test(rhs);
|
|
247979
|
+
const fromTainted = [...tainted].some((t3) => new RegExp("\\b" + t3 + "\\b").test(rhs));
|
|
247980
|
+
if (fromRoot || fromTainted) {
|
|
247981
|
+
tainted.add(name);
|
|
247982
|
+
grew = true;
|
|
247983
|
+
}
|
|
247984
|
+
}
|
|
247985
|
+
if (!grew) break;
|
|
247986
|
+
}
|
|
247987
|
+
for (const name of tainted) {
|
|
247988
|
+
const use = new RegExp("fetch\\s*\\(\\s*[^,)]*\\b" + name + "\\b[^,)]*[,)]", "g");
|
|
247989
|
+
if (use.test(body)) out.push("fetch(<request-derived url>)");
|
|
247990
|
+
}
|
|
247932
247991
|
return out;
|
|
247933
247992
|
}
|
|
247934
247993
|
var ts2, ServerSerializationError, MAX_DEPTH;
|
|
@@ -248031,6 +248090,36 @@ function serverStateCollisions(program) {
|
|
|
248031
248090
|
}
|
|
248032
248091
|
return out;
|
|
248033
248092
|
}
|
|
248093
|
+
function checkDeclarationConflicts(program, paramNames = []) {
|
|
248094
|
+
const out = [];
|
|
248095
|
+
const params = new Set(paramNames);
|
|
248096
|
+
const seen = /* @__PURE__ */ new Set();
|
|
248097
|
+
for (const d of program.directives ?? []) {
|
|
248098
|
+
if (d.type !== "StateDirective") continue;
|
|
248099
|
+
for (const decl of d.declarations ?? []) {
|
|
248100
|
+
const name = String(decl.name ?? "");
|
|
248101
|
+
if (!name) continue;
|
|
248102
|
+
if (params.has(name)) {
|
|
248103
|
+
out.push({
|
|
248104
|
+
code: "TW102",
|
|
248105
|
+
message: `state declares '${name}', which collides with the route param '${name}' -- the param overwrites the state value`,
|
|
248106
|
+
line: decl.line ?? d.line ?? 1,
|
|
248107
|
+
col: decl.col ?? d.col ?? 1
|
|
248108
|
+
});
|
|
248109
|
+
}
|
|
248110
|
+
if (seen.has(name)) {
|
|
248111
|
+
out.push({
|
|
248112
|
+
code: "TW121",
|
|
248113
|
+
message: `'${name}' is declared by more than one state { } block -- the earlier declaration wins and this one is dead`,
|
|
248114
|
+
line: decl.line ?? d.line ?? 1,
|
|
248115
|
+
col: decl.col ?? d.col ?? 1
|
|
248116
|
+
});
|
|
248117
|
+
}
|
|
248118
|
+
seen.add(name);
|
|
248119
|
+
}
|
|
248120
|
+
}
|
|
248121
|
+
return out;
|
|
248122
|
+
}
|
|
248034
248123
|
function serverRouteParamCollisions(blocks, paramNames) {
|
|
248035
248124
|
const params = new Set(paramNames);
|
|
248036
248125
|
const out = [];
|
|
@@ -248268,7 +248357,14 @@ function checkServerBlocks(program, opts = {}) {
|
|
|
248268
248357
|
const blocks = collectServerBlocks(program);
|
|
248269
248358
|
if (!blocks.length) return [];
|
|
248270
248359
|
const out = [];
|
|
248271
|
-
const push = (code, message, line, col) => out.push({
|
|
248360
|
+
const push = (code, message, line, col) => out.push({
|
|
248361
|
+
severity: ERROR_CODES[code]?.severity === "warning" ? "warning" : "error",
|
|
248362
|
+
code,
|
|
248363
|
+
message,
|
|
248364
|
+
line,
|
|
248365
|
+
col,
|
|
248366
|
+
category: "semantic"
|
|
248367
|
+
});
|
|
248272
248368
|
if (opts.isLayout) {
|
|
248273
248369
|
for (const b of blocks) push("TW105", "server blocks in layouts are not supported yet", b.line, b.col);
|
|
248274
248370
|
return out;
|
|
@@ -248446,6 +248542,7 @@ function parsePageCache(source) {
|
|
|
248446
248542
|
var ts3, REQUEST_IDENTIFIERS, SERVER_REDIRECT_BRAND, SERVER_NOT_FOUND_BRAND, ServerRedirect, ServerNotFound, isServerRedirect, isServerNotFound, DEFAULT_SERVER_BLOCK_TIMEOUT_MS;
|
|
248447
248543
|
var init_server_blocks = __esm({
|
|
248448
248544
|
"../../packages/compiler/tw/server-blocks/index.ts"() {
|
|
248545
|
+
init_codes();
|
|
248449
248546
|
init_serialize();
|
|
248450
248547
|
ts3 = __toESM(require_typescript(), 1);
|
|
248451
248548
|
REQUEST_IDENTIFIERS = /* @__PURE__ */ new Set(["headers", "cookies", "query", "params"]);
|
|
@@ -255166,6 +255263,7 @@ __export(tw_exports3, {
|
|
|
255166
255263
|
canonicalVaryQuery: () => canonicalVaryQuery,
|
|
255167
255264
|
charCode: () => charCode,
|
|
255168
255265
|
check: () => check,
|
|
255266
|
+
checkDeclarationConflicts: () => checkDeclarationConflicts,
|
|
255169
255267
|
checkServerBlocks: () => checkServerBlocks,
|
|
255170
255268
|
chunksToHTML: () => chunksToHTML,
|
|
255171
255269
|
clearComponentRegistry: () => clearComponentRegistry,
|
|
@@ -273421,6 +273519,17 @@ var init_tw10 = __esm({
|
|
|
273421
273519
|
cfgIn.redirects = normalizedRedirects.filter(Boolean);
|
|
273422
273520
|
}
|
|
273423
273521
|
}
|
|
273522
|
+
if (Array.isArray(cfgIn.redirects)) {
|
|
273523
|
+
const seenFrom = /* @__PURE__ */ new Set();
|
|
273524
|
+
for (const r of cfgIn.redirects) {
|
|
273525
|
+
const from = r && typeof r.from === "string" ? r.from : null;
|
|
273526
|
+
if (!from) continue;
|
|
273527
|
+
if (seenFrom.has(from)) {
|
|
273528
|
+
console.warn("[tw] redirects: '" + from + "' is listed more than once -- the first entry wins, the later one never runs");
|
|
273529
|
+
}
|
|
273530
|
+
seenFrom.add(from);
|
|
273531
|
+
}
|
|
273532
|
+
}
|
|
273424
273533
|
if (cfgIn.headers && !Array.isArray(cfgIn.headers)) {
|
|
273425
273534
|
const entries = Object.entries(cfgIn.headers);
|
|
273426
273535
|
cfgIn.headers = entries.map(([source, headers]) => ({ source, headers }));
|
|
@@ -285603,9 +285712,41 @@ function defineStore(idOrDefinition, maybeDefinition) {
|
|
|
285603
285712
|
return () => set.delete(cb);
|
|
285604
285713
|
}
|
|
285605
285714
|
};
|
|
285715
|
+
const MUTATORS = /* @__PURE__ */ new Set(["push", "pop", "shift", "unshift", "splice", "sort", "reverse", "fill", "copyWithin"]);
|
|
285716
|
+
const tracking = /* @__PURE__ */ new WeakMap();
|
|
285717
|
+
const track2 = (value, prop) => {
|
|
285718
|
+
if (value === null || typeof value !== "object") return value;
|
|
285719
|
+
const existing2 = tracking.get(value);
|
|
285720
|
+
if (existing2) return existing2;
|
|
285721
|
+
const wrapped = new Proxy(value, {
|
|
285722
|
+
get(t3, key2, recv) {
|
|
285723
|
+
const v = Reflect.get(t3, key2, recv);
|
|
285724
|
+
if (typeof v === "function" && MUTATORS.has(String(key2))) {
|
|
285725
|
+
return (...args) => {
|
|
285726
|
+
const out = v.apply(t3, args);
|
|
285727
|
+
reactiveState[prop]?.touch();
|
|
285728
|
+
return out;
|
|
285729
|
+
};
|
|
285730
|
+
}
|
|
285731
|
+
return v;
|
|
285732
|
+
},
|
|
285733
|
+
set(t3, key2, v) {
|
|
285734
|
+
const ok3 = Reflect.set(t3, key2, v);
|
|
285735
|
+
reactiveState[prop]?.touch();
|
|
285736
|
+
return ok3;
|
|
285737
|
+
},
|
|
285738
|
+
deleteProperty(t3, key2) {
|
|
285739
|
+
const ok3 = Reflect.deleteProperty(t3, key2);
|
|
285740
|
+
reactiveState[prop]?.touch();
|
|
285741
|
+
return ok3;
|
|
285742
|
+
}
|
|
285743
|
+
});
|
|
285744
|
+
tracking.set(value, wrapped);
|
|
285745
|
+
return wrapped;
|
|
285746
|
+
};
|
|
285606
285747
|
const stateProxy = new Proxy({}, {
|
|
285607
285748
|
get(_target, prop) {
|
|
285608
|
-
return reactiveState[prop]?.value;
|
|
285749
|
+
return track2(reactiveState[prop]?.value, prop);
|
|
285609
285750
|
},
|
|
285610
285751
|
set(_target, prop, value) {
|
|
285611
285752
|
if (reactiveState[prop]) {
|
|
@@ -285726,6 +285867,14 @@ var init_store = __esm({
|
|
|
285726
285867
|
update(updater) {
|
|
285727
285868
|
this.set(updater(this._value));
|
|
285728
285869
|
}
|
|
285870
|
+
/**
|
|
285871
|
+
* Re-notify subscribers without replacing the value. An array or object that
|
|
285872
|
+
* was mutated in place (`this.items.push(x)`) has the same identity, so
|
|
285873
|
+
* `set()` short-circuits and nothing downstream hears about it.
|
|
285874
|
+
*/
|
|
285875
|
+
touch() {
|
|
285876
|
+
this._notify();
|
|
285877
|
+
}
|
|
285729
285878
|
subscribe(listener) {
|
|
285730
285879
|
this._listeners.add(listener);
|
|
285731
285880
|
return () => {
|
|
@@ -286742,7 +286891,7 @@ var init_virtual_list = __esm({
|
|
|
286742
286891
|
return this.container.scrollTop;
|
|
286743
286892
|
}
|
|
286744
286893
|
getFirstVisibleIndex() {
|
|
286745
|
-
const last = Math.max(0, this.options?.itemCount ?? 0 - 1);
|
|
286894
|
+
const last = Math.max(0, (this.options?.itemCount ?? 0) - 1);
|
|
286746
286895
|
return Math.min(Math.max(this.visibleRange.start, 0), last);
|
|
286747
286896
|
}
|
|
286748
286897
|
getLastVisibleIndex() {
|
|
@@ -289735,7 +289884,7 @@ __export(server_boundary_exports, {
|
|
|
289735
289884
|
walkClientGraph: () => walkClientGraph
|
|
289736
289885
|
});
|
|
289737
289886
|
import { readFileSync as readFileSync17, existsSync as existsSync25 } from "node:fs";
|
|
289738
|
-
import { dirname as dirname12, resolve as resolve7, extname as extname9, relative as relative2 } from "node:path";
|
|
289887
|
+
import { dirname as dirname12, resolve as resolve7, extname as extname9, relative as relative2, sep as sep2 } from "node:path";
|
|
289739
289888
|
function collectModuleImports(src) {
|
|
289740
289889
|
const out = [];
|
|
289741
289890
|
if (!src.trim()) return out;
|
|
@@ -289772,7 +289921,7 @@ function matchesOnlyPackages(spec, only) {
|
|
|
289772
289921
|
return false;
|
|
289773
289922
|
}
|
|
289774
289923
|
function isServerOnlyByName(spec) {
|
|
289775
|
-
return /\.server\.(ts|js)
|
|
289924
|
+
return /\.server(\.(ts|js|mjs|cjs))?$/.test(spec);
|
|
289776
289925
|
}
|
|
289777
289926
|
function packageName(spec) {
|
|
289778
289927
|
if (spec.startsWith("@")) return spec.split("/").slice(0, 2).join("/");
|
|
@@ -289803,8 +289952,13 @@ function walkClientGraph(entryFiles, opts = {}) {
|
|
|
289803
289952
|
const spec = imp.specifier;
|
|
289804
289953
|
let layer = null;
|
|
289805
289954
|
if (isServerOnlyByName(spec)) layer = "name";
|
|
289806
|
-
else if (isLocal(spec))
|
|
289807
|
-
|
|
289955
|
+
else if (isLocal(spec)) {
|
|
289956
|
+
const resolvedLocal = resolveLocal(spec, dirname12(file));
|
|
289957
|
+
const libRoot = opts.rootDir ? resolve7(opts.rootDir, "lib") : null;
|
|
289958
|
+
if (resolvedLocal && libRoot && (resolvedLocal === libRoot || resolvedLocal.startsWith(libRoot + sep2))) {
|
|
289959
|
+
layer = "lib";
|
|
289960
|
+
}
|
|
289961
|
+
} else if (spec === SERVER_ONLY_MARKER) layer = "L4";
|
|
289808
289962
|
else if (spec.startsWith("node:") || DENY_NODE_BUILTINS.has(spec)) layer = "L1";
|
|
289809
289963
|
else if (matchesOnlyPackages(spec, only)) layer = "L3";
|
|
289810
289964
|
else if (DEFAULT_DENY_PACKAGES.includes(packageName(spec))) layer = "L2";
|
|
@@ -290560,6 +290714,30 @@ async function buildCommand() {
|
|
|
290560
290714
|
console.log(" index.tw wins this route -- delete one of them");
|
|
290561
290715
|
}
|
|
290562
290716
|
}
|
|
290717
|
+
{
|
|
290718
|
+
const shapes = /* @__PURE__ */ new Map();
|
|
290719
|
+
for (const pf of pageFiles) {
|
|
290720
|
+
const dir = dirname13(pf);
|
|
290721
|
+
if (existsSync26(join30(dir, "page.twm"))) {
|
|
290722
|
+
console.log(" \x1B[33m!\x1B[0m " + dir.replace(homeDir, "").replace(/^\//, "") + "/ has BOTH page.tw and page.twm");
|
|
290723
|
+
console.log(" the .twm handler never runs -- delete one of them");
|
|
290724
|
+
}
|
|
290725
|
+
const rel = pf.replace(homeDir, "").replace(/^\//, "");
|
|
290726
|
+
const segs = rel.split("/").slice(0, -1).filter((seg) => !/^\(.*\)$/.test(seg));
|
|
290727
|
+
const parent = segs.slice(0, -1).join("/");
|
|
290728
|
+
const shape = segs.map((seg) => seg.startsWith("[") ? "[*]" : seg).join("/");
|
|
290729
|
+
if (!segs.length) continue;
|
|
290730
|
+
const key2 = parent + "\0" + shape;
|
|
290731
|
+
const prev = shapes.get(key2);
|
|
290732
|
+
if (prev && prev !== dir) {
|
|
290733
|
+
console.log(" \x1B[31m\u2717\x1B[0m two dynamic routes match the same URL: " + prev.replace(homeDir, "") + " and " + dir.replace(homeDir, ""));
|
|
290734
|
+
console.log(" rename one of the params -- only one of these pages can ever render");
|
|
290735
|
+
errorCount++;
|
|
290736
|
+
} else if (!prev) {
|
|
290737
|
+
shapes.set(key2, dir);
|
|
290738
|
+
}
|
|
290739
|
+
}
|
|
290740
|
+
}
|
|
290563
290741
|
begin("compile", pageFiles.length);
|
|
290564
290742
|
await runBuildHook("pages:discover", { pages: pageFiles, rootDir });
|
|
290565
290743
|
await runBuildHook("before:build", { pages: pageFiles, rootDir, outDir });
|
|
@@ -290625,6 +290803,16 @@ async function buildCommand() {
|
|
|
290625
290803
|
}
|
|
290626
290804
|
}
|
|
290627
290805
|
const renderMode = extractRenderMode2(readFileSync18(pageFile, "utf8"));
|
|
290806
|
+
try {
|
|
290807
|
+
const { parseWithDetails: _pd, checkDeclarationConflicts: checkDeclarationConflicts2 } = _compilerMod;
|
|
290808
|
+
const _prog = _pd(readFileSync18(pageFile, "utf-8"), { filePath: pageFile, cache: false }).program;
|
|
290809
|
+
const _paramNames = routePath.split("/").filter((seg) => seg.startsWith("[")).map((seg) => seg.replace(/^\[+/, "").replace(/\]+$/, "").replace(/^\.\.\./, ""));
|
|
290810
|
+
for (const c of checkDeclarationConflicts2(_prog, _paramNames)) {
|
|
290811
|
+
console.error(" \x1B[33m!\x1B[0m " + pageFile.replace(rootDir + "/", "") + ":" + c.line + " " + c.code + " " + c.message);
|
|
290812
|
+
errorCount++;
|
|
290813
|
+
}
|
|
290814
|
+
} catch {
|
|
290815
|
+
}
|
|
290628
290816
|
{
|
|
290629
290817
|
const pageSrc = readFileSync18(pageFile, "utf-8");
|
|
290630
290818
|
const { extractCacheDirective: extractCacheDirective2, resolveCache: resolveCache2 } = await Promise.resolve().then(() => (init_tw(), tw_exports));
|
|
@@ -290679,8 +290867,11 @@ async function buildCommand() {
|
|
|
290679
290867
|
hasVary: extractVary2(src).length > 0,
|
|
290680
290868
|
referenced: collectReferencedNames3(src)
|
|
290681
290869
|
});
|
|
290682
|
-
for (const p of problems)
|
|
290683
|
-
|
|
290870
|
+
for (const p of problems) {
|
|
290871
|
+
const warn2 = p.severity === "warning";
|
|
290872
|
+
console.error(" " + (warn2 ? "\x1B[33m!\x1B[0m" : "\x1B[31m\u2717\x1B[0m") + " " + pageFile.replace(rootDir + "/", "") + ":" + p.line + " " + p.code + " " + p.message);
|
|
290873
|
+
if (!warn2) errorCount++;
|
|
290874
|
+
}
|
|
290684
290875
|
}
|
|
290685
290876
|
} catch {
|
|
290686
290877
|
}
|
|
@@ -291009,10 +291200,6 @@ async function buildCommand() {
|
|
|
291009
291200
|
apiCount++;
|
|
291010
291201
|
}
|
|
291011
291202
|
}
|
|
291012
|
-
if (existsSync26(libDir)) {
|
|
291013
|
-
copyDir2(libDir, join30(outDir, "lib"));
|
|
291014
|
-
console.log(" \x1B[32mOK\x1B[0m lib/");
|
|
291015
|
-
}
|
|
291016
291203
|
if (existsSync26(publicDir)) {
|
|
291017
291204
|
copyDir2(publicDir, outDir);
|
|
291018
291205
|
console.log(" \x1B[32mOK\x1B[0m public/");
|
|
@@ -291030,6 +291217,10 @@ async function buildCommand() {
|
|
|
291030
291217
|
}
|
|
291031
291218
|
process.exit(1);
|
|
291032
291219
|
}
|
|
291220
|
+
if (existsSync26(libDir)) {
|
|
291221
|
+
copyDir2(libDir, join30(outDir, "lib"));
|
|
291222
|
+
console.log(" \x1B[32mOK\x1B[0m lib/");
|
|
291223
|
+
}
|
|
291033
291224
|
if (clientChunkUrls.size > 0) {
|
|
291034
291225
|
console.log(" \x1B[36m\u26A1\x1B[0m client modules: " + clientChunkUrls.size + " shared chunk" + (clientChunkUrls.size === 1 ? "" : "s") + " (content-hashed, tree-shaken)");
|
|
291035
291226
|
}
|
|
@@ -294176,10 +294367,10 @@ if (typeof globalThis.Bun === "undefined") {
|
|
|
294176
294367
|
const parts = bodyStr.split(boundary);
|
|
294177
294368
|
for (let i = 1; i < parts.length - 1; i++) {
|
|
294178
294369
|
const raw = parts[i];
|
|
294179
|
-
const
|
|
294180
|
-
if (
|
|
294181
|
-
const head = raw.slice(0,
|
|
294182
|
-
let data = raw.slice(
|
|
294370
|
+
const sep3 = raw.indexOf("\r\n\r\n");
|
|
294371
|
+
if (sep3 < 0) continue;
|
|
294372
|
+
const head = raw.slice(0, sep3);
|
|
294373
|
+
let data = raw.slice(sep3 + 4);
|
|
294183
294374
|
if (data.endsWith("\r\n")) data = data.slice(0, -2);
|
|
294184
294375
|
const nameM = /name="([^"]*)"/.exec(head);
|
|
294185
294376
|
if (!nameM) continue;
|
|
@@ -294484,7 +294675,7 @@ async function createPackageJson(dir, name) {
|
|
|
294484
294675
|
ship: "tw ship"
|
|
294485
294676
|
},
|
|
294486
294677
|
dependencies: {
|
|
294487
|
-
"tw-framework": "^2.0.
|
|
294678
|
+
"tw-framework": "^2.0.3"
|
|
294488
294679
|
},
|
|
294489
294680
|
devDependencies: {
|
|
294490
294681
|
typescript: "^5.4.0",
|
|
@@ -294571,7 +294762,7 @@ dist/
|
|
|
294571
294762
|
async function createReadme(dir, name) {
|
|
294572
294763
|
const content = `# ${name}
|
|
294573
294764
|
|
|
294574
|
-
Built with TW Framework 2.0.
|
|
294765
|
+
Built with TW Framework 2.0.3.
|
|
294575
294766
|
|
|
294576
294767
|
## Getting Started
|
|
294577
294768
|
|
|
@@ -296008,6 +296199,7 @@ async function devCommand() {
|
|
|
296008
296199
|
let devRewrites = [];
|
|
296009
296200
|
let devSigCfg = void 0;
|
|
296010
296201
|
let devApiDir = "api";
|
|
296202
|
+
let devHydrationOff = false;
|
|
296011
296203
|
let devSignalTransport = "sse";
|
|
296012
296204
|
try {
|
|
296013
296205
|
const cfgFile = join31(rootDir, "tw.config.ts");
|
|
@@ -296031,6 +296223,7 @@ async function devCommand() {
|
|
|
296031
296223
|
if (cfg?.headers) {
|
|
296032
296224
|
devCfgHeaders = Array.isArray(cfg.headers) ? cfg.headers : Object.entries(cfg.headers).map(([source, headers]) => ({ source, headers }));
|
|
296033
296225
|
}
|
|
296226
|
+
if (cfg?.strategies?.hydration?.mode === "none") devHydrationOff = true;
|
|
296034
296227
|
const st = cfg?.strategies?.signals?.transport;
|
|
296035
296228
|
if (st === "sse" || st === "ws" || st === "long-poll") devSignalTransport = st;
|
|
296036
296229
|
if (cfg?.signalStream) devSigCfg = cfg.signalStream;
|
|
@@ -296342,7 +296535,8 @@ async function devCommand() {
|
|
|
296342
296535
|
`;
|
|
296343
296536
|
}
|
|
296344
296537
|
if (/<\/body>/.test(html)) {
|
|
296345
|
-
|
|
296538
|
+
const runtimeTag = devHydrationOff ? "" : ' <script src="/__tw_runtime.js"></script>\n';
|
|
296539
|
+
html = html.replace("</body>", devClientTag + (devOpts?.overlay === false ? "" : CLIENT_OVERLAY_SCRIPT) + runtimeTag + "</body>");
|
|
296346
296540
|
}
|
|
296347
296541
|
const devGlobalHead = join31(homeDir, "head.tw");
|
|
296348
296542
|
const devHeadSources = [];
|
|
@@ -297113,7 +297307,7 @@ function ensureTestingShim(rootDir) {
|
|
|
297113
297307
|
if (existsSync32(marker)) return;
|
|
297114
297308
|
const { mkdirSync: mkdirSync12, writeFileSync: writeFileSync14 } = _require("node:fs");
|
|
297115
297309
|
mkdirSync12(join37(shimPkgDir, "tw"), { recursive: true });
|
|
297116
|
-
writeFileSync14(marker, JSON.stringify({ name: "@tw/server", version: "2.0.
|
|
297310
|
+
writeFileSync14(marker, JSON.stringify({ name: "@tw/server", version: "2.0.3", private: true }, null, 2));
|
|
297117
297311
|
let testingBundle = null;
|
|
297118
297312
|
try {
|
|
297119
297313
|
const here = new URL(".", import.meta.url).pathname;
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tw-framework",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "Full-stack web framework \u2014 own template language (.tw), styling (.tss), compiler and VDOM; runs on Bun and Node",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/tw.mjs",
|
|
7
7
|
"bin": {
|
|
8
|
-
"tw": "./dist/tw.mjs"
|
|
8
|
+
"tw": "./dist/tw.mjs",
|
|
9
|
+
"tw-framework": "./dist/tw.mjs"
|
|
9
10
|
},
|
|
10
11
|
"dependencies": {
|
|
11
12
|
"esbuild": "^0.21.0"
|