tw-framework 2.0.4 → 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 +56 -0
- package/dist/testing.cjs +452 -189
- package/dist/tw-server.mjs +422 -158
- package/dist/tw.mjs +845 -475
- 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.
|
|
@@ -227672,7 +227716,7 @@ function parseElement(cursor, errors, state, parseBody) {
|
|
|
227672
227716
|
const tag2 = tagToken.value;
|
|
227673
227717
|
if (tag2 && /^[A-Za-z][A-Za-z0-9-]*$/.test(tag2)) {
|
|
227674
227718
|
errors.add(new CompilerError(
|
|
227675
|
-
"raw HTML is not supported in .tw -- write it in TW syntax: " + tag2 + " { ... }
|
|
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}',
|
|
227676
227720
|
tagToken.pos.line,
|
|
227677
227721
|
tagToken.pos.col,
|
|
227678
227722
|
"TW123",
|
|
@@ -236336,7 +236380,7 @@ var init_types4 = __esm({
|
|
|
236336
236380
|
var TW_VERSION, TW_GENERATOR_META;
|
|
236337
236381
|
var init_version = __esm({
|
|
236338
236382
|
"../../packages/compiler/tw/codegen/version.ts"() {
|
|
236339
|
-
TW_VERSION = "2.0.
|
|
236383
|
+
TW_VERSION = "2.0.5";
|
|
236340
236384
|
TW_GENERATOR_META = `<meta name="generator" content="TW Framework ${TW_VERSION}">`;
|
|
236341
236385
|
}
|
|
236342
236386
|
});
|
|
@@ -237942,6 +237986,39 @@ function validatePlainCss(src, filePath) {
|
|
|
237942
237986
|
checkDecl();
|
|
237943
237987
|
return src;
|
|
237944
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
|
+
}
|
|
237945
238022
|
function compileDecl(decl) {
|
|
237946
238023
|
const trimmed = decl.trim();
|
|
237947
238024
|
if (!trimmed) return "";
|
|
@@ -237949,10 +238026,10 @@ function compileDecl(decl) {
|
|
|
237949
238026
|
if (cssForm) return trimmed.replace(/^([-\w]+)\s*:\s*/, "$1: ");
|
|
237950
238027
|
const spaceIdx = trimmed.search(/[\s]/);
|
|
237951
238028
|
if (spaceIdx === -1) {
|
|
237952
|
-
return
|
|
238029
|
+
return "";
|
|
237953
238030
|
}
|
|
237954
238031
|
const prop = trimmed.slice(0, spaceIdx);
|
|
237955
|
-
const value = trimmed.slice(spaceIdx).trim();
|
|
238032
|
+
const value = collapseWhitespace(trimmed.slice(spaceIdx).trim());
|
|
237956
238033
|
const full = TSS_SHORTHANDS2[prop] ?? prop;
|
|
237957
238034
|
return `${full}: ${value}`;
|
|
237958
238035
|
}
|
|
@@ -238110,26 +238187,47 @@ function __twCompileTSSInner(source) {
|
|
|
238110
238187
|
if (!changed) break;
|
|
238111
238188
|
}
|
|
238112
238189
|
}
|
|
238113
|
-
const
|
|
238190
|
+
const root = [];
|
|
238114
238191
|
const stack = [];
|
|
238115
|
-
const declsByLevel = [];
|
|
238116
238192
|
let buf = "";
|
|
238117
|
-
const
|
|
238118
|
-
|
|
238119
|
-
|
|
238120
|
-
for (let i2 = wrapStack.length - 1; i2 >= 0; i2--) {
|
|
238121
|
-
if (wrapStack[i2].startsWith("@")) rule = `${wrapStack[i2]} { ${rule} }`;
|
|
238122
|
-
}
|
|
238123
|
-
rules.push(rule);
|
|
238124
|
-
};
|
|
238193
|
+
const current2 = () => stack.length ? stack[stack.length - 1] : null;
|
|
238194
|
+
const statements = [];
|
|
238195
|
+
const isStatementAtRule = (t3) => /^@(import|charset|namespace|layer)\b/.test(t3);
|
|
238125
238196
|
const pushDecl = (text) => {
|
|
238126
|
-
const
|
|
238127
|
-
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: [] });
|
|
238128
238208
|
};
|
|
238129
|
-
const isDeclLine = (l) => /^[
|
|
238209
|
+
const isDeclLine = (l) => /^(--[A-Za-z][\w-]*|-?[A-Za-z][\w-]*)(\s|:)/.test(l) && !/^[>+~]/.test(l);
|
|
238130
238210
|
let i = 0;
|
|
238211
|
+
let quote = null;
|
|
238131
238212
|
while (i < src.length) {
|
|
238132
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
|
+
}
|
|
238133
238231
|
if (ch === "{") {
|
|
238134
238232
|
let sel = buf.trim();
|
|
238135
238233
|
buf = "";
|
|
@@ -238142,53 +238240,38 @@ function __twCompileTSSInner(source) {
|
|
|
238142
238240
|
const last = lines[lines.length - 1];
|
|
238143
238241
|
const prior = lines.slice(0, -1);
|
|
238144
238242
|
const priorComplete = !/[(,]\s*$/.test(prior[prior.length - 1] ?? "");
|
|
238145
|
-
if (priorComplete && prior.every(isDeclLine)
|
|
238243
|
+
if (priorComplete && prior.every(isDeclLine)) {
|
|
238146
238244
|
for (const p of prior) pushDecl(p);
|
|
238147
238245
|
sel = last;
|
|
238148
238246
|
}
|
|
238149
238247
|
}
|
|
238150
|
-
const parent =
|
|
238151
|
-
let full;
|
|
238248
|
+
const parent = current2();
|
|
238152
238249
|
if (sel.startsWith("@")) {
|
|
238153
|
-
|
|
238154
|
-
|
|
238155
|
-
|
|
238250
|
+
const node = { kind: "at", head: sel, decls: [], children: [] };
|
|
238251
|
+
(parent ? parent.children : root).push(node);
|
|
238252
|
+
stack.push(node);
|
|
238156
238253
|
} else {
|
|
238157
|
-
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);
|
|
238158
238258
|
}
|
|
238159
|
-
stack.push(full);
|
|
238160
|
-
declsByLevel.push([]);
|
|
238161
238259
|
i++;
|
|
238162
238260
|
} else if (ch === "}") {
|
|
238163
238261
|
if (buf.trim()) {
|
|
238164
238262
|
const blines = buf.split(/\n+/).map((l) => l.trim()).filter(Boolean);
|
|
238165
|
-
|
|
238263
|
+
const valueContinues = blines.some((l) => /[(,]\s*$/.test(l));
|
|
238264
|
+
if (blines.length > 1 && !valueContinues) {
|
|
238166
238265
|
for (const l of blines) pushDecl(l);
|
|
238167
238266
|
} else {
|
|
238168
238267
|
pushDecl(buf);
|
|
238169
238268
|
}
|
|
238170
238269
|
}
|
|
238171
238270
|
buf = "";
|
|
238172
|
-
|
|
238173
|
-
const decls = declsByLevel.pop() ?? [];
|
|
238174
|
-
if (level) {
|
|
238175
|
-
if (level.startsWith("@") && decls.length > 0) {
|
|
238176
|
-
let realSel = null;
|
|
238177
|
-
for (let j = stack.length - 1; j >= 0; j--) {
|
|
238178
|
-
if (!stack[j].startsWith("@")) {
|
|
238179
|
-
realSel = stack[j];
|
|
238180
|
-
break;
|
|
238181
|
-
}
|
|
238182
|
-
}
|
|
238183
|
-
if (realSel) emit4(realSel, decls, [...stack, level]);
|
|
238184
|
-
else emit4(level, decls, stack);
|
|
238185
|
-
} else {
|
|
238186
|
-
emit4(level, decls, stack);
|
|
238187
|
-
}
|
|
238188
|
-
}
|
|
238271
|
+
stack.pop();
|
|
238189
238272
|
i++;
|
|
238190
238273
|
} else if (ch === ";") {
|
|
238191
|
-
pushDecl(buf);
|
|
238274
|
+
if (buf.trim()) pushDecl(buf);
|
|
238192
238275
|
buf = "";
|
|
238193
238276
|
i++;
|
|
238194
238277
|
} else {
|
|
@@ -238196,11 +238279,24 @@ function __twCompileTSSInner(source) {
|
|
|
238196
238279
|
i++;
|
|
238197
238280
|
}
|
|
238198
238281
|
}
|
|
238199
|
-
if (buf.trim())
|
|
238200
|
-
|
|
238201
|
-
if (
|
|
238202
|
-
|
|
238203
|
-
|
|
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");
|
|
238204
238300
|
}
|
|
238205
238301
|
var TSS_SHORTHANDS2;
|
|
238206
238302
|
var init_tss = __esm({
|
|
@@ -238244,6 +238340,12 @@ var init_tss = __esm({
|
|
|
238244
238340
|
"br-t": "border-top-left-radius",
|
|
238245
238341
|
bxsh: "box-shadow",
|
|
238246
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",
|
|
238247
238349
|
// `box` is the documented box-sizing shorthand (docs/tss-syntax.md).
|
|
238248
238350
|
box: "box-sizing",
|
|
238249
238351
|
// typography
|
|
@@ -238285,7 +238387,13 @@ var init_tss = __esm({
|
|
|
238285
238387
|
tr: "transition",
|
|
238286
238388
|
tf: "transform",
|
|
238287
238389
|
us: "user-select",
|
|
238288
|
-
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"
|
|
238289
238397
|
};
|
|
238290
238398
|
}
|
|
238291
238399
|
});
|
|
@@ -239425,7 +239533,9 @@ function generateElement(el, ctx) {
|
|
|
239425
239533
|
if (el.children.length === 0 && el.selfClosing) {
|
|
239426
239534
|
return `<${tag2}${attrPrefix}></${tag2}>`;
|
|
239427
239535
|
}
|
|
239428
|
-
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("");
|
|
239429
239539
|
return `<${tag2}${attrPrefix}>${childrenHTML}</${tag2}>`;
|
|
239430
239540
|
}
|
|
239431
239541
|
function renderAttrs(el, ctx) {
|
|
@@ -239556,10 +239666,30 @@ function wrapInterpolations(rendered, raw) {
|
|
|
239556
239666
|
}
|
|
239557
239667
|
return out;
|
|
239558
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
|
+
}
|
|
239559
239683
|
function generateText(text, ctx) {
|
|
239560
239684
|
ctx_global_interactive = ctx.interactive === true;
|
|
239561
239685
|
ctx_global_inhead = ctx.inHead === true;
|
|
239562
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
|
+
}
|
|
239563
239693
|
if (text.isInterpolated) {
|
|
239564
239694
|
if (ctx.interactive && ctx.inHead !== true) {
|
|
239565
239695
|
return `<span data-tw-i="${escapeHTML(text.value)}"${dataTwSFor(text.value)}>${escapeHTML(interpolate2(`{${text.value}}`, ctx.stateVars))}</span>`;
|
|
@@ -240860,7 +240990,7 @@ function minifyHTML2(html, options) {
|
|
|
240860
240990
|
result = removeComments(result);
|
|
240861
240991
|
}
|
|
240862
240992
|
if (opts.collapseWhitespace) {
|
|
240863
|
-
result =
|
|
240993
|
+
result = collapseWhitespace2(result);
|
|
240864
240994
|
}
|
|
240865
240995
|
if (opts.removeRedundantAttrs) {
|
|
240866
240996
|
result = removeRedundantAttrs(result);
|
|
@@ -240883,7 +241013,7 @@ function removeComments(html) {
|
|
|
240883
241013
|
if (html.indexOf("<!--") === -1) return html;
|
|
240884
241014
|
return html.replace(/<!--(?!\[if\s)[\s\S]*?-->/g, "");
|
|
240885
241015
|
}
|
|
240886
|
-
function
|
|
241016
|
+
function collapseWhitespace2(html) {
|
|
240887
241017
|
const result = [];
|
|
240888
241018
|
let pos = 0;
|
|
240889
241019
|
let inPreserved = false;
|
|
@@ -244141,7 +244271,7 @@ var init_codes = __esm({
|
|
|
244141
244271
|
TW105: { message: "Server blocks in layouts are not supported yet", severity: "error", category: "semantic" },
|
|
244142
244272
|
TW106: { message: "Request context (headers/cookies/query/params) is not available in a static server block", severity: "error", category: "semantic" },
|
|
244143
244273
|
TW107: { message: "getSession()/requireUser() are not available in a static page's server block", severity: "error", category: "semantic" },
|
|
244144
|
-
TW108: { message: "redirect()
|
|
244274
|
+
TW108: { message: "redirect() is not available in a static page's server block", severity: "error", category: "semantic" },
|
|
244145
244275
|
TW109: { message: "redirect() target must be a same-origin internal path", severity: "error", category: "semantic" },
|
|
244146
244276
|
TW110: { message: "A cached fetch must not set an Authorization, Proxy-Authorization or Cookie header", severity: "error", category: "semantic" },
|
|
244147
244277
|
TW111: { message: "A cached page's server block cannot read headers, cookies, getSession() or requireUser()", severity: "error", category: "semantic" },
|
|
@@ -244156,6 +244286,7 @@ var init_codes = __esm({
|
|
|
244156
244286
|
TW121: { message: "The same name is declared by more than one state { } block (the earlier one wins)", severity: "warning", category: "semantic" },
|
|
244157
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" },
|
|
244158
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" },
|
|
244159
244290
|
// Codes thrown outside the rule engine. TW303 comes from the stylesheet
|
|
244160
244291
|
// parser (codegen/tss.ts); TW000 is the generic fallback used when an error
|
|
244161
244292
|
// carries no code of its own.
|
|
@@ -244356,8 +244487,17 @@ function checkPerformance(program, filePath, diags) {
|
|
|
244356
244487
|
]));
|
|
244357
244488
|
}
|
|
244358
244489
|
if (isElement(node) && node.tag.toLowerCase() === "img") {
|
|
244490
|
+
const attr = (n) => node.attrs.find((a) => a.name === n)?.value;
|
|
244359
244491
|
const hasLazy = node.attrs.some((a) => a.name === "loading" && a.value === "lazy");
|
|
244360
|
-
|
|
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) {
|
|
244361
244501
|
diags.push(createDiagnostic("TW054", node.line, node.col, filePath, void 0, [
|
|
244362
244502
|
'Add loading="lazy" for below-fold images'
|
|
244363
244503
|
]));
|
|
@@ -244872,6 +245012,55 @@ var init_rules = __esm({
|
|
|
244872
245012
|
"foreignobject"
|
|
244873
245013
|
]);
|
|
244874
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",
|
|
244875
245064
|
"accept",
|
|
244876
245065
|
"accept-charset",
|
|
244877
245066
|
"accesskey",
|
|
@@ -248075,20 +248264,36 @@ var node_import_exports = {};
|
|
|
248075
248264
|
__export(node_import_exports, {
|
|
248076
248265
|
twImportTs: () => twImportTs
|
|
248077
248266
|
});
|
|
248078
|
-
import { join as join15 } from "node:path";
|
|
248267
|
+
import { join as join15, dirname as dirname9, basename as basename2, extname as extname6 } from "node:path";
|
|
248079
248268
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
248080
248269
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
248081
|
-
|
|
248270
|
+
import { writeFileSync as writeFileSync5, rmSync as rmSync2 } from "node:fs";
|
|
248271
|
+
async function twImportTs(tsPath, bust, opts) {
|
|
248082
248272
|
const q = bust ? "?v=" + bust : "";
|
|
248273
|
+
const override = opts?.source;
|
|
248083
248274
|
if (!globalThis.__TW_NODE) {
|
|
248084
|
-
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
|
+
}
|
|
248085
248288
|
}
|
|
248086
248289
|
const esbuildMain = globalThis.__TW_ESBUILD_MODULE;
|
|
248087
248290
|
const esbuild = await (esbuildMain ? import(esbuildMain) : import("esbuild"));
|
|
248088
248291
|
const safe = tsPath.replace(/[^a-zA-Z0-9]/g, "_").slice(-120);
|
|
248089
248292
|
const cachePath = join15(tmpdir2(), "tw-" + safe + (bust ? "-" + bust : "") + ".mjs");
|
|
248090
248293
|
await esbuild.build({
|
|
248091
|
-
|
|
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" } },
|
|
248092
248297
|
bundle: true,
|
|
248093
248298
|
format: "esm",
|
|
248094
248299
|
platform: "node",
|
|
@@ -248098,12 +248303,15 @@ async function twImportTs(tsPath, bust) {
|
|
|
248098
248303
|
});
|
|
248099
248304
|
return import(pathToFileURL2(cachePath).href + q);
|
|
248100
248305
|
}
|
|
248306
|
+
var overrideSeq;
|
|
248101
248307
|
var init_node_import = __esm({
|
|
248102
248308
|
"../../packages/shared/tw/node-import.ts"() {
|
|
248309
|
+
overrideSeq = 0;
|
|
248103
248310
|
}
|
|
248104
248311
|
});
|
|
248105
248312
|
|
|
248106
248313
|
// ../../packages/compiler/tw/server-blocks/index.ts
|
|
248314
|
+
import { readFileSync as readFileSync8, existsSync as existsSync11 } from "node:fs";
|
|
248107
248315
|
function encodeServerValue(v) {
|
|
248108
248316
|
if (v === void 0) return "";
|
|
248109
248317
|
if (v === null) return "null";
|
|
@@ -248360,41 +248568,45 @@ function withTimeout2(p, ms, label) {
|
|
|
248360
248568
|
});
|
|
248361
248569
|
});
|
|
248362
248570
|
}
|
|
248363
|
-
function
|
|
248364
|
-
const
|
|
248365
|
-
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();
|
|
248366
248574
|
const fromIdx = s.lastIndexOf(" from ");
|
|
248367
|
-
if (fromIdx < 0) return
|
|
248575
|
+
if (fromIdx < 0) return out;
|
|
248368
248576
|
const clause = s.slice(0, fromIdx).trim();
|
|
248369
|
-
if (clause.startsWith("{")) {
|
|
248370
|
-
|
|
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(",")) {
|
|
248371
248586
|
const t3 = part.trim();
|
|
248372
248587
|
if (!t3) continue;
|
|
248373
|
-
const
|
|
248374
|
-
|
|
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" });
|
|
248375
248592
|
}
|
|
248376
|
-
} else if (clause.startsWith("*")) {
|
|
248377
|
-
const as = clause.split(/\s+as\s+/);
|
|
248378
|
-
if (as[1]) names.push(as[1].trim());
|
|
248379
|
-
} else {
|
|
248380
|
-
const first = clause.split(",")[0].trim();
|
|
248381
|
-
if (first && /^[A-Za-z_$]/.test(first)) names.push(first);
|
|
248382
248593
|
}
|
|
248383
|
-
return
|
|
248594
|
+
return out;
|
|
248384
248595
|
}
|
|
248385
248596
|
async function resolveServerImports(block, pageFile, opts = {}) {
|
|
248386
248597
|
if (!block.imports.length) return {};
|
|
248387
248598
|
const out = {};
|
|
248388
248599
|
const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
248389
|
-
const { dirname:
|
|
248600
|
+
const { dirname: dirname18, resolve: resolve12 } = await import("node:path");
|
|
248390
248601
|
const { statSync: statSync13 } = await import("node:fs");
|
|
248391
248602
|
for (const imp of block.imports) {
|
|
248392
248603
|
if (!imp.specifier) continue;
|
|
248393
248604
|
const spec = imp.specifier;
|
|
248605
|
+
if (spec === "@tw/server-only" || spec === "@tw/client-safe") continue;
|
|
248394
248606
|
let mod;
|
|
248395
248607
|
if (spec.startsWith("./") || spec.startsWith("../") || spec.startsWith("@./")) {
|
|
248396
248608
|
const rel = spec.startsWith("@./") ? spec.slice(2) : spec;
|
|
248397
|
-
const abs = resolve12(
|
|
248609
|
+
const abs = resolve12(dirname18(pageFile), rel);
|
|
248398
248610
|
let bust;
|
|
248399
248611
|
if (opts.dev) {
|
|
248400
248612
|
try {
|
|
@@ -248402,12 +248614,49 @@ async function resolveServerImports(block, pageFile, opts = {}) {
|
|
|
248402
248614
|
} catch {
|
|
248403
248615
|
}
|
|
248404
248616
|
}
|
|
248405
|
-
|
|
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 });
|
|
248406
248636
|
} else {
|
|
248407
248637
|
mod = await import(spec);
|
|
248408
248638
|
}
|
|
248409
|
-
const
|
|
248410
|
-
|
|
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
|
+
}
|
|
248411
248660
|
}
|
|
248412
248661
|
return out;
|
|
248413
248662
|
}
|
|
@@ -248446,7 +248695,7 @@ function checkServerBlocks(program, opts = {}) {
|
|
|
248446
248695
|
}
|
|
248447
248696
|
const calls = scanRuntimeCalls(b.source);
|
|
248448
248697
|
if (calls.getSession || calls.requireUser) push("TW107", "getSession()/requireUser() are not available in a static page's server block", b.line, b.col);
|
|
248449
|
-
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);
|
|
248450
248699
|
}
|
|
248451
248700
|
}
|
|
248452
248701
|
for (const b of blocks) {
|
|
@@ -248597,7 +248846,7 @@ function parsePageCache(source) {
|
|
|
248597
248846
|
const rv = revalidate ?? 60;
|
|
248598
248847
|
return { revalidate: rv, expire: expire ?? rv, tag: tagM ? tagM[1] : void 0 };
|
|
248599
248848
|
}
|
|
248600
|
-
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;
|
|
248601
248850
|
var init_server_blocks = __esm({
|
|
248602
248851
|
"../../packages/compiler/tw/server-blocks/index.ts"() {
|
|
248603
248852
|
init_codes();
|
|
@@ -248624,6 +248873,19 @@ var init_server_blocks = __esm({
|
|
|
248624
248873
|
isServerRedirect = (e) => !!(e && e[SERVER_REDIRECT_BRAND]);
|
|
248625
248874
|
isServerNotFound = (e) => !!(e && e[SERVER_NOT_FOUND_BRAND]);
|
|
248626
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
|
+
];
|
|
248627
248889
|
}
|
|
248628
248890
|
});
|
|
248629
248891
|
|
|
@@ -250079,8 +250341,8 @@ var init_memory = __esm({
|
|
|
250079
250341
|
});
|
|
250080
250342
|
|
|
250081
250343
|
// ../../packages/compiler/tw/cache/disk.ts
|
|
250082
|
-
import { existsSync as
|
|
250083
|
-
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";
|
|
250084
250346
|
var DiskCache;
|
|
250085
250347
|
var init_disk = __esm({
|
|
250086
250348
|
"../../packages/compiler/tw/cache/disk.ts"() {
|
|
@@ -250088,15 +250350,15 @@ var init_disk = __esm({
|
|
|
250088
250350
|
DiskCache = class {
|
|
250089
250351
|
constructor(cacheDir) {
|
|
250090
250352
|
this.cacheDir = cacheDir;
|
|
250091
|
-
if (!
|
|
250353
|
+
if (!existsSync12(cacheDir)) {
|
|
250092
250354
|
mkdirSync4(cacheDir, { recursive: true });
|
|
250093
250355
|
}
|
|
250094
250356
|
}
|
|
250095
250357
|
get(key2) {
|
|
250096
250358
|
const path = this.keyToPath(key2);
|
|
250097
|
-
if (!
|
|
250359
|
+
if (!existsSync12(path)) return null;
|
|
250098
250360
|
try {
|
|
250099
|
-
const data = JSON.parse(
|
|
250361
|
+
const data = JSON.parse(readFileSync9(path, "utf-8"));
|
|
250100
250362
|
return data.value;
|
|
250101
250363
|
} catch {
|
|
250102
250364
|
return null;
|
|
@@ -250104,12 +250366,12 @@ var init_disk = __esm({
|
|
|
250104
250366
|
}
|
|
250105
250367
|
set(key2, value, hash3) {
|
|
250106
250368
|
const path = this.keyToPath(key2);
|
|
250107
|
-
mkdirSync4(
|
|
250369
|
+
mkdirSync4(dirname10(path), { recursive: true });
|
|
250108
250370
|
const entry = { key: key2, value, hash: hash3, createdAt: Date.now() };
|
|
250109
|
-
|
|
250371
|
+
writeFileSync6(path, JSON.stringify(entry));
|
|
250110
250372
|
}
|
|
250111
250373
|
has(key2) {
|
|
250112
|
-
return
|
|
250374
|
+
return existsSync12(this.keyToPath(key2));
|
|
250113
250375
|
}
|
|
250114
250376
|
delete(key2) {
|
|
250115
250377
|
const path = this.keyToPath(key2);
|
|
@@ -250605,7 +250867,7 @@ var init_incremental = __esm({
|
|
|
250605
250867
|
|
|
250606
250868
|
// ../../packages/compiler/tw/native/child-process.ts
|
|
250607
250869
|
import { spawn } from "node:child_process";
|
|
250608
|
-
import { existsSync as
|
|
250870
|
+
import { existsSync as existsSync13 } from "node:fs";
|
|
250609
250871
|
import { join as join17 } from "node:path";
|
|
250610
250872
|
function safeJsonParse3(json2, fallback) {
|
|
250611
250873
|
try {
|
|
@@ -250633,7 +250895,7 @@ function findRustBinary() {
|
|
|
250633
250895
|
}
|
|
250634
250896
|
for (const candidate of candidates) {
|
|
250635
250897
|
if (candidate.includes("/") || candidate.includes("\\")) {
|
|
250636
|
-
if (
|
|
250898
|
+
if (existsSync13(candidate)) {
|
|
250637
250899
|
cachedBinaryPath = candidate;
|
|
250638
250900
|
return candidate;
|
|
250639
250901
|
}
|
|
@@ -255251,6 +255513,7 @@ __export(tw_exports3, {
|
|
|
255251
255513
|
PropParser: () => PropParser,
|
|
255252
255514
|
RENDER_MODE_ALIASES: () => RENDER_MODE_ALIASES,
|
|
255253
255515
|
RENDER_MODE_NAMES: () => RENDER_MODE_NAMES,
|
|
255516
|
+
RESERVED_BLOCK_BINDINGS: () => RESERVED_BLOCK_BINDINGS,
|
|
255254
255517
|
RESERVED_WORDS: () => RESERVED_WORDS,
|
|
255255
255518
|
RuleEngine: () => RuleEngine,
|
|
255256
255519
|
RulesEngine: () => RulesEngine,
|
|
@@ -255894,6 +256157,7 @@ __export(tw_exports3, {
|
|
|
255894
256157
|
secretEnvValues: () => secretEnvValues,
|
|
255895
256158
|
separateByType: () => separateByType,
|
|
255896
256159
|
serializeCache: () => serializeCache,
|
|
256160
|
+
serverImportCollisions: () => serverImportCollisions,
|
|
255897
256161
|
serverRouteParamCollisions: () => serverRouteParamCollisions,
|
|
255898
256162
|
serverStateCollisions: () => serverStateCollisions,
|
|
255899
256163
|
setBackend: () => setBackend,
|
|
@@ -256252,7 +256516,7 @@ __export(client_bundle_exports, {
|
|
|
256252
256516
|
setClientOutputRoot: () => setClientOutputRoot
|
|
256253
256517
|
});
|
|
256254
256518
|
import { join as join18, resolve as resolve4 } from "node:path";
|
|
256255
|
-
import { existsSync as
|
|
256519
|
+
import { existsSync as existsSync14, readFileSync as readFileSync10, writeFileSync as writeFileSync7, mkdirSync as mkdirSync5, unlinkSync as unlinkSync2 } from "node:fs";
|
|
256256
256520
|
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
256257
256521
|
function isClientImportSpecifier(spec) {
|
|
256258
256522
|
if (spec.startsWith("@./") || spec.startsWith("./") || spec.startsWith("../")) return false;
|
|
@@ -256304,7 +256568,7 @@ function findEsbuildBin(rootDir) {
|
|
|
256304
256568
|
];
|
|
256305
256569
|
for (const c of candidates) {
|
|
256306
256570
|
try {
|
|
256307
|
-
if (
|
|
256571
|
+
if (existsSync14(c)) return c;
|
|
256308
256572
|
} catch {
|
|
256309
256573
|
}
|
|
256310
256574
|
}
|
|
@@ -256312,7 +256576,7 @@ function findEsbuildBin(rootDir) {
|
|
|
256312
256576
|
if (bd) {
|
|
256313
256577
|
const b = resolve4(bd, "..", "..", "..", "node_modules", ".bin", "esbuild");
|
|
256314
256578
|
try {
|
|
256315
|
-
if (
|
|
256579
|
+
if (existsSync14(b)) return b;
|
|
256316
256580
|
} catch {
|
|
256317
256581
|
}
|
|
256318
256582
|
}
|
|
@@ -256366,9 +256630,9 @@ function getClientOutputRoot() {
|
|
|
256366
256630
|
}
|
|
256367
256631
|
function vendoredRuntimeClient() {
|
|
256368
256632
|
const fromSrc = new URL("../../dist/tw-runtime-client.mjs", import.meta.url).pathname;
|
|
256369
|
-
if (
|
|
256633
|
+
if (existsSync14(fromSrc)) return fromSrc;
|
|
256370
256634
|
const fromBundle = new URL("./tw-runtime-client.mjs", import.meta.url).pathname;
|
|
256371
|
-
if (
|
|
256635
|
+
if (existsSync14(fromBundle)) return fromBundle;
|
|
256372
256636
|
return null;
|
|
256373
256637
|
}
|
|
256374
256638
|
function rewriteRuntimeSpecifier(importLine) {
|
|
@@ -256385,10 +256649,10 @@ function minifyJsSource(rootDir, source, target = "es2019") {
|
|
|
256385
256649
|
const outPath = join18(rootDir, OUT_ROOT, ".min-out-" + stamp + ".js");
|
|
256386
256650
|
try {
|
|
256387
256651
|
mkdirSync5(join18(rootDir, OUT_ROOT), { recursive: true });
|
|
256388
|
-
|
|
256652
|
+
writeFileSync7(inPath, source);
|
|
256389
256653
|
const r = spawnSync4(bin, [inPath, "--minify", "--target=" + (target || "es2019"), "--format=iife", "--outfile=" + outPath], { cwd: rootDir });
|
|
256390
256654
|
if (r.status !== 0) return source;
|
|
256391
|
-
const out =
|
|
256655
|
+
const out = readFileSync10(outPath, "utf-8");
|
|
256392
256656
|
return out || source;
|
|
256393
256657
|
} catch {
|
|
256394
256658
|
return source;
|
|
@@ -256419,7 +256683,7 @@ function esbuildTargetFor(target) {
|
|
|
256419
256683
|
}
|
|
256420
256684
|
function buildEntryPoint(rootDir, entry, flags = {}) {
|
|
256421
256685
|
const abs = join18(rootDir, entry);
|
|
256422
|
-
if (!
|
|
256686
|
+
if (!existsSync14(abs)) return "";
|
|
256423
256687
|
const jsDir = join18(rootDir, OUT_ROOT, "js");
|
|
256424
256688
|
mkdirSync5(jsDir, { recursive: true });
|
|
256425
256689
|
const stamp = contentHash2(entry);
|
|
@@ -256435,9 +256699,9 @@ function buildEntryPoint(rootDir, entry, flags = {}) {
|
|
|
256435
256699
|
}
|
|
256436
256700
|
return "";
|
|
256437
256701
|
}
|
|
256438
|
-
const code =
|
|
256702
|
+
const code = readFileSync10(tmpOut, "utf-8");
|
|
256439
256703
|
const url = "js/e-" + contentHash2(code) + ".js";
|
|
256440
|
-
|
|
256704
|
+
writeFileSync7(join18(rootDir, OUT_ROOT, url), code);
|
|
256441
256705
|
try {
|
|
256442
256706
|
unlinkSync2(tmpOut);
|
|
256443
256707
|
} catch {
|
|
@@ -256465,7 +256729,7 @@ function buildClientChunk(rootDir, importLine, flagsOrMinify = true, sourcemap =
|
|
|
256465
256729
|
const flags = typeof flagsOrMinify === "boolean" ? { minify: flagsOrMinify, sourcemap } : flagsOrMinify;
|
|
256466
256730
|
const key2 = importLine + "|" + JSON.stringify(flags);
|
|
256467
256731
|
const cached2 = chunkCache.get(key2);
|
|
256468
|
-
if (cached2 &&
|
|
256732
|
+
if (cached2 && existsSync14(join18(rootDir, OUT_ROOT, cached2))) return cached2;
|
|
256469
256733
|
const jsDir = join18(rootDir, OUT_ROOT, "js");
|
|
256470
256734
|
mkdirSync5(jsDir, { recursive: true });
|
|
256471
256735
|
const names = importNames(importLine);
|
|
@@ -256478,7 +256742,7 @@ function buildClientChunk(rootDir, importLine, flagsOrMinify = true, sourcemap =
|
|
|
256478
256742
|
const stamp = contentHash2(importLine);
|
|
256479
256743
|
const entryPath = join18(rootDir, OUT_ROOT, ".chunk-entry-" + stamp + ".js");
|
|
256480
256744
|
const tmpOut = join18(rootDir, OUT_ROOT, ".chunk-tmp-" + stamp + ".js");
|
|
256481
|
-
|
|
256745
|
+
writeFileSync7(entryPath, entry);
|
|
256482
256746
|
const bin = findEsbuildBin(rootDir);
|
|
256483
256747
|
const args = [entryPath, ...chunkEsbuildArgs(flags, tmpOut)];
|
|
256484
256748
|
const r = spawnSync4(bin, args, { cwd: rootDir });
|
|
@@ -256495,9 +256759,9 @@ function buildClientChunk(rootDir, importLine, flagsOrMinify = true, sourcemap =
|
|
|
256495
256759
|
}
|
|
256496
256760
|
return "";
|
|
256497
256761
|
}
|
|
256498
|
-
const code =
|
|
256762
|
+
const code = readFileSync10(tmpOut, "utf-8");
|
|
256499
256763
|
const url = "js/c-" + contentHash2(code) + ".js";
|
|
256500
|
-
|
|
256764
|
+
writeFileSync7(join18(rootDir, OUT_ROOT, url), code);
|
|
256501
256765
|
try {
|
|
256502
256766
|
unlinkSync2(tmpOut);
|
|
256503
256767
|
} catch {
|
|
@@ -256513,7 +256777,7 @@ function buildPageScope(rootDir, ownImportLines) {
|
|
|
256513
256777
|
const body = names.map((n) => "p." + n + " = g.__twClient." + n + ";").join("\n");
|
|
256514
256778
|
const code = "(function(g){g.__twClient=g.__twClient||{};var p={};\n" + body + "\ng.__twClient.$page=p;})(globalThis);\n";
|
|
256515
256779
|
const url = "js/p-" + contentHash2(names.slice().sort().join("|")) + ".js";
|
|
256516
|
-
|
|
256780
|
+
writeFileSync7(join18(rootDir, OUT_ROOT, url), code);
|
|
256517
256781
|
return url;
|
|
256518
256782
|
}
|
|
256519
256783
|
var IMPORT_RE, BUILTIN_CLIENT_OK_SPECIFIERS, RUNTIME_CLIENT_OK_SPECIFIERS, chunkCache, OUT_ROOT;
|
|
@@ -256528,7 +256792,7 @@ var init_client_bundle = __esm({
|
|
|
256528
256792
|
});
|
|
256529
256793
|
|
|
256530
256794
|
// ../../packages/plugins/tw/resolve.ts
|
|
256531
|
-
import { existsSync as
|
|
256795
|
+
import { existsSync as existsSync15, readFileSync as readFileSync11 } from "node:fs";
|
|
256532
256796
|
import { join as join19 } from "node:path";
|
|
256533
256797
|
function isExplicitPath(spec) {
|
|
256534
256798
|
return spec.startsWith(".") || spec.startsWith("/");
|
|
@@ -256558,9 +256822,9 @@ function resolvePackageFile(spec, rootDir) {
|
|
|
256558
256822
|
function readPackageManifest(packageName2, rootDir) {
|
|
256559
256823
|
const dir = join19(rootDir, "node_modules", ...packageName2.split("/"));
|
|
256560
256824
|
const pj = join19(dir, "package.json");
|
|
256561
|
-
if (!
|
|
256825
|
+
if (!existsSync15(pj)) return null;
|
|
256562
256826
|
try {
|
|
256563
|
-
return JSON.parse(
|
|
256827
|
+
return JSON.parse(readFileSync11(pj, "utf-8"));
|
|
256564
256828
|
} catch {
|
|
256565
256829
|
return null;
|
|
256566
256830
|
}
|
|
@@ -256576,12 +256840,12 @@ function resolvePlugin(spec, rootDir) {
|
|
|
256576
256840
|
if (isExplicitPath(spec)) {
|
|
256577
256841
|
const base = join19(rootDir, spec);
|
|
256578
256842
|
for (const candidate of [base, base + ".ts", join19(base, "index.ts")]) {
|
|
256579
|
-
if (
|
|
256843
|
+
if (existsSync15(candidate)) return { spec, kind: "path", file: candidate };
|
|
256580
256844
|
}
|
|
256581
256845
|
return { spec, kind: "path", error: `path not found: ${spec}` };
|
|
256582
256846
|
}
|
|
256583
256847
|
const local = join19(rootDir, "plugins", spec + ".ts");
|
|
256584
|
-
if (
|
|
256848
|
+
if (existsSync15(local)) return { spec, kind: "local", file: local };
|
|
256585
256849
|
const file = resolvePackageFile(spec, rootDir);
|
|
256586
256850
|
if (file) {
|
|
256587
256851
|
const manifest = readPackageManifest(spec, rootDir);
|
|
@@ -257047,7 +257311,7 @@ var init_hooks = __esm({
|
|
|
257047
257311
|
});
|
|
257048
257312
|
|
|
257049
257313
|
// ../../packages/plugins/tw/upgrade.ts
|
|
257050
|
-
import { existsSync as
|
|
257314
|
+
import { existsSync as existsSync16, readFileSync as readFileSync12 } from "node:fs";
|
|
257051
257315
|
import { join as join20 } from "node:path";
|
|
257052
257316
|
function extractPluginsArray(source) {
|
|
257053
257317
|
const at = /plugins\s*:\s*\[/.exec(source);
|
|
@@ -257168,9 +257432,9 @@ function looksLikeSpec(value) {
|
|
|
257168
257432
|
}
|
|
257169
257433
|
function installedVersion(pkg, rootDir) {
|
|
257170
257434
|
const pj = join20(rootDir, "node_modules", ...pkg.split("/"), "package.json");
|
|
257171
|
-
if (!
|
|
257435
|
+
if (!existsSync16(pj)) return null;
|
|
257172
257436
|
try {
|
|
257173
|
-
return JSON.parse(
|
|
257437
|
+
return JSON.parse(readFileSync12(pj, "utf-8")).version ?? null;
|
|
257174
257438
|
} catch {
|
|
257175
257439
|
return null;
|
|
257176
257440
|
}
|
|
@@ -257279,8 +257543,8 @@ __export(tw_exports4, {
|
|
|
257279
257543
|
resolvePlugin: () => resolvePlugin,
|
|
257280
257544
|
splitTopLevel: () => splitTopLevel
|
|
257281
257545
|
});
|
|
257282
|
-
import { existsSync as
|
|
257283
|
-
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";
|
|
257284
257548
|
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
257285
257549
|
async function loadPlugins(rootDir, config, logger) {
|
|
257286
257550
|
const manager = new PluginManager(config, logger);
|
|
@@ -257292,7 +257556,7 @@ async function loadPlugins(rootDir, config, logger) {
|
|
|
257292
257556
|
if (typeof entry === "string") specs.push(entry);
|
|
257293
257557
|
else if (entry && typeof entry === "object" && typeof entry.name === "string") specs.push(entry.name);
|
|
257294
257558
|
}
|
|
257295
|
-
} else if (
|
|
257559
|
+
} else if (existsSync17(pluginsDir)) {
|
|
257296
257560
|
for (const file of readdirSync5(pluginsDir)) {
|
|
257297
257561
|
if (/\.ts$/.test(file) && !file.endsWith(".d.ts")) specs.push(file.replace(/\.ts$/, ""));
|
|
257298
257562
|
}
|
|
@@ -257478,10 +257742,10 @@ var init_tw8 = __esm({
|
|
|
257478
257742
|
}
|
|
257479
257743
|
// Load plugins from a directory
|
|
257480
257744
|
async loadFromDir(pluginsDir) {
|
|
257481
|
-
if (!
|
|
257745
|
+
if (!existsSync17(pluginsDir)) return;
|
|
257482
257746
|
const entries = readdirSync5(pluginsDir);
|
|
257483
257747
|
for (const entry of entries) {
|
|
257484
|
-
const ext =
|
|
257748
|
+
const ext = extname7(entry).toLowerCase();
|
|
257485
257749
|
if (![".ts", ".js", ".mjs"].includes(ext)) continue;
|
|
257486
257750
|
const filePath = join21(pluginsDir, entry);
|
|
257487
257751
|
try {
|
|
@@ -257607,13 +257871,13 @@ __export(island_bundle_exports, {
|
|
|
257607
257871
|
resolveForeignPath: () => resolveForeignPath,
|
|
257608
257872
|
scanForeignImports: () => scanForeignImports
|
|
257609
257873
|
});
|
|
257610
|
-
import { existsSync as
|
|
257611
|
-
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";
|
|
257612
257876
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
257613
257877
|
import { createHash as createHash4 } from "node:crypto";
|
|
257614
257878
|
import { pathToFileURL as pathToFileURL4 } from "node:url";
|
|
257615
257879
|
function collectTwFiles(dir, out = []) {
|
|
257616
|
-
if (!
|
|
257880
|
+
if (!existsSync18(dir)) return out;
|
|
257617
257881
|
for (const entry of readdirSync6(dir)) {
|
|
257618
257882
|
if (SKIP_DIRS.has(entry)) continue;
|
|
257619
257883
|
const full = join22(dir, entry);
|
|
@@ -257626,12 +257890,12 @@ function collectTwFiles(dir, out = []) {
|
|
|
257626
257890
|
function resolveForeignPath(fromFile, specifier, rootDir) {
|
|
257627
257891
|
const rel = specifier.replace(/^@/, "").replace(/^\.?\//, "");
|
|
257628
257892
|
const direct = join22(rootDir, rel);
|
|
257629
|
-
if (
|
|
257630
|
-
let dir =
|
|
257893
|
+
if (existsSync18(direct)) return direct;
|
|
257894
|
+
let dir = dirname11(fromFile);
|
|
257631
257895
|
for (let i = 0; i < 12; i++) {
|
|
257632
257896
|
const candidate = join22(dir, rel);
|
|
257633
|
-
if (
|
|
257634
|
-
const parent =
|
|
257897
|
+
if (existsSync18(candidate)) return candidate;
|
|
257898
|
+
const parent = dirname11(dir);
|
|
257635
257899
|
if (parent === dir || !parent.startsWith(rootDir)) break;
|
|
257636
257900
|
dir = parent;
|
|
257637
257901
|
}
|
|
@@ -257642,7 +257906,7 @@ function scanForeignImports(rootDir, twFiles) {
|
|
|
257642
257906
|
for (const file of twFiles) {
|
|
257643
257907
|
let src = "";
|
|
257644
257908
|
try {
|
|
257645
|
-
src =
|
|
257909
|
+
src = readFileSync13(file, "utf-8");
|
|
257646
257910
|
} catch {
|
|
257647
257911
|
continue;
|
|
257648
257912
|
}
|
|
@@ -257668,7 +257932,7 @@ function findEsbuildBin2(rootDir) {
|
|
|
257668
257932
|
resolve5(rootDir, "..", "node_modules", ".bin", "esbuild"),
|
|
257669
257933
|
resolve5(new URL(".", import.meta.url).pathname, "..", "..", "..", "..", "node_modules", ".bin", "esbuild")
|
|
257670
257934
|
];
|
|
257671
|
-
for (const c of candidates) if (
|
|
257935
|
+
for (const c of candidates) if (existsSync18(c)) return c;
|
|
257672
257936
|
return "esbuild";
|
|
257673
257937
|
}
|
|
257674
257938
|
function runEsbuild(rootDir, entryPath, outFile, extra) {
|
|
@@ -257790,13 +258054,13 @@ async function loadSsrRenderer(rootDir, absPath, engine = "preact") {
|
|
|
257790
258054
|
mkdirSync6(dir, { recursive: true });
|
|
257791
258055
|
let contentHash3 = "";
|
|
257792
258056
|
try {
|
|
257793
|
-
contentHash3 = hash2(
|
|
258057
|
+
contentHash3 = hash2(readFileSync13(absPath, "utf-8"));
|
|
257794
258058
|
} catch {
|
|
257795
258059
|
}
|
|
257796
258060
|
const stamp = hash2(absPath + ":" + engine + ":" + contentHash3);
|
|
257797
258061
|
const entryPath = join22(dir, "entry-" + stamp + ".mjs");
|
|
257798
258062
|
const outFile = join22(dir, "ssr-" + stamp + ".mjs");
|
|
257799
|
-
|
|
258063
|
+
writeFileSync8(entryPath, entry.ssr(absPath));
|
|
257800
258064
|
const res = runEsbuild(rootDir, entryPath, outFile, ["--format=esm", "--platform=node", "--target=node18", "--log-level=error", ...entry.jsxArgs]);
|
|
257801
258065
|
try {
|
|
257802
258066
|
unlinkSync3(entryPath);
|
|
@@ -257813,17 +258077,17 @@ function buildIslandChunk(rootDir, absPath, name, minify, engine = "preact", str
|
|
|
257813
258077
|
const stamp = hash2(absPath + ":" + name + ":" + engine + ":" + strategy);
|
|
257814
258078
|
const entryPath = join22(dir, "entry-" + stamp + ".mjs");
|
|
257815
258079
|
const outFile = join22(dir, "out-" + stamp + ".js");
|
|
257816
|
-
|
|
258080
|
+
writeFileSync8(entryPath, entry.hydrate(absPath, name, strategy));
|
|
257817
258081
|
const res = runEsbuild(rootDir, entryPath, outFile, ["--format=iife", "--target=es2019", "--log-level=error", ...entry.jsxArgs, ...minify ? ["--minify"] : []]);
|
|
257818
258082
|
try {
|
|
257819
258083
|
unlinkSync3(entryPath);
|
|
257820
258084
|
} catch {
|
|
257821
258085
|
}
|
|
257822
258086
|
if (!res.ok) throw new Error("esbuild (island) failed: " + res.err);
|
|
257823
|
-
const code =
|
|
258087
|
+
const code = readFileSync13(outFile, "utf-8");
|
|
257824
258088
|
const url = "js/island-" + hash2(code) + ".js";
|
|
257825
258089
|
mkdirSync6(join22(rootDir, ".tw", "js"), { recursive: true });
|
|
257826
|
-
|
|
258090
|
+
writeFileSync8(join22(rootDir, ".tw", url), code);
|
|
257827
258091
|
try {
|
|
257828
258092
|
unlinkSync3(outFile);
|
|
257829
258093
|
} catch {
|
|
@@ -257834,7 +258098,7 @@ function pruneIslandCache(rootDir) {
|
|
|
257834
258098
|
let removed = 0;
|
|
257835
258099
|
for (const name of [".island-ssr", ".island"]) {
|
|
257836
258100
|
const dir = join22(rootDir, ".tw", name);
|
|
257837
|
-
if (!
|
|
258101
|
+
if (!existsSync18(dir)) continue;
|
|
257838
258102
|
for (const entry of readdirSync6(dir)) {
|
|
257839
258103
|
try {
|
|
257840
258104
|
unlinkSync3(join22(dir, entry));
|
|
@@ -259177,10 +259441,10 @@ var init_layout_chain = __esm({
|
|
|
259177
259441
|
});
|
|
259178
259442
|
|
|
259179
259443
|
// ../../packages/server/tw/routing/scanner.ts
|
|
259180
|
-
import { existsSync as
|
|
259181
|
-
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";
|
|
259182
259446
|
function scanRouteTree(opts) {
|
|
259183
|
-
if (!
|
|
259447
|
+
if (!existsSync19(opts.homeDir)) return null;
|
|
259184
259448
|
const root = {
|
|
259185
259449
|
segment: "",
|
|
259186
259450
|
relativePath: "",
|
|
@@ -259205,7 +259469,7 @@ function scanDirectory(dirPath, urlPath, groups, parentNode, opts) {
|
|
|
259205
259469
|
}
|
|
259206
259470
|
for (const entry of entries) {
|
|
259207
259471
|
const fullPath = join23(dirPath, entry);
|
|
259208
|
-
const ext =
|
|
259472
|
+
const ext = extname8(entry);
|
|
259209
259473
|
if (!ROUTE_EXTENSIONS.has(ext)) continue;
|
|
259210
259474
|
let stat;
|
|
259211
259475
|
try {
|
|
@@ -259214,7 +259478,7 @@ function scanDirectory(dirPath, urlPath, groups, parentNode, opts) {
|
|
|
259214
259478
|
continue;
|
|
259215
259479
|
}
|
|
259216
259480
|
if (!stat.isFile()) continue;
|
|
259217
|
-
const baseName =
|
|
259481
|
+
const baseName = basename3(entry, ext);
|
|
259218
259482
|
const fileType = getRouteFileType(baseName);
|
|
259219
259483
|
if (fileType === null) {
|
|
259220
259484
|
continue;
|
|
@@ -259588,8 +259852,8 @@ var init_helpers = __esm({
|
|
|
259588
259852
|
});
|
|
259589
259853
|
|
|
259590
259854
|
// ../../packages/server/tw/routing/render-pipeline.ts
|
|
259591
|
-
import { readFileSync as
|
|
259592
|
-
import { dirname as
|
|
259855
|
+
import { readFileSync as readFileSync14, existsSync as existsSync20 } from "node:fs";
|
|
259856
|
+
import { dirname as dirname12 } from "node:path";
|
|
259593
259857
|
function getCacheProfiles(rootDir) {
|
|
259594
259858
|
if (__profilesCache && __profilesCache.rootDir === rootDir) return __profilesCache.profiles;
|
|
259595
259859
|
let profiles = {};
|
|
@@ -259627,8 +259891,8 @@ var init_render_pipeline = __esm({
|
|
|
259627
259891
|
*/
|
|
259628
259892
|
async isUnenumeratedParam(pageFile, params) {
|
|
259629
259893
|
if (!/\[[^\]]+\]/.test(pageFile)) return false;
|
|
259630
|
-
const paramsTwm =
|
|
259631
|
-
if (!
|
|
259894
|
+
const paramsTwm = dirname12(pageFile) + "/params.twm";
|
|
259895
|
+
if (!existsSync20(paramsTwm)) return false;
|
|
259632
259896
|
try {
|
|
259633
259897
|
const { loadTWMModule: loadTWMModule2 } = await Promise.resolve().then(() => (init_twm_loader(), twm_loader_exports));
|
|
259634
259898
|
const pmod = await loadTWMModule2(paramsTwm, this.rootDir);
|
|
@@ -259719,10 +259983,10 @@ var init_render_pipeline = __esm({
|
|
|
259719
259983
|
/** Read a route file, memoised outside dev. See `sourceCache`. */
|
|
259720
259984
|
readSource(file) {
|
|
259721
259985
|
const key2 = file.absolutePath;
|
|
259722
|
-
if (this.dev) return
|
|
259986
|
+
if (this.dev) return readFileSync14(key2, "utf-8");
|
|
259723
259987
|
const hit = this.sourceCache.get(key2);
|
|
259724
259988
|
if (hit !== void 0) return hit;
|
|
259725
|
-
const src =
|
|
259989
|
+
const src = readFileSync14(key2, "utf-8");
|
|
259726
259990
|
this.sourceCache.set(key2, src);
|
|
259727
259991
|
return src;
|
|
259728
259992
|
}
|
|
@@ -260182,9 +260446,9 @@ ${bodyHTML}`;
|
|
|
260182
260446
|
try {
|
|
260183
260447
|
const headCandidates = [];
|
|
260184
260448
|
const globalHead = join24(this.rootDir, "home", "head.tw");
|
|
260185
|
-
if (
|
|
260186
|
-
const siblingHead = join24(
|
|
260187
|
-
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);
|
|
260188
260452
|
for (const hp of headCandidates) {
|
|
260189
260453
|
const headCompiled = this.compileFile({ absolutePath: hp, type: "head" });
|
|
260190
260454
|
const m = headCompiled.html.match(/<body>([\s\S]*)<\/body>/);
|
|
@@ -260318,7 +260582,7 @@ ${bodyHTML}`;
|
|
|
260318
260582
|
}
|
|
260319
260583
|
};
|
|
260320
260584
|
}
|
|
260321
|
-
if (!
|
|
260585
|
+
if (!existsSync20(file.absolutePath)) {
|
|
260322
260586
|
throw new Error(`Route file not found: ${file.absolutePath}`);
|
|
260323
260587
|
}
|
|
260324
260588
|
const source = this.readSource(file);
|
|
@@ -260712,7 +260976,7 @@ ${devScript}
|
|
|
260712
260976
|
*/
|
|
260713
260977
|
async runMiddleware(pathname, request) {
|
|
260714
260978
|
const middlewarePath = join24(this.rootDir, "middleware.twm");
|
|
260715
|
-
if (!
|
|
260979
|
+
if (!existsSync20(middlewarePath)) return;
|
|
260716
260980
|
const mod = await loadTWMModule(middlewarePath, this.rootDir);
|
|
260717
260981
|
if (mod.config?.matcher && !shouldMatchMiddleware(mod.config.matcher, pathname)) {
|
|
260718
260982
|
return;
|
|
@@ -260864,7 +261128,7 @@ var init_fs_compat = __esm({
|
|
|
260864
261128
|
});
|
|
260865
261129
|
|
|
260866
261130
|
// ../../packages/server/tw/router/index.ts
|
|
260867
|
-
import { existsSync as
|
|
261131
|
+
import { existsSync as existsSync21, readdirSync as readdirSync8, statSync as statSync7 } from "node:fs";
|
|
260868
261132
|
import { join as join25 } from "node:path";
|
|
260869
261133
|
var RouteRegistry;
|
|
260870
261134
|
var init_router = __esm({
|
|
@@ -260933,7 +261197,7 @@ var init_router = __esm({
|
|
|
260933
261197
|
return [...this.routes];
|
|
260934
261198
|
}
|
|
260935
261199
|
loadFromDir(pagesDir, basePath = "/") {
|
|
260936
|
-
if (!
|
|
261200
|
+
if (!existsSync21(pagesDir)) return;
|
|
260937
261201
|
const files = [];
|
|
260938
261202
|
this.collectFiles(pagesDir, ".tw", files, "");
|
|
260939
261203
|
for (const file of files) {
|
|
@@ -262688,8 +262952,8 @@ var init_signal_transports = __esm({
|
|
|
262688
262952
|
});
|
|
262689
262953
|
|
|
262690
262954
|
// ../../packages/server/tw/static/index.ts
|
|
262691
|
-
import { existsSync as
|
|
262692
|
-
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";
|
|
262693
262957
|
var StaticHandler;
|
|
262694
262958
|
var init_static = __esm({
|
|
262695
262959
|
"../../packages/server/tw/static/index.ts"() {
|
|
@@ -262729,32 +262993,32 @@ var init_static = __esm({
|
|
|
262729
262993
|
return new Response("Not Found", { status: 404, headers: { "Content-Type": "text/plain" } });
|
|
262730
262994
|
}
|
|
262731
262995
|
let filePath = join26(this.root, safePath);
|
|
262732
|
-
if (
|
|
262996
|
+
if (existsSync22(filePath) && statSync8(filePath).isDirectory()) {
|
|
262733
262997
|
filePath = join26(filePath, this.indexFile);
|
|
262734
262998
|
}
|
|
262735
|
-
if (!
|
|
262999
|
+
if (!existsSync22(filePath)) {
|
|
262736
263000
|
filePath = join26(this.root, safePath + ".html");
|
|
262737
263001
|
}
|
|
262738
263002
|
let notFoundFallback = false;
|
|
262739
|
-
if (!
|
|
263003
|
+
if (!existsSync22(filePath)) {
|
|
262740
263004
|
filePath = join26(this.root, safePath, this.indexFile);
|
|
262741
263005
|
}
|
|
262742
|
-
if (!
|
|
263006
|
+
if (!existsSync22(filePath)) {
|
|
262743
263007
|
if (this.spa) {
|
|
262744
263008
|
filePath = join26(this.root, this.indexFile);
|
|
262745
|
-
if (!
|
|
263009
|
+
if (!existsSync22(filePath)) {
|
|
262746
263010
|
return new Response("Not Found", { status: 404 });
|
|
262747
263011
|
}
|
|
262748
263012
|
} else {
|
|
262749
263013
|
filePath = join26(this.root, "404.html");
|
|
262750
263014
|
notFoundFallback = true;
|
|
262751
|
-
if (!
|
|
263015
|
+
if (!existsSync22(filePath)) {
|
|
262752
263016
|
return new Response("Not Found", { status: 404, headers: { "Content-Type": "text/plain" } });
|
|
262753
263017
|
}
|
|
262754
263018
|
}
|
|
262755
263019
|
}
|
|
262756
263020
|
const stat = statSync8(filePath);
|
|
262757
|
-
const ext =
|
|
263021
|
+
const ext = extname9(filePath).toLowerCase();
|
|
262758
263022
|
const contentType = MIME_TYPES[ext] ?? "application/octet-stream";
|
|
262759
263023
|
const bytes = await readBytes(filePath);
|
|
262760
263024
|
let etagValue = "";
|
|
@@ -264982,8 +265246,8 @@ var init_bot_detection = __esm({
|
|
|
264982
265246
|
|
|
264983
265247
|
// ../../packages/security/tw/content-security/protector.ts
|
|
264984
265248
|
function sanitizeFilename(filename) {
|
|
264985
|
-
const
|
|
264986
|
-
let clean =
|
|
265249
|
+
const basename4 = filename.replace(/^.*[\\/]/, "");
|
|
265250
|
+
let clean = basename4.replace(/\x00/g, "");
|
|
264987
265251
|
clean = clean.replace(/[<>:"|?*]/g, "_");
|
|
264988
265252
|
clean = clean.replace(/^\.+/, "");
|
|
264989
265253
|
if (clean.length > 255) {
|
|
@@ -271724,7 +271988,7 @@ var init_tw9 = __esm({
|
|
|
271724
271988
|
});
|
|
271725
271989
|
|
|
271726
271990
|
// ../../packages/server/tw/ssr/index.ts
|
|
271727
|
-
import { readFileSync as
|
|
271991
|
+
import { readFileSync as readFileSync15, writeFileSync as writeFileSync9, existsSync as existsSync23, mkdirSync as mkdirSync7 } from "node:fs";
|
|
271728
271992
|
import { createHash as createHash6 } from "node:crypto";
|
|
271729
271993
|
import { join as join27 } from "node:path";
|
|
271730
271994
|
import { existsSync as existsSyncSync } from "node:fs";
|
|
@@ -271738,7 +272002,7 @@ function getCachedSSR(pathname) {
|
|
|
271738
272002
|
}
|
|
271739
272003
|
const diskPath = join27(_diskCacheDir, pathname.replace(/[\/]/g, "_") + ".html");
|
|
271740
272004
|
if (existsSyncSync(diskPath)) {
|
|
271741
|
-
const content =
|
|
272005
|
+
const content = readFileSync15(diskPath, "utf-8");
|
|
271742
272006
|
const etag = createHash6("sha256").update(content).digest("hex").slice(0, 16);
|
|
271743
272007
|
_ssrCache.set(pathname, { html: content, etag, expires: Date.now() + 6e4 });
|
|
271744
272008
|
return { html: content, etag };
|
|
@@ -271751,7 +272015,7 @@ function setCachedSSR(pathname, html) {
|
|
|
271751
272015
|
try {
|
|
271752
272016
|
if (!existsSyncSync(_diskCacheDir)) mkdirSync7(_diskCacheDir, { recursive: true });
|
|
271753
272017
|
const diskPath = join27(_diskCacheDir, pathname.replace(/[\/]/g, "_") + ".html");
|
|
271754
|
-
|
|
272018
|
+
writeFileSync9(diskPath, html);
|
|
271755
272019
|
} catch {
|
|
271756
272020
|
}
|
|
271757
272021
|
return etag;
|
|
@@ -271854,9 +272118,9 @@ var init_ssr = __esm({
|
|
|
271854
272118
|
}
|
|
271855
272119
|
}
|
|
271856
272120
|
const filePath = this.resolveRoute(pathname);
|
|
271857
|
-
if (!filePath || !
|
|
272121
|
+
if (!filePath || !existsSync23(filePath)) return null;
|
|
271858
272122
|
try {
|
|
271859
|
-
const source =
|
|
272123
|
+
const source = readFileSync15(filePath, "utf-8");
|
|
271860
272124
|
return {
|
|
271861
272125
|
html: `<html><body>SSR sync not available</body></html>`,
|
|
271862
272126
|
css: "",
|
|
@@ -271891,35 +272155,35 @@ var init_ssr = __esm({
|
|
|
271891
272155
|
let currentDir = this.pagesDir;
|
|
271892
272156
|
if (segments.length === 0) {
|
|
271893
272157
|
const pagePath = join27(this.pagesDir, "page.tw");
|
|
271894
|
-
if (
|
|
272158
|
+
if (existsSync23(pagePath)) return pagePath;
|
|
271895
272159
|
const indexPath = join27(this.pagesDir, "index.tw");
|
|
271896
|
-
if (
|
|
272160
|
+
if (existsSync23(indexPath)) return indexPath;
|
|
271897
272161
|
return null;
|
|
271898
272162
|
}
|
|
271899
272163
|
for (let i = 0; i < segments.length; i++) {
|
|
271900
272164
|
const seg = segments[i];
|
|
271901
272165
|
const isLast = i === segments.length - 1;
|
|
271902
|
-
const entries =
|
|
272166
|
+
const entries = existsSync23(currentDir) ? __require("node:fs").readdirSync(currentDir) : [];
|
|
271903
272167
|
if (isLast) {
|
|
271904
272168
|
const exactPath = join27(currentDir, seg + ".tw");
|
|
271905
|
-
if (
|
|
272169
|
+
if (existsSync23(exactPath)) return exactPath;
|
|
271906
272170
|
const dirPage = join27(currentDir, seg, "page.tw");
|
|
271907
|
-
if (
|
|
272171
|
+
if (existsSync23(dirPage)) return dirPage;
|
|
271908
272172
|
const paramFile = entries.find((e) => e.match(/^\[([^\]]+)\]\.tw$/));
|
|
271909
272173
|
if (paramFile) return join27(currentDir, paramFile);
|
|
271910
272174
|
const paramDir = entries.find((e) => e.match(/^\[([^\]]+)\]$/));
|
|
271911
272175
|
if (paramDir) {
|
|
271912
272176
|
const p = join27(currentDir, paramDir, "page.tw");
|
|
271913
|
-
if (
|
|
272177
|
+
if (existsSync23(p)) return p;
|
|
271914
272178
|
const pIdx = join27(currentDir, paramDir, "index.tw");
|
|
271915
|
-
if (
|
|
272179
|
+
if (existsSync23(pIdx)) return pIdx;
|
|
271916
272180
|
}
|
|
271917
272181
|
const idx = join27(currentDir, seg, "index.tw");
|
|
271918
|
-
if (
|
|
272182
|
+
if (existsSync23(idx)) return idx;
|
|
271919
272183
|
return null;
|
|
271920
272184
|
}
|
|
271921
272185
|
const dirPath = join27(currentDir, seg);
|
|
271922
|
-
if (
|
|
272186
|
+
if (existsSync23(dirPath) && __require("node:fs").statSync(dirPath).isDirectory()) {
|
|
271923
272187
|
currentDir = dirPath;
|
|
271924
272188
|
} else {
|
|
271925
272189
|
const paramDir = entries.find((e) => e.match(/^\[([^\]]+)\]$/));
|
|
@@ -273432,7 +273696,7 @@ __export(tw_exports6, {
|
|
|
273432
273696
|
wwwRedirect: () => wwwRedirect
|
|
273433
273697
|
});
|
|
273434
273698
|
import { join as join28 } from "node:path";
|
|
273435
|
-
import { existsSync as
|
|
273699
|
+
import { existsSync as existsSync24, readFileSync as readFileSync16 } from "node:fs";
|
|
273436
273700
|
function normalizePathname(p) {
|
|
273437
273701
|
return p.replace(/\/{2,}/g, "/");
|
|
273438
273702
|
}
|
|
@@ -273723,11 +273987,11 @@ var init_tw10 = __esm({
|
|
|
273723
273987
|
}
|
|
273724
273988
|
}
|
|
273725
273989
|
const staticDir = this.options.staticDir ?? join28(options.rootDir, ".tw");
|
|
273726
|
-
if (
|
|
273990
|
+
if (existsSync24(staticDir)) {
|
|
273727
273991
|
try {
|
|
273728
273992
|
const manifestPath = join28(staticDir, "routes.json");
|
|
273729
|
-
if (
|
|
273730
|
-
const manifest = JSON.parse(
|
|
273993
|
+
if (existsSync24(manifestPath)) {
|
|
273994
|
+
const manifest = JSON.parse(readFileSync16(manifestPath, "utf-8"));
|
|
273731
273995
|
for (const [route, secs] of Object.entries(manifest)) {
|
|
273732
273996
|
this.isrRoutes.set(route, secs);
|
|
273733
273997
|
}
|
|
@@ -273745,7 +274009,7 @@ var init_tw10 = __esm({
|
|
|
273745
274009
|
});
|
|
273746
274010
|
}
|
|
273747
274011
|
const homeDir = this.options.pagesDir ?? join28(options.rootDir, "home");
|
|
273748
|
-
if (
|
|
274012
|
+
if (existsSync24(homeDir)) {
|
|
273749
274013
|
this.ssr = new SSRRenderer({ pagesDir: homeDir, enableCache: true, cacheTTL: 6e4 });
|
|
273750
274014
|
}
|
|
273751
274015
|
}
|
|
@@ -273792,11 +274056,11 @@ var init_tw10 = __esm({
|
|
|
273792
274056
|
middlewarePath = null;
|
|
273793
274057
|
loadMiddleware() {
|
|
273794
274058
|
const middlewarePath = join28(this.options.rootDir, "middleware.twm");
|
|
273795
|
-
if (
|
|
274059
|
+
if (existsSync24(middlewarePath)) {
|
|
273796
274060
|
this.middlewarePath = middlewarePath;
|
|
273797
274061
|
console.log(" Middleware: middleware.twm loaded");
|
|
273798
274062
|
try {
|
|
273799
|
-
const src =
|
|
274063
|
+
const src = readFileSync16(middlewarePath, "utf-8");
|
|
273800
274064
|
const rules = parseRules(src, "middleware.twm");
|
|
273801
274065
|
for (const r of rules) {
|
|
273802
274066
|
const conds = [];
|
|
@@ -274287,7 +274551,7 @@ var init_tw10 = __esm({
|
|
|
274287
274551
|
return new Response("Bad Request", { status: 400 });
|
|
274288
274552
|
}
|
|
274289
274553
|
const homeDir = join28(this.options.rootDir, "home");
|
|
274290
|
-
if (!
|
|
274554
|
+
if (!existsSync24(homeDir)) return new Response("Not Found", { status: 404 });
|
|
274291
274555
|
try {
|
|
274292
274556
|
const { createRenderPipeline: createRenderPipeline2 } = await Promise.resolve().then(() => (init_routing2(), routing_exports));
|
|
274293
274557
|
if (!this.renderPipeline) {
|
|
@@ -274436,7 +274700,7 @@ var init_tw10 = __esm({
|
|
|
274436
274700
|
try {
|
|
274437
274701
|
const { createRenderPipeline: createRenderPipeline2 } = await Promise.resolve().then(() => (init_routing2(), routing_exports));
|
|
274438
274702
|
const homeDir = join28(this.options.rootDir, "home");
|
|
274439
|
-
if (
|
|
274703
|
+
if (existsSync24(homeDir)) {
|
|
274440
274704
|
const pipeline = createRenderPipeline2({
|
|
274441
274705
|
rootDir: this.options.rootDir,
|
|
274442
274706
|
homeDir,
|
|
@@ -274496,7 +274760,7 @@ ${err2.stack ?? ""}`);
|
|
|
274496
274760
|
try {
|
|
274497
274761
|
const { createRenderPipeline: createRenderPipeline2, setActivePipeline: setActivePipeline2 } = await Promise.resolve().then(() => (init_routing2(), routing_exports));
|
|
274498
274762
|
const homeDir = join28(this.options.rootDir, "home");
|
|
274499
|
-
if (
|
|
274763
|
+
if (existsSync24(homeDir)) {
|
|
274500
274764
|
if (!this.renderPipeline) {
|
|
274501
274765
|
this.renderPipeline = createRenderPipeline2({
|
|
274502
274766
|
rootDir: this.options.rootDir,
|
|
@@ -289265,7 +289529,7 @@ __export(twm_loader_exports, {
|
|
|
289265
289529
|
stripCommentsSafe: () => stripCommentsSafe,
|
|
289266
289530
|
validateTWMSyntax: () => validateTWMSyntax
|
|
289267
289531
|
});
|
|
289268
|
-
import { readFileSync as
|
|
289532
|
+
import { readFileSync as readFileSync17, existsSync as existsSync25 } from "node:fs";
|
|
289269
289533
|
import { join as join29 } from "node:path";
|
|
289270
289534
|
function clearTWMCache() {
|
|
289271
289535
|
moduleCache.clear();
|
|
@@ -289273,7 +289537,7 @@ function clearTWMCache() {
|
|
|
289273
289537
|
function validateTWMSyntax(filePath) {
|
|
289274
289538
|
let source;
|
|
289275
289539
|
try {
|
|
289276
|
-
source =
|
|
289540
|
+
source = readFileSync17(filePath, "utf-8");
|
|
289277
289541
|
} catch (err2) {
|
|
289278
289542
|
return "cannot read: " + (err2?.message ?? err2);
|
|
289279
289543
|
}
|
|
@@ -289373,7 +289637,7 @@ async function loadLibModule(rootDir, name) {
|
|
|
289373
289637
|
const cacheKey = rootDir + "/" + rel;
|
|
289374
289638
|
if (libCache.has(cacheKey)) return libCache.get(cacheKey);
|
|
289375
289639
|
const libPath = join29(rootDir, "lib", rel + ".ts");
|
|
289376
|
-
if (!
|
|
289640
|
+
if (!existsSync25(libPath)) {
|
|
289377
289641
|
throw new Error("Module '" + name + "' not found. Create lib/" + name + ".ts");
|
|
289378
289642
|
}
|
|
289379
289643
|
try {
|
|
@@ -289415,10 +289679,10 @@ async function loadTWMModule(filePath, rootDir) {
|
|
|
289415
289679
|
const cacheKey = filePath;
|
|
289416
289680
|
const cached2 = moduleCache.get(cacheKey);
|
|
289417
289681
|
if (cached2) return cached2;
|
|
289418
|
-
if (!
|
|
289682
|
+
if (!existsSync25(filePath)) {
|
|
289419
289683
|
throw new Error("TWM module not found: " + filePath);
|
|
289420
289684
|
}
|
|
289421
|
-
const source =
|
|
289685
|
+
const source = readFileSync17(filePath, "utf-8");
|
|
289422
289686
|
const rd = rootDir || process.cwd();
|
|
289423
289687
|
if (isRuleDsl(source)) {
|
|
289424
289688
|
try {
|
|
@@ -289983,6 +290247,7 @@ var init_twm_loader = __esm({
|
|
|
289983
290247
|
// tw/commands/server-boundary.ts
|
|
289984
290248
|
var server_boundary_exports = {};
|
|
289985
290249
|
__export(server_boundary_exports, {
|
|
290250
|
+
CLIENT_SAFE_MARKER: () => CLIENT_SAFE_MARKER,
|
|
289986
290251
|
DEFAULT_DENY_PACKAGES: () => DEFAULT_DENY_PACKAGES,
|
|
289987
290252
|
DENY_NODE_BUILTINS: () => DENY_NODE_BUILTINS,
|
|
289988
290253
|
SERVER_ONLY_MARKER: () => SERVER_ONLY_MARKER,
|
|
@@ -289991,19 +290256,32 @@ __export(server_boundary_exports, {
|
|
|
289991
290256
|
formatChain: () => formatChain,
|
|
289992
290257
|
walkClientGraph: () => walkClientGraph
|
|
289993
290258
|
});
|
|
289994
|
-
import { readFileSync as
|
|
289995
|
-
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
|
+
}
|
|
289996
290264
|
function collectModuleImports(src) {
|
|
289997
290265
|
const out = [];
|
|
289998
290266
|
if (!src.trim()) return out;
|
|
289999
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
|
+
};
|
|
290000
290278
|
const visit = (node) => {
|
|
290001
290279
|
if (ts4.isImportDeclaration(node) && ts4.isStringLiteral(node.moduleSpecifier)) {
|
|
290002
|
-
out.push({ specifier: node.moduleSpecifier.text, kind: "import" });
|
|
290280
|
+
out.push({ specifier: node.moduleSpecifier.text, kind: "import", names: names(node), source: node.getText(sf) });
|
|
290003
290281
|
} else if (ts4.isExportDeclaration(node) && node.moduleSpecifier && ts4.isStringLiteral(node.moduleSpecifier)) {
|
|
290004
|
-
out.push({ specifier: node.moduleSpecifier.text, kind: "export-from" });
|
|
290282
|
+
out.push({ specifier: node.moduleSpecifier.text, kind: "export-from", names: [], source: node.getText(sf) });
|
|
290005
290283
|
} else if (ts4.isCallExpression(node) && node.expression.kind === ts4.SyntaxKind.ImportKeyword && node.arguments[0] && ts4.isStringLiteral(node.arguments[0])) {
|
|
290006
|
-
out.push({ specifier: node.arguments[0].text, kind: "dynamic" });
|
|
290284
|
+
out.push({ specifier: node.arguments[0].text, kind: "dynamic", names: [], source: node.getText(sf) });
|
|
290007
290285
|
}
|
|
290008
290286
|
ts4.forEachChild(node, visit);
|
|
290009
290287
|
};
|
|
@@ -290016,8 +290294,8 @@ function isLocal(spec) {
|
|
|
290016
290294
|
function resolveLocal(spec, fromDir) {
|
|
290017
290295
|
const rel = spec.startsWith("@./") ? spec.slice(2) : spec;
|
|
290018
290296
|
const base = resolve7(fromDir, rel);
|
|
290019
|
-
if (
|
|
290020
|
-
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;
|
|
290021
290299
|
return null;
|
|
290022
290300
|
}
|
|
290023
290301
|
function matchesOnlyPackages(spec, only) {
|
|
@@ -290041,41 +290319,50 @@ function walkClientGraph(entryFiles, opts = {}) {
|
|
|
290041
290319
|
const only = opts.onlyPackages ?? [];
|
|
290042
290320
|
const label = (f) => opts.rootDir && f.startsWith(opts.rootDir) ? relative2(opts.rootDir, f) : f;
|
|
290043
290321
|
const queue = entryFiles.map((f) => ({ file: resolve7(f), chain: [label(resolve7(f))] }));
|
|
290322
|
+
const entrySet = new Set(entryFiles.map((f) => resolve7(f)));
|
|
290044
290323
|
while (queue.length) {
|
|
290045
290324
|
const { file, chain: chain2 } = queue.shift();
|
|
290046
290325
|
if (seen.has(file)) continue;
|
|
290047
290326
|
seen.add(file);
|
|
290048
|
-
if (!
|
|
290327
|
+
if (!existsSync26(file)) continue;
|
|
290049
290328
|
let src;
|
|
290050
290329
|
try {
|
|
290051
|
-
src =
|
|
290330
|
+
src = readFileSync18(file, "utf8");
|
|
290052
290331
|
} catch {
|
|
290053
290332
|
continue;
|
|
290054
290333
|
}
|
|
290055
290334
|
const scannable = opts.stripServerRegions ? opts.stripServerRegions(src) : src;
|
|
290056
|
-
if (scannable.includes(`"${SERVER_ONLY_MARKER}"`) || scannable.includes(`'${SERVER_ONLY_MARKER}'`)) {
|
|
290057
|
-
violations.push({ file, specifier: SERVER_ONLY_MARKER, layer: "L4", chain: [...chain2, SERVER_ONLY_MARKER] });
|
|
290058
|
-
}
|
|
290059
290335
|
for (const imp of collectModuleImports(scannable)) {
|
|
290060
290336
|
const spec = imp.specifier;
|
|
290061
290337
|
let layer = null;
|
|
290062
290338
|
if (isServerOnlyByName(spec)) layer = "name";
|
|
290063
290339
|
else if (isLocal(spec)) {
|
|
290064
|
-
const resolvedLocal = resolveLocal(spec,
|
|
290340
|
+
const resolvedLocal = resolveLocal(spec, dirname13(file));
|
|
290065
290341
|
const libRoot = opts.rootDir ? resolve7(opts.rootDir, "lib") : null;
|
|
290066
290342
|
if (resolvedLocal && libRoot && (resolvedLocal === libRoot || resolvedLocal.startsWith(libRoot + sep2))) {
|
|
290067
|
-
|
|
290343
|
+
let clientSafe = false;
|
|
290344
|
+
try {
|
|
290345
|
+
clientSafe = hasMarker(readFileSync18(resolvedLocal, "utf8"), CLIENT_SAFE_MARKER);
|
|
290346
|
+
} catch {
|
|
290347
|
+
}
|
|
290348
|
+
if (!clientSafe) layer = "lib";
|
|
290068
290349
|
}
|
|
290069
290350
|
} else if (spec === SERVER_ONLY_MARKER) layer = "L4";
|
|
290351
|
+
else if (spec === CLIENT_SAFE_MARKER) continue;
|
|
290070
290352
|
else if (spec.startsWith("node:") || DENY_NODE_BUILTINS.has(spec)) layer = "L1";
|
|
290071
290353
|
else if (matchesOnlyPackages(spec, only)) layer = "L3";
|
|
290072
290354
|
else if (DEFAULT_DENY_PACKAGES.includes(packageName(spec))) layer = "L2";
|
|
290073
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
|
+
}
|
|
290074
290361
|
violations.push({ file, specifier: spec, layer, chain: [...chain2, spec] });
|
|
290075
290362
|
continue;
|
|
290076
290363
|
}
|
|
290077
290364
|
if (isLocal(spec)) {
|
|
290078
|
-
const local = resolveLocal(spec,
|
|
290365
|
+
const local = resolveLocal(spec, dirname13(file));
|
|
290079
290366
|
if (local) queue.push({ file: local, chain: [...chain2, label(local)] });
|
|
290080
290367
|
}
|
|
290081
290368
|
}
|
|
@@ -290105,11 +290392,12 @@ async function devServerOnlyBoundary(rootDir, entryFiles, onlyPackages) {
|
|
|
290105
290392
|
const viols = walkClientGraph(entryFiles, { rootDir, onlyPackages, stripServerRegions: strip });
|
|
290106
290393
|
return viols.map((v) => `${v.layer}:${v.specifier} [${formatChain(v)}]`);
|
|
290107
290394
|
}
|
|
290108
|
-
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;
|
|
290109
290396
|
var init_server_boundary = __esm({
|
|
290110
290397
|
"tw/commands/server-boundary.ts"() {
|
|
290111
290398
|
ts4 = __toESM(require_typescript(), 1);
|
|
290112
290399
|
SERVER_ONLY_MARKER = "@tw/server-only";
|
|
290400
|
+
CLIENT_SAFE_MARKER = "@tw/client-safe";
|
|
290113
290401
|
DENY_NODE_BUILTINS = /* @__PURE__ */ new Set([
|
|
290114
290402
|
"fs",
|
|
290115
290403
|
"fs/promises",
|
|
@@ -290169,9 +290457,9 @@ __export(build_exports, {
|
|
|
290169
290457
|
csrifyHtml: () => csrifyHtml,
|
|
290170
290458
|
extractRenderMode: () => extractRenderMode2
|
|
290171
290459
|
});
|
|
290172
|
-
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";
|
|
290173
290461
|
import { createHash as createHash8 } from "node:crypto";
|
|
290174
|
-
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";
|
|
290175
290463
|
function findCompilerPath() {
|
|
290176
290464
|
const fileUrl = import.meta.url.replace("file://", "");
|
|
290177
290465
|
const cmdDir = fileUrl.substring(0, fileUrl.lastIndexOf("/"));
|
|
@@ -290181,7 +290469,7 @@ function findCompilerPath() {
|
|
|
290181
290469
|
resolve8(process.cwd(), "node_modules/tw-framework/packages/compiler/tw/index.ts")
|
|
290182
290470
|
];
|
|
290183
290471
|
for (const p of candidates) {
|
|
290184
|
-
if (
|
|
290472
|
+
if (existsSync27(p)) return p;
|
|
290185
290473
|
}
|
|
290186
290474
|
return resolve8(process.cwd(), "packages/compiler/tw/index.ts");
|
|
290187
290475
|
}
|
|
@@ -290211,7 +290499,7 @@ function matchesPageFile(entry, stem) {
|
|
|
290211
290499
|
return entry === stem || entry === stem + ".tw";
|
|
290212
290500
|
}
|
|
290213
290501
|
function collectFiles(dir, fileName, results) {
|
|
290214
|
-
if (!
|
|
290502
|
+
if (!existsSync27(dir)) return;
|
|
290215
290503
|
for (const entry of readdirSync9(dir)) {
|
|
290216
290504
|
if (entry.startsWith("_") || entry.startsWith("@")) continue;
|
|
290217
290505
|
const fullPath = join30(dir, entry);
|
|
@@ -290224,7 +290512,7 @@ function collectFiles(dir, fileName, results) {
|
|
|
290224
290512
|
}
|
|
290225
290513
|
}
|
|
290226
290514
|
function copyDir2(src, dest) {
|
|
290227
|
-
if (!
|
|
290515
|
+
if (!existsSync27(src)) return;
|
|
290228
290516
|
mkdirSync8(dest, { recursive: true });
|
|
290229
290517
|
for (const entry of readdirSync9(src)) {
|
|
290230
290518
|
const srcPath = join30(src, entry);
|
|
@@ -290243,7 +290531,7 @@ function findLayoutChain(dir, homeDir) {
|
|
|
290243
290531
|
const homeAbs = resolve8(homeDir);
|
|
290244
290532
|
for (let i = 0; i < 16; i++) {
|
|
290245
290533
|
const cand = join30(cur, "layout.tw");
|
|
290246
|
-
if (
|
|
290534
|
+
if (existsSync27(cand)) chain2.push(cand);
|
|
290247
290535
|
if (resolve8(cur) === homeAbs) break;
|
|
290248
290536
|
const parent = resolve8(cur, "..");
|
|
290249
290537
|
if (parent === resolve8(cur) || !parent.startsWith(homeAbs)) break;
|
|
@@ -290253,7 +290541,7 @@ function findLayoutChain(dir, homeDir) {
|
|
|
290253
290541
|
}
|
|
290254
290542
|
function loadGlobalStyles(rootDir) {
|
|
290255
290543
|
const legacy = join30(rootDir, "style.css");
|
|
290256
|
-
if (
|
|
290544
|
+
if (existsSync27(legacy)) return readFileSync19(legacy, "utf-8");
|
|
290257
290545
|
return "";
|
|
290258
290546
|
}
|
|
290259
290547
|
function collectComponentUsages(node, out) {
|
|
@@ -290346,19 +290634,19 @@ async function transformEmittedFiles(outDir, pm) {
|
|
|
290346
290634
|
await walk3(p);
|
|
290347
290635
|
continue;
|
|
290348
290636
|
}
|
|
290349
|
-
const ext =
|
|
290637
|
+
const ext = extname11(e.name).toLowerCase();
|
|
290350
290638
|
const rel = p.slice(outDir.length).replace(/^[\\/]/, "");
|
|
290351
290639
|
try {
|
|
290352
290640
|
if (js && (ext === ".js" || ext === ".mjs")) {
|
|
290353
|
-
const out = await pm.runHookChain("transform:js",
|
|
290354
|
-
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);
|
|
290355
290643
|
} else if (css && ext === ".css") {
|
|
290356
|
-
const out = await pm.runHookChain("transform:css",
|
|
290357
|
-
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);
|
|
290358
290646
|
} else if (asset && ![".html", ".json", ".js", ".mjs", ".css"].includes(ext)) {
|
|
290359
|
-
const buf =
|
|
290647
|
+
const buf = readFileSync19(p);
|
|
290360
290648
|
const out = await pm.runHookChain("optimize:asset", buf, { file: rel });
|
|
290361
|
-
if (out && out !== buf)
|
|
290649
|
+
if (out && out !== buf) writeFileSync10(p, out);
|
|
290362
290650
|
}
|
|
290363
290651
|
} catch {
|
|
290364
290652
|
}
|
|
@@ -290412,9 +290700,9 @@ function stripServerRegionsForScan(source) {
|
|
|
290412
290700
|
async function buildCommand() {
|
|
290413
290701
|
const rootDir = process.cwd();
|
|
290414
290702
|
const envPath = join30(rootDir, ".env");
|
|
290415
|
-
if (
|
|
290703
|
+
if (existsSync27(envPath)) {
|
|
290416
290704
|
try {
|
|
290417
|
-
for (const line of
|
|
290705
|
+
for (const line of readFileSync19(envPath, "utf-8").split("\n")) {
|
|
290418
290706
|
const m = /^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/.exec(line);
|
|
290419
290707
|
if (m && !(m[1] in process.env)) {
|
|
290420
290708
|
process.env[m[1]] = m[2].replace(/^["']|["']$/g, "");
|
|
@@ -290435,6 +290723,7 @@ async function buildCommand() {
|
|
|
290435
290723
|
};
|
|
290436
290724
|
let needsRuntime = false;
|
|
290437
290725
|
let skippedPages = 0;
|
|
290726
|
+
let skippedNotFound = 0;
|
|
290438
290727
|
let incCache = {};
|
|
290439
290728
|
const incNext = {};
|
|
290440
290729
|
const incHash = (t3) => createHash8("sha256").update(t3).digest("hex").slice(0, 16);
|
|
@@ -290544,11 +290833,35 @@ async function buildCommand() {
|
|
|
290544
290833
|
};
|
|
290545
290834
|
try {
|
|
290546
290835
|
const cfgPath = join30(rootDir, "tw.config.ts");
|
|
290547
|
-
if (
|
|
290836
|
+
if (existsSync27(cfgPath)) {
|
|
290548
290837
|
const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
290549
290838
|
const cfgMod = await twImportTs2(cfgPath);
|
|
290550
290839
|
const cfg = cfgMod.default ?? cfgMod;
|
|
290551
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
|
+
}
|
|
290552
290865
|
serverBlocksOn = cfg?.server?.blocks ?? cfg?.experimental?.serverBlocks ?? true;
|
|
290553
290866
|
serverOnlyPackages = Array.isArray(cfg?.server?.onlyPackages) ? cfg.server.onlyPackages : [];
|
|
290554
290867
|
fetchTimeoutMs = cfg?.server?.fetchTimeoutMs;
|
|
@@ -290587,7 +290900,7 @@ async function buildCommand() {
|
|
|
290587
290900
|
outDir = join30(rootDir, buildOpts.outputDir);
|
|
290588
290901
|
if (buildOpts.incremental) {
|
|
290589
290902
|
try {
|
|
290590
|
-
incCache = JSON.parse(
|
|
290903
|
+
incCache = JSON.parse(readFileSync19(join30(outDir, ".build-cache.json"), "utf-8"));
|
|
290591
290904
|
} catch {
|
|
290592
290905
|
incCache = {};
|
|
290593
290906
|
}
|
|
@@ -290633,7 +290946,7 @@ async function buildCommand() {
|
|
|
290633
290946
|
} catch {
|
|
290634
290947
|
}
|
|
290635
290948
|
}
|
|
290636
|
-
if (
|
|
290949
|
+
if (existsSync27(outDir)) {
|
|
290637
290950
|
rmDirRecursive(outDir);
|
|
290638
290951
|
}
|
|
290639
290952
|
mkdirSync8(outDir, { recursive: true });
|
|
@@ -290679,7 +290992,7 @@ async function buildCommand() {
|
|
|
290679
290992
|
const plan = foreign.map((fi) => {
|
|
290680
290993
|
let src = "";
|
|
290681
290994
|
try {
|
|
290682
|
-
src =
|
|
290995
|
+
src = readFileSync19(fi.absPath, "utf-8");
|
|
290683
290996
|
} catch {
|
|
290684
290997
|
}
|
|
290685
290998
|
return { fi, engine: ib.detectEngine(src, renderEngine), ...ib.parseClientStrategy(src) };
|
|
@@ -290779,11 +291092,11 @@ async function buildCommand() {
|
|
|
290779
291092
|
const { checkEdgeSafety: checkEdgeSafety2 } = await Promise.resolve().then(() => (init_tw(), tw_exports));
|
|
290780
291093
|
const apiFiles = [];
|
|
290781
291094
|
const apiRoot = join30(homeDir, apiDirName);
|
|
290782
|
-
collectFiles(
|
|
291095
|
+
collectFiles(existsSync27(apiRoot) ? apiRoot : homeDir, "route.twm", apiFiles);
|
|
290783
291096
|
const violations = [];
|
|
290784
291097
|
for (const f of apiFiles) {
|
|
290785
291098
|
try {
|
|
290786
|
-
violations.push(...checkEdgeSafety2(
|
|
291099
|
+
violations.push(...checkEdgeSafety2(readFileSync19(f, "utf-8"), f));
|
|
290787
291100
|
} catch {
|
|
290788
291101
|
}
|
|
290789
291102
|
}
|
|
@@ -290810,23 +291123,23 @@ async function buildCommand() {
|
|
|
290810
291123
|
pf,
|
|
290811
291124
|
rootDir,
|
|
290812
291125
|
{ compileSync: _compileSync, registerComponentTemplate: _registerComponentTemplate, clearComponentRegistry: _clearComponentRegistry },
|
|
290813
|
-
|
|
291126
|
+
readFileSync19(pf, "utf-8"),
|
|
290814
291127
|
(name) => registeredComponentNames.add(name)
|
|
290815
291128
|
);
|
|
290816
291129
|
} catch {
|
|
290817
291130
|
}
|
|
290818
291131
|
}
|
|
290819
291132
|
for (const pf of pageFiles) {
|
|
290820
|
-
if (
|
|
290821
|
-
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");
|
|
290822
291135
|
console.log(" index.tw wins this route -- delete one of them");
|
|
290823
291136
|
}
|
|
290824
291137
|
}
|
|
290825
291138
|
{
|
|
290826
291139
|
const shapes = /* @__PURE__ */ new Map();
|
|
290827
291140
|
for (const pf of pageFiles) {
|
|
290828
|
-
const dir =
|
|
290829
|
-
if (
|
|
291141
|
+
const dir = dirname14(pf);
|
|
291142
|
+
if (existsSync27(join30(dir, "page.twm"))) {
|
|
290830
291143
|
console.log(" \x1B[33m!\x1B[0m " + dir.replace(homeDir, "").replace(/^\//, "") + "/ has BOTH page.tw and page.twm");
|
|
290831
291144
|
console.log(" the .twm handler never runs -- delete one of them");
|
|
290832
291145
|
}
|
|
@@ -290857,26 +291170,26 @@ async function buildCommand() {
|
|
|
290857
291170
|
const routeName = relativePath.replace(/\/?page(?:\.tw)?$/, "").replace(/\\/g, "/");
|
|
290858
291171
|
const routePath = routeName === "" ? "/" : "/" + routeName;
|
|
290859
291172
|
if (buildOpts?.incremental) {
|
|
290860
|
-
const deps = [pageFile, ...findLayoutChain(
|
|
291173
|
+
const deps = [pageFile, ...findLayoutChain(dirname14(pageFile), homeDir)];
|
|
290861
291174
|
let raw = "";
|
|
290862
291175
|
for (const d of deps) {
|
|
290863
291176
|
try {
|
|
290864
|
-
raw += d + "\0" +
|
|
291177
|
+
raw += d + "\0" + readFileSync19(d, "utf-8");
|
|
290865
291178
|
} catch {
|
|
290866
291179
|
}
|
|
290867
291180
|
}
|
|
290868
291181
|
const h3 = incHash(raw);
|
|
290869
291182
|
incNext[pageFile] = h3;
|
|
290870
291183
|
const outHtml = join30(outDir, routeName, "index.html");
|
|
290871
|
-
if (incCache[pageFile] === h3 &&
|
|
291184
|
+
if (incCache[pageFile] === h3 && existsSync27(outHtml)) {
|
|
290872
291185
|
skippedPages++;
|
|
290873
291186
|
continue;
|
|
290874
291187
|
}
|
|
290875
291188
|
}
|
|
290876
291189
|
let paramSets = [{}];
|
|
290877
291190
|
if (/\[[^\]]+\]/.test(pageFile)) {
|
|
290878
|
-
const paramsTwm = join30(
|
|
290879
|
-
if (
|
|
291191
|
+
const paramsTwm = join30(dirname14(pageFile), "params.twm");
|
|
291192
|
+
if (existsSync27(paramsTwm)) {
|
|
290880
291193
|
try {
|
|
290881
291194
|
const { loadTWMModule: loadTWMModule2 } = await Promise.resolve().then(() => (init_twm_loader(), twm_loader_exports));
|
|
290882
291195
|
const pmod = await loadTWMModule2(paramsTwm, rootDir);
|
|
@@ -290910,10 +291223,10 @@ async function buildCommand() {
|
|
|
290910
291223
|
continue;
|
|
290911
291224
|
}
|
|
290912
291225
|
}
|
|
290913
|
-
const renderMode = extractRenderMode2(
|
|
291226
|
+
const renderMode = extractRenderMode2(readFileSync19(pageFile, "utf8"));
|
|
290914
291227
|
try {
|
|
290915
291228
|
const { parseWithDetails: _pd, checkDeclarationConflicts: checkDeclarationConflicts2 } = _compilerMod;
|
|
290916
|
-
const _prog = _pd(
|
|
291229
|
+
const _prog = _pd(readFileSync19(pageFile, "utf-8"), { filePath: pageFile, cache: false }).program;
|
|
290917
291230
|
const _paramNames = routePath.split("/").filter((seg) => seg.startsWith("[")).map((seg) => seg.replace(/^\[+/, "").replace(/\]+$/, "").replace(/^\.\.\./, ""));
|
|
290918
291231
|
for (const c of checkDeclarationConflicts2(_prog, _paramNames)) {
|
|
290919
291232
|
console.error(" \x1B[33m!\x1B[0m " + pageFile.replace(rootDir + "/", "") + ":" + c.line + " " + c.code + " " + c.message);
|
|
@@ -290922,7 +291235,7 @@ async function buildCommand() {
|
|
|
290922
291235
|
} catch {
|
|
290923
291236
|
}
|
|
290924
291237
|
{
|
|
290925
|
-
const pageSrc =
|
|
291238
|
+
const pageSrc = readFileSync19(pageFile, "utf-8");
|
|
290926
291239
|
const { extractCacheDirective: extractCacheDirective2, resolveCache: resolveCache2 } = await Promise.resolve().then(() => (init_tw(), tw_exports));
|
|
290927
291240
|
const cacheMeta = extractCacheDirective2(pageSrc);
|
|
290928
291241
|
let resolved = null;
|
|
@@ -290960,7 +291273,7 @@ async function buildCommand() {
|
|
|
290960
291273
|
console.log(" \x1B[36m~\x1B[0m " + routePath + " [" + renderMode + ": rendered at request time]");
|
|
290961
291274
|
isrRoutes.set(routePath === "" ? "/" : routePath, 0);
|
|
290962
291275
|
try {
|
|
290963
|
-
const src =
|
|
291276
|
+
const src = readFileSync19(pageFile, "utf-8");
|
|
290964
291277
|
if (serverBlocksOn) {
|
|
290965
291278
|
try {
|
|
290966
291279
|
const { parseWithDetails: parseWithDetails2, collectServerBlocks: collectServerBlocks2, checkServerBlocks: checkServerBlocks2, collectReferencedNames: collectReferencedNames3, extractVary: extractVary2 } = _compilerMod;
|
|
@@ -291023,13 +291336,21 @@ async function buildCommand() {
|
|
|
291023
291336
|
_compilerMod.beginCssRouteCapture?.(routePath);
|
|
291024
291337
|
for (const paramSet of paramSets) {
|
|
291025
291338
|
try {
|
|
291026
|
-
const source =
|
|
291339
|
+
const source = readFileSync19(pageFile, "utf-8");
|
|
291027
291340
|
let serverVars = {};
|
|
291028
291341
|
if (serverBlocksOn) {
|
|
291029
291342
|
const { parseWithDetails: parseWithDetails2, collectServerBlocks: collectServerBlocks2, checkServerBlocks: checkServerBlocks2, executeServerBlocks: executeServerBlocks2, encodeServerValues: encodeServerValues2, collectReferencedNames: collectReferencedNames3, extractVary: extractVary2, secretEnvValues: secretEnvValues3, resolveServerImports: resolveServerImports2 } = _compilerMod;
|
|
291030
291343
|
const prog = parseWithDetails2(source, { filePath: pageFile, cache: false, experimental: { serverBlocks: true } }).program;
|
|
291031
291344
|
const sb = collectServerBlocks2(prog);
|
|
291032
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
|
+
}
|
|
291033
291354
|
const referenced = collectReferencedNames3(source);
|
|
291034
291355
|
const problems = checkServerBlocks2(prog, {
|
|
291035
291356
|
mode: renderMode,
|
|
@@ -291047,14 +291368,34 @@ async function buildCommand() {
|
|
|
291047
291368
|
const omit = ["headers", "cookies", "query"];
|
|
291048
291369
|
if (!hasExplicitParams) omit.push("params");
|
|
291049
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
|
+
}
|
|
291050
291385
|
for (const b of sb) Object.assign(imports, await resolveServerImports2(b, pageFile, { dev: false }));
|
|
291051
291386
|
try {
|
|
291052
291387
|
const { createServerFetch: createServerFetch2, wrapJsonErrors: wrapJsonErrors2, SERVER_FETCH_BUILD_ID: SERVER_FETCH_BUILD_ID2 } = _compilerMod;
|
|
291053
291388
|
const sfetch = createServerFetch2({ buildId: SERVER_FETCH_BUILD_ID2, timeoutMs: fetchTimeoutMs, maxBytes: fetchCacheMaxBytes });
|
|
291054
291389
|
const fetchShim = (u, i) => sfetch(u, i).then(wrapJsonErrors2);
|
|
291055
|
-
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) });
|
|
291056
291391
|
serverVars = encodeServerValues2(vals);
|
|
291057
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
|
+
}
|
|
291058
291399
|
console.error(" \x1B[31m\u2717\x1B[0m " + pageFile.replace(rootDir + "/", "") + " server block failed: " + (e?.message ?? e));
|
|
291059
291400
|
errorCount++;
|
|
291060
291401
|
continue;
|
|
@@ -291065,7 +291406,7 @@ async function buildCommand() {
|
|
|
291065
291406
|
let pageImports = {};
|
|
291066
291407
|
try {
|
|
291067
291408
|
const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
291068
|
-
const { dirname:
|
|
291409
|
+
const { dirname: dirname18, resolve: resolvePath } = await import("node:path");
|
|
291069
291410
|
const parseFn = _compilerMod.parseWithDetails;
|
|
291070
291411
|
const parsed = parseFn(source, pageFile);
|
|
291071
291412
|
const prog = parsed?.program ?? parsed?.ast;
|
|
@@ -291073,7 +291414,7 @@ async function buildCommand() {
|
|
|
291073
291414
|
if (d?.type !== "ImportDirective" || !d.source || d.isTypeOnly) continue;
|
|
291074
291415
|
const spec = String(d.source);
|
|
291075
291416
|
if (!(spec.startsWith("./") || spec.startsWith("../") || spec.startsWith("@./"))) continue;
|
|
291076
|
-
const abs = spec.startsWith("@./") ? resolvePath(rootDir, spec.slice(3)) : resolvePath(
|
|
291417
|
+
const abs = spec.startsWith("@./") ? resolvePath(rootDir, spec.slice(3)) : resolvePath(dirname18(pageFile), spec);
|
|
291077
291418
|
const mod = await twImportTs2(abs);
|
|
291078
291419
|
if (d.namespaceImport) pageImports[d.namespaceImport] = mod;
|
|
291079
291420
|
if (d.defaultImport) pageImports[d.defaultImport] = mod?.default ?? mod;
|
|
@@ -291102,10 +291443,10 @@ async function buildCommand() {
|
|
|
291102
291443
|
}
|
|
291103
291444
|
}
|
|
291104
291445
|
let html = result.html;
|
|
291105
|
-
const layoutChain = findLayoutChain(
|
|
291446
|
+
const layoutChain = findLayoutChain(dirname14(pageFile), homeDir);
|
|
291106
291447
|
if (layoutChain.length > 0) {
|
|
291107
291448
|
const layoutPrograms = layoutChain.map((lp) => {
|
|
291108
|
-
const ls =
|
|
291449
|
+
const ls = readFileSync19(lp, "utf-8");
|
|
291109
291450
|
const lr = _compileSync(ls, { filePath: lp, ...compilePassOpts() });
|
|
291110
291451
|
if (serverBlocksOn) {
|
|
291111
291452
|
const { checkServerBlocks: checkServerBlocks2 } = _compilerMod;
|
|
@@ -291128,12 +291469,12 @@ async function buildCommand() {
|
|
|
291128
291469
|
}
|
|
291129
291470
|
const headSources = [];
|
|
291130
291471
|
const globalHeadTw = join30(homeDir, "head.tw");
|
|
291131
|
-
if (
|
|
291132
|
-
const headTwPath = join30(
|
|
291133
|
-
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);
|
|
291134
291475
|
for (const headSrc of headSources) {
|
|
291135
291476
|
try {
|
|
291136
|
-
const headSource =
|
|
291477
|
+
const headSource = readFileSync19(headSrc, "utf-8");
|
|
291137
291478
|
const headResult = _compileSync(headSource, { filePath: headSrc });
|
|
291138
291479
|
const headBody = headResult.html.match(/<body>([\s\S]*)<\/body>/);
|
|
291139
291480
|
if (headBody && headBody[1].trim()) {
|
|
@@ -291162,7 +291503,7 @@ async function buildCommand() {
|
|
|
291162
291503
|
}
|
|
291163
291504
|
let pageMods = pageClientLines.get(pageFile);
|
|
291164
291505
|
if (!pageMods) {
|
|
291165
|
-
const chainFiles = findLayoutChain(
|
|
291506
|
+
const chainFiles = findLayoutChain(dirname14(pageFile), homeDir);
|
|
291166
291507
|
const own = /* @__PURE__ */ new Set();
|
|
291167
291508
|
const deps = /* @__PURE__ */ new Set();
|
|
291168
291509
|
const { collectClientImportsFromSource: collectClientImportsFromSource2, findServerOnlyViolations: findServerOnlyViolations2 } = await Promise.resolve().then(() => (init_client_bundle(), client_bundle_exports));
|
|
@@ -291180,7 +291521,7 @@ async function buildCommand() {
|
|
|
291180
291521
|
for (const v of findServerOnlyViolations2(source)) tw1007.push({ file: pageFile, spec: v });
|
|
291181
291522
|
}
|
|
291182
291523
|
for (const lf of chainFiles) {
|
|
291183
|
-
const ls =
|
|
291524
|
+
const ls = readFileSync19(lf, "utf-8");
|
|
291184
291525
|
for (const l of collectClientImportsFromSource2(ls)) deps.add(l);
|
|
291185
291526
|
if (!serverBlocksOn) for (const v of findServerOnlyViolations2(ls)) tw1007.push({ file: lf, spec: v });
|
|
291186
291527
|
}
|
|
@@ -291308,11 +291649,11 @@ async function buildCommand() {
|
|
|
291308
291649
|
apiCount++;
|
|
291309
291650
|
}
|
|
291310
291651
|
}
|
|
291311
|
-
if (
|
|
291652
|
+
if (existsSync27(publicDir)) {
|
|
291312
291653
|
copyDir2(publicDir, outDir);
|
|
291313
291654
|
console.log(" \x1B[32mOK\x1B[0m public/");
|
|
291314
291655
|
}
|
|
291315
|
-
if (
|
|
291656
|
+
if (existsSync27(stylePath)) {
|
|
291316
291657
|
copyFileSync2(stylePath, join30(outDir, "style.css"));
|
|
291317
291658
|
console.log(" \x1B[32mOK\x1B[0m style.css");
|
|
291318
291659
|
}
|
|
@@ -291322,10 +291663,12 @@ async function buildCommand() {
|
|
|
291322
291663
|
const rel = v.file.startsWith(rootDir) ? v.file.slice(rootDir.length + 1) : v.file;
|
|
291323
291664
|
console.log(" TW1007: " + rel + " \u2192 " + v.spec);
|
|
291324
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";');
|
|
291325
291668
|
}
|
|
291326
291669
|
process.exit(1);
|
|
291327
291670
|
}
|
|
291328
|
-
if (
|
|
291671
|
+
if (existsSync27(libDir)) {
|
|
291329
291672
|
copyDir2(libDir, join30(outDir, "lib"));
|
|
291330
291673
|
console.log(" \x1B[32mOK\x1B[0m lib/");
|
|
291331
291674
|
}
|
|
@@ -291333,7 +291676,7 @@ async function buildCommand() {
|
|
|
291333
291676
|
console.log(" \x1B[36m\u26A1\x1B[0m client modules: " + clientChunkUrls.size + " shared chunk" + (clientChunkUrls.size === 1 ? "" : "s") + " (content-hashed, tree-shaken)");
|
|
291334
291677
|
}
|
|
291335
291678
|
const mwPath = join30(rootDir, "middleware.twm");
|
|
291336
|
-
if (
|
|
291679
|
+
if (existsSync27(mwPath)) {
|
|
291337
291680
|
copyFileSync2(mwPath, join30(outDir, "middleware.twm"));
|
|
291338
291681
|
console.log(" \x1B[32mOK\x1B[0m middleware.twm");
|
|
291339
291682
|
}
|
|
@@ -291346,7 +291689,7 @@ async function buildCommand() {
|
|
|
291346
291689
|
}
|
|
291347
291690
|
const manifest = purgeManifest2(routes);
|
|
291348
291691
|
if (manifest) {
|
|
291349
|
-
|
|
291692
|
+
writeFileSync10(join30(outDir, "cdn-purge.json"), JSON.stringify(manifest, null, 2));
|
|
291350
291693
|
console.log(" \x1B[36m\u26A1\x1B[0m cdn: purge manifest for " + routes.length + " route" + (routes.length === 1 ? "" : "s"));
|
|
291351
291694
|
}
|
|
291352
291695
|
}
|
|
@@ -291397,7 +291740,7 @@ async function buildCommand() {
|
|
|
291397
291740
|
}
|
|
291398
291741
|
return out;
|
|
291399
291742
|
};
|
|
291400
|
-
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));
|
|
291401
291744
|
}
|
|
291402
291745
|
let inlined = 0;
|
|
291403
291746
|
for (const out of htmlOutputs) {
|
|
@@ -291413,14 +291756,14 @@ async function buildCommand() {
|
|
|
291413
291756
|
}
|
|
291414
291757
|
if (inject2) out.html = out.html.replace("</head>", inject2 + "\n</head>");
|
|
291415
291758
|
const finalHtml = await runBuildHookValue("transform:html", out.html, { route: out.route });
|
|
291416
|
-
|
|
291759
|
+
writeFileSync10(join30(out.outputDir, "index.html"), finalHtml);
|
|
291417
291760
|
}
|
|
291418
291761
|
const linked = htmlOutputs.length - inlined;
|
|
291419
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]");
|
|
291420
291763
|
} else {
|
|
291421
291764
|
for (const out of htmlOutputs) {
|
|
291422
291765
|
const finalHtml = await runBuildHookValue("transform:html", out.html, { route: out.route });
|
|
291423
|
-
|
|
291766
|
+
writeFileSync10(join30(out.outputDir, "index.html"), finalHtml);
|
|
291424
291767
|
}
|
|
291425
291768
|
}
|
|
291426
291769
|
m.clearCssCapture?.();
|
|
@@ -291428,9 +291771,9 @@ async function buildCommand() {
|
|
|
291428
291771
|
end("css");
|
|
291429
291772
|
{
|
|
291430
291773
|
const nfFile = join30(homeDir, "not-found.tw");
|
|
291431
|
-
if (
|
|
291774
|
+
if (existsSync27(nfFile)) {
|
|
291432
291775
|
try {
|
|
291433
|
-
const nfSource =
|
|
291776
|
+
const nfSource = readFileSync19(nfFile, "utf-8");
|
|
291434
291777
|
try {
|
|
291435
291778
|
registerImportedComponents(
|
|
291436
291779
|
nfFile,
|
|
@@ -291443,14 +291786,14 @@ async function buildCommand() {
|
|
|
291443
291786
|
}
|
|
291444
291787
|
const nfResult = _compileSync(nfSource, { filePath: nfFile });
|
|
291445
291788
|
let nfHtml = nfResult.html;
|
|
291446
|
-
const nfChain = findLayoutChain(
|
|
291789
|
+
const nfChain = findLayoutChain(dirname14(nfFile), homeDir);
|
|
291447
291790
|
if (nfChain.length > 0 && _generateWithLayoutChain) {
|
|
291448
|
-
const layoutPrograms = nfChain.map((lp) => _compileSync(
|
|
291791
|
+
const layoutPrograms = nfChain.map((lp) => _compileSync(readFileSync19(lp, "utf-8"), { filePath: lp }).ast).filter(Boolean);
|
|
291449
291792
|
if (layoutPrograms.length > 0) nfHtml = _generateWithLayoutChain(layoutPrograms, nfResult.ast, {});
|
|
291450
291793
|
}
|
|
291451
291794
|
if (css) nfHtml = nfHtml.replace("</head>", "<style>" + css + "</style>\n</head>");
|
|
291452
291795
|
const finalNf = await runBuildHookValue("transform:html", nfHtml, { route: "/404" });
|
|
291453
|
-
|
|
291796
|
+
writeFileSync10(join30(outDir, "404.html"), finalNf);
|
|
291454
291797
|
console.log(" \x1B[32mOK\x1B[0m /404 -> 404.html (" + nfFile.replace(rootDir + "/", "") + ")");
|
|
291455
291798
|
} catch (e) {
|
|
291456
291799
|
console.log(" \x1B[31mX\x1B[0m " + nfFile.replace(rootDir + "/", "") + ": " + e.message + "\x1B[0m");
|
|
@@ -291463,15 +291806,15 @@ async function buildCommand() {
|
|
|
291463
291806
|
const _fu = import.meta.url.replace("file://", "");
|
|
291464
291807
|
const _srcDir = _fu.substring(0, _fu.lastIndexOf("/"));
|
|
291465
291808
|
const runtimeSrc = _bundleDir ? resolve8(_bundleDir, "hydration-runtime.js") : resolve8(_srcDir, "../../../..", "packages/runtime/tw/client/hydration-runtime.js");
|
|
291466
|
-
if (
|
|
291467
|
-
const raw =
|
|
291809
|
+
if (existsSync27(runtimeSrc)) {
|
|
291810
|
+
const raw = readFileSync19(runtimeSrc, "utf-8");
|
|
291468
291811
|
let code = raw;
|
|
291469
291812
|
try {
|
|
291470
291813
|
const cb = await Promise.resolve().then(() => (init_client_bundle(), client_bundle_exports));
|
|
291471
291814
|
code = cb.minifyJsSource?.(rootDir, raw, esbuildTargetFor(buildOpts?.target)) ?? raw;
|
|
291472
291815
|
} catch {
|
|
291473
291816
|
}
|
|
291474
|
-
|
|
291817
|
+
writeFileSync10(join30(outDir, "__tw_runtime.js"), code);
|
|
291475
291818
|
const saved = raw.length - code.length;
|
|
291476
291819
|
console.log(" \x1B[36m\u26A1\x1B[0m hydration runtime: .tw/__tw_runtime.js" + (saved > 0 ? " (" + (saved / 1024).toFixed(1) + " KB smaller)" : ""));
|
|
291477
291820
|
}
|
|
@@ -291483,20 +291826,21 @@ async function buildCommand() {
|
|
|
291483
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.");
|
|
291484
291827
|
console.log(" APIs: " + apiCount + " routes");
|
|
291485
291828
|
try {
|
|
291486
|
-
|
|
291829
|
+
writeFileSync10(join30(outDir, "build-summary.json"), JSON.stringify({
|
|
291487
291830
|
staticPages: pageCount,
|
|
291488
291831
|
ssrPages: requestRenderedCount,
|
|
291489
291832
|
apiRoutes: apiCount,
|
|
291490
|
-
middleware:
|
|
291833
|
+
middleware: existsSync27(join30(rootDir, "middleware.twm"))
|
|
291491
291834
|
}, null, 2));
|
|
291492
291835
|
} catch {
|
|
291493
291836
|
}
|
|
291494
291837
|
if (buildOpts?.incremental) {
|
|
291495
291838
|
try {
|
|
291496
|
-
|
|
291839
|
+
writeFileSync10(join30(outDir, ".build-cache.json"), JSON.stringify(incNext));
|
|
291497
291840
|
} catch {
|
|
291498
291841
|
}
|
|
291499
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");
|
|
291500
291844
|
}
|
|
291501
291845
|
if (buildOpts?.entryPoints?.length) {
|
|
291502
291846
|
try {
|
|
@@ -291527,7 +291871,7 @@ async function buildCommand() {
|
|
|
291527
291871
|
files.sort((a, b) => b.size - a.size);
|
|
291528
291872
|
const total = files.reduce((n, f) => n + f.size, 0);
|
|
291529
291873
|
if (buildOpts.metafile) {
|
|
291530
|
-
|
|
291874
|
+
writeFileSync10(join30(outDir, "build-meta.json"), JSON.stringify({ total, files }, null, 2));
|
|
291531
291875
|
}
|
|
291532
291876
|
if (buildOpts.bundleAnalysis) {
|
|
291533
291877
|
console.log("\n Bundle analysis (largest first):");
|
|
@@ -291540,7 +291884,7 @@ async function buildCommand() {
|
|
|
291540
291884
|
if (isrRoutes.size > 0) {
|
|
291541
291885
|
const manifest = {};
|
|
291542
291886
|
for (const [k, v] of isrRoutes) manifest[k] = v;
|
|
291543
|
-
|
|
291887
|
+
writeFileSync10(join30(outDir, "routes.json"), JSON.stringify(manifest, null, 2));
|
|
291544
291888
|
console.log(" \x1B[36m~\x1B[0m ISR: " + isrRoutes.size + " route(s) with cache windows -> .tw/routes.json");
|
|
291545
291889
|
}
|
|
291546
291890
|
{
|
|
@@ -291624,7 +291968,7 @@ async function buildCommand() {
|
|
|
291624
291968
|
if (errorCount > 0 || tw1007.length > 0) process.exit(1);
|
|
291625
291969
|
}
|
|
291626
291970
|
function rmDirRecursive(dir) {
|
|
291627
|
-
if (!
|
|
291971
|
+
if (!existsSync27(dir)) return;
|
|
291628
291972
|
for (const entry of readdirSync9(dir)) {
|
|
291629
291973
|
const fullPath = join30(dir, entry);
|
|
291630
291974
|
const stat = statSync9(fullPath);
|
|
@@ -291677,17 +292021,17 @@ __export(tw_exports8, {
|
|
|
291677
292021
|
vercelStaticConfig: () => vercelStaticConfig,
|
|
291678
292022
|
writeVercelFiles: () => writeVercelFiles
|
|
291679
292023
|
});
|
|
291680
|
-
import { existsSync as
|
|
291681
|
-
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";
|
|
291682
292026
|
import { fileURLToPath } from "node:url";
|
|
291683
292027
|
function resolvePkgDir() {
|
|
291684
|
-
const self2 =
|
|
292028
|
+
const self2 = dirname16(fileURLToPath(import.meta.url));
|
|
291685
292029
|
const bundleDir = globalThis.__TW_BUNDLE_DIR;
|
|
291686
292030
|
if (bundleDir) {
|
|
291687
292031
|
const fromBundle = join33(bundleDir, "adapters");
|
|
291688
|
-
if (
|
|
292032
|
+
if (existsSync30(join33(fromBundle, "node", "server.mjs"))) return fromBundle;
|
|
291689
292033
|
}
|
|
291690
|
-
if (
|
|
292034
|
+
if (existsSync30(join33(self2, "node", "server.mjs"))) return self2;
|
|
291691
292035
|
return self2;
|
|
291692
292036
|
}
|
|
291693
292037
|
function generateAdapter(name, appDir) {
|
|
@@ -291699,10 +292043,10 @@ function generateAdapter(name, appDir) {
|
|
|
291699
292043
|
const written = [];
|
|
291700
292044
|
for (const f of adapter.files) {
|
|
291701
292045
|
const src = join33(PKG_DIR, f.from);
|
|
291702
|
-
if (!
|
|
292046
|
+
if (!existsSync30(src)) throw new Error(`Adapter file missing: ${f.from}`);
|
|
291703
292047
|
const dest = join33(appDir, f.to);
|
|
291704
|
-
mkdirSync9(
|
|
291705
|
-
|
|
292048
|
+
mkdirSync9(dirname16(dest), { recursive: true });
|
|
292049
|
+
writeFileSync11(dest, readFileSync21(src));
|
|
291706
292050
|
written.push(dest);
|
|
291707
292051
|
}
|
|
291708
292052
|
return written;
|
|
@@ -291895,12 +292239,12 @@ __export(node_test_runner_exports, {
|
|
|
291895
292239
|
runNodeTests: () => runNodeTests
|
|
291896
292240
|
});
|
|
291897
292241
|
import { join as join36 } from "node:path";
|
|
291898
|
-
import { mkdirSync as mkdirSync10, writeFileSync as
|
|
292242
|
+
import { mkdirSync as mkdirSync10, writeFileSync as writeFileSync13, readFileSync as readFileSync24 } from "node:fs";
|
|
291899
292243
|
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
291900
292244
|
async function runNodeTests(files, rootDir) {
|
|
291901
292245
|
const cacheDir = join36(rootDir, ".tw", ".tests");
|
|
291902
292246
|
mkdirSync10(cacheDir, { recursive: true });
|
|
291903
|
-
|
|
292247
|
+
writeFileSync13(join36(cacheDir, "mini-bun-test.cjs"), MINI_BUN_TEST);
|
|
291904
292248
|
let esbuildMain = "";
|
|
291905
292249
|
try {
|
|
291906
292250
|
const { createRequire } = await import("node:module");
|
|
@@ -291910,21 +292254,21 @@ async function runNodeTests(files, rootDir) {
|
|
|
291910
292254
|
}
|
|
291911
292255
|
const runnerSrc = esbuildMain ? `globalThis.__TW_ESBUILD_MODULE = ${JSON.stringify(esbuildMain)};
|
|
291912
292256
|
` + RUNNER : RUNNER;
|
|
291913
|
-
|
|
292257
|
+
writeFileSync13(join36(cacheDir, "runner.cjs"), runnerSrc);
|
|
291914
292258
|
const esbuild = await import("esbuild");
|
|
291915
|
-
const { basename:
|
|
292259
|
+
const { basename: basename4 } = await import("node:path");
|
|
291916
292260
|
const compiled = [];
|
|
291917
292261
|
for (const f of files) {
|
|
291918
|
-
const outPath = join36(cacheDir,
|
|
292262
|
+
const outPath = join36(cacheDir, basename4(f).replace(/\.(ts|tsx|js)$/, ".cjs"));
|
|
291919
292263
|
const adapterPath = join36(cacheDir, "node-adapter.ts");
|
|
291920
292264
|
try {
|
|
291921
|
-
|
|
292265
|
+
writeFileSync13(adapterPath, readFileSync24(join36(new URL(".", import.meta.url).pathname, "node-adapter.ts"), "utf-8"));
|
|
291922
292266
|
} catch {
|
|
291923
292267
|
const bd = globalThis.__TW_BUNDLE_DIR;
|
|
291924
292268
|
const src = bd ? join36(bd, "..", "tw", "node-adapter.ts") : "";
|
|
291925
292269
|
if (src) {
|
|
291926
292270
|
try {
|
|
291927
|
-
|
|
292271
|
+
writeFileSync13(adapterPath, readFileSync24(src, "utf-8"));
|
|
291928
292272
|
} catch {
|
|
291929
292273
|
}
|
|
291930
292274
|
}
|
|
@@ -291974,7 +292318,7 @@ async function runNodeTests(files, rootDir) {
|
|
|
291974
292318
|
}
|
|
291975
292319
|
const childEnv = { ...process.env };
|
|
291976
292320
|
try {
|
|
291977
|
-
const envFile =
|
|
292321
|
+
const envFile = readFileSync24(join36(rootDir, ".env"), "utf-8");
|
|
291978
292322
|
for (const line of envFile.split("\n")) {
|
|
291979
292323
|
const m = line.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/);
|
|
291980
292324
|
if (m && !(m[1] in childEnv)) childEnv[m[1]] = m[2].replace(/^["']|["']$/g, "");
|
|
@@ -294783,7 +295127,7 @@ async function createPackageJson(dir, name) {
|
|
|
294783
295127
|
ship: "tw ship"
|
|
294784
295128
|
},
|
|
294785
295129
|
dependencies: {
|
|
294786
|
-
"tw-framework": "^2.0.
|
|
295130
|
+
"tw-framework": "^2.0.5"
|
|
294787
295131
|
},
|
|
294788
295132
|
devDependencies: {
|
|
294789
295133
|
typescript: "^5.4.0",
|
|
@@ -294870,7 +295214,7 @@ dist/
|
|
|
294870
295214
|
async function createReadme(dir, name) {
|
|
294871
295215
|
const content = `# ${name}
|
|
294872
295216
|
|
|
294873
|
-
Built with TW Framework 2.0.
|
|
295217
|
+
Built with TW Framework 2.0.5.
|
|
294874
295218
|
|
|
294875
295219
|
## Getting Started
|
|
294876
295220
|
|
|
@@ -295751,7 +296095,8 @@ body { font-family system-ui, sans-serif; bg #0d1117; color #c9d1d9 }
|
|
|
295751
296095
|
}
|
|
295752
296096
|
|
|
295753
296097
|
// tw/commands/dev.ts
|
|
295754
|
-
|
|
296098
|
+
init_tw();
|
|
296099
|
+
import { join as join31, resolve as resolve9, dirname as dirname15 } from "node:path";
|
|
295755
296100
|
|
|
295756
296101
|
// tw/dev-overlay.ts
|
|
295757
296102
|
var OVERLAY_CSS = [
|
|
@@ -295778,7 +296123,7 @@ var CLIENT_OVERLAY_SCRIPT = '<script id="__tw_error_overlay">(function(){if(wind
|
|
|
295778
296123
|
// tw/commands/dev.ts
|
|
295779
296124
|
init_components();
|
|
295780
296125
|
await init_build();
|
|
295781
|
-
import { existsSync as
|
|
296126
|
+
import { existsSync as existsSync28, readFileSync as readFileSync20, readdirSync as readdirSync10, statSync as statSync10 } from "node:fs";
|
|
295782
296127
|
function findCompilerPath2() {
|
|
295783
296128
|
const fileUrl = import.meta.url.replace("file://", "");
|
|
295784
296129
|
const cmdDir = fileUrl.substring(0, fileUrl.lastIndexOf("/"));
|
|
@@ -295788,7 +296133,7 @@ function findCompilerPath2() {
|
|
|
295788
296133
|
resolve9(process.cwd(), "node_modules/tw-framework/packages/compiler/tw/index.ts")
|
|
295789
296134
|
];
|
|
295790
296135
|
for (const p of candidates) {
|
|
295791
|
-
if (
|
|
296136
|
+
if (existsSync28(p)) return p;
|
|
295792
296137
|
}
|
|
295793
296138
|
return resolve9(process.cwd(), "packages/compiler/tw/index.ts");
|
|
295794
296139
|
}
|
|
@@ -295843,14 +296188,14 @@ function resolveHomeFile(homeDir, pathname, leafNames) {
|
|
|
295843
296188
|
const segments = pathname.split("/").filter(Boolean).map(decodeURIComponent);
|
|
295844
296189
|
const isDir = (p) => {
|
|
295845
296190
|
try {
|
|
295846
|
-
return
|
|
296191
|
+
return existsSync28(p) && statSync10(p).isDirectory();
|
|
295847
296192
|
} catch {
|
|
295848
296193
|
return false;
|
|
295849
296194
|
}
|
|
295850
296195
|
};
|
|
295851
296196
|
const listDir = (p) => {
|
|
295852
296197
|
try {
|
|
295853
|
-
return
|
|
296198
|
+
return existsSync28(p) ? readdirSync10(p) : [];
|
|
295854
296199
|
} catch {
|
|
295855
296200
|
return [];
|
|
295856
296201
|
}
|
|
@@ -295859,14 +296204,14 @@ function resolveHomeFile(homeDir, pathname, leafNames) {
|
|
|
295859
296204
|
if (i >= segments.length) {
|
|
295860
296205
|
for (const leaf of leafNames) {
|
|
295861
296206
|
const f = join31(dir, leaf);
|
|
295862
|
-
if (
|
|
296207
|
+
if (existsSync28(f)) return { file: f, params };
|
|
295863
296208
|
}
|
|
295864
296209
|
for (const entry of listDir(dir)) {
|
|
295865
296210
|
const m = /^\[\[\.\.\.(.+)\]\]$/.exec(entry);
|
|
295866
296211
|
if (m && isDir(join31(dir, entry))) {
|
|
295867
296212
|
for (const leaf of leafNames) {
|
|
295868
296213
|
const f = join31(dir, entry, leaf);
|
|
295869
|
-
if (
|
|
296214
|
+
if (existsSync28(f)) return { file: f, params: { ...params, [m[1]]: "" } };
|
|
295870
296215
|
}
|
|
295871
296216
|
}
|
|
295872
296217
|
}
|
|
@@ -295896,13 +296241,13 @@ function resolveHomeFile(homeDir, pathname, leafNames) {
|
|
|
295896
296241
|
if (m && isDir(join31(dir, entry))) {
|
|
295897
296242
|
for (const leaf of leafNames) {
|
|
295898
296243
|
const f = join31(dir, entry, leaf);
|
|
295899
|
-
if (
|
|
296244
|
+
if (existsSync28(f)) return { file: f, params: { ...params, [m[1]]: segments.slice(i).join("/") } };
|
|
295900
296245
|
}
|
|
295901
296246
|
}
|
|
295902
296247
|
}
|
|
295903
296248
|
if (i === segments.length - 1) {
|
|
295904
296249
|
const f = join31(dir, seg + ".tw");
|
|
295905
|
-
if (
|
|
296250
|
+
if (existsSync28(f)) return { file: f, params };
|
|
295906
296251
|
}
|
|
295907
296252
|
return null;
|
|
295908
296253
|
}
|
|
@@ -295913,7 +296258,7 @@ function findLayoutDev(dir, homeDir) {
|
|
|
295913
296258
|
const homeAbs = resolve9(homeDir);
|
|
295914
296259
|
for (let i = 0; i < 16; i++) {
|
|
295915
296260
|
const cand = join31(cur, "layout.tw");
|
|
295916
|
-
if (
|
|
296261
|
+
if (existsSync28(cand)) return cand;
|
|
295917
296262
|
if (resolve9(cur) === homeAbs) break;
|
|
295918
296263
|
const parent = resolve9(cur, "..");
|
|
295919
296264
|
if (parent === resolve9(cur) || !parent.startsWith(homeAbs)) break;
|
|
@@ -296098,7 +296443,7 @@ function destroySession(req) {
|
|
|
296098
296443
|
}
|
|
296099
296444
|
async function loadMiddlewareRules(mwPath) {
|
|
296100
296445
|
try {
|
|
296101
|
-
const source =
|
|
296446
|
+
const source = readFileSync20(mwPath, "utf-8");
|
|
296102
296447
|
const { parseRules: parseRules2 } = await Promise.resolve().then(() => (init_twm_rules(), twm_rules_exports));
|
|
296103
296448
|
return parseRules2(source);
|
|
296104
296449
|
} catch (e) {
|
|
@@ -296126,7 +296471,7 @@ async function devCommand() {
|
|
|
296126
296471
|
try {
|
|
296127
296472
|
const cfgPath = join31(rootDir, "tw.config.ts");
|
|
296128
296473
|
let rawCfg = null;
|
|
296129
|
-
if (
|
|
296474
|
+
if (existsSync28(cfgPath)) {
|
|
296130
296475
|
const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
296131
296476
|
const cfgMod = await twImportTs2(cfgPath);
|
|
296132
296477
|
rawCfg = cfgMod.default ?? cfgMod;
|
|
@@ -296142,7 +296487,7 @@ async function devCommand() {
|
|
|
296142
296487
|
try {
|
|
296143
296488
|
const cfgPath2 = join31(rootDir, "tw.config.ts");
|
|
296144
296489
|
let cfgImages = null;
|
|
296145
|
-
if (
|
|
296490
|
+
if (existsSync28(cfgPath2)) {
|
|
296146
296491
|
try {
|
|
296147
296492
|
const { twImportTs: _twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
296148
296493
|
const cfgMod2 = await _twImportTs2(cfgPath2);
|
|
@@ -296158,9 +296503,9 @@ async function devCommand() {
|
|
|
296158
296503
|
} catch {
|
|
296159
296504
|
}
|
|
296160
296505
|
const envPath = join31(rootDir, ".env");
|
|
296161
|
-
if (
|
|
296506
|
+
if (existsSync28(envPath)) {
|
|
296162
296507
|
try {
|
|
296163
|
-
for (const line of
|
|
296508
|
+
for (const line of readFileSync20(envPath, "utf-8").split("\n")) {
|
|
296164
296509
|
const m = /^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/.exec(line);
|
|
296165
296510
|
if (m && !(m[1] in process.env)) {
|
|
296166
296511
|
process.env[m[1]] = m[2].replace(/^["']|["']$/g, "");
|
|
@@ -296177,29 +296522,29 @@ async function devCommand() {
|
|
|
296177
296522
|
{
|
|
296178
296523
|
const styleDir = join31(rootDir, "style");
|
|
296179
296524
|
const parts = [];
|
|
296180
|
-
if (
|
|
296525
|
+
if (existsSync28(styleDir)) {
|
|
296181
296526
|
for (const f of readdirSync10(styleDir).filter((f2) => f2.endsWith(".tss")).sort()) {
|
|
296182
296527
|
try {
|
|
296183
|
-
parts.push(_compileTSS2(
|
|
296528
|
+
parts.push(_compileTSS2(readFileSync20(join31(styleDir, f), "utf-8")));
|
|
296184
296529
|
} catch (e) {
|
|
296185
296530
|
console.log(" Warning: failed to compile " + f + ": " + e.message);
|
|
296186
296531
|
}
|
|
296187
296532
|
}
|
|
296188
296533
|
}
|
|
296189
|
-
if (
|
|
296534
|
+
if (existsSync28(stylePath)) parts.push(readFileSync20(stylePath, "utf-8"));
|
|
296190
296535
|
if (parts.length) css = parts.join("\n");
|
|
296191
296536
|
}
|
|
296192
296537
|
const mwPath = join31(rootDir, "middleware.twm");
|
|
296193
|
-
const middlewareRules =
|
|
296538
|
+
const middlewareRules = existsSync28(mwPath) ? await loadMiddlewareRules(mwPath) : [];
|
|
296194
296539
|
scanComponents3(rootDir);
|
|
296195
296540
|
const compDir = join31(rootDir, "components");
|
|
296196
|
-
if (
|
|
296541
|
+
if (existsSync28(compDir)) {
|
|
296197
296542
|
const compFiles = readdirSync10(compDir).filter((f) => f.endsWith(".tw"));
|
|
296198
296543
|
if (compFiles.length > 0) console.log(" Components: " + compFiles.map((f) => f.replace(/\.tw$/, "")).join(", "));
|
|
296199
296544
|
}
|
|
296200
296545
|
function findRoutes(dir, prefix) {
|
|
296201
296546
|
const routes2 = [];
|
|
296202
|
-
if (!
|
|
296547
|
+
if (!existsSync28(dir)) return routes2;
|
|
296203
296548
|
for (const entry of readdirSync10(dir)) {
|
|
296204
296549
|
const fullPath = join31(dir, entry);
|
|
296205
296550
|
const stat = statSync10(fullPath);
|
|
@@ -296214,10 +296559,10 @@ async function devCommand() {
|
|
|
296214
296559
|
return routes2;
|
|
296215
296560
|
}
|
|
296216
296561
|
const routes = findRoutes(homeDir, "");
|
|
296217
|
-
const components =
|
|
296562
|
+
const components = existsSync28(compDir) ? readdirSync10(compDir).filter((f) => f.endsWith(".tw")) : [];
|
|
296218
296563
|
const libDir = join31(rootDir, "lib");
|
|
296219
|
-
const libFiles =
|
|
296220
|
-
const hasConfig =
|
|
296564
|
+
const libFiles = existsSync28(libDir) ? readdirSync10(libDir).filter((f) => f.endsWith(".ts")) : [];
|
|
296565
|
+
const hasConfig = existsSync28(join31(rootDir, "tw.config.ts"));
|
|
296221
296566
|
console.log("\n \x1B[36mtw dev\x1B[0m -- starting development server\n");
|
|
296222
296567
|
console.log(" Root: " + rootDir);
|
|
296223
296568
|
console.log(" Port: http://" + host + ":" + port + "\n");
|
|
@@ -296239,7 +296584,7 @@ async function devCommand() {
|
|
|
296239
296584
|
const deps = new Set(own);
|
|
296240
296585
|
for (const lf of layoutFiles) {
|
|
296241
296586
|
try {
|
|
296242
|
-
const ls =
|
|
296587
|
+
const ls = readFileSync20(lf, "utf-8");
|
|
296243
296588
|
for (const l of collectClientImportsFromSource2(ls)) deps.add(l);
|
|
296244
296589
|
for (const v of findServerOnlyViolations2(ls)) console.error(" [tw] TW1007 (dev): " + lf + " \u2192 server-only import " + v);
|
|
296245
296590
|
} catch {
|
|
@@ -296266,7 +296611,7 @@ async function devCommand() {
|
|
|
296266
296611
|
async function runUserMiddleware(req) {
|
|
296267
296612
|
try {
|
|
296268
296613
|
const mwPath2 = join31(rootDir, "middleware.twm");
|
|
296269
|
-
if (!
|
|
296614
|
+
if (!existsSync28(mwPath2)) return null;
|
|
296270
296615
|
const { executeMiddleware: executeMiddleware2, loadTWMModule: loadTWMModule2, shouldMatchMiddleware: shouldMatchMiddleware2 } = await Promise.resolve().then(() => (init_twm_loader(), twm_loader_exports));
|
|
296271
296616
|
const mod = await loadTWMModule2(mwPath2, rootDir);
|
|
296272
296617
|
const mwPathname = new URL(req.url).pathname;
|
|
@@ -296288,7 +296633,7 @@ async function devCommand() {
|
|
|
296288
296633
|
let devSecMode = "dev";
|
|
296289
296634
|
try {
|
|
296290
296635
|
const cfgFile = join31(rootDir, "tw.config.ts");
|
|
296291
|
-
if (
|
|
296636
|
+
if (existsSync28(cfgFile)) {
|
|
296292
296637
|
const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
296293
296638
|
const cfgMod = await twImportTs2(cfgFile);
|
|
296294
296639
|
devSecMode = (cfgMod.default ?? cfgMod)?.security?.headers ?? "dev";
|
|
@@ -296311,7 +296656,7 @@ async function devCommand() {
|
|
|
296311
296656
|
let devSignalTransport = "sse";
|
|
296312
296657
|
try {
|
|
296313
296658
|
const cfgFile = join31(rootDir, "tw.config.ts");
|
|
296314
|
-
if (
|
|
296659
|
+
if (existsSync28(cfgFile)) {
|
|
296315
296660
|
const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
296316
296661
|
const cfgMod = await twImportTs2(cfgFile);
|
|
296317
296662
|
const cfg = cfgMod.default ?? cfgMod;
|
|
@@ -296382,8 +296727,8 @@ async function devCommand() {
|
|
|
296382
296727
|
const _bd = globalThis.__TW_BUNDLE_DIR;
|
|
296383
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")];
|
|
296384
296729
|
for (const runtimePath of runtimeCandidates) {
|
|
296385
|
-
if (
|
|
296386
|
-
return new Response(
|
|
296730
|
+
if (existsSync28(runtimePath)) {
|
|
296731
|
+
return new Response(readFileSync20(runtimePath, "utf-8"), {
|
|
296387
296732
|
headers: { "Content-Type": "application/javascript; charset=utf-8" }
|
|
296388
296733
|
});
|
|
296389
296734
|
}
|
|
@@ -296392,8 +296737,8 @@ async function devCommand() {
|
|
|
296392
296737
|
}
|
|
296393
296738
|
if (/^\/js\/(c|p|e|tw-client)-[a-z0-9]+\.js$/.test(path)) {
|
|
296394
296739
|
const clientBundlePath = join31(rootDir, ".tw", path.slice(1));
|
|
296395
|
-
if (
|
|
296396
|
-
return new Response(
|
|
296740
|
+
if (existsSync28(clientBundlePath)) {
|
|
296741
|
+
return new Response(readFileSync20(clientBundlePath, "utf-8"), {
|
|
296397
296742
|
headers: { "Content-Type": "application/javascript; charset=utf-8" }
|
|
296398
296743
|
});
|
|
296399
296744
|
}
|
|
@@ -296409,13 +296754,13 @@ async function devCommand() {
|
|
|
296409
296754
|
if (path === "/style.css") {
|
|
296410
296755
|
return new Response(css, { headers: { "Content-Type": "text/css" } });
|
|
296411
296756
|
}
|
|
296412
|
-
if (
|
|
296757
|
+
if (existsSync28(publicDir)) {
|
|
296413
296758
|
const publicFile = join31(publicDir, path);
|
|
296414
296759
|
const pubFile = Bun.file(publicFile);
|
|
296415
296760
|
if (await pubFile.exists()) {
|
|
296416
|
-
|
|
296417
|
-
|
|
296418
|
-
});
|
|
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 } });
|
|
296419
296764
|
}
|
|
296420
296765
|
}
|
|
296421
296766
|
if (path === "/placeholder.png" || path.endsWith(".png")) {
|
|
@@ -296513,9 +296858,9 @@ async function devCommand() {
|
|
|
296513
296858
|
delete result.json._errorMessage;
|
|
296514
296859
|
const pageRoutePath = renderPath === "/" ? "" : renderPath;
|
|
296515
296860
|
const pageFile = join31(homeDir, pageRoutePath, "page.tw");
|
|
296516
|
-
if (
|
|
296861
|
+
if (existsSync28(pageFile)) {
|
|
296517
296862
|
try {
|
|
296518
|
-
const pageSource =
|
|
296863
|
+
const pageSource = readFileSync20(pageFile, "utf-8");
|
|
296519
296864
|
const pageResult = compileSync3(pageSource, { filePath: pageFile });
|
|
296520
296865
|
let pageHtml = pageResult.html;
|
|
296521
296866
|
pageHtml = pageHtml.replace("</head>", "<style>" + css + "</style>\n</head>");
|
|
@@ -296566,14 +296911,22 @@ async function devCommand() {
|
|
|
296566
296911
|
if (resolved) {
|
|
296567
296912
|
const twFile = resolved.file;
|
|
296568
296913
|
try {
|
|
296569
|
-
const source =
|
|
296914
|
+
const source = readFileSync20(twFile, "utf-8");
|
|
296570
296915
|
if (typeof beginCssRouteCapture2 === "function") beginCssRouteCapture2(path);
|
|
296571
296916
|
let result = compileSync3(source, { filePath: twFile, stateVars: resolved.params, experimental: { serverBlocks: true } });
|
|
296572
296917
|
try {
|
|
296573
296918
|
const _c = await Promise.resolve().then(() => (init_tw7(), tw_exports3));
|
|
296574
296919
|
const blocks = _c.collectServerBlocks(result.ast);
|
|
296575
296920
|
if (blocks.length) {
|
|
296576
|
-
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
|
+
});
|
|
296577
296930
|
if (values && Object.keys(values).length) {
|
|
296578
296931
|
const merged = {
|
|
296579
296932
|
...resolved.params ?? {},
|
|
@@ -296606,7 +296959,7 @@ async function devCommand() {
|
|
|
296606
296959
|
const homeAbs = resolve9(homeDir);
|
|
296607
296960
|
for (let i = 0; i < 16; i++) {
|
|
296608
296961
|
const cand = join31(cur, "layout.tw");
|
|
296609
|
-
if (
|
|
296962
|
+
if (existsSync28(cand)) chain2.push(cand);
|
|
296610
296963
|
if (resolve9(cur) === homeAbs) break;
|
|
296611
296964
|
const parent = resolve9(cur, "..");
|
|
296612
296965
|
if (parent === resolve9(cur) || !parent.startsWith(homeAbs)) break;
|
|
@@ -296615,7 +296968,7 @@ async function devCommand() {
|
|
|
296615
296968
|
chain2.reverse();
|
|
296616
296969
|
}
|
|
296617
296970
|
if (chain2.length > 0 && generateWithLayoutChain2) {
|
|
296618
|
-
const layoutPrograms = chain2.map((lp) => compileSync3(
|
|
296971
|
+
const layoutPrograms = chain2.map((lp) => compileSync3(readFileSync20(lp, "utf-8"), { filePath: lp }).ast).filter(Boolean);
|
|
296619
296972
|
if (layoutPrograms.length > 0) {
|
|
296620
296973
|
html = generateWithLayoutChain2(layoutPrograms, result.ast, resolved.params);
|
|
296621
296974
|
const pageTitle = result.html.match(/<title>([^<]*)<\/title>/);
|
|
@@ -296634,7 +296987,7 @@ async function devCommand() {
|
|
|
296634
296987
|
}
|
|
296635
296988
|
let devClientTag = "";
|
|
296636
296989
|
try {
|
|
296637
|
-
const _clockSrc =
|
|
296990
|
+
const _clockSrc = existsSync28(resolved.file) ? readFileSync20(resolved.file, "utf-8") : "";
|
|
296638
296991
|
devClientTag = await ensureDevClientBundle(rootDir, _clockSrc, chain2);
|
|
296639
296992
|
} catch {
|
|
296640
296993
|
}
|
|
@@ -296657,12 +297010,12 @@ async function devCommand() {
|
|
|
296657
297010
|
}
|
|
296658
297011
|
const devGlobalHead = join31(homeDir, "head.tw");
|
|
296659
297012
|
const devHeadSources = [];
|
|
296660
|
-
if (
|
|
296661
|
-
const headTw = join31(
|
|
296662
|
-
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);
|
|
296663
297016
|
for (const devHeadTw of devHeadSources) {
|
|
296664
297017
|
try {
|
|
296665
|
-
const headRes = compileSync3(
|
|
297018
|
+
const headRes = compileSync3(readFileSync20(devHeadTw, "utf-8"), { filePath: devHeadTw });
|
|
296666
297019
|
const headBody = headRes.html.match(/<body>([\s\S]*)<\/body>/);
|
|
296667
297020
|
if (headBody && headBody[1].trim()) {
|
|
296668
297021
|
html = html.replace(
|
|
@@ -296708,14 +297061,14 @@ async function devCommand() {
|
|
|
296708
297061
|
}
|
|
296709
297062
|
console.log(" -> 404 Not Found");
|
|
296710
297063
|
const nfFile = join31(homeDir, "not-found.tw");
|
|
296711
|
-
if (
|
|
297064
|
+
if (existsSync28(nfFile)) {
|
|
296712
297065
|
try {
|
|
296713
|
-
const nfSource =
|
|
297066
|
+
const nfSource = readFileSync20(nfFile, "utf-8");
|
|
296714
297067
|
const nfResult = compileSync3(nfSource, { filePath: nfFile });
|
|
296715
297068
|
let nfHtml = nfResult.html;
|
|
296716
297069
|
const layoutPath = findLayoutDev(homeDir, homeDir);
|
|
296717
297070
|
if (layoutPath) {
|
|
296718
|
-
const layoutSource =
|
|
297071
|
+
const layoutSource = readFileSync20(layoutPath, "utf-8");
|
|
296719
297072
|
const layoutResult = compileSync3(layoutSource, { filePath: layoutPath });
|
|
296720
297073
|
if (layoutResult.ast && generateWithLayout2) nfHtml = generateWithLayout2(layoutResult.ast, nfResult.ast);
|
|
296721
297074
|
}
|
|
@@ -296845,7 +297198,7 @@ async function devCommand() {
|
|
|
296845
297198
|
const { loadPlugins: loadPlugins2 } = await Promise.resolve().then(() => (init_tw8(), tw_exports4));
|
|
296846
297199
|
const cfgPath = join31(rootDir, "tw.config.ts");
|
|
296847
297200
|
let cfg = void 0;
|
|
296848
|
-
if (
|
|
297201
|
+
if (existsSync28(cfgPath)) {
|
|
296849
297202
|
const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
296850
297203
|
const cfgMod = await twImportTs2(cfgPath);
|
|
296851
297204
|
cfg = cfgMod.default ?? cfgMod;
|
|
@@ -296857,7 +297210,7 @@ async function devCommand() {
|
|
|
296857
297210
|
let devTls = {};
|
|
296858
297211
|
if (devOpts?.https && devOpts.httpsCert && devOpts.httpsKey) {
|
|
296859
297212
|
try {
|
|
296860
|
-
devTls = { tls: { cert:
|
|
297213
|
+
devTls = { tls: { cert: readFileSync20(devOpts.httpsCert, "utf-8"), key: readFileSync20(devOpts.httpsKey, "utf-8") } };
|
|
296861
297214
|
} catch (e) {
|
|
296862
297215
|
console.log(" [tw] dev.https: could not read cert/key -- " + (e?.message ?? e));
|
|
296863
297216
|
}
|
|
@@ -296951,7 +297304,7 @@ await init_build();
|
|
|
296951
297304
|
|
|
296952
297305
|
// tw/commands/serve.ts
|
|
296953
297306
|
import { join as join32 } from "node:path";
|
|
296954
|
-
import { existsSync as
|
|
297307
|
+
import { existsSync as existsSync29 } from "node:fs";
|
|
296955
297308
|
async function serveCommand() {
|
|
296956
297309
|
const args = process.argv.slice(3);
|
|
296957
297310
|
if (args.includes("-h") || args.includes("--help")) {
|
|
@@ -296987,10 +297340,10 @@ async function serveCommand() {
|
|
|
296987
297340
|
const rootDir = process.cwd();
|
|
296988
297341
|
let outDir = join32(rootDir, ".tw");
|
|
296989
297342
|
const envPath = join32(rootDir, ".env");
|
|
296990
|
-
if (
|
|
297343
|
+
if (existsSync29(envPath)) {
|
|
296991
297344
|
try {
|
|
296992
|
-
const { readFileSync:
|
|
296993
|
-
for (const line of
|
|
297345
|
+
const { readFileSync: readFileSync30 } = await import("node:fs");
|
|
297346
|
+
for (const line of readFileSync30(envPath, "utf-8").split("\n")) {
|
|
296994
297347
|
const m = /^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/.exec(line);
|
|
296995
297348
|
if (m && !(m[1] in process.env)) {
|
|
296996
297349
|
process.env[m[1]] = m[2].replace(/^["']|["']$/g, "");
|
|
@@ -297003,7 +297356,7 @@ async function serveCommand() {
|
|
|
297003
297356
|
let config = {};
|
|
297004
297357
|
try {
|
|
297005
297358
|
const cfgPath = join32(rootDir, "tw.config.ts");
|
|
297006
|
-
if (
|
|
297359
|
+
if (existsSync29(cfgPath)) {
|
|
297007
297360
|
const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
297008
297361
|
const cfgMod = await twImportTs2(cfgPath);
|
|
297009
297362
|
config = cfgMod.default ?? cfgMod;
|
|
@@ -297030,7 +297383,7 @@ async function serveCommand() {
|
|
|
297030
297383
|
} catch {
|
|
297031
297384
|
}
|
|
297032
297385
|
console.debug("\n tw serve -- starting production server\n");
|
|
297033
|
-
if (!
|
|
297386
|
+
if (!existsSync29(outDir)) {
|
|
297034
297387
|
console.debug(" No build found. Run 'tw build' first.\n");
|
|
297035
297388
|
process.exit(1);
|
|
297036
297389
|
}
|
|
@@ -297128,7 +297481,7 @@ function startStaticServer(outDir, port, host) {
|
|
|
297128
297481
|
});
|
|
297129
297482
|
}
|
|
297130
297483
|
const notFoundPath = join32(outDir, "404.html");
|
|
297131
|
-
if (
|
|
297484
|
+
if (existsSync29(notFoundPath)) {
|
|
297132
297485
|
const nf = Bun.file(notFoundPath);
|
|
297133
297486
|
return new Response(nf, { status: 404, headers: { "Content-Type": "text/html" } });
|
|
297134
297487
|
}
|
|
@@ -297143,14 +297496,14 @@ function startStaticServer(outDir, port, host) {
|
|
|
297143
297496
|
|
|
297144
297497
|
// tw/commands/ship.ts
|
|
297145
297498
|
import { join as join34, resolve as resolve10 } from "node:path";
|
|
297146
|
-
import { existsSync as
|
|
297499
|
+
import { existsSync as existsSync31, readFileSync as readFileSync22, writeFileSync as writeFileSync12 } from "node:fs";
|
|
297147
297500
|
async function loadAdapters(rootDir) {
|
|
297148
297501
|
const candidates = [
|
|
297149
297502
|
resolve10(rootDir, "node_modules", "@tw", "adapters", "tw", "index.ts"),
|
|
297150
297503
|
resolve10(rootDir, "node_modules", "@tw", "adapters", "tw", "index.js")
|
|
297151
297504
|
];
|
|
297152
297505
|
for (const c of candidates) {
|
|
297153
|
-
if (
|
|
297506
|
+
if (existsSync31(c)) {
|
|
297154
297507
|
try {
|
|
297155
297508
|
return await import(c);
|
|
297156
297509
|
} catch {
|
|
@@ -297169,7 +297522,7 @@ async function shipCommand() {
|
|
|
297169
297522
|
const rootDir = process.cwd();
|
|
297170
297523
|
const outDir = join34(rootDir, ".tw");
|
|
297171
297524
|
console.log("\n tw ship -- deploy project\n");
|
|
297172
|
-
if (!
|
|
297525
|
+
if (!existsSync31(outDir)) {
|
|
297173
297526
|
console.log(" No build found. Running build first...\n");
|
|
297174
297527
|
try {
|
|
297175
297528
|
const { buildCommand: buildCommand2 } = await init_build().then(() => build_exports);
|
|
@@ -297182,13 +297535,13 @@ async function shipCommand() {
|
|
|
297182
297535
|
}
|
|
297183
297536
|
let deployTarget = target;
|
|
297184
297537
|
if (target === "auto") {
|
|
297185
|
-
if (
|
|
297538
|
+
if (existsSync31(join34(rootDir, "vercel.json"))) {
|
|
297186
297539
|
deployTarget = "vercel";
|
|
297187
|
-
} else if (
|
|
297540
|
+
} else if (existsSync31(join34(rootDir, "netlify.toml"))) {
|
|
297188
297541
|
deployTarget = "netlify";
|
|
297189
|
-
} else if (
|
|
297542
|
+
} else if (existsSync31(join34(rootDir, "wrangler.toml"))) {
|
|
297190
297543
|
deployTarget = "cloudflare";
|
|
297191
|
-
} else if (
|
|
297544
|
+
} else if (existsSync31(join34(rootDir, "Dockerfile"))) {
|
|
297192
297545
|
deployTarget = "docker";
|
|
297193
297546
|
} else {
|
|
297194
297547
|
deployTarget = "static";
|
|
@@ -297248,13 +297601,13 @@ async function shipCommand() {
|
|
|
297248
297601
|
async function generateVercelConfig(rootDir, outDir) {
|
|
297249
297602
|
const adapters = await loadAdapters(rootDir);
|
|
297250
297603
|
const configPath = join34(rootDir, "vercel.json");
|
|
297251
|
-
if (
|
|
297604
|
+
if (existsSync31(configPath)) {
|
|
297252
297605
|
console.log(" OK vercel.json already exists (left unchanged)");
|
|
297253
297606
|
if (adapters?.readBuildSummary && adapters?.needsServer) {
|
|
297254
297607
|
if (adapters.needsServer(adapters.readBuildSummary(rootDir))) {
|
|
297255
297608
|
let raw = "";
|
|
297256
297609
|
try {
|
|
297257
|
-
raw =
|
|
297610
|
+
raw = readFileSync22(configPath, "utf-8");
|
|
297258
297611
|
} catch {
|
|
297259
297612
|
}
|
|
297260
297613
|
if (!/"functions"|"rewrites"/.test(raw)) {
|
|
@@ -297270,7 +297623,7 @@ async function generateVercelConfig(rootDir, outDir) {
|
|
|
297270
297623
|
for (const w of adapters.generateAdapter("vercel", rootDir)) console.log(" OK " + w.replace(rootDir + "/", ""));
|
|
297271
297624
|
return;
|
|
297272
297625
|
}
|
|
297273
|
-
|
|
297626
|
+
writeFileSync12(configPath, JSON.stringify({ buildCommand: "npx tw build", installCommand: "npm install", outputDirectory: ".tw", framework: null }, null, 2));
|
|
297274
297627
|
console.log(" OK Generated vercel.json");
|
|
297275
297628
|
}
|
|
297276
297629
|
function generateNetlifyConfig(rootDir, outDir) {
|
|
@@ -297281,9 +297634,9 @@ function generateNetlifyConfig(rootDir, outDir) {
|
|
|
297281
297634
|
[build.environment]
|
|
297282
297635
|
NODE_VERSION = "20"`;
|
|
297283
297636
|
const configPath = join34(rootDir, "netlify.toml");
|
|
297284
|
-
const existing =
|
|
297637
|
+
const existing = existsSync31(configPath);
|
|
297285
297638
|
if (!existing) {
|
|
297286
|
-
|
|
297639
|
+
writeFileSync12(configPath, config);
|
|
297287
297640
|
console.log(" OK Generated netlify.toml");
|
|
297288
297641
|
} else {
|
|
297289
297642
|
console.log(" OK netlify.toml already exists");
|
|
@@ -297296,9 +297649,9 @@ compatibility_date = "2024-01-01"
|
|
|
297296
297649
|
[assets]
|
|
297297
297650
|
directory = ".tw"`;
|
|
297298
297651
|
const configPath = join34(rootDir, "wrangler.toml");
|
|
297299
|
-
const existing =
|
|
297652
|
+
const existing = existsSync31(configPath);
|
|
297300
297653
|
if (!existing) {
|
|
297301
|
-
|
|
297654
|
+
writeFileSync12(configPath, config);
|
|
297302
297655
|
console.log(" OK Generated wrangler.toml");
|
|
297303
297656
|
} else {
|
|
297304
297657
|
console.log(" OK wrangler.toml already exists");
|
|
@@ -297336,9 +297689,9 @@ COPY --from=build /app ./
|
|
|
297336
297689
|
EXPOSE 8000
|
|
297337
297690
|
CMD ["bunx", "tw", "serve"]`;
|
|
297338
297691
|
const configPath = join34(rootDir, "Dockerfile");
|
|
297339
|
-
const existing =
|
|
297692
|
+
const existing = existsSync31(configPath);
|
|
297340
297693
|
if (!existing) {
|
|
297341
|
-
|
|
297694
|
+
writeFileSync12(configPath, dockerfile);
|
|
297342
297695
|
console.log(" OK Generated Dockerfile");
|
|
297343
297696
|
} else {
|
|
297344
297697
|
console.log(" OK Dockerfile already exists");
|
|
@@ -297347,7 +297700,7 @@ CMD ["bunx", "tw", "serve"]`;
|
|
|
297347
297700
|
|
|
297348
297701
|
// tw/commands/adapter.ts
|
|
297349
297702
|
import { join as join35, resolve as resolve11 } from "node:path";
|
|
297350
|
-
import { existsSync as
|
|
297703
|
+
import { existsSync as existsSync32, readdirSync as readdirSync11, readFileSync as readFileSync23 } from "node:fs";
|
|
297351
297704
|
async function adapterCommand() {
|
|
297352
297705
|
const args = process.argv.slice(3);
|
|
297353
297706
|
const rootDir = process.cwd();
|
|
@@ -297358,7 +297711,7 @@ async function adapterCommand() {
|
|
|
297358
297711
|
let adaptersMod = null;
|
|
297359
297712
|
let via = "";
|
|
297360
297713
|
for (const c of candidates) {
|
|
297361
|
-
if (
|
|
297714
|
+
if (existsSync32(c)) {
|
|
297362
297715
|
adaptersMod = await import(c);
|
|
297363
297716
|
via = c;
|
|
297364
297717
|
break;
|
|
@@ -297413,7 +297766,7 @@ async function adapterCommand() {
|
|
|
297413
297766
|
const apiRoots = [join35(rootDir, ".tw", "api"), join35(rootDir, "api")];
|
|
297414
297767
|
let apiCount = 0;
|
|
297415
297768
|
const countTwm = (dir) => {
|
|
297416
|
-
if (!
|
|
297769
|
+
if (!existsSync32(dir)) return;
|
|
297417
297770
|
for (const entry of readdirSync11(dir, { withFileTypes: true })) {
|
|
297418
297771
|
const full = join35(dir, entry.name);
|
|
297419
297772
|
if (entry.isDirectory()) countTwm(full);
|
|
@@ -297423,7 +297776,7 @@ async function adapterCommand() {
|
|
|
297423
297776
|
for (const r of apiRoots) countTwm(r);
|
|
297424
297777
|
let ssrCount = 0;
|
|
297425
297778
|
const countSsr = (dir) => {
|
|
297426
|
-
if (!
|
|
297779
|
+
if (!existsSync32(dir)) return;
|
|
297427
297780
|
for (const entry of readdirSync11(dir, { withFileTypes: true })) {
|
|
297428
297781
|
const full = join35(dir, entry.name);
|
|
297429
297782
|
if (entry.isDirectory()) {
|
|
@@ -297431,7 +297784,7 @@ async function adapterCommand() {
|
|
|
297431
297784
|
continue;
|
|
297432
297785
|
}
|
|
297433
297786
|
if (entry.name !== "page.tw") continue;
|
|
297434
|
-
const src =
|
|
297787
|
+
const src = readFileSync23(full, "utf-8");
|
|
297435
297788
|
const m = src.match(/render\s+(ssr|stream|csr|ppr)\b/);
|
|
297436
297789
|
if (m) ssrCount++;
|
|
297437
297790
|
}
|
|
@@ -297459,10 +297812,10 @@ async function adapterCommand() {
|
|
|
297459
297812
|
// tw/commands/test.ts
|
|
297460
297813
|
import { join as join37 } from "node:path";
|
|
297461
297814
|
import { createRequire as _cr } from "node:module";
|
|
297462
|
-
import { existsSync as
|
|
297815
|
+
import { existsSync as existsSync33, readdirSync as readdirSync12, statSync as statSync11, readFileSync as readFileSync25 } from "node:fs";
|
|
297463
297816
|
var _require = _cr(import.meta.url);
|
|
297464
297817
|
function collectTests(dir, out) {
|
|
297465
|
-
if (!
|
|
297818
|
+
if (!existsSync33(dir)) return;
|
|
297466
297819
|
for (const entry of readdirSync12(dir)) {
|
|
297467
297820
|
const full = join37(dir, entry);
|
|
297468
297821
|
if (statSync11(full).isDirectory()) collectTests(full, out);
|
|
@@ -297473,10 +297826,10 @@ function ensureTestingShim(rootDir) {
|
|
|
297473
297826
|
try {
|
|
297474
297827
|
const shimPkgDir = join37(rootDir, "node_modules", "@tw", "server");
|
|
297475
297828
|
const marker = join37(shimPkgDir, "package.json");
|
|
297476
|
-
if (
|
|
297477
|
-
const { mkdirSync: mkdirSync12, writeFileSync:
|
|
297829
|
+
if (existsSync33(marker)) return;
|
|
297830
|
+
const { mkdirSync: mkdirSync12, writeFileSync: writeFileSync15 } = _require("node:fs");
|
|
297478
297831
|
mkdirSync12(join37(shimPkgDir, "tw"), { recursive: true });
|
|
297479
|
-
|
|
297832
|
+
writeFileSync15(marker, JSON.stringify({ name: "@tw/server", version: "2.0.5", private: true }, null, 2));
|
|
297480
297833
|
let testingBundle = null;
|
|
297481
297834
|
try {
|
|
297482
297835
|
const here = new URL(".", import.meta.url).pathname;
|
|
@@ -297485,7 +297838,7 @@ function ensureTestingShim(rootDir) {
|
|
|
297485
297838
|
join37(here, "..", "..", "dist", "testing.cjs")
|
|
297486
297839
|
];
|
|
297487
297840
|
for (const c of candidates) {
|
|
297488
|
-
if (
|
|
297841
|
+
if (existsSync33(c)) {
|
|
297489
297842
|
testingBundle = c;
|
|
297490
297843
|
break;
|
|
297491
297844
|
}
|
|
@@ -297496,7 +297849,7 @@ function ensureTestingShim(rootDir) {
|
|
|
297496
297849
|
console.warn(" [tw test] testing bundle not found (dist/testing.cjs); test helpers unavailable");
|
|
297497
297850
|
return;
|
|
297498
297851
|
}
|
|
297499
|
-
|
|
297852
|
+
writeFileSync15(
|
|
297500
297853
|
join37(shimPkgDir, "tw", "testing.js"),
|
|
297501
297854
|
"// Generated by `tw test` -- shim pointing at the CLI testing bundle.\nmodule.exports = require(" + JSON.stringify(testingBundle) + ");\n"
|
|
297502
297855
|
);
|
|
@@ -297509,7 +297862,7 @@ async function testCommand() {
|
|
|
297509
297862
|
ensureTestingShim(rootDir);
|
|
297510
297863
|
const files = [];
|
|
297511
297864
|
collectTests(testsDir, files);
|
|
297512
|
-
if (
|
|
297865
|
+
if (existsSync33(rootDir)) {
|
|
297513
297866
|
for (const f of readdirSync12(rootDir)) {
|
|
297514
297867
|
if (/\.test\.(ts|tsx|js)$/.test(f)) files.push(join37(rootDir, f));
|
|
297515
297868
|
}
|
|
@@ -297517,7 +297870,7 @@ async function testCommand() {
|
|
|
297517
297870
|
console.log("\n tw test -- running " + files.length + " test file" + (files.length === 1 ? "" : "s") + "\n");
|
|
297518
297871
|
for (const f of files) {
|
|
297519
297872
|
try {
|
|
297520
|
-
const src =
|
|
297873
|
+
const src = readFileSync25(f, "utf-8");
|
|
297521
297874
|
const hasBunTest = src.includes("bun:test");
|
|
297522
297875
|
const hasTestCall = /\b(test|it|describe)\s*\(/.test(src);
|
|
297523
297876
|
if (!hasBunTest && !hasTestCall) {
|
|
@@ -297559,15 +297912,28 @@ async function testCommand() {
|
|
|
297559
297912
|
// tw/commands/check.ts
|
|
297560
297913
|
init_tw();
|
|
297561
297914
|
init_components();
|
|
297562
|
-
import { join as join38, dirname as
|
|
297563
|
-
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";
|
|
297564
297917
|
async function checkCommand() {
|
|
297565
297918
|
const args = process.argv.slice(3);
|
|
297566
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
|
+
}
|
|
297567
297933
|
const srcDir = join38(rootDir, "home");
|
|
297568
297934
|
console.debug("\n tw check -- running type check and diagnostics\n");
|
|
297569
297935
|
const twFiles = [];
|
|
297570
|
-
if (
|
|
297936
|
+
if (existsSync34(srcDir)) {
|
|
297571
297937
|
collectFiles2(srcDir, ".tw", twFiles);
|
|
297572
297938
|
}
|
|
297573
297939
|
if (twFiles.length === 0) {
|
|
@@ -297589,7 +297955,7 @@ async function checkCommand() {
|
|
|
297589
297955
|
for (const filePath of twFiles) {
|
|
297590
297956
|
const relativePath = filePath.replace(rootDir + "/", "");
|
|
297591
297957
|
try {
|
|
297592
|
-
const source =
|
|
297958
|
+
const source = readFileSync26(filePath, "utf-8");
|
|
297593
297959
|
registerImportedComponents(filePath, rootDir, { compileSync: compileSync4, registerComponentTemplate: registerComponentTemplate3, clearComponentRegistry: clearComponentRegistry3 }, source);
|
|
297594
297960
|
const result = await compile2(source, {
|
|
297595
297961
|
filePath,
|
|
@@ -297601,7 +297967,7 @@ async function checkCommand() {
|
|
|
297601
297967
|
const errors = diagnostics.filter((d) => d.severity === "error");
|
|
297602
297968
|
const warnings = diagnostics.filter((d) => d.severity === "warning");
|
|
297603
297969
|
const info = diagnostics.filter((d) => d.severity === "info");
|
|
297604
|
-
const checkSource =
|
|
297970
|
+
const checkSource = readFileSync26(filePath, "utf-8");
|
|
297605
297971
|
const usedTags = /* @__PURE__ */ new Set();
|
|
297606
297972
|
const collectUsed = (n) => {
|
|
297607
297973
|
if (!n) return;
|
|
@@ -297627,7 +297993,7 @@ async function checkCommand() {
|
|
|
297627
297993
|
const unknownComponents = [];
|
|
297628
297994
|
for (const tag2 of usedTags) {
|
|
297629
297995
|
if (SAFE_TAGS.has(tag2) || importedNames.has(tag2)) continue;
|
|
297630
|
-
if (findComponentUp(
|
|
297996
|
+
if (findComponentUp(dirname17(filePath), tag2)) continue;
|
|
297631
297997
|
unknownComponents.push(tag2);
|
|
297632
297998
|
}
|
|
297633
297999
|
if (unknownComponents.length > 0) {
|
|
@@ -297637,14 +298003,18 @@ async function checkCommand() {
|
|
|
297637
298003
|
}
|
|
297638
298004
|
totalWarnings += unknownComponents.length;
|
|
297639
298005
|
}
|
|
297640
|
-
|
|
297641
|
-
|
|
297642
|
-
|
|
297643
|
-
|
|
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) {
|
|
297644
298014
|
console.debug(` OK ${relativePath} -- no issues`);
|
|
297645
298015
|
} else {
|
|
297646
|
-
console.debug(` ? ${relativePath} -- ${
|
|
297647
|
-
for (const d of
|
|
298016
|
+
console.debug(` ? ${relativePath} -- ${keptErrors.length} errors, ${keptWarnings.length} warnings, ${keptInfo.length} info`);
|
|
298017
|
+
for (const d of kept) {
|
|
297648
298018
|
const sev = d.severity === "error" ? "?" : d.severity === "warning" ? "?" : "?";
|
|
297649
298019
|
const loc = `line ${d.line}, col ${d.col}`;
|
|
297650
298020
|
console.debug(` ${sev} ${d.code} ${loc}: ${d.message}`);
|
|
@@ -297658,7 +298028,7 @@ async function checkCommand() {
|
|
|
297658
298028
|
} else {
|
|
297659
298029
|
for (const filePath of twFiles) {
|
|
297660
298030
|
const relativePath = filePath.replace(rootDir + "/", "");
|
|
297661
|
-
const source =
|
|
298031
|
+
const source = readFileSync26(filePath, "utf-8");
|
|
297662
298032
|
const maskedSource = maskSourceStringsAndComments(source);
|
|
297663
298033
|
const openBraces = (maskedSource.match(/\{/g) || []).length;
|
|
297664
298034
|
const closeBraces = (maskedSource.match(/\}/g) || []).length;
|
|
@@ -297698,10 +298068,10 @@ function findComponentUp(dir, name) {
|
|
|
297698
298068
|
for (let i = 0; i < 12 && cur && cur !== "/"; i++) {
|
|
297699
298069
|
try {
|
|
297700
298070
|
const candidate = join38(cur, "components", name + ".tw");
|
|
297701
|
-
if (
|
|
298071
|
+
if (existsSync34(candidate)) return true;
|
|
297702
298072
|
} catch {
|
|
297703
298073
|
}
|
|
297704
|
-
const parent =
|
|
298074
|
+
const parent = dirname17(cur);
|
|
297705
298075
|
if (parent === cur) break;
|
|
297706
298076
|
cur = parent;
|
|
297707
298077
|
}
|
|
@@ -297724,38 +298094,38 @@ function collectFiles2(dir, ext, results) {
|
|
|
297724
298094
|
init_tw();
|
|
297725
298095
|
init_tw8();
|
|
297726
298096
|
import { join as join39 } from "node:path";
|
|
297727
|
-
import { existsSync as
|
|
298097
|
+
import { existsSync as existsSync35, readFileSync as readFileSync27, writeFileSync as writeFileSync14, mkdirSync as mkdirSync11, readdirSync as readdirSync14 } from "node:fs";
|
|
297728
298098
|
function readConfigPlugins(cfgPath) {
|
|
297729
|
-
if (!
|
|
297730
|
-
const src = stripCommentsStringAware(
|
|
298099
|
+
if (!existsSync35(cfgPath)) return [];
|
|
298100
|
+
const src = stripCommentsStringAware(readFileSync27(cfgPath, "utf-8"));
|
|
297731
298101
|
return readPluginSpecs(src);
|
|
297732
298102
|
}
|
|
297733
298103
|
function addConfigPlugin(cfgPath, name) {
|
|
297734
|
-
if (!
|
|
297735
|
-
|
|
298104
|
+
if (!existsSync35(cfgPath)) {
|
|
298105
|
+
writeFileSync14(cfgPath, `export default {
|
|
297736
298106
|
plugins: ["${name}"],
|
|
297737
298107
|
};
|
|
297738
298108
|
`);
|
|
297739
298109
|
return true;
|
|
297740
298110
|
}
|
|
297741
|
-
const src = stripCommentsStringAware(
|
|
298111
|
+
const src = stripCommentsStringAware(readFileSync27(cfgPath, "utf-8"));
|
|
297742
298112
|
if (new RegExp(`["'\`]${name}["'\`]`).test(src)) return false;
|
|
297743
298113
|
const m = /plugins\s*:\s*\[([^\]]*)\]/s.exec(src);
|
|
297744
298114
|
if (m) {
|
|
297745
298115
|
const inner = m[1].trim();
|
|
297746
298116
|
const next = inner.length ? `${inner}, "${name}"` : `"${name}"`;
|
|
297747
|
-
|
|
298117
|
+
writeFileSync14(cfgPath, src.replace(m[0], `plugins: [${next}]`));
|
|
297748
298118
|
} else {
|
|
297749
298119
|
const idx = src.lastIndexOf("}");
|
|
297750
298120
|
if (idx === -1) return false;
|
|
297751
|
-
|
|
298121
|
+
writeFileSync14(cfgPath, src.slice(0, idx) + ` plugins: ["${name}"],
|
|
297752
298122
|
` + src.slice(idx));
|
|
297753
298123
|
}
|
|
297754
298124
|
return true;
|
|
297755
298125
|
}
|
|
297756
298126
|
function removeConfigPlugin(cfgPath, name) {
|
|
297757
|
-
if (!
|
|
297758
|
-
const src =
|
|
298127
|
+
if (!existsSync35(cfgPath)) return false;
|
|
298128
|
+
const src = readFileSync27(cfgPath, "utf-8");
|
|
297759
298129
|
const masked = maskSourceStringsAndComments(src);
|
|
297760
298130
|
const range2 = pluginsArrayRange(masked);
|
|
297761
298131
|
if (!range2) return false;
|
|
@@ -297763,12 +298133,12 @@ function removeConfigPlugin(cfgPath, name) {
|
|
|
297763
298133
|
const kept = entries.map((e) => e.trim()).filter((e) => e && entryName(e) !== name);
|
|
297764
298134
|
if (kept.length === entries.filter((e) => e.trim()).length) return false;
|
|
297765
298135
|
const body = kept.length ? " " + kept.join(", ") + " " : "";
|
|
297766
|
-
|
|
298136
|
+
writeFileSync14(cfgPath, src.slice(0, range2.start) + body + src.slice(range2.end));
|
|
297767
298137
|
return true;
|
|
297768
298138
|
}
|
|
297769
298139
|
function listPluginFiles(rootDir) {
|
|
297770
298140
|
const dir = join39(rootDir, "plugins");
|
|
297771
|
-
if (!
|
|
298141
|
+
if (!existsSync35(dir)) return [];
|
|
297772
298142
|
return readdirSync14(dir).filter((f) => f.endsWith(".ts") && !f.endsWith(".d.ts"));
|
|
297773
298143
|
}
|
|
297774
298144
|
async function searchPlugins(term) {
|
|
@@ -297826,7 +298196,7 @@ async function initPluginPackage(rootDir, name) {
|
|
|
297826
298196
|
}
|
|
297827
298197
|
const pkgName = name.startsWith("tw-plugin-") ? name : `tw-plugin-${name}`;
|
|
297828
298198
|
const dir = join39(rootDir, pkgName);
|
|
297829
|
-
if (
|
|
298199
|
+
if (existsSync35(dir)) {
|
|
297830
298200
|
console.error(` Already exists: ${pkgName}/`);
|
|
297831
298201
|
process.exit(1);
|
|
297832
298202
|
}
|
|
@@ -297845,7 +298215,7 @@ async function initPluginPackage(rootDir, name) {
|
|
|
297845
298215
|
peerDependencies: { "tw-framework": ">=2.0.0" },
|
|
297846
298216
|
license: "MIT"
|
|
297847
298217
|
};
|
|
297848
|
-
|
|
298218
|
+
writeFileSync14(join39(dir, "package.json"), JSON.stringify(manifest, null, 2) + "\n");
|
|
297849
298219
|
const src = `import type { TWPlugin } from "tw-framework/plugins";
|
|
297850
298220
|
|
|
297851
298221
|
/**
|
|
@@ -297872,7 +298242,7 @@ const plugin: TWPlugin = {
|
|
|
297872
298242
|
|
|
297873
298243
|
export default plugin;
|
|
297874
298244
|
`;
|
|
297875
|
-
|
|
298245
|
+
writeFileSync14(join39(dir, "src", "index.ts"), src);
|
|
297876
298246
|
const readme = `# ${pkgName}
|
|
297877
298247
|
|
|
297878
298248
|
A TW Framework plugin.
|
|
@@ -297890,9 +298260,9 @@ server with Bun (\`tw serve\`) \u2014 plugins load as TypeScript modules.
|
|
|
297890
298260
|
|
|
297891
298261
|
Describe the hooks and routes this plugin registers.
|
|
297892
298262
|
`;
|
|
297893
|
-
|
|
298263
|
+
writeFileSync14(join39(dir, "README.md"), readme);
|
|
297894
298264
|
const gitignore = "node_modules/\ndist/\n*.log\n";
|
|
297895
|
-
|
|
298265
|
+
writeFileSync14(join39(dir, ".gitignore"), gitignore);
|
|
297896
298266
|
console.log(`
|
|
297897
298267
|
Created ${pkgName}/`);
|
|
297898
298268
|
console.log(` package.json name + the "tw-plugin" keyword (required for search)`);
|
|
@@ -297907,12 +298277,12 @@ Describe the hooks and routes this plugin registers.
|
|
|
297907
298277
|
}
|
|
297908
298278
|
async function upgradePlugins(rootDir, opts) {
|
|
297909
298279
|
const cfgPath = join39(rootDir, "tw.config.ts");
|
|
297910
|
-
if (!
|
|
298280
|
+
if (!existsSync35(cfgPath)) {
|
|
297911
298281
|
console.error(" No tw.config.ts here. Run this from a project root.\n");
|
|
297912
298282
|
process.exit(1);
|
|
297913
298283
|
}
|
|
297914
298284
|
const { readPluginSpecs: readPluginSpecs2, planUpgrade: planUpgrade2, outdated: outdated2 } = await Promise.resolve().then(() => (init_tw8(), tw_exports4));
|
|
297915
|
-
const specs = readPluginSpecs2(
|
|
298285
|
+
const specs = readPluginSpecs2(readFileSync27(cfgPath, "utf-8"));
|
|
297916
298286
|
if (specs.length === 0) {
|
|
297917
298287
|
console.log("\n No plugins in tw.config.ts -- nothing to upgrade.\n");
|
|
297918
298288
|
return;
|
|
@@ -298014,7 +298384,7 @@ async function pluginCommand() {
|
|
|
298014
298384
|
console.error("Usage: tw plugin add <name>");
|
|
298015
298385
|
process.exit(1);
|
|
298016
298386
|
}
|
|
298017
|
-
if (!
|
|
298387
|
+
if (!existsSync35(join39(rootDir, "plugins", `${name}.ts`))) {
|
|
298018
298388
|
console.error(` No file plugins/${name}.ts -- create it first: tw plugin create ${name}`);
|
|
298019
298389
|
process.exit(1);
|
|
298020
298390
|
}
|
|
@@ -298042,11 +298412,11 @@ async function pluginCommand() {
|
|
|
298042
298412
|
const pluginsDir = join39(rootDir, "plugins");
|
|
298043
298413
|
mkdirSync11(pluginsDir, { recursive: true });
|
|
298044
298414
|
const file = join39(pluginsDir, `${name}.ts`);
|
|
298045
|
-
if (
|
|
298415
|
+
if (existsSync35(file)) {
|
|
298046
298416
|
console.error(` Already exists: plugins/${name}.ts`);
|
|
298047
298417
|
process.exit(1);
|
|
298048
298418
|
}
|
|
298049
|
-
|
|
298419
|
+
writeFileSync14(file, `/** ${name} - TW Framework plugin */
|
|
298050
298420
|
|
|
298051
298421
|
import type { TWPlugin } from "@tw/plugins";
|
|
298052
298422
|
|
|
@@ -298166,10 +298536,10 @@ var colors = {
|
|
|
298166
298536
|
|
|
298167
298537
|
// tw/commands/lsp.ts
|
|
298168
298538
|
import { join as join40 } from "node:path";
|
|
298169
|
-
import { existsSync as
|
|
298539
|
+
import { existsSync as existsSync36 } from "node:fs";
|
|
298170
298540
|
async function lspCommand() {
|
|
298171
298541
|
const rootDir = process.cwd();
|
|
298172
|
-
if (!
|
|
298542
|
+
if (!existsSync36(join40(rootDir, "tw.config.ts")) && !existsSync36(join40(rootDir, "home"))) {
|
|
298173
298543
|
console.error(`${colors.yellow("!")} Not inside a TW project (no tw.config.ts / home/) \u2014 starting anyway from ${rootDir}`);
|
|
298174
298544
|
}
|
|
298175
298545
|
console.error(` ${colors.bold("tw lsp")} \u2014 language server on stdio`);
|
|
@@ -298185,7 +298555,7 @@ async function lspCommand() {
|
|
|
298185
298555
|
// tw/commands/doctor.ts
|
|
298186
298556
|
init_tw();
|
|
298187
298557
|
init_tw();
|
|
298188
|
-
import { existsSync as
|
|
298558
|
+
import { existsSync as existsSync37 } from "node:fs";
|
|
298189
298559
|
import { join as join41 } from "node:path";
|
|
298190
298560
|
var C = {
|
|
298191
298561
|
reset: "\x1B[0m",
|
|
@@ -298201,7 +298571,7 @@ var warn = (s) => `${C.yellow}!${C.reset} ${s}`;
|
|
|
298201
298571
|
var bad = (s) => `${C.red}\u2717${C.reset} ${s}`;
|
|
298202
298572
|
function hasPackage4(rootDir, name) {
|
|
298203
298573
|
for (const base of [rootDir, process.cwd()]) {
|
|
298204
|
-
if (
|
|
298574
|
+
if (existsSync37(join41(base, "node_modules", name))) return true;
|
|
298205
298575
|
}
|
|
298206
298576
|
return false;
|
|
298207
298577
|
}
|
|
@@ -298272,7 +298642,7 @@ async function doctorCommand() {
|
|
|
298272
298642
|
let cfg = null;
|
|
298273
298643
|
try {
|
|
298274
298644
|
const tsPath = join41(rootDir, "tw.config.ts");
|
|
298275
|
-
if (
|
|
298645
|
+
if (existsSync37(tsPath)) {
|
|
298276
298646
|
const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
298277
298647
|
const mod = await twImportTs2(tsPath);
|
|
298278
298648
|
cfg = mod?.default ?? mod;
|
|
@@ -298368,13 +298738,13 @@ async function doctorCommand() {
|
|
|
298368
298738
|
}
|
|
298369
298739
|
|
|
298370
298740
|
// tw/help.ts
|
|
298371
|
-
import { readFileSync as
|
|
298741
|
+
import { readFileSync as readFileSync28 } from "node:fs";
|
|
298372
298742
|
import { join as join42 } from "node:path";
|
|
298373
298743
|
function cliVersion() {
|
|
298374
298744
|
try {
|
|
298375
298745
|
const bd = globalThis.__TW_BUNDLE_DIR;
|
|
298376
298746
|
const pj = bd ? join42(bd, "..", "package.json") : new URL("../package.json", import.meta.url).pathname;
|
|
298377
|
-
return JSON.parse(
|
|
298747
|
+
return JSON.parse(readFileSync28(pj, "utf-8")).version ?? "0.0.0";
|
|
298378
298748
|
} catch {
|
|
298379
298749
|
return "0.0.0";
|
|
298380
298750
|
}
|
|
@@ -298448,13 +298818,13 @@ var helpText = `
|
|
|
298448
298818
|
|
|
298449
298819
|
// tw/commands/index.ts
|
|
298450
298820
|
await init_build();
|
|
298451
|
-
import { readFileSync as
|
|
298821
|
+
import { readFileSync as readFileSync29 } from "node:fs";
|
|
298452
298822
|
import { join as join43 } from "node:path";
|
|
298453
298823
|
var VERSION2 = (() => {
|
|
298454
298824
|
try {
|
|
298455
298825
|
const bd = globalThis.__TW_BUNDLE_DIR;
|
|
298456
298826
|
const pj = bd ? join43(bd, "..", "package.json") : new URL("../../package.json", import.meta.url).pathname;
|
|
298457
|
-
return JSON.parse(
|
|
298827
|
+
return JSON.parse(readFileSync29(pj, "utf-8")).version ?? "0.0.0";
|
|
298458
298828
|
} catch {
|
|
298459
298829
|
return "0.0.0";
|
|
298460
298830
|
}
|