tw-framework 2.0.3 → 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 +52 -0
- package/dist/testing.cjs +111 -3
- package/dist/tw-server.mjs +111 -3
- package/dist/tw.mjs +207 -38
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,58 @@ 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
|
+
|
|
7
59
|
## [2.0.3]
|
|
8
60
|
|
|
9
61
|
A patch release: bug fixes only, no breaking changes, no public API changes.
|
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
|
|
|
@@ -296304,7 +296412,11 @@ async function devCommand() {
|
|
|
296304
296412
|
if (existsSync27(publicDir)) {
|
|
296305
296413
|
const publicFile = join31(publicDir, path);
|
|
296306
296414
|
const pubFile = Bun.file(publicFile);
|
|
296307
|
-
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
|
+
}
|
|
296308
296420
|
}
|
|
296309
296421
|
if (path === "/placeholder.png" || path.endsWith(".png")) {
|
|
296310
296422
|
return new Response(PLACEHOLDER_PNG, { headers: { "Content-Type": "image/png" } });
|
|
@@ -296456,14 +296568,19 @@ async function devCommand() {
|
|
|
296456
296568
|
try {
|
|
296457
296569
|
const source = readFileSync19(twFile, "utf-8");
|
|
296458
296570
|
if (typeof beginCssRouteCapture2 === "function") beginCssRouteCapture2(path);
|
|
296459
|
-
let result = compileSync3(source, { filePath: twFile, stateVars: resolved.params });
|
|
296571
|
+
let result = compileSync3(source, { filePath: twFile, stateVars: resolved.params, experimental: { serverBlocks: true } });
|
|
296460
296572
|
try {
|
|
296461
296573
|
const _c = await Promise.resolve().then(() => (init_tw7(), tw_exports3));
|
|
296462
296574
|
const blocks = _c.collectServerBlocks(result.ast);
|
|
296463
296575
|
if (blocks.length) {
|
|
296464
296576
|
const values = await _c.executeServerBlocks(blocks.filter((b) => !b.deferred), { label: twFile });
|
|
296465
296577
|
if (values && Object.keys(values).length) {
|
|
296466
|
-
|
|
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 } });
|
|
296467
296584
|
}
|
|
296468
296585
|
}
|
|
296469
296586
|
} catch (e) {
|
|
@@ -296872,8 +296989,8 @@ async function serveCommand() {
|
|
|
296872
296989
|
const envPath = join32(rootDir, ".env");
|
|
296873
296990
|
if (existsSync28(envPath)) {
|
|
296874
296991
|
try {
|
|
296875
|
-
const { readFileSync:
|
|
296876
|
-
for (const line of
|
|
296992
|
+
const { readFileSync: readFileSync29 } = await import("node:fs");
|
|
296993
|
+
for (const line of readFileSync29(envPath, "utf-8").split("\n")) {
|
|
296877
296994
|
const m = /^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/.exec(line);
|
|
296878
296995
|
if (m && !(m[1] in process.env)) {
|
|
296879
296996
|
process.env[m[1]] = m[2].replace(/^["']|["']$/g, "");
|
|
@@ -297229,8 +297346,8 @@ CMD ["bunx", "tw", "serve"]`;
|
|
|
297229
297346
|
}
|
|
297230
297347
|
|
|
297231
297348
|
// tw/commands/adapter.ts
|
|
297232
|
-
import { resolve as resolve11 } from "node:path";
|
|
297233
|
-
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";
|
|
297234
297351
|
async function adapterCommand() {
|
|
297235
297352
|
const args = process.argv.slice(3);
|
|
297236
297353
|
const rootDir = process.cwd();
|
|
@@ -297277,6 +297394,58 @@ async function adapterCommand() {
|
|
|
297277
297394
|
`);
|
|
297278
297395
|
process.exit(1);
|
|
297279
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
|
+
}
|
|
297280
297449
|
const written = adaptersMod.generateAdapter(name, rootDir);
|
|
297281
297450
|
console.log(`
|
|
297282
297451
|
${via ? "" : ""}Generated ${name} adapter:
|
|
@@ -297290,11 +297459,11 @@ async function adapterCommand() {
|
|
|
297290
297459
|
// tw/commands/test.ts
|
|
297291
297460
|
import { join as join37 } from "node:path";
|
|
297292
297461
|
import { createRequire as _cr } from "node:module";
|
|
297293
|
-
import { existsSync as existsSync32, readdirSync as
|
|
297462
|
+
import { existsSync as existsSync32, readdirSync as readdirSync12, statSync as statSync11, readFileSync as readFileSync24 } from "node:fs";
|
|
297294
297463
|
var _require = _cr(import.meta.url);
|
|
297295
297464
|
function collectTests(dir, out) {
|
|
297296
297465
|
if (!existsSync32(dir)) return;
|
|
297297
|
-
for (const entry of
|
|
297466
|
+
for (const entry of readdirSync12(dir)) {
|
|
297298
297467
|
const full = join37(dir, entry);
|
|
297299
297468
|
if (statSync11(full).isDirectory()) collectTests(full, out);
|
|
297300
297469
|
else if (/\.test\.(ts|tsx|js)$/.test(entry)) out.push(full);
|
|
@@ -297307,7 +297476,7 @@ function ensureTestingShim(rootDir) {
|
|
|
297307
297476
|
if (existsSync32(marker)) return;
|
|
297308
297477
|
const { mkdirSync: mkdirSync12, writeFileSync: writeFileSync14 } = _require("node:fs");
|
|
297309
297478
|
mkdirSync12(join37(shimPkgDir, "tw"), { recursive: true });
|
|
297310
|
-
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));
|
|
297311
297480
|
let testingBundle = null;
|
|
297312
297481
|
try {
|
|
297313
297482
|
const here = new URL(".", import.meta.url).pathname;
|
|
@@ -297341,14 +297510,14 @@ async function testCommand() {
|
|
|
297341
297510
|
const files = [];
|
|
297342
297511
|
collectTests(testsDir, files);
|
|
297343
297512
|
if (existsSync32(rootDir)) {
|
|
297344
|
-
for (const f of
|
|
297513
|
+
for (const f of readdirSync12(rootDir)) {
|
|
297345
297514
|
if (/\.test\.(ts|tsx|js)$/.test(f)) files.push(join37(rootDir, f));
|
|
297346
297515
|
}
|
|
297347
297516
|
}
|
|
297348
297517
|
console.log("\n tw test -- running " + files.length + " test file" + (files.length === 1 ? "" : "s") + "\n");
|
|
297349
297518
|
for (const f of files) {
|
|
297350
297519
|
try {
|
|
297351
|
-
const src =
|
|
297520
|
+
const src = readFileSync24(f, "utf-8");
|
|
297352
297521
|
const hasBunTest = src.includes("bun:test");
|
|
297353
297522
|
const hasTestCall = /\b(test|it|describe)\s*\(/.test(src);
|
|
297354
297523
|
if (!hasBunTest && !hasTestCall) {
|
|
@@ -297391,7 +297560,7 @@ async function testCommand() {
|
|
|
297391
297560
|
init_tw();
|
|
297392
297561
|
init_components();
|
|
297393
297562
|
import { join as join38, dirname as dirname16 } from "node:path";
|
|
297394
|
-
import { existsSync as existsSync33, readFileSync as
|
|
297563
|
+
import { existsSync as existsSync33, readFileSync as readFileSync25, readdirSync as readdirSync13, statSync as statSync12 } from "node:fs";
|
|
297395
297564
|
async function checkCommand() {
|
|
297396
297565
|
const args = process.argv.slice(3);
|
|
297397
297566
|
const rootDir = process.cwd();
|
|
@@ -297420,7 +297589,7 @@ async function checkCommand() {
|
|
|
297420
297589
|
for (const filePath of twFiles) {
|
|
297421
297590
|
const relativePath = filePath.replace(rootDir + "/", "");
|
|
297422
297591
|
try {
|
|
297423
|
-
const source =
|
|
297592
|
+
const source = readFileSync25(filePath, "utf-8");
|
|
297424
297593
|
registerImportedComponents(filePath, rootDir, { compileSync: compileSync4, registerComponentTemplate: registerComponentTemplate3, clearComponentRegistry: clearComponentRegistry3 }, source);
|
|
297425
297594
|
const result = await compile2(source, {
|
|
297426
297595
|
filePath,
|
|
@@ -297432,7 +297601,7 @@ async function checkCommand() {
|
|
|
297432
297601
|
const errors = diagnostics.filter((d) => d.severity === "error");
|
|
297433
297602
|
const warnings = diagnostics.filter((d) => d.severity === "warning");
|
|
297434
297603
|
const info = diagnostics.filter((d) => d.severity === "info");
|
|
297435
|
-
const checkSource =
|
|
297604
|
+
const checkSource = readFileSync25(filePath, "utf-8");
|
|
297436
297605
|
const usedTags = /* @__PURE__ */ new Set();
|
|
297437
297606
|
const collectUsed = (n) => {
|
|
297438
297607
|
if (!n) return;
|
|
@@ -297489,7 +297658,7 @@ async function checkCommand() {
|
|
|
297489
297658
|
} else {
|
|
297490
297659
|
for (const filePath of twFiles) {
|
|
297491
297660
|
const relativePath = filePath.replace(rootDir + "/", "");
|
|
297492
|
-
const source =
|
|
297661
|
+
const source = readFileSync25(filePath, "utf-8");
|
|
297493
297662
|
const maskedSource = maskSourceStringsAndComments(source);
|
|
297494
297663
|
const openBraces = (maskedSource.match(/\{/g) || []).length;
|
|
297495
297664
|
const closeBraces = (maskedSource.match(/\}/g) || []).length;
|
|
@@ -297539,7 +297708,7 @@ function findComponentUp(dir, name) {
|
|
|
297539
297708
|
return false;
|
|
297540
297709
|
}
|
|
297541
297710
|
function collectFiles2(dir, ext, results) {
|
|
297542
|
-
const entries =
|
|
297711
|
+
const entries = readdirSync13(dir);
|
|
297543
297712
|
for (const entry of entries) {
|
|
297544
297713
|
const fullPath = join38(dir, entry);
|
|
297545
297714
|
const stat = statSync12(fullPath);
|
|
@@ -297555,10 +297724,10 @@ function collectFiles2(dir, ext, results) {
|
|
|
297555
297724
|
init_tw();
|
|
297556
297725
|
init_tw8();
|
|
297557
297726
|
import { join as join39 } from "node:path";
|
|
297558
|
-
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";
|
|
297559
297728
|
function readConfigPlugins(cfgPath) {
|
|
297560
297729
|
if (!existsSync34(cfgPath)) return [];
|
|
297561
|
-
const src = stripCommentsStringAware(
|
|
297730
|
+
const src = stripCommentsStringAware(readFileSync26(cfgPath, "utf-8"));
|
|
297562
297731
|
return readPluginSpecs(src);
|
|
297563
297732
|
}
|
|
297564
297733
|
function addConfigPlugin(cfgPath, name) {
|
|
@@ -297569,7 +297738,7 @@ function addConfigPlugin(cfgPath, name) {
|
|
|
297569
297738
|
`);
|
|
297570
297739
|
return true;
|
|
297571
297740
|
}
|
|
297572
|
-
const src = stripCommentsStringAware(
|
|
297741
|
+
const src = stripCommentsStringAware(readFileSync26(cfgPath, "utf-8"));
|
|
297573
297742
|
if (new RegExp(`["'\`]${name}["'\`]`).test(src)) return false;
|
|
297574
297743
|
const m = /plugins\s*:\s*\[([^\]]*)\]/s.exec(src);
|
|
297575
297744
|
if (m) {
|
|
@@ -297586,7 +297755,7 @@ function addConfigPlugin(cfgPath, name) {
|
|
|
297586
297755
|
}
|
|
297587
297756
|
function removeConfigPlugin(cfgPath, name) {
|
|
297588
297757
|
if (!existsSync34(cfgPath)) return false;
|
|
297589
|
-
const src =
|
|
297758
|
+
const src = readFileSync26(cfgPath, "utf-8");
|
|
297590
297759
|
const masked = maskSourceStringsAndComments(src);
|
|
297591
297760
|
const range2 = pluginsArrayRange(masked);
|
|
297592
297761
|
if (!range2) return false;
|
|
@@ -297600,7 +297769,7 @@ function removeConfigPlugin(cfgPath, name) {
|
|
|
297600
297769
|
function listPluginFiles(rootDir) {
|
|
297601
297770
|
const dir = join39(rootDir, "plugins");
|
|
297602
297771
|
if (!existsSync34(dir)) return [];
|
|
297603
|
-
return
|
|
297772
|
+
return readdirSync14(dir).filter((f) => f.endsWith(".ts") && !f.endsWith(".d.ts"));
|
|
297604
297773
|
}
|
|
297605
297774
|
async function searchPlugins(term) {
|
|
297606
297775
|
const q = term ? `keywords:tw-plugin ${term}` : "keywords:tw-plugin";
|
|
@@ -297743,7 +297912,7 @@ async function upgradePlugins(rootDir, opts) {
|
|
|
297743
297912
|
process.exit(1);
|
|
297744
297913
|
}
|
|
297745
297914
|
const { readPluginSpecs: readPluginSpecs2, planUpgrade: planUpgrade2, outdated: outdated2 } = await Promise.resolve().then(() => (init_tw8(), tw_exports4));
|
|
297746
|
-
const specs = readPluginSpecs2(
|
|
297915
|
+
const specs = readPluginSpecs2(readFileSync26(cfgPath, "utf-8"));
|
|
297747
297916
|
if (specs.length === 0) {
|
|
297748
297917
|
console.log("\n No plugins in tw.config.ts -- nothing to upgrade.\n");
|
|
297749
297918
|
return;
|
|
@@ -298199,13 +298368,13 @@ async function doctorCommand() {
|
|
|
298199
298368
|
}
|
|
298200
298369
|
|
|
298201
298370
|
// tw/help.ts
|
|
298202
|
-
import { readFileSync as
|
|
298371
|
+
import { readFileSync as readFileSync27 } from "node:fs";
|
|
298203
298372
|
import { join as join42 } from "node:path";
|
|
298204
298373
|
function cliVersion() {
|
|
298205
298374
|
try {
|
|
298206
298375
|
const bd = globalThis.__TW_BUNDLE_DIR;
|
|
298207
298376
|
const pj = bd ? join42(bd, "..", "package.json") : new URL("../package.json", import.meta.url).pathname;
|
|
298208
|
-
return JSON.parse(
|
|
298377
|
+
return JSON.parse(readFileSync27(pj, "utf-8")).version ?? "0.0.0";
|
|
298209
298378
|
} catch {
|
|
298210
298379
|
return "0.0.0";
|
|
298211
298380
|
}
|
|
@@ -298279,13 +298448,13 @@ var helpText = `
|
|
|
298279
298448
|
|
|
298280
298449
|
// tw/commands/index.ts
|
|
298281
298450
|
await init_build();
|
|
298282
|
-
import { readFileSync as
|
|
298451
|
+
import { readFileSync as readFileSync28 } from "node:fs";
|
|
298283
298452
|
import { join as join43 } from "node:path";
|
|
298284
298453
|
var VERSION2 = (() => {
|
|
298285
298454
|
try {
|
|
298286
298455
|
const bd = globalThis.__TW_BUNDLE_DIR;
|
|
298287
298456
|
const pj = bd ? join43(bd, "..", "package.json") : new URL("../../package.json", import.meta.url).pathname;
|
|
298288
|
-
return JSON.parse(
|
|
298457
|
+
return JSON.parse(readFileSync28(pj, "utf-8")).version ?? "0.0.0";
|
|
298289
298458
|
} catch {
|
|
298290
298459
|
return "0.0.0";
|
|
298291
298460
|
}
|
package/package.json
CHANGED