tw-framework 2.0.3 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +108 -0
- package/dist/testing.cjs +560 -189
- package/dist/tw-server.mjs +529 -157
- package/dist/tw.mjs +1017 -478
- package/package.json +1 -1
package/dist/tw.mjs
CHANGED
|
@@ -17135,13 +17135,13 @@ var require_typescript = __commonJS({
|
|
|
17135
17135
|
isNamedExportBindings: () => isNamedExportBindings,
|
|
17136
17136
|
isNamedExports: () => isNamedExports,
|
|
17137
17137
|
isNamedImportBindings: () => isNamedImportBindings,
|
|
17138
|
-
isNamedImports: () =>
|
|
17138
|
+
isNamedImports: () => isNamedImports2,
|
|
17139
17139
|
isNamedImportsOrExports: () => isNamedImportsOrExports,
|
|
17140
17140
|
isNamedTupleMember: () => isNamedTupleMember,
|
|
17141
17141
|
isNamespaceBody: () => isNamespaceBody,
|
|
17142
17142
|
isNamespaceExport: () => isNamespaceExport,
|
|
17143
17143
|
isNamespaceExportDeclaration: () => isNamespaceExportDeclaration,
|
|
17144
|
-
isNamespaceImport: () =>
|
|
17144
|
+
isNamespaceImport: () => isNamespaceImport2,
|
|
17145
17145
|
isNamespaceReexportDeclaration: () => isNamespaceReexportDeclaration,
|
|
17146
17146
|
isNewExpression: () => isNewExpression2,
|
|
17147
17147
|
isNewExpressionTarget: () => isNewExpressionTarget,
|
|
@@ -34897,7 +34897,7 @@ ${lanes.join("\n")}
|
|
|
34897
34897
|
function getNamespaceDeclarationNode(node) {
|
|
34898
34898
|
switch (node.kind) {
|
|
34899
34899
|
case 273:
|
|
34900
|
-
return node.importClause && tryCast(node.importClause.namedBindings,
|
|
34900
|
+
return node.importClause && tryCast(node.importClause.namedBindings, isNamespaceImport2);
|
|
34901
34901
|
case 272:
|
|
34902
34902
|
return node;
|
|
34903
34903
|
case 279:
|
|
@@ -34915,7 +34915,7 @@ ${lanes.join("\n")}
|
|
|
34915
34915
|
if (result) return result;
|
|
34916
34916
|
}
|
|
34917
34917
|
if (node.namedBindings) {
|
|
34918
|
-
const result =
|
|
34918
|
+
const result = isNamespaceImport2(node.namedBindings) ? action(node.namedBindings) : forEach(node.namedBindings.elements, action);
|
|
34919
34919
|
if (result) return result;
|
|
34920
34920
|
}
|
|
34921
34921
|
}
|
|
@@ -48128,13 +48128,13 @@ ${lanes.join("\n")}
|
|
|
48128
48128
|
function isImportAttribute(node) {
|
|
48129
48129
|
return node.kind === 302;
|
|
48130
48130
|
}
|
|
48131
|
-
function
|
|
48131
|
+
function isNamespaceImport2(node) {
|
|
48132
48132
|
return node.kind === 275;
|
|
48133
48133
|
}
|
|
48134
48134
|
function isNamespaceExport(node) {
|
|
48135
48135
|
return node.kind === 281;
|
|
48136
48136
|
}
|
|
48137
|
-
function
|
|
48137
|
+
function isNamedImports2(node) {
|
|
48138
48138
|
return node.kind === 276;
|
|
48139
48139
|
}
|
|
48140
48140
|
function isImportSpecifier(node) {
|
|
@@ -119491,7 +119491,7 @@ ${lanes.join("\n")}
|
|
|
119491
119491
|
}
|
|
119492
119492
|
function containsDefaultReference(node) {
|
|
119493
119493
|
if (!node) return false;
|
|
119494
|
-
if (!
|
|
119494
|
+
if (!isNamedImports2(node) && !isNamedExports(node)) return false;
|
|
119495
119495
|
return some(node.elements, isNamedDefaultReference);
|
|
119496
119496
|
}
|
|
119497
119497
|
function isNamedDefaultReference(e) {
|
|
@@ -119517,7 +119517,7 @@ ${lanes.join("\n")}
|
|
|
119517
119517
|
if (!bindings) {
|
|
119518
119518
|
return false;
|
|
119519
119519
|
}
|
|
119520
|
-
if (!
|
|
119520
|
+
if (!isNamedImports2(bindings)) return false;
|
|
119521
119521
|
let defaultRefCount = 0;
|
|
119522
119522
|
for (const binding of bindings.elements) {
|
|
119523
119523
|
if (isNamedDefaultReference(binding)) {
|
|
@@ -119527,7 +119527,7 @@ ${lanes.join("\n")}
|
|
|
119527
119527
|
return defaultRefCount > 0 && defaultRefCount !== bindings.elements.length || !!(bindings.elements.length - defaultRefCount) && isDefaultImport(node);
|
|
119528
119528
|
}
|
|
119529
119529
|
function getImportNeedsImportDefaultHelper(node) {
|
|
119530
|
-
return !getImportNeedsImportStarHelper(node) && (isDefaultImport(node) || !!node.importClause &&
|
|
119530
|
+
return !getImportNeedsImportStarHelper(node) && (isDefaultImport(node) || !!node.importClause && isNamedImports2(node.importClause.namedBindings) && containsDefaultReference(node.importClause.namedBindings));
|
|
119531
119531
|
}
|
|
119532
119532
|
function collectExternalModuleInfo(context, sourceFile) {
|
|
119533
119533
|
const resolver = context.getEmitResolver();
|
|
@@ -151871,9 +151871,9 @@ ${lanes.join("\n")}
|
|
|
151871
151871
|
/*ignoreCase*/
|
|
151872
151872
|
false
|
|
151873
151873
|
)) {
|
|
151874
|
-
const
|
|
151875
|
-
if (
|
|
151876
|
-
const name = removeSuffix(removePrefix(
|
|
151874
|
+
const basename4 = getBaseFileName(a.fileName);
|
|
151875
|
+
if (basename4 === "lib.d.ts" || basename4 === "lib.es6.d.ts") return 0;
|
|
151876
|
+
const name = removeSuffix(removePrefix(basename4, "lib."), ".d.ts");
|
|
151877
151877
|
const index = libs.indexOf(name);
|
|
151878
151878
|
if (index !== -1) return index + 1;
|
|
151879
151879
|
}
|
|
@@ -164786,13 +164786,13 @@ ${lanes.join("\n")}
|
|
|
164786
164786
|
return node.importClause.name;
|
|
164787
164787
|
}
|
|
164788
164788
|
if (node.importClause.namedBindings) {
|
|
164789
|
-
if (
|
|
164789
|
+
if (isNamedImports2(node.importClause.namedBindings)) {
|
|
164790
164790
|
const onlyBinding = singleOrUndefined(node.importClause.namedBindings.elements);
|
|
164791
164791
|
if (!onlyBinding) {
|
|
164792
164792
|
return;
|
|
164793
164793
|
}
|
|
164794
164794
|
return onlyBinding.name;
|
|
164795
|
-
} else if (
|
|
164795
|
+
} else if (isNamespaceImport2(node.importClause.namedBindings)) {
|
|
164796
164796
|
return node.importClause.namedBindings.name;
|
|
164797
164797
|
}
|
|
164798
164798
|
}
|
|
@@ -164851,7 +164851,7 @@ ${lanes.join("\n")}
|
|
|
164851
164851
|
}
|
|
164852
164852
|
}
|
|
164853
164853
|
if (node.kind === 130) {
|
|
164854
|
-
if (isImportSpecifier(parent2) && parent2.propertyName || isExportSpecifier(parent2) && parent2.propertyName ||
|
|
164854
|
+
if (isImportSpecifier(parent2) && parent2.propertyName || isExportSpecifier(parent2) && parent2.propertyName || isNamespaceImport2(parent2) || isNamespaceExport(parent2)) {
|
|
164855
164855
|
return parent2.name;
|
|
164856
164856
|
}
|
|
164857
164857
|
if (isExportDeclaration3(parent2) && parent2.exportClause && isNamespaceExport(parent2.exportClause)) {
|
|
@@ -172945,7 +172945,7 @@ interface Symbol {
|
|
|
172945
172945
|
const targetFileImportsFromOldFile = /* @__PURE__ */ new Map();
|
|
172946
172946
|
const jsxNamespaceSymbol = getJsxNamespaceSymbol(containsJsx(toMove));
|
|
172947
172947
|
if (jsxNamespaceSymbol) {
|
|
172948
|
-
oldImportsNeededByTargetFile.set(jsxNamespaceSymbol, [false, tryCast((_a = jsxNamespaceSymbol.declarations) == null ? void 0 : _a[0], (d) => isImportSpecifier(d) || isImportClause(d) ||
|
|
172948
|
+
oldImportsNeededByTargetFile.set(jsxNamespaceSymbol, [false, tryCast((_a = jsxNamespaceSymbol.declarations) == null ? void 0 : _a[0], (d) => isImportSpecifier(d) || isImportClause(d) || isNamespaceImport2(d) || isImportEqualsDeclaration(d) || isBindingElement2(d) || isVariableDeclaration3(d))]);
|
|
172949
172949
|
}
|
|
172950
172950
|
for (const statement of toMove) {
|
|
172951
172951
|
forEachTopLevelDeclaration(statement, (decl) => {
|
|
@@ -172967,7 +172967,7 @@ interface Symbol {
|
|
|
172967
172967
|
const prevIsTypeOnly = oldImportsNeededByTargetFile.get(symbol);
|
|
172968
172968
|
oldImportsNeededByTargetFile.set(symbol, [
|
|
172969
172969
|
prevIsTypeOnly === void 0 ? isValidTypeOnlyUseSite : prevIsTypeOnly && isValidTypeOnlyUseSite,
|
|
172970
|
-
tryCast(importedDeclaration, (d) => isImportSpecifier(d) || isImportClause(d) ||
|
|
172970
|
+
tryCast(importedDeclaration, (d) => isImportSpecifier(d) || isImportClause(d) || isNamespaceImport2(d) || isImportEqualsDeclaration(d) || isBindingElement2(d) || isVariableDeclaration3(d))
|
|
172971
172971
|
]);
|
|
172972
172972
|
} else if (!movedSymbols.has(symbol) && every(symbol.declarations, (decl) => isTopLevelDeclaration(decl) && sourceFileOfTopLevelDeclaration(decl) === oldFile)) {
|
|
172973
172973
|
targetFileImportsFromOldFile.set(symbol, isValidTypeOnlyUseSite);
|
|
@@ -173169,7 +173169,7 @@ interface Symbol {
|
|
|
173169
173169
|
const existingLocals = /* @__PURE__ */ new Set();
|
|
173170
173170
|
for (const moduleSpecifier of sourceFile.imports) {
|
|
173171
173171
|
const declaration = importFromModuleSpecifier(moduleSpecifier);
|
|
173172
|
-
if (isImportDeclaration4(declaration) && declaration.importClause && declaration.importClause.namedBindings &&
|
|
173172
|
+
if (isImportDeclaration4(declaration) && declaration.importClause && declaration.importClause.namedBindings && isNamedImports2(declaration.importClause.namedBindings)) {
|
|
173173
173173
|
for (const e of declaration.importClause.namedBindings.elements) {
|
|
173174
173174
|
const symbol = checker.getSymbolAtLocation(e.propertyName || e.name);
|
|
173175
173175
|
if (symbol) {
|
|
@@ -174206,7 +174206,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
|
|
|
174206
174206
|
}
|
|
174207
174207
|
function entryToImportOrExport(entry) {
|
|
174208
174208
|
const node = entry.node;
|
|
174209
|
-
if (isImportSpecifier(node.parent) || isImportClause(node.parent) || isImportEqualsDeclaration(node.parent) ||
|
|
174209
|
+
if (isImportSpecifier(node.parent) || isImportClause(node.parent) || isImportEqualsDeclaration(node.parent) || isNamespaceImport2(node.parent)) {
|
|
174210
174210
|
return node;
|
|
174211
174211
|
}
|
|
174212
174212
|
if (isExportSpecifier(node.parent) || isExportAssignment(node.parent)) {
|
|
@@ -177037,7 +177037,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
|
|
|
177037
177037
|
}
|
|
177038
177038
|
function inImportClause(node) {
|
|
177039
177039
|
const parent2 = node.parent;
|
|
177040
|
-
return parent2 && (isImportClause(parent2) || isImportSpecifier(parent2) ||
|
|
177040
|
+
return parent2 && (isImportClause(parent2) || isImportSpecifier(parent2) || isNamespaceImport2(parent2));
|
|
177041
177041
|
}
|
|
177042
177042
|
function isExpressionInCallExpression(node) {
|
|
177043
177043
|
while (isRightSideOfQualifiedNameOrPropertyAccess2(node)) {
|
|
@@ -184120,8 +184120,8 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
|
|
|
184120
184120
|
// nothing added to the import declaration
|
|
184121
184121
|
!addToExisting.has(d.importClause) && // no default, or default is being removed
|
|
184122
184122
|
(!((_a2 = d.importClause) == null ? void 0 : _a2.name) || removeExisting.has(d.importClause)) && // no namespace import, or namespace import is being removed
|
|
184123
|
-
(!tryCast((_b2 = d.importClause) == null ? void 0 : _b2.namedBindings,
|
|
184124
|
-
(!tryCast((_c = d.importClause) == null ? void 0 : _c.namedBindings,
|
|
184123
|
+
(!tryCast((_b2 = d.importClause) == null ? void 0 : _b2.namedBindings, isNamespaceImport2) || removeExisting.has(d.importClause.namedBindings)) && // no named imports, or all named imports are being removed
|
|
184124
|
+
(!tryCast((_c = d.importClause) == null ? void 0 : _c.namedBindings, isNamedImports2) || every(d.importClause.namedBindings.elements, (e) => removeExisting.has(e)))
|
|
184125
184125
|
);
|
|
184126
184126
|
}
|
|
184127
184127
|
);
|
|
@@ -184249,7 +184249,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
|
|
|
184249
184249
|
d.importClause,
|
|
184250
184250
|
d.importClause.phaseModifier,
|
|
184251
184251
|
verbatimImports.has(d.importClause) ? d.importClause.name : void 0,
|
|
184252
|
-
verbatimImports.has(d.importClause.namedBindings) ? d.importClause.namedBindings : ((_a = tryCast(d.importClause.namedBindings,
|
|
184252
|
+
verbatimImports.has(d.importClause.namedBindings) ? d.importClause.namedBindings : ((_a = tryCast(d.importClause.namedBindings, isNamedImports2)) == null ? void 0 : _a.elements.some((e) => verbatimImports.has(e))) ? factory.updateNamedImports(
|
|
184253
184253
|
d.importClause.namedBindings,
|
|
184254
184254
|
d.importClause.namedBindings.elements.filter((e) => verbatimImports.has(e))
|
|
184255
184255
|
) : void 0
|
|
@@ -184464,7 +184464,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
|
|
|
184464
184464
|
return declaration.name.text;
|
|
184465
184465
|
case 352:
|
|
184466
184466
|
case 273:
|
|
184467
|
-
return (_c = tryCast((_b = declaration.importClause) == null ? void 0 : _b.namedBindings,
|
|
184467
|
+
return (_c = tryCast((_b = declaration.importClause) == null ? void 0 : _b.namedBindings, isNamespaceImport2)) == null ? void 0 : _c.name.text;
|
|
184468
184468
|
default:
|
|
184469
184469
|
return Debug.assertNever(declaration);
|
|
184470
184470
|
}
|
|
@@ -185085,7 +185085,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
|
|
|
185085
185085
|
}
|
|
185086
185086
|
}
|
|
185087
185087
|
if (convertExistingToTypeOnly) {
|
|
185088
|
-
const namedImports = tryCast(importClause.namedBindings,
|
|
185088
|
+
const namedImports = tryCast(importClause.namedBindings, isNamedImports2);
|
|
185089
185089
|
if (namedImports && namedImports.elements.length > 1) {
|
|
185090
185090
|
const sortState = ts_OrganizeImports_exports.getNamedImportSpecifierComparerWithDetection(importClause.parent, preferences, sourceFile);
|
|
185091
185091
|
if (sortState.isSorted !== false && aliasDeclaration.kind === 277 && namedImports.elements.indexOf(aliasDeclaration) !== 0) {
|
|
@@ -185140,7 +185140,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
|
|
|
185140
185140
|
(i) => (i == null ? void 0 : i.addAsTypeOnly) === 4
|
|
185141
185141
|
/* NotAllowed */
|
|
185142
185142
|
);
|
|
185143
|
-
const existingSpecifiers = clause.namedBindings && ((_a = tryCast(clause.namedBindings,
|
|
185143
|
+
const existingSpecifiers = clause.namedBindings && ((_a = tryCast(clause.namedBindings, isNamedImports2)) == null ? void 0 : _a.elements);
|
|
185144
185144
|
if (defaultImport) {
|
|
185145
185145
|
Debug.assert(!clause.name, "Cannot add a default import to an import clause that already has one");
|
|
185146
185146
|
changes.insertNodeAt(sourceFile, clause.getStart(sourceFile), factory.createIdentifier(defaultImport.name), { suffix: ", " });
|
|
@@ -191938,7 +191938,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
|
|
|
191938
191938
|
const { parent: parent2 } = name;
|
|
191939
191939
|
if (isImportEqualsDeclaration(parent2) && isExternalModuleReference(parent2.moduleReference)) {
|
|
191940
191940
|
return { importNode: parent2, name, moduleSpecifier: parent2.moduleReference.expression };
|
|
191941
|
-
} else if (
|
|
191941
|
+
} else if (isNamespaceImport2(parent2) && isImportDeclaration4(parent2.parent.parent)) {
|
|
191942
191942
|
const importNode = parent2.parent.parent;
|
|
191943
191943
|
return { importNode, name, moduleSpecifier: importNode.moduleSpecifier };
|
|
191944
191944
|
}
|
|
@@ -196483,7 +196483,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
|
|
|
196483
196483
|
if (couldBeTypeOnlyImportSpecifier(parent2, contextToken) && canCompleteFromNamedBindings(parent2.parent)) {
|
|
196484
196484
|
return parent2;
|
|
196485
196485
|
}
|
|
196486
|
-
if (
|
|
196486
|
+
if (isNamedImports2(parent2) || isNamespaceImport2(parent2)) {
|
|
196487
196487
|
if (!parent2.parent.isTypeOnly && (contextToken.kind === 19 || contextToken.kind === 102 || contextToken.kind === 28)) {
|
|
196488
196488
|
keywordCompletion = 156;
|
|
196489
196489
|
}
|
|
@@ -196537,7 +196537,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
|
|
|
196537
196537
|
function getPotentiallyInvalidImportSpecifier(namedBindings) {
|
|
196538
196538
|
var _a;
|
|
196539
196539
|
return find2(
|
|
196540
|
-
(_a = tryCast(namedBindings,
|
|
196540
|
+
(_a = tryCast(namedBindings, isNamedImports2)) == null ? void 0 : _a.elements,
|
|
196541
196541
|
(e) => {
|
|
196542
196542
|
var _a2;
|
|
196543
196543
|
return !e.propertyName && isStringANonContextualKeyword(e.name.text) && ((_a2 = findPrecedingToken(e.name.pos, namedBindings.getSourceFile(), namedBindings)) == null ? void 0 : _a2.kind) !== 28;
|
|
@@ -196551,7 +196551,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
|
|
|
196551
196551
|
if (!isModuleSpecifierMissingOrEmpty(namedBindings.parent.parent.moduleSpecifier) || namedBindings.parent.name) {
|
|
196552
196552
|
return false;
|
|
196553
196553
|
}
|
|
196554
|
-
if (
|
|
196554
|
+
if (isNamedImports2(namedBindings)) {
|
|
196555
196555
|
const invalidNamedImport = getPotentiallyInvalidImportSpecifier(namedBindings);
|
|
196556
196556
|
const validImports = invalidNamedImport ? namedBindings.elements.indexOf(invalidNamedImport) : namedBindings.elements.length;
|
|
196557
196557
|
return validImports < 2;
|
|
@@ -202489,7 +202489,7 @@ ${content}
|
|
|
202489
202489
|
name = void 0;
|
|
202490
202490
|
}
|
|
202491
202491
|
if (namedBindings) {
|
|
202492
|
-
if (
|
|
202492
|
+
if (isNamespaceImport2(namedBindings)) {
|
|
202493
202493
|
if (!isDeclarationUsed(namedBindings.name)) {
|
|
202494
202494
|
namedBindings = void 0;
|
|
202495
202495
|
}
|
|
@@ -202540,7 +202540,7 @@ ${content}
|
|
|
202540
202540
|
group2.defaultImports.push(importDeclaration);
|
|
202541
202541
|
}
|
|
202542
202542
|
if (namedBindings) {
|
|
202543
|
-
if (
|
|
202543
|
+
if (isNamespaceImport2(namedBindings)) {
|
|
202544
202544
|
group2.namespaceImports.push(importDeclaration);
|
|
202545
202545
|
} else {
|
|
202546
202546
|
group2.namedImports.push(importDeclaration);
|
|
@@ -202760,7 +202760,7 @@ ${content}
|
|
|
202760
202760
|
}
|
|
202761
202761
|
function tryGetNamedBindingElements(namedImport) {
|
|
202762
202762
|
var _a;
|
|
202763
|
-
return ((_a = namedImport.importClause) == null ? void 0 : _a.namedBindings) &&
|
|
202763
|
+
return ((_a = namedImport.importClause) == null ? void 0 : _a.namedBindings) && isNamedImports2(namedImport.importClause.namedBindings) ? namedImport.importClause.namedBindings.elements : void 0;
|
|
202764
202764
|
}
|
|
202765
202765
|
function detectModuleSpecifierCaseBySort(importDeclsByGroup, comparersToTest) {
|
|
202766
202766
|
const moduleSpecifiersByGroup = [];
|
|
@@ -202773,7 +202773,7 @@ ${content}
|
|
|
202773
202773
|
let bothNamedImports = false;
|
|
202774
202774
|
const importDeclsWithNamed = originalGroups.filter((i) => {
|
|
202775
202775
|
var _a, _b;
|
|
202776
|
-
const namedImports = (_b = tryCast((_a = i.importClause) == null ? void 0 : _a.namedBindings,
|
|
202776
|
+
const namedImports = (_b = tryCast((_a = i.importClause) == null ? void 0 : _a.namedBindings, isNamedImports2)) == null ? void 0 : _b.elements;
|
|
202777
202777
|
if (!(namedImports == null ? void 0 : namedImports.length)) return false;
|
|
202778
202778
|
if (!bothNamedImports && namedImports.some((n) => n.isTypeOnly) && namedImports.some((n) => !n.isTypeOnly)) {
|
|
202779
202779
|
bothNamedImports = true;
|
|
@@ -202783,7 +202783,7 @@ ${content}
|
|
|
202783
202783
|
if (importDeclsWithNamed.length === 0) return;
|
|
202784
202784
|
const namedImportsByDecl = importDeclsWithNamed.map((importDecl) => {
|
|
202785
202785
|
var _a, _b;
|
|
202786
|
-
return (_b = tryCast((_a = importDecl.importClause) == null ? void 0 : _a.namedBindings,
|
|
202786
|
+
return (_b = tryCast((_a = importDecl.importClause) == null ? void 0 : _a.namedBindings, isNamedImports2)) == null ? void 0 : _b.elements;
|
|
202787
202787
|
}).filter((elements) => elements !== void 0);
|
|
202788
202788
|
if (!bothNamedImports || typesToTest.length === 0) {
|
|
202789
202789
|
const sortState = detectCaseSensitivityBySort(namedImportsByDecl.map((i) => i.map((n) => n.name.text)), comparersToTest);
|
|
@@ -205702,7 +205702,7 @@ ${content}
|
|
|
205702
205702
|
return { suffix: ", " };
|
|
205703
205703
|
} else if (isParameter(before)) {
|
|
205704
205704
|
return isParameter(inserted) ? { suffix: ", " } : {};
|
|
205705
|
-
} else if (isStringLiteral4(before) && isImportDeclaration4(before.parent) ||
|
|
205705
|
+
} else if (isStringLiteral4(before) && isImportDeclaration4(before.parent) || isNamedImports2(before)) {
|
|
205706
205706
|
return { suffix: ", " };
|
|
205707
205707
|
} else if (isImportSpecifier(before)) {
|
|
205708
205708
|
return { suffix: "," + (blankLineBetween ? this.newLineCharacter : " ") };
|
|
@@ -212237,13 +212237,13 @@ ${options.prefix}` : "\n" : options.prefix
|
|
|
212237
212237
|
isNamedExportBindings: () => isNamedExportBindings,
|
|
212238
212238
|
isNamedExports: () => isNamedExports,
|
|
212239
212239
|
isNamedImportBindings: () => isNamedImportBindings,
|
|
212240
|
-
isNamedImports: () =>
|
|
212240
|
+
isNamedImports: () => isNamedImports2,
|
|
212241
212241
|
isNamedImportsOrExports: () => isNamedImportsOrExports,
|
|
212242
212242
|
isNamedTupleMember: () => isNamedTupleMember,
|
|
212243
212243
|
isNamespaceBody: () => isNamespaceBody,
|
|
212244
212244
|
isNamespaceExport: () => isNamespaceExport,
|
|
212245
212245
|
isNamespaceExportDeclaration: () => isNamespaceExportDeclaration,
|
|
212246
|
-
isNamespaceImport: () =>
|
|
212246
|
+
isNamespaceImport: () => isNamespaceImport2,
|
|
212247
212247
|
isNamespaceReexportDeclaration: () => isNamespaceReexportDeclaration,
|
|
212248
212248
|
isNewExpression: () => isNewExpression2,
|
|
212249
212249
|
isNewExpressionTarget: () => isNewExpressionTarget,
|
|
@@ -215469,8 +215469,8 @@ ${options.prefix}` : "\n" : options.prefix
|
|
|
215469
215469
|
}
|
|
215470
215470
|
};
|
|
215471
215471
|
for (const file of files) {
|
|
215472
|
-
const
|
|
215473
|
-
if (
|
|
215472
|
+
const basename4 = getBaseFileName(file);
|
|
215473
|
+
if (basename4 === "package.json" || basename4 === "bower.json") {
|
|
215474
215474
|
createProjectWatcher(
|
|
215475
215475
|
file,
|
|
215476
215476
|
"FileWatcher"
|
|
@@ -219138,8 +219138,8 @@ All files are: ${JSON.stringify(names)}`,
|
|
|
219138
219138
|
var _a;
|
|
219139
219139
|
const fileOrDirectoryPath = removeIgnoredPath(this.toPath(fileOrDirectory));
|
|
219140
219140
|
if (!fileOrDirectoryPath) return;
|
|
219141
|
-
const
|
|
219142
|
-
if (((_a = result.affectedModuleSpecifierCacheProjects) == null ? void 0 : _a.size) && (
|
|
219141
|
+
const basename4 = getBaseFileName(fileOrDirectoryPath);
|
|
219142
|
+
if (((_a = result.affectedModuleSpecifierCacheProjects) == null ? void 0 : _a.size) && (basename4 === "package.json" || basename4 === "node_modules")) {
|
|
219143
219143
|
result.affectedModuleSpecifierCacheProjects.forEach((project) => {
|
|
219144
219144
|
var _a2;
|
|
219145
219145
|
(_a2 = project.getModuleSpecifierCache()) == null ? void 0 : _a2.clear();
|
|
@@ -227103,7 +227103,51 @@ function parseStatements(cursor, errors, opts) {
|
|
|
227103
227103
|
"cols",
|
|
227104
227104
|
"rows",
|
|
227105
227105
|
"wrap",
|
|
227106
|
-
"datetime"
|
|
227106
|
+
"datetime",
|
|
227107
|
+
// SVG attributes. `path d "M4 7h16"` was read as text "path" plus a
|
|
227108
|
+
// <d> element, because `d` was not a known attribute name -- so an
|
|
227109
|
+
// inline icon could not be written at all.
|
|
227110
|
+
"d",
|
|
227111
|
+
"cx",
|
|
227112
|
+
"cy",
|
|
227113
|
+
"r",
|
|
227114
|
+
"rx",
|
|
227115
|
+
"ry",
|
|
227116
|
+
"x",
|
|
227117
|
+
"y",
|
|
227118
|
+
"x1",
|
|
227119
|
+
"y1",
|
|
227120
|
+
"x2",
|
|
227121
|
+
"y2",
|
|
227122
|
+
"points",
|
|
227123
|
+
"viewBox",
|
|
227124
|
+
"fill",
|
|
227125
|
+
"stroke",
|
|
227126
|
+
"stroke-width",
|
|
227127
|
+
"stroke-linecap",
|
|
227128
|
+
"stroke-linejoin",
|
|
227129
|
+
"stroke-dasharray",
|
|
227130
|
+
"stroke-dashoffset",
|
|
227131
|
+
"fill-rule",
|
|
227132
|
+
"clip-rule",
|
|
227133
|
+
"clip-path",
|
|
227134
|
+
"transform",
|
|
227135
|
+
"opacity",
|
|
227136
|
+
"fill-opacity",
|
|
227137
|
+
"stroke-opacity",
|
|
227138
|
+
"stop-color",
|
|
227139
|
+
"offset",
|
|
227140
|
+
"gradientUnits",
|
|
227141
|
+
"gradientTransform",
|
|
227142
|
+
"preserveAspectRatio",
|
|
227143
|
+
"text-anchor",
|
|
227144
|
+
"dominant-baseline",
|
|
227145
|
+
"font-size",
|
|
227146
|
+
"font-family",
|
|
227147
|
+
"marker-end",
|
|
227148
|
+
"marker-start",
|
|
227149
|
+
"mask",
|
|
227150
|
+
"xmlns"
|
|
227107
227151
|
]);
|
|
227108
227152
|
const isSelector = nextTok && (nextTok.type === "DOT" || nextTok.type === "HASH" || nextTok.type === "LBRACE" || nextTok.type === "STRING" || // `width 800` — a bare IDENT followed by a NUMBER is a prop/value
|
|
227109
227153
|
// pair (builtin component props accept numbers), not text content.
|
|
@@ -227670,6 +227714,15 @@ function parseElement(cursor, errors, state, parseBody) {
|
|
|
227670
227714
|
const tagToken = cursor.advance();
|
|
227671
227715
|
if (!tagToken) return null;
|
|
227672
227716
|
const tag2 = tagToken.value;
|
|
227717
|
+
if (tag2 && /^[A-Za-z][A-Za-z0-9-]*$/.test(tag2)) {
|
|
227718
|
+
errors.add(new CompilerError(
|
|
227719
|
+
"raw HTML is not supported in .tw -- write it in TW syntax: " + tag2 + ' { ... }. For an inline icon use svg/path/circle with attributes on the tag line; for a script body use script type "..." { ... }; for markup that comes from data use {@html expr}',
|
|
227720
|
+
tagToken.pos.line,
|
|
227721
|
+
tagToken.pos.col,
|
|
227722
|
+
"TW123",
|
|
227723
|
+
"error"
|
|
227724
|
+
));
|
|
227725
|
+
}
|
|
227673
227726
|
const controlFlowTags = {
|
|
227674
227727
|
"if": "if",
|
|
227675
227728
|
"for": "for",
|
|
@@ -236327,7 +236380,7 @@ var init_types4 = __esm({
|
|
|
236327
236380
|
var TW_VERSION, TW_GENERATOR_META;
|
|
236328
236381
|
var init_version = __esm({
|
|
236329
236382
|
"../../packages/compiler/tw/codegen/version.ts"() {
|
|
236330
|
-
TW_VERSION = "2.0.
|
|
236383
|
+
TW_VERSION = "2.0.5";
|
|
236331
236384
|
TW_GENERATOR_META = `<meta name="generator" content="TW Framework ${TW_VERSION}">`;
|
|
236332
236385
|
}
|
|
236333
236386
|
});
|
|
@@ -237933,6 +237986,39 @@ function validatePlainCss(src, filePath) {
|
|
|
237933
237986
|
checkDecl();
|
|
237934
237987
|
return src;
|
|
237935
237988
|
}
|
|
237989
|
+
function collapseWhitespace(text) {
|
|
237990
|
+
let out = "";
|
|
237991
|
+
let quote = null;
|
|
237992
|
+
let pendingSpace = false;
|
|
237993
|
+
for (let i = 0; i < text.length; i++) {
|
|
237994
|
+
const ch = text[i];
|
|
237995
|
+
if (quote) {
|
|
237996
|
+
out += ch;
|
|
237997
|
+
if (ch === "\\" && i + 1 < text.length) {
|
|
237998
|
+
out += text[i + 1];
|
|
237999
|
+
i++;
|
|
238000
|
+
continue;
|
|
238001
|
+
}
|
|
238002
|
+
if (ch === quote) quote = null;
|
|
238003
|
+
continue;
|
|
238004
|
+
}
|
|
238005
|
+
if (ch === '"' || ch === "'") {
|
|
238006
|
+
if (pendingSpace && out) out += " ";
|
|
238007
|
+
pendingSpace = false;
|
|
238008
|
+
quote = ch;
|
|
238009
|
+
out += ch;
|
|
238010
|
+
continue;
|
|
238011
|
+
}
|
|
238012
|
+
if (/\s/.test(ch)) {
|
|
238013
|
+
pendingSpace = true;
|
|
238014
|
+
continue;
|
|
238015
|
+
}
|
|
238016
|
+
if (pendingSpace && out) out += " ";
|
|
238017
|
+
pendingSpace = false;
|
|
238018
|
+
out += ch;
|
|
238019
|
+
}
|
|
238020
|
+
return out;
|
|
238021
|
+
}
|
|
237936
238022
|
function compileDecl(decl) {
|
|
237937
238023
|
const trimmed = decl.trim();
|
|
237938
238024
|
if (!trimmed) return "";
|
|
@@ -237940,10 +238026,10 @@ function compileDecl(decl) {
|
|
|
237940
238026
|
if (cssForm) return trimmed.replace(/^([-\w]+)\s*:\s*/, "$1: ");
|
|
237941
238027
|
const spaceIdx = trimmed.search(/[\s]/);
|
|
237942
238028
|
if (spaceIdx === -1) {
|
|
237943
|
-
return
|
|
238029
|
+
return "";
|
|
237944
238030
|
}
|
|
237945
238031
|
const prop = trimmed.slice(0, spaceIdx);
|
|
237946
|
-
const value = trimmed.slice(spaceIdx).trim();
|
|
238032
|
+
const value = collapseWhitespace(trimmed.slice(spaceIdx).trim());
|
|
237947
238033
|
const full = TSS_SHORTHANDS2[prop] ?? prop;
|
|
237948
238034
|
return `${full}: ${value}`;
|
|
237949
238035
|
}
|
|
@@ -238101,26 +238187,47 @@ function __twCompileTSSInner(source) {
|
|
|
238101
238187
|
if (!changed) break;
|
|
238102
238188
|
}
|
|
238103
238189
|
}
|
|
238104
|
-
const
|
|
238190
|
+
const root = [];
|
|
238105
238191
|
const stack = [];
|
|
238106
|
-
const declsByLevel = [];
|
|
238107
238192
|
let buf = "";
|
|
238108
|
-
const
|
|
238109
|
-
|
|
238110
|
-
|
|
238111
|
-
for (let i2 = wrapStack.length - 1; i2 >= 0; i2--) {
|
|
238112
|
-
if (wrapStack[i2].startsWith("@")) rule = `${wrapStack[i2]} { ${rule} }`;
|
|
238113
|
-
}
|
|
238114
|
-
rules.push(rule);
|
|
238115
|
-
};
|
|
238193
|
+
const current2 = () => stack.length ? stack[stack.length - 1] : null;
|
|
238194
|
+
const statements = [];
|
|
238195
|
+
const isStatementAtRule = (t3) => /^@(import|charset|namespace|layer)\b/.test(t3);
|
|
238116
238196
|
const pushDecl = (text) => {
|
|
238117
|
-
const
|
|
238118
|
-
if (
|
|
238197
|
+
const raw = text.trim();
|
|
238198
|
+
if (!raw) return;
|
|
238199
|
+
if (isStatementAtRule(raw)) {
|
|
238200
|
+
statements.push(raw.endsWith(";") ? raw : raw + ";");
|
|
238201
|
+
return;
|
|
238202
|
+
}
|
|
238203
|
+
const d = compileDecl(raw);
|
|
238204
|
+
if (!d) return;
|
|
238205
|
+
const node = current2();
|
|
238206
|
+
if (node) node.decls.push(d);
|
|
238207
|
+
else root.push({ kind: "rule", selector: "*", decls: [d], children: [] });
|
|
238119
238208
|
};
|
|
238120
|
-
const isDeclLine = (l) => /^[
|
|
238209
|
+
const isDeclLine = (l) => /^(--[A-Za-z][\w-]*|-?[A-Za-z][\w-]*)(\s|:)/.test(l) && !/^[>+~]/.test(l);
|
|
238121
238210
|
let i = 0;
|
|
238211
|
+
let quote = null;
|
|
238122
238212
|
while (i < src.length) {
|
|
238123
238213
|
const ch = src[i];
|
|
238214
|
+
if (quote) {
|
|
238215
|
+
buf += ch;
|
|
238216
|
+
if (ch === "\\" && i + 1 < src.length) {
|
|
238217
|
+
buf += src[i + 1];
|
|
238218
|
+
i += 2;
|
|
238219
|
+
continue;
|
|
238220
|
+
}
|
|
238221
|
+
if (ch === quote) quote = null;
|
|
238222
|
+
i++;
|
|
238223
|
+
continue;
|
|
238224
|
+
}
|
|
238225
|
+
if (ch === '"' || ch === "'") {
|
|
238226
|
+
quote = ch;
|
|
238227
|
+
buf += ch;
|
|
238228
|
+
i++;
|
|
238229
|
+
continue;
|
|
238230
|
+
}
|
|
238124
238231
|
if (ch === "{") {
|
|
238125
238232
|
let sel = buf.trim();
|
|
238126
238233
|
buf = "";
|
|
@@ -238133,53 +238240,38 @@ function __twCompileTSSInner(source) {
|
|
|
238133
238240
|
const last = lines[lines.length - 1];
|
|
238134
238241
|
const prior = lines.slice(0, -1);
|
|
238135
238242
|
const priorComplete = !/[(,]\s*$/.test(prior[prior.length - 1] ?? "");
|
|
238136
|
-
if (priorComplete && prior.every(isDeclLine)
|
|
238243
|
+
if (priorComplete && prior.every(isDeclLine)) {
|
|
238137
238244
|
for (const p of prior) pushDecl(p);
|
|
238138
238245
|
sel = last;
|
|
238139
238246
|
}
|
|
238140
238247
|
}
|
|
238141
|
-
const parent =
|
|
238142
|
-
let full;
|
|
238248
|
+
const parent = current2();
|
|
238143
238249
|
if (sel.startsWith("@")) {
|
|
238144
|
-
|
|
238145
|
-
|
|
238146
|
-
|
|
238250
|
+
const node = { kind: "at", head: sel, decls: [], children: [] };
|
|
238251
|
+
(parent ? parent.children : root).push(node);
|
|
238252
|
+
stack.push(node);
|
|
238147
238253
|
} else {
|
|
238148
|
-
full = sel;
|
|
238254
|
+
const full = parent && parent.kind === "rule" ? combineSelector(parent.selector, sel) : sel;
|
|
238255
|
+
const node = { kind: "rule", selector: full, decls: [], children: [] };
|
|
238256
|
+
(parent ? parent.children : root).push(node);
|
|
238257
|
+
stack.push(node);
|
|
238149
238258
|
}
|
|
238150
|
-
stack.push(full);
|
|
238151
|
-
declsByLevel.push([]);
|
|
238152
238259
|
i++;
|
|
238153
238260
|
} else if (ch === "}") {
|
|
238154
238261
|
if (buf.trim()) {
|
|
238155
238262
|
const blines = buf.split(/\n+/).map((l) => l.trim()).filter(Boolean);
|
|
238156
|
-
|
|
238263
|
+
const valueContinues = blines.some((l) => /[(,]\s*$/.test(l));
|
|
238264
|
+
if (blines.length > 1 && !valueContinues) {
|
|
238157
238265
|
for (const l of blines) pushDecl(l);
|
|
238158
238266
|
} else {
|
|
238159
238267
|
pushDecl(buf);
|
|
238160
238268
|
}
|
|
238161
238269
|
}
|
|
238162
238270
|
buf = "";
|
|
238163
|
-
|
|
238164
|
-
const decls = declsByLevel.pop() ?? [];
|
|
238165
|
-
if (level) {
|
|
238166
|
-
if (level.startsWith("@") && decls.length > 0) {
|
|
238167
|
-
let realSel = null;
|
|
238168
|
-
for (let j = stack.length - 1; j >= 0; j--) {
|
|
238169
|
-
if (!stack[j].startsWith("@")) {
|
|
238170
|
-
realSel = stack[j];
|
|
238171
|
-
break;
|
|
238172
|
-
}
|
|
238173
|
-
}
|
|
238174
|
-
if (realSel) emit4(realSel, decls, [...stack, level]);
|
|
238175
|
-
else emit4(level, decls, stack);
|
|
238176
|
-
} else {
|
|
238177
|
-
emit4(level, decls, stack);
|
|
238178
|
-
}
|
|
238179
|
-
}
|
|
238271
|
+
stack.pop();
|
|
238180
238272
|
i++;
|
|
238181
238273
|
} else if (ch === ";") {
|
|
238182
|
-
pushDecl(buf);
|
|
238274
|
+
if (buf.trim()) pushDecl(buf);
|
|
238183
238275
|
buf = "";
|
|
238184
238276
|
i++;
|
|
238185
238277
|
} else {
|
|
@@ -238187,11 +238279,24 @@ function __twCompileTSSInner(source) {
|
|
|
238187
238279
|
i++;
|
|
238188
238280
|
}
|
|
238189
238281
|
}
|
|
238190
|
-
if (buf.trim())
|
|
238191
|
-
|
|
238192
|
-
if (
|
|
238193
|
-
|
|
238194
|
-
|
|
238282
|
+
if (buf.trim()) pushDecl(buf);
|
|
238283
|
+
const ser = (node, parentSel) => {
|
|
238284
|
+
if (node.kind === "rule") {
|
|
238285
|
+
const lines = [];
|
|
238286
|
+
if (node.decls.length) lines.push(node.selector + " { " + node.decls.join("; ") + " }");
|
|
238287
|
+
for (const c of node.children) lines.push(...ser(c, node.selector));
|
|
238288
|
+
return lines;
|
|
238289
|
+
}
|
|
238290
|
+
const inner = [];
|
|
238291
|
+
if (node.decls.length) {
|
|
238292
|
+
inner.push(parentSel ? parentSel + " { " + node.decls.join("; ") + " }" : node.decls.join("; "));
|
|
238293
|
+
}
|
|
238294
|
+
for (const c of node.children) inner.push(...ser(c, parentSel));
|
|
238295
|
+
return [node.head + " { " + inner.join(" ") + " }"];
|
|
238296
|
+
};
|
|
238297
|
+
const out = [...statements];
|
|
238298
|
+
for (const node of root) out.push(...ser(node, ""));
|
|
238299
|
+
return out.join("\n");
|
|
238195
238300
|
}
|
|
238196
238301
|
var TSS_SHORTHANDS2;
|
|
238197
238302
|
var init_tss = __esm({
|
|
@@ -238235,6 +238340,12 @@ var init_tss = __esm({
|
|
|
238235
238340
|
"br-t": "border-top-left-radius",
|
|
238236
238341
|
bxsh: "box-shadow",
|
|
238237
238342
|
bxz: "box-sizing",
|
|
238343
|
+
// Documented in docs/tss-syntax.md but never implemented, so `br-tl 4px`
|
|
238344
|
+
// emitted the literal property name `br-tl` and the corner stayed square.
|
|
238345
|
+
"br-tl": "border-top-left-radius",
|
|
238346
|
+
"br-tr": "border-top-right-radius",
|
|
238347
|
+
"br-bl": "border-bottom-left-radius",
|
|
238348
|
+
"br-br": "border-bottom-right-radius",
|
|
238238
238349
|
// `box` is the documented box-sizing shorthand (docs/tss-syntax.md).
|
|
238239
238350
|
box: "box-sizing",
|
|
238240
238351
|
// typography
|
|
@@ -238276,7 +238387,13 @@ var init_tss = __esm({
|
|
|
238276
238387
|
tr: "transition",
|
|
238277
238388
|
tf: "transform",
|
|
238278
238389
|
us: "user-select",
|
|
238279
|
-
pe: "pointer-events"
|
|
238390
|
+
pe: "pointer-events",
|
|
238391
|
+
// Also documented, also missing.
|
|
238392
|
+
fl: "float",
|
|
238393
|
+
cl: "clear",
|
|
238394
|
+
dir: "direction",
|
|
238395
|
+
ww: "word-wrap",
|
|
238396
|
+
va: "vertical-align"
|
|
238280
238397
|
};
|
|
238281
238398
|
}
|
|
238282
238399
|
});
|
|
@@ -239416,7 +239533,9 @@ function generateElement(el, ctx) {
|
|
|
239416
239533
|
if (el.children.length === 0 && el.selfClosing) {
|
|
239417
239534
|
return `<${tag2}${attrPrefix}></${tag2}>`;
|
|
239418
239535
|
}
|
|
239419
|
-
const
|
|
239536
|
+
const isRawText = tag2 === "script" || tag2 === "style";
|
|
239537
|
+
const childCtx = isRawText ? { ...ctx, rawText: true } : ctx;
|
|
239538
|
+
const childrenHTML = el.children.map((c) => generateNode(c, childCtx)).join("");
|
|
239420
239539
|
return `<${tag2}${attrPrefix}>${childrenHTML}</${tag2}>`;
|
|
239421
239540
|
}
|
|
239422
239541
|
function renderAttrs(el, ctx) {
|
|
@@ -239547,10 +239666,30 @@ function wrapInterpolations(rendered, raw) {
|
|
|
239547
239666
|
}
|
|
239548
239667
|
return out;
|
|
239549
239668
|
}
|
|
239669
|
+
function generateTrustedHtml(text, ctx) {
|
|
239670
|
+
const src = text.isInterpolated ? `{${text.value}}` : String(text.value ?? "");
|
|
239671
|
+
let out = "";
|
|
239672
|
+
let i = 0;
|
|
239673
|
+
const re = /\{@html\s+([^}]*)\}/g;
|
|
239674
|
+
let m;
|
|
239675
|
+
while (m = re.exec(src)) {
|
|
239676
|
+
out += escapeHTML(interpolate2(src.slice(i, m.index), ctx.stateVars));
|
|
239677
|
+
out += String(interpolate2(`{${m[1]}}`, ctx.stateVars));
|
|
239678
|
+
i = m.index + m[0].length;
|
|
239679
|
+
}
|
|
239680
|
+
out += escapeHTML(interpolate2(src.slice(i), ctx.stateVars));
|
|
239681
|
+
return out;
|
|
239682
|
+
}
|
|
239550
239683
|
function generateText(text, ctx) {
|
|
239551
239684
|
ctx_global_interactive = ctx.interactive === true;
|
|
239552
239685
|
ctx_global_inhead = ctx.inHead === true;
|
|
239553
239686
|
lastStateVars = ctx.stateVars;
|
|
239687
|
+
if (text.value && String(text.value).includes("@html")) return generateTrustedHtml(text, ctx);
|
|
239688
|
+
if (ctx.rawText) {
|
|
239689
|
+
if (text.isInterpolated) return String(interpolate2(`{${text.value}}`, ctx.stateVars));
|
|
239690
|
+
if (text.value && /\{[^}]+\}/.test(text.value)) return String(interpolate2(text.value, ctx.stateVars));
|
|
239691
|
+
return text.value ?? "";
|
|
239692
|
+
}
|
|
239554
239693
|
if (text.isInterpolated) {
|
|
239555
239694
|
if (ctx.interactive && ctx.inHead !== true) {
|
|
239556
239695
|
return `<span data-tw-i="${escapeHTML(text.value)}"${dataTwSFor(text.value)}>${escapeHTML(interpolate2(`{${text.value}}`, ctx.stateVars))}</span>`;
|
|
@@ -240851,7 +240990,7 @@ function minifyHTML2(html, options) {
|
|
|
240851
240990
|
result = removeComments(result);
|
|
240852
240991
|
}
|
|
240853
240992
|
if (opts.collapseWhitespace) {
|
|
240854
|
-
result =
|
|
240993
|
+
result = collapseWhitespace2(result);
|
|
240855
240994
|
}
|
|
240856
240995
|
if (opts.removeRedundantAttrs) {
|
|
240857
240996
|
result = removeRedundantAttrs(result);
|
|
@@ -240874,7 +241013,7 @@ function removeComments(html) {
|
|
|
240874
241013
|
if (html.indexOf("<!--") === -1) return html;
|
|
240875
241014
|
return html.replace(/<!--(?!\[if\s)[\s\S]*?-->/g, "");
|
|
240876
241015
|
}
|
|
240877
|
-
function
|
|
241016
|
+
function collapseWhitespace2(html) {
|
|
240878
241017
|
const result = [];
|
|
240879
241018
|
let pos = 0;
|
|
240880
241019
|
let inPreserved = false;
|
|
@@ -243502,6 +243641,15 @@ function generateWithLayout(layoutProgram, pageProgram, stateVars) {
|
|
|
243502
243641
|
function generateWithLayoutChain(layoutPrograms, pageProgram, stateVars) {
|
|
243503
243642
|
const seedCtx = (ctx2) => {
|
|
243504
243643
|
if (stateVars) ctx2.stateVars = { ...stateVars };
|
|
243644
|
+
for (const lp of layoutPrograms ?? []) {
|
|
243645
|
+
for (const dir of lp.directives || []) {
|
|
243646
|
+
if (dir.type === "StateDirective") {
|
|
243647
|
+
for (const decl of dir.declarations || []) {
|
|
243648
|
+
ctx2.stateVars[decl.name] = stateLiteralForRender(decl.value);
|
|
243649
|
+
}
|
|
243650
|
+
}
|
|
243651
|
+
}
|
|
243652
|
+
}
|
|
243505
243653
|
for (const dir of pageProgram.directives || []) {
|
|
243506
243654
|
if (dir.type === "StateDirective") {
|
|
243507
243655
|
for (const decl of dir.declarations || []) {
|
|
@@ -244123,7 +244271,7 @@ var init_codes = __esm({
|
|
|
244123
244271
|
TW105: { message: "Server blocks in layouts are not supported yet", severity: "error", category: "semantic" },
|
|
244124
244272
|
TW106: { message: "Request context (headers/cookies/query/params) is not available in a static server block", severity: "error", category: "semantic" },
|
|
244125
244273
|
TW107: { message: "getSession()/requireUser() are not available in a static page's server block", severity: "error", category: "semantic" },
|
|
244126
|
-
TW108: { message: "redirect()
|
|
244274
|
+
TW108: { message: "redirect() is not available in a static page's server block", severity: "error", category: "semantic" },
|
|
244127
244275
|
TW109: { message: "redirect() target must be a same-origin internal path", severity: "error", category: "semantic" },
|
|
244128
244276
|
TW110: { message: "A cached fetch must not set an Authorization, Proxy-Authorization or Cookie header", severity: "error", category: "semantic" },
|
|
244129
244277
|
TW111: { message: "A cached page's server block cannot read headers, cookies, getSession() or requireUser()", severity: "error", category: "semantic" },
|
|
@@ -244137,6 +244285,8 @@ var init_codes = __esm({
|
|
|
244137
244285
|
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
244286
|
TW121: { message: "The same name is declared by more than one state { } block (the earlier one wins)", severity: "warning", category: "semantic" },
|
|
244139
244287
|
TW122: { message: "More than one default slot in the same component -- a caller's default content has no defined destination", severity: "warning", category: "semantic" },
|
|
244288
|
+
TW123: { message: "Raw HTML is not supported in .tw -- write the element in TW syntax", severity: "error", category: "syntax" },
|
|
244289
|
+
TW125: { message: "An import's local name is also a server-block built-in, so the import would be silently overwritten", severity: "error", category: "semantic" },
|
|
244140
244290
|
// Codes thrown outside the rule engine. TW303 comes from the stylesheet
|
|
244141
244291
|
// parser (codegen/tss.ts); TW000 is the generic fallback used when an error
|
|
244142
244292
|
// carries no code of its own.
|
|
@@ -244337,8 +244487,17 @@ function checkPerformance(program, filePath, diags) {
|
|
|
244337
244487
|
]));
|
|
244338
244488
|
}
|
|
244339
244489
|
if (isElement(node) && node.tag.toLowerCase() === "img") {
|
|
244490
|
+
const attr = (n) => node.attrs.find((a) => a.name === n)?.value;
|
|
244340
244491
|
const hasLazy = node.attrs.some((a) => a.name === "loading" && a.value === "lazy");
|
|
244341
|
-
|
|
244492
|
+
const isEager = String(attr("loading") ?? "") === "eager" || String(attr("fetchpriority") ?? "") === "high";
|
|
244493
|
+
const px = (v) => {
|
|
244494
|
+
const n = parseFloat(String(v ?? ""));
|
|
244495
|
+
return Number.isFinite(n) ? n : null;
|
|
244496
|
+
};
|
|
244497
|
+
const w = px(attr("width"));
|
|
244498
|
+
const h3 = px(attr("height"));
|
|
244499
|
+
const isSmallIcon = w !== null && h3 !== null && w <= 32 && h3 <= 32;
|
|
244500
|
+
if (!hasLazy && !isEager && !isSmallIcon) {
|
|
244342
244501
|
diags.push(createDiagnostic("TW054", node.line, node.col, filePath, void 0, [
|
|
244343
244502
|
'Add loading="lazy" for below-fold images'
|
|
244344
244503
|
]));
|
|
@@ -244811,9 +244970,97 @@ var init_rules = __esm({
|
|
|
244811
244970
|
"noframes",
|
|
244812
244971
|
"area",
|
|
244813
244972
|
"map",
|
|
244814
|
-
"marquee"
|
|
244973
|
+
"marquee",
|
|
244974
|
+
// Inline text tags. `b` and `i` were missing, so breadcrumbs and emphasis
|
|
244975
|
+
// collected a TW003 per tag on markup that renders perfectly well.
|
|
244976
|
+
"b",
|
|
244977
|
+
"i",
|
|
244978
|
+
"em",
|
|
244979
|
+
"strong",
|
|
244980
|
+
"small",
|
|
244981
|
+
"u",
|
|
244982
|
+
"s",
|
|
244983
|
+
"ins",
|
|
244984
|
+
"del",
|
|
244985
|
+
"sub",
|
|
244986
|
+
"sup",
|
|
244987
|
+
"nobr",
|
|
244988
|
+
"big",
|
|
244989
|
+
"tt",
|
|
244990
|
+
// SVG children -- the same warning fired on inline icons.
|
|
244991
|
+
"circle",
|
|
244992
|
+
"path",
|
|
244993
|
+
"rect",
|
|
244994
|
+
"line",
|
|
244995
|
+
"polyline",
|
|
244996
|
+
"polygon",
|
|
244997
|
+
"g",
|
|
244998
|
+
"defs",
|
|
244999
|
+
"use",
|
|
245000
|
+
"text",
|
|
245001
|
+
"ellipse",
|
|
245002
|
+
"tspan",
|
|
245003
|
+
"clippath",
|
|
245004
|
+
"lineargradient",
|
|
245005
|
+
"radialgradient",
|
|
245006
|
+
"stop",
|
|
245007
|
+
"mask",
|
|
245008
|
+
"pattern",
|
|
245009
|
+
"symbol",
|
|
245010
|
+
"marker",
|
|
245011
|
+
"filter",
|
|
245012
|
+
"foreignobject"
|
|
244815
245013
|
]);
|
|
244816
245014
|
HTML_ATTRIBUTES2 = /* @__PURE__ */ new Set([
|
|
245015
|
+
// SVG attributes. This rule keeps its own copy of the list, and it was missing
|
|
245016
|
+
// every SVG name, so an inline icon raised a TW006 per attribute.
|
|
245017
|
+
"d",
|
|
245018
|
+
"cx",
|
|
245019
|
+
"cy",
|
|
245020
|
+
"r",
|
|
245021
|
+
"rx",
|
|
245022
|
+
"ry",
|
|
245023
|
+
"x",
|
|
245024
|
+
"y",
|
|
245025
|
+
"x1",
|
|
245026
|
+
"y1",
|
|
245027
|
+
"x2",
|
|
245028
|
+
"y2",
|
|
245029
|
+
"points",
|
|
245030
|
+
"viewBox",
|
|
245031
|
+
"fill",
|
|
245032
|
+
"stroke",
|
|
245033
|
+
"stroke-width",
|
|
245034
|
+
"stroke-linecap",
|
|
245035
|
+
"stroke-linejoin",
|
|
245036
|
+
"stroke-dasharray",
|
|
245037
|
+
"stroke-dashoffset",
|
|
245038
|
+
"stroke-opacity",
|
|
245039
|
+
"fill-opacity",
|
|
245040
|
+
"fill-rule",
|
|
245041
|
+
"clip-rule",
|
|
245042
|
+
"clip-path",
|
|
245043
|
+
"opacity",
|
|
245044
|
+
"transform",
|
|
245045
|
+
"preserveAspectRatio",
|
|
245046
|
+
"xmlns",
|
|
245047
|
+
"gradientUnits",
|
|
245048
|
+
"gradientTransform",
|
|
245049
|
+
"offset",
|
|
245050
|
+
"stop-color",
|
|
245051
|
+
"stop-opacity",
|
|
245052
|
+
"text-anchor",
|
|
245053
|
+
"dominant-baseline",
|
|
245054
|
+
"font-family",
|
|
245055
|
+
"font-size",
|
|
245056
|
+
"font-weight",
|
|
245057
|
+
"font-style",
|
|
245058
|
+
"letter-spacing",
|
|
245059
|
+
"marker-start",
|
|
245060
|
+
"marker-mid",
|
|
245061
|
+
"marker-end",
|
|
245062
|
+
"mask",
|
|
245063
|
+
"pathLength",
|
|
244817
245064
|
"accept",
|
|
244818
245065
|
"accept-charset",
|
|
244819
245066
|
"accesskey",
|
|
@@ -248017,20 +248264,36 @@ var node_import_exports = {};
|
|
|
248017
248264
|
__export(node_import_exports, {
|
|
248018
248265
|
twImportTs: () => twImportTs
|
|
248019
248266
|
});
|
|
248020
|
-
import { join as join15 } from "node:path";
|
|
248267
|
+
import { join as join15, dirname as dirname9, basename as basename2, extname as extname6 } from "node:path";
|
|
248021
248268
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
248022
248269
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
248023
|
-
|
|
248270
|
+
import { writeFileSync as writeFileSync5, rmSync as rmSync2 } from "node:fs";
|
|
248271
|
+
async function twImportTs(tsPath, bust, opts) {
|
|
248024
248272
|
const q = bust ? "?v=" + bust : "";
|
|
248273
|
+
const override = opts?.source;
|
|
248025
248274
|
if (!globalThis.__TW_NODE) {
|
|
248026
|
-
return import(tsPath + q);
|
|
248275
|
+
if (override === void 0) return import(tsPath + q);
|
|
248276
|
+
const ext = extname6(tsPath) || ".ts";
|
|
248277
|
+
const unique = process.pid + "-" + (overrideSeq++).toString(36) + "-" + Math.random().toString(36).slice(2, 8);
|
|
248278
|
+
const tmpPath = join15(dirname9(tsPath), "." + basename2(tsPath, ext) + ".tw-override-" + unique + ext);
|
|
248279
|
+
writeFileSync5(tmpPath, override, "utf-8");
|
|
248280
|
+
try {
|
|
248281
|
+
return await import(tmpPath + q);
|
|
248282
|
+
} finally {
|
|
248283
|
+
try {
|
|
248284
|
+
rmSync2(tmpPath, { force: true });
|
|
248285
|
+
} catch {
|
|
248286
|
+
}
|
|
248287
|
+
}
|
|
248027
248288
|
}
|
|
248028
248289
|
const esbuildMain = globalThis.__TW_ESBUILD_MODULE;
|
|
248029
248290
|
const esbuild = await (esbuildMain ? import(esbuildMain) : import("esbuild"));
|
|
248030
248291
|
const safe = tsPath.replace(/[^a-zA-Z0-9]/g, "_").slice(-120);
|
|
248031
248292
|
const cachePath = join15(tmpdir2(), "tw-" + safe + (bust ? "-" + bust : "") + ".mjs");
|
|
248032
248293
|
await esbuild.build({
|
|
248033
|
-
|
|
248294
|
+
// stdin + resolveDir keeps relative imports resolving from the original
|
|
248295
|
+
// file's directory, and sourcefile keeps error locations on the real file.
|
|
248296
|
+
...override === void 0 ? { entryPoints: [tsPath] } : { stdin: { contents: override, resolveDir: dirname9(tsPath), sourcefile: tsPath, loader: extname6(tsPath) === ".js" ? "js" : "ts" } },
|
|
248034
248297
|
bundle: true,
|
|
248035
248298
|
format: "esm",
|
|
248036
248299
|
platform: "node",
|
|
@@ -248040,12 +248303,15 @@ async function twImportTs(tsPath, bust) {
|
|
|
248040
248303
|
});
|
|
248041
248304
|
return import(pathToFileURL2(cachePath).href + q);
|
|
248042
248305
|
}
|
|
248306
|
+
var overrideSeq;
|
|
248043
248307
|
var init_node_import = __esm({
|
|
248044
248308
|
"../../packages/shared/tw/node-import.ts"() {
|
|
248309
|
+
overrideSeq = 0;
|
|
248045
248310
|
}
|
|
248046
248311
|
});
|
|
248047
248312
|
|
|
248048
248313
|
// ../../packages/compiler/tw/server-blocks/index.ts
|
|
248314
|
+
import { readFileSync as readFileSync8, existsSync as existsSync11 } from "node:fs";
|
|
248049
248315
|
function encodeServerValue(v) {
|
|
248050
248316
|
if (v === void 0) return "";
|
|
248051
248317
|
if (v === null) return "null";
|
|
@@ -248302,41 +248568,45 @@ function withTimeout2(p, ms, label) {
|
|
|
248302
248568
|
});
|
|
248303
248569
|
});
|
|
248304
248570
|
}
|
|
248305
|
-
function
|
|
248306
|
-
const
|
|
248307
|
-
const s = stmt.replace(/^import\s+(type\s+)?/, "");
|
|
248571
|
+
function importBindings(stmt) {
|
|
248572
|
+
const out = [];
|
|
248573
|
+
const s = stmt.replace(/^import\s+(type\s+)?/, "").trim();
|
|
248308
248574
|
const fromIdx = s.lastIndexOf(" from ");
|
|
248309
|
-
if (fromIdx < 0) return
|
|
248575
|
+
if (fromIdx < 0) return out;
|
|
248310
248576
|
const clause = s.slice(0, fromIdx).trim();
|
|
248311
|
-
if (clause.startsWith("{")) {
|
|
248312
|
-
|
|
248577
|
+
if (!clause.startsWith("{") && !clause.startsWith("*")) {
|
|
248578
|
+
const first = clause.split(",")[0].trim();
|
|
248579
|
+
if (first && /^[A-Za-z_$]/.test(first)) out.push({ local: first, imported: "default", kind: "default" });
|
|
248580
|
+
}
|
|
248581
|
+
const ns = clause.match(/\*\s+as\s+([A-Za-z_$][\w$]*)/);
|
|
248582
|
+
if (ns) out.push({ local: ns[1], imported: "*", kind: "namespace" });
|
|
248583
|
+
const braces = clause.match(/\{([\s\S]*)\}/);
|
|
248584
|
+
if (braces) {
|
|
248585
|
+
for (const part of braces[1].split(",")) {
|
|
248313
248586
|
const t3 = part.trim();
|
|
248314
248587
|
if (!t3) continue;
|
|
248315
|
-
const
|
|
248316
|
-
|
|
248588
|
+
const parts = t3.split(/\s+as\s+/);
|
|
248589
|
+
const imported = parts[0].trim();
|
|
248590
|
+
const local = (parts[1] ?? parts[0]).trim();
|
|
248591
|
+
if (local) out.push({ local, imported, kind: "named" });
|
|
248317
248592
|
}
|
|
248318
|
-
} else if (clause.startsWith("*")) {
|
|
248319
|
-
const as = clause.split(/\s+as\s+/);
|
|
248320
|
-
if (as[1]) names.push(as[1].trim());
|
|
248321
|
-
} else {
|
|
248322
|
-
const first = clause.split(",")[0].trim();
|
|
248323
|
-
if (first && /^[A-Za-z_$]/.test(first)) names.push(first);
|
|
248324
248593
|
}
|
|
248325
|
-
return
|
|
248594
|
+
return out;
|
|
248326
248595
|
}
|
|
248327
248596
|
async function resolveServerImports(block, pageFile, opts = {}) {
|
|
248328
248597
|
if (!block.imports.length) return {};
|
|
248329
248598
|
const out = {};
|
|
248330
248599
|
const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
248331
|
-
const { dirname:
|
|
248600
|
+
const { dirname: dirname18, resolve: resolve12 } = await import("node:path");
|
|
248332
248601
|
const { statSync: statSync13 } = await import("node:fs");
|
|
248333
248602
|
for (const imp of block.imports) {
|
|
248334
248603
|
if (!imp.specifier) continue;
|
|
248335
248604
|
const spec = imp.specifier;
|
|
248605
|
+
if (spec === "@tw/server-only" || spec === "@tw/client-safe") continue;
|
|
248336
248606
|
let mod;
|
|
248337
248607
|
if (spec.startsWith("./") || spec.startsWith("../") || spec.startsWith("@./")) {
|
|
248338
248608
|
const rel = spec.startsWith("@./") ? spec.slice(2) : spec;
|
|
248339
|
-
const abs = resolve12(
|
|
248609
|
+
const abs = resolve12(dirname18(pageFile), rel);
|
|
248340
248610
|
let bust;
|
|
248341
248611
|
if (opts.dev) {
|
|
248342
248612
|
try {
|
|
@@ -248344,12 +248614,49 @@ async function resolveServerImports(block, pageFile, opts = {}) {
|
|
|
248344
248614
|
} catch {
|
|
248345
248615
|
}
|
|
248346
248616
|
}
|
|
248347
|
-
|
|
248617
|
+
let override;
|
|
248618
|
+
try {
|
|
248619
|
+
let realAbs = abs;
|
|
248620
|
+
if (!existsSync11(realAbs)) {
|
|
248621
|
+
for (const ext of [".js", ".mjs", ".cjs", ".ts", ".mts", ".cts"]) {
|
|
248622
|
+
if (existsSync11(realAbs + ext)) {
|
|
248623
|
+
realAbs = realAbs + ext;
|
|
248624
|
+
break;
|
|
248625
|
+
}
|
|
248626
|
+
}
|
|
248627
|
+
}
|
|
248628
|
+
const raw = readFileSync8(realAbs, "utf-8");
|
|
248629
|
+
if (MARKER_IMPORT_RE.test(raw)) {
|
|
248630
|
+
MARKER_IMPORT_RE.lastIndex = 0;
|
|
248631
|
+
override = raw.replace(MARKER_IMPORT_RE, "");
|
|
248632
|
+
}
|
|
248633
|
+
} catch {
|
|
248634
|
+
}
|
|
248635
|
+
mod = override === void 0 ? await twImportTs2(abs, bust) : await twImportTs2(abs, bust, { source: override });
|
|
248348
248636
|
} else {
|
|
248349
248637
|
mod = await import(spec);
|
|
248350
248638
|
}
|
|
248351
|
-
const
|
|
248352
|
-
|
|
248639
|
+
for (const bind of importBindings(imp.source)) {
|
|
248640
|
+
if (bind.kind === "namespace") out[bind.local] = mod;
|
|
248641
|
+
else if (bind.kind === "default") out[bind.local] = mod?.default ?? mod?.[bind.imported];
|
|
248642
|
+
else out[bind.local] = mod?.[bind.imported] ?? mod?.default;
|
|
248643
|
+
}
|
|
248644
|
+
}
|
|
248645
|
+
return out;
|
|
248646
|
+
}
|
|
248647
|
+
function serverImportCollisions(source) {
|
|
248648
|
+
const out = [];
|
|
248649
|
+
const re = /^[ \t]*import\s+([\s\S]*?)\s+from\s+["']([^"']+)["'][ \t]*;?/gm;
|
|
248650
|
+
let m;
|
|
248651
|
+
while (m = re.exec(source)) {
|
|
248652
|
+
const stmt = m[0];
|
|
248653
|
+
const specifier = m[2];
|
|
248654
|
+
const line = source.slice(0, m.index).split("\n").length;
|
|
248655
|
+
for (const b of importBindings(stmt)) {
|
|
248656
|
+
if (RESERVED_BLOCK_BINDINGS.includes(b.local)) {
|
|
248657
|
+
out.push({ name: b.local, specifier, line, col: 1 });
|
|
248658
|
+
}
|
|
248659
|
+
}
|
|
248353
248660
|
}
|
|
248354
248661
|
return out;
|
|
248355
248662
|
}
|
|
@@ -248388,7 +248695,7 @@ function checkServerBlocks(program, opts = {}) {
|
|
|
248388
248695
|
}
|
|
248389
248696
|
const calls = scanRuntimeCalls(b.source);
|
|
248390
248697
|
if (calls.getSession || calls.requireUser) push("TW107", "getSession()/requireUser() are not available in a static page's server block", b.line, b.col);
|
|
248391
|
-
if (calls.redirect
|
|
248698
|
+
if (calls.redirect) push("TW108", "redirect() is not available in a static page's server block -- a static page is built before the request, so there is nothing to redirect", b.line, b.col);
|
|
248392
248699
|
}
|
|
248393
248700
|
}
|
|
248394
248701
|
for (const b of blocks) {
|
|
@@ -248539,7 +248846,7 @@ function parsePageCache(source) {
|
|
|
248539
248846
|
const rv = revalidate ?? 60;
|
|
248540
248847
|
return { revalidate: rv, expire: expire ?? rv, tag: tagM ? tagM[1] : void 0 };
|
|
248541
248848
|
}
|
|
248542
|
-
var ts3, REQUEST_IDENTIFIERS, SERVER_REDIRECT_BRAND, SERVER_NOT_FOUND_BRAND, ServerRedirect, ServerNotFound, isServerRedirect, isServerNotFound, DEFAULT_SERVER_BLOCK_TIMEOUT_MS;
|
|
248849
|
+
var ts3, REQUEST_IDENTIFIERS, SERVER_REDIRECT_BRAND, SERVER_NOT_FOUND_BRAND, ServerRedirect, ServerNotFound, isServerRedirect, isServerNotFound, DEFAULT_SERVER_BLOCK_TIMEOUT_MS, MARKER_IMPORT_RE, RESERVED_BLOCK_BINDINGS;
|
|
248543
248850
|
var init_server_blocks = __esm({
|
|
248544
248851
|
"../../packages/compiler/tw/server-blocks/index.ts"() {
|
|
248545
248852
|
init_codes();
|
|
@@ -248566,6 +248873,19 @@ var init_server_blocks = __esm({
|
|
|
248566
248873
|
isServerRedirect = (e) => !!(e && e[SERVER_REDIRECT_BRAND]);
|
|
248567
248874
|
isServerNotFound = (e) => !!(e && e[SERVER_NOT_FOUND_BRAND]);
|
|
248568
248875
|
DEFAULT_SERVER_BLOCK_TIMEOUT_MS = 1e4;
|
|
248876
|
+
MARKER_IMPORT_RE = /^[ \t]*import\s*["']@tw\/(?:server-only|client-safe)["'][ \t]*;?[ \t]*\r?\n?/gm;
|
|
248877
|
+
RESERVED_BLOCK_BINDINGS = [
|
|
248878
|
+
"params",
|
|
248879
|
+
"query",
|
|
248880
|
+
"headers",
|
|
248881
|
+
"cookies",
|
|
248882
|
+
"env",
|
|
248883
|
+
"fetch",
|
|
248884
|
+
"getSession",
|
|
248885
|
+
"requireUser",
|
|
248886
|
+
"redirect",
|
|
248887
|
+
"notFound"
|
|
248888
|
+
];
|
|
248569
248889
|
}
|
|
248570
248890
|
});
|
|
248571
248891
|
|
|
@@ -250021,8 +250341,8 @@ var init_memory = __esm({
|
|
|
250021
250341
|
});
|
|
250022
250342
|
|
|
250023
250343
|
// ../../packages/compiler/tw/cache/disk.ts
|
|
250024
|
-
import { existsSync as
|
|
250025
|
-
import { join as join16, dirname as
|
|
250344
|
+
import { existsSync as existsSync12, readFileSync as readFileSync9, writeFileSync as writeFileSync6, mkdirSync as mkdirSync4, unlinkSync, readdirSync as readdirSync3 } from "node:fs";
|
|
250345
|
+
import { join as join16, dirname as dirname10 } from "node:path";
|
|
250026
250346
|
var DiskCache;
|
|
250027
250347
|
var init_disk = __esm({
|
|
250028
250348
|
"../../packages/compiler/tw/cache/disk.ts"() {
|
|
@@ -250030,15 +250350,15 @@ var init_disk = __esm({
|
|
|
250030
250350
|
DiskCache = class {
|
|
250031
250351
|
constructor(cacheDir) {
|
|
250032
250352
|
this.cacheDir = cacheDir;
|
|
250033
|
-
if (!
|
|
250353
|
+
if (!existsSync12(cacheDir)) {
|
|
250034
250354
|
mkdirSync4(cacheDir, { recursive: true });
|
|
250035
250355
|
}
|
|
250036
250356
|
}
|
|
250037
250357
|
get(key2) {
|
|
250038
250358
|
const path = this.keyToPath(key2);
|
|
250039
|
-
if (!
|
|
250359
|
+
if (!existsSync12(path)) return null;
|
|
250040
250360
|
try {
|
|
250041
|
-
const data = JSON.parse(
|
|
250361
|
+
const data = JSON.parse(readFileSync9(path, "utf-8"));
|
|
250042
250362
|
return data.value;
|
|
250043
250363
|
} catch {
|
|
250044
250364
|
return null;
|
|
@@ -250046,12 +250366,12 @@ var init_disk = __esm({
|
|
|
250046
250366
|
}
|
|
250047
250367
|
set(key2, value, hash3) {
|
|
250048
250368
|
const path = this.keyToPath(key2);
|
|
250049
|
-
mkdirSync4(
|
|
250369
|
+
mkdirSync4(dirname10(path), { recursive: true });
|
|
250050
250370
|
const entry = { key: key2, value, hash: hash3, createdAt: Date.now() };
|
|
250051
|
-
|
|
250371
|
+
writeFileSync6(path, JSON.stringify(entry));
|
|
250052
250372
|
}
|
|
250053
250373
|
has(key2) {
|
|
250054
|
-
return
|
|
250374
|
+
return existsSync12(this.keyToPath(key2));
|
|
250055
250375
|
}
|
|
250056
250376
|
delete(key2) {
|
|
250057
250377
|
const path = this.keyToPath(key2);
|
|
@@ -250547,7 +250867,7 @@ var init_incremental = __esm({
|
|
|
250547
250867
|
|
|
250548
250868
|
// ../../packages/compiler/tw/native/child-process.ts
|
|
250549
250869
|
import { spawn } from "node:child_process";
|
|
250550
|
-
import { existsSync as
|
|
250870
|
+
import { existsSync as existsSync13 } from "node:fs";
|
|
250551
250871
|
import { join as join17 } from "node:path";
|
|
250552
250872
|
function safeJsonParse3(json2, fallback) {
|
|
250553
250873
|
try {
|
|
@@ -250575,7 +250895,7 @@ function findRustBinary() {
|
|
|
250575
250895
|
}
|
|
250576
250896
|
for (const candidate of candidates) {
|
|
250577
250897
|
if (candidate.includes("/") || candidate.includes("\\")) {
|
|
250578
|
-
if (
|
|
250898
|
+
if (existsSync13(candidate)) {
|
|
250579
250899
|
cachedBinaryPath = candidate;
|
|
250580
250900
|
return candidate;
|
|
250581
250901
|
}
|
|
@@ -255193,6 +255513,7 @@ __export(tw_exports3, {
|
|
|
255193
255513
|
PropParser: () => PropParser,
|
|
255194
255514
|
RENDER_MODE_ALIASES: () => RENDER_MODE_ALIASES,
|
|
255195
255515
|
RENDER_MODE_NAMES: () => RENDER_MODE_NAMES,
|
|
255516
|
+
RESERVED_BLOCK_BINDINGS: () => RESERVED_BLOCK_BINDINGS,
|
|
255196
255517
|
RESERVED_WORDS: () => RESERVED_WORDS,
|
|
255197
255518
|
RuleEngine: () => RuleEngine,
|
|
255198
255519
|
RulesEngine: () => RulesEngine,
|
|
@@ -255836,6 +256157,7 @@ __export(tw_exports3, {
|
|
|
255836
256157
|
secretEnvValues: () => secretEnvValues,
|
|
255837
256158
|
separateByType: () => separateByType,
|
|
255838
256159
|
serializeCache: () => serializeCache,
|
|
256160
|
+
serverImportCollisions: () => serverImportCollisions,
|
|
255839
256161
|
serverRouteParamCollisions: () => serverRouteParamCollisions,
|
|
255840
256162
|
serverStateCollisions: () => serverStateCollisions,
|
|
255841
256163
|
setBackend: () => setBackend,
|
|
@@ -256194,7 +256516,7 @@ __export(client_bundle_exports, {
|
|
|
256194
256516
|
setClientOutputRoot: () => setClientOutputRoot
|
|
256195
256517
|
});
|
|
256196
256518
|
import { join as join18, resolve as resolve4 } from "node:path";
|
|
256197
|
-
import { existsSync as
|
|
256519
|
+
import { existsSync as existsSync14, readFileSync as readFileSync10, writeFileSync as writeFileSync7, mkdirSync as mkdirSync5, unlinkSync as unlinkSync2 } from "node:fs";
|
|
256198
256520
|
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
256199
256521
|
function isClientImportSpecifier(spec) {
|
|
256200
256522
|
if (spec.startsWith("@./") || spec.startsWith("./") || spec.startsWith("../")) return false;
|
|
@@ -256246,7 +256568,7 @@ function findEsbuildBin(rootDir) {
|
|
|
256246
256568
|
];
|
|
256247
256569
|
for (const c of candidates) {
|
|
256248
256570
|
try {
|
|
256249
|
-
if (
|
|
256571
|
+
if (existsSync14(c)) return c;
|
|
256250
256572
|
} catch {
|
|
256251
256573
|
}
|
|
256252
256574
|
}
|
|
@@ -256254,7 +256576,7 @@ function findEsbuildBin(rootDir) {
|
|
|
256254
256576
|
if (bd) {
|
|
256255
256577
|
const b = resolve4(bd, "..", "..", "..", "node_modules", ".bin", "esbuild");
|
|
256256
256578
|
try {
|
|
256257
|
-
if (
|
|
256579
|
+
if (existsSync14(b)) return b;
|
|
256258
256580
|
} catch {
|
|
256259
256581
|
}
|
|
256260
256582
|
}
|
|
@@ -256308,9 +256630,9 @@ function getClientOutputRoot() {
|
|
|
256308
256630
|
}
|
|
256309
256631
|
function vendoredRuntimeClient() {
|
|
256310
256632
|
const fromSrc = new URL("../../dist/tw-runtime-client.mjs", import.meta.url).pathname;
|
|
256311
|
-
if (
|
|
256633
|
+
if (existsSync14(fromSrc)) return fromSrc;
|
|
256312
256634
|
const fromBundle = new URL("./tw-runtime-client.mjs", import.meta.url).pathname;
|
|
256313
|
-
if (
|
|
256635
|
+
if (existsSync14(fromBundle)) return fromBundle;
|
|
256314
256636
|
return null;
|
|
256315
256637
|
}
|
|
256316
256638
|
function rewriteRuntimeSpecifier(importLine) {
|
|
@@ -256327,10 +256649,10 @@ function minifyJsSource(rootDir, source, target = "es2019") {
|
|
|
256327
256649
|
const outPath = join18(rootDir, OUT_ROOT, ".min-out-" + stamp + ".js");
|
|
256328
256650
|
try {
|
|
256329
256651
|
mkdirSync5(join18(rootDir, OUT_ROOT), { recursive: true });
|
|
256330
|
-
|
|
256652
|
+
writeFileSync7(inPath, source);
|
|
256331
256653
|
const r = spawnSync4(bin, [inPath, "--minify", "--target=" + (target || "es2019"), "--format=iife", "--outfile=" + outPath], { cwd: rootDir });
|
|
256332
256654
|
if (r.status !== 0) return source;
|
|
256333
|
-
const out =
|
|
256655
|
+
const out = readFileSync10(outPath, "utf-8");
|
|
256334
256656
|
return out || source;
|
|
256335
256657
|
} catch {
|
|
256336
256658
|
return source;
|
|
@@ -256361,7 +256683,7 @@ function esbuildTargetFor(target) {
|
|
|
256361
256683
|
}
|
|
256362
256684
|
function buildEntryPoint(rootDir, entry, flags = {}) {
|
|
256363
256685
|
const abs = join18(rootDir, entry);
|
|
256364
|
-
if (!
|
|
256686
|
+
if (!existsSync14(abs)) return "";
|
|
256365
256687
|
const jsDir = join18(rootDir, OUT_ROOT, "js");
|
|
256366
256688
|
mkdirSync5(jsDir, { recursive: true });
|
|
256367
256689
|
const stamp = contentHash2(entry);
|
|
@@ -256377,9 +256699,9 @@ function buildEntryPoint(rootDir, entry, flags = {}) {
|
|
|
256377
256699
|
}
|
|
256378
256700
|
return "";
|
|
256379
256701
|
}
|
|
256380
|
-
const code =
|
|
256702
|
+
const code = readFileSync10(tmpOut, "utf-8");
|
|
256381
256703
|
const url = "js/e-" + contentHash2(code) + ".js";
|
|
256382
|
-
|
|
256704
|
+
writeFileSync7(join18(rootDir, OUT_ROOT, url), code);
|
|
256383
256705
|
try {
|
|
256384
256706
|
unlinkSync2(tmpOut);
|
|
256385
256707
|
} catch {
|
|
@@ -256407,7 +256729,7 @@ function buildClientChunk(rootDir, importLine, flagsOrMinify = true, sourcemap =
|
|
|
256407
256729
|
const flags = typeof flagsOrMinify === "boolean" ? { minify: flagsOrMinify, sourcemap } : flagsOrMinify;
|
|
256408
256730
|
const key2 = importLine + "|" + JSON.stringify(flags);
|
|
256409
256731
|
const cached2 = chunkCache.get(key2);
|
|
256410
|
-
if (cached2 &&
|
|
256732
|
+
if (cached2 && existsSync14(join18(rootDir, OUT_ROOT, cached2))) return cached2;
|
|
256411
256733
|
const jsDir = join18(rootDir, OUT_ROOT, "js");
|
|
256412
256734
|
mkdirSync5(jsDir, { recursive: true });
|
|
256413
256735
|
const names = importNames(importLine);
|
|
@@ -256420,7 +256742,7 @@ function buildClientChunk(rootDir, importLine, flagsOrMinify = true, sourcemap =
|
|
|
256420
256742
|
const stamp = contentHash2(importLine);
|
|
256421
256743
|
const entryPath = join18(rootDir, OUT_ROOT, ".chunk-entry-" + stamp + ".js");
|
|
256422
256744
|
const tmpOut = join18(rootDir, OUT_ROOT, ".chunk-tmp-" + stamp + ".js");
|
|
256423
|
-
|
|
256745
|
+
writeFileSync7(entryPath, entry);
|
|
256424
256746
|
const bin = findEsbuildBin(rootDir);
|
|
256425
256747
|
const args = [entryPath, ...chunkEsbuildArgs(flags, tmpOut)];
|
|
256426
256748
|
const r = spawnSync4(bin, args, { cwd: rootDir });
|
|
@@ -256437,9 +256759,9 @@ function buildClientChunk(rootDir, importLine, flagsOrMinify = true, sourcemap =
|
|
|
256437
256759
|
}
|
|
256438
256760
|
return "";
|
|
256439
256761
|
}
|
|
256440
|
-
const code =
|
|
256762
|
+
const code = readFileSync10(tmpOut, "utf-8");
|
|
256441
256763
|
const url = "js/c-" + contentHash2(code) + ".js";
|
|
256442
|
-
|
|
256764
|
+
writeFileSync7(join18(rootDir, OUT_ROOT, url), code);
|
|
256443
256765
|
try {
|
|
256444
256766
|
unlinkSync2(tmpOut);
|
|
256445
256767
|
} catch {
|
|
@@ -256455,7 +256777,7 @@ function buildPageScope(rootDir, ownImportLines) {
|
|
|
256455
256777
|
const body = names.map((n) => "p." + n + " = g.__twClient." + n + ";").join("\n");
|
|
256456
256778
|
const code = "(function(g){g.__twClient=g.__twClient||{};var p={};\n" + body + "\ng.__twClient.$page=p;})(globalThis);\n";
|
|
256457
256779
|
const url = "js/p-" + contentHash2(names.slice().sort().join("|")) + ".js";
|
|
256458
|
-
|
|
256780
|
+
writeFileSync7(join18(rootDir, OUT_ROOT, url), code);
|
|
256459
256781
|
return url;
|
|
256460
256782
|
}
|
|
256461
256783
|
var IMPORT_RE, BUILTIN_CLIENT_OK_SPECIFIERS, RUNTIME_CLIENT_OK_SPECIFIERS, chunkCache, OUT_ROOT;
|
|
@@ -256470,7 +256792,7 @@ var init_client_bundle = __esm({
|
|
|
256470
256792
|
});
|
|
256471
256793
|
|
|
256472
256794
|
// ../../packages/plugins/tw/resolve.ts
|
|
256473
|
-
import { existsSync as
|
|
256795
|
+
import { existsSync as existsSync15, readFileSync as readFileSync11 } from "node:fs";
|
|
256474
256796
|
import { join as join19 } from "node:path";
|
|
256475
256797
|
function isExplicitPath(spec) {
|
|
256476
256798
|
return spec.startsWith(".") || spec.startsWith("/");
|
|
@@ -256500,9 +256822,9 @@ function resolvePackageFile(spec, rootDir) {
|
|
|
256500
256822
|
function readPackageManifest(packageName2, rootDir) {
|
|
256501
256823
|
const dir = join19(rootDir, "node_modules", ...packageName2.split("/"));
|
|
256502
256824
|
const pj = join19(dir, "package.json");
|
|
256503
|
-
if (!
|
|
256825
|
+
if (!existsSync15(pj)) return null;
|
|
256504
256826
|
try {
|
|
256505
|
-
return JSON.parse(
|
|
256827
|
+
return JSON.parse(readFileSync11(pj, "utf-8"));
|
|
256506
256828
|
} catch {
|
|
256507
256829
|
return null;
|
|
256508
256830
|
}
|
|
@@ -256518,12 +256840,12 @@ function resolvePlugin(spec, rootDir) {
|
|
|
256518
256840
|
if (isExplicitPath(spec)) {
|
|
256519
256841
|
const base = join19(rootDir, spec);
|
|
256520
256842
|
for (const candidate of [base, base + ".ts", join19(base, "index.ts")]) {
|
|
256521
|
-
if (
|
|
256843
|
+
if (existsSync15(candidate)) return { spec, kind: "path", file: candidate };
|
|
256522
256844
|
}
|
|
256523
256845
|
return { spec, kind: "path", error: `path not found: ${spec}` };
|
|
256524
256846
|
}
|
|
256525
256847
|
const local = join19(rootDir, "plugins", spec + ".ts");
|
|
256526
|
-
if (
|
|
256848
|
+
if (existsSync15(local)) return { spec, kind: "local", file: local };
|
|
256527
256849
|
const file = resolvePackageFile(spec, rootDir);
|
|
256528
256850
|
if (file) {
|
|
256529
256851
|
const manifest = readPackageManifest(spec, rootDir);
|
|
@@ -256989,7 +257311,7 @@ var init_hooks = __esm({
|
|
|
256989
257311
|
});
|
|
256990
257312
|
|
|
256991
257313
|
// ../../packages/plugins/tw/upgrade.ts
|
|
256992
|
-
import { existsSync as
|
|
257314
|
+
import { existsSync as existsSync16, readFileSync as readFileSync12 } from "node:fs";
|
|
256993
257315
|
import { join as join20 } from "node:path";
|
|
256994
257316
|
function extractPluginsArray(source) {
|
|
256995
257317
|
const at = /plugins\s*:\s*\[/.exec(source);
|
|
@@ -257110,9 +257432,9 @@ function looksLikeSpec(value) {
|
|
|
257110
257432
|
}
|
|
257111
257433
|
function installedVersion(pkg, rootDir) {
|
|
257112
257434
|
const pj = join20(rootDir, "node_modules", ...pkg.split("/"), "package.json");
|
|
257113
|
-
if (!
|
|
257435
|
+
if (!existsSync16(pj)) return null;
|
|
257114
257436
|
try {
|
|
257115
|
-
return JSON.parse(
|
|
257437
|
+
return JSON.parse(readFileSync12(pj, "utf-8")).version ?? null;
|
|
257116
257438
|
} catch {
|
|
257117
257439
|
return null;
|
|
257118
257440
|
}
|
|
@@ -257221,8 +257543,8 @@ __export(tw_exports4, {
|
|
|
257221
257543
|
resolvePlugin: () => resolvePlugin,
|
|
257222
257544
|
splitTopLevel: () => splitTopLevel
|
|
257223
257545
|
});
|
|
257224
|
-
import { existsSync as
|
|
257225
|
-
import { join as join21, extname as
|
|
257546
|
+
import { existsSync as existsSync17, readdirSync as readdirSync5 } from "node:fs";
|
|
257547
|
+
import { join as join21, extname as extname7 } from "node:path";
|
|
257226
257548
|
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
257227
257549
|
async function loadPlugins(rootDir, config, logger) {
|
|
257228
257550
|
const manager = new PluginManager(config, logger);
|
|
@@ -257234,7 +257556,7 @@ async function loadPlugins(rootDir, config, logger) {
|
|
|
257234
257556
|
if (typeof entry === "string") specs.push(entry);
|
|
257235
257557
|
else if (entry && typeof entry === "object" && typeof entry.name === "string") specs.push(entry.name);
|
|
257236
257558
|
}
|
|
257237
|
-
} else if (
|
|
257559
|
+
} else if (existsSync17(pluginsDir)) {
|
|
257238
257560
|
for (const file of readdirSync5(pluginsDir)) {
|
|
257239
257561
|
if (/\.ts$/.test(file) && !file.endsWith(".d.ts")) specs.push(file.replace(/\.ts$/, ""));
|
|
257240
257562
|
}
|
|
@@ -257420,10 +257742,10 @@ var init_tw8 = __esm({
|
|
|
257420
257742
|
}
|
|
257421
257743
|
// Load plugins from a directory
|
|
257422
257744
|
async loadFromDir(pluginsDir) {
|
|
257423
|
-
if (!
|
|
257745
|
+
if (!existsSync17(pluginsDir)) return;
|
|
257424
257746
|
const entries = readdirSync5(pluginsDir);
|
|
257425
257747
|
for (const entry of entries) {
|
|
257426
|
-
const ext =
|
|
257748
|
+
const ext = extname7(entry).toLowerCase();
|
|
257427
257749
|
if (![".ts", ".js", ".mjs"].includes(ext)) continue;
|
|
257428
257750
|
const filePath = join21(pluginsDir, entry);
|
|
257429
257751
|
try {
|
|
@@ -257549,13 +257871,13 @@ __export(island_bundle_exports, {
|
|
|
257549
257871
|
resolveForeignPath: () => resolveForeignPath,
|
|
257550
257872
|
scanForeignImports: () => scanForeignImports
|
|
257551
257873
|
});
|
|
257552
|
-
import { existsSync as
|
|
257553
|
-
import { join as join22, dirname as
|
|
257874
|
+
import { existsSync as existsSync18, readFileSync as readFileSync13, writeFileSync as writeFileSync8, mkdirSync as mkdirSync6, unlinkSync as unlinkSync3, readdirSync as readdirSync6, statSync as statSync5 } from "node:fs";
|
|
257875
|
+
import { join as join22, dirname as dirname11, resolve as resolve5 } from "node:path";
|
|
257554
257876
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
257555
257877
|
import { createHash as createHash4 } from "node:crypto";
|
|
257556
257878
|
import { pathToFileURL as pathToFileURL4 } from "node:url";
|
|
257557
257879
|
function collectTwFiles(dir, out = []) {
|
|
257558
|
-
if (!
|
|
257880
|
+
if (!existsSync18(dir)) return out;
|
|
257559
257881
|
for (const entry of readdirSync6(dir)) {
|
|
257560
257882
|
if (SKIP_DIRS.has(entry)) continue;
|
|
257561
257883
|
const full = join22(dir, entry);
|
|
@@ -257568,12 +257890,12 @@ function collectTwFiles(dir, out = []) {
|
|
|
257568
257890
|
function resolveForeignPath(fromFile, specifier, rootDir) {
|
|
257569
257891
|
const rel = specifier.replace(/^@/, "").replace(/^\.?\//, "");
|
|
257570
257892
|
const direct = join22(rootDir, rel);
|
|
257571
|
-
if (
|
|
257572
|
-
let dir =
|
|
257893
|
+
if (existsSync18(direct)) return direct;
|
|
257894
|
+
let dir = dirname11(fromFile);
|
|
257573
257895
|
for (let i = 0; i < 12; i++) {
|
|
257574
257896
|
const candidate = join22(dir, rel);
|
|
257575
|
-
if (
|
|
257576
|
-
const parent =
|
|
257897
|
+
if (existsSync18(candidate)) return candidate;
|
|
257898
|
+
const parent = dirname11(dir);
|
|
257577
257899
|
if (parent === dir || !parent.startsWith(rootDir)) break;
|
|
257578
257900
|
dir = parent;
|
|
257579
257901
|
}
|
|
@@ -257584,7 +257906,7 @@ function scanForeignImports(rootDir, twFiles) {
|
|
|
257584
257906
|
for (const file of twFiles) {
|
|
257585
257907
|
let src = "";
|
|
257586
257908
|
try {
|
|
257587
|
-
src =
|
|
257909
|
+
src = readFileSync13(file, "utf-8");
|
|
257588
257910
|
} catch {
|
|
257589
257911
|
continue;
|
|
257590
257912
|
}
|
|
@@ -257610,7 +257932,7 @@ function findEsbuildBin2(rootDir) {
|
|
|
257610
257932
|
resolve5(rootDir, "..", "node_modules", ".bin", "esbuild"),
|
|
257611
257933
|
resolve5(new URL(".", import.meta.url).pathname, "..", "..", "..", "..", "node_modules", ".bin", "esbuild")
|
|
257612
257934
|
];
|
|
257613
|
-
for (const c of candidates) if (
|
|
257935
|
+
for (const c of candidates) if (existsSync18(c)) return c;
|
|
257614
257936
|
return "esbuild";
|
|
257615
257937
|
}
|
|
257616
257938
|
function runEsbuild(rootDir, entryPath, outFile, extra) {
|
|
@@ -257732,13 +258054,13 @@ async function loadSsrRenderer(rootDir, absPath, engine = "preact") {
|
|
|
257732
258054
|
mkdirSync6(dir, { recursive: true });
|
|
257733
258055
|
let contentHash3 = "";
|
|
257734
258056
|
try {
|
|
257735
|
-
contentHash3 = hash2(
|
|
258057
|
+
contentHash3 = hash2(readFileSync13(absPath, "utf-8"));
|
|
257736
258058
|
} catch {
|
|
257737
258059
|
}
|
|
257738
258060
|
const stamp = hash2(absPath + ":" + engine + ":" + contentHash3);
|
|
257739
258061
|
const entryPath = join22(dir, "entry-" + stamp + ".mjs");
|
|
257740
258062
|
const outFile = join22(dir, "ssr-" + stamp + ".mjs");
|
|
257741
|
-
|
|
258063
|
+
writeFileSync8(entryPath, entry.ssr(absPath));
|
|
257742
258064
|
const res = runEsbuild(rootDir, entryPath, outFile, ["--format=esm", "--platform=node", "--target=node18", "--log-level=error", ...entry.jsxArgs]);
|
|
257743
258065
|
try {
|
|
257744
258066
|
unlinkSync3(entryPath);
|
|
@@ -257755,17 +258077,17 @@ function buildIslandChunk(rootDir, absPath, name, minify, engine = "preact", str
|
|
|
257755
258077
|
const stamp = hash2(absPath + ":" + name + ":" + engine + ":" + strategy);
|
|
257756
258078
|
const entryPath = join22(dir, "entry-" + stamp + ".mjs");
|
|
257757
258079
|
const outFile = join22(dir, "out-" + stamp + ".js");
|
|
257758
|
-
|
|
258080
|
+
writeFileSync8(entryPath, entry.hydrate(absPath, name, strategy));
|
|
257759
258081
|
const res = runEsbuild(rootDir, entryPath, outFile, ["--format=iife", "--target=es2019", "--log-level=error", ...entry.jsxArgs, ...minify ? ["--minify"] : []]);
|
|
257760
258082
|
try {
|
|
257761
258083
|
unlinkSync3(entryPath);
|
|
257762
258084
|
} catch {
|
|
257763
258085
|
}
|
|
257764
258086
|
if (!res.ok) throw new Error("esbuild (island) failed: " + res.err);
|
|
257765
|
-
const code =
|
|
258087
|
+
const code = readFileSync13(outFile, "utf-8");
|
|
257766
258088
|
const url = "js/island-" + hash2(code) + ".js";
|
|
257767
258089
|
mkdirSync6(join22(rootDir, ".tw", "js"), { recursive: true });
|
|
257768
|
-
|
|
258090
|
+
writeFileSync8(join22(rootDir, ".tw", url), code);
|
|
257769
258091
|
try {
|
|
257770
258092
|
unlinkSync3(outFile);
|
|
257771
258093
|
} catch {
|
|
@@ -257776,7 +258098,7 @@ function pruneIslandCache(rootDir) {
|
|
|
257776
258098
|
let removed = 0;
|
|
257777
258099
|
for (const name of [".island-ssr", ".island"]) {
|
|
257778
258100
|
const dir = join22(rootDir, ".tw", name);
|
|
257779
|
-
if (!
|
|
258101
|
+
if (!existsSync18(dir)) continue;
|
|
257780
258102
|
for (const entry of readdirSync6(dir)) {
|
|
257781
258103
|
try {
|
|
257782
258104
|
unlinkSync3(join22(dir, entry));
|
|
@@ -259119,10 +259441,10 @@ var init_layout_chain = __esm({
|
|
|
259119
259441
|
});
|
|
259120
259442
|
|
|
259121
259443
|
// ../../packages/server/tw/routing/scanner.ts
|
|
259122
|
-
import { existsSync as
|
|
259123
|
-
import { join as join23, relative, basename as
|
|
259444
|
+
import { existsSync as existsSync19, readdirSync as readdirSync7, statSync as statSync6 } from "node:fs";
|
|
259445
|
+
import { join as join23, relative, basename as basename3, extname as extname8 } from "node:path";
|
|
259124
259446
|
function scanRouteTree(opts) {
|
|
259125
|
-
if (!
|
|
259447
|
+
if (!existsSync19(opts.homeDir)) return null;
|
|
259126
259448
|
const root = {
|
|
259127
259449
|
segment: "",
|
|
259128
259450
|
relativePath: "",
|
|
@@ -259147,7 +259469,7 @@ function scanDirectory(dirPath, urlPath, groups, parentNode, opts) {
|
|
|
259147
259469
|
}
|
|
259148
259470
|
for (const entry of entries) {
|
|
259149
259471
|
const fullPath = join23(dirPath, entry);
|
|
259150
|
-
const ext =
|
|
259472
|
+
const ext = extname8(entry);
|
|
259151
259473
|
if (!ROUTE_EXTENSIONS.has(ext)) continue;
|
|
259152
259474
|
let stat;
|
|
259153
259475
|
try {
|
|
@@ -259156,7 +259478,7 @@ function scanDirectory(dirPath, urlPath, groups, parentNode, opts) {
|
|
|
259156
259478
|
continue;
|
|
259157
259479
|
}
|
|
259158
259480
|
if (!stat.isFile()) continue;
|
|
259159
|
-
const baseName =
|
|
259481
|
+
const baseName = basename3(entry, ext);
|
|
259160
259482
|
const fileType = getRouteFileType(baseName);
|
|
259161
259483
|
if (fileType === null) {
|
|
259162
259484
|
continue;
|
|
@@ -259530,8 +259852,8 @@ var init_helpers = __esm({
|
|
|
259530
259852
|
});
|
|
259531
259853
|
|
|
259532
259854
|
// ../../packages/server/tw/routing/render-pipeline.ts
|
|
259533
|
-
import { readFileSync as
|
|
259534
|
-
import { dirname as
|
|
259855
|
+
import { readFileSync as readFileSync14, existsSync as existsSync20 } from "node:fs";
|
|
259856
|
+
import { dirname as dirname12 } from "node:path";
|
|
259535
259857
|
function getCacheProfiles(rootDir) {
|
|
259536
259858
|
if (__profilesCache && __profilesCache.rootDir === rootDir) return __profilesCache.profiles;
|
|
259537
259859
|
let profiles = {};
|
|
@@ -259560,6 +259882,32 @@ var init_render_pipeline = __esm({
|
|
|
259560
259882
|
init_tw10();
|
|
259561
259883
|
__profilesCache = null;
|
|
259562
259884
|
RenderPipeline = class {
|
|
259885
|
+
/**
|
|
259886
|
+
* A dynamic route with a sibling `params.twm` is an enumerated route: the
|
|
259887
|
+
* static build only writes the generated slugs, so a static host 404s an
|
|
259888
|
+
* unknown one. The server matched `[slug]` for anything and rendered the
|
|
259889
|
+
* page's fallback branch with status 200, so search engines indexed those as
|
|
259890
|
+
* real pages. Return true when the requested params are not in `generate()`.
|
|
259891
|
+
*/
|
|
259892
|
+
async isUnenumeratedParam(pageFile, params) {
|
|
259893
|
+
if (!/\[[^\]]+\]/.test(pageFile)) return false;
|
|
259894
|
+
const paramsTwm = dirname12(pageFile) + "/params.twm";
|
|
259895
|
+
if (!existsSync20(paramsTwm)) return false;
|
|
259896
|
+
try {
|
|
259897
|
+
const { loadTWMModule: loadTWMModule2 } = await Promise.resolve().then(() => (init_twm_loader(), twm_loader_exports));
|
|
259898
|
+
const pmod = await loadTWMModule2(paramsTwm, this.rootDir);
|
|
259899
|
+
if (typeof pmod?.generate !== "function") return false;
|
|
259900
|
+
const arr2 = await pmod.generate();
|
|
259901
|
+
if (!Array.isArray(arr2) || arr2.length === 0) return false;
|
|
259902
|
+
const keys = Object.keys(params);
|
|
259903
|
+
if (keys.length === 0) return false;
|
|
259904
|
+
const sets = arr2.map((x) => x && typeof x === "object" ? x : { [keys[0]]: String(x) });
|
|
259905
|
+
const found = sets.some((set) => keys.every((k) => String(set[k] ?? "") === String(params[k] ?? "")));
|
|
259906
|
+
return !found;
|
|
259907
|
+
} catch {
|
|
259908
|
+
return false;
|
|
259909
|
+
}
|
|
259910
|
+
}
|
|
259563
259911
|
rootDir;
|
|
259564
259912
|
homeDir;
|
|
259565
259913
|
enableCache;
|
|
@@ -259635,10 +259983,10 @@ var init_render_pipeline = __esm({
|
|
|
259635
259983
|
/** Read a route file, memoised outside dev. See `sourceCache`. */
|
|
259636
259984
|
readSource(file) {
|
|
259637
259985
|
const key2 = file.absolutePath;
|
|
259638
|
-
if (this.dev) return
|
|
259986
|
+
if (this.dev) return readFileSync14(key2, "utf-8");
|
|
259639
259987
|
const hit = this.sourceCache.get(key2);
|
|
259640
259988
|
if (hit !== void 0) return hit;
|
|
259641
|
-
const src =
|
|
259989
|
+
const src = readFileSync14(key2, "utf-8");
|
|
259642
259990
|
this.sourceCache.set(key2, src);
|
|
259643
259991
|
return src;
|
|
259644
259992
|
}
|
|
@@ -259663,6 +260011,17 @@ var init_render_pipeline = __esm({
|
|
|
259663
260011
|
const ctx = match ? resolveLayoutChain2(match) : null;
|
|
259664
260012
|
const pageFile = ctx?.page?.absolutePath;
|
|
259665
260013
|
if (!pageFile) return this.render(pathname);
|
|
260014
|
+
try {
|
|
260015
|
+
if (await this.isUnenumeratedParam(pageFile, match?.params ?? {})) {
|
|
260016
|
+
this.__forceNotFound = true;
|
|
260017
|
+
try {
|
|
260018
|
+
return this.render(pathname);
|
|
260019
|
+
} finally {
|
|
260020
|
+
this.__forceNotFound = false;
|
|
260021
|
+
}
|
|
260022
|
+
}
|
|
260023
|
+
} catch {
|
|
260024
|
+
}
|
|
259666
260025
|
let blocks = [];
|
|
259667
260026
|
let src = "";
|
|
259668
260027
|
try {
|
|
@@ -259938,7 +260297,7 @@ var init_render_pipeline = __esm({
|
|
|
259938
260297
|
if (!tree) {
|
|
259939
260298
|
return this.renderError("home/ directory not found", 500, startTime);
|
|
259940
260299
|
}
|
|
259941
|
-
const match = matchRoute(tree, pathname);
|
|
260300
|
+
const match = this.__forceNotFound ? null : matchRoute(tree, pathname);
|
|
259942
260301
|
if (!match) {
|
|
259943
260302
|
const rootNotFound = findNearestNotFound(tree, pathname.split("/").filter(Boolean));
|
|
259944
260303
|
if (rootNotFound) {
|
|
@@ -260087,9 +260446,9 @@ ${bodyHTML}`;
|
|
|
260087
260446
|
try {
|
|
260088
260447
|
const headCandidates = [];
|
|
260089
260448
|
const globalHead = join24(this.rootDir, "home", "head.tw");
|
|
260090
|
-
if (
|
|
260091
|
-
const siblingHead = join24(
|
|
260092
|
-
if (siblingHead !== globalHead &&
|
|
260449
|
+
if (existsSync20(globalHead)) headCandidates.push(globalHead);
|
|
260450
|
+
const siblingHead = join24(dirname12(ctx.page.absolutePath), "head.tw");
|
|
260451
|
+
if (siblingHead !== globalHead && existsSync20(siblingHead)) headCandidates.push(siblingHead);
|
|
260093
260452
|
for (const hp of headCandidates) {
|
|
260094
260453
|
const headCompiled = this.compileFile({ absolutePath: hp, type: "head" });
|
|
260095
260454
|
const m = headCompiled.html.match(/<body>([\s\S]*)<\/body>/);
|
|
@@ -260186,11 +260545,11 @@ ${bodyHTML}`;
|
|
|
260186
260545
|
if (this.__compsRegistered) return;
|
|
260187
260546
|
this.__compsRegistered = true;
|
|
260188
260547
|
try {
|
|
260189
|
-
const { readdirSync:
|
|
260548
|
+
const { readdirSync: readdirSync15 } = __require("node:fs");
|
|
260190
260549
|
const { join: join44 } = __require("node:path");
|
|
260191
260550
|
const dir = join44(this.rootDir, "components");
|
|
260192
260551
|
if (!__require("node:fs").existsSync(dir)) return;
|
|
260193
|
-
for (const f of
|
|
260552
|
+
for (const f of readdirSync15(dir).filter((f2) => f2.endsWith(".tw"))) {
|
|
260194
260553
|
try {
|
|
260195
260554
|
const src = __require("node:fs").readFileSync(join44(dir, f), "utf-8");
|
|
260196
260555
|
const r = compileSync(src, { filePath: join44(dir, f), transforms: false, optimize: false, diagnostics: false });
|
|
@@ -260223,7 +260582,7 @@ ${bodyHTML}`;
|
|
|
260223
260582
|
}
|
|
260224
260583
|
};
|
|
260225
260584
|
}
|
|
260226
|
-
if (!
|
|
260585
|
+
if (!existsSync20(file.absolutePath)) {
|
|
260227
260586
|
throw new Error(`Route file not found: ${file.absolutePath}`);
|
|
260228
260587
|
}
|
|
260229
260588
|
const source = this.readSource(file);
|
|
@@ -260617,7 +260976,7 @@ ${devScript}
|
|
|
260617
260976
|
*/
|
|
260618
260977
|
async runMiddleware(pathname, request) {
|
|
260619
260978
|
const middlewarePath = join24(this.rootDir, "middleware.twm");
|
|
260620
|
-
if (!
|
|
260979
|
+
if (!existsSync20(middlewarePath)) return;
|
|
260621
260980
|
const mod = await loadTWMModule(middlewarePath, this.rootDir);
|
|
260622
260981
|
if (mod.config?.matcher && !shouldMatchMiddleware(mod.config.matcher, pathname)) {
|
|
260623
260982
|
return;
|
|
@@ -260769,7 +261128,7 @@ var init_fs_compat = __esm({
|
|
|
260769
261128
|
});
|
|
260770
261129
|
|
|
260771
261130
|
// ../../packages/server/tw/router/index.ts
|
|
260772
|
-
import { existsSync as
|
|
261131
|
+
import { existsSync as existsSync21, readdirSync as readdirSync8, statSync as statSync7 } from "node:fs";
|
|
260773
261132
|
import { join as join25 } from "node:path";
|
|
260774
261133
|
var RouteRegistry;
|
|
260775
261134
|
var init_router = __esm({
|
|
@@ -260838,7 +261197,7 @@ var init_router = __esm({
|
|
|
260838
261197
|
return [...this.routes];
|
|
260839
261198
|
}
|
|
260840
261199
|
loadFromDir(pagesDir, basePath = "/") {
|
|
260841
|
-
if (!
|
|
261200
|
+
if (!existsSync21(pagesDir)) return;
|
|
260842
261201
|
const files = [];
|
|
260843
261202
|
this.collectFiles(pagesDir, ".tw", files, "");
|
|
260844
261203
|
for (const file of files) {
|
|
@@ -262593,8 +262952,8 @@ var init_signal_transports = __esm({
|
|
|
262593
262952
|
});
|
|
262594
262953
|
|
|
262595
262954
|
// ../../packages/server/tw/static/index.ts
|
|
262596
|
-
import { existsSync as
|
|
262597
|
-
import { join as join26, extname as
|
|
262955
|
+
import { existsSync as existsSync22, statSync as statSync8 } from "node:fs";
|
|
262956
|
+
import { join as join26, extname as extname9, normalize as normalize2, resolve as resolve6, sep } from "node:path";
|
|
262598
262957
|
var StaticHandler;
|
|
262599
262958
|
var init_static = __esm({
|
|
262600
262959
|
"../../packages/server/tw/static/index.ts"() {
|
|
@@ -262634,32 +262993,32 @@ var init_static = __esm({
|
|
|
262634
262993
|
return new Response("Not Found", { status: 404, headers: { "Content-Type": "text/plain" } });
|
|
262635
262994
|
}
|
|
262636
262995
|
let filePath = join26(this.root, safePath);
|
|
262637
|
-
if (
|
|
262996
|
+
if (existsSync22(filePath) && statSync8(filePath).isDirectory()) {
|
|
262638
262997
|
filePath = join26(filePath, this.indexFile);
|
|
262639
262998
|
}
|
|
262640
|
-
if (!
|
|
262999
|
+
if (!existsSync22(filePath)) {
|
|
262641
263000
|
filePath = join26(this.root, safePath + ".html");
|
|
262642
263001
|
}
|
|
262643
263002
|
let notFoundFallback = false;
|
|
262644
|
-
if (!
|
|
263003
|
+
if (!existsSync22(filePath)) {
|
|
262645
263004
|
filePath = join26(this.root, safePath, this.indexFile);
|
|
262646
263005
|
}
|
|
262647
|
-
if (!
|
|
263006
|
+
if (!existsSync22(filePath)) {
|
|
262648
263007
|
if (this.spa) {
|
|
262649
263008
|
filePath = join26(this.root, this.indexFile);
|
|
262650
|
-
if (!
|
|
263009
|
+
if (!existsSync22(filePath)) {
|
|
262651
263010
|
return new Response("Not Found", { status: 404 });
|
|
262652
263011
|
}
|
|
262653
263012
|
} else {
|
|
262654
263013
|
filePath = join26(this.root, "404.html");
|
|
262655
263014
|
notFoundFallback = true;
|
|
262656
|
-
if (!
|
|
263015
|
+
if (!existsSync22(filePath)) {
|
|
262657
263016
|
return new Response("Not Found", { status: 404, headers: { "Content-Type": "text/plain" } });
|
|
262658
263017
|
}
|
|
262659
263018
|
}
|
|
262660
263019
|
}
|
|
262661
263020
|
const stat = statSync8(filePath);
|
|
262662
|
-
const ext =
|
|
263021
|
+
const ext = extname9(filePath).toLowerCase();
|
|
262663
263022
|
const contentType = MIME_TYPES[ext] ?? "application/octet-stream";
|
|
262664
263023
|
const bytes = await readBytes(filePath);
|
|
262665
263024
|
let etagValue = "";
|
|
@@ -264887,8 +265246,8 @@ var init_bot_detection = __esm({
|
|
|
264887
265246
|
|
|
264888
265247
|
// ../../packages/security/tw/content-security/protector.ts
|
|
264889
265248
|
function sanitizeFilename(filename) {
|
|
264890
|
-
const
|
|
264891
|
-
let clean =
|
|
265249
|
+
const basename4 = filename.replace(/^.*[\\/]/, "");
|
|
265250
|
+
let clean = basename4.replace(/\x00/g, "");
|
|
264892
265251
|
clean = clean.replace(/[<>:"|?*]/g, "_");
|
|
264893
265252
|
clean = clean.replace(/^\.+/, "");
|
|
264894
265253
|
if (clean.length > 255) {
|
|
@@ -271629,7 +271988,7 @@ var init_tw9 = __esm({
|
|
|
271629
271988
|
});
|
|
271630
271989
|
|
|
271631
271990
|
// ../../packages/server/tw/ssr/index.ts
|
|
271632
|
-
import { readFileSync as
|
|
271991
|
+
import { readFileSync as readFileSync15, writeFileSync as writeFileSync9, existsSync as existsSync23, mkdirSync as mkdirSync7 } from "node:fs";
|
|
271633
271992
|
import { createHash as createHash6 } from "node:crypto";
|
|
271634
271993
|
import { join as join27 } from "node:path";
|
|
271635
271994
|
import { existsSync as existsSyncSync } from "node:fs";
|
|
@@ -271643,7 +272002,7 @@ function getCachedSSR(pathname) {
|
|
|
271643
272002
|
}
|
|
271644
272003
|
const diskPath = join27(_diskCacheDir, pathname.replace(/[\/]/g, "_") + ".html");
|
|
271645
272004
|
if (existsSyncSync(diskPath)) {
|
|
271646
|
-
const content =
|
|
272005
|
+
const content = readFileSync15(diskPath, "utf-8");
|
|
271647
272006
|
const etag = createHash6("sha256").update(content).digest("hex").slice(0, 16);
|
|
271648
272007
|
_ssrCache.set(pathname, { html: content, etag, expires: Date.now() + 6e4 });
|
|
271649
272008
|
return { html: content, etag };
|
|
@@ -271656,7 +272015,7 @@ function setCachedSSR(pathname, html) {
|
|
|
271656
272015
|
try {
|
|
271657
272016
|
if (!existsSyncSync(_diskCacheDir)) mkdirSync7(_diskCacheDir, { recursive: true });
|
|
271658
272017
|
const diskPath = join27(_diskCacheDir, pathname.replace(/[\/]/g, "_") + ".html");
|
|
271659
|
-
|
|
272018
|
+
writeFileSync9(diskPath, html);
|
|
271660
272019
|
} catch {
|
|
271661
272020
|
}
|
|
271662
272021
|
return etag;
|
|
@@ -271759,9 +272118,9 @@ var init_ssr = __esm({
|
|
|
271759
272118
|
}
|
|
271760
272119
|
}
|
|
271761
272120
|
const filePath = this.resolveRoute(pathname);
|
|
271762
|
-
if (!filePath || !
|
|
272121
|
+
if (!filePath || !existsSync23(filePath)) return null;
|
|
271763
272122
|
try {
|
|
271764
|
-
const source =
|
|
272123
|
+
const source = readFileSync15(filePath, "utf-8");
|
|
271765
272124
|
return {
|
|
271766
272125
|
html: `<html><body>SSR sync not available</body></html>`,
|
|
271767
272126
|
css: "",
|
|
@@ -271796,35 +272155,35 @@ var init_ssr = __esm({
|
|
|
271796
272155
|
let currentDir = this.pagesDir;
|
|
271797
272156
|
if (segments.length === 0) {
|
|
271798
272157
|
const pagePath = join27(this.pagesDir, "page.tw");
|
|
271799
|
-
if (
|
|
272158
|
+
if (existsSync23(pagePath)) return pagePath;
|
|
271800
272159
|
const indexPath = join27(this.pagesDir, "index.tw");
|
|
271801
|
-
if (
|
|
272160
|
+
if (existsSync23(indexPath)) return indexPath;
|
|
271802
272161
|
return null;
|
|
271803
272162
|
}
|
|
271804
272163
|
for (let i = 0; i < segments.length; i++) {
|
|
271805
272164
|
const seg = segments[i];
|
|
271806
272165
|
const isLast = i === segments.length - 1;
|
|
271807
|
-
const entries =
|
|
272166
|
+
const entries = existsSync23(currentDir) ? __require("node:fs").readdirSync(currentDir) : [];
|
|
271808
272167
|
if (isLast) {
|
|
271809
272168
|
const exactPath = join27(currentDir, seg + ".tw");
|
|
271810
|
-
if (
|
|
272169
|
+
if (existsSync23(exactPath)) return exactPath;
|
|
271811
272170
|
const dirPage = join27(currentDir, seg, "page.tw");
|
|
271812
|
-
if (
|
|
272171
|
+
if (existsSync23(dirPage)) return dirPage;
|
|
271813
272172
|
const paramFile = entries.find((e) => e.match(/^\[([^\]]+)\]\.tw$/));
|
|
271814
272173
|
if (paramFile) return join27(currentDir, paramFile);
|
|
271815
272174
|
const paramDir = entries.find((e) => e.match(/^\[([^\]]+)\]$/));
|
|
271816
272175
|
if (paramDir) {
|
|
271817
272176
|
const p = join27(currentDir, paramDir, "page.tw");
|
|
271818
|
-
if (
|
|
272177
|
+
if (existsSync23(p)) return p;
|
|
271819
272178
|
const pIdx = join27(currentDir, paramDir, "index.tw");
|
|
271820
|
-
if (
|
|
272179
|
+
if (existsSync23(pIdx)) return pIdx;
|
|
271821
272180
|
}
|
|
271822
272181
|
const idx = join27(currentDir, seg, "index.tw");
|
|
271823
|
-
if (
|
|
272182
|
+
if (existsSync23(idx)) return idx;
|
|
271824
272183
|
return null;
|
|
271825
272184
|
}
|
|
271826
272185
|
const dirPath = join27(currentDir, seg);
|
|
271827
|
-
if (
|
|
272186
|
+
if (existsSync23(dirPath) && __require("node:fs").statSync(dirPath).isDirectory()) {
|
|
271828
272187
|
currentDir = dirPath;
|
|
271829
272188
|
} else {
|
|
271830
272189
|
const paramDir = entries.find((e) => e.match(/^\[([^\]]+)\]$/));
|
|
@@ -273337,7 +273696,7 @@ __export(tw_exports6, {
|
|
|
273337
273696
|
wwwRedirect: () => wwwRedirect
|
|
273338
273697
|
});
|
|
273339
273698
|
import { join as join28 } from "node:path";
|
|
273340
|
-
import { existsSync as
|
|
273699
|
+
import { existsSync as existsSync24, readFileSync as readFileSync16 } from "node:fs";
|
|
273341
273700
|
function normalizePathname(p) {
|
|
273342
273701
|
return p.replace(/\/{2,}/g, "/");
|
|
273343
273702
|
}
|
|
@@ -273538,6 +273897,19 @@ var init_tw10 = __esm({
|
|
|
273538
273897
|
const entries = Object.entries(cfgIn.rewrites);
|
|
273539
273898
|
cfgIn.rewrites = entries.map(([from, to]) => typeof to === "string" ? { from, to } : { from, ...to });
|
|
273540
273899
|
}
|
|
273900
|
+
if (Array.isArray(cfgIn.headers)) {
|
|
273901
|
+
const HEADER_ENTRY_KEYS = /* @__PURE__ */ new Set(["source", "headers"]);
|
|
273902
|
+
for (const h3 of cfgIn.headers) {
|
|
273903
|
+
if (!h3 || typeof h3 !== "object") continue;
|
|
273904
|
+
const unknown = Object.keys(h3).filter((k) => !HEADER_ENTRY_KEYS.has(k));
|
|
273905
|
+
if (unknown.length > 0) {
|
|
273906
|
+
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'?)" : ""));
|
|
273907
|
+
}
|
|
273908
|
+
if (h3.source === void 0 && h3.path !== void 0) {
|
|
273909
|
+
console.warn("[tw] headers: entry uses 'path' instead of 'source' -- it will not be applied");
|
|
273910
|
+
}
|
|
273911
|
+
}
|
|
273912
|
+
}
|
|
273541
273913
|
for (const h3 of cfgIn.headers ?? []) {
|
|
273542
273914
|
if (h3?.headers && typeof h3.headers === "object") {
|
|
273543
273915
|
for (const k of Object.keys(h3.headers)) {
|
|
@@ -273615,11 +273987,11 @@ var init_tw10 = __esm({
|
|
|
273615
273987
|
}
|
|
273616
273988
|
}
|
|
273617
273989
|
const staticDir = this.options.staticDir ?? join28(options.rootDir, ".tw");
|
|
273618
|
-
if (
|
|
273990
|
+
if (existsSync24(staticDir)) {
|
|
273619
273991
|
try {
|
|
273620
273992
|
const manifestPath = join28(staticDir, "routes.json");
|
|
273621
|
-
if (
|
|
273622
|
-
const manifest = JSON.parse(
|
|
273993
|
+
if (existsSync24(manifestPath)) {
|
|
273994
|
+
const manifest = JSON.parse(readFileSync16(manifestPath, "utf-8"));
|
|
273623
273995
|
for (const [route, secs] of Object.entries(manifest)) {
|
|
273624
273996
|
this.isrRoutes.set(route, secs);
|
|
273625
273997
|
}
|
|
@@ -273637,7 +274009,7 @@ var init_tw10 = __esm({
|
|
|
273637
274009
|
});
|
|
273638
274010
|
}
|
|
273639
274011
|
const homeDir = this.options.pagesDir ?? join28(options.rootDir, "home");
|
|
273640
|
-
if (
|
|
274012
|
+
if (existsSync24(homeDir)) {
|
|
273641
274013
|
this.ssr = new SSRRenderer({ pagesDir: homeDir, enableCache: true, cacheTTL: 6e4 });
|
|
273642
274014
|
}
|
|
273643
274015
|
}
|
|
@@ -273684,11 +274056,11 @@ var init_tw10 = __esm({
|
|
|
273684
274056
|
middlewarePath = null;
|
|
273685
274057
|
loadMiddleware() {
|
|
273686
274058
|
const middlewarePath = join28(this.options.rootDir, "middleware.twm");
|
|
273687
|
-
if (
|
|
274059
|
+
if (existsSync24(middlewarePath)) {
|
|
273688
274060
|
this.middlewarePath = middlewarePath;
|
|
273689
274061
|
console.log(" Middleware: middleware.twm loaded");
|
|
273690
274062
|
try {
|
|
273691
|
-
const src =
|
|
274063
|
+
const src = readFileSync16(middlewarePath, "utf-8");
|
|
273692
274064
|
const rules = parseRules(src, "middleware.twm");
|
|
273693
274065
|
for (const r of rules) {
|
|
273694
274066
|
const conds = [];
|
|
@@ -274179,7 +274551,7 @@ var init_tw10 = __esm({
|
|
|
274179
274551
|
return new Response("Bad Request", { status: 400 });
|
|
274180
274552
|
}
|
|
274181
274553
|
const homeDir = join28(this.options.rootDir, "home");
|
|
274182
|
-
if (!
|
|
274554
|
+
if (!existsSync24(homeDir)) return new Response("Not Found", { status: 404 });
|
|
274183
274555
|
try {
|
|
274184
274556
|
const { createRenderPipeline: createRenderPipeline2 } = await Promise.resolve().then(() => (init_routing2(), routing_exports));
|
|
274185
274557
|
if (!this.renderPipeline) {
|
|
@@ -274328,7 +274700,7 @@ var init_tw10 = __esm({
|
|
|
274328
274700
|
try {
|
|
274329
274701
|
const { createRenderPipeline: createRenderPipeline2 } = await Promise.resolve().then(() => (init_routing2(), routing_exports));
|
|
274330
274702
|
const homeDir = join28(this.options.rootDir, "home");
|
|
274331
|
-
if (
|
|
274703
|
+
if (existsSync24(homeDir)) {
|
|
274332
274704
|
const pipeline = createRenderPipeline2({
|
|
274333
274705
|
rootDir: this.options.rootDir,
|
|
274334
274706
|
homeDir,
|
|
@@ -274388,7 +274760,7 @@ ${err2.stack ?? ""}`);
|
|
|
274388
274760
|
try {
|
|
274389
274761
|
const { createRenderPipeline: createRenderPipeline2, setActivePipeline: setActivePipeline2 } = await Promise.resolve().then(() => (init_routing2(), routing_exports));
|
|
274390
274762
|
const homeDir = join28(this.options.rootDir, "home");
|
|
274391
|
-
if (
|
|
274763
|
+
if (existsSync24(homeDir)) {
|
|
274392
274764
|
if (!this.renderPipeline) {
|
|
274393
274765
|
this.renderPipeline = createRenderPipeline2({
|
|
274394
274766
|
rootDir: this.options.rootDir,
|
|
@@ -289157,7 +289529,7 @@ __export(twm_loader_exports, {
|
|
|
289157
289529
|
stripCommentsSafe: () => stripCommentsSafe,
|
|
289158
289530
|
validateTWMSyntax: () => validateTWMSyntax
|
|
289159
289531
|
});
|
|
289160
|
-
import { readFileSync as
|
|
289532
|
+
import { readFileSync as readFileSync17, existsSync as existsSync25 } from "node:fs";
|
|
289161
289533
|
import { join as join29 } from "node:path";
|
|
289162
289534
|
function clearTWMCache() {
|
|
289163
289535
|
moduleCache.clear();
|
|
@@ -289165,7 +289537,7 @@ function clearTWMCache() {
|
|
|
289165
289537
|
function validateTWMSyntax(filePath) {
|
|
289166
289538
|
let source;
|
|
289167
289539
|
try {
|
|
289168
|
-
source =
|
|
289540
|
+
source = readFileSync17(filePath, "utf-8");
|
|
289169
289541
|
} catch (err2) {
|
|
289170
289542
|
return "cannot read: " + (err2?.message ?? err2);
|
|
289171
289543
|
}
|
|
@@ -289265,7 +289637,7 @@ async function loadLibModule(rootDir, name) {
|
|
|
289265
289637
|
const cacheKey = rootDir + "/" + rel;
|
|
289266
289638
|
if (libCache.has(cacheKey)) return libCache.get(cacheKey);
|
|
289267
289639
|
const libPath = join29(rootDir, "lib", rel + ".ts");
|
|
289268
|
-
if (!
|
|
289640
|
+
if (!existsSync25(libPath)) {
|
|
289269
289641
|
throw new Error("Module '" + name + "' not found. Create lib/" + name + ".ts");
|
|
289270
289642
|
}
|
|
289271
289643
|
try {
|
|
@@ -289307,10 +289679,10 @@ async function loadTWMModule(filePath, rootDir) {
|
|
|
289307
289679
|
const cacheKey = filePath;
|
|
289308
289680
|
const cached2 = moduleCache.get(cacheKey);
|
|
289309
289681
|
if (cached2) return cached2;
|
|
289310
|
-
if (!
|
|
289682
|
+
if (!existsSync25(filePath)) {
|
|
289311
289683
|
throw new Error("TWM module not found: " + filePath);
|
|
289312
289684
|
}
|
|
289313
|
-
const source =
|
|
289685
|
+
const source = readFileSync17(filePath, "utf-8");
|
|
289314
289686
|
const rd = rootDir || process.cwd();
|
|
289315
289687
|
if (isRuleDsl(source)) {
|
|
289316
289688
|
try {
|
|
@@ -289875,6 +290247,7 @@ var init_twm_loader = __esm({
|
|
|
289875
290247
|
// tw/commands/server-boundary.ts
|
|
289876
290248
|
var server_boundary_exports = {};
|
|
289877
290249
|
__export(server_boundary_exports, {
|
|
290250
|
+
CLIENT_SAFE_MARKER: () => CLIENT_SAFE_MARKER,
|
|
289878
290251
|
DEFAULT_DENY_PACKAGES: () => DEFAULT_DENY_PACKAGES,
|
|
289879
290252
|
DENY_NODE_BUILTINS: () => DENY_NODE_BUILTINS,
|
|
289880
290253
|
SERVER_ONLY_MARKER: () => SERVER_ONLY_MARKER,
|
|
@@ -289883,19 +290256,32 @@ __export(server_boundary_exports, {
|
|
|
289883
290256
|
formatChain: () => formatChain,
|
|
289884
290257
|
walkClientGraph: () => walkClientGraph
|
|
289885
290258
|
});
|
|
289886
|
-
import { readFileSync as
|
|
289887
|
-
import { dirname as
|
|
290259
|
+
import { readFileSync as readFileSync18, existsSync as existsSync26 } from "node:fs";
|
|
290260
|
+
import { dirname as dirname13, resolve as resolve7, extname as extname10, relative as relative2, sep as sep2 } from "node:path";
|
|
290261
|
+
function hasMarker(src, marker) {
|
|
290262
|
+
return src.includes(`"${marker}"`) || src.includes(`'${marker}'`);
|
|
290263
|
+
}
|
|
289888
290264
|
function collectModuleImports(src) {
|
|
289889
290265
|
const out = [];
|
|
289890
290266
|
if (!src.trim()) return out;
|
|
289891
290267
|
const sf = ts4.createSourceFile("m.ts", src, ts4.ScriptTarget.Latest, true, ts4.ScriptKind.TSX);
|
|
290268
|
+
const names = (node) => {
|
|
290269
|
+
const clause = node.importClause;
|
|
290270
|
+
if (!clause) return [];
|
|
290271
|
+
const out2 = [];
|
|
290272
|
+
if (clause.name) out2.push(clause.name.text);
|
|
290273
|
+
const nb = clause.namedBindings;
|
|
290274
|
+
if (nb && ts4.isNamespaceImport(nb)) out2.push(nb.name.text);
|
|
290275
|
+
else if (nb && ts4.isNamedImports(nb)) for (const el of nb.elements) out2.push((el.name ?? el.propertyName).text);
|
|
290276
|
+
return out2;
|
|
290277
|
+
};
|
|
289892
290278
|
const visit = (node) => {
|
|
289893
290279
|
if (ts4.isImportDeclaration(node) && ts4.isStringLiteral(node.moduleSpecifier)) {
|
|
289894
|
-
out.push({ specifier: node.moduleSpecifier.text, kind: "import" });
|
|
290280
|
+
out.push({ specifier: node.moduleSpecifier.text, kind: "import", names: names(node), source: node.getText(sf) });
|
|
289895
290281
|
} else if (ts4.isExportDeclaration(node) && node.moduleSpecifier && ts4.isStringLiteral(node.moduleSpecifier)) {
|
|
289896
|
-
out.push({ specifier: node.moduleSpecifier.text, kind: "export-from" });
|
|
290282
|
+
out.push({ specifier: node.moduleSpecifier.text, kind: "export-from", names: [], source: node.getText(sf) });
|
|
289897
290283
|
} else if (ts4.isCallExpression(node) && node.expression.kind === ts4.SyntaxKind.ImportKeyword && node.arguments[0] && ts4.isStringLiteral(node.arguments[0])) {
|
|
289898
|
-
out.push({ specifier: node.arguments[0].text, kind: "dynamic" });
|
|
290284
|
+
out.push({ specifier: node.arguments[0].text, kind: "dynamic", names: [], source: node.getText(sf) });
|
|
289899
290285
|
}
|
|
289900
290286
|
ts4.forEachChild(node, visit);
|
|
289901
290287
|
};
|
|
@@ -289908,8 +290294,8 @@ function isLocal(spec) {
|
|
|
289908
290294
|
function resolveLocal(spec, fromDir) {
|
|
289909
290295
|
const rel = spec.startsWith("@./") ? spec.slice(2) : spec;
|
|
289910
290296
|
const base = resolve7(fromDir, rel);
|
|
289911
|
-
if (
|
|
289912
|
-
for (const e of LOCAL_EXT) if (
|
|
290297
|
+
if (existsSync26(base) && extname10(base)) return base;
|
|
290298
|
+
for (const e of LOCAL_EXT) if (existsSync26(base + e)) return base + e;
|
|
289913
290299
|
return null;
|
|
289914
290300
|
}
|
|
289915
290301
|
function matchesOnlyPackages(spec, only) {
|
|
@@ -289933,41 +290319,50 @@ function walkClientGraph(entryFiles, opts = {}) {
|
|
|
289933
290319
|
const only = opts.onlyPackages ?? [];
|
|
289934
290320
|
const label = (f) => opts.rootDir && f.startsWith(opts.rootDir) ? relative2(opts.rootDir, f) : f;
|
|
289935
290321
|
const queue = entryFiles.map((f) => ({ file: resolve7(f), chain: [label(resolve7(f))] }));
|
|
290322
|
+
const entrySet = new Set(entryFiles.map((f) => resolve7(f)));
|
|
289936
290323
|
while (queue.length) {
|
|
289937
290324
|
const { file, chain: chain2 } = queue.shift();
|
|
289938
290325
|
if (seen.has(file)) continue;
|
|
289939
290326
|
seen.add(file);
|
|
289940
|
-
if (!
|
|
290327
|
+
if (!existsSync26(file)) continue;
|
|
289941
290328
|
let src;
|
|
289942
290329
|
try {
|
|
289943
|
-
src =
|
|
290330
|
+
src = readFileSync18(file, "utf8");
|
|
289944
290331
|
} catch {
|
|
289945
290332
|
continue;
|
|
289946
290333
|
}
|
|
289947
290334
|
const scannable = opts.stripServerRegions ? opts.stripServerRegions(src) : src;
|
|
289948
|
-
if (scannable.includes(`"${SERVER_ONLY_MARKER}"`) || scannable.includes(`'${SERVER_ONLY_MARKER}'`)) {
|
|
289949
|
-
violations.push({ file, specifier: SERVER_ONLY_MARKER, layer: "L4", chain: [...chain2, SERVER_ONLY_MARKER] });
|
|
289950
|
-
}
|
|
289951
290335
|
for (const imp of collectModuleImports(scannable)) {
|
|
289952
290336
|
const spec = imp.specifier;
|
|
289953
290337
|
let layer = null;
|
|
289954
290338
|
if (isServerOnlyByName(spec)) layer = "name";
|
|
289955
290339
|
else if (isLocal(spec)) {
|
|
289956
|
-
const resolvedLocal = resolveLocal(spec,
|
|
290340
|
+
const resolvedLocal = resolveLocal(spec, dirname13(file));
|
|
289957
290341
|
const libRoot = opts.rootDir ? resolve7(opts.rootDir, "lib") : null;
|
|
289958
290342
|
if (resolvedLocal && libRoot && (resolvedLocal === libRoot || resolvedLocal.startsWith(libRoot + sep2))) {
|
|
289959
|
-
|
|
290343
|
+
let clientSafe = false;
|
|
290344
|
+
try {
|
|
290345
|
+
clientSafe = hasMarker(readFileSync18(resolvedLocal, "utf8"), CLIENT_SAFE_MARKER);
|
|
290346
|
+
} catch {
|
|
290347
|
+
}
|
|
290348
|
+
if (!clientSafe) layer = "lib";
|
|
289960
290349
|
}
|
|
289961
290350
|
} else if (spec === SERVER_ONLY_MARKER) layer = "L4";
|
|
290351
|
+
else if (spec === CLIENT_SAFE_MARKER) continue;
|
|
289962
290352
|
else if (spec.startsWith("node:") || DENY_NODE_BUILTINS.has(spec)) layer = "L1";
|
|
289963
290353
|
else if (matchesOnlyPackages(spec, only)) layer = "L3";
|
|
289964
290354
|
else if (DEFAULT_DENY_PACKAGES.includes(packageName(spec))) layer = "L2";
|
|
289965
290355
|
if (layer) {
|
|
290356
|
+
if (layer === "lib" && entrySet.has(file) && imp.names.length > 0) {
|
|
290357
|
+
const clientBody = scannable.replace(/^\s*import\s[\s\S]*?from\s*["'][^"']+["'];?/gm, "").replace(/^\s*import\s*["'][^"']+["'];?/gm, "").replace(/^\s*export\s[\s\S]*?from\s*["'][^"']+["'];?/gm, "");
|
|
290358
|
+
const usedOnClient = imp.names.some((nm) => new RegExp("\\b" + nm.replace(/[$]/g, "\\$") + "\\b").test(clientBody));
|
|
290359
|
+
if (!usedOnClient) continue;
|
|
290360
|
+
}
|
|
289966
290361
|
violations.push({ file, specifier: spec, layer, chain: [...chain2, spec] });
|
|
289967
290362
|
continue;
|
|
289968
290363
|
}
|
|
289969
290364
|
if (isLocal(spec)) {
|
|
289970
|
-
const local = resolveLocal(spec,
|
|
290365
|
+
const local = resolveLocal(spec, dirname13(file));
|
|
289971
290366
|
if (local) queue.push({ file: local, chain: [...chain2, label(local)] });
|
|
289972
290367
|
}
|
|
289973
290368
|
}
|
|
@@ -289997,11 +290392,12 @@ async function devServerOnlyBoundary(rootDir, entryFiles, onlyPackages) {
|
|
|
289997
290392
|
const viols = walkClientGraph(entryFiles, { rootDir, onlyPackages, stripServerRegions: strip });
|
|
289998
290393
|
return viols.map((v) => `${v.layer}:${v.specifier} [${formatChain(v)}]`);
|
|
289999
290394
|
}
|
|
290000
|
-
var ts4, SERVER_ONLY_MARKER, DENY_NODE_BUILTINS, DEFAULT_DENY_PACKAGES, LOCAL_EXT;
|
|
290395
|
+
var ts4, SERVER_ONLY_MARKER, CLIENT_SAFE_MARKER, DENY_NODE_BUILTINS, DEFAULT_DENY_PACKAGES, LOCAL_EXT;
|
|
290001
290396
|
var init_server_boundary = __esm({
|
|
290002
290397
|
"tw/commands/server-boundary.ts"() {
|
|
290003
290398
|
ts4 = __toESM(require_typescript(), 1);
|
|
290004
290399
|
SERVER_ONLY_MARKER = "@tw/server-only";
|
|
290400
|
+
CLIENT_SAFE_MARKER = "@tw/client-safe";
|
|
290005
290401
|
DENY_NODE_BUILTINS = /* @__PURE__ */ new Set([
|
|
290006
290402
|
"fs",
|
|
290007
290403
|
"fs/promises",
|
|
@@ -290061,9 +290457,9 @@ __export(build_exports, {
|
|
|
290061
290457
|
csrifyHtml: () => csrifyHtml,
|
|
290062
290458
|
extractRenderMode: () => extractRenderMode2
|
|
290063
290459
|
});
|
|
290064
|
-
import { join as join30, resolve as resolve8, dirname as
|
|
290460
|
+
import { join as join30, resolve as resolve8, dirname as dirname14, extname as extname11 } from "node:path";
|
|
290065
290461
|
import { createHash as createHash8 } from "node:crypto";
|
|
290066
|
-
import { existsSync as
|
|
290462
|
+
import { existsSync as existsSync27, mkdirSync as mkdirSync8, writeFileSync as writeFileSync10, readFileSync as readFileSync19, readdirSync as readdirSync9, statSync as statSync9, copyFileSync as copyFileSync2, unlinkSync as unlinkSync4, rmdirSync } from "node:fs";
|
|
290067
290463
|
function findCompilerPath() {
|
|
290068
290464
|
const fileUrl = import.meta.url.replace("file://", "");
|
|
290069
290465
|
const cmdDir = fileUrl.substring(0, fileUrl.lastIndexOf("/"));
|
|
@@ -290073,7 +290469,7 @@ function findCompilerPath() {
|
|
|
290073
290469
|
resolve8(process.cwd(), "node_modules/tw-framework/packages/compiler/tw/index.ts")
|
|
290074
290470
|
];
|
|
290075
290471
|
for (const p of candidates) {
|
|
290076
|
-
if (
|
|
290472
|
+
if (existsSync27(p)) return p;
|
|
290077
290473
|
}
|
|
290078
290474
|
return resolve8(process.cwd(), "packages/compiler/tw/index.ts");
|
|
290079
290475
|
}
|
|
@@ -290103,7 +290499,7 @@ function matchesPageFile(entry, stem) {
|
|
|
290103
290499
|
return entry === stem || entry === stem + ".tw";
|
|
290104
290500
|
}
|
|
290105
290501
|
function collectFiles(dir, fileName, results) {
|
|
290106
|
-
if (!
|
|
290502
|
+
if (!existsSync27(dir)) return;
|
|
290107
290503
|
for (const entry of readdirSync9(dir)) {
|
|
290108
290504
|
if (entry.startsWith("_") || entry.startsWith("@")) continue;
|
|
290109
290505
|
const fullPath = join30(dir, entry);
|
|
@@ -290116,7 +290512,7 @@ function collectFiles(dir, fileName, results) {
|
|
|
290116
290512
|
}
|
|
290117
290513
|
}
|
|
290118
290514
|
function copyDir2(src, dest) {
|
|
290119
|
-
if (!
|
|
290515
|
+
if (!existsSync27(src)) return;
|
|
290120
290516
|
mkdirSync8(dest, { recursive: true });
|
|
290121
290517
|
for (const entry of readdirSync9(src)) {
|
|
290122
290518
|
const srcPath = join30(src, entry);
|
|
@@ -290135,7 +290531,7 @@ function findLayoutChain(dir, homeDir) {
|
|
|
290135
290531
|
const homeAbs = resolve8(homeDir);
|
|
290136
290532
|
for (let i = 0; i < 16; i++) {
|
|
290137
290533
|
const cand = join30(cur, "layout.tw");
|
|
290138
|
-
if (
|
|
290534
|
+
if (existsSync27(cand)) chain2.push(cand);
|
|
290139
290535
|
if (resolve8(cur) === homeAbs) break;
|
|
290140
290536
|
const parent = resolve8(cur, "..");
|
|
290141
290537
|
if (parent === resolve8(cur) || !parent.startsWith(homeAbs)) break;
|
|
@@ -290145,7 +290541,7 @@ function findLayoutChain(dir, homeDir) {
|
|
|
290145
290541
|
}
|
|
290146
290542
|
function loadGlobalStyles(rootDir) {
|
|
290147
290543
|
const legacy = join30(rootDir, "style.css");
|
|
290148
|
-
if (
|
|
290544
|
+
if (existsSync27(legacy)) return readFileSync19(legacy, "utf-8");
|
|
290149
290545
|
return "";
|
|
290150
290546
|
}
|
|
290151
290547
|
function collectComponentUsages(node, out) {
|
|
@@ -290238,19 +290634,19 @@ async function transformEmittedFiles(outDir, pm) {
|
|
|
290238
290634
|
await walk3(p);
|
|
290239
290635
|
continue;
|
|
290240
290636
|
}
|
|
290241
|
-
const ext =
|
|
290637
|
+
const ext = extname11(e.name).toLowerCase();
|
|
290242
290638
|
const rel = p.slice(outDir.length).replace(/^[\\/]/, "");
|
|
290243
290639
|
try {
|
|
290244
290640
|
if (js && (ext === ".js" || ext === ".mjs")) {
|
|
290245
|
-
const out = await pm.runHookChain("transform:js",
|
|
290246
|
-
if (typeof out === "string")
|
|
290641
|
+
const out = await pm.runHookChain("transform:js", readFileSync19(p, "utf-8"), { file: rel });
|
|
290642
|
+
if (typeof out === "string") writeFileSync10(p, out);
|
|
290247
290643
|
} else if (css && ext === ".css") {
|
|
290248
|
-
const out = await pm.runHookChain("transform:css",
|
|
290249
|
-
if (typeof out === "string")
|
|
290644
|
+
const out = await pm.runHookChain("transform:css", readFileSync19(p, "utf-8"), { file: rel });
|
|
290645
|
+
if (typeof out === "string") writeFileSync10(p, out);
|
|
290250
290646
|
} else if (asset && ![".html", ".json", ".js", ".mjs", ".css"].includes(ext)) {
|
|
290251
|
-
const buf =
|
|
290647
|
+
const buf = readFileSync19(p);
|
|
290252
290648
|
const out = await pm.runHookChain("optimize:asset", buf, { file: rel });
|
|
290253
|
-
if (out && out !== buf)
|
|
290649
|
+
if (out && out !== buf) writeFileSync10(p, out);
|
|
290254
290650
|
}
|
|
290255
290651
|
} catch {
|
|
290256
290652
|
}
|
|
@@ -290304,9 +290700,9 @@ function stripServerRegionsForScan(source) {
|
|
|
290304
290700
|
async function buildCommand() {
|
|
290305
290701
|
const rootDir = process.cwd();
|
|
290306
290702
|
const envPath = join30(rootDir, ".env");
|
|
290307
|
-
if (
|
|
290703
|
+
if (existsSync27(envPath)) {
|
|
290308
290704
|
try {
|
|
290309
|
-
for (const line of
|
|
290705
|
+
for (const line of readFileSync19(envPath, "utf-8").split("\n")) {
|
|
290310
290706
|
const m = /^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/.exec(line);
|
|
290311
290707
|
if (m && !(m[1] in process.env)) {
|
|
290312
290708
|
process.env[m[1]] = m[2].replace(/^["']|["']$/g, "");
|
|
@@ -290327,6 +290723,7 @@ async function buildCommand() {
|
|
|
290327
290723
|
};
|
|
290328
290724
|
let needsRuntime = false;
|
|
290329
290725
|
let skippedPages = 0;
|
|
290726
|
+
let skippedNotFound = 0;
|
|
290330
290727
|
let incCache = {};
|
|
290331
290728
|
const incNext = {};
|
|
290332
290729
|
const incHash = (t3) => createHash8("sha256").update(t3).digest("hex").slice(0, 16);
|
|
@@ -290436,11 +290833,35 @@ async function buildCommand() {
|
|
|
290436
290833
|
};
|
|
290437
290834
|
try {
|
|
290438
290835
|
const cfgPath = join30(rootDir, "tw.config.ts");
|
|
290439
|
-
if (
|
|
290836
|
+
if (existsSync27(cfgPath)) {
|
|
290440
290837
|
const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
290441
290838
|
const cfgMod = await twImportTs2(cfgPath);
|
|
290442
290839
|
const cfg = cfgMod.default ?? cfgMod;
|
|
290443
290840
|
resolvedCfg = cfg;
|
|
290841
|
+
try {
|
|
290842
|
+
const HEADER_KEYS = /* @__PURE__ */ new Set(["source", "headers"]);
|
|
290843
|
+
const REDIRECT_KEYS = /* @__PURE__ */ new Set(["from", "to", "status", "source", "destination", "permanent"]);
|
|
290844
|
+
const cfgErrs = [];
|
|
290845
|
+
if (Array.isArray(cfg?.headers)) {
|
|
290846
|
+
for (const h4 of cfg.headers) {
|
|
290847
|
+
if (!h4 || typeof h4 !== "object") continue;
|
|
290848
|
+
const unknown = Object.keys(h4).filter((k) => !HEADER_KEYS.has(k));
|
|
290849
|
+
if (unknown.length) cfgErrs.push("headers: unrecognized key " + unknown.join(", ") + " (accepted: source, headers)");
|
|
290850
|
+
}
|
|
290851
|
+
}
|
|
290852
|
+
if (Array.isArray(cfg?.redirects)) {
|
|
290853
|
+
for (const r of cfg.redirects) {
|
|
290854
|
+
if (!r || typeof r !== "object") continue;
|
|
290855
|
+
const unknown = Object.keys(r).filter((k) => !REDIRECT_KEYS.has(k));
|
|
290856
|
+
if (unknown.length) cfgErrs.push("redirects: unrecognized key " + unknown.join(", ") + " (accepted: from, to, status)");
|
|
290857
|
+
}
|
|
290858
|
+
}
|
|
290859
|
+
for (const m of cfgErrs) {
|
|
290860
|
+
console.error(" \x1B[31m\u2717\x1B[0m tw.config.ts " + m);
|
|
290861
|
+
errorCount++;
|
|
290862
|
+
}
|
|
290863
|
+
} catch {
|
|
290864
|
+
}
|
|
290444
290865
|
serverBlocksOn = cfg?.server?.blocks ?? cfg?.experimental?.serverBlocks ?? true;
|
|
290445
290866
|
serverOnlyPackages = Array.isArray(cfg?.server?.onlyPackages) ? cfg.server.onlyPackages : [];
|
|
290446
290867
|
fetchTimeoutMs = cfg?.server?.fetchTimeoutMs;
|
|
@@ -290479,7 +290900,7 @@ async function buildCommand() {
|
|
|
290479
290900
|
outDir = join30(rootDir, buildOpts.outputDir);
|
|
290480
290901
|
if (buildOpts.incremental) {
|
|
290481
290902
|
try {
|
|
290482
|
-
incCache = JSON.parse(
|
|
290903
|
+
incCache = JSON.parse(readFileSync19(join30(outDir, ".build-cache.json"), "utf-8"));
|
|
290483
290904
|
} catch {
|
|
290484
290905
|
incCache = {};
|
|
290485
290906
|
}
|
|
@@ -290525,7 +290946,7 @@ async function buildCommand() {
|
|
|
290525
290946
|
} catch {
|
|
290526
290947
|
}
|
|
290527
290948
|
}
|
|
290528
|
-
if (
|
|
290949
|
+
if (existsSync27(outDir)) {
|
|
290529
290950
|
rmDirRecursive(outDir);
|
|
290530
290951
|
}
|
|
290531
290952
|
mkdirSync8(outDir, { recursive: true });
|
|
@@ -290571,7 +290992,7 @@ async function buildCommand() {
|
|
|
290571
290992
|
const plan = foreign.map((fi) => {
|
|
290572
290993
|
let src = "";
|
|
290573
290994
|
try {
|
|
290574
|
-
src =
|
|
290995
|
+
src = readFileSync19(fi.absPath, "utf-8");
|
|
290575
290996
|
} catch {
|
|
290576
290997
|
}
|
|
290577
290998
|
return { fi, engine: ib.detectEngine(src, renderEngine), ...ib.parseClientStrategy(src) };
|
|
@@ -290671,11 +291092,11 @@ async function buildCommand() {
|
|
|
290671
291092
|
const { checkEdgeSafety: checkEdgeSafety2 } = await Promise.resolve().then(() => (init_tw(), tw_exports));
|
|
290672
291093
|
const apiFiles = [];
|
|
290673
291094
|
const apiRoot = join30(homeDir, apiDirName);
|
|
290674
|
-
collectFiles(
|
|
291095
|
+
collectFiles(existsSync27(apiRoot) ? apiRoot : homeDir, "route.twm", apiFiles);
|
|
290675
291096
|
const violations = [];
|
|
290676
291097
|
for (const f of apiFiles) {
|
|
290677
291098
|
try {
|
|
290678
|
-
violations.push(...checkEdgeSafety2(
|
|
291099
|
+
violations.push(...checkEdgeSafety2(readFileSync19(f, "utf-8"), f));
|
|
290679
291100
|
} catch {
|
|
290680
291101
|
}
|
|
290681
291102
|
}
|
|
@@ -290702,23 +291123,23 @@ async function buildCommand() {
|
|
|
290702
291123
|
pf,
|
|
290703
291124
|
rootDir,
|
|
290704
291125
|
{ compileSync: _compileSync, registerComponentTemplate: _registerComponentTemplate, clearComponentRegistry: _clearComponentRegistry },
|
|
290705
|
-
|
|
291126
|
+
readFileSync19(pf, "utf-8"),
|
|
290706
291127
|
(name) => registeredComponentNames.add(name)
|
|
290707
291128
|
);
|
|
290708
291129
|
} catch {
|
|
290709
291130
|
}
|
|
290710
291131
|
}
|
|
290711
291132
|
for (const pf of pageFiles) {
|
|
290712
|
-
if (
|
|
290713
|
-
console.log(" \x1B[33m!\x1B[0m " +
|
|
291133
|
+
if (existsSync27(join30(dirname14(pf), "index.tw"))) {
|
|
291134
|
+
console.log(" \x1B[33m!\x1B[0m " + dirname14(pf).replace(homeDir, "").replace(/^\//, "") + "/ has BOTH page.tw and index.tw");
|
|
290714
291135
|
console.log(" index.tw wins this route -- delete one of them");
|
|
290715
291136
|
}
|
|
290716
291137
|
}
|
|
290717
291138
|
{
|
|
290718
291139
|
const shapes = /* @__PURE__ */ new Map();
|
|
290719
291140
|
for (const pf of pageFiles) {
|
|
290720
|
-
const dir =
|
|
290721
|
-
if (
|
|
291141
|
+
const dir = dirname14(pf);
|
|
291142
|
+
if (existsSync27(join30(dir, "page.twm"))) {
|
|
290722
291143
|
console.log(" \x1B[33m!\x1B[0m " + dir.replace(homeDir, "").replace(/^\//, "") + "/ has BOTH page.tw and page.twm");
|
|
290723
291144
|
console.log(" the .twm handler never runs -- delete one of them");
|
|
290724
291145
|
}
|
|
@@ -290749,26 +291170,26 @@ async function buildCommand() {
|
|
|
290749
291170
|
const routeName = relativePath.replace(/\/?page(?:\.tw)?$/, "").replace(/\\/g, "/");
|
|
290750
291171
|
const routePath = routeName === "" ? "/" : "/" + routeName;
|
|
290751
291172
|
if (buildOpts?.incremental) {
|
|
290752
|
-
const deps = [pageFile, ...findLayoutChain(
|
|
291173
|
+
const deps = [pageFile, ...findLayoutChain(dirname14(pageFile), homeDir)];
|
|
290753
291174
|
let raw = "";
|
|
290754
291175
|
for (const d of deps) {
|
|
290755
291176
|
try {
|
|
290756
|
-
raw += d + "\0" +
|
|
291177
|
+
raw += d + "\0" + readFileSync19(d, "utf-8");
|
|
290757
291178
|
} catch {
|
|
290758
291179
|
}
|
|
290759
291180
|
}
|
|
290760
291181
|
const h3 = incHash(raw);
|
|
290761
291182
|
incNext[pageFile] = h3;
|
|
290762
291183
|
const outHtml = join30(outDir, routeName, "index.html");
|
|
290763
|
-
if (incCache[pageFile] === h3 &&
|
|
291184
|
+
if (incCache[pageFile] === h3 && existsSync27(outHtml)) {
|
|
290764
291185
|
skippedPages++;
|
|
290765
291186
|
continue;
|
|
290766
291187
|
}
|
|
290767
291188
|
}
|
|
290768
291189
|
let paramSets = [{}];
|
|
290769
291190
|
if (/\[[^\]]+\]/.test(pageFile)) {
|
|
290770
|
-
const paramsTwm = join30(
|
|
290771
|
-
if (
|
|
291191
|
+
const paramsTwm = join30(dirname14(pageFile), "params.twm");
|
|
291192
|
+
if (existsSync27(paramsTwm)) {
|
|
290772
291193
|
try {
|
|
290773
291194
|
const { loadTWMModule: loadTWMModule2 } = await Promise.resolve().then(() => (init_twm_loader(), twm_loader_exports));
|
|
290774
291195
|
const pmod = await loadTWMModule2(paramsTwm, rootDir);
|
|
@@ -290802,10 +291223,10 @@ async function buildCommand() {
|
|
|
290802
291223
|
continue;
|
|
290803
291224
|
}
|
|
290804
291225
|
}
|
|
290805
|
-
const renderMode = extractRenderMode2(
|
|
291226
|
+
const renderMode = extractRenderMode2(readFileSync19(pageFile, "utf8"));
|
|
290806
291227
|
try {
|
|
290807
291228
|
const { parseWithDetails: _pd, checkDeclarationConflicts: checkDeclarationConflicts2 } = _compilerMod;
|
|
290808
|
-
const _prog = _pd(
|
|
291229
|
+
const _prog = _pd(readFileSync19(pageFile, "utf-8"), { filePath: pageFile, cache: false }).program;
|
|
290809
291230
|
const _paramNames = routePath.split("/").filter((seg) => seg.startsWith("[")).map((seg) => seg.replace(/^\[+/, "").replace(/\]+$/, "").replace(/^\.\.\./, ""));
|
|
290810
291231
|
for (const c of checkDeclarationConflicts2(_prog, _paramNames)) {
|
|
290811
291232
|
console.error(" \x1B[33m!\x1B[0m " + pageFile.replace(rootDir + "/", "") + ":" + c.line + " " + c.code + " " + c.message);
|
|
@@ -290814,7 +291235,7 @@ async function buildCommand() {
|
|
|
290814
291235
|
} catch {
|
|
290815
291236
|
}
|
|
290816
291237
|
{
|
|
290817
|
-
const pageSrc =
|
|
291238
|
+
const pageSrc = readFileSync19(pageFile, "utf-8");
|
|
290818
291239
|
const { extractCacheDirective: extractCacheDirective2, resolveCache: resolveCache2 } = await Promise.resolve().then(() => (init_tw(), tw_exports));
|
|
290819
291240
|
const cacheMeta = extractCacheDirective2(pageSrc);
|
|
290820
291241
|
let resolved = null;
|
|
@@ -290852,7 +291273,7 @@ async function buildCommand() {
|
|
|
290852
291273
|
console.log(" \x1B[36m~\x1B[0m " + routePath + " [" + renderMode + ": rendered at request time]");
|
|
290853
291274
|
isrRoutes.set(routePath === "" ? "/" : routePath, 0);
|
|
290854
291275
|
try {
|
|
290855
|
-
const src =
|
|
291276
|
+
const src = readFileSync19(pageFile, "utf-8");
|
|
290856
291277
|
if (serverBlocksOn) {
|
|
290857
291278
|
try {
|
|
290858
291279
|
const { parseWithDetails: parseWithDetails2, collectServerBlocks: collectServerBlocks2, checkServerBlocks: checkServerBlocks2, collectReferencedNames: collectReferencedNames3, extractVary: extractVary2 } = _compilerMod;
|
|
@@ -290915,13 +291336,21 @@ async function buildCommand() {
|
|
|
290915
291336
|
_compilerMod.beginCssRouteCapture?.(routePath);
|
|
290916
291337
|
for (const paramSet of paramSets) {
|
|
290917
291338
|
try {
|
|
290918
|
-
const source =
|
|
291339
|
+
const source = readFileSync19(pageFile, "utf-8");
|
|
290919
291340
|
let serverVars = {};
|
|
290920
291341
|
if (serverBlocksOn) {
|
|
290921
291342
|
const { parseWithDetails: parseWithDetails2, collectServerBlocks: collectServerBlocks2, checkServerBlocks: checkServerBlocks2, executeServerBlocks: executeServerBlocks2, encodeServerValues: encodeServerValues2, collectReferencedNames: collectReferencedNames3, extractVary: extractVary2, secretEnvValues: secretEnvValues3, resolveServerImports: resolveServerImports2 } = _compilerMod;
|
|
290922
291343
|
const prog = parseWithDetails2(source, { filePath: pageFile, cache: false, experimental: { serverBlocks: true } }).program;
|
|
290923
291344
|
const sb = collectServerBlocks2(prog);
|
|
290924
291345
|
if (sb.length) {
|
|
291346
|
+
try {
|
|
291347
|
+
const { serverImportCollisions: serverImportCollisions2 } = _compilerMod;
|
|
291348
|
+
for (const c of serverImportCollisions2(source)) {
|
|
291349
|
+
console.error(" \x1B[31m\u2717\x1B[0m " + pageFile.replace(rootDir + "/", "") + ":" + c.line + " TW125 import '" + c.name + `' from "` + c.specifier + '" is also a server-block built-in, so the block would see the built-in instead of your import. Rename it: import { ' + c.name + " as my" + c.name.charAt(0).toUpperCase() + c.name.slice(1) + ' } from "' + c.specifier + '"');
|
|
291350
|
+
errorCount++;
|
|
291351
|
+
}
|
|
291352
|
+
} catch {
|
|
291353
|
+
}
|
|
290925
291354
|
const referenced = collectReferencedNames3(source);
|
|
290926
291355
|
const problems = checkServerBlocks2(prog, {
|
|
290927
291356
|
mode: renderMode,
|
|
@@ -290939,14 +291368,34 @@ async function buildCommand() {
|
|
|
290939
291368
|
const omit = ["headers", "cookies", "query"];
|
|
290940
291369
|
if (!hasExplicitParams) omit.push("params");
|
|
290941
291370
|
const imports = {};
|
|
291371
|
+
try {
|
|
291372
|
+
const { collectModuleImports: collectModuleImports2 } = await Promise.resolve().then(() => (init_server_boundary(), server_boundary_exports));
|
|
291373
|
+
const blockText = sb.map((b) => String(b.source ?? "")).join("\n");
|
|
291374
|
+
const pageLevel = collectModuleImports2(source).filter(
|
|
291375
|
+
(imp) => imp.kind === "import" && imp.names.length > 0 && imp.names.some((nm) => new RegExp("\\b" + nm.replace(/[$]/g, "\\$") + "\\b").test(blockText))
|
|
291376
|
+
);
|
|
291377
|
+
if (pageLevel.length) {
|
|
291378
|
+
Object.assign(imports, await resolveServerImports2({ imports: pageLevel }, pageFile, { dev: false }));
|
|
291379
|
+
}
|
|
291380
|
+
} catch (e) {
|
|
291381
|
+
console.error(" \x1B[31m\u2717\x1B[0m " + pageFile.replace(rootDir + "/", "") + " a page-level import used by a server block could not be resolved: " + (e?.message ?? e));
|
|
291382
|
+
errorCount++;
|
|
291383
|
+
continue;
|
|
291384
|
+
}
|
|
290942
291385
|
for (const b of sb) Object.assign(imports, await resolveServerImports2(b, pageFile, { dev: false }));
|
|
290943
291386
|
try {
|
|
290944
291387
|
const { createServerFetch: createServerFetch2, wrapJsonErrors: wrapJsonErrors2, SERVER_FETCH_BUILD_ID: SERVER_FETCH_BUILD_ID2 } = _compilerMod;
|
|
290945
291388
|
const sfetch = createServerFetch2({ buildId: SERVER_FETCH_BUILD_ID2, timeoutMs: fetchTimeoutMs, maxBytes: fetchCacheMaxBytes });
|
|
290946
291389
|
const fetchShim = (u, i) => sfetch(u, i).then(wrapJsonErrors2);
|
|
290947
|
-
const vals = await executeServerBlocks2(sb, { context: { params: paramSet, env: process.env, loginPath }, imports, omit, omitRuntime: ["getSession", "requireUser", "redirect"
|
|
291390
|
+
const vals = await executeServerBlocks2(sb, { context: { params: paramSet, env: process.env, loginPath }, imports, omit, omitRuntime: ["getSession", "requireUser", "redirect"], label: pageFile, fetch: fetchShim, referenced, maxPayloadBytes, secrets: secretEnvValues3(process.env) });
|
|
290948
291391
|
serverVars = encodeServerValues2(vals);
|
|
290949
291392
|
} catch (e) {
|
|
291393
|
+
const { isServerNotFound: isServerNotFound2 } = _compilerMod;
|
|
291394
|
+
if (typeof isServerNotFound2 === "function" && isServerNotFound2(e)) {
|
|
291395
|
+
console.log(" \x1B[33m!\x1B[0m " + pageFile.replace(rootDir + "/", "") + " notFound() -- page skipped, the host will serve a 404");
|
|
291396
|
+
skippedNotFound++;
|
|
291397
|
+
continue;
|
|
291398
|
+
}
|
|
290950
291399
|
console.error(" \x1B[31m\u2717\x1B[0m " + pageFile.replace(rootDir + "/", "") + " server block failed: " + (e?.message ?? e));
|
|
290951
291400
|
errorCount++;
|
|
290952
291401
|
continue;
|
|
@@ -290957,7 +291406,7 @@ async function buildCommand() {
|
|
|
290957
291406
|
let pageImports = {};
|
|
290958
291407
|
try {
|
|
290959
291408
|
const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
290960
|
-
const { dirname:
|
|
291409
|
+
const { dirname: dirname18, resolve: resolvePath } = await import("node:path");
|
|
290961
291410
|
const parseFn = _compilerMod.parseWithDetails;
|
|
290962
291411
|
const parsed = parseFn(source, pageFile);
|
|
290963
291412
|
const prog = parsed?.program ?? parsed?.ast;
|
|
@@ -290965,7 +291414,7 @@ async function buildCommand() {
|
|
|
290965
291414
|
if (d?.type !== "ImportDirective" || !d.source || d.isTypeOnly) continue;
|
|
290966
291415
|
const spec = String(d.source);
|
|
290967
291416
|
if (!(spec.startsWith("./") || spec.startsWith("../") || spec.startsWith("@./"))) continue;
|
|
290968
|
-
const abs = spec.startsWith("@./") ? resolvePath(rootDir, spec.slice(3)) : resolvePath(
|
|
291417
|
+
const abs = spec.startsWith("@./") ? resolvePath(rootDir, spec.slice(3)) : resolvePath(dirname18(pageFile), spec);
|
|
290969
291418
|
const mod = await twImportTs2(abs);
|
|
290970
291419
|
if (d.namespaceImport) pageImports[d.namespaceImport] = mod;
|
|
290971
291420
|
if (d.defaultImport) pageImports[d.defaultImport] = mod?.default ?? mod;
|
|
@@ -290994,10 +291443,10 @@ async function buildCommand() {
|
|
|
290994
291443
|
}
|
|
290995
291444
|
}
|
|
290996
291445
|
let html = result.html;
|
|
290997
|
-
const layoutChain = findLayoutChain(
|
|
291446
|
+
const layoutChain = findLayoutChain(dirname14(pageFile), homeDir);
|
|
290998
291447
|
if (layoutChain.length > 0) {
|
|
290999
291448
|
const layoutPrograms = layoutChain.map((lp) => {
|
|
291000
|
-
const ls =
|
|
291449
|
+
const ls = readFileSync19(lp, "utf-8");
|
|
291001
291450
|
const lr = _compileSync(ls, { filePath: lp, ...compilePassOpts() });
|
|
291002
291451
|
if (serverBlocksOn) {
|
|
291003
291452
|
const { checkServerBlocks: checkServerBlocks2 } = _compilerMod;
|
|
@@ -291020,12 +291469,12 @@ async function buildCommand() {
|
|
|
291020
291469
|
}
|
|
291021
291470
|
const headSources = [];
|
|
291022
291471
|
const globalHeadTw = join30(homeDir, "head.tw");
|
|
291023
|
-
if (
|
|
291024
|
-
const headTwPath = join30(
|
|
291025
|
-
if (headTwPath !== globalHeadTw &&
|
|
291472
|
+
if (existsSync27(globalHeadTw)) headSources.push(globalHeadTw);
|
|
291473
|
+
const headTwPath = join30(dirname14(pageFile), "head.tw");
|
|
291474
|
+
if (headTwPath !== globalHeadTw && existsSync27(headTwPath)) headSources.push(headTwPath);
|
|
291026
291475
|
for (const headSrc of headSources) {
|
|
291027
291476
|
try {
|
|
291028
|
-
const headSource =
|
|
291477
|
+
const headSource = readFileSync19(headSrc, "utf-8");
|
|
291029
291478
|
const headResult = _compileSync(headSource, { filePath: headSrc });
|
|
291030
291479
|
const headBody = headResult.html.match(/<body>([\s\S]*)<\/body>/);
|
|
291031
291480
|
if (headBody && headBody[1].trim()) {
|
|
@@ -291054,7 +291503,7 @@ async function buildCommand() {
|
|
|
291054
291503
|
}
|
|
291055
291504
|
let pageMods = pageClientLines.get(pageFile);
|
|
291056
291505
|
if (!pageMods) {
|
|
291057
|
-
const chainFiles = findLayoutChain(
|
|
291506
|
+
const chainFiles = findLayoutChain(dirname14(pageFile), homeDir);
|
|
291058
291507
|
const own = /* @__PURE__ */ new Set();
|
|
291059
291508
|
const deps = /* @__PURE__ */ new Set();
|
|
291060
291509
|
const { collectClientImportsFromSource: collectClientImportsFromSource2, findServerOnlyViolations: findServerOnlyViolations2 } = await Promise.resolve().then(() => (init_client_bundle(), client_bundle_exports));
|
|
@@ -291072,7 +291521,7 @@ async function buildCommand() {
|
|
|
291072
291521
|
for (const v of findServerOnlyViolations2(source)) tw1007.push({ file: pageFile, spec: v });
|
|
291073
291522
|
}
|
|
291074
291523
|
for (const lf of chainFiles) {
|
|
291075
|
-
const ls =
|
|
291524
|
+
const ls = readFileSync19(lf, "utf-8");
|
|
291076
291525
|
for (const l of collectClientImportsFromSource2(ls)) deps.add(l);
|
|
291077
291526
|
if (!serverBlocksOn) for (const v of findServerOnlyViolations2(ls)) tw1007.push({ file: lf, spec: v });
|
|
291078
291527
|
}
|
|
@@ -291200,11 +291649,11 @@ async function buildCommand() {
|
|
|
291200
291649
|
apiCount++;
|
|
291201
291650
|
}
|
|
291202
291651
|
}
|
|
291203
|
-
if (
|
|
291652
|
+
if (existsSync27(publicDir)) {
|
|
291204
291653
|
copyDir2(publicDir, outDir);
|
|
291205
291654
|
console.log(" \x1B[32mOK\x1B[0m public/");
|
|
291206
291655
|
}
|
|
291207
|
-
if (
|
|
291656
|
+
if (existsSync27(stylePath)) {
|
|
291208
291657
|
copyFileSync2(stylePath, join30(outDir, "style.css"));
|
|
291209
291658
|
console.log(" \x1B[32mOK\x1B[0m style.css");
|
|
291210
291659
|
}
|
|
@@ -291214,10 +291663,12 @@ async function buildCommand() {
|
|
|
291214
291663
|
const rel = v.file.startsWith(rootDir) ? v.file.slice(rootDir.length + 1) : v.file;
|
|
291215
291664
|
console.log(" TW1007: " + rel + " \u2192 " + v.spec);
|
|
291216
291665
|
console.log(" Server-only modules (lib/, .twm, @tw/*) cannot be imported from page.tw / layout.tw.");
|
|
291666
|
+
console.log(' A shared helper that lives in lib/ can opt out with: import "@tw/client-safe";');
|
|
291667
|
+
console.log(' A server module outside lib/ can be marked with: import "@tw/server-only";');
|
|
291217
291668
|
}
|
|
291218
291669
|
process.exit(1);
|
|
291219
291670
|
}
|
|
291220
|
-
if (
|
|
291671
|
+
if (existsSync27(libDir)) {
|
|
291221
291672
|
copyDir2(libDir, join30(outDir, "lib"));
|
|
291222
291673
|
console.log(" \x1B[32mOK\x1B[0m lib/");
|
|
291223
291674
|
}
|
|
@@ -291225,7 +291676,7 @@ async function buildCommand() {
|
|
|
291225
291676
|
console.log(" \x1B[36m\u26A1\x1B[0m client modules: " + clientChunkUrls.size + " shared chunk" + (clientChunkUrls.size === 1 ? "" : "s") + " (content-hashed, tree-shaken)");
|
|
291226
291677
|
}
|
|
291227
291678
|
const mwPath = join30(rootDir, "middleware.twm");
|
|
291228
|
-
if (
|
|
291679
|
+
if (existsSync27(mwPath)) {
|
|
291229
291680
|
copyFileSync2(mwPath, join30(outDir, "middleware.twm"));
|
|
291230
291681
|
console.log(" \x1B[32mOK\x1B[0m middleware.twm");
|
|
291231
291682
|
}
|
|
@@ -291238,7 +291689,7 @@ async function buildCommand() {
|
|
|
291238
291689
|
}
|
|
291239
291690
|
const manifest = purgeManifest2(routes);
|
|
291240
291691
|
if (manifest) {
|
|
291241
|
-
|
|
291692
|
+
writeFileSync10(join30(outDir, "cdn-purge.json"), JSON.stringify(manifest, null, 2));
|
|
291242
291693
|
console.log(" \x1B[36m\u26A1\x1B[0m cdn: purge manifest for " + routes.length + " route" + (routes.length === 1 ? "" : "s"));
|
|
291243
291694
|
}
|
|
291244
291695
|
}
|
|
@@ -291289,7 +291740,7 @@ async function buildCommand() {
|
|
|
291289
291740
|
}
|
|
291290
291741
|
return out;
|
|
291291
291742
|
};
|
|
291292
|
-
for (const f of plan.files) if (linkedNames.has(f.name))
|
|
291743
|
+
for (const f of plan.files) if (linkedNames.has(f.name)) writeFileSync10(join30(outDir, assetsDirName(), f.name), postCss(f.css));
|
|
291293
291744
|
}
|
|
291294
291745
|
let inlined = 0;
|
|
291295
291746
|
for (const out of htmlOutputs) {
|
|
@@ -291305,14 +291756,14 @@ async function buildCommand() {
|
|
|
291305
291756
|
}
|
|
291306
291757
|
if (inject2) out.html = out.html.replace("</head>", inject2 + "\n</head>");
|
|
291307
291758
|
const finalHtml = await runBuildHookValue("transform:html", out.html, { route: out.route });
|
|
291308
|
-
|
|
291759
|
+
writeFileSync10(join30(out.outputDir, "index.html"), finalHtml);
|
|
291309
291760
|
}
|
|
291310
291761
|
const linked = htmlOutputs.length - inlined;
|
|
291311
291762
|
console.log(" \x1B[36m\u26A1\x1B[0m styles: " + linkedNames.size + " css file" + (plan.files.length === 1 ? "" : "s") + " (route-split, content-hashed)" + (inlined > 0 ? " + " + inlined + " route" + (inlined === 1 ? "" : "s") + " inlined critical css" : "") + " [" + linked + " page" + (linked === 1 ? "" : "s") + " linked]");
|
|
291312
291763
|
} else {
|
|
291313
291764
|
for (const out of htmlOutputs) {
|
|
291314
291765
|
const finalHtml = await runBuildHookValue("transform:html", out.html, { route: out.route });
|
|
291315
|
-
|
|
291766
|
+
writeFileSync10(join30(out.outputDir, "index.html"), finalHtml);
|
|
291316
291767
|
}
|
|
291317
291768
|
}
|
|
291318
291769
|
m.clearCssCapture?.();
|
|
@@ -291320,9 +291771,9 @@ async function buildCommand() {
|
|
|
291320
291771
|
end("css");
|
|
291321
291772
|
{
|
|
291322
291773
|
const nfFile = join30(homeDir, "not-found.tw");
|
|
291323
|
-
if (
|
|
291774
|
+
if (existsSync27(nfFile)) {
|
|
291324
291775
|
try {
|
|
291325
|
-
const nfSource =
|
|
291776
|
+
const nfSource = readFileSync19(nfFile, "utf-8");
|
|
291326
291777
|
try {
|
|
291327
291778
|
registerImportedComponents(
|
|
291328
291779
|
nfFile,
|
|
@@ -291335,14 +291786,14 @@ async function buildCommand() {
|
|
|
291335
291786
|
}
|
|
291336
291787
|
const nfResult = _compileSync(nfSource, { filePath: nfFile });
|
|
291337
291788
|
let nfHtml = nfResult.html;
|
|
291338
|
-
const nfChain = findLayoutChain(
|
|
291789
|
+
const nfChain = findLayoutChain(dirname14(nfFile), homeDir);
|
|
291339
291790
|
if (nfChain.length > 0 && _generateWithLayoutChain) {
|
|
291340
|
-
const layoutPrograms = nfChain.map((lp) => _compileSync(
|
|
291791
|
+
const layoutPrograms = nfChain.map((lp) => _compileSync(readFileSync19(lp, "utf-8"), { filePath: lp }).ast).filter(Boolean);
|
|
291341
291792
|
if (layoutPrograms.length > 0) nfHtml = _generateWithLayoutChain(layoutPrograms, nfResult.ast, {});
|
|
291342
291793
|
}
|
|
291343
291794
|
if (css) nfHtml = nfHtml.replace("</head>", "<style>" + css + "</style>\n</head>");
|
|
291344
291795
|
const finalNf = await runBuildHookValue("transform:html", nfHtml, { route: "/404" });
|
|
291345
|
-
|
|
291796
|
+
writeFileSync10(join30(outDir, "404.html"), finalNf);
|
|
291346
291797
|
console.log(" \x1B[32mOK\x1B[0m /404 -> 404.html (" + nfFile.replace(rootDir + "/", "") + ")");
|
|
291347
291798
|
} catch (e) {
|
|
291348
291799
|
console.log(" \x1B[31mX\x1B[0m " + nfFile.replace(rootDir + "/", "") + ": " + e.message + "\x1B[0m");
|
|
@@ -291355,15 +291806,15 @@ async function buildCommand() {
|
|
|
291355
291806
|
const _fu = import.meta.url.replace("file://", "");
|
|
291356
291807
|
const _srcDir = _fu.substring(0, _fu.lastIndexOf("/"));
|
|
291357
291808
|
const runtimeSrc = _bundleDir ? resolve8(_bundleDir, "hydration-runtime.js") : resolve8(_srcDir, "../../../..", "packages/runtime/tw/client/hydration-runtime.js");
|
|
291358
|
-
if (
|
|
291359
|
-
const raw =
|
|
291809
|
+
if (existsSync27(runtimeSrc)) {
|
|
291810
|
+
const raw = readFileSync19(runtimeSrc, "utf-8");
|
|
291360
291811
|
let code = raw;
|
|
291361
291812
|
try {
|
|
291362
291813
|
const cb = await Promise.resolve().then(() => (init_client_bundle(), client_bundle_exports));
|
|
291363
291814
|
code = cb.minifyJsSource?.(rootDir, raw, esbuildTargetFor(buildOpts?.target)) ?? raw;
|
|
291364
291815
|
} catch {
|
|
291365
291816
|
}
|
|
291366
|
-
|
|
291817
|
+
writeFileSync10(join30(outDir, "__tw_runtime.js"), code);
|
|
291367
291818
|
const saved = raw.length - code.length;
|
|
291368
291819
|
console.log(" \x1B[36m\u26A1\x1B[0m hydration runtime: .tw/__tw_runtime.js" + (saved > 0 ? " (" + (saved / 1024).toFixed(1) + " KB smaller)" : ""));
|
|
291369
291820
|
}
|
|
@@ -291375,20 +291826,21 @@ async function buildCommand() {
|
|
|
291375
291826
|
if (pageCount === 0) console.warn(" [!] No static pages were compiled -- every page is SSR/API. Static hosts (Vercel/Cloudflare Pages output) will serve an empty site. Use `render static` or check your render modes.");
|
|
291376
291827
|
console.log(" APIs: " + apiCount + " routes");
|
|
291377
291828
|
try {
|
|
291378
|
-
|
|
291829
|
+
writeFileSync10(join30(outDir, "build-summary.json"), JSON.stringify({
|
|
291379
291830
|
staticPages: pageCount,
|
|
291380
291831
|
ssrPages: requestRenderedCount,
|
|
291381
291832
|
apiRoutes: apiCount,
|
|
291382
|
-
middleware:
|
|
291833
|
+
middleware: existsSync27(join30(rootDir, "middleware.twm"))
|
|
291383
291834
|
}, null, 2));
|
|
291384
291835
|
} catch {
|
|
291385
291836
|
}
|
|
291386
291837
|
if (buildOpts?.incremental) {
|
|
291387
291838
|
try {
|
|
291388
|
-
|
|
291839
|
+
writeFileSync10(join30(outDir, ".build-cache.json"), JSON.stringify(incNext));
|
|
291389
291840
|
} catch {
|
|
291390
291841
|
}
|
|
291391
291842
|
if (skippedPages > 0) console.log(" \x1B[36m~\x1B[0m incremental: " + skippedPages + " page(s) unchanged, reused");
|
|
291843
|
+
if (skippedNotFound > 0) console.log(" \x1B[33m!\x1B[0m " + skippedNotFound + " page(s) skipped by notFound() -- the host will serve a 404 for them");
|
|
291392
291844
|
}
|
|
291393
291845
|
if (buildOpts?.entryPoints?.length) {
|
|
291394
291846
|
try {
|
|
@@ -291419,7 +291871,7 @@ async function buildCommand() {
|
|
|
291419
291871
|
files.sort((a, b) => b.size - a.size);
|
|
291420
291872
|
const total = files.reduce((n, f) => n + f.size, 0);
|
|
291421
291873
|
if (buildOpts.metafile) {
|
|
291422
|
-
|
|
291874
|
+
writeFileSync10(join30(outDir, "build-meta.json"), JSON.stringify({ total, files }, null, 2));
|
|
291423
291875
|
}
|
|
291424
291876
|
if (buildOpts.bundleAnalysis) {
|
|
291425
291877
|
console.log("\n Bundle analysis (largest first):");
|
|
@@ -291432,7 +291884,7 @@ async function buildCommand() {
|
|
|
291432
291884
|
if (isrRoutes.size > 0) {
|
|
291433
291885
|
const manifest = {};
|
|
291434
291886
|
for (const [k, v] of isrRoutes) manifest[k] = v;
|
|
291435
|
-
|
|
291887
|
+
writeFileSync10(join30(outDir, "routes.json"), JSON.stringify(manifest, null, 2));
|
|
291436
291888
|
console.log(" \x1B[36m~\x1B[0m ISR: " + isrRoutes.size + " route(s) with cache windows -> .tw/routes.json");
|
|
291437
291889
|
}
|
|
291438
291890
|
{
|
|
@@ -291516,7 +291968,7 @@ async function buildCommand() {
|
|
|
291516
291968
|
if (errorCount > 0 || tw1007.length > 0) process.exit(1);
|
|
291517
291969
|
}
|
|
291518
291970
|
function rmDirRecursive(dir) {
|
|
291519
|
-
if (!
|
|
291971
|
+
if (!existsSync27(dir)) return;
|
|
291520
291972
|
for (const entry of readdirSync9(dir)) {
|
|
291521
291973
|
const fullPath = join30(dir, entry);
|
|
291522
291974
|
const stat = statSync9(fullPath);
|
|
@@ -291569,17 +292021,17 @@ __export(tw_exports8, {
|
|
|
291569
292021
|
vercelStaticConfig: () => vercelStaticConfig,
|
|
291570
292022
|
writeVercelFiles: () => writeVercelFiles
|
|
291571
292023
|
});
|
|
291572
|
-
import { existsSync as
|
|
291573
|
-
import { join as join33, dirname as
|
|
292024
|
+
import { existsSync as existsSync30, mkdirSync as mkdirSync9, readFileSync as readFileSync21, writeFileSync as writeFileSync11 } from "node:fs";
|
|
292025
|
+
import { join as join33, dirname as dirname16 } from "node:path";
|
|
291574
292026
|
import { fileURLToPath } from "node:url";
|
|
291575
292027
|
function resolvePkgDir() {
|
|
291576
|
-
const self2 =
|
|
292028
|
+
const self2 = dirname16(fileURLToPath(import.meta.url));
|
|
291577
292029
|
const bundleDir = globalThis.__TW_BUNDLE_DIR;
|
|
291578
292030
|
if (bundleDir) {
|
|
291579
292031
|
const fromBundle = join33(bundleDir, "adapters");
|
|
291580
|
-
if (
|
|
292032
|
+
if (existsSync30(join33(fromBundle, "node", "server.mjs"))) return fromBundle;
|
|
291581
292033
|
}
|
|
291582
|
-
if (
|
|
292034
|
+
if (existsSync30(join33(self2, "node", "server.mjs"))) return self2;
|
|
291583
292035
|
return self2;
|
|
291584
292036
|
}
|
|
291585
292037
|
function generateAdapter(name, appDir) {
|
|
@@ -291591,10 +292043,10 @@ function generateAdapter(name, appDir) {
|
|
|
291591
292043
|
const written = [];
|
|
291592
292044
|
for (const f of adapter.files) {
|
|
291593
292045
|
const src = join33(PKG_DIR, f.from);
|
|
291594
|
-
if (!
|
|
292046
|
+
if (!existsSync30(src)) throw new Error(`Adapter file missing: ${f.from}`);
|
|
291595
292047
|
const dest = join33(appDir, f.to);
|
|
291596
|
-
mkdirSync9(
|
|
291597
|
-
|
|
292048
|
+
mkdirSync9(dirname16(dest), { recursive: true });
|
|
292049
|
+
writeFileSync11(dest, readFileSync21(src));
|
|
291598
292050
|
written.push(dest);
|
|
291599
292051
|
}
|
|
291600
292052
|
return written;
|
|
@@ -291787,12 +292239,12 @@ __export(node_test_runner_exports, {
|
|
|
291787
292239
|
runNodeTests: () => runNodeTests
|
|
291788
292240
|
});
|
|
291789
292241
|
import { join as join36 } from "node:path";
|
|
291790
|
-
import { mkdirSync as mkdirSync10, writeFileSync as
|
|
292242
|
+
import { mkdirSync as mkdirSync10, writeFileSync as writeFileSync13, readFileSync as readFileSync24 } from "node:fs";
|
|
291791
292243
|
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
291792
292244
|
async function runNodeTests(files, rootDir) {
|
|
291793
292245
|
const cacheDir = join36(rootDir, ".tw", ".tests");
|
|
291794
292246
|
mkdirSync10(cacheDir, { recursive: true });
|
|
291795
|
-
|
|
292247
|
+
writeFileSync13(join36(cacheDir, "mini-bun-test.cjs"), MINI_BUN_TEST);
|
|
291796
292248
|
let esbuildMain = "";
|
|
291797
292249
|
try {
|
|
291798
292250
|
const { createRequire } = await import("node:module");
|
|
@@ -291802,21 +292254,21 @@ async function runNodeTests(files, rootDir) {
|
|
|
291802
292254
|
}
|
|
291803
292255
|
const runnerSrc = esbuildMain ? `globalThis.__TW_ESBUILD_MODULE = ${JSON.stringify(esbuildMain)};
|
|
291804
292256
|
` + RUNNER : RUNNER;
|
|
291805
|
-
|
|
292257
|
+
writeFileSync13(join36(cacheDir, "runner.cjs"), runnerSrc);
|
|
291806
292258
|
const esbuild = await import("esbuild");
|
|
291807
|
-
const { basename:
|
|
292259
|
+
const { basename: basename4 } = await import("node:path");
|
|
291808
292260
|
const compiled = [];
|
|
291809
292261
|
for (const f of files) {
|
|
291810
|
-
const outPath = join36(cacheDir,
|
|
292262
|
+
const outPath = join36(cacheDir, basename4(f).replace(/\.(ts|tsx|js)$/, ".cjs"));
|
|
291811
292263
|
const adapterPath = join36(cacheDir, "node-adapter.ts");
|
|
291812
292264
|
try {
|
|
291813
|
-
|
|
292265
|
+
writeFileSync13(adapterPath, readFileSync24(join36(new URL(".", import.meta.url).pathname, "node-adapter.ts"), "utf-8"));
|
|
291814
292266
|
} catch {
|
|
291815
292267
|
const bd = globalThis.__TW_BUNDLE_DIR;
|
|
291816
292268
|
const src = bd ? join36(bd, "..", "tw", "node-adapter.ts") : "";
|
|
291817
292269
|
if (src) {
|
|
291818
292270
|
try {
|
|
291819
|
-
|
|
292271
|
+
writeFileSync13(adapterPath, readFileSync24(src, "utf-8"));
|
|
291820
292272
|
} catch {
|
|
291821
292273
|
}
|
|
291822
292274
|
}
|
|
@@ -291866,7 +292318,7 @@ async function runNodeTests(files, rootDir) {
|
|
|
291866
292318
|
}
|
|
291867
292319
|
const childEnv = { ...process.env };
|
|
291868
292320
|
try {
|
|
291869
|
-
const envFile =
|
|
292321
|
+
const envFile = readFileSync24(join36(rootDir, ".env"), "utf-8");
|
|
291870
292322
|
for (const line of envFile.split("\n")) {
|
|
291871
292323
|
const m = line.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/);
|
|
291872
292324
|
if (m && !(m[1] in childEnv)) childEnv[m[1]] = m[2].replace(/^["']|["']$/g, "");
|
|
@@ -294675,7 +295127,7 @@ async function createPackageJson(dir, name) {
|
|
|
294675
295127
|
ship: "tw ship"
|
|
294676
295128
|
},
|
|
294677
295129
|
dependencies: {
|
|
294678
|
-
"tw-framework": "^2.0.
|
|
295130
|
+
"tw-framework": "^2.0.5"
|
|
294679
295131
|
},
|
|
294680
295132
|
devDependencies: {
|
|
294681
295133
|
typescript: "^5.4.0",
|
|
@@ -294762,7 +295214,7 @@ dist/
|
|
|
294762
295214
|
async function createReadme(dir, name) {
|
|
294763
295215
|
const content = `# ${name}
|
|
294764
295216
|
|
|
294765
|
-
Built with TW Framework 2.0.
|
|
295217
|
+
Built with TW Framework 2.0.5.
|
|
294766
295218
|
|
|
294767
295219
|
## Getting Started
|
|
294768
295220
|
|
|
@@ -295643,7 +296095,8 @@ body { font-family system-ui, sans-serif; bg #0d1117; color #c9d1d9 }
|
|
|
295643
296095
|
}
|
|
295644
296096
|
|
|
295645
296097
|
// tw/commands/dev.ts
|
|
295646
|
-
|
|
296098
|
+
init_tw();
|
|
296099
|
+
import { join as join31, resolve as resolve9, dirname as dirname15 } from "node:path";
|
|
295647
296100
|
|
|
295648
296101
|
// tw/dev-overlay.ts
|
|
295649
296102
|
var OVERLAY_CSS = [
|
|
@@ -295670,7 +296123,7 @@ var CLIENT_OVERLAY_SCRIPT = '<script id="__tw_error_overlay">(function(){if(wind
|
|
|
295670
296123
|
// tw/commands/dev.ts
|
|
295671
296124
|
init_components();
|
|
295672
296125
|
await init_build();
|
|
295673
|
-
import { existsSync as
|
|
296126
|
+
import { existsSync as existsSync28, readFileSync as readFileSync20, readdirSync as readdirSync10, statSync as statSync10 } from "node:fs";
|
|
295674
296127
|
function findCompilerPath2() {
|
|
295675
296128
|
const fileUrl = import.meta.url.replace("file://", "");
|
|
295676
296129
|
const cmdDir = fileUrl.substring(0, fileUrl.lastIndexOf("/"));
|
|
@@ -295680,7 +296133,7 @@ function findCompilerPath2() {
|
|
|
295680
296133
|
resolve9(process.cwd(), "node_modules/tw-framework/packages/compiler/tw/index.ts")
|
|
295681
296134
|
];
|
|
295682
296135
|
for (const p of candidates) {
|
|
295683
|
-
if (
|
|
296136
|
+
if (existsSync28(p)) return p;
|
|
295684
296137
|
}
|
|
295685
296138
|
return resolve9(process.cwd(), "packages/compiler/tw/index.ts");
|
|
295686
296139
|
}
|
|
@@ -295735,14 +296188,14 @@ function resolveHomeFile(homeDir, pathname, leafNames) {
|
|
|
295735
296188
|
const segments = pathname.split("/").filter(Boolean).map(decodeURIComponent);
|
|
295736
296189
|
const isDir = (p) => {
|
|
295737
296190
|
try {
|
|
295738
|
-
return
|
|
296191
|
+
return existsSync28(p) && statSync10(p).isDirectory();
|
|
295739
296192
|
} catch {
|
|
295740
296193
|
return false;
|
|
295741
296194
|
}
|
|
295742
296195
|
};
|
|
295743
296196
|
const listDir = (p) => {
|
|
295744
296197
|
try {
|
|
295745
|
-
return
|
|
296198
|
+
return existsSync28(p) ? readdirSync10(p) : [];
|
|
295746
296199
|
} catch {
|
|
295747
296200
|
return [];
|
|
295748
296201
|
}
|
|
@@ -295751,14 +296204,14 @@ function resolveHomeFile(homeDir, pathname, leafNames) {
|
|
|
295751
296204
|
if (i >= segments.length) {
|
|
295752
296205
|
for (const leaf of leafNames) {
|
|
295753
296206
|
const f = join31(dir, leaf);
|
|
295754
|
-
if (
|
|
296207
|
+
if (existsSync28(f)) return { file: f, params };
|
|
295755
296208
|
}
|
|
295756
296209
|
for (const entry of listDir(dir)) {
|
|
295757
296210
|
const m = /^\[\[\.\.\.(.+)\]\]$/.exec(entry);
|
|
295758
296211
|
if (m && isDir(join31(dir, entry))) {
|
|
295759
296212
|
for (const leaf of leafNames) {
|
|
295760
296213
|
const f = join31(dir, entry, leaf);
|
|
295761
|
-
if (
|
|
296214
|
+
if (existsSync28(f)) return { file: f, params: { ...params, [m[1]]: "" } };
|
|
295762
296215
|
}
|
|
295763
296216
|
}
|
|
295764
296217
|
}
|
|
@@ -295788,13 +296241,13 @@ function resolveHomeFile(homeDir, pathname, leafNames) {
|
|
|
295788
296241
|
if (m && isDir(join31(dir, entry))) {
|
|
295789
296242
|
for (const leaf of leafNames) {
|
|
295790
296243
|
const f = join31(dir, entry, leaf);
|
|
295791
|
-
if (
|
|
296244
|
+
if (existsSync28(f)) return { file: f, params: { ...params, [m[1]]: segments.slice(i).join("/") } };
|
|
295792
296245
|
}
|
|
295793
296246
|
}
|
|
295794
296247
|
}
|
|
295795
296248
|
if (i === segments.length - 1) {
|
|
295796
296249
|
const f = join31(dir, seg + ".tw");
|
|
295797
|
-
if (
|
|
296250
|
+
if (existsSync28(f)) return { file: f, params };
|
|
295798
296251
|
}
|
|
295799
296252
|
return null;
|
|
295800
296253
|
}
|
|
@@ -295805,7 +296258,7 @@ function findLayoutDev(dir, homeDir) {
|
|
|
295805
296258
|
const homeAbs = resolve9(homeDir);
|
|
295806
296259
|
for (let i = 0; i < 16; i++) {
|
|
295807
296260
|
const cand = join31(cur, "layout.tw");
|
|
295808
|
-
if (
|
|
296261
|
+
if (existsSync28(cand)) return cand;
|
|
295809
296262
|
if (resolve9(cur) === homeAbs) break;
|
|
295810
296263
|
const parent = resolve9(cur, "..");
|
|
295811
296264
|
if (parent === resolve9(cur) || !parent.startsWith(homeAbs)) break;
|
|
@@ -295990,7 +296443,7 @@ function destroySession(req) {
|
|
|
295990
296443
|
}
|
|
295991
296444
|
async function loadMiddlewareRules(mwPath) {
|
|
295992
296445
|
try {
|
|
295993
|
-
const source =
|
|
296446
|
+
const source = readFileSync20(mwPath, "utf-8");
|
|
295994
296447
|
const { parseRules: parseRules2 } = await Promise.resolve().then(() => (init_twm_rules(), twm_rules_exports));
|
|
295995
296448
|
return parseRules2(source);
|
|
295996
296449
|
} catch (e) {
|
|
@@ -296018,7 +296471,7 @@ async function devCommand() {
|
|
|
296018
296471
|
try {
|
|
296019
296472
|
const cfgPath = join31(rootDir, "tw.config.ts");
|
|
296020
296473
|
let rawCfg = null;
|
|
296021
|
-
if (
|
|
296474
|
+
if (existsSync28(cfgPath)) {
|
|
296022
296475
|
const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
296023
296476
|
const cfgMod = await twImportTs2(cfgPath);
|
|
296024
296477
|
rawCfg = cfgMod.default ?? cfgMod;
|
|
@@ -296034,7 +296487,7 @@ async function devCommand() {
|
|
|
296034
296487
|
try {
|
|
296035
296488
|
const cfgPath2 = join31(rootDir, "tw.config.ts");
|
|
296036
296489
|
let cfgImages = null;
|
|
296037
|
-
if (
|
|
296490
|
+
if (existsSync28(cfgPath2)) {
|
|
296038
296491
|
try {
|
|
296039
296492
|
const { twImportTs: _twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
296040
296493
|
const cfgMod2 = await _twImportTs2(cfgPath2);
|
|
@@ -296050,9 +296503,9 @@ async function devCommand() {
|
|
|
296050
296503
|
} catch {
|
|
296051
296504
|
}
|
|
296052
296505
|
const envPath = join31(rootDir, ".env");
|
|
296053
|
-
if (
|
|
296506
|
+
if (existsSync28(envPath)) {
|
|
296054
296507
|
try {
|
|
296055
|
-
for (const line of
|
|
296508
|
+
for (const line of readFileSync20(envPath, "utf-8").split("\n")) {
|
|
296056
296509
|
const m = /^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/.exec(line);
|
|
296057
296510
|
if (m && !(m[1] in process.env)) {
|
|
296058
296511
|
process.env[m[1]] = m[2].replace(/^["']|["']$/g, "");
|
|
@@ -296069,29 +296522,29 @@ async function devCommand() {
|
|
|
296069
296522
|
{
|
|
296070
296523
|
const styleDir = join31(rootDir, "style");
|
|
296071
296524
|
const parts = [];
|
|
296072
|
-
if (
|
|
296525
|
+
if (existsSync28(styleDir)) {
|
|
296073
296526
|
for (const f of readdirSync10(styleDir).filter((f2) => f2.endsWith(".tss")).sort()) {
|
|
296074
296527
|
try {
|
|
296075
|
-
parts.push(_compileTSS2(
|
|
296528
|
+
parts.push(_compileTSS2(readFileSync20(join31(styleDir, f), "utf-8")));
|
|
296076
296529
|
} catch (e) {
|
|
296077
296530
|
console.log(" Warning: failed to compile " + f + ": " + e.message);
|
|
296078
296531
|
}
|
|
296079
296532
|
}
|
|
296080
296533
|
}
|
|
296081
|
-
if (
|
|
296534
|
+
if (existsSync28(stylePath)) parts.push(readFileSync20(stylePath, "utf-8"));
|
|
296082
296535
|
if (parts.length) css = parts.join("\n");
|
|
296083
296536
|
}
|
|
296084
296537
|
const mwPath = join31(rootDir, "middleware.twm");
|
|
296085
|
-
const middlewareRules =
|
|
296538
|
+
const middlewareRules = existsSync28(mwPath) ? await loadMiddlewareRules(mwPath) : [];
|
|
296086
296539
|
scanComponents3(rootDir);
|
|
296087
296540
|
const compDir = join31(rootDir, "components");
|
|
296088
|
-
if (
|
|
296541
|
+
if (existsSync28(compDir)) {
|
|
296089
296542
|
const compFiles = readdirSync10(compDir).filter((f) => f.endsWith(".tw"));
|
|
296090
296543
|
if (compFiles.length > 0) console.log(" Components: " + compFiles.map((f) => f.replace(/\.tw$/, "")).join(", "));
|
|
296091
296544
|
}
|
|
296092
296545
|
function findRoutes(dir, prefix) {
|
|
296093
296546
|
const routes2 = [];
|
|
296094
|
-
if (!
|
|
296547
|
+
if (!existsSync28(dir)) return routes2;
|
|
296095
296548
|
for (const entry of readdirSync10(dir)) {
|
|
296096
296549
|
const fullPath = join31(dir, entry);
|
|
296097
296550
|
const stat = statSync10(fullPath);
|
|
@@ -296106,10 +296559,10 @@ async function devCommand() {
|
|
|
296106
296559
|
return routes2;
|
|
296107
296560
|
}
|
|
296108
296561
|
const routes = findRoutes(homeDir, "");
|
|
296109
|
-
const components =
|
|
296562
|
+
const components = existsSync28(compDir) ? readdirSync10(compDir).filter((f) => f.endsWith(".tw")) : [];
|
|
296110
296563
|
const libDir = join31(rootDir, "lib");
|
|
296111
|
-
const libFiles =
|
|
296112
|
-
const hasConfig =
|
|
296564
|
+
const libFiles = existsSync28(libDir) ? readdirSync10(libDir).filter((f) => f.endsWith(".ts")) : [];
|
|
296565
|
+
const hasConfig = existsSync28(join31(rootDir, "tw.config.ts"));
|
|
296113
296566
|
console.log("\n \x1B[36mtw dev\x1B[0m -- starting development server\n");
|
|
296114
296567
|
console.log(" Root: " + rootDir);
|
|
296115
296568
|
console.log(" Port: http://" + host + ":" + port + "\n");
|
|
@@ -296131,7 +296584,7 @@ async function devCommand() {
|
|
|
296131
296584
|
const deps = new Set(own);
|
|
296132
296585
|
for (const lf of layoutFiles) {
|
|
296133
296586
|
try {
|
|
296134
|
-
const ls =
|
|
296587
|
+
const ls = readFileSync20(lf, "utf-8");
|
|
296135
296588
|
for (const l of collectClientImportsFromSource2(ls)) deps.add(l);
|
|
296136
296589
|
for (const v of findServerOnlyViolations2(ls)) console.error(" [tw] TW1007 (dev): " + lf + " \u2192 server-only import " + v);
|
|
296137
296590
|
} catch {
|
|
@@ -296158,7 +296611,7 @@ async function devCommand() {
|
|
|
296158
296611
|
async function runUserMiddleware(req) {
|
|
296159
296612
|
try {
|
|
296160
296613
|
const mwPath2 = join31(rootDir, "middleware.twm");
|
|
296161
|
-
if (!
|
|
296614
|
+
if (!existsSync28(mwPath2)) return null;
|
|
296162
296615
|
const { executeMiddleware: executeMiddleware2, loadTWMModule: loadTWMModule2, shouldMatchMiddleware: shouldMatchMiddleware2 } = await Promise.resolve().then(() => (init_twm_loader(), twm_loader_exports));
|
|
296163
296616
|
const mod = await loadTWMModule2(mwPath2, rootDir);
|
|
296164
296617
|
const mwPathname = new URL(req.url).pathname;
|
|
@@ -296180,7 +296633,7 @@ async function devCommand() {
|
|
|
296180
296633
|
let devSecMode = "dev";
|
|
296181
296634
|
try {
|
|
296182
296635
|
const cfgFile = join31(rootDir, "tw.config.ts");
|
|
296183
|
-
if (
|
|
296636
|
+
if (existsSync28(cfgFile)) {
|
|
296184
296637
|
const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
296185
296638
|
const cfgMod = await twImportTs2(cfgFile);
|
|
296186
296639
|
devSecMode = (cfgMod.default ?? cfgMod)?.security?.headers ?? "dev";
|
|
@@ -296203,7 +296656,7 @@ async function devCommand() {
|
|
|
296203
296656
|
let devSignalTransport = "sse";
|
|
296204
296657
|
try {
|
|
296205
296658
|
const cfgFile = join31(rootDir, "tw.config.ts");
|
|
296206
|
-
if (
|
|
296659
|
+
if (existsSync28(cfgFile)) {
|
|
296207
296660
|
const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
296208
296661
|
const cfgMod = await twImportTs2(cfgFile);
|
|
296209
296662
|
const cfg = cfgMod.default ?? cfgMod;
|
|
@@ -296274,8 +296727,8 @@ async function devCommand() {
|
|
|
296274
296727
|
const _bd = globalThis.__TW_BUNDLE_DIR;
|
|
296275
296728
|
const runtimeCandidates = _bd ? [resolve9(_bd, "hydration-runtime.js"), resolve9(_srcDir, "../../../..", "packages/runtime/tw/client/hydration-runtime.js")] : [resolve9(_srcDir, "../../../..", "packages/runtime/tw/client/hydration-runtime.js")];
|
|
296276
296729
|
for (const runtimePath of runtimeCandidates) {
|
|
296277
|
-
if (
|
|
296278
|
-
return new Response(
|
|
296730
|
+
if (existsSync28(runtimePath)) {
|
|
296731
|
+
return new Response(readFileSync20(runtimePath, "utf-8"), {
|
|
296279
296732
|
headers: { "Content-Type": "application/javascript; charset=utf-8" }
|
|
296280
296733
|
});
|
|
296281
296734
|
}
|
|
@@ -296284,8 +296737,8 @@ async function devCommand() {
|
|
|
296284
296737
|
}
|
|
296285
296738
|
if (/^\/js\/(c|p|e|tw-client)-[a-z0-9]+\.js$/.test(path)) {
|
|
296286
296739
|
const clientBundlePath = join31(rootDir, ".tw", path.slice(1));
|
|
296287
|
-
if (
|
|
296288
|
-
return new Response(
|
|
296740
|
+
if (existsSync28(clientBundlePath)) {
|
|
296741
|
+
return new Response(readFileSync20(clientBundlePath, "utf-8"), {
|
|
296289
296742
|
headers: { "Content-Type": "application/javascript; charset=utf-8" }
|
|
296290
296743
|
});
|
|
296291
296744
|
}
|
|
@@ -296301,10 +296754,14 @@ async function devCommand() {
|
|
|
296301
296754
|
if (path === "/style.css") {
|
|
296302
296755
|
return new Response(css, { headers: { "Content-Type": "text/css" } });
|
|
296303
296756
|
}
|
|
296304
|
-
if (
|
|
296757
|
+
if (existsSync28(publicDir)) {
|
|
296305
296758
|
const publicFile = join31(publicDir, path);
|
|
296306
296759
|
const pubFile = Bun.file(publicFile);
|
|
296307
|
-
if (await pubFile.exists())
|
|
296760
|
+
if (await pubFile.exists()) {
|
|
296761
|
+
const _ext = (publicFile.split(".").pop() ?? "").toLowerCase();
|
|
296762
|
+
const _type = MIME_TYPES[_ext] ?? pubFile.type ?? "application/octet-stream";
|
|
296763
|
+
return new Response(pubFile, { headers: { "Content-Type": _type } });
|
|
296764
|
+
}
|
|
296308
296765
|
}
|
|
296309
296766
|
if (path === "/placeholder.png" || path.endsWith(".png")) {
|
|
296310
296767
|
return new Response(PLACEHOLDER_PNG, { headers: { "Content-Type": "image/png" } });
|
|
@@ -296401,9 +296858,9 @@ async function devCommand() {
|
|
|
296401
296858
|
delete result.json._errorMessage;
|
|
296402
296859
|
const pageRoutePath = renderPath === "/" ? "" : renderPath;
|
|
296403
296860
|
const pageFile = join31(homeDir, pageRoutePath, "page.tw");
|
|
296404
|
-
if (
|
|
296861
|
+
if (existsSync28(pageFile)) {
|
|
296405
296862
|
try {
|
|
296406
|
-
const pageSource =
|
|
296863
|
+
const pageSource = readFileSync20(pageFile, "utf-8");
|
|
296407
296864
|
const pageResult = compileSync3(pageSource, { filePath: pageFile });
|
|
296408
296865
|
let pageHtml = pageResult.html;
|
|
296409
296866
|
pageHtml = pageHtml.replace("</head>", "<style>" + css + "</style>\n</head>");
|
|
@@ -296454,16 +296911,29 @@ async function devCommand() {
|
|
|
296454
296911
|
if (resolved) {
|
|
296455
296912
|
const twFile = resolved.file;
|
|
296456
296913
|
try {
|
|
296457
|
-
const source =
|
|
296914
|
+
const source = readFileSync20(twFile, "utf-8");
|
|
296458
296915
|
if (typeof beginCssRouteCapture2 === "function") beginCssRouteCapture2(path);
|
|
296459
|
-
let result = compileSync3(source, { filePath: twFile, stateVars: resolved.params });
|
|
296916
|
+
let result = compileSync3(source, { filePath: twFile, stateVars: resolved.params, experimental: { serverBlocks: true } });
|
|
296460
296917
|
try {
|
|
296461
296918
|
const _c = await Promise.resolve().then(() => (init_tw7(), tw_exports3));
|
|
296462
296919
|
const blocks = _c.collectServerBlocks(result.ast);
|
|
296463
296920
|
if (blocks.length) {
|
|
296464
|
-
const
|
|
296921
|
+
const _blocks = blocks.filter((b) => !b.deferred);
|
|
296922
|
+
const _imports = {};
|
|
296923
|
+
for (const b of _blocks) Object.assign(_imports, await _c.resolveServerImports(b, twFile, { dev: true }));
|
|
296924
|
+
const values = await _c.executeServerBlocks(_blocks, {
|
|
296925
|
+
context: { params: resolved.params ?? {}, env: process.env, loginPath: devOpts?.loginPath },
|
|
296926
|
+
imports: _imports,
|
|
296927
|
+
label: twFile,
|
|
296928
|
+
referenced: _c.collectReferencedNames(source)
|
|
296929
|
+
});
|
|
296465
296930
|
if (values && Object.keys(values).length) {
|
|
296466
|
-
|
|
296931
|
+
const merged = {
|
|
296932
|
+
...resolved.params ?? {},
|
|
296933
|
+
params: resolved.params ?? {},
|
|
296934
|
+
..._c.encodeServerValues(values)
|
|
296935
|
+
};
|
|
296936
|
+
result = compileSync3(source, { filePath: twFile, stateVars: merged, experimental: { serverBlocks: true } });
|
|
296467
296937
|
}
|
|
296468
296938
|
}
|
|
296469
296939
|
} catch (e) {
|
|
@@ -296489,7 +296959,7 @@ async function devCommand() {
|
|
|
296489
296959
|
const homeAbs = resolve9(homeDir);
|
|
296490
296960
|
for (let i = 0; i < 16; i++) {
|
|
296491
296961
|
const cand = join31(cur, "layout.tw");
|
|
296492
|
-
if (
|
|
296962
|
+
if (existsSync28(cand)) chain2.push(cand);
|
|
296493
296963
|
if (resolve9(cur) === homeAbs) break;
|
|
296494
296964
|
const parent = resolve9(cur, "..");
|
|
296495
296965
|
if (parent === resolve9(cur) || !parent.startsWith(homeAbs)) break;
|
|
@@ -296498,7 +296968,7 @@ async function devCommand() {
|
|
|
296498
296968
|
chain2.reverse();
|
|
296499
296969
|
}
|
|
296500
296970
|
if (chain2.length > 0 && generateWithLayoutChain2) {
|
|
296501
|
-
const layoutPrograms = chain2.map((lp) => compileSync3(
|
|
296971
|
+
const layoutPrograms = chain2.map((lp) => compileSync3(readFileSync20(lp, "utf-8"), { filePath: lp }).ast).filter(Boolean);
|
|
296502
296972
|
if (layoutPrograms.length > 0) {
|
|
296503
296973
|
html = generateWithLayoutChain2(layoutPrograms, result.ast, resolved.params);
|
|
296504
296974
|
const pageTitle = result.html.match(/<title>([^<]*)<\/title>/);
|
|
@@ -296517,7 +296987,7 @@ async function devCommand() {
|
|
|
296517
296987
|
}
|
|
296518
296988
|
let devClientTag = "";
|
|
296519
296989
|
try {
|
|
296520
|
-
const _clockSrc =
|
|
296990
|
+
const _clockSrc = existsSync28(resolved.file) ? readFileSync20(resolved.file, "utf-8") : "";
|
|
296521
296991
|
devClientTag = await ensureDevClientBundle(rootDir, _clockSrc, chain2);
|
|
296522
296992
|
} catch {
|
|
296523
296993
|
}
|
|
@@ -296540,12 +297010,12 @@ async function devCommand() {
|
|
|
296540
297010
|
}
|
|
296541
297011
|
const devGlobalHead = join31(homeDir, "head.tw");
|
|
296542
297012
|
const devHeadSources = [];
|
|
296543
|
-
if (
|
|
296544
|
-
const headTw = join31(
|
|
296545
|
-
if (headTw !== devGlobalHead &&
|
|
297013
|
+
if (existsSync28(devGlobalHead)) devHeadSources.push(devGlobalHead);
|
|
297014
|
+
const headTw = join31(dirname15(resolved.file), "head.tw");
|
|
297015
|
+
if (headTw !== devGlobalHead && existsSync28(headTw)) devHeadSources.push(headTw);
|
|
296546
297016
|
for (const devHeadTw of devHeadSources) {
|
|
296547
297017
|
try {
|
|
296548
|
-
const headRes = compileSync3(
|
|
297018
|
+
const headRes = compileSync3(readFileSync20(devHeadTw, "utf-8"), { filePath: devHeadTw });
|
|
296549
297019
|
const headBody = headRes.html.match(/<body>([\s\S]*)<\/body>/);
|
|
296550
297020
|
if (headBody && headBody[1].trim()) {
|
|
296551
297021
|
html = html.replace(
|
|
@@ -296591,14 +297061,14 @@ async function devCommand() {
|
|
|
296591
297061
|
}
|
|
296592
297062
|
console.log(" -> 404 Not Found");
|
|
296593
297063
|
const nfFile = join31(homeDir, "not-found.tw");
|
|
296594
|
-
if (
|
|
297064
|
+
if (existsSync28(nfFile)) {
|
|
296595
297065
|
try {
|
|
296596
|
-
const nfSource =
|
|
297066
|
+
const nfSource = readFileSync20(nfFile, "utf-8");
|
|
296597
297067
|
const nfResult = compileSync3(nfSource, { filePath: nfFile });
|
|
296598
297068
|
let nfHtml = nfResult.html;
|
|
296599
297069
|
const layoutPath = findLayoutDev(homeDir, homeDir);
|
|
296600
297070
|
if (layoutPath) {
|
|
296601
|
-
const layoutSource =
|
|
297071
|
+
const layoutSource = readFileSync20(layoutPath, "utf-8");
|
|
296602
297072
|
const layoutResult = compileSync3(layoutSource, { filePath: layoutPath });
|
|
296603
297073
|
if (layoutResult.ast && generateWithLayout2) nfHtml = generateWithLayout2(layoutResult.ast, nfResult.ast);
|
|
296604
297074
|
}
|
|
@@ -296728,7 +297198,7 @@ async function devCommand() {
|
|
|
296728
297198
|
const { loadPlugins: loadPlugins2 } = await Promise.resolve().then(() => (init_tw8(), tw_exports4));
|
|
296729
297199
|
const cfgPath = join31(rootDir, "tw.config.ts");
|
|
296730
297200
|
let cfg = void 0;
|
|
296731
|
-
if (
|
|
297201
|
+
if (existsSync28(cfgPath)) {
|
|
296732
297202
|
const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
296733
297203
|
const cfgMod = await twImportTs2(cfgPath);
|
|
296734
297204
|
cfg = cfgMod.default ?? cfgMod;
|
|
@@ -296740,7 +297210,7 @@ async function devCommand() {
|
|
|
296740
297210
|
let devTls = {};
|
|
296741
297211
|
if (devOpts?.https && devOpts.httpsCert && devOpts.httpsKey) {
|
|
296742
297212
|
try {
|
|
296743
|
-
devTls = { tls: { cert:
|
|
297213
|
+
devTls = { tls: { cert: readFileSync20(devOpts.httpsCert, "utf-8"), key: readFileSync20(devOpts.httpsKey, "utf-8") } };
|
|
296744
297214
|
} catch (e) {
|
|
296745
297215
|
console.log(" [tw] dev.https: could not read cert/key -- " + (e?.message ?? e));
|
|
296746
297216
|
}
|
|
@@ -296834,7 +297304,7 @@ await init_build();
|
|
|
296834
297304
|
|
|
296835
297305
|
// tw/commands/serve.ts
|
|
296836
297306
|
import { join as join32 } from "node:path";
|
|
296837
|
-
import { existsSync as
|
|
297307
|
+
import { existsSync as existsSync29 } from "node:fs";
|
|
296838
297308
|
async function serveCommand() {
|
|
296839
297309
|
const args = process.argv.slice(3);
|
|
296840
297310
|
if (args.includes("-h") || args.includes("--help")) {
|
|
@@ -296870,10 +297340,10 @@ async function serveCommand() {
|
|
|
296870
297340
|
const rootDir = process.cwd();
|
|
296871
297341
|
let outDir = join32(rootDir, ".tw");
|
|
296872
297342
|
const envPath = join32(rootDir, ".env");
|
|
296873
|
-
if (
|
|
297343
|
+
if (existsSync29(envPath)) {
|
|
296874
297344
|
try {
|
|
296875
|
-
const { readFileSync:
|
|
296876
|
-
for (const line of
|
|
297345
|
+
const { readFileSync: readFileSync30 } = await import("node:fs");
|
|
297346
|
+
for (const line of readFileSync30(envPath, "utf-8").split("\n")) {
|
|
296877
297347
|
const m = /^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/.exec(line);
|
|
296878
297348
|
if (m && !(m[1] in process.env)) {
|
|
296879
297349
|
process.env[m[1]] = m[2].replace(/^["']|["']$/g, "");
|
|
@@ -296886,7 +297356,7 @@ async function serveCommand() {
|
|
|
296886
297356
|
let config = {};
|
|
296887
297357
|
try {
|
|
296888
297358
|
const cfgPath = join32(rootDir, "tw.config.ts");
|
|
296889
|
-
if (
|
|
297359
|
+
if (existsSync29(cfgPath)) {
|
|
296890
297360
|
const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
296891
297361
|
const cfgMod = await twImportTs2(cfgPath);
|
|
296892
297362
|
config = cfgMod.default ?? cfgMod;
|
|
@@ -296913,7 +297383,7 @@ async function serveCommand() {
|
|
|
296913
297383
|
} catch {
|
|
296914
297384
|
}
|
|
296915
297385
|
console.debug("\n tw serve -- starting production server\n");
|
|
296916
|
-
if (!
|
|
297386
|
+
if (!existsSync29(outDir)) {
|
|
296917
297387
|
console.debug(" No build found. Run 'tw build' first.\n");
|
|
296918
297388
|
process.exit(1);
|
|
296919
297389
|
}
|
|
@@ -297011,7 +297481,7 @@ function startStaticServer(outDir, port, host) {
|
|
|
297011
297481
|
});
|
|
297012
297482
|
}
|
|
297013
297483
|
const notFoundPath = join32(outDir, "404.html");
|
|
297014
|
-
if (
|
|
297484
|
+
if (existsSync29(notFoundPath)) {
|
|
297015
297485
|
const nf = Bun.file(notFoundPath);
|
|
297016
297486
|
return new Response(nf, { status: 404, headers: { "Content-Type": "text/html" } });
|
|
297017
297487
|
}
|
|
@@ -297026,14 +297496,14 @@ function startStaticServer(outDir, port, host) {
|
|
|
297026
297496
|
|
|
297027
297497
|
// tw/commands/ship.ts
|
|
297028
297498
|
import { join as join34, resolve as resolve10 } from "node:path";
|
|
297029
|
-
import { existsSync as
|
|
297499
|
+
import { existsSync as existsSync31, readFileSync as readFileSync22, writeFileSync as writeFileSync12 } from "node:fs";
|
|
297030
297500
|
async function loadAdapters(rootDir) {
|
|
297031
297501
|
const candidates = [
|
|
297032
297502
|
resolve10(rootDir, "node_modules", "@tw", "adapters", "tw", "index.ts"),
|
|
297033
297503
|
resolve10(rootDir, "node_modules", "@tw", "adapters", "tw", "index.js")
|
|
297034
297504
|
];
|
|
297035
297505
|
for (const c of candidates) {
|
|
297036
|
-
if (
|
|
297506
|
+
if (existsSync31(c)) {
|
|
297037
297507
|
try {
|
|
297038
297508
|
return await import(c);
|
|
297039
297509
|
} catch {
|
|
@@ -297052,7 +297522,7 @@ async function shipCommand() {
|
|
|
297052
297522
|
const rootDir = process.cwd();
|
|
297053
297523
|
const outDir = join34(rootDir, ".tw");
|
|
297054
297524
|
console.log("\n tw ship -- deploy project\n");
|
|
297055
|
-
if (!
|
|
297525
|
+
if (!existsSync31(outDir)) {
|
|
297056
297526
|
console.log(" No build found. Running build first...\n");
|
|
297057
297527
|
try {
|
|
297058
297528
|
const { buildCommand: buildCommand2 } = await init_build().then(() => build_exports);
|
|
@@ -297065,13 +297535,13 @@ async function shipCommand() {
|
|
|
297065
297535
|
}
|
|
297066
297536
|
let deployTarget = target;
|
|
297067
297537
|
if (target === "auto") {
|
|
297068
|
-
if (
|
|
297538
|
+
if (existsSync31(join34(rootDir, "vercel.json"))) {
|
|
297069
297539
|
deployTarget = "vercel";
|
|
297070
|
-
} else if (
|
|
297540
|
+
} else if (existsSync31(join34(rootDir, "netlify.toml"))) {
|
|
297071
297541
|
deployTarget = "netlify";
|
|
297072
|
-
} else if (
|
|
297542
|
+
} else if (existsSync31(join34(rootDir, "wrangler.toml"))) {
|
|
297073
297543
|
deployTarget = "cloudflare";
|
|
297074
|
-
} else if (
|
|
297544
|
+
} else if (existsSync31(join34(rootDir, "Dockerfile"))) {
|
|
297075
297545
|
deployTarget = "docker";
|
|
297076
297546
|
} else {
|
|
297077
297547
|
deployTarget = "static";
|
|
@@ -297131,13 +297601,13 @@ async function shipCommand() {
|
|
|
297131
297601
|
async function generateVercelConfig(rootDir, outDir) {
|
|
297132
297602
|
const adapters = await loadAdapters(rootDir);
|
|
297133
297603
|
const configPath = join34(rootDir, "vercel.json");
|
|
297134
|
-
if (
|
|
297604
|
+
if (existsSync31(configPath)) {
|
|
297135
297605
|
console.log(" OK vercel.json already exists (left unchanged)");
|
|
297136
297606
|
if (adapters?.readBuildSummary && adapters?.needsServer) {
|
|
297137
297607
|
if (adapters.needsServer(adapters.readBuildSummary(rootDir))) {
|
|
297138
297608
|
let raw = "";
|
|
297139
297609
|
try {
|
|
297140
|
-
raw =
|
|
297610
|
+
raw = readFileSync22(configPath, "utf-8");
|
|
297141
297611
|
} catch {
|
|
297142
297612
|
}
|
|
297143
297613
|
if (!/"functions"|"rewrites"/.test(raw)) {
|
|
@@ -297153,7 +297623,7 @@ async function generateVercelConfig(rootDir, outDir) {
|
|
|
297153
297623
|
for (const w of adapters.generateAdapter("vercel", rootDir)) console.log(" OK " + w.replace(rootDir + "/", ""));
|
|
297154
297624
|
return;
|
|
297155
297625
|
}
|
|
297156
|
-
|
|
297626
|
+
writeFileSync12(configPath, JSON.stringify({ buildCommand: "npx tw build", installCommand: "npm install", outputDirectory: ".tw", framework: null }, null, 2));
|
|
297157
297627
|
console.log(" OK Generated vercel.json");
|
|
297158
297628
|
}
|
|
297159
297629
|
function generateNetlifyConfig(rootDir, outDir) {
|
|
@@ -297164,9 +297634,9 @@ function generateNetlifyConfig(rootDir, outDir) {
|
|
|
297164
297634
|
[build.environment]
|
|
297165
297635
|
NODE_VERSION = "20"`;
|
|
297166
297636
|
const configPath = join34(rootDir, "netlify.toml");
|
|
297167
|
-
const existing =
|
|
297637
|
+
const existing = existsSync31(configPath);
|
|
297168
297638
|
if (!existing) {
|
|
297169
|
-
|
|
297639
|
+
writeFileSync12(configPath, config);
|
|
297170
297640
|
console.log(" OK Generated netlify.toml");
|
|
297171
297641
|
} else {
|
|
297172
297642
|
console.log(" OK netlify.toml already exists");
|
|
@@ -297179,9 +297649,9 @@ compatibility_date = "2024-01-01"
|
|
|
297179
297649
|
[assets]
|
|
297180
297650
|
directory = ".tw"`;
|
|
297181
297651
|
const configPath = join34(rootDir, "wrangler.toml");
|
|
297182
|
-
const existing =
|
|
297652
|
+
const existing = existsSync31(configPath);
|
|
297183
297653
|
if (!existing) {
|
|
297184
|
-
|
|
297654
|
+
writeFileSync12(configPath, config);
|
|
297185
297655
|
console.log(" OK Generated wrangler.toml");
|
|
297186
297656
|
} else {
|
|
297187
297657
|
console.log(" OK wrangler.toml already exists");
|
|
@@ -297219,9 +297689,9 @@ COPY --from=build /app ./
|
|
|
297219
297689
|
EXPOSE 8000
|
|
297220
297690
|
CMD ["bunx", "tw", "serve"]`;
|
|
297221
297691
|
const configPath = join34(rootDir, "Dockerfile");
|
|
297222
|
-
const existing =
|
|
297692
|
+
const existing = existsSync31(configPath);
|
|
297223
297693
|
if (!existing) {
|
|
297224
|
-
|
|
297694
|
+
writeFileSync12(configPath, dockerfile);
|
|
297225
297695
|
console.log(" OK Generated Dockerfile");
|
|
297226
297696
|
} else {
|
|
297227
297697
|
console.log(" OK Dockerfile already exists");
|
|
@@ -297229,8 +297699,8 @@ CMD ["bunx", "tw", "serve"]`;
|
|
|
297229
297699
|
}
|
|
297230
297700
|
|
|
297231
297701
|
// tw/commands/adapter.ts
|
|
297232
|
-
import { resolve as resolve11 } from "node:path";
|
|
297233
|
-
import { existsSync as
|
|
297702
|
+
import { join as join35, resolve as resolve11 } from "node:path";
|
|
297703
|
+
import { existsSync as existsSync32, readdirSync as readdirSync11, readFileSync as readFileSync23 } from "node:fs";
|
|
297234
297704
|
async function adapterCommand() {
|
|
297235
297705
|
const args = process.argv.slice(3);
|
|
297236
297706
|
const rootDir = process.cwd();
|
|
@@ -297241,7 +297711,7 @@ async function adapterCommand() {
|
|
|
297241
297711
|
let adaptersMod = null;
|
|
297242
297712
|
let via = "";
|
|
297243
297713
|
for (const c of candidates) {
|
|
297244
|
-
if (
|
|
297714
|
+
if (existsSync32(c)) {
|
|
297245
297715
|
adaptersMod = await import(c);
|
|
297246
297716
|
via = c;
|
|
297247
297717
|
break;
|
|
@@ -297277,6 +297747,58 @@ async function adapterCommand() {
|
|
|
297277
297747
|
`);
|
|
297278
297748
|
process.exit(1);
|
|
297279
297749
|
}
|
|
297750
|
+
const STATIC_ONLY = /* @__PURE__ */ new Set([
|
|
297751
|
+
"node",
|
|
297752
|
+
"deno",
|
|
297753
|
+
"cloudflare",
|
|
297754
|
+
"netlify",
|
|
297755
|
+
"github-pages",
|
|
297756
|
+
"firebase",
|
|
297757
|
+
"aws",
|
|
297758
|
+
"digitalocean",
|
|
297759
|
+
"render",
|
|
297760
|
+
"nginx",
|
|
297761
|
+
"caddy",
|
|
297762
|
+
"vercel",
|
|
297763
|
+
"static"
|
|
297764
|
+
]);
|
|
297765
|
+
if (STATIC_ONLY.has(name)) {
|
|
297766
|
+
const apiRoots = [join35(rootDir, ".tw", "api"), join35(rootDir, "api")];
|
|
297767
|
+
let apiCount = 0;
|
|
297768
|
+
const countTwm = (dir) => {
|
|
297769
|
+
if (!existsSync32(dir)) return;
|
|
297770
|
+
for (const entry of readdirSync11(dir, { withFileTypes: true })) {
|
|
297771
|
+
const full = join35(dir, entry.name);
|
|
297772
|
+
if (entry.isDirectory()) countTwm(full);
|
|
297773
|
+
else if (entry.name === "route.twm") apiCount++;
|
|
297774
|
+
}
|
|
297775
|
+
};
|
|
297776
|
+
for (const r of apiRoots) countTwm(r);
|
|
297777
|
+
let ssrCount = 0;
|
|
297778
|
+
const countSsr = (dir) => {
|
|
297779
|
+
if (!existsSync32(dir)) return;
|
|
297780
|
+
for (const entry of readdirSync11(dir, { withFileTypes: true })) {
|
|
297781
|
+
const full = join35(dir, entry.name);
|
|
297782
|
+
if (entry.isDirectory()) {
|
|
297783
|
+
countSsr(full);
|
|
297784
|
+
continue;
|
|
297785
|
+
}
|
|
297786
|
+
if (entry.name !== "page.tw") continue;
|
|
297787
|
+
const src = readFileSync23(full, "utf-8");
|
|
297788
|
+
const m = src.match(/render\s+(ssr|stream|csr|ppr)\b/);
|
|
297789
|
+
if (m) ssrCount++;
|
|
297790
|
+
}
|
|
297791
|
+
};
|
|
297792
|
+
countSsr(join35(rootDir, "home"));
|
|
297793
|
+
if (apiCount > 0 || ssrCount > 0) {
|
|
297794
|
+
const parts = [];
|
|
297795
|
+
if (ssrCount > 0) parts.push(ssrCount + " page" + (ssrCount === 1 ? "" : "s") + " rendered per request");
|
|
297796
|
+
if (apiCount > 0) parts.push(apiCount + " API route" + (apiCount === 1 ? "" : "s"));
|
|
297797
|
+
console.log("\n ! " + parts.join(" and ") + " will not be served by the " + name + " adapter.");
|
|
297798
|
+
console.log(" It packages the static build only, so those routes answer 404.");
|
|
297799
|
+
console.log(" Use `tw adapter bun` (or the Dockerfile) if they must run.\n");
|
|
297800
|
+
}
|
|
297801
|
+
}
|
|
297280
297802
|
const written = adaptersMod.generateAdapter(name, rootDir);
|
|
297281
297803
|
console.log(`
|
|
297282
297804
|
${via ? "" : ""}Generated ${name} adapter:
|
|
@@ -297290,11 +297812,11 @@ async function adapterCommand() {
|
|
|
297290
297812
|
// tw/commands/test.ts
|
|
297291
297813
|
import { join as join37 } from "node:path";
|
|
297292
297814
|
import { createRequire as _cr } from "node:module";
|
|
297293
|
-
import { existsSync as
|
|
297815
|
+
import { existsSync as existsSync33, readdirSync as readdirSync12, statSync as statSync11, readFileSync as readFileSync25 } from "node:fs";
|
|
297294
297816
|
var _require = _cr(import.meta.url);
|
|
297295
297817
|
function collectTests(dir, out) {
|
|
297296
|
-
if (!
|
|
297297
|
-
for (const entry of
|
|
297818
|
+
if (!existsSync33(dir)) return;
|
|
297819
|
+
for (const entry of readdirSync12(dir)) {
|
|
297298
297820
|
const full = join37(dir, entry);
|
|
297299
297821
|
if (statSync11(full).isDirectory()) collectTests(full, out);
|
|
297300
297822
|
else if (/\.test\.(ts|tsx|js)$/.test(entry)) out.push(full);
|
|
@@ -297304,10 +297826,10 @@ function ensureTestingShim(rootDir) {
|
|
|
297304
297826
|
try {
|
|
297305
297827
|
const shimPkgDir = join37(rootDir, "node_modules", "@tw", "server");
|
|
297306
297828
|
const marker = join37(shimPkgDir, "package.json");
|
|
297307
|
-
if (
|
|
297308
|
-
const { mkdirSync: mkdirSync12, writeFileSync:
|
|
297829
|
+
if (existsSync33(marker)) return;
|
|
297830
|
+
const { mkdirSync: mkdirSync12, writeFileSync: writeFileSync15 } = _require("node:fs");
|
|
297309
297831
|
mkdirSync12(join37(shimPkgDir, "tw"), { recursive: true });
|
|
297310
|
-
|
|
297832
|
+
writeFileSync15(marker, JSON.stringify({ name: "@tw/server", version: "2.0.5", private: true }, null, 2));
|
|
297311
297833
|
let testingBundle = null;
|
|
297312
297834
|
try {
|
|
297313
297835
|
const here = new URL(".", import.meta.url).pathname;
|
|
@@ -297316,7 +297838,7 @@ function ensureTestingShim(rootDir) {
|
|
|
297316
297838
|
join37(here, "..", "..", "dist", "testing.cjs")
|
|
297317
297839
|
];
|
|
297318
297840
|
for (const c of candidates) {
|
|
297319
|
-
if (
|
|
297841
|
+
if (existsSync33(c)) {
|
|
297320
297842
|
testingBundle = c;
|
|
297321
297843
|
break;
|
|
297322
297844
|
}
|
|
@@ -297327,7 +297849,7 @@ function ensureTestingShim(rootDir) {
|
|
|
297327
297849
|
console.warn(" [tw test] testing bundle not found (dist/testing.cjs); test helpers unavailable");
|
|
297328
297850
|
return;
|
|
297329
297851
|
}
|
|
297330
|
-
|
|
297852
|
+
writeFileSync15(
|
|
297331
297853
|
join37(shimPkgDir, "tw", "testing.js"),
|
|
297332
297854
|
"// Generated by `tw test` -- shim pointing at the CLI testing bundle.\nmodule.exports = require(" + JSON.stringify(testingBundle) + ");\n"
|
|
297333
297855
|
);
|
|
@@ -297340,15 +297862,15 @@ async function testCommand() {
|
|
|
297340
297862
|
ensureTestingShim(rootDir);
|
|
297341
297863
|
const files = [];
|
|
297342
297864
|
collectTests(testsDir, files);
|
|
297343
|
-
if (
|
|
297344
|
-
for (const f of
|
|
297865
|
+
if (existsSync33(rootDir)) {
|
|
297866
|
+
for (const f of readdirSync12(rootDir)) {
|
|
297345
297867
|
if (/\.test\.(ts|tsx|js)$/.test(f)) files.push(join37(rootDir, f));
|
|
297346
297868
|
}
|
|
297347
297869
|
}
|
|
297348
297870
|
console.log("\n tw test -- running " + files.length + " test file" + (files.length === 1 ? "" : "s") + "\n");
|
|
297349
297871
|
for (const f of files) {
|
|
297350
297872
|
try {
|
|
297351
|
-
const src =
|
|
297873
|
+
const src = readFileSync25(f, "utf-8");
|
|
297352
297874
|
const hasBunTest = src.includes("bun:test");
|
|
297353
297875
|
const hasTestCall = /\b(test|it|describe)\s*\(/.test(src);
|
|
297354
297876
|
if (!hasBunTest && !hasTestCall) {
|
|
@@ -297390,15 +297912,28 @@ async function testCommand() {
|
|
|
297390
297912
|
// tw/commands/check.ts
|
|
297391
297913
|
init_tw();
|
|
297392
297914
|
init_components();
|
|
297393
|
-
import { join as join38, dirname as
|
|
297394
|
-
import { existsSync as
|
|
297915
|
+
import { join as join38, dirname as dirname17 } from "node:path";
|
|
297916
|
+
import { existsSync as existsSync34, readFileSync as readFileSync26, readdirSync as readdirSync13, statSync as statSync12 } from "node:fs";
|
|
297395
297917
|
async function checkCommand() {
|
|
297396
297918
|
const args = process.argv.slice(3);
|
|
297397
297919
|
const rootDir = process.cwd();
|
|
297920
|
+
const ignored = /* @__PURE__ */ new Set();
|
|
297921
|
+
for (let i = 0; i < args.length; i++) {
|
|
297922
|
+
if (args[i] === "--ignore" && args[i + 1]) {
|
|
297923
|
+
for (const code of String(args[i + 1]).split(/[,\s]+/)) {
|
|
297924
|
+
if (code) ignored.add(code.trim().toUpperCase());
|
|
297925
|
+
}
|
|
297926
|
+
i++;
|
|
297927
|
+
} else if (args[i].startsWith("--ignore=")) {
|
|
297928
|
+
for (const code of args[i].slice("--ignore=".length).split(/[,\s]+/)) {
|
|
297929
|
+
if (code) ignored.add(code.trim().toUpperCase());
|
|
297930
|
+
}
|
|
297931
|
+
}
|
|
297932
|
+
}
|
|
297398
297933
|
const srcDir = join38(rootDir, "home");
|
|
297399
297934
|
console.debug("\n tw check -- running type check and diagnostics\n");
|
|
297400
297935
|
const twFiles = [];
|
|
297401
|
-
if (
|
|
297936
|
+
if (existsSync34(srcDir)) {
|
|
297402
297937
|
collectFiles2(srcDir, ".tw", twFiles);
|
|
297403
297938
|
}
|
|
297404
297939
|
if (twFiles.length === 0) {
|
|
@@ -297420,7 +297955,7 @@ async function checkCommand() {
|
|
|
297420
297955
|
for (const filePath of twFiles) {
|
|
297421
297956
|
const relativePath = filePath.replace(rootDir + "/", "");
|
|
297422
297957
|
try {
|
|
297423
|
-
const source =
|
|
297958
|
+
const source = readFileSync26(filePath, "utf-8");
|
|
297424
297959
|
registerImportedComponents(filePath, rootDir, { compileSync: compileSync4, registerComponentTemplate: registerComponentTemplate3, clearComponentRegistry: clearComponentRegistry3 }, source);
|
|
297425
297960
|
const result = await compile2(source, {
|
|
297426
297961
|
filePath,
|
|
@@ -297432,7 +297967,7 @@ async function checkCommand() {
|
|
|
297432
297967
|
const errors = diagnostics.filter((d) => d.severity === "error");
|
|
297433
297968
|
const warnings = diagnostics.filter((d) => d.severity === "warning");
|
|
297434
297969
|
const info = diagnostics.filter((d) => d.severity === "info");
|
|
297435
|
-
const checkSource =
|
|
297970
|
+
const checkSource = readFileSync26(filePath, "utf-8");
|
|
297436
297971
|
const usedTags = /* @__PURE__ */ new Set();
|
|
297437
297972
|
const collectUsed = (n) => {
|
|
297438
297973
|
if (!n) return;
|
|
@@ -297458,7 +297993,7 @@ async function checkCommand() {
|
|
|
297458
297993
|
const unknownComponents = [];
|
|
297459
297994
|
for (const tag2 of usedTags) {
|
|
297460
297995
|
if (SAFE_TAGS.has(tag2) || importedNames.has(tag2)) continue;
|
|
297461
|
-
if (findComponentUp(
|
|
297996
|
+
if (findComponentUp(dirname17(filePath), tag2)) continue;
|
|
297462
297997
|
unknownComponents.push(tag2);
|
|
297463
297998
|
}
|
|
297464
297999
|
if (unknownComponents.length > 0) {
|
|
@@ -297468,14 +298003,18 @@ async function checkCommand() {
|
|
|
297468
298003
|
}
|
|
297469
298004
|
totalWarnings += unknownComponents.length;
|
|
297470
298005
|
}
|
|
297471
|
-
|
|
297472
|
-
|
|
297473
|
-
|
|
297474
|
-
|
|
298006
|
+
const kept = ignored.size === 0 ? diagnostics : diagnostics.filter((d) => !ignored.has(String(d.code).toUpperCase()));
|
|
298007
|
+
const keptErrors = kept.filter((d) => d.severity === "error");
|
|
298008
|
+
const keptWarnings = kept.filter((d) => d.severity === "warning");
|
|
298009
|
+
const keptInfo = kept.filter((d) => d.severity !== "error" && d.severity !== "warning");
|
|
298010
|
+
totalErrors += keptErrors.length;
|
|
298011
|
+
totalWarnings += keptWarnings.length;
|
|
298012
|
+
totalInfo += keptInfo.length;
|
|
298013
|
+
if (kept.length === 0) {
|
|
297475
298014
|
console.debug(` OK ${relativePath} -- no issues`);
|
|
297476
298015
|
} else {
|
|
297477
|
-
console.debug(` ? ${relativePath} -- ${
|
|
297478
|
-
for (const d of
|
|
298016
|
+
console.debug(` ? ${relativePath} -- ${keptErrors.length} errors, ${keptWarnings.length} warnings, ${keptInfo.length} info`);
|
|
298017
|
+
for (const d of kept) {
|
|
297479
298018
|
const sev = d.severity === "error" ? "?" : d.severity === "warning" ? "?" : "?";
|
|
297480
298019
|
const loc = `line ${d.line}, col ${d.col}`;
|
|
297481
298020
|
console.debug(` ${sev} ${d.code} ${loc}: ${d.message}`);
|
|
@@ -297489,7 +298028,7 @@ async function checkCommand() {
|
|
|
297489
298028
|
} else {
|
|
297490
298029
|
for (const filePath of twFiles) {
|
|
297491
298030
|
const relativePath = filePath.replace(rootDir + "/", "");
|
|
297492
|
-
const source =
|
|
298031
|
+
const source = readFileSync26(filePath, "utf-8");
|
|
297493
298032
|
const maskedSource = maskSourceStringsAndComments(source);
|
|
297494
298033
|
const openBraces = (maskedSource.match(/\{/g) || []).length;
|
|
297495
298034
|
const closeBraces = (maskedSource.match(/\}/g) || []).length;
|
|
@@ -297529,17 +298068,17 @@ function findComponentUp(dir, name) {
|
|
|
297529
298068
|
for (let i = 0; i < 12 && cur && cur !== "/"; i++) {
|
|
297530
298069
|
try {
|
|
297531
298070
|
const candidate = join38(cur, "components", name + ".tw");
|
|
297532
|
-
if (
|
|
298071
|
+
if (existsSync34(candidate)) return true;
|
|
297533
298072
|
} catch {
|
|
297534
298073
|
}
|
|
297535
|
-
const parent =
|
|
298074
|
+
const parent = dirname17(cur);
|
|
297536
298075
|
if (parent === cur) break;
|
|
297537
298076
|
cur = parent;
|
|
297538
298077
|
}
|
|
297539
298078
|
return false;
|
|
297540
298079
|
}
|
|
297541
298080
|
function collectFiles2(dir, ext, results) {
|
|
297542
|
-
const entries =
|
|
298081
|
+
const entries = readdirSync13(dir);
|
|
297543
298082
|
for (const entry of entries) {
|
|
297544
298083
|
const fullPath = join38(dir, entry);
|
|
297545
298084
|
const stat = statSync12(fullPath);
|
|
@@ -297555,38 +298094,38 @@ function collectFiles2(dir, ext, results) {
|
|
|
297555
298094
|
init_tw();
|
|
297556
298095
|
init_tw8();
|
|
297557
298096
|
import { join as join39 } from "node:path";
|
|
297558
|
-
import { existsSync as
|
|
298097
|
+
import { existsSync as existsSync35, readFileSync as readFileSync27, writeFileSync as writeFileSync14, mkdirSync as mkdirSync11, readdirSync as readdirSync14 } from "node:fs";
|
|
297559
298098
|
function readConfigPlugins(cfgPath) {
|
|
297560
|
-
if (!
|
|
297561
|
-
const src = stripCommentsStringAware(
|
|
298099
|
+
if (!existsSync35(cfgPath)) return [];
|
|
298100
|
+
const src = stripCommentsStringAware(readFileSync27(cfgPath, "utf-8"));
|
|
297562
298101
|
return readPluginSpecs(src);
|
|
297563
298102
|
}
|
|
297564
298103
|
function addConfigPlugin(cfgPath, name) {
|
|
297565
|
-
if (!
|
|
297566
|
-
|
|
298104
|
+
if (!existsSync35(cfgPath)) {
|
|
298105
|
+
writeFileSync14(cfgPath, `export default {
|
|
297567
298106
|
plugins: ["${name}"],
|
|
297568
298107
|
};
|
|
297569
298108
|
`);
|
|
297570
298109
|
return true;
|
|
297571
298110
|
}
|
|
297572
|
-
const src = stripCommentsStringAware(
|
|
298111
|
+
const src = stripCommentsStringAware(readFileSync27(cfgPath, "utf-8"));
|
|
297573
298112
|
if (new RegExp(`["'\`]${name}["'\`]`).test(src)) return false;
|
|
297574
298113
|
const m = /plugins\s*:\s*\[([^\]]*)\]/s.exec(src);
|
|
297575
298114
|
if (m) {
|
|
297576
298115
|
const inner = m[1].trim();
|
|
297577
298116
|
const next = inner.length ? `${inner}, "${name}"` : `"${name}"`;
|
|
297578
|
-
|
|
298117
|
+
writeFileSync14(cfgPath, src.replace(m[0], `plugins: [${next}]`));
|
|
297579
298118
|
} else {
|
|
297580
298119
|
const idx = src.lastIndexOf("}");
|
|
297581
298120
|
if (idx === -1) return false;
|
|
297582
|
-
|
|
298121
|
+
writeFileSync14(cfgPath, src.slice(0, idx) + ` plugins: ["${name}"],
|
|
297583
298122
|
` + src.slice(idx));
|
|
297584
298123
|
}
|
|
297585
298124
|
return true;
|
|
297586
298125
|
}
|
|
297587
298126
|
function removeConfigPlugin(cfgPath, name) {
|
|
297588
|
-
if (!
|
|
297589
|
-
const src =
|
|
298127
|
+
if (!existsSync35(cfgPath)) return false;
|
|
298128
|
+
const src = readFileSync27(cfgPath, "utf-8");
|
|
297590
298129
|
const masked = maskSourceStringsAndComments(src);
|
|
297591
298130
|
const range2 = pluginsArrayRange(masked);
|
|
297592
298131
|
if (!range2) return false;
|
|
@@ -297594,13 +298133,13 @@ function removeConfigPlugin(cfgPath, name) {
|
|
|
297594
298133
|
const kept = entries.map((e) => e.trim()).filter((e) => e && entryName(e) !== name);
|
|
297595
298134
|
if (kept.length === entries.filter((e) => e.trim()).length) return false;
|
|
297596
298135
|
const body = kept.length ? " " + kept.join(", ") + " " : "";
|
|
297597
|
-
|
|
298136
|
+
writeFileSync14(cfgPath, src.slice(0, range2.start) + body + src.slice(range2.end));
|
|
297598
298137
|
return true;
|
|
297599
298138
|
}
|
|
297600
298139
|
function listPluginFiles(rootDir) {
|
|
297601
298140
|
const dir = join39(rootDir, "plugins");
|
|
297602
|
-
if (!
|
|
297603
|
-
return
|
|
298141
|
+
if (!existsSync35(dir)) return [];
|
|
298142
|
+
return readdirSync14(dir).filter((f) => f.endsWith(".ts") && !f.endsWith(".d.ts"));
|
|
297604
298143
|
}
|
|
297605
298144
|
async function searchPlugins(term) {
|
|
297606
298145
|
const q = term ? `keywords:tw-plugin ${term}` : "keywords:tw-plugin";
|
|
@@ -297657,7 +298196,7 @@ async function initPluginPackage(rootDir, name) {
|
|
|
297657
298196
|
}
|
|
297658
298197
|
const pkgName = name.startsWith("tw-plugin-") ? name : `tw-plugin-${name}`;
|
|
297659
298198
|
const dir = join39(rootDir, pkgName);
|
|
297660
|
-
if (
|
|
298199
|
+
if (existsSync35(dir)) {
|
|
297661
298200
|
console.error(` Already exists: ${pkgName}/`);
|
|
297662
298201
|
process.exit(1);
|
|
297663
298202
|
}
|
|
@@ -297676,7 +298215,7 @@ async function initPluginPackage(rootDir, name) {
|
|
|
297676
298215
|
peerDependencies: { "tw-framework": ">=2.0.0" },
|
|
297677
298216
|
license: "MIT"
|
|
297678
298217
|
};
|
|
297679
|
-
|
|
298218
|
+
writeFileSync14(join39(dir, "package.json"), JSON.stringify(manifest, null, 2) + "\n");
|
|
297680
298219
|
const src = `import type { TWPlugin } from "tw-framework/plugins";
|
|
297681
298220
|
|
|
297682
298221
|
/**
|
|
@@ -297703,7 +298242,7 @@ const plugin: TWPlugin = {
|
|
|
297703
298242
|
|
|
297704
298243
|
export default plugin;
|
|
297705
298244
|
`;
|
|
297706
|
-
|
|
298245
|
+
writeFileSync14(join39(dir, "src", "index.ts"), src);
|
|
297707
298246
|
const readme = `# ${pkgName}
|
|
297708
298247
|
|
|
297709
298248
|
A TW Framework plugin.
|
|
@@ -297721,9 +298260,9 @@ server with Bun (\`tw serve\`) \u2014 plugins load as TypeScript modules.
|
|
|
297721
298260
|
|
|
297722
298261
|
Describe the hooks and routes this plugin registers.
|
|
297723
298262
|
`;
|
|
297724
|
-
|
|
298263
|
+
writeFileSync14(join39(dir, "README.md"), readme);
|
|
297725
298264
|
const gitignore = "node_modules/\ndist/\n*.log\n";
|
|
297726
|
-
|
|
298265
|
+
writeFileSync14(join39(dir, ".gitignore"), gitignore);
|
|
297727
298266
|
console.log(`
|
|
297728
298267
|
Created ${pkgName}/`);
|
|
297729
298268
|
console.log(` package.json name + the "tw-plugin" keyword (required for search)`);
|
|
@@ -297738,12 +298277,12 @@ Describe the hooks and routes this plugin registers.
|
|
|
297738
298277
|
}
|
|
297739
298278
|
async function upgradePlugins(rootDir, opts) {
|
|
297740
298279
|
const cfgPath = join39(rootDir, "tw.config.ts");
|
|
297741
|
-
if (!
|
|
298280
|
+
if (!existsSync35(cfgPath)) {
|
|
297742
298281
|
console.error(" No tw.config.ts here. Run this from a project root.\n");
|
|
297743
298282
|
process.exit(1);
|
|
297744
298283
|
}
|
|
297745
298284
|
const { readPluginSpecs: readPluginSpecs2, planUpgrade: planUpgrade2, outdated: outdated2 } = await Promise.resolve().then(() => (init_tw8(), tw_exports4));
|
|
297746
|
-
const specs = readPluginSpecs2(
|
|
298285
|
+
const specs = readPluginSpecs2(readFileSync27(cfgPath, "utf-8"));
|
|
297747
298286
|
if (specs.length === 0) {
|
|
297748
298287
|
console.log("\n No plugins in tw.config.ts -- nothing to upgrade.\n");
|
|
297749
298288
|
return;
|
|
@@ -297845,7 +298384,7 @@ async function pluginCommand() {
|
|
|
297845
298384
|
console.error("Usage: tw plugin add <name>");
|
|
297846
298385
|
process.exit(1);
|
|
297847
298386
|
}
|
|
297848
|
-
if (!
|
|
298387
|
+
if (!existsSync35(join39(rootDir, "plugins", `${name}.ts`))) {
|
|
297849
298388
|
console.error(` No file plugins/${name}.ts -- create it first: tw plugin create ${name}`);
|
|
297850
298389
|
process.exit(1);
|
|
297851
298390
|
}
|
|
@@ -297873,11 +298412,11 @@ async function pluginCommand() {
|
|
|
297873
298412
|
const pluginsDir = join39(rootDir, "plugins");
|
|
297874
298413
|
mkdirSync11(pluginsDir, { recursive: true });
|
|
297875
298414
|
const file = join39(pluginsDir, `${name}.ts`);
|
|
297876
|
-
if (
|
|
298415
|
+
if (existsSync35(file)) {
|
|
297877
298416
|
console.error(` Already exists: plugins/${name}.ts`);
|
|
297878
298417
|
process.exit(1);
|
|
297879
298418
|
}
|
|
297880
|
-
|
|
298419
|
+
writeFileSync14(file, `/** ${name} - TW Framework plugin */
|
|
297881
298420
|
|
|
297882
298421
|
import type { TWPlugin } from "@tw/plugins";
|
|
297883
298422
|
|
|
@@ -297997,10 +298536,10 @@ var colors = {
|
|
|
297997
298536
|
|
|
297998
298537
|
// tw/commands/lsp.ts
|
|
297999
298538
|
import { join as join40 } from "node:path";
|
|
298000
|
-
import { existsSync as
|
|
298539
|
+
import { existsSync as existsSync36 } from "node:fs";
|
|
298001
298540
|
async function lspCommand() {
|
|
298002
298541
|
const rootDir = process.cwd();
|
|
298003
|
-
if (!
|
|
298542
|
+
if (!existsSync36(join40(rootDir, "tw.config.ts")) && !existsSync36(join40(rootDir, "home"))) {
|
|
298004
298543
|
console.error(`${colors.yellow("!")} Not inside a TW project (no tw.config.ts / home/) \u2014 starting anyway from ${rootDir}`);
|
|
298005
298544
|
}
|
|
298006
298545
|
console.error(` ${colors.bold("tw lsp")} \u2014 language server on stdio`);
|
|
@@ -298016,7 +298555,7 @@ async function lspCommand() {
|
|
|
298016
298555
|
// tw/commands/doctor.ts
|
|
298017
298556
|
init_tw();
|
|
298018
298557
|
init_tw();
|
|
298019
|
-
import { existsSync as
|
|
298558
|
+
import { existsSync as existsSync37 } from "node:fs";
|
|
298020
298559
|
import { join as join41 } from "node:path";
|
|
298021
298560
|
var C = {
|
|
298022
298561
|
reset: "\x1B[0m",
|
|
@@ -298032,7 +298571,7 @@ var warn = (s) => `${C.yellow}!${C.reset} ${s}`;
|
|
|
298032
298571
|
var bad = (s) => `${C.red}\u2717${C.reset} ${s}`;
|
|
298033
298572
|
function hasPackage4(rootDir, name) {
|
|
298034
298573
|
for (const base of [rootDir, process.cwd()]) {
|
|
298035
|
-
if (
|
|
298574
|
+
if (existsSync37(join41(base, "node_modules", name))) return true;
|
|
298036
298575
|
}
|
|
298037
298576
|
return false;
|
|
298038
298577
|
}
|
|
@@ -298103,7 +298642,7 @@ async function doctorCommand() {
|
|
|
298103
298642
|
let cfg = null;
|
|
298104
298643
|
try {
|
|
298105
298644
|
const tsPath = join41(rootDir, "tw.config.ts");
|
|
298106
|
-
if (
|
|
298645
|
+
if (existsSync37(tsPath)) {
|
|
298107
298646
|
const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
298108
298647
|
const mod = await twImportTs2(tsPath);
|
|
298109
298648
|
cfg = mod?.default ?? mod;
|
|
@@ -298199,13 +298738,13 @@ async function doctorCommand() {
|
|
|
298199
298738
|
}
|
|
298200
298739
|
|
|
298201
298740
|
// tw/help.ts
|
|
298202
|
-
import { readFileSync as
|
|
298741
|
+
import { readFileSync as readFileSync28 } from "node:fs";
|
|
298203
298742
|
import { join as join42 } from "node:path";
|
|
298204
298743
|
function cliVersion() {
|
|
298205
298744
|
try {
|
|
298206
298745
|
const bd = globalThis.__TW_BUNDLE_DIR;
|
|
298207
298746
|
const pj = bd ? join42(bd, "..", "package.json") : new URL("../package.json", import.meta.url).pathname;
|
|
298208
|
-
return JSON.parse(
|
|
298747
|
+
return JSON.parse(readFileSync28(pj, "utf-8")).version ?? "0.0.0";
|
|
298209
298748
|
} catch {
|
|
298210
298749
|
return "0.0.0";
|
|
298211
298750
|
}
|
|
@@ -298279,13 +298818,13 @@ var helpText = `
|
|
|
298279
298818
|
|
|
298280
298819
|
// tw/commands/index.ts
|
|
298281
298820
|
await init_build();
|
|
298282
|
-
import { readFileSync as
|
|
298821
|
+
import { readFileSync as readFileSync29 } from "node:fs";
|
|
298283
298822
|
import { join as join43 } from "node:path";
|
|
298284
298823
|
var VERSION2 = (() => {
|
|
298285
298824
|
try {
|
|
298286
298825
|
const bd = globalThis.__TW_BUNDLE_DIR;
|
|
298287
298826
|
const pj = bd ? join43(bd, "..", "package.json") : new URL("../../package.json", import.meta.url).pathname;
|
|
298288
|
-
return JSON.parse(
|
|
298827
|
+
return JSON.parse(readFileSync29(pj, "utf-8")).version ?? "0.0.0";
|
|
298289
298828
|
} catch {
|
|
298290
298829
|
return "0.0.0";
|
|
298291
298830
|
}
|