tw-framework 2.0.2 → 2.0.4
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 +73 -0
- package/dist/hydration-runtime.js +14 -1
- package/dist/testing.cjs +111 -3
- package/dist/tw-server.mjs +111 -3
- package/dist/tw.mjs +211 -39
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,79 @@ Notable changes to TW Framework. The format follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/), and the project uses
|
|
5
5
|
[Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [2.0.4]
|
|
8
|
+
|
|
9
|
+
A patch release on top of 2.0.3. Bug fixes plus one deliberate behaviour change
|
|
10
|
+
(raw HTML in a `.tw` file is now an error, see below).
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- **`tw dev` runs `server { }` blocks.** It called the compiler without
|
|
15
|
+
`experimental.serverBlocks`, so `collectServerBlocks()` always came back empty
|
|
16
|
+
and the block never executed: a page whose content came from `server { }`
|
|
17
|
+
rendered with empty lists. The values are also merged the way the serve path
|
|
18
|
+
does (`params` as a key, through `encodeServerValues`), which is what actually
|
|
19
|
+
gets them into the markup.
|
|
20
|
+
- **`tw dev` sets `Content-Type` for `public/` files.** `new Response(Bun.file())`
|
|
21
|
+
does not carry the file's type, so every `.svg`, `.css` and `.json` arrived
|
|
22
|
+
without one and images showed as broken icons.
|
|
23
|
+
- **`state { }` in `layout.tw`.** Only the page's state was seeded into the vars
|
|
24
|
+
the layout's markup is generated from, so a layout holding state for its own
|
|
25
|
+
chrome rendered empty. Layouts are seeded first, so the page still wins a name
|
|
26
|
+
clash.
|
|
27
|
+
- **`TW003` on valid inline tags.** `HTML_ELEMENTS` was missing `b`, `i`, `em`,
|
|
28
|
+
`strong`, `small`, `u`, `s`, `ins`, `del`, `sub`, `sup`, `nobr`, `big`, `tt`
|
|
29
|
+
and the SVG children (`circle`, `path`, `rect`, `g`, `defs`, `use`, …), which
|
|
30
|
+
produced a warning per tag on markup that renders fine and buried the real
|
|
31
|
+
findings.
|
|
32
|
+
- **`tw serve` answered 200 for an unknown dynamic param.** A route with a
|
|
33
|
+
`params.twm` enumerates its slugs, and the static build only writes those — but
|
|
34
|
+
the server matched `[slug]` for anything and rendered the fallback branch with
|
|
35
|
+
200, so search engines indexed those as real pages. An unenumerated param is a
|
|
36
|
+
404 now, through the normal not-found path.
|
|
37
|
+
- **`headers` config ignored an unknown key.** `{ path, headers }` — the natural
|
|
38
|
+
guess, docs say `{ source, headers }` — was accepted silently and did nothing,
|
|
39
|
+
so a CSP or X-Frame-Options set there never reached the response. The server
|
|
40
|
+
names the unknown key at startup.
|
|
41
|
+
- **`tw adapter` notice counts SSR pages too.** It reported only `.twm` API
|
|
42
|
+
routes; pages with `render ssr`, `stream`, `csr` or `ppr` cannot be served by a
|
|
43
|
+
static adapter either and are counted now.
|
|
44
|
+
|
|
45
|
+
### Changed
|
|
46
|
+
|
|
47
|
+
- **Raw HTML in a `.tw` file is a build error (`TW123`).** It was never a
|
|
48
|
+
supported form, but it parsed and then had its text rewritten by the class
|
|
49
|
+
shorthand — `one two.` became `<two>`, `mid. sentence` became
|
|
50
|
+
`<mid class="sentence">` — with no diagnostic. Write the element in TW syntax
|
|
51
|
+
(`p { ... }`) instead. `<if>`, `<for>`, `<while>`, `<switch>` and components are
|
|
52
|
+
unaffected.
|
|
53
|
+
|
|
54
|
+
### Docs
|
|
55
|
+
|
|
56
|
+
- `docs/syntax-interpolation.md` documents printing a literal brace (`\{` and
|
|
57
|
+
`\}`), which already worked but was not written down.
|
|
58
|
+
|
|
59
|
+
## [2.0.3]
|
|
60
|
+
|
|
61
|
+
A patch release: bug fixes only, no breaking changes, no public API changes.
|
|
62
|
+
|
|
63
|
+
### Fixed
|
|
64
|
+
|
|
65
|
+
- **Runtime -- hydration no longer discards server-rendered values.** A value
|
|
66
|
+
that comes from a page's `server { }` block is never serialised into
|
|
67
|
+
`__tw_state`, so the client runtime saw it as missing: a `for` loop over such a
|
|
68
|
+
value was emptied, an interpolation reading one was blanked, and an `if`
|
|
69
|
+
testing one was hidden -- after the server had already rendered them correctly.
|
|
70
|
+
An expression that evaluates to `undefined` is now treated as "not client
|
|
71
|
+
state" and the server's markup is left alone. Real client state stays reactive.
|
|
72
|
+
- **`tw dev` -- `strategies.hydration.mode: "none"` is honoured.** The dev server
|
|
73
|
+
injected the hydration runtime unconditionally, so there was no way to look at
|
|
74
|
+
a page without hydration while building it.
|
|
75
|
+
- **CLI -- the `tw-framework` bin alias.** The package declared only a `tw` bin,
|
|
76
|
+
so `bunx tw-framework dev` and a `"build": "tw-framework build"` script both
|
|
77
|
+
failed with "not found" even though the README documents that form. Both names
|
|
78
|
+
resolve to the same entry point now.
|
|
79
|
+
|
|
7
80
|
## [2.0.2]
|
|
8
81
|
|
|
9
82
|
A patch release: bug fixes only. No new features, no breaking changes, and no
|
|
@@ -66,6 +66,8 @@
|
|
|
66
66
|
var el = ifs[i];
|
|
67
67
|
if (ownedByLoop(el)) continue;
|
|
68
68
|
var val = evalExpr(el.getAttribute("data-tw-if"));
|
|
69
|
+
// Not client state (a server { } value): keep the branch the server chose.
|
|
70
|
+
if (val === undefined) continue;
|
|
69
71
|
var show = !!val && val !== "false" && val !== "0" && val !== "";
|
|
70
72
|
el.style.display = show ? "" : "none";
|
|
71
73
|
}
|
|
@@ -74,6 +76,7 @@
|
|
|
74
76
|
var el2 = nots[j];
|
|
75
77
|
if (ownedByLoop(el2)) continue;
|
|
76
78
|
var val2 = evalExpr(el2.getAttribute("data-tw-not"));
|
|
79
|
+
if (val2 === undefined) continue;
|
|
77
80
|
var hide = !!val2 && val2 !== "false" && val2 !== "0" && val2 !== "";
|
|
78
81
|
el2.style.display = hide ? "none" : "";
|
|
79
82
|
}
|
|
@@ -88,7 +91,10 @@
|
|
|
88
91
|
var holder = document.createElement("tw-render");
|
|
89
92
|
holder.innerHTML = tpl;
|
|
90
93
|
var spans = holder.querySelectorAll("[data-tw-i]");
|
|
91
|
-
for (var i = 0; i < spans.length; i++)
|
|
94
|
+
for (var i = 0; i < spans.length; i++) {
|
|
95
|
+
if (evalExpr(spans[i].getAttribute("data-tw-i")) === undefined) continue;
|
|
96
|
+
setSpanText(spans[i], spans[i].getAttribute("data-tw-i"));
|
|
97
|
+
}
|
|
92
98
|
|
|
93
99
|
// Nested if/not inside the loop body (evaluated while loopVar is bound)
|
|
94
100
|
var all = holder.querySelectorAll("*");
|
|
@@ -139,6 +145,10 @@
|
|
|
139
145
|
for (var i = 0; i < loops.length; i++) {
|
|
140
146
|
var el = loops[i];
|
|
141
147
|
var arr = evalExpr(el.getAttribute("data-tw-list"));
|
|
148
|
+
// `undefined` means the name is not client state -- a value a server { }
|
|
149
|
+
// block produced, which is never serialised into __tw_state. Treating it
|
|
150
|
+
// as [] wiped the items the server had already rendered.
|
|
151
|
+
if (arr === undefined) continue;
|
|
142
152
|
var v = el.getAttribute("data-tw-var");
|
|
143
153
|
var tpl = el.getAttribute("data-tw-tpl") || "";
|
|
144
154
|
if (!Array.isArray(arr)) arr = [];
|
|
@@ -182,6 +192,9 @@
|
|
|
182
192
|
// here (with the variable out of scope) blanked the text the build had
|
|
183
193
|
// already produced correctly.
|
|
184
194
|
if (spans[i].closest && spans[i].closest("tw-for")) continue;
|
|
195
|
+
// Same rule: an expression that is not client state leaves the
|
|
196
|
+
// server-rendered text alone instead of blanking it.
|
|
197
|
+
if (evalExpr(spans[i].getAttribute("data-tw-i")) === undefined) continue;
|
|
185
198
|
setSpanText(spans[i], spans[i].getAttribute("data-tw-i"));
|
|
186
199
|
}
|
|
187
200
|
var inputs = document.querySelectorAll("[data-tw-model]");
|
package/dist/testing.cjs
CHANGED
|
@@ -227514,6 +227514,15 @@ function parseElement(cursor, errors, state, parseBody) {
|
|
|
227514
227514
|
const tagToken = cursor.advance();
|
|
227515
227515
|
if (!tagToken) return null;
|
|
227516
227516
|
const tag2 = tagToken.value;
|
|
227517
|
+
if (tag2 && /^[A-Za-z][A-Za-z0-9-]*$/.test(tag2)) {
|
|
227518
|
+
errors.add(new CompilerError(
|
|
227519
|
+
"raw HTML is not supported in .tw -- write it in TW syntax: " + tag2 + " { ... }",
|
|
227520
|
+
tagToken.pos.line,
|
|
227521
|
+
tagToken.pos.col,
|
|
227522
|
+
"TW123",
|
|
227523
|
+
"error"
|
|
227524
|
+
));
|
|
227525
|
+
}
|
|
227517
227526
|
const controlFlowTags = {
|
|
227518
227527
|
"if": "if",
|
|
227519
227528
|
"for": "for",
|
|
@@ -236171,7 +236180,7 @@ var init_types4 = __esm({
|
|
|
236171
236180
|
var TW_VERSION, TW_GENERATOR_META;
|
|
236172
236181
|
var init_version = __esm({
|
|
236173
236182
|
"../../packages/compiler/tw/codegen/version.ts"() {
|
|
236174
|
-
TW_VERSION = "2.0.
|
|
236183
|
+
TW_VERSION = "2.0.4";
|
|
236175
236184
|
TW_GENERATOR_META = `<meta name="generator" content="TW Framework ${TW_VERSION}">`;
|
|
236176
236185
|
}
|
|
236177
236186
|
});
|
|
@@ -243339,6 +243348,15 @@ function generateWithLayout(layoutProgram, pageProgram, stateVars) {
|
|
|
243339
243348
|
function generateWithLayoutChain(layoutPrograms, pageProgram, stateVars) {
|
|
243340
243349
|
const seedCtx = (ctx2) => {
|
|
243341
243350
|
if (stateVars) ctx2.stateVars = { ...stateVars };
|
|
243351
|
+
for (const lp of layoutPrograms ?? []) {
|
|
243352
|
+
for (const dir of lp.directives || []) {
|
|
243353
|
+
if (dir.type === "StateDirective") {
|
|
243354
|
+
for (const decl of dir.declarations || []) {
|
|
243355
|
+
ctx2.stateVars[decl.name] = stateLiteralForRender(decl.value);
|
|
243356
|
+
}
|
|
243357
|
+
}
|
|
243358
|
+
}
|
|
243359
|
+
}
|
|
243342
243360
|
for (const dir of pageProgram.directives || []) {
|
|
243343
243361
|
if (dir.type === "StateDirective") {
|
|
243344
243362
|
for (const decl of dir.declarations || []) {
|
|
@@ -243975,6 +243993,7 @@ var init_codes = __esm({
|
|
|
243975
243993
|
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
243994
|
TW121: { message: "The same name is declared by more than one state { } block (the earlier one wins)", severity: "warning", category: "semantic" },
|
|
243977
243995
|
TW122: { message: "More than one default slot in the same component -- a caller's default content has no defined destination", severity: "warning", category: "semantic" },
|
|
243996
|
+
TW123: { message: "Raw HTML is not supported in .tw -- write the element in TW syntax", severity: "error", category: "syntax" },
|
|
243978
243997
|
// Codes thrown outside the rule engine. TW303 comes from the stylesheet
|
|
243979
243998
|
// parser (codegen/tss.ts); TW000 is the generic fallback used when an error
|
|
243980
243999
|
// carries no code of its own.
|
|
@@ -244649,7 +244668,46 @@ var init_rules = __esm({
|
|
|
244649
244668
|
"noframes",
|
|
244650
244669
|
"area",
|
|
244651
244670
|
"map",
|
|
244652
|
-
"marquee"
|
|
244671
|
+
"marquee",
|
|
244672
|
+
// Inline text tags. `b` and `i` were missing, so breadcrumbs and emphasis
|
|
244673
|
+
// collected a TW003 per tag on markup that renders perfectly well.
|
|
244674
|
+
"b",
|
|
244675
|
+
"i",
|
|
244676
|
+
"em",
|
|
244677
|
+
"strong",
|
|
244678
|
+
"small",
|
|
244679
|
+
"u",
|
|
244680
|
+
"s",
|
|
244681
|
+
"ins",
|
|
244682
|
+
"del",
|
|
244683
|
+
"sub",
|
|
244684
|
+
"sup",
|
|
244685
|
+
"nobr",
|
|
244686
|
+
"big",
|
|
244687
|
+
"tt",
|
|
244688
|
+
// SVG children -- the same warning fired on inline icons.
|
|
244689
|
+
"circle",
|
|
244690
|
+
"path",
|
|
244691
|
+
"rect",
|
|
244692
|
+
"line",
|
|
244693
|
+
"polyline",
|
|
244694
|
+
"polygon",
|
|
244695
|
+
"g",
|
|
244696
|
+
"defs",
|
|
244697
|
+
"use",
|
|
244698
|
+
"text",
|
|
244699
|
+
"ellipse",
|
|
244700
|
+
"tspan",
|
|
244701
|
+
"clippath",
|
|
244702
|
+
"lineargradient",
|
|
244703
|
+
"radialgradient",
|
|
244704
|
+
"stop",
|
|
244705
|
+
"mask",
|
|
244706
|
+
"pattern",
|
|
244707
|
+
"symbol",
|
|
244708
|
+
"marker",
|
|
244709
|
+
"filter",
|
|
244710
|
+
"foreignobject"
|
|
244653
244711
|
]);
|
|
244654
244712
|
HTML_ATTRIBUTES2 = /* @__PURE__ */ new Set([
|
|
244655
244713
|
"accept",
|
|
@@ -257731,6 +257789,32 @@ var init_render_pipeline = __esm({
|
|
|
257731
257789
|
init_tw9();
|
|
257732
257790
|
__profilesCache = null;
|
|
257733
257791
|
RenderPipeline = class {
|
|
257792
|
+
/**
|
|
257793
|
+
* A dynamic route with a sibling `params.twm` is an enumerated route: the
|
|
257794
|
+
* static build only writes the generated slugs, so a static host 404s an
|
|
257795
|
+
* unknown one. The server matched `[slug]` for anything and rendered the
|
|
257796
|
+
* page's fallback branch with status 200, so search engines indexed those as
|
|
257797
|
+
* real pages. Return true when the requested params are not in `generate()`.
|
|
257798
|
+
*/
|
|
257799
|
+
async isUnenumeratedParam(pageFile, params) {
|
|
257800
|
+
if (!/\[[^\]]+\]/.test(pageFile)) return false;
|
|
257801
|
+
const paramsTwm = (0, import_node_path18.dirname)(pageFile) + "/params.twm";
|
|
257802
|
+
if (!(0, import_node_fs11.existsSync)(paramsTwm)) return false;
|
|
257803
|
+
try {
|
|
257804
|
+
const { loadTWMModule: loadTWMModule2 } = await Promise.resolve().then(() => (init_twm_loader(), twm_loader_exports));
|
|
257805
|
+
const pmod = await loadTWMModule2(paramsTwm, this.rootDir);
|
|
257806
|
+
if (typeof pmod?.generate !== "function") return false;
|
|
257807
|
+
const arr2 = await pmod.generate();
|
|
257808
|
+
if (!Array.isArray(arr2) || arr2.length === 0) return false;
|
|
257809
|
+
const keys = Object.keys(params);
|
|
257810
|
+
if (keys.length === 0) return false;
|
|
257811
|
+
const sets = arr2.map((x) => x && typeof x === "object" ? x : { [keys[0]]: String(x) });
|
|
257812
|
+
const found = sets.some((set) => keys.every((k) => String(set[k] ?? "") === String(params[k] ?? "")));
|
|
257813
|
+
return !found;
|
|
257814
|
+
} catch {
|
|
257815
|
+
return false;
|
|
257816
|
+
}
|
|
257817
|
+
}
|
|
257734
257818
|
rootDir;
|
|
257735
257819
|
homeDir;
|
|
257736
257820
|
enableCache;
|
|
@@ -257834,6 +257918,17 @@ var init_render_pipeline = __esm({
|
|
|
257834
257918
|
const ctx = match ? resolveLayoutChain2(match) : null;
|
|
257835
257919
|
const pageFile = ctx?.page?.absolutePath;
|
|
257836
257920
|
if (!pageFile) return this.render(pathname);
|
|
257921
|
+
try {
|
|
257922
|
+
if (await this.isUnenumeratedParam(pageFile, match?.params ?? {})) {
|
|
257923
|
+
this.__forceNotFound = true;
|
|
257924
|
+
try {
|
|
257925
|
+
return this.render(pathname);
|
|
257926
|
+
} finally {
|
|
257927
|
+
this.__forceNotFound = false;
|
|
257928
|
+
}
|
|
257929
|
+
}
|
|
257930
|
+
} catch {
|
|
257931
|
+
}
|
|
257837
257932
|
let blocks = [];
|
|
257838
257933
|
let src = "";
|
|
257839
257934
|
try {
|
|
@@ -258109,7 +258204,7 @@ var init_render_pipeline = __esm({
|
|
|
258109
258204
|
if (!tree) {
|
|
258110
258205
|
return this.renderError("home/ directory not found", 500, startTime);
|
|
258111
258206
|
}
|
|
258112
|
-
const match = matchRoute(tree, pathname);
|
|
258207
|
+
const match = this.__forceNotFound ? null : matchRoute(tree, pathname);
|
|
258113
258208
|
if (!match) {
|
|
258114
258209
|
const rootNotFound = findNearestNotFound(tree, pathname.split("/").filter(Boolean));
|
|
258115
258210
|
if (rootNotFound) {
|
|
@@ -271709,6 +271804,19 @@ var init_tw9 = __esm({
|
|
|
271709
271804
|
const entries = Object.entries(cfgIn.rewrites);
|
|
271710
271805
|
cfgIn.rewrites = entries.map(([from, to]) => typeof to === "string" ? { from, to } : { from, ...to });
|
|
271711
271806
|
}
|
|
271807
|
+
if (Array.isArray(cfgIn.headers)) {
|
|
271808
|
+
const HEADER_ENTRY_KEYS = /* @__PURE__ */ new Set(["source", "headers"]);
|
|
271809
|
+
for (const h3 of cfgIn.headers) {
|
|
271810
|
+
if (!h3 || typeof h3 !== "object") continue;
|
|
271811
|
+
const unknown = Object.keys(h3).filter((k) => !HEADER_ENTRY_KEYS.has(k));
|
|
271812
|
+
if (unknown.length > 0) {
|
|
271813
|
+
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'?)" : ""));
|
|
271814
|
+
}
|
|
271815
|
+
if (h3.source === void 0 && h3.path !== void 0) {
|
|
271816
|
+
console.warn("[tw] headers: entry uses 'path' instead of 'source' -- it will not be applied");
|
|
271817
|
+
}
|
|
271818
|
+
}
|
|
271819
|
+
}
|
|
271712
271820
|
for (const h3 of cfgIn.headers ?? []) {
|
|
271713
271821
|
if (h3?.headers && typeof h3.headers === "object") {
|
|
271714
271822
|
for (const k of Object.keys(h3.headers)) {
|
package/dist/tw-server.mjs
CHANGED
|
@@ -228585,6 +228585,15 @@ function parseElement(cursor, errors, state, parseBody) {
|
|
|
228585
228585
|
const tagToken = cursor.advance();
|
|
228586
228586
|
if (!tagToken) return null;
|
|
228587
228587
|
const tag2 = tagToken.value;
|
|
228588
|
+
if (tag2 && /^[A-Za-z][A-Za-z0-9-]*$/.test(tag2)) {
|
|
228589
|
+
errors.add(new CompilerError(
|
|
228590
|
+
"raw HTML is not supported in .tw -- write it in TW syntax: " + tag2 + " { ... }",
|
|
228591
|
+
tagToken.pos.line,
|
|
228592
|
+
tagToken.pos.col,
|
|
228593
|
+
"TW123",
|
|
228594
|
+
"error"
|
|
228595
|
+
));
|
|
228596
|
+
}
|
|
228588
228597
|
const controlFlowTags = {
|
|
228589
228598
|
"if": "if",
|
|
228590
228599
|
"for": "for",
|
|
@@ -237242,7 +237251,7 @@ var init_types4 = __esm({
|
|
|
237242
237251
|
var TW_VERSION, TW_GENERATOR_META;
|
|
237243
237252
|
var init_version = __esm({
|
|
237244
237253
|
"../../packages/compiler/tw/codegen/version.ts"() {
|
|
237245
|
-
TW_VERSION = "2.0.
|
|
237254
|
+
TW_VERSION = "2.0.4";
|
|
237246
237255
|
TW_GENERATOR_META = `<meta name="generator" content="TW Framework ${TW_VERSION}">`;
|
|
237247
237256
|
}
|
|
237248
237257
|
});
|
|
@@ -244094,6 +244103,15 @@ function generateWithLayout(layoutProgram, pageProgram, stateVars) {
|
|
|
244094
244103
|
function generateWithLayoutChain(layoutPrograms, pageProgram, stateVars) {
|
|
244095
244104
|
const seedCtx = (ctx2) => {
|
|
244096
244105
|
if (stateVars) ctx2.stateVars = { ...stateVars };
|
|
244106
|
+
for (const lp of layoutPrograms ?? []) {
|
|
244107
|
+
for (const dir of lp.directives || []) {
|
|
244108
|
+
if (dir.type === "StateDirective") {
|
|
244109
|
+
for (const decl of dir.declarations || []) {
|
|
244110
|
+
ctx2.stateVars[decl.name] = stateLiteralForRender(decl.value);
|
|
244111
|
+
}
|
|
244112
|
+
}
|
|
244113
|
+
}
|
|
244114
|
+
}
|
|
244097
244115
|
for (const dir of pageProgram.directives || []) {
|
|
244098
244116
|
if (dir.type === "StateDirective") {
|
|
244099
244117
|
for (const decl of dir.declarations || []) {
|
|
@@ -244729,6 +244747,7 @@ var init_codes = __esm({
|
|
|
244729
244747
|
TW119: { message: "A deferred server block cannot be used on a cached page -- cache { } serves one HTML to every request", severity: "error", category: "semantic" },
|
|
244730
244748
|
TW121: { message: "The same name is declared by more than one state { } block (the earlier one wins)", severity: "warning", category: "semantic" },
|
|
244731
244749
|
TW122: { message: "More than one default slot in the same component -- a caller's default content has no defined destination", severity: "warning", category: "semantic" },
|
|
244750
|
+
TW123: { message: "Raw HTML is not supported in .tw -- write the element in TW syntax", severity: "error", category: "syntax" },
|
|
244732
244751
|
// Codes thrown outside the rule engine. TW303 comes from the stylesheet
|
|
244733
244752
|
// parser (codegen/tss.ts); TW000 is the generic fallback used when an error
|
|
244734
244753
|
// carries no code of its own.
|
|
@@ -245403,7 +245422,46 @@ var init_rules = __esm({
|
|
|
245403
245422
|
"noframes",
|
|
245404
245423
|
"area",
|
|
245405
245424
|
"map",
|
|
245406
|
-
"marquee"
|
|
245425
|
+
"marquee",
|
|
245426
|
+
// Inline text tags. `b` and `i` were missing, so breadcrumbs and emphasis
|
|
245427
|
+
// collected a TW003 per tag on markup that renders perfectly well.
|
|
245428
|
+
"b",
|
|
245429
|
+
"i",
|
|
245430
|
+
"em",
|
|
245431
|
+
"strong",
|
|
245432
|
+
"small",
|
|
245433
|
+
"u",
|
|
245434
|
+
"s",
|
|
245435
|
+
"ins",
|
|
245436
|
+
"del",
|
|
245437
|
+
"sub",
|
|
245438
|
+
"sup",
|
|
245439
|
+
"nobr",
|
|
245440
|
+
"big",
|
|
245441
|
+
"tt",
|
|
245442
|
+
// SVG children -- the same warning fired on inline icons.
|
|
245443
|
+
"circle",
|
|
245444
|
+
"path",
|
|
245445
|
+
"rect",
|
|
245446
|
+
"line",
|
|
245447
|
+
"polyline",
|
|
245448
|
+
"polygon",
|
|
245449
|
+
"g",
|
|
245450
|
+
"defs",
|
|
245451
|
+
"use",
|
|
245452
|
+
"text",
|
|
245453
|
+
"ellipse",
|
|
245454
|
+
"tspan",
|
|
245455
|
+
"clippath",
|
|
245456
|
+
"lineargradient",
|
|
245457
|
+
"radialgradient",
|
|
245458
|
+
"stop",
|
|
245459
|
+
"mask",
|
|
245460
|
+
"pattern",
|
|
245461
|
+
"symbol",
|
|
245462
|
+
"marker",
|
|
245463
|
+
"filter",
|
|
245464
|
+
"foreignobject"
|
|
245407
245465
|
]);
|
|
245408
245466
|
HTML_ATTRIBUTES2 = /* @__PURE__ */ new Set([
|
|
245409
245467
|
"accept",
|
|
@@ -282070,6 +282128,32 @@ var init_render_pipeline = __esm({
|
|
|
282070
282128
|
init_tw10();
|
|
282071
282129
|
__profilesCache = null;
|
|
282072
282130
|
RenderPipeline = class {
|
|
282131
|
+
/**
|
|
282132
|
+
* A dynamic route with a sibling `params.twm` is an enumerated route: the
|
|
282133
|
+
* static build only writes the generated slugs, so a static host 404s an
|
|
282134
|
+
* unknown one. The server matched `[slug]` for anything and rendered the
|
|
282135
|
+
* page's fallback branch with status 200, so search engines indexed those as
|
|
282136
|
+
* real pages. Return true when the requested params are not in `generate()`.
|
|
282137
|
+
*/
|
|
282138
|
+
async isUnenumeratedParam(pageFile, params) {
|
|
282139
|
+
if (!/\[[^\]]+\]/.test(pageFile)) return false;
|
|
282140
|
+
const paramsTwm = dirname8(pageFile) + "/params.twm";
|
|
282141
|
+
if (!existsSync13(paramsTwm)) return false;
|
|
282142
|
+
try {
|
|
282143
|
+
const { loadTWMModule: loadTWMModule2 } = await Promise.resolve().then(() => (init_twm_loader(), twm_loader_exports));
|
|
282144
|
+
const pmod = await loadTWMModule2(paramsTwm, this.rootDir);
|
|
282145
|
+
if (typeof pmod?.generate !== "function") return false;
|
|
282146
|
+
const arr2 = await pmod.generate();
|
|
282147
|
+
if (!Array.isArray(arr2) || arr2.length === 0) return false;
|
|
282148
|
+
const keys = Object.keys(params);
|
|
282149
|
+
if (keys.length === 0) return false;
|
|
282150
|
+
const sets = arr2.map((x) => x && typeof x === "object" ? x : { [keys[0]]: String(x) });
|
|
282151
|
+
const found = sets.some((set) => keys.every((k) => String(set[k] ?? "") === String(params[k] ?? "")));
|
|
282152
|
+
return !found;
|
|
282153
|
+
} catch {
|
|
282154
|
+
return false;
|
|
282155
|
+
}
|
|
282156
|
+
}
|
|
282073
282157
|
rootDir;
|
|
282074
282158
|
homeDir;
|
|
282075
282159
|
enableCache;
|
|
@@ -282173,6 +282257,17 @@ var init_render_pipeline = __esm({
|
|
|
282173
282257
|
const ctx = match ? resolveLayoutChain(match) : null;
|
|
282174
282258
|
const pageFile = ctx?.page?.absolutePath;
|
|
282175
282259
|
if (!pageFile) return this.render(pathname);
|
|
282260
|
+
try {
|
|
282261
|
+
if (await this.isUnenumeratedParam(pageFile, match?.params ?? {})) {
|
|
282262
|
+
this.__forceNotFound = true;
|
|
282263
|
+
try {
|
|
282264
|
+
return this.render(pathname);
|
|
282265
|
+
} finally {
|
|
282266
|
+
this.__forceNotFound = false;
|
|
282267
|
+
}
|
|
282268
|
+
}
|
|
282269
|
+
} catch {
|
|
282270
|
+
}
|
|
282176
282271
|
let blocks = [];
|
|
282177
282272
|
let src = "";
|
|
282178
282273
|
try {
|
|
@@ -282448,7 +282543,7 @@ var init_render_pipeline = __esm({
|
|
|
282448
282543
|
if (!tree) {
|
|
282449
282544
|
return this.renderError("home/ directory not found", 500, startTime);
|
|
282450
282545
|
}
|
|
282451
|
-
const match = matchRoute2(tree, pathname);
|
|
282546
|
+
const match = this.__forceNotFound ? null : matchRoute2(tree, pathname);
|
|
282452
282547
|
if (!match) {
|
|
282453
282548
|
const rootNotFound = findNearestNotFound(tree, pathname.split("/").filter(Boolean));
|
|
282454
282549
|
if (rootNotFound) {
|
|
@@ -287073,6 +287168,19 @@ var init_tw10 = __esm({
|
|
|
287073
287168
|
const entries = Object.entries(cfgIn.rewrites);
|
|
287074
287169
|
cfgIn.rewrites = entries.map(([from, to]) => typeof to === "string" ? { from, to } : { from, ...to });
|
|
287075
287170
|
}
|
|
287171
|
+
if (Array.isArray(cfgIn.headers)) {
|
|
287172
|
+
const HEADER_ENTRY_KEYS = /* @__PURE__ */ new Set(["source", "headers"]);
|
|
287173
|
+
for (const h3 of cfgIn.headers) {
|
|
287174
|
+
if (!h3 || typeof h3 !== "object") continue;
|
|
287175
|
+
const unknown = Object.keys(h3).filter((k) => !HEADER_ENTRY_KEYS.has(k));
|
|
287176
|
+
if (unknown.length > 0) {
|
|
287177
|
+
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'?)" : ""));
|
|
287178
|
+
}
|
|
287179
|
+
if (h3.source === void 0 && h3.path !== void 0) {
|
|
287180
|
+
console.warn("[tw] headers: entry uses 'path' instead of 'source' -- it will not be applied");
|
|
287181
|
+
}
|
|
287182
|
+
}
|
|
287183
|
+
}
|
|
287076
287184
|
for (const h3 of cfgIn.headers ?? []) {
|
|
287077
287185
|
if (h3?.headers && typeof h3.headers === "object") {
|
|
287078
287186
|
for (const k of Object.keys(h3.headers)) {
|
package/dist/tw.mjs
CHANGED
|
@@ -227670,6 +227670,15 @@ function parseElement(cursor, errors, state, parseBody) {
|
|
|
227670
227670
|
const tagToken = cursor.advance();
|
|
227671
227671
|
if (!tagToken) return null;
|
|
227672
227672
|
const tag2 = tagToken.value;
|
|
227673
|
+
if (tag2 && /^[A-Za-z][A-Za-z0-9-]*$/.test(tag2)) {
|
|
227674
|
+
errors.add(new CompilerError(
|
|
227675
|
+
"raw HTML is not supported in .tw -- write it in TW syntax: " + tag2 + " { ... }",
|
|
227676
|
+
tagToken.pos.line,
|
|
227677
|
+
tagToken.pos.col,
|
|
227678
|
+
"TW123",
|
|
227679
|
+
"error"
|
|
227680
|
+
));
|
|
227681
|
+
}
|
|
227673
227682
|
const controlFlowTags = {
|
|
227674
227683
|
"if": "if",
|
|
227675
227684
|
"for": "for",
|
|
@@ -236327,7 +236336,7 @@ var init_types4 = __esm({
|
|
|
236327
236336
|
var TW_VERSION, TW_GENERATOR_META;
|
|
236328
236337
|
var init_version = __esm({
|
|
236329
236338
|
"../../packages/compiler/tw/codegen/version.ts"() {
|
|
236330
|
-
TW_VERSION = "2.0.
|
|
236339
|
+
TW_VERSION = "2.0.4";
|
|
236331
236340
|
TW_GENERATOR_META = `<meta name="generator" content="TW Framework ${TW_VERSION}">`;
|
|
236332
236341
|
}
|
|
236333
236342
|
});
|
|
@@ -243502,6 +243511,15 @@ function generateWithLayout(layoutProgram, pageProgram, stateVars) {
|
|
|
243502
243511
|
function generateWithLayoutChain(layoutPrograms, pageProgram, stateVars) {
|
|
243503
243512
|
const seedCtx = (ctx2) => {
|
|
243504
243513
|
if (stateVars) ctx2.stateVars = { ...stateVars };
|
|
243514
|
+
for (const lp of layoutPrograms ?? []) {
|
|
243515
|
+
for (const dir of lp.directives || []) {
|
|
243516
|
+
if (dir.type === "StateDirective") {
|
|
243517
|
+
for (const decl of dir.declarations || []) {
|
|
243518
|
+
ctx2.stateVars[decl.name] = stateLiteralForRender(decl.value);
|
|
243519
|
+
}
|
|
243520
|
+
}
|
|
243521
|
+
}
|
|
243522
|
+
}
|
|
243505
243523
|
for (const dir of pageProgram.directives || []) {
|
|
243506
243524
|
if (dir.type === "StateDirective") {
|
|
243507
243525
|
for (const decl of dir.declarations || []) {
|
|
@@ -244137,6 +244155,7 @@ var init_codes = __esm({
|
|
|
244137
244155
|
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
244156
|
TW121: { message: "The same name is declared by more than one state { } block (the earlier one wins)", severity: "warning", category: "semantic" },
|
|
244139
244157
|
TW122: { message: "More than one default slot in the same component -- a caller's default content has no defined destination", severity: "warning", category: "semantic" },
|
|
244158
|
+
TW123: { message: "Raw HTML is not supported in .tw -- write the element in TW syntax", severity: "error", category: "syntax" },
|
|
244140
244159
|
// Codes thrown outside the rule engine. TW303 comes from the stylesheet
|
|
244141
244160
|
// parser (codegen/tss.ts); TW000 is the generic fallback used when an error
|
|
244142
244161
|
// carries no code of its own.
|
|
@@ -244811,7 +244830,46 @@ var init_rules = __esm({
|
|
|
244811
244830
|
"noframes",
|
|
244812
244831
|
"area",
|
|
244813
244832
|
"map",
|
|
244814
|
-
"marquee"
|
|
244833
|
+
"marquee",
|
|
244834
|
+
// Inline text tags. `b` and `i` were missing, so breadcrumbs and emphasis
|
|
244835
|
+
// collected a TW003 per tag on markup that renders perfectly well.
|
|
244836
|
+
"b",
|
|
244837
|
+
"i",
|
|
244838
|
+
"em",
|
|
244839
|
+
"strong",
|
|
244840
|
+
"small",
|
|
244841
|
+
"u",
|
|
244842
|
+
"s",
|
|
244843
|
+
"ins",
|
|
244844
|
+
"del",
|
|
244845
|
+
"sub",
|
|
244846
|
+
"sup",
|
|
244847
|
+
"nobr",
|
|
244848
|
+
"big",
|
|
244849
|
+
"tt",
|
|
244850
|
+
// SVG children -- the same warning fired on inline icons.
|
|
244851
|
+
"circle",
|
|
244852
|
+
"path",
|
|
244853
|
+
"rect",
|
|
244854
|
+
"line",
|
|
244855
|
+
"polyline",
|
|
244856
|
+
"polygon",
|
|
244857
|
+
"g",
|
|
244858
|
+
"defs",
|
|
244859
|
+
"use",
|
|
244860
|
+
"text",
|
|
244861
|
+
"ellipse",
|
|
244862
|
+
"tspan",
|
|
244863
|
+
"clippath",
|
|
244864
|
+
"lineargradient",
|
|
244865
|
+
"radialgradient",
|
|
244866
|
+
"stop",
|
|
244867
|
+
"mask",
|
|
244868
|
+
"pattern",
|
|
244869
|
+
"symbol",
|
|
244870
|
+
"marker",
|
|
244871
|
+
"filter",
|
|
244872
|
+
"foreignobject"
|
|
244815
244873
|
]);
|
|
244816
244874
|
HTML_ATTRIBUTES2 = /* @__PURE__ */ new Set([
|
|
244817
244875
|
"accept",
|
|
@@ -259560,6 +259618,32 @@ var init_render_pipeline = __esm({
|
|
|
259560
259618
|
init_tw10();
|
|
259561
259619
|
__profilesCache = null;
|
|
259562
259620
|
RenderPipeline = class {
|
|
259621
|
+
/**
|
|
259622
|
+
* A dynamic route with a sibling `params.twm` is an enumerated route: the
|
|
259623
|
+
* static build only writes the generated slugs, so a static host 404s an
|
|
259624
|
+
* unknown one. The server matched `[slug]` for anything and rendered the
|
|
259625
|
+
* page's fallback branch with status 200, so search engines indexed those as
|
|
259626
|
+
* real pages. Return true when the requested params are not in `generate()`.
|
|
259627
|
+
*/
|
|
259628
|
+
async isUnenumeratedParam(pageFile, params) {
|
|
259629
|
+
if (!/\[[^\]]+\]/.test(pageFile)) return false;
|
|
259630
|
+
const paramsTwm = dirname11(pageFile) + "/params.twm";
|
|
259631
|
+
if (!existsSync19(paramsTwm)) return false;
|
|
259632
|
+
try {
|
|
259633
|
+
const { loadTWMModule: loadTWMModule2 } = await Promise.resolve().then(() => (init_twm_loader(), twm_loader_exports));
|
|
259634
|
+
const pmod = await loadTWMModule2(paramsTwm, this.rootDir);
|
|
259635
|
+
if (typeof pmod?.generate !== "function") return false;
|
|
259636
|
+
const arr2 = await pmod.generate();
|
|
259637
|
+
if (!Array.isArray(arr2) || arr2.length === 0) return false;
|
|
259638
|
+
const keys = Object.keys(params);
|
|
259639
|
+
if (keys.length === 0) return false;
|
|
259640
|
+
const sets = arr2.map((x) => x && typeof x === "object" ? x : { [keys[0]]: String(x) });
|
|
259641
|
+
const found = sets.some((set) => keys.every((k) => String(set[k] ?? "") === String(params[k] ?? "")));
|
|
259642
|
+
return !found;
|
|
259643
|
+
} catch {
|
|
259644
|
+
return false;
|
|
259645
|
+
}
|
|
259646
|
+
}
|
|
259563
259647
|
rootDir;
|
|
259564
259648
|
homeDir;
|
|
259565
259649
|
enableCache;
|
|
@@ -259663,6 +259747,17 @@ var init_render_pipeline = __esm({
|
|
|
259663
259747
|
const ctx = match ? resolveLayoutChain2(match) : null;
|
|
259664
259748
|
const pageFile = ctx?.page?.absolutePath;
|
|
259665
259749
|
if (!pageFile) return this.render(pathname);
|
|
259750
|
+
try {
|
|
259751
|
+
if (await this.isUnenumeratedParam(pageFile, match?.params ?? {})) {
|
|
259752
|
+
this.__forceNotFound = true;
|
|
259753
|
+
try {
|
|
259754
|
+
return this.render(pathname);
|
|
259755
|
+
} finally {
|
|
259756
|
+
this.__forceNotFound = false;
|
|
259757
|
+
}
|
|
259758
|
+
}
|
|
259759
|
+
} catch {
|
|
259760
|
+
}
|
|
259666
259761
|
let blocks = [];
|
|
259667
259762
|
let src = "";
|
|
259668
259763
|
try {
|
|
@@ -259938,7 +260033,7 @@ var init_render_pipeline = __esm({
|
|
|
259938
260033
|
if (!tree) {
|
|
259939
260034
|
return this.renderError("home/ directory not found", 500, startTime);
|
|
259940
260035
|
}
|
|
259941
|
-
const match = matchRoute(tree, pathname);
|
|
260036
|
+
const match = this.__forceNotFound ? null : matchRoute(tree, pathname);
|
|
259942
260037
|
if (!match) {
|
|
259943
260038
|
const rootNotFound = findNearestNotFound(tree, pathname.split("/").filter(Boolean));
|
|
259944
260039
|
if (rootNotFound) {
|
|
@@ -260186,11 +260281,11 @@ ${bodyHTML}`;
|
|
|
260186
260281
|
if (this.__compsRegistered) return;
|
|
260187
260282
|
this.__compsRegistered = true;
|
|
260188
260283
|
try {
|
|
260189
|
-
const { readdirSync:
|
|
260284
|
+
const { readdirSync: readdirSync15 } = __require("node:fs");
|
|
260190
260285
|
const { join: join44 } = __require("node:path");
|
|
260191
260286
|
const dir = join44(this.rootDir, "components");
|
|
260192
260287
|
if (!__require("node:fs").existsSync(dir)) return;
|
|
260193
|
-
for (const f of
|
|
260288
|
+
for (const f of readdirSync15(dir).filter((f2) => f2.endsWith(".tw"))) {
|
|
260194
260289
|
try {
|
|
260195
260290
|
const src = __require("node:fs").readFileSync(join44(dir, f), "utf-8");
|
|
260196
260291
|
const r = compileSync(src, { filePath: join44(dir, f), transforms: false, optimize: false, diagnostics: false });
|
|
@@ -273538,6 +273633,19 @@ var init_tw10 = __esm({
|
|
|
273538
273633
|
const entries = Object.entries(cfgIn.rewrites);
|
|
273539
273634
|
cfgIn.rewrites = entries.map(([from, to]) => typeof to === "string" ? { from, to } : { from, ...to });
|
|
273540
273635
|
}
|
|
273636
|
+
if (Array.isArray(cfgIn.headers)) {
|
|
273637
|
+
const HEADER_ENTRY_KEYS = /* @__PURE__ */ new Set(["source", "headers"]);
|
|
273638
|
+
for (const h3 of cfgIn.headers) {
|
|
273639
|
+
if (!h3 || typeof h3 !== "object") continue;
|
|
273640
|
+
const unknown = Object.keys(h3).filter((k) => !HEADER_ENTRY_KEYS.has(k));
|
|
273641
|
+
if (unknown.length > 0) {
|
|
273642
|
+
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'?)" : ""));
|
|
273643
|
+
}
|
|
273644
|
+
if (h3.source === void 0 && h3.path !== void 0) {
|
|
273645
|
+
console.warn("[tw] headers: entry uses 'path' instead of 'source' -- it will not be applied");
|
|
273646
|
+
}
|
|
273647
|
+
}
|
|
273648
|
+
}
|
|
273541
273649
|
for (const h3 of cfgIn.headers ?? []) {
|
|
273542
273650
|
if (h3?.headers && typeof h3.headers === "object") {
|
|
273543
273651
|
for (const k of Object.keys(h3.headers)) {
|
|
@@ -291787,7 +291895,7 @@ __export(node_test_runner_exports, {
|
|
|
291787
291895
|
runNodeTests: () => runNodeTests
|
|
291788
291896
|
});
|
|
291789
291897
|
import { join as join36 } from "node:path";
|
|
291790
|
-
import { mkdirSync as mkdirSync10, writeFileSync as writeFileSync12, readFileSync as
|
|
291898
|
+
import { mkdirSync as mkdirSync10, writeFileSync as writeFileSync12, readFileSync as readFileSync23 } from "node:fs";
|
|
291791
291899
|
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
291792
291900
|
async function runNodeTests(files, rootDir) {
|
|
291793
291901
|
const cacheDir = join36(rootDir, ".tw", ".tests");
|
|
@@ -291810,13 +291918,13 @@ async function runNodeTests(files, rootDir) {
|
|
|
291810
291918
|
const outPath = join36(cacheDir, basename3(f).replace(/\.(ts|tsx|js)$/, ".cjs"));
|
|
291811
291919
|
const adapterPath = join36(cacheDir, "node-adapter.ts");
|
|
291812
291920
|
try {
|
|
291813
|
-
writeFileSync12(adapterPath,
|
|
291921
|
+
writeFileSync12(adapterPath, readFileSync23(join36(new URL(".", import.meta.url).pathname, "node-adapter.ts"), "utf-8"));
|
|
291814
291922
|
} catch {
|
|
291815
291923
|
const bd = globalThis.__TW_BUNDLE_DIR;
|
|
291816
291924
|
const src = bd ? join36(bd, "..", "tw", "node-adapter.ts") : "";
|
|
291817
291925
|
if (src) {
|
|
291818
291926
|
try {
|
|
291819
|
-
writeFileSync12(adapterPath,
|
|
291927
|
+
writeFileSync12(adapterPath, readFileSync23(src, "utf-8"));
|
|
291820
291928
|
} catch {
|
|
291821
291929
|
}
|
|
291822
291930
|
}
|
|
@@ -291866,7 +291974,7 @@ async function runNodeTests(files, rootDir) {
|
|
|
291866
291974
|
}
|
|
291867
291975
|
const childEnv = { ...process.env };
|
|
291868
291976
|
try {
|
|
291869
|
-
const envFile =
|
|
291977
|
+
const envFile = readFileSync23(join36(rootDir, ".env"), "utf-8");
|
|
291870
291978
|
for (const line of envFile.split("\n")) {
|
|
291871
291979
|
const m = line.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/);
|
|
291872
291980
|
if (m && !(m[1] in childEnv)) childEnv[m[1]] = m[2].replace(/^["']|["']$/g, "");
|
|
@@ -294675,7 +294783,7 @@ async function createPackageJson(dir, name) {
|
|
|
294675
294783
|
ship: "tw ship"
|
|
294676
294784
|
},
|
|
294677
294785
|
dependencies: {
|
|
294678
|
-
"tw-framework": "^2.0.
|
|
294786
|
+
"tw-framework": "^2.0.4"
|
|
294679
294787
|
},
|
|
294680
294788
|
devDependencies: {
|
|
294681
294789
|
typescript: "^5.4.0",
|
|
@@ -294762,7 +294870,7 @@ dist/
|
|
|
294762
294870
|
async function createReadme(dir, name) {
|
|
294763
294871
|
const content = `# ${name}
|
|
294764
294872
|
|
|
294765
|
-
Built with TW Framework 2.0.
|
|
294873
|
+
Built with TW Framework 2.0.4.
|
|
294766
294874
|
|
|
294767
294875
|
## Getting Started
|
|
294768
294876
|
|
|
@@ -296199,6 +296307,7 @@ async function devCommand() {
|
|
|
296199
296307
|
let devRewrites = [];
|
|
296200
296308
|
let devSigCfg = void 0;
|
|
296201
296309
|
let devApiDir = "api";
|
|
296310
|
+
let devHydrationOff = false;
|
|
296202
296311
|
let devSignalTransport = "sse";
|
|
296203
296312
|
try {
|
|
296204
296313
|
const cfgFile = join31(rootDir, "tw.config.ts");
|
|
@@ -296222,6 +296331,7 @@ async function devCommand() {
|
|
|
296222
296331
|
if (cfg?.headers) {
|
|
296223
296332
|
devCfgHeaders = Array.isArray(cfg.headers) ? cfg.headers : Object.entries(cfg.headers).map(([source, headers]) => ({ source, headers }));
|
|
296224
296333
|
}
|
|
296334
|
+
if (cfg?.strategies?.hydration?.mode === "none") devHydrationOff = true;
|
|
296225
296335
|
const st = cfg?.strategies?.signals?.transport;
|
|
296226
296336
|
if (st === "sse" || st === "ws" || st === "long-poll") devSignalTransport = st;
|
|
296227
296337
|
if (cfg?.signalStream) devSigCfg = cfg.signalStream;
|
|
@@ -296302,7 +296412,11 @@ async function devCommand() {
|
|
|
296302
296412
|
if (existsSync27(publicDir)) {
|
|
296303
296413
|
const publicFile = join31(publicDir, path);
|
|
296304
296414
|
const pubFile = Bun.file(publicFile);
|
|
296305
|
-
if (await pubFile.exists())
|
|
296415
|
+
if (await pubFile.exists()) {
|
|
296416
|
+
return new Response(pubFile, {
|
|
296417
|
+
headers: { "Content-Type": pubFile.type || "application/octet-stream" }
|
|
296418
|
+
});
|
|
296419
|
+
}
|
|
296306
296420
|
}
|
|
296307
296421
|
if (path === "/placeholder.png" || path.endsWith(".png")) {
|
|
296308
296422
|
return new Response(PLACEHOLDER_PNG, { headers: { "Content-Type": "image/png" } });
|
|
@@ -296454,14 +296568,19 @@ async function devCommand() {
|
|
|
296454
296568
|
try {
|
|
296455
296569
|
const source = readFileSync19(twFile, "utf-8");
|
|
296456
296570
|
if (typeof beginCssRouteCapture2 === "function") beginCssRouteCapture2(path);
|
|
296457
|
-
let result = compileSync3(source, { filePath: twFile, stateVars: resolved.params });
|
|
296571
|
+
let result = compileSync3(source, { filePath: twFile, stateVars: resolved.params, experimental: { serverBlocks: true } });
|
|
296458
296572
|
try {
|
|
296459
296573
|
const _c = await Promise.resolve().then(() => (init_tw7(), tw_exports3));
|
|
296460
296574
|
const blocks = _c.collectServerBlocks(result.ast);
|
|
296461
296575
|
if (blocks.length) {
|
|
296462
296576
|
const values = await _c.executeServerBlocks(blocks.filter((b) => !b.deferred), { label: twFile });
|
|
296463
296577
|
if (values && Object.keys(values).length) {
|
|
296464
|
-
|
|
296578
|
+
const merged = {
|
|
296579
|
+
...resolved.params ?? {},
|
|
296580
|
+
params: resolved.params ?? {},
|
|
296581
|
+
..._c.encodeServerValues(values)
|
|
296582
|
+
};
|
|
296583
|
+
result = compileSync3(source, { filePath: twFile, stateVars: merged, experimental: { serverBlocks: true } });
|
|
296465
296584
|
}
|
|
296466
296585
|
}
|
|
296467
296586
|
} catch (e) {
|
|
@@ -296533,7 +296652,8 @@ async function devCommand() {
|
|
|
296533
296652
|
`;
|
|
296534
296653
|
}
|
|
296535
296654
|
if (/<\/body>/.test(html)) {
|
|
296536
|
-
|
|
296655
|
+
const runtimeTag = devHydrationOff ? "" : ' <script src="/__tw_runtime.js"></script>\n';
|
|
296656
|
+
html = html.replace("</body>", devClientTag + (devOpts?.overlay === false ? "" : CLIENT_OVERLAY_SCRIPT) + runtimeTag + "</body>");
|
|
296537
296657
|
}
|
|
296538
296658
|
const devGlobalHead = join31(homeDir, "head.tw");
|
|
296539
296659
|
const devHeadSources = [];
|
|
@@ -296869,8 +296989,8 @@ async function serveCommand() {
|
|
|
296869
296989
|
const envPath = join32(rootDir, ".env");
|
|
296870
296990
|
if (existsSync28(envPath)) {
|
|
296871
296991
|
try {
|
|
296872
|
-
const { readFileSync:
|
|
296873
|
-
for (const line of
|
|
296992
|
+
const { readFileSync: readFileSync29 } = await import("node:fs");
|
|
296993
|
+
for (const line of readFileSync29(envPath, "utf-8").split("\n")) {
|
|
296874
296994
|
const m = /^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/.exec(line);
|
|
296875
296995
|
if (m && !(m[1] in process.env)) {
|
|
296876
296996
|
process.env[m[1]] = m[2].replace(/^["']|["']$/g, "");
|
|
@@ -297226,8 +297346,8 @@ CMD ["bunx", "tw", "serve"]`;
|
|
|
297226
297346
|
}
|
|
297227
297347
|
|
|
297228
297348
|
// tw/commands/adapter.ts
|
|
297229
|
-
import { resolve as resolve11 } from "node:path";
|
|
297230
|
-
import { existsSync as existsSync31 } from "node:fs";
|
|
297349
|
+
import { join as join35, resolve as resolve11 } from "node:path";
|
|
297350
|
+
import { existsSync as existsSync31, readdirSync as readdirSync11, readFileSync as readFileSync22 } from "node:fs";
|
|
297231
297351
|
async function adapterCommand() {
|
|
297232
297352
|
const args = process.argv.slice(3);
|
|
297233
297353
|
const rootDir = process.cwd();
|
|
@@ -297274,6 +297394,58 @@ async function adapterCommand() {
|
|
|
297274
297394
|
`);
|
|
297275
297395
|
process.exit(1);
|
|
297276
297396
|
}
|
|
297397
|
+
const STATIC_ONLY = /* @__PURE__ */ new Set([
|
|
297398
|
+
"node",
|
|
297399
|
+
"deno",
|
|
297400
|
+
"cloudflare",
|
|
297401
|
+
"netlify",
|
|
297402
|
+
"github-pages",
|
|
297403
|
+
"firebase",
|
|
297404
|
+
"aws",
|
|
297405
|
+
"digitalocean",
|
|
297406
|
+
"render",
|
|
297407
|
+
"nginx",
|
|
297408
|
+
"caddy",
|
|
297409
|
+
"vercel",
|
|
297410
|
+
"static"
|
|
297411
|
+
]);
|
|
297412
|
+
if (STATIC_ONLY.has(name)) {
|
|
297413
|
+
const apiRoots = [join35(rootDir, ".tw", "api"), join35(rootDir, "api")];
|
|
297414
|
+
let apiCount = 0;
|
|
297415
|
+
const countTwm = (dir) => {
|
|
297416
|
+
if (!existsSync31(dir)) return;
|
|
297417
|
+
for (const entry of readdirSync11(dir, { withFileTypes: true })) {
|
|
297418
|
+
const full = join35(dir, entry.name);
|
|
297419
|
+
if (entry.isDirectory()) countTwm(full);
|
|
297420
|
+
else if (entry.name === "route.twm") apiCount++;
|
|
297421
|
+
}
|
|
297422
|
+
};
|
|
297423
|
+
for (const r of apiRoots) countTwm(r);
|
|
297424
|
+
let ssrCount = 0;
|
|
297425
|
+
const countSsr = (dir) => {
|
|
297426
|
+
if (!existsSync31(dir)) return;
|
|
297427
|
+
for (const entry of readdirSync11(dir, { withFileTypes: true })) {
|
|
297428
|
+
const full = join35(dir, entry.name);
|
|
297429
|
+
if (entry.isDirectory()) {
|
|
297430
|
+
countSsr(full);
|
|
297431
|
+
continue;
|
|
297432
|
+
}
|
|
297433
|
+
if (entry.name !== "page.tw") continue;
|
|
297434
|
+
const src = readFileSync22(full, "utf-8");
|
|
297435
|
+
const m = src.match(/render\s+(ssr|stream|csr|ppr)\b/);
|
|
297436
|
+
if (m) ssrCount++;
|
|
297437
|
+
}
|
|
297438
|
+
};
|
|
297439
|
+
countSsr(join35(rootDir, "home"));
|
|
297440
|
+
if (apiCount > 0 || ssrCount > 0) {
|
|
297441
|
+
const parts = [];
|
|
297442
|
+
if (ssrCount > 0) parts.push(ssrCount + " page" + (ssrCount === 1 ? "" : "s") + " rendered per request");
|
|
297443
|
+
if (apiCount > 0) parts.push(apiCount + " API route" + (apiCount === 1 ? "" : "s"));
|
|
297444
|
+
console.log("\n ! " + parts.join(" and ") + " will not be served by the " + name + " adapter.");
|
|
297445
|
+
console.log(" It packages the static build only, so those routes answer 404.");
|
|
297446
|
+
console.log(" Use `tw adapter bun` (or the Dockerfile) if they must run.\n");
|
|
297447
|
+
}
|
|
297448
|
+
}
|
|
297277
297449
|
const written = adaptersMod.generateAdapter(name, rootDir);
|
|
297278
297450
|
console.log(`
|
|
297279
297451
|
${via ? "" : ""}Generated ${name} adapter:
|
|
@@ -297287,11 +297459,11 @@ async function adapterCommand() {
|
|
|
297287
297459
|
// tw/commands/test.ts
|
|
297288
297460
|
import { join as join37 } from "node:path";
|
|
297289
297461
|
import { createRequire as _cr } from "node:module";
|
|
297290
|
-
import { existsSync as existsSync32, readdirSync as
|
|
297462
|
+
import { existsSync as existsSync32, readdirSync as readdirSync12, statSync as statSync11, readFileSync as readFileSync24 } from "node:fs";
|
|
297291
297463
|
var _require = _cr(import.meta.url);
|
|
297292
297464
|
function collectTests(dir, out) {
|
|
297293
297465
|
if (!existsSync32(dir)) return;
|
|
297294
|
-
for (const entry of
|
|
297466
|
+
for (const entry of readdirSync12(dir)) {
|
|
297295
297467
|
const full = join37(dir, entry);
|
|
297296
297468
|
if (statSync11(full).isDirectory()) collectTests(full, out);
|
|
297297
297469
|
else if (/\.test\.(ts|tsx|js)$/.test(entry)) out.push(full);
|
|
@@ -297304,7 +297476,7 @@ function ensureTestingShim(rootDir) {
|
|
|
297304
297476
|
if (existsSync32(marker)) return;
|
|
297305
297477
|
const { mkdirSync: mkdirSync12, writeFileSync: writeFileSync14 } = _require("node:fs");
|
|
297306
297478
|
mkdirSync12(join37(shimPkgDir, "tw"), { recursive: true });
|
|
297307
|
-
writeFileSync14(marker, JSON.stringify({ name: "@tw/server", version: "2.0.
|
|
297479
|
+
writeFileSync14(marker, JSON.stringify({ name: "@tw/server", version: "2.0.4", private: true }, null, 2));
|
|
297308
297480
|
let testingBundle = null;
|
|
297309
297481
|
try {
|
|
297310
297482
|
const here = new URL(".", import.meta.url).pathname;
|
|
@@ -297338,14 +297510,14 @@ async function testCommand() {
|
|
|
297338
297510
|
const files = [];
|
|
297339
297511
|
collectTests(testsDir, files);
|
|
297340
297512
|
if (existsSync32(rootDir)) {
|
|
297341
|
-
for (const f of
|
|
297513
|
+
for (const f of readdirSync12(rootDir)) {
|
|
297342
297514
|
if (/\.test\.(ts|tsx|js)$/.test(f)) files.push(join37(rootDir, f));
|
|
297343
297515
|
}
|
|
297344
297516
|
}
|
|
297345
297517
|
console.log("\n tw test -- running " + files.length + " test file" + (files.length === 1 ? "" : "s") + "\n");
|
|
297346
297518
|
for (const f of files) {
|
|
297347
297519
|
try {
|
|
297348
|
-
const src =
|
|
297520
|
+
const src = readFileSync24(f, "utf-8");
|
|
297349
297521
|
const hasBunTest = src.includes("bun:test");
|
|
297350
297522
|
const hasTestCall = /\b(test|it|describe)\s*\(/.test(src);
|
|
297351
297523
|
if (!hasBunTest && !hasTestCall) {
|
|
@@ -297388,7 +297560,7 @@ async function testCommand() {
|
|
|
297388
297560
|
init_tw();
|
|
297389
297561
|
init_components();
|
|
297390
297562
|
import { join as join38, dirname as dirname16 } from "node:path";
|
|
297391
|
-
import { existsSync as existsSync33, readFileSync as
|
|
297563
|
+
import { existsSync as existsSync33, readFileSync as readFileSync25, readdirSync as readdirSync13, statSync as statSync12 } from "node:fs";
|
|
297392
297564
|
async function checkCommand() {
|
|
297393
297565
|
const args = process.argv.slice(3);
|
|
297394
297566
|
const rootDir = process.cwd();
|
|
@@ -297417,7 +297589,7 @@ async function checkCommand() {
|
|
|
297417
297589
|
for (const filePath of twFiles) {
|
|
297418
297590
|
const relativePath = filePath.replace(rootDir + "/", "");
|
|
297419
297591
|
try {
|
|
297420
|
-
const source =
|
|
297592
|
+
const source = readFileSync25(filePath, "utf-8");
|
|
297421
297593
|
registerImportedComponents(filePath, rootDir, { compileSync: compileSync4, registerComponentTemplate: registerComponentTemplate3, clearComponentRegistry: clearComponentRegistry3 }, source);
|
|
297422
297594
|
const result = await compile2(source, {
|
|
297423
297595
|
filePath,
|
|
@@ -297429,7 +297601,7 @@ async function checkCommand() {
|
|
|
297429
297601
|
const errors = diagnostics.filter((d) => d.severity === "error");
|
|
297430
297602
|
const warnings = diagnostics.filter((d) => d.severity === "warning");
|
|
297431
297603
|
const info = diagnostics.filter((d) => d.severity === "info");
|
|
297432
|
-
const checkSource =
|
|
297604
|
+
const checkSource = readFileSync25(filePath, "utf-8");
|
|
297433
297605
|
const usedTags = /* @__PURE__ */ new Set();
|
|
297434
297606
|
const collectUsed = (n) => {
|
|
297435
297607
|
if (!n) return;
|
|
@@ -297486,7 +297658,7 @@ async function checkCommand() {
|
|
|
297486
297658
|
} else {
|
|
297487
297659
|
for (const filePath of twFiles) {
|
|
297488
297660
|
const relativePath = filePath.replace(rootDir + "/", "");
|
|
297489
|
-
const source =
|
|
297661
|
+
const source = readFileSync25(filePath, "utf-8");
|
|
297490
297662
|
const maskedSource = maskSourceStringsAndComments(source);
|
|
297491
297663
|
const openBraces = (maskedSource.match(/\{/g) || []).length;
|
|
297492
297664
|
const closeBraces = (maskedSource.match(/\}/g) || []).length;
|
|
@@ -297536,7 +297708,7 @@ function findComponentUp(dir, name) {
|
|
|
297536
297708
|
return false;
|
|
297537
297709
|
}
|
|
297538
297710
|
function collectFiles2(dir, ext, results) {
|
|
297539
|
-
const entries =
|
|
297711
|
+
const entries = readdirSync13(dir);
|
|
297540
297712
|
for (const entry of entries) {
|
|
297541
297713
|
const fullPath = join38(dir, entry);
|
|
297542
297714
|
const stat = statSync12(fullPath);
|
|
@@ -297552,10 +297724,10 @@ function collectFiles2(dir, ext, results) {
|
|
|
297552
297724
|
init_tw();
|
|
297553
297725
|
init_tw8();
|
|
297554
297726
|
import { join as join39 } from "node:path";
|
|
297555
|
-
import { existsSync as existsSync34, readFileSync as
|
|
297727
|
+
import { existsSync as existsSync34, readFileSync as readFileSync26, writeFileSync as writeFileSync13, mkdirSync as mkdirSync11, readdirSync as readdirSync14 } from "node:fs";
|
|
297556
297728
|
function readConfigPlugins(cfgPath) {
|
|
297557
297729
|
if (!existsSync34(cfgPath)) return [];
|
|
297558
|
-
const src = stripCommentsStringAware(
|
|
297730
|
+
const src = stripCommentsStringAware(readFileSync26(cfgPath, "utf-8"));
|
|
297559
297731
|
return readPluginSpecs(src);
|
|
297560
297732
|
}
|
|
297561
297733
|
function addConfigPlugin(cfgPath, name) {
|
|
@@ -297566,7 +297738,7 @@ function addConfigPlugin(cfgPath, name) {
|
|
|
297566
297738
|
`);
|
|
297567
297739
|
return true;
|
|
297568
297740
|
}
|
|
297569
|
-
const src = stripCommentsStringAware(
|
|
297741
|
+
const src = stripCommentsStringAware(readFileSync26(cfgPath, "utf-8"));
|
|
297570
297742
|
if (new RegExp(`["'\`]${name}["'\`]`).test(src)) return false;
|
|
297571
297743
|
const m = /plugins\s*:\s*\[([^\]]*)\]/s.exec(src);
|
|
297572
297744
|
if (m) {
|
|
@@ -297583,7 +297755,7 @@ function addConfigPlugin(cfgPath, name) {
|
|
|
297583
297755
|
}
|
|
297584
297756
|
function removeConfigPlugin(cfgPath, name) {
|
|
297585
297757
|
if (!existsSync34(cfgPath)) return false;
|
|
297586
|
-
const src =
|
|
297758
|
+
const src = readFileSync26(cfgPath, "utf-8");
|
|
297587
297759
|
const masked = maskSourceStringsAndComments(src);
|
|
297588
297760
|
const range2 = pluginsArrayRange(masked);
|
|
297589
297761
|
if (!range2) return false;
|
|
@@ -297597,7 +297769,7 @@ function removeConfigPlugin(cfgPath, name) {
|
|
|
297597
297769
|
function listPluginFiles(rootDir) {
|
|
297598
297770
|
const dir = join39(rootDir, "plugins");
|
|
297599
297771
|
if (!existsSync34(dir)) return [];
|
|
297600
|
-
return
|
|
297772
|
+
return readdirSync14(dir).filter((f) => f.endsWith(".ts") && !f.endsWith(".d.ts"));
|
|
297601
297773
|
}
|
|
297602
297774
|
async function searchPlugins(term) {
|
|
297603
297775
|
const q = term ? `keywords:tw-plugin ${term}` : "keywords:tw-plugin";
|
|
@@ -297740,7 +297912,7 @@ async function upgradePlugins(rootDir, opts) {
|
|
|
297740
297912
|
process.exit(1);
|
|
297741
297913
|
}
|
|
297742
297914
|
const { readPluginSpecs: readPluginSpecs2, planUpgrade: planUpgrade2, outdated: outdated2 } = await Promise.resolve().then(() => (init_tw8(), tw_exports4));
|
|
297743
|
-
const specs = readPluginSpecs2(
|
|
297915
|
+
const specs = readPluginSpecs2(readFileSync26(cfgPath, "utf-8"));
|
|
297744
297916
|
if (specs.length === 0) {
|
|
297745
297917
|
console.log("\n No plugins in tw.config.ts -- nothing to upgrade.\n");
|
|
297746
297918
|
return;
|
|
@@ -298196,13 +298368,13 @@ async function doctorCommand() {
|
|
|
298196
298368
|
}
|
|
298197
298369
|
|
|
298198
298370
|
// tw/help.ts
|
|
298199
|
-
import { readFileSync as
|
|
298371
|
+
import { readFileSync as readFileSync27 } from "node:fs";
|
|
298200
298372
|
import { join as join42 } from "node:path";
|
|
298201
298373
|
function cliVersion() {
|
|
298202
298374
|
try {
|
|
298203
298375
|
const bd = globalThis.__TW_BUNDLE_DIR;
|
|
298204
298376
|
const pj = bd ? join42(bd, "..", "package.json") : new URL("../package.json", import.meta.url).pathname;
|
|
298205
|
-
return JSON.parse(
|
|
298377
|
+
return JSON.parse(readFileSync27(pj, "utf-8")).version ?? "0.0.0";
|
|
298206
298378
|
} catch {
|
|
298207
298379
|
return "0.0.0";
|
|
298208
298380
|
}
|
|
@@ -298276,13 +298448,13 @@ var helpText = `
|
|
|
298276
298448
|
|
|
298277
298449
|
// tw/commands/index.ts
|
|
298278
298450
|
await init_build();
|
|
298279
|
-
import { readFileSync as
|
|
298451
|
+
import { readFileSync as readFileSync28 } from "node:fs";
|
|
298280
298452
|
import { join as join43 } from "node:path";
|
|
298281
298453
|
var VERSION2 = (() => {
|
|
298282
298454
|
try {
|
|
298283
298455
|
const bd = globalThis.__TW_BUNDLE_DIR;
|
|
298284
298456
|
const pj = bd ? join43(bd, "..", "package.json") : new URL("../../package.json", import.meta.url).pathname;
|
|
298285
|
-
return JSON.parse(
|
|
298457
|
+
return JSON.parse(readFileSync28(pj, "utf-8")).version ?? "0.0.0";
|
|
298286
298458
|
} catch {
|
|
298287
298459
|
return "0.0.0";
|
|
298288
298460
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tw-framework",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
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"
|