vela 0.15.0-next.0 → 0.15.0-next.1
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/dist/bin.js +1187 -507
- package/dist/bin.js.map +4 -4
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/bin.ts
|
|
4
|
-
import
|
|
4
|
+
import process51 from "node:process";
|
|
5
5
|
|
|
6
6
|
// src/lib/argv.ts
|
|
7
7
|
function normalizeArgv(argv) {
|
|
@@ -11,7 +11,7 @@ function normalizeArgv(argv) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
// src/program.ts
|
|
14
|
-
import
|
|
14
|
+
import process50 from "node:process";
|
|
15
15
|
import * as p72 from "@clack/prompts";
|
|
16
16
|
import { Command as Command117 } from "commander";
|
|
17
17
|
import nodePath from "node:path";
|
|
@@ -21,7 +21,7 @@ import pc45 from "picocolors";
|
|
|
21
21
|
// package.json
|
|
22
22
|
var package_default = {
|
|
23
23
|
name: "vela",
|
|
24
|
-
version: "0.15.0-next.
|
|
24
|
+
version: "0.15.0-next.1",
|
|
25
25
|
type: "module",
|
|
26
26
|
description: "A CLI for creating and updating SvelteKit projects",
|
|
27
27
|
license: "MIT",
|
|
@@ -298,8 +298,8 @@ function dropTemplateAdapters(user, template) {
|
|
|
298
298
|
}
|
|
299
299
|
return copy;
|
|
300
300
|
}
|
|
301
|
-
function readPackageJson(
|
|
302
|
-
return JSON.parse(fs2.readFileSync(
|
|
301
|
+
function readPackageJson(path61) {
|
|
302
|
+
return JSON.parse(fs2.readFileSync(path61, "utf8"));
|
|
303
303
|
}
|
|
304
304
|
var PACKAGE_NAME_PLACEHOLDER = /~TODO~/g;
|
|
305
305
|
var APP_NAME_PLACEHOLDER = /~APP_NAME~/g;
|
|
@@ -328,12 +328,12 @@ function jsString(value) {
|
|
|
328
328
|
const quote2 = count("'") > count('"') ? '"' : "'";
|
|
329
329
|
return `${quote2}${escapeFor(quote2, value)}${quote2}`;
|
|
330
330
|
}
|
|
331
|
-
function readTemplatePackageJson(
|
|
332
|
-
const raw = fillTemplatePlaceholders(fs2.readFileSync(
|
|
331
|
+
function readTemplatePackageJson(path61, values) {
|
|
332
|
+
const raw = fillTemplatePlaceholders(fs2.readFileSync(path61, "utf8"), values);
|
|
333
333
|
return JSON.parse(raw);
|
|
334
334
|
}
|
|
335
|
-
function writePackageJson(
|
|
336
|
-
fs2.writeFileSync(
|
|
335
|
+
function writePackageJson(path61, pkg) {
|
|
336
|
+
fs2.writeFileSync(path61, JSON.stringify(pkg, null, " ") + "\n");
|
|
337
337
|
}
|
|
338
338
|
function toValidPackageName(name) {
|
|
339
339
|
return name.trim().toLowerCase().replace(/\s+/g, "-").replace(/^[._]/, "").replace(/[^a-z0-9~.-]+/g, "-");
|
|
@@ -419,6 +419,63 @@ function parseVersionPart(text19) {
|
|
|
419
419
|
wildcard: firstWild === 1 ? "major" : firstWild === 2 ? "minor" : void 0
|
|
420
420
|
};
|
|
421
421
|
}
|
|
422
|
+
function rangeAdmits(range, version) {
|
|
423
|
+
const target = parseVersionPart(version)?.version;
|
|
424
|
+
if (!target) return null;
|
|
425
|
+
let unreadable = false;
|
|
426
|
+
for (const alt of range.split("||").map((a) => a.trim())) {
|
|
427
|
+
const comparators = comparatorsOf(alt);
|
|
428
|
+
if (!comparators) {
|
|
429
|
+
unreadable = true;
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
432
|
+
if (comparators.every(([op, v12]) => compare(target, op, v12))) return true;
|
|
433
|
+
}
|
|
434
|
+
return unreadable ? null : false;
|
|
435
|
+
}
|
|
436
|
+
function compare(target, op, v12) {
|
|
437
|
+
const c = compareVersions(target, v12);
|
|
438
|
+
return op === ">=" ? c >= 0 : op === ">" ? c > 0 : op === "<" ? c < 0 : op === "<=" ? c <= 0 : c === 0;
|
|
439
|
+
}
|
|
440
|
+
function comparatorsOf(set) {
|
|
441
|
+
if (set === "" || set === "*" || /^[xX]$/.test(set)) return [];
|
|
442
|
+
const hyphen = set.match(/^(\S+)\s+-\s+(\S+)$/);
|
|
443
|
+
if (hyphen) {
|
|
444
|
+
const low = parseVersionPart(hyphen[1]);
|
|
445
|
+
const high = parseVersionPart(hyphen[2]);
|
|
446
|
+
if (!low || !high) return null;
|
|
447
|
+
return [
|
|
448
|
+
[">=", low.version],
|
|
449
|
+
high.wildcard ? ["<", bump(high.version, high.wildcard)] : ["<=", high.version]
|
|
450
|
+
];
|
|
451
|
+
}
|
|
452
|
+
const out = [];
|
|
453
|
+
for (const part of set.replace(/([<>=~^]+)\s+/g, "$1").split(/\s+/)) {
|
|
454
|
+
const match = part.match(/^(<=|>=|<|>|=|\^|~>?)?(.*)$/);
|
|
455
|
+
const op = match[1] ?? "";
|
|
456
|
+
if (/^[*xX]$/.test(match[2])) continue;
|
|
457
|
+
const parsed = parseVersionPart(match[2]);
|
|
458
|
+
if (!parsed) return null;
|
|
459
|
+
const { version: v12, wildcard } = parsed;
|
|
460
|
+
const written = wildcard === "major" ? 1 : wildcard === "minor" ? 2 : 3;
|
|
461
|
+
if (op === "^") {
|
|
462
|
+
const upper = v12.major > 0 || written === 1 ? bump(v12, "major") : v12.minor > 0 || written === 2 ? bump(v12, "minor") : bump(v12, "patch");
|
|
463
|
+
out.push([">=", v12], ["<", upper]);
|
|
464
|
+
} else if (op === "~" || op === "~>") {
|
|
465
|
+
out.push([">=", v12], ["<", bump(v12, written === 1 ? "major" : "minor")]);
|
|
466
|
+
} else if (op === "" || op === "=") {
|
|
467
|
+
if (wildcard) out.push([">=", v12], ["<", bump(v12, wildcard)]);
|
|
468
|
+
else out.push(["=", v12]);
|
|
469
|
+
} else if (op === ">") {
|
|
470
|
+
out.push(wildcard ? [">=", bump(v12, wildcard)] : [">", v12]);
|
|
471
|
+
} else if (op === "<=") {
|
|
472
|
+
out.push(wildcard ? ["<", bump(v12, wildcard)] : ["<=", v12]);
|
|
473
|
+
} else {
|
|
474
|
+
out.push([op, v12]);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
return out;
|
|
478
|
+
}
|
|
422
479
|
function bump(version, part) {
|
|
423
480
|
if (part === "major") return { major: version.major + 1, minor: 0, patch: 0, prerelease: [] };
|
|
424
481
|
if (part === "minor") return { ...version, minor: version.minor + 1, patch: 0, prerelease: [] };
|
|
@@ -1063,17 +1120,17 @@ async function packageManagerPrompt(cwd) {
|
|
|
1063
1120
|
}
|
|
1064
1121
|
var installedCache = /* @__PURE__ */ new Map();
|
|
1065
1122
|
function isInstalled(agent) {
|
|
1066
|
-
let
|
|
1067
|
-
if (
|
|
1123
|
+
let installed2 = installedCache.get(agent);
|
|
1124
|
+
if (installed2 === void 0) {
|
|
1068
1125
|
try {
|
|
1069
1126
|
execSync(agent, ["--version"], { nodeOptions: { stdio: "ignore" } });
|
|
1070
|
-
|
|
1127
|
+
installed2 = true;
|
|
1071
1128
|
} catch {
|
|
1072
|
-
|
|
1129
|
+
installed2 = false;
|
|
1073
1130
|
}
|
|
1074
|
-
installedCache.set(agent,
|
|
1131
|
+
installedCache.set(agent, installed2);
|
|
1075
1132
|
}
|
|
1076
|
-
return
|
|
1133
|
+
return installed2;
|
|
1077
1134
|
}
|
|
1078
1135
|
async function installDependencies(agent, cwd, { exitOnFailure = true } = {}) {
|
|
1079
1136
|
if (!isInstalled(agent)) {
|
|
@@ -1546,20 +1603,20 @@ var SITE_FILE = path10.join("src", "lib", "site.ts");
|
|
|
1546
1603
|
async function readSite(root) {
|
|
1547
1604
|
const file = path10.join(root, SITE_FILE);
|
|
1548
1605
|
if (!fs12.existsSync(file)) return null;
|
|
1549
|
-
const { Project:
|
|
1550
|
-
const project = new
|
|
1606
|
+
const { Project: Project4, Node: Node3 } = await import("ts-morph");
|
|
1607
|
+
const project = new Project4({ useInMemoryFileSystem: true });
|
|
1551
1608
|
const source = project.createSourceFile("site.ts", fs12.readFileSync(file, "utf8"));
|
|
1552
1609
|
let object6 = source.getVariableDeclaration("site")?.getInitializer();
|
|
1553
|
-
while (object6 && (
|
|
1610
|
+
while (object6 && (Node3.isAsExpression(object6) || Node3.isSatisfiesExpression(object6))) {
|
|
1554
1611
|
object6 = object6.getExpression();
|
|
1555
1612
|
}
|
|
1556
|
-
if (!object6 || !
|
|
1613
|
+
if (!object6 || !Node3.isObjectLiteralExpression(object6)) return null;
|
|
1557
1614
|
const info = {};
|
|
1558
1615
|
for (const key of ["name", "url"]) {
|
|
1559
1616
|
const property = object6.getProperty(key);
|
|
1560
|
-
if (!property || !
|
|
1617
|
+
if (!property || !Node3.isPropertyAssignment(property)) continue;
|
|
1561
1618
|
const value = property.getInitializer();
|
|
1562
|
-
if (
|
|
1619
|
+
if (Node3.isStringLiteral(value) || Node3.isNoSubstitutionTemplateLiteral(value)) {
|
|
1563
1620
|
const text19 = value.getLiteralValue().trim();
|
|
1564
1621
|
if (text19) info[key] = text19;
|
|
1565
1622
|
}
|
|
@@ -1580,6 +1637,7 @@ import fs15 from "node:fs";
|
|
|
1580
1637
|
import path13 from "node:path";
|
|
1581
1638
|
import {
|
|
1582
1639
|
Node,
|
|
1640
|
+
Project as Project2,
|
|
1583
1641
|
SyntaxKind as SyntaxKind2,
|
|
1584
1642
|
ts
|
|
1585
1643
|
} from "ts-morph";
|
|
@@ -1696,8 +1754,8 @@ function kitStatus(root) {
|
|
|
1696
1754
|
declaredMajor: range === void 0 ? null : declaredMajor(range),
|
|
1697
1755
|
svelteConfig: findSvelteConfig(root)
|
|
1698
1756
|
};
|
|
1699
|
-
const
|
|
1700
|
-
if (typeof
|
|
1757
|
+
const installed2 = readPkg(path12.join(root, "node_modules", KIT, "package.json"))?.version;
|
|
1758
|
+
if (typeof installed2 === "string") status3.installedVersion = installed2;
|
|
1701
1759
|
return status3;
|
|
1702
1760
|
}
|
|
1703
1761
|
function declaredMajor(range) {
|
|
@@ -1708,8 +1766,8 @@ function declaredMajor(range) {
|
|
|
1708
1766
|
}
|
|
1709
1767
|
function assertKit3(root, label4) {
|
|
1710
1768
|
const status3 = kitStatus(root);
|
|
1711
|
-
const
|
|
1712
|
-
const why = status3.declaredMajor !== null && status3.declaredMajor < 3 ? `package.json declares ${KIT} ${status3.declaredMajor}.x.` : status3.declaredMajor === null &&
|
|
1769
|
+
const installed2 = installedMajor(status3.installedVersion);
|
|
1770
|
+
const why = status3.declaredMajor !== null && status3.declaredMajor < 3 ? `package.json declares ${KIT} ${status3.declaredMajor}.x.` : status3.declaredMajor === null && installed2 !== null && installed2 < 3 ? `It has ${KIT} ${status3.installedVersion} installed.` : status3.svelteConfig ? `It still has ${path12.basename(status3.svelteConfig)}, which SvelteKit 3 no longer reads.` : null;
|
|
1713
1771
|
if (!why) return;
|
|
1714
1772
|
throw new KitVersionError(
|
|
1715
1773
|
`${label4}: SvelteKit 2 project detected. ${why}
|
|
@@ -1797,19 +1855,35 @@ function mergeRunesIntoViteArg(vite, arg) {
|
|
|
1797
1855
|
return { applied: true, reason: "added runes compilerOption", file };
|
|
1798
1856
|
}
|
|
1799
1857
|
var ORIGIN_SPREAD = `...(process.env.VELA_ORIGIN ? { paths: { origin: process.env.VELA_ORIGIN } } : {})`;
|
|
1800
|
-
function mergeOriginConfig(root) {
|
|
1858
|
+
function mergeOriginConfig(root, options = {}) {
|
|
1801
1859
|
const svelteConfig = findSvelteConfig(root);
|
|
1802
1860
|
if (svelteConfig) return svelteConfigOutcome(svelteConfig);
|
|
1803
1861
|
const vite = inspectViteSveltekit(root);
|
|
1804
|
-
|
|
1862
|
+
const carry = options.carry;
|
|
1863
|
+
let arg = vite?.inlineArg ?? null;
|
|
1864
|
+
if (vite && !arg && carry && !vite.nonObjectArg) arg = createSveltekitArg(vite);
|
|
1865
|
+
if (!vite || !arg) {
|
|
1805
1866
|
return {
|
|
1806
1867
|
applied: false,
|
|
1807
1868
|
reason: "no sveltekit({...}) config, so no prerender.origin to move",
|
|
1808
|
-
file: vite ? path13.basename(vite.filePath) : void 0
|
|
1869
|
+
file: vite ? path13.basename(vite.filePath) : void 0,
|
|
1870
|
+
...carry ? { snippet: carry.text } : {}
|
|
1809
1871
|
};
|
|
1810
1872
|
}
|
|
1811
1873
|
const file = path13.basename(vite.filePath);
|
|
1812
|
-
|
|
1874
|
+
let carried = false;
|
|
1875
|
+
if (carry && !configSetsOrigin(arg)) {
|
|
1876
|
+
if (carry.isPrerenderProperty && arg.getProperty("prerender")) {
|
|
1877
|
+
return {
|
|
1878
|
+
applied: false,
|
|
1879
|
+
reason: `sv dropped the origin from ${carry.from}, and the config already has a \`prerender\` object to merge it into; add it to paths.origin by hand`,
|
|
1880
|
+
snippet: carry.text,
|
|
1881
|
+
file
|
|
1882
|
+
};
|
|
1883
|
+
}
|
|
1884
|
+
arg.addProperty(carry.text);
|
|
1885
|
+
carried = true;
|
|
1886
|
+
}
|
|
1813
1887
|
const sources = findPrerenderOrigins(arg);
|
|
1814
1888
|
const pathsProp = arg.getProperty("paths");
|
|
1815
1889
|
const paths = pathsProp && Node.isPropertyAssignment(pathsProp) ? pathsProp.getInitializerIfKind(SyntaxKind2.ObjectLiteralExpression) : void 0;
|
|
@@ -1843,6 +1917,9 @@ function mergeOriginConfig(root) {
|
|
|
1843
1917
|
const [source] = sources;
|
|
1844
1918
|
const replacement = source.condition ? `...(${source.condition} ? { paths: { origin: ${source.value} } } : {})` : `paths: { origin: ${source.value} }`;
|
|
1845
1919
|
const index = arg.getProperties().indexOf(source.anchor);
|
|
1920
|
+
const staleComment = sources.some((s) => mentionsPrerender(s.node));
|
|
1921
|
+
const inPlace = !hasPathsOrigin && !paths && Node.isSpreadAssignment(source.anchor) ? source : void 0;
|
|
1922
|
+
const orphaned = sources.filter((s) => s !== inPlace).flatMap((s) => s.node.getLeadingCommentRanges().map((c) => c.getText()));
|
|
1846
1923
|
if (hasPathsOrigin) {
|
|
1847
1924
|
for (const s of sources) s.remove();
|
|
1848
1925
|
} else if (paths) {
|
|
@@ -1872,13 +1949,125 @@ function mergeOriginConfig(root) {
|
|
|
1872
1949
|
});
|
|
1873
1950
|
}
|
|
1874
1951
|
}
|
|
1952
|
+
if (staleComment && !hasPathsOrigin && !paths) {
|
|
1953
|
+
const target = arg.getProperties().find((p73) => isOriginElement(p73));
|
|
1954
|
+
if (target) setOriginComment(target);
|
|
1955
|
+
}
|
|
1956
|
+
if (orphaned.length > 0) {
|
|
1957
|
+
let text19 = vite.sourceFile.getFullText();
|
|
1958
|
+
for (const comment of orphaned) {
|
|
1959
|
+
text19 = text19.replace(new RegExp(String.raw`\n[\t ]*${escapeRegExp2(comment)}[\t ]*(?=\n)`), "");
|
|
1960
|
+
}
|
|
1961
|
+
vite.sourceFile.replaceWithText(text19);
|
|
1962
|
+
}
|
|
1875
1963
|
vite.sourceFile.saveSync();
|
|
1964
|
+
const moved = hasPathsOrigin ? "removed prerender.origin, which SvelteKit 3 no longer accepts; kept the existing paths.origin" : "moved prerender.origin to paths.origin";
|
|
1876
1965
|
return {
|
|
1877
1966
|
applied: true,
|
|
1878
|
-
reason:
|
|
1967
|
+
reason: carried ? `restored the origin sv dropped from ${carry.from}, and ${moved}` : moved,
|
|
1879
1968
|
file
|
|
1880
1969
|
};
|
|
1881
1970
|
}
|
|
1971
|
+
function configSetsOrigin(arg) {
|
|
1972
|
+
const prerender = findPrerenderOrigins(arg);
|
|
1973
|
+
if (prerender === "unsupported" || prerender.length > 0) return true;
|
|
1974
|
+
return arg.getProperties().some((p73) => {
|
|
1975
|
+
if (Node.isPropertyAssignment(p73) && p73.getName() === "paths") {
|
|
1976
|
+
const paths = p73.getInitializerIfKind(SyntaxKind2.ObjectLiteralExpression);
|
|
1977
|
+
return paths !== void 0 && hasOrigin(paths);
|
|
1978
|
+
}
|
|
1979
|
+
const spread = conditionalSpreadOf(p73, "paths");
|
|
1980
|
+
return spread !== void 0 && hasOrigin(spread.object);
|
|
1981
|
+
});
|
|
1982
|
+
}
|
|
1983
|
+
function isOriginElement(element) {
|
|
1984
|
+
if (Node.isPropertyAssignment(element) && element.getName() === "paths") return true;
|
|
1985
|
+
return conditionalSpreadOf(element, "paths") !== void 0;
|
|
1986
|
+
}
|
|
1987
|
+
var ORIGIN_COMMENT = [
|
|
1988
|
+
"The public origin, which SvelteKit checks form posts against and uses",
|
|
1989
|
+
"for prerendered pages. `vela deploy` sets VELA_ORIGIN, and the value is",
|
|
1990
|
+
"baked in at build time. It is left unset for a deploy that serves more",
|
|
1991
|
+
"than one host, where each request's own origin is used instead."
|
|
1992
|
+
];
|
|
1993
|
+
function escapeRegExp2(text19) {
|
|
1994
|
+
return text19.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1995
|
+
}
|
|
1996
|
+
function mentionsPrerender(node) {
|
|
1997
|
+
return node.getLeadingCommentRanges().some((c) => /prerender/i.test(c.getText()));
|
|
1998
|
+
}
|
|
1999
|
+
function setOriginComment(node) {
|
|
2000
|
+
const sourceFile = node.getSourceFile();
|
|
2001
|
+
const full = sourceFile.getFullText();
|
|
2002
|
+
const start = node.getStart();
|
|
2003
|
+
const lineStart = full.lastIndexOf("\n", start - 1) + 1;
|
|
2004
|
+
const indent = full.slice(lineStart, start).match(/^[\t ]*/)[0];
|
|
2005
|
+
const comment = ORIGIN_COMMENT.map((line) => `// ${line}`).join(`
|
|
2006
|
+
${indent}`);
|
|
2007
|
+
const ranges = node.getLeadingCommentRanges();
|
|
2008
|
+
if (ranges.length > 0) {
|
|
2009
|
+
sourceFile.replaceText([ranges[0].getPos(), ranges.at(-1).getEnd()], comment);
|
|
2010
|
+
} else {
|
|
2011
|
+
sourceFile.insertText(start, `${comment}
|
|
2012
|
+
${indent}`);
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
function captureSvelteConfig(root) {
|
|
2016
|
+
const filePath = findSvelteConfig(root);
|
|
2017
|
+
if (!filePath) return null;
|
|
2018
|
+
const file = path13.basename(filePath);
|
|
2019
|
+
const capture = { file, spreads: [] };
|
|
2020
|
+
let config;
|
|
2021
|
+
try {
|
|
2022
|
+
const project = new Project2({ compilerOptions: { allowJs: true } });
|
|
2023
|
+
config = configObject(project.addSourceFileAtPath(filePath));
|
|
2024
|
+
} catch {
|
|
2025
|
+
return capture;
|
|
2026
|
+
}
|
|
2027
|
+
if (!config) return capture;
|
|
2028
|
+
const kitProp = config.getProperty("kit");
|
|
2029
|
+
const kit = Node.isPropertyAssignment(kitProp) ? kitProp.getInitializerIfKind(SyntaxKind2.ObjectLiteralExpression) : void 0;
|
|
2030
|
+
for (const object6 of [config, kit]) {
|
|
2031
|
+
for (const element of object6?.getProperties() ?? []) {
|
|
2032
|
+
if (Node.isSpreadAssignment(element)) capture.spreads.push(element.getText());
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
if (!kit) return capture;
|
|
2036
|
+
for (const element of kit.getProperties()) {
|
|
2037
|
+
const spread = conditionalSpreadOf(element, "prerender");
|
|
2038
|
+
const isPrerender = Node.isPropertyAssignment(element) && element.getName() === "prerender";
|
|
2039
|
+
if (!(spread && hasOrigin(spread.object)) && !isPrerender) continue;
|
|
2040
|
+
if (isPrerender) {
|
|
2041
|
+
const prerender = element.getInitializerIfKind(SyntaxKind2.ObjectLiteralExpression);
|
|
2042
|
+
if (!prerender || !hasOrigin(prerender)) continue;
|
|
2043
|
+
}
|
|
2044
|
+
capture.origin = { from: file, text: withComments(element), isPrerenderProperty: isPrerender };
|
|
2045
|
+
break;
|
|
2046
|
+
}
|
|
2047
|
+
return capture;
|
|
2048
|
+
}
|
|
2049
|
+
function withComments(node) {
|
|
2050
|
+
const ranges = node.getLeadingCommentRanges();
|
|
2051
|
+
const start = ranges[0]?.getPos() ?? node.getStart();
|
|
2052
|
+
return node.getSourceFile().getFullText().slice(start, node.getEnd()).split("\n").map((line) => line.trim()).join("\n");
|
|
2053
|
+
}
|
|
2054
|
+
function configObject(sourceFile) {
|
|
2055
|
+
const exported = sourceFile.getExportAssignment((e) => !e.isExportEquals())?.getExpression();
|
|
2056
|
+
let node = exported;
|
|
2057
|
+
for (let depth = 0; node && depth < 5; depth++) {
|
|
2058
|
+
if (Node.isObjectLiteralExpression(node)) return node;
|
|
2059
|
+
if (Node.isParenthesizedExpression(node) || Node.isSatisfiesExpression(node) || Node.isAsExpression(node)) {
|
|
2060
|
+
node = node.getExpression();
|
|
2061
|
+
} else if (Node.isCallExpression(node)) {
|
|
2062
|
+
node = node.getArguments()[0];
|
|
2063
|
+
} else if (Node.isIdentifier(node)) {
|
|
2064
|
+
node = sourceFile.getVariableDeclaration(node.getText())?.getInitializer();
|
|
2065
|
+
} else {
|
|
2066
|
+
return void 0;
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
return void 0;
|
|
2070
|
+
}
|
|
1882
2071
|
function unwrap(node) {
|
|
1883
2072
|
let current = node;
|
|
1884
2073
|
while (Node.isParenthesizedExpression(current)) current = current.getExpression();
|
|
@@ -1927,6 +2116,7 @@ function findPrerenderOrigins(arg) {
|
|
|
1927
2116
|
condition: spread.condition,
|
|
1928
2117
|
value,
|
|
1929
2118
|
anchor: element,
|
|
2119
|
+
node: element,
|
|
1930
2120
|
remove: () => element.remove()
|
|
1931
2121
|
});
|
|
1932
2122
|
continue;
|
|
@@ -1947,6 +2137,7 @@ function findPrerenderOrigins(arg) {
|
|
|
1947
2137
|
condition: conditional.condition,
|
|
1948
2138
|
value,
|
|
1949
2139
|
anchor: element,
|
|
2140
|
+
node: inner,
|
|
1950
2141
|
remove: removeFromPrerender(inner)
|
|
1951
2142
|
});
|
|
1952
2143
|
continue;
|
|
@@ -1957,6 +2148,7 @@ function findPrerenderOrigins(arg) {
|
|
|
1957
2148
|
sources.push({
|
|
1958
2149
|
value,
|
|
1959
2150
|
anchor: element,
|
|
2151
|
+
node: inner,
|
|
1960
2152
|
remove: removeFromPrerender(inner)
|
|
1961
2153
|
});
|
|
1962
2154
|
}
|
|
@@ -2680,8 +2872,8 @@ function printNextSteps(projectPath, packageManager2) {
|
|
|
2680
2872
|
}
|
|
2681
2873
|
|
|
2682
2874
|
// src/commands/create.ts
|
|
2683
|
-
import
|
|
2684
|
-
import
|
|
2875
|
+
import fs27 from "node:fs";
|
|
2876
|
+
import path25 from "node:path";
|
|
2685
2877
|
import process13 from "node:process";
|
|
2686
2878
|
import * as v5 from "valibot";
|
|
2687
2879
|
import { Command as Command3 } from "commander";
|
|
@@ -3119,8 +3311,8 @@ function extractApiKey(cookie) {
|
|
|
3119
3311
|
}
|
|
3120
3312
|
|
|
3121
3313
|
// src/lib/kit3-migrate.ts
|
|
3122
|
-
import
|
|
3123
|
-
import
|
|
3314
|
+
import fs25 from "node:fs";
|
|
3315
|
+
import path23 from "node:path";
|
|
3124
3316
|
import process12 from "node:process";
|
|
3125
3317
|
import { execFileSync, spawn as spawn2 } from "node:child_process";
|
|
3126
3318
|
import { createRequire as createRequire2 } from "node:module";
|
|
@@ -3130,24 +3322,330 @@ import { detect as detect3 } from "package-manager-detector";
|
|
|
3130
3322
|
import {
|
|
3131
3323
|
ADAPTER_NODE,
|
|
3132
3324
|
ADAPTER_STATIC,
|
|
3325
|
+
ensurePackageOverrides,
|
|
3133
3326
|
FLASH,
|
|
3134
|
-
NEGOTIATE,
|
|
3135
3327
|
SUPERFORMS_VERSION,
|
|
3136
3328
|
VELASTACK_CMS,
|
|
3137
3329
|
VELASTACK_KIT,
|
|
3138
3330
|
VELASTACK_POCKETBASE
|
|
3139
3331
|
} from "@velastack/patterns";
|
|
3140
3332
|
|
|
3141
|
-
// src/lib/
|
|
3333
|
+
// src/lib/kit-peers.ts
|
|
3142
3334
|
import fs20 from "node:fs";
|
|
3143
3335
|
import path18 from "node:path";
|
|
3336
|
+
import { execFile } from "node:child_process";
|
|
3337
|
+
var LOOKUP_TIMEOUT_MS = 15e3;
|
|
3338
|
+
var CONCURRENCY = 8;
|
|
3339
|
+
var OFFLINE_AFTER = 3;
|
|
3340
|
+
var npmViewLookup = (name, range, cwd) => new Promise((resolve2, reject) => {
|
|
3341
|
+
execFile(
|
|
3342
|
+
"npm",
|
|
3343
|
+
["view", `${name}@${range}`, "--json"],
|
|
3344
|
+
{ cwd, timeout: LOOKUP_TIMEOUT_MS, maxBuffer: 64 * 1024 * 1024 },
|
|
3345
|
+
(error, stdout, stderr) => {
|
|
3346
|
+
if (error && /\bE404\b/.test(`${stderr}${error.message}`)) return resolve2(null);
|
|
3347
|
+
if (error) return reject(error);
|
|
3348
|
+
const text19 = stdout.trim();
|
|
3349
|
+
if (!text19) return resolve2(null);
|
|
3350
|
+
try {
|
|
3351
|
+
resolve2(newest(JSON.parse(text19)));
|
|
3352
|
+
} catch (e) {
|
|
3353
|
+
reject(e);
|
|
3354
|
+
}
|
|
3355
|
+
}
|
|
3356
|
+
);
|
|
3357
|
+
});
|
|
3358
|
+
function newest(data) {
|
|
3359
|
+
const list3 = (Array.isArray(data) ? data : [data]).filter((m) => typeof m?.version === "string");
|
|
3360
|
+
let best = null;
|
|
3361
|
+
for (const manifest of list3) {
|
|
3362
|
+
const v12 = minVersion(manifest.version);
|
|
3363
|
+
const b = best ? minVersion(best.version) : null;
|
|
3364
|
+
if (v12 && (!b || compareVersions(v12, b) > 0)) best = manifest;
|
|
3365
|
+
}
|
|
3366
|
+
return best;
|
|
3367
|
+
}
|
|
3368
|
+
function installed(root, name) {
|
|
3369
|
+
try {
|
|
3370
|
+
const data = JSON.parse(
|
|
3371
|
+
fs20.readFileSync(path18.join(root, "node_modules", name, "package.json"), "utf8")
|
|
3372
|
+
);
|
|
3373
|
+
return typeof data.version === "string" ? data : null;
|
|
3374
|
+
} catch {
|
|
3375
|
+
return null;
|
|
3376
|
+
}
|
|
3377
|
+
}
|
|
3378
|
+
async function findKit2Peers(root, pkg, skip, lookup = npmViewLookup) {
|
|
3379
|
+
const deps = /* @__PURE__ */ new Map();
|
|
3380
|
+
for (const kind of ["dependencies", "devDependencies"]) {
|
|
3381
|
+
for (const [name, range] of Object.entries(pkg[kind] ?? {})) {
|
|
3382
|
+
if (!skip(name)) deps.set(name, range);
|
|
3383
|
+
}
|
|
3384
|
+
}
|
|
3385
|
+
const kit2 = [];
|
|
3386
|
+
const unchecked = [];
|
|
3387
|
+
const check2 = (name, manifest) => {
|
|
3388
|
+
const peer = manifest.peerDependencies?.["@sveltejs/kit"];
|
|
3389
|
+
if (peer && rangeAdmits(peer, "3.0.0") === false) {
|
|
3390
|
+
kit2.push({ name, version: manifest.version, peer });
|
|
3391
|
+
}
|
|
3392
|
+
};
|
|
3393
|
+
const remote = [];
|
|
3394
|
+
for (const [name, range] of deps) {
|
|
3395
|
+
const local = installed(root, name);
|
|
3396
|
+
if (local) check2(name, local);
|
|
3397
|
+
else if (!range.includes(":") && !range.includes("/")) remote.push([name, range]);
|
|
3398
|
+
}
|
|
3399
|
+
let answered = 0;
|
|
3400
|
+
let failed = 0;
|
|
3401
|
+
const queue = [...remote];
|
|
3402
|
+
const worker = async () => {
|
|
3403
|
+
for (let next = queue.shift(); next; next = queue.shift()) {
|
|
3404
|
+
const [name, range] = next;
|
|
3405
|
+
if (answered === 0 && failed >= OFFLINE_AFTER) {
|
|
3406
|
+
unchecked.push(name);
|
|
3407
|
+
continue;
|
|
3408
|
+
}
|
|
3409
|
+
try {
|
|
3410
|
+
const manifest = await lookup(name, range, root);
|
|
3411
|
+
answered++;
|
|
3412
|
+
if (manifest) check2(name, manifest);
|
|
3413
|
+
else unchecked.push(name);
|
|
3414
|
+
} catch {
|
|
3415
|
+
failed++;
|
|
3416
|
+
unchecked.push(name);
|
|
3417
|
+
}
|
|
3418
|
+
}
|
|
3419
|
+
};
|
|
3420
|
+
await Promise.all(Array.from({ length: Math.min(CONCURRENCY, remote.length) }, worker));
|
|
3421
|
+
const order = [...deps.keys()];
|
|
3422
|
+
const byOrder = (a, b) => order.indexOf(a) - order.indexOf(b);
|
|
3423
|
+
kit2.sort((a, b) => byOrder(a.name, b.name));
|
|
3424
|
+
unchecked.sort(byOrder);
|
|
3425
|
+
return { kit2, unchecked };
|
|
3426
|
+
}
|
|
3427
|
+
|
|
3428
|
+
// src/lib/locales-alias.ts
|
|
3429
|
+
import fs21 from "node:fs";
|
|
3430
|
+
import path19 from "node:path";
|
|
3431
|
+
import { Node as Node2, SyntaxKind as SyntaxKind3 } from "ts-morph";
|
|
3432
|
+
import { ensurePackageImports } from "@velastack/patterns";
|
|
3433
|
+
var LOCALES_IMPORTS = { "#locales/*": "./src/locales/*" };
|
|
3434
|
+
var LOCALES_DIR = "src/locales";
|
|
3435
|
+
function keyName(node) {
|
|
3436
|
+
if (!Node2.isPropertyAssignment(node)) return void 0;
|
|
3437
|
+
return node.getNameNode().getText().replace(/^['"`]|['"`]$/g, "");
|
|
3438
|
+
}
|
|
3439
|
+
function localesProperty(alias) {
|
|
3440
|
+
return alias.getProperties().find((p73) => keyName(p73) === "$locales");
|
|
3441
|
+
}
|
|
3442
|
+
function localesSpecifier(root, rest) {
|
|
3443
|
+
if (/\.(?:js|mjs|cjs|json)$/.test(rest)) return `#locales/${rest}`;
|
|
3444
|
+
const dir = path19.join(root, LOCALES_DIR);
|
|
3445
|
+
const exists = (name) => fs21.existsSync(path19.join(dir, name));
|
|
3446
|
+
if (!exists(`${rest}.js`) && (exists(`${rest}.svelte.js`) || exists(`${rest}.svelte.ts`))) {
|
|
3447
|
+
return `#locales/${rest}.svelte.js`;
|
|
3448
|
+
}
|
|
3449
|
+
return `#locales/${rest}.js`;
|
|
3450
|
+
}
|
|
3451
|
+
var LOCALES_SPECIFIER = /(['"])\$locales\/([^'"\n]+)\1/g;
|
|
3452
|
+
function rewriteLocalesSource(root, source) {
|
|
3453
|
+
const changes = [];
|
|
3454
|
+
const code2 = source.replace(LOCALES_SPECIFIER, (_whole, quote2, rest) => {
|
|
3455
|
+
const next = localesSpecifier(root, rest);
|
|
3456
|
+
changes.push(`$locales/${rest} \u2192 ${next}`);
|
|
3457
|
+
return `${quote2}${next}${quote2}`;
|
|
3458
|
+
});
|
|
3459
|
+
return { code: code2, changes };
|
|
3460
|
+
}
|
|
3461
|
+
async function migrateLocalesAlias(root) {
|
|
3462
|
+
const outcome = { changed: false, details: [], warnings: [] };
|
|
3463
|
+
const vite = inspectViteSveltekit(root);
|
|
3464
|
+
const aliasProp = vite?.inlineArg?.getProperty("alias");
|
|
3465
|
+
if (!vite || !aliasProp || !Node2.isPropertyAssignment(aliasProp)) return outcome;
|
|
3466
|
+
const alias = aliasProp.getInitializerIfKind(SyntaxKind3.ObjectLiteralExpression);
|
|
3467
|
+
const entry = alias && localesProperty(alias);
|
|
3468
|
+
if (!alias || !entry || !Node2.isPropertyAssignment(entry)) return outcome;
|
|
3469
|
+
const target = entry.getInitializerIfKind(SyntaxKind3.StringLiteral)?.getLiteralValue();
|
|
3470
|
+
const normalized = target?.replace(/^\.\//, "").replace(/\/$/, "");
|
|
3471
|
+
if (normalized !== LOCALES_DIR) return outcome;
|
|
3472
|
+
const imports = await ensurePackageImports(root, LOCALES_IMPORTS);
|
|
3473
|
+
if (imports.outcome.status !== "success") {
|
|
3474
|
+
outcome.warnings.push(
|
|
3475
|
+
`alias.$locales was left in place: ${imports.outcome.message ?? "package.json imports could not be updated"}`
|
|
3476
|
+
);
|
|
3477
|
+
return outcome;
|
|
3478
|
+
}
|
|
3479
|
+
if (imports.outcome.changed) {
|
|
3480
|
+
outcome.changed = true;
|
|
3481
|
+
outcome.details.push("package.json imports #locales/*");
|
|
3482
|
+
}
|
|
3483
|
+
const files = [...sourceFiles(path19.join(root, "src")), ...sourceFiles(path19.join(root, "test"))];
|
|
3484
|
+
let rewritten = 0;
|
|
3485
|
+
for (const file of files) {
|
|
3486
|
+
const source = fs21.readFileSync(file, "utf8");
|
|
3487
|
+
if (!source.includes("$locales/")) continue;
|
|
3488
|
+
const { code: code2, changes } = rewriteLocalesSource(root, source);
|
|
3489
|
+
if (code2 === source) continue;
|
|
3490
|
+
fs21.writeFileSync(file, code2);
|
|
3491
|
+
rewritten += changes.length;
|
|
3492
|
+
outcome.details.push(`${path19.relative(root, file)}: ${[...new Set(changes)].join(", ")}`);
|
|
3493
|
+
}
|
|
3494
|
+
entry.remove();
|
|
3495
|
+
if (alias.getProperties().length === 0) aliasProp.remove();
|
|
3496
|
+
vite.sourceFile.saveSync();
|
|
3497
|
+
outcome.changed = true;
|
|
3498
|
+
outcome.details.push(
|
|
3499
|
+
`${path19.basename(vite.filePath)}: removed alias.$locales${rewritten ? ` (${rewritten} specifier${rewritten === 1 ? "" : "s"} now #locales)` : ""}`
|
|
3500
|
+
);
|
|
3501
|
+
return outcome;
|
|
3502
|
+
}
|
|
3503
|
+
|
|
3504
|
+
// src/lib/params-native.ts
|
|
3505
|
+
import fs22 from "node:fs";
|
|
3506
|
+
import path20 from "node:path";
|
|
3507
|
+
import { Project as Project3, QuoteKind as QuoteKind2 } from "ts-morph";
|
|
3508
|
+
var PARAMS_FILES = ["src/params.ts", "src/params.js"];
|
|
3509
|
+
var PARAMS_DIR = "src/params";
|
|
3510
|
+
var IMPORT_SPECIFIERS = /import\s+(type\s+)?([^'";]*?)\s*from\s*(['"])([^'"]+)\3/g;
|
|
3511
|
+
function captureParamTypeImports(root) {
|
|
3512
|
+
const names = /* @__PURE__ */ new Set();
|
|
3513
|
+
const dir = path20.join(root, PARAMS_DIR);
|
|
3514
|
+
if (!fs22.existsSync(dir)) return names;
|
|
3515
|
+
for (const entry of fs22.readdirSync(dir)) {
|
|
3516
|
+
if (!/\.(ts|js)$/.test(entry)) continue;
|
|
3517
|
+
const source = fs22.readFileSync(path20.join(dir, entry), "utf8");
|
|
3518
|
+
for (const match of source.matchAll(IMPORT_SPECIFIERS)) {
|
|
3519
|
+
const clause = match[2];
|
|
3520
|
+
const braces = clause.match(/\{([^}]*)\}/)?.[1];
|
|
3521
|
+
if (!braces) continue;
|
|
3522
|
+
for (const raw of braces.split(",")) {
|
|
3523
|
+
const spec = raw.trim();
|
|
3524
|
+
const inline = /^type\s+/.test(spec);
|
|
3525
|
+
if (!spec || !match[1] && !inline) continue;
|
|
3526
|
+
const [, local] = spec.replace(/^type\s+/, "").match(/^(?:[\w$]+\s+as\s+)?([\w$]+)$/) ?? [];
|
|
3527
|
+
if (local) names.add(local);
|
|
3528
|
+
}
|
|
3529
|
+
}
|
|
3530
|
+
}
|
|
3531
|
+
return names;
|
|
3532
|
+
}
|
|
3533
|
+
function resolveLocal(root, fromDir, spec) {
|
|
3534
|
+
let base2;
|
|
3535
|
+
if (spec.startsWith("#lib/") || spec.startsWith("$lib/")) {
|
|
3536
|
+
base2 = path20.join(root, "src", "lib", spec.slice(5));
|
|
3537
|
+
} else if (spec.startsWith("./") || spec.startsWith("../")) {
|
|
3538
|
+
base2 = path20.resolve(fromDir, spec);
|
|
3539
|
+
} else {
|
|
3540
|
+
return null;
|
|
3541
|
+
}
|
|
3542
|
+
const stem = base2.replace(/\.js$/, "");
|
|
3543
|
+
const candidates = /\.js$/.test(base2) ? [base2, `${stem}.ts`] : [base2, `${base2}.ts`, `${base2}.js`, path20.join(base2, "index.ts"), path20.join(base2, "index.js")];
|
|
3544
|
+
return candidates.find((c) => fs22.existsSync(c) && fs22.statSync(c).isFile()) ?? null;
|
|
3545
|
+
}
|
|
3546
|
+
function declaresTypeOnly(file, name) {
|
|
3547
|
+
const source = fs22.readFileSync(file, "utf8");
|
|
3548
|
+
const n = name.replace(/[$]/g, "\\$");
|
|
3549
|
+
const asValue = new RegExp(
|
|
3550
|
+
String.raw`\bexport\s+(?:declare\s+)?(?:const|let|var|function|class|enum|async\s+function)\s+${n}\b|\bexport\s*\{[^}]*\b${n}\b`
|
|
3551
|
+
);
|
|
3552
|
+
if (asValue.test(source)) return false;
|
|
3553
|
+
return new RegExp(
|
|
3554
|
+
String.raw`\bexport\s+(?:declare\s+)?(?:type|interface)\s+${n}\b|@(?:typedef|callback)\s+(?:\{[\s\S]*?\}\s+)?${n}\b`
|
|
3555
|
+
).test(source);
|
|
3556
|
+
}
|
|
3557
|
+
function relativeSpecifier(root, target) {
|
|
3558
|
+
const rel = path20.relative(path20.join(root, "src"), target).split(path20.sep).join("/");
|
|
3559
|
+
return rel.startsWith(".") ? rel : `./${rel}`;
|
|
3560
|
+
}
|
|
3561
|
+
function fixParamsImports(root, typeNames = /* @__PURE__ */ new Set()) {
|
|
3562
|
+
const rel = PARAMS_FILES.find((f) => fs22.existsSync(path20.join(root, f)));
|
|
3563
|
+
if (!rel) return { changes: [], viteOnly: [] };
|
|
3564
|
+
const file = path20.join(root, rel);
|
|
3565
|
+
const outcome = { file: rel, changes: [], viteOnly: [] };
|
|
3566
|
+
const project = new Project3({
|
|
3567
|
+
compilerOptions: { allowJs: true },
|
|
3568
|
+
manipulationSettings: { quoteKind: QuoteKind2.Single }
|
|
3569
|
+
});
|
|
3570
|
+
const sourceFile = project.addSourceFileAtPath(file);
|
|
3571
|
+
const srcDir = path20.join(root, "src");
|
|
3572
|
+
const loaded = [];
|
|
3573
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3574
|
+
const spec = decl.getModuleSpecifierValue();
|
|
3575
|
+
const target = resolveLocal(root, srcDir, spec);
|
|
3576
|
+
if (!target) continue;
|
|
3577
|
+
if (!decl.isTypeOnly()) restoreTypes(decl, target, typeNames, outcome);
|
|
3578
|
+
if (decl.isTypeOnly()) continue;
|
|
3579
|
+
loaded.push(target);
|
|
3580
|
+
const nodeResolves = spec.startsWith("#lib/") && /\.js$/.test(spec) ? fs22.existsSync(path20.join(root, "src", "lib", spec.slice(5))) : spec.startsWith(".") && path20.resolve(srcDir, spec) === target;
|
|
3581
|
+
if (nodeResolves) continue;
|
|
3582
|
+
const next = relativeSpecifier(root, target);
|
|
3583
|
+
decl.setModuleSpecifier(next);
|
|
3584
|
+
outcome.changes.push(`${spec} \u2192 ${next}`);
|
|
3585
|
+
}
|
|
3586
|
+
if (outcome.changes.length > 0) sourceFile.saveSync();
|
|
3587
|
+
outcome.viteOnly = viteOnlyImports(root, loaded);
|
|
3588
|
+
return outcome;
|
|
3589
|
+
}
|
|
3590
|
+
function restoreTypes(decl, target, typeNames, outcome) {
|
|
3591
|
+
const named = decl.getNamedImports();
|
|
3592
|
+
const restored = [];
|
|
3593
|
+
for (const specifier of named) {
|
|
3594
|
+
if (specifier.isTypeOnly()) continue;
|
|
3595
|
+
const local = specifier.getAliasNode()?.getText() ?? specifier.getName();
|
|
3596
|
+
if (!typeNames.has(local) && !declaresTypeOnly(target, specifier.getName())) continue;
|
|
3597
|
+
specifier.setIsTypeOnly(true);
|
|
3598
|
+
restored.push(local);
|
|
3599
|
+
}
|
|
3600
|
+
if (restored.length === 0) return;
|
|
3601
|
+
if (named.every((s) => s.isTypeOnly()) && !decl.getDefaultImport() && !decl.getNamespaceImport()) {
|
|
3602
|
+
for (const s of named) s.setIsTypeOnly(false);
|
|
3603
|
+
decl.setIsTypeOnly(true);
|
|
3604
|
+
}
|
|
3605
|
+
outcome.changes.push(`type ${restored.join(", ")} (from ${decl.getModuleSpecifierValue()})`);
|
|
3606
|
+
}
|
|
3607
|
+
function viteOnlyImports(root, start) {
|
|
3608
|
+
const found = [];
|
|
3609
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3610
|
+
const queue = [...start];
|
|
3611
|
+
for (let file = queue.shift(); file; file = queue.shift()) {
|
|
3612
|
+
if (seen.has(file) || !file.startsWith(path20.join(root, "src"))) continue;
|
|
3613
|
+
seen.add(file);
|
|
3614
|
+
const source = fs22.readFileSync(file, "utf8");
|
|
3615
|
+
const rel = path20.relative(root, file).split(path20.sep).join("/");
|
|
3616
|
+
for (const match of source.matchAll(IMPORT_SPECIFIERS)) {
|
|
3617
|
+
const clause = match[2];
|
|
3618
|
+
const spec = match[4];
|
|
3619
|
+
if (match[1] || /^\{\s*(?:type\s+[\w$]+(?:\s+as\s+[\w$]+)?\s*,?\s*)+\}$/.test(clause))
|
|
3620
|
+
continue;
|
|
3621
|
+
if (/^\$(?:lib|app|env|locales|service-worker)\b/.test(spec)) {
|
|
3622
|
+
found.push(`${rel}: ${spec}`);
|
|
3623
|
+
continue;
|
|
3624
|
+
}
|
|
3625
|
+
const target = resolveLocal(root, path20.dirname(file), spec);
|
|
3626
|
+
if (spec.startsWith("#lib/")) {
|
|
3627
|
+
if (!fs22.existsSync(path20.join(root, "src", "lib", spec.slice(5)))) {
|
|
3628
|
+
found.push(`${rel}: ${spec}`);
|
|
3629
|
+
}
|
|
3630
|
+
} else if (spec.startsWith(".") && target && path20.resolve(path20.dirname(file), spec) !== target) {
|
|
3631
|
+
found.push(`${rel}: ${spec}`);
|
|
3632
|
+
}
|
|
3633
|
+
if (target) queue.push(target);
|
|
3634
|
+
}
|
|
3635
|
+
}
|
|
3636
|
+
return found;
|
|
3637
|
+
}
|
|
3638
|
+
|
|
3639
|
+
// src/lib/lib-rewrite.ts
|
|
3640
|
+
import fs23 from "node:fs";
|
|
3641
|
+
import path21 from "node:path";
|
|
3144
3642
|
import { libSpecifier } from "@velastack/patterns";
|
|
3145
3643
|
var KEPT_EXTENSIONS = /\.(svelte|svg|svx|css|json)$/;
|
|
3146
3644
|
var MODULE_EXTENSIONS = [".ts", ".js", ".mts", ".mjs"];
|
|
3147
3645
|
function resolveLibPath(root, rel) {
|
|
3148
|
-
const lib =
|
|
3149
|
-
const isFile = (p73) =>
|
|
3150
|
-
const isDir = (p73) =>
|
|
3646
|
+
const lib = path21.join(root, "src", "lib");
|
|
3647
|
+
const isFile = (p73) => fs23.existsSync(path21.join(lib, p73)) && fs23.statSync(path21.join(lib, p73)).isFile();
|
|
3648
|
+
const isDir = (p73) => fs23.existsSync(path21.join(lib, p73)) && fs23.statSync(path21.join(lib, p73)).isDirectory();
|
|
3151
3649
|
if (rel === "") return "";
|
|
3152
3650
|
if (KEPT_EXTENSIONS.test(rel)) {
|
|
3153
3651
|
if (isFile(rel)) return rel;
|
|
@@ -3187,40 +3685,40 @@ function rewriteLibSpecifiers(root, source) {
|
|
|
3187
3685
|
}
|
|
3188
3686
|
function filesOutsideSrc(root) {
|
|
3189
3687
|
const files = [];
|
|
3190
|
-
const test =
|
|
3191
|
-
if (
|
|
3192
|
-
for (const rel of
|
|
3688
|
+
const test = path21.join(root, "test");
|
|
3689
|
+
if (fs23.existsSync(test)) {
|
|
3690
|
+
for (const rel of fs23.globSync("**/*.{ts,js,mts,mjs,svelte}", {
|
|
3193
3691
|
cwd: test,
|
|
3194
3692
|
exclude: (name) => name === "node_modules"
|
|
3195
3693
|
})) {
|
|
3196
|
-
files.push(
|
|
3694
|
+
files.push(path21.join(test, rel));
|
|
3197
3695
|
}
|
|
3198
3696
|
}
|
|
3199
|
-
for (const entry of
|
|
3697
|
+
for (const entry of fs23.readdirSync(root, { withFileTypes: true })) {
|
|
3200
3698
|
if (entry.isFile() && /\.(ts|js|mts|mjs|cts|cjs)$/.test(entry.name) && !entry.name.endsWith(".d.ts")) {
|
|
3201
|
-
files.push(
|
|
3699
|
+
files.push(path21.join(root, entry.name));
|
|
3202
3700
|
}
|
|
3203
3701
|
}
|
|
3204
|
-
return files.filter((f) =>
|
|
3702
|
+
return files.filter((f) => fs23.statSync(f).isFile()).sort();
|
|
3205
3703
|
}
|
|
3206
3704
|
function rewriteLibOutsideSrc(root) {
|
|
3207
3705
|
const result = { rewritten: [], unresolved: [] };
|
|
3208
3706
|
for (const file of filesOutsideSrc(root)) {
|
|
3209
|
-
const source =
|
|
3707
|
+
const source = fs23.readFileSync(file, "utf8");
|
|
3210
3708
|
if (!source.includes("$lib")) continue;
|
|
3211
|
-
const rel =
|
|
3709
|
+
const rel = path21.relative(root, file);
|
|
3212
3710
|
const { code: code2, changes, unresolved } = rewriteLibSpecifiers(root, source);
|
|
3213
3711
|
result.unresolved.push(...unresolved.map((spec) => `${rel}: ${spec}`));
|
|
3214
3712
|
if (code2 === source) continue;
|
|
3215
|
-
|
|
3713
|
+
fs23.writeFileSync(file, code2);
|
|
3216
3714
|
result.rewritten.push({ file: rel, changes });
|
|
3217
3715
|
}
|
|
3218
3716
|
return result;
|
|
3219
3717
|
}
|
|
3220
3718
|
function rewriteComponentsJsonAliases(root) {
|
|
3221
|
-
const file =
|
|
3222
|
-
if (!
|
|
3223
|
-
const source =
|
|
3719
|
+
const file = path21.join(root, "components.json");
|
|
3720
|
+
if (!fs23.existsSync(file)) return null;
|
|
3721
|
+
const source = fs23.readFileSync(file, "utf8");
|
|
3224
3722
|
let data;
|
|
3225
3723
|
try {
|
|
3226
3724
|
data = JSON.parse(source);
|
|
@@ -3238,13 +3736,13 @@ function rewriteComponentsJsonAliases(root) {
|
|
|
3238
3736
|
changes.push(`${value} \u2192 ${next}`);
|
|
3239
3737
|
}
|
|
3240
3738
|
if (code2 === source) return null;
|
|
3241
|
-
|
|
3739
|
+
fs23.writeFileSync(file, code2);
|
|
3242
3740
|
return { file: "components.json", changes };
|
|
3243
3741
|
}
|
|
3244
3742
|
|
|
3245
3743
|
// src/lib/kit3-rewrites.ts
|
|
3246
|
-
import
|
|
3247
|
-
import
|
|
3744
|
+
import fs24 from "node:fs";
|
|
3745
|
+
import path22 from "node:path";
|
|
3248
3746
|
var MIGRATION_TASK_MARKER = "@migration-task";
|
|
3249
3747
|
var NAVIGATION_IMPORT = /import\s*\{([^}]*)\}\s*from\s*['"]\$app\/navigation['"]\s*;?/g;
|
|
3250
3748
|
function navigationBindings(source) {
|
|
@@ -3337,7 +3835,7 @@ function lineOf(source, index) {
|
|
|
3337
3835
|
function rewriteGotoCalls(source, gotoNames) {
|
|
3338
3836
|
const outcome = { edits: [], changes: [], tasks: [] };
|
|
3339
3837
|
for (const local of gotoNames) {
|
|
3340
|
-
const call = new RegExp(String.raw`(?<![\w$.])${
|
|
3838
|
+
const call = new RegExp(String.raw`(?<![\w$.])${escapeRegExp3(local)}\s*\(`, "g");
|
|
3341
3839
|
for (const match of source.matchAll(call)) {
|
|
3342
3840
|
if (inComment(source, match.index)) continue;
|
|
3343
3841
|
const open = match.index + match[0].length - 1;
|
|
@@ -3444,7 +3942,7 @@ function rewriteGotoOptions(inner) {
|
|
|
3444
3942
|
if (!joined.startsWith(lead)) joined = lead + joined.trimStart();
|
|
3445
3943
|
return { inner: joined + tail, summary: summary.join("; ") };
|
|
3446
3944
|
}
|
|
3447
|
-
function
|
|
3945
|
+
function escapeRegExp3(text19) {
|
|
3448
3946
|
return text19.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3449
3947
|
}
|
|
3450
3948
|
function rewriteInvalidateAll(source) {
|
|
@@ -3561,7 +4059,37 @@ function insideScript(source, index) {
|
|
|
3561
4059
|
return open !== -1 && open > close;
|
|
3562
4060
|
}
|
|
3563
4061
|
var MOCK_ENVIRONMENT = /(\bvi\.(?:mock|doMock|unmock|doUnmock|importActual|importMock)\s*\(\s*)(['"])\$app\/environment\2/g;
|
|
4062
|
+
var MOCK_ENV = /(\bvi\.(mock|doMock|unmock|doUnmock|importActual|importMock)\s*\(\s*)(['"])\$env\/(dynamic|static)\/(private|public)\3/g;
|
|
3564
4063
|
var NEW_URL_PAGE_URL = /\bnew\s+URL\(\s*(\$?page\.url)\s*\)/g;
|
|
4064
|
+
function rewriteEnvMocks(source) {
|
|
4065
|
+
const changes = [];
|
|
4066
|
+
const tasks = [];
|
|
4067
|
+
let code2 = "";
|
|
4068
|
+
let last = 0;
|
|
4069
|
+
for (const match of source.matchAll(MOCK_ENV)) {
|
|
4070
|
+
const [whole, lead, method, quote2, kind, visibility] = match;
|
|
4071
|
+
const start = match.index;
|
|
4072
|
+
const target = `$app/env/${visibility}`;
|
|
4073
|
+
code2 += source.slice(last, start);
|
|
4074
|
+
const at = code2.length;
|
|
4075
|
+
code2 += `${lead}${quote2}${target}${quote2}`;
|
|
4076
|
+
last = start + whole.length;
|
|
4077
|
+
changes.push(`line ${lineOf(source, start)}: mock of $env/${kind}/${visibility} \u2192 ${target}`);
|
|
4078
|
+
if (kind !== "dynamic" || method !== "mock" && method !== "doMock") continue;
|
|
4079
|
+
const open = start + lead.lastIndexOf("(");
|
|
4080
|
+
const close = matchBracket(source, open);
|
|
4081
|
+
if (close === -1) continue;
|
|
4082
|
+
const factory = splitTopLevel(source.slice(open + 1, close - 1))[1]?.text ?? "";
|
|
4083
|
+
if (/(?<![\w$.])env\s*[:,}]/.test(factory)) {
|
|
4084
|
+
tasks.push([
|
|
4085
|
+
at,
|
|
4086
|
+
`\`${target}\` exports each variable by name, but this mock returns Kit 2's \`{ env: {...} }\`. Return the variables themselves, e.g. \`() => ({ TEST: 'true' })\`.`
|
|
4087
|
+
]);
|
|
4088
|
+
}
|
|
4089
|
+
}
|
|
4090
|
+
code2 += source.slice(last);
|
|
4091
|
+
return { code: code2, changes, tasks };
|
|
4092
|
+
}
|
|
3565
4093
|
function rewriteKit3Source(file, source) {
|
|
3566
4094
|
const changes = [];
|
|
3567
4095
|
let code2 = source;
|
|
@@ -3573,13 +4101,17 @@ function rewriteKit3Source(file, source) {
|
|
|
3573
4101
|
changes.push(`line ${lineOf(code2, offset)}: new URL(${url}) \u2192 new URL(${url}.href)`);
|
|
3574
4102
|
return `new URL(${url}.href)`;
|
|
3575
4103
|
});
|
|
3576
|
-
|
|
4104
|
+
const envMocks = rewriteEnvMocks(code2);
|
|
4105
|
+
code2 = envMocks.code;
|
|
4106
|
+
changes.push(...envMocks.changes);
|
|
4107
|
+
let tasks = [...envMocks.tasks];
|
|
3577
4108
|
const bindings = navigationBindings(code2);
|
|
3578
4109
|
const gotoNames = [...bindings].filter(([, name]) => name === "goto").map(([local]) => local);
|
|
3579
4110
|
if (gotoNames.length > 0) {
|
|
3580
4111
|
const goto = rewriteGotoCalls(code2, gotoNames);
|
|
3581
4112
|
code2 = applyEdits(code2, goto.edits);
|
|
3582
4113
|
changes.push(...goto.changes);
|
|
4114
|
+
tasks = tasks.map(([i, m]) => [mapIndex(goto.edits, i), m]);
|
|
3583
4115
|
tasks.push(...goto.tasks.map(([i, m]) => [mapIndex(goto.edits, i), m]));
|
|
3584
4116
|
}
|
|
3585
4117
|
if ([...bindings.values()].includes("invalidateAll")) {
|
|
@@ -3596,15 +4128,15 @@ function rewriteKit3Source(file, source) {
|
|
|
3596
4128
|
}
|
|
3597
4129
|
function rewriteKit3Code(root) {
|
|
3598
4130
|
const results = [];
|
|
3599
|
-
const files = [...sourceFiles(
|
|
4131
|
+
const files = [...sourceFiles(path22.join(root, "src")), ...sourceFiles(path22.join(root, "test"))];
|
|
3600
4132
|
for (const file of files) {
|
|
3601
|
-
const source =
|
|
3602
|
-
if (!/\$app\/navigation|\$app\/environment
|
|
4133
|
+
const source = fs24.readFileSync(file, "utf8");
|
|
4134
|
+
if (!/\$app\/navigation|\$app\/environment|\$env\/|new\s+URL\(\s*\$?page\.url\s*\)/.test(source))
|
|
3603
4135
|
continue;
|
|
3604
|
-
const rel =
|
|
4136
|
+
const rel = path22.relative(root, file);
|
|
3605
4137
|
const { code: code2, changes, tasks } = rewriteKit3Source(rel, source);
|
|
3606
4138
|
if (code2 === source) continue;
|
|
3607
|
-
|
|
4139
|
+
fs24.writeFileSync(file, code2);
|
|
3608
4140
|
results.push({ file: rel, changes, tasks });
|
|
3609
4141
|
}
|
|
3610
4142
|
return results;
|
|
@@ -3629,7 +4161,7 @@ function rewriteVelaEnvDefaultsSource(source) {
|
|
|
3629
4161
|
const changes = [];
|
|
3630
4162
|
if (locals.length === 0) return { code: source, changes };
|
|
3631
4163
|
const pattern = new RegExp(
|
|
3632
|
-
String.raw`(?<![\w$.])(${locals.map(
|
|
4164
|
+
String.raw`(?<![\w$.])(${locals.map(escapeRegExp3).join("|")})(\s*)\?\?(?!=)(?!\s*(?:''|""|\`\`))`,
|
|
3633
4165
|
"g"
|
|
3634
4166
|
);
|
|
3635
4167
|
const edits = [];
|
|
@@ -3650,13 +4182,13 @@ function rewriteVelaEnvDefaultsSource(source) {
|
|
|
3650
4182
|
}
|
|
3651
4183
|
function rewriteVelaEnvDefaults(root) {
|
|
3652
4184
|
const results = [];
|
|
3653
|
-
for (const file of sourceFiles(
|
|
3654
|
-
const source =
|
|
4185
|
+
for (const file of sourceFiles(path22.join(root, "src"))) {
|
|
4186
|
+
const source = fs24.readFileSync(file, "utf8");
|
|
3655
4187
|
if (!source.includes("$app/env/") || !source.includes("??")) continue;
|
|
3656
4188
|
const { code: code2, changes } = rewriteVelaEnvDefaultsSource(source);
|
|
3657
4189
|
if (code2 === source) continue;
|
|
3658
|
-
|
|
3659
|
-
results.push({ file:
|
|
4190
|
+
fs24.writeFileSync(file, code2);
|
|
4191
|
+
results.push({ file: path22.relative(root, file), changes, tasks: [] });
|
|
3660
4192
|
}
|
|
3661
4193
|
return results;
|
|
3662
4194
|
}
|
|
@@ -3695,7 +4227,9 @@ async function runKit3Migration(root, options = {}) {
|
|
|
3695
4227
|
} } : base2;
|
|
3696
4228
|
const mode = await preflight(root, options);
|
|
3697
4229
|
const dirtyBefore = new Set(gitDirty(root) ?? []);
|
|
3698
|
-
const sv = { ran: false, failures: [], excluded: [], cleared: [] };
|
|
4230
|
+
const sv = { ran: false, failures: [], excluded: [], cleared: [], dropped: [] };
|
|
4231
|
+
let svelteConfig = null;
|
|
4232
|
+
let paramTypes = /* @__PURE__ */ new Set();
|
|
3699
4233
|
if (mode === "repair") {
|
|
3700
4234
|
sv.skipped = "SvelteKit 3 already, with no svelte.config: running only the vela steps";
|
|
3701
4235
|
log55.info("Already on SvelteKit 3: skipping sv and re-checking the vela steps.");
|
|
@@ -3705,41 +4239,47 @@ async function runKit3Migration(root, options = {}) {
|
|
|
3705
4239
|
} else {
|
|
3706
4240
|
log55.step("Running sv migrate sveltekit-3...");
|
|
3707
4241
|
sv.cleared = clearOutputDirs(root, log55);
|
|
4242
|
+
svelteConfig = captureSvelteConfig(root);
|
|
4243
|
+
paramTypes = captureParamTypeImports(root);
|
|
3708
4244
|
await runSv(root, options.runSv ?? defaultSvRunner, quiet, sv, log55);
|
|
3709
4245
|
sv.ran = true;
|
|
3710
4246
|
}
|
|
3711
4247
|
log55.step("Applying the vela steps...");
|
|
3712
4248
|
const cliVersion = options.cliVersion ?? package_default.version;
|
|
3713
4249
|
const fixups = [
|
|
3714
|
-
originFixup(root),
|
|
4250
|
+
originFixup(root, svelteConfig, sv),
|
|
3715
4251
|
await envFixup(root),
|
|
3716
4252
|
libFixup(root, sv.excluded),
|
|
4253
|
+
await localesFixup(root),
|
|
4254
|
+
paramsFixup(root, paramTypes),
|
|
3717
4255
|
codeFixup(root),
|
|
3718
4256
|
tsconfigFixup(root),
|
|
3719
4257
|
packageFixup(root, cliVersion),
|
|
4258
|
+
await peersFixup(root, options.peerLookup),
|
|
3720
4259
|
lockfileFixup(root)
|
|
3721
4260
|
];
|
|
3722
4261
|
for (const fixup2 of fixups) {
|
|
3723
4262
|
if (fixup2.changed) log55.info(`${fixup2.name}: ${fixup2.details.join("; ")}`);
|
|
3724
4263
|
for (const warning of fixup2.warnings) log55.warn(`${fixup2.name}: ${warning}`);
|
|
3725
4264
|
}
|
|
3726
|
-
let
|
|
4265
|
+
let installed2 = null;
|
|
3727
4266
|
let formatted = [];
|
|
3728
4267
|
if (options.install !== false) {
|
|
3729
|
-
|
|
3730
|
-
if (
|
|
4268
|
+
installed2 = options.installer ? await options.installer(root) : await install(root);
|
|
4269
|
+
if (installed2) formatted = await formatChanged(root, dirtyBefore);
|
|
3731
4270
|
}
|
|
3732
|
-
const
|
|
3733
|
-
if (!sv.ran)
|
|
4271
|
+
const found = [...collectFollowUps(root, sv), ...fixups.flatMap((f) => f.followUps ?? [])];
|
|
4272
|
+
if (!sv.ran) found.unshift(...previousSvFollowUps(root));
|
|
4273
|
+
const followUps = [...new Set(found)];
|
|
3734
4274
|
const genericFollowUps = depRange(
|
|
3735
|
-
readJson(
|
|
4275
|
+
readJson(path23.join(root, "package.json")).data,
|
|
3736
4276
|
"@sveltejs/adapter-node"
|
|
3737
4277
|
) ? [
|
|
3738
4278
|
"Servers need Node 22.17 or later: run `vela provision` on each before the first SvelteKit 3 deploy."
|
|
3739
4279
|
] : [];
|
|
3740
4280
|
writeFollowUps(root, followUps, genericFollowUps);
|
|
3741
4281
|
const tasks = summarizeMigrationTasks(root);
|
|
3742
|
-
return { mode, sv, fixups, followUps, genericFollowUps, tasks, installed, formatted };
|
|
4282
|
+
return { mode, sv, fixups, followUps, genericFollowUps, tasks, installed: installed2, formatted };
|
|
3743
4283
|
}
|
|
3744
4284
|
async function preflight(root, options) {
|
|
3745
4285
|
const node = minVersion(options.nodeVersion ?? process12.versions.node);
|
|
@@ -3748,9 +4288,9 @@ async function preflight(root, options) {
|
|
|
3748
4288
|
`SvelteKit 3 needs Node ${NODE_FLOOR} or later; this is Node ${options.nodeVersion ?? process12.versions.node}.`
|
|
3749
4289
|
);
|
|
3750
4290
|
}
|
|
3751
|
-
const pkgPath =
|
|
3752
|
-
if (!
|
|
3753
|
-
const project = JSON.parse(
|
|
4291
|
+
const pkgPath = path23.join(root, "package.json");
|
|
4292
|
+
if (!fs25.existsSync(pkgPath)) throw new Kit3MigrationError(`No package.json found in ${root}.`);
|
|
4293
|
+
const project = JSON.parse(fs25.readFileSync(pkgPath, "utf8"));
|
|
3754
4294
|
if (!project.devDependencies?.["@sveltejs/kit"]) {
|
|
3755
4295
|
throw new Kit3MigrationError(
|
|
3756
4296
|
project.dependencies?.["@sveltejs/kit"] ? "@sveltejs/kit is in dependencies; sv migrates it only from devDependencies. Move it there and run this again." : `@sveltejs/kit is not a devDependency in ${pkgPath}: this does not look like a SvelteKit project.`
|
|
@@ -3807,14 +4347,14 @@ function clearOutputDirs(root, log55) {
|
|
|
3807
4347
|
const cleared = [];
|
|
3808
4348
|
const inGit = spawnSync("git", ["rev-parse", "--is-inside-work-tree"], root) !== null;
|
|
3809
4349
|
const walk2 = (dir, depth) => {
|
|
3810
|
-
for (const entry of
|
|
4350
|
+
for (const entry of fs25.readdirSync(dir, { withFileTypes: true })) {
|
|
3811
4351
|
if (!entry.isDirectory() || entry.name === "node_modules" || entry.name === ".git") continue;
|
|
3812
|
-
const full =
|
|
3813
|
-
const rel =
|
|
4352
|
+
const full = path23.join(dir, entry.name);
|
|
4353
|
+
const rel = path23.relative(root, full);
|
|
3814
4354
|
if (OUTPUT_DIRS.has(entry.name)) {
|
|
3815
4355
|
const ignored = inGit ? spawnSync("git", ["check-ignore", "-q", rel], root) !== null : entry.name === ".svelte-kit";
|
|
3816
4356
|
if (ignored) {
|
|
3817
|
-
|
|
4357
|
+
fs25.rmSync(full, { recursive: true, force: true });
|
|
3818
4358
|
cleared.push(rel);
|
|
3819
4359
|
} else if (entry.name !== ".svelte-kit") {
|
|
3820
4360
|
log55.warn(
|
|
@@ -3833,18 +4373,18 @@ function clearOutputDirs(root, log55) {
|
|
|
3833
4373
|
}
|
|
3834
4374
|
function svBin() {
|
|
3835
4375
|
const entry = require_.resolve("sv");
|
|
3836
|
-
let dir =
|
|
3837
|
-
while (dir !==
|
|
3838
|
-
const manifest =
|
|
3839
|
-
if (
|
|
3840
|
-
const data = JSON.parse(
|
|
4376
|
+
let dir = path23.dirname(entry);
|
|
4377
|
+
while (dir !== path23.dirname(dir)) {
|
|
4378
|
+
const manifest = path23.join(dir, "package.json");
|
|
4379
|
+
if (fs25.existsSync(manifest)) {
|
|
4380
|
+
const data = JSON.parse(fs25.readFileSync(manifest, "utf8"));
|
|
3841
4381
|
if (data.name === "sv") {
|
|
3842
4382
|
const bin = typeof data.bin === "string" ? data.bin : data.bin?.sv;
|
|
3843
4383
|
if (!bin) throw new Kit3MigrationError("The installed sv package has no bin.");
|
|
3844
|
-
return
|
|
4384
|
+
return path23.join(dir, bin);
|
|
3845
4385
|
}
|
|
3846
4386
|
}
|
|
3847
|
-
dir =
|
|
4387
|
+
dir = path23.dirname(dir);
|
|
3848
4388
|
}
|
|
3849
4389
|
throw new Kit3MigrationError("Could not find the sv package vela depends on. Reinstall vela.");
|
|
3850
4390
|
}
|
|
@@ -3962,9 +4502,10 @@ async function runSv(root, runner, quiet, summary, log55) {
|
|
|
3962
4502
|
function fixup(name) {
|
|
3963
4503
|
return { name, changed: false, details: [], warnings: [] };
|
|
3964
4504
|
}
|
|
3965
|
-
function originFixup(root) {
|
|
4505
|
+
function originFixup(root, capture, sv) {
|
|
3966
4506
|
const f = fixup("origin");
|
|
3967
|
-
const
|
|
4507
|
+
const carry = capture?.origin;
|
|
4508
|
+
const outcome = mergeOriginConfig(root, { carry });
|
|
3968
4509
|
if (outcome.applied) {
|
|
3969
4510
|
f.changed = true;
|
|
3970
4511
|
f.details.push(`${outcome.file}: ${outcome.reason}`);
|
|
@@ -3972,6 +4513,11 @@ function originFixup(root) {
|
|
|
3972
4513
|
f.warnings.push(`${outcome.file ?? "vite.config"}: ${outcome.reason}
|
|
3973
4514
|
${outcome.snippet}`);
|
|
3974
4515
|
}
|
|
4516
|
+
const lost = Boolean(carry && !outcome.applied && outcome.snippet);
|
|
4517
|
+
for (const text19 of capture?.spreads ?? []) {
|
|
4518
|
+
if (carry && !lost && carry.text.endsWith(text19)) continue;
|
|
4519
|
+
sv.dropped.push({ file: capture.file, text: text19 });
|
|
4520
|
+
}
|
|
3975
4521
|
return f;
|
|
3976
4522
|
}
|
|
3977
4523
|
async function envFixup(root) {
|
|
@@ -3988,7 +4534,7 @@ async function envFixup(root) {
|
|
|
3988
4534
|
}
|
|
3989
4535
|
function libFixup(root, skippedBySv) {
|
|
3990
4536
|
const f = fixup("#lib");
|
|
3991
|
-
const pkgPath =
|
|
4537
|
+
const pkgPath = path23.join(root, "package.json");
|
|
3992
4538
|
const { data, indent } = readJson(pkgPath);
|
|
3993
4539
|
if (ensureLibImports(data)) {
|
|
3994
4540
|
writeJson(pkgPath, data, indent);
|
|
@@ -4001,14 +4547,14 @@ function libFixup(root, skippedBySv) {
|
|
|
4001
4547
|
f.details.push(`components.json aliases ${components.changes.join(", ")}`);
|
|
4002
4548
|
}
|
|
4003
4549
|
for (const rel of skippedBySv) {
|
|
4004
|
-
const file =
|
|
4005
|
-
if (!
|
|
4006
|
-
const source =
|
|
4550
|
+
const file = path23.join(root, rel);
|
|
4551
|
+
if (!fs25.existsSync(file)) continue;
|
|
4552
|
+
const source = fs25.readFileSync(file, "utf8");
|
|
4007
4553
|
const { code: code2, changes, unresolved } = rewriteLibSpecifiers(root, source);
|
|
4008
4554
|
for (const u of unresolved)
|
|
4009
4555
|
f.warnings.push(`${rel}: ${u} names nothing under src/lib; change it by hand`);
|
|
4010
4556
|
if (code2 === source) continue;
|
|
4011
|
-
|
|
4557
|
+
fs25.writeFileSync(file, code2);
|
|
4012
4558
|
f.changed = true;
|
|
4013
4559
|
f.details.push(`${rel} (skipped by sv): ${changes.join(", ")}`);
|
|
4014
4560
|
}
|
|
@@ -4021,6 +4567,29 @@ function libFixup(root, skippedBySv) {
|
|
|
4021
4567
|
f.warnings.push(`${u} names nothing under src/lib; change it by hand`);
|
|
4022
4568
|
return f;
|
|
4023
4569
|
}
|
|
4570
|
+
async function localesFixup(root) {
|
|
4571
|
+
const f = fixup("#locales");
|
|
4572
|
+
const outcome = await migrateLocalesAlias(root);
|
|
4573
|
+
f.changed = outcome.changed;
|
|
4574
|
+
f.details.push(...outcome.details);
|
|
4575
|
+
f.warnings.push(...outcome.warnings);
|
|
4576
|
+
return f;
|
|
4577
|
+
}
|
|
4578
|
+
function paramsFixup(root, typeNames) {
|
|
4579
|
+
const f = fixup("params");
|
|
4580
|
+
const outcome = fixParamsImports(root, typeNames);
|
|
4581
|
+
if (!outcome.file) return f;
|
|
4582
|
+
if (outcome.changes.length > 0) {
|
|
4583
|
+
f.changed = true;
|
|
4584
|
+
f.details.push(`${outcome.file}: ${outcome.changes.join(", ")}`);
|
|
4585
|
+
}
|
|
4586
|
+
const typescript = outcome.file.endsWith(".ts");
|
|
4587
|
+
const viteOnly = outcome.viteOnly.length ? ` These imports it loads do not: ${outcome.viteOnly.map(code).join(", ")}.` : "";
|
|
4588
|
+
f.followUps = [
|
|
4589
|
+
`${code(outcome.file)} is loaded by Node directly (SvelteKit's build imports it with \`import()\`, not through Vite), so everything it imports has to resolve without Vite: relative paths with real file names, no \`$lib\` or other aliases, \`type\` on type-only imports.${viteOnly}${typescript ? " A TypeScript params.ts needs Node 22.18 or later (native type stripping) wherever the app is built." : ""}`
|
|
4590
|
+
];
|
|
4591
|
+
return f;
|
|
4592
|
+
}
|
|
4024
4593
|
function codeFixup(root) {
|
|
4025
4594
|
const f = fixup("code");
|
|
4026
4595
|
for (const r of rewriteKit3Code(root)) {
|
|
@@ -4066,7 +4635,10 @@ var FLOORS = [
|
|
|
4066
4635
|
splitSpec(VELASTACK_KIT),
|
|
4067
4636
|
splitSpec(VELASTACK_POCKETBASE),
|
|
4068
4637
|
splitSpec(VELASTACK_CMS),
|
|
4069
|
-
|
|
4638
|
+
// 0.3.0's package lost the `type="text/plain"` its prerender test relies on.
|
|
4639
|
+
["sveltekit-negotiate", "^0.3.1"],
|
|
4640
|
+
// 0.3 peers @velastack/pocketbase ^0.3, which the floor above moves past.
|
|
4641
|
+
["@velastack/patterns", package_default.dependencies["@velastack/patterns"]]
|
|
4070
4642
|
];
|
|
4071
4643
|
var EXACT_PINS = [
|
|
4072
4644
|
["sveltekit-superforms", SUPERFORMS_VERSION],
|
|
@@ -4075,7 +4647,7 @@ var EXACT_PINS = [
|
|
|
4075
4647
|
var ENGINES_FLOOR = ">=22.17";
|
|
4076
4648
|
function packageFixup(root, cliVersion) {
|
|
4077
4649
|
const f = fixup("package.json");
|
|
4078
|
-
const pkgPath =
|
|
4650
|
+
const pkgPath = path23.join(root, "package.json");
|
|
4079
4651
|
const { data, indent } = readJson(pkgPath);
|
|
4080
4652
|
const changed = [];
|
|
4081
4653
|
for (const [name, range] of [...FLOORS, ["vela", `^${cliVersion}`]]) {
|
|
@@ -4121,16 +4693,72 @@ function packageFixup(root, cliVersion) {
|
|
|
4121
4693
|
}
|
|
4122
4694
|
return f;
|
|
4123
4695
|
}
|
|
4696
|
+
function bumpedHere(name) {
|
|
4697
|
+
return name === "vela" || name.startsWith("@sveltejs/") || name.startsWith("@velastack/") || name.startsWith("@types/") || FLOORS.some(([floor]) => floor === name) || EXACT_PINS.some(([pin]) => pin === name);
|
|
4698
|
+
}
|
|
4699
|
+
async function peersFixup(root, lookup) {
|
|
4700
|
+
const f = fixup("SvelteKit 2 peers");
|
|
4701
|
+
f.followUps = [];
|
|
4702
|
+
const data = readJson(path23.join(root, "package.json")).data;
|
|
4703
|
+
const kit = depRange(data, "@sveltejs/kit") ?? "^3.0.0";
|
|
4704
|
+
const overrides = data.overrides ?? {};
|
|
4705
|
+
const overridden = (name) => {
|
|
4706
|
+
const entry = overrides[name];
|
|
4707
|
+
return typeof entry === "object" && entry !== null && "@sveltejs/kit" in entry;
|
|
4708
|
+
};
|
|
4709
|
+
const scan = await findKit2Peers(
|
|
4710
|
+
root,
|
|
4711
|
+
data,
|
|
4712
|
+
(name) => bumpedHere(name) || overridden(name),
|
|
4713
|
+
lookup
|
|
4714
|
+
);
|
|
4715
|
+
const wanted = {};
|
|
4716
|
+
for (const peer of scan.kit2) wanted[peer.name] = { "@sveltejs/kit": kit };
|
|
4717
|
+
if (scan.kit2.length > 0) {
|
|
4718
|
+
const result = await ensurePackageOverrides(root, wanted);
|
|
4719
|
+
if (result.outcome.status === "success") {
|
|
4720
|
+
if (result.outcome.changed) {
|
|
4721
|
+
f.changed = true;
|
|
4722
|
+
for (const peer of scan.kit2) {
|
|
4723
|
+
f.details.push(
|
|
4724
|
+
`overrides ${peer.name} \u2192 @sveltejs/kit ${kit} (${peer.name}@${peer.version} peers @sveltejs/kit ${peer.peer})`
|
|
4725
|
+
);
|
|
4726
|
+
}
|
|
4727
|
+
}
|
|
4728
|
+
} else {
|
|
4729
|
+
f.warnings.push(result.outcome.message ?? "could not write package.json overrides");
|
|
4730
|
+
}
|
|
4731
|
+
}
|
|
4732
|
+
const names = [
|
|
4733
|
+
...Object.keys(data.dependencies ?? {}),
|
|
4734
|
+
...Object.keys(data.devDependencies ?? {})
|
|
4735
|
+
].filter((name, i, all) => all.indexOf(name) === i);
|
|
4736
|
+
const after = readJson(path23.join(root, "package.json")).data.overrides ?? {};
|
|
4737
|
+
for (const name of names) {
|
|
4738
|
+
const entry = after[name];
|
|
4739
|
+
if (bumpedHere(name) || typeof entry !== "object" || entry === null) continue;
|
|
4740
|
+
if (!("@sveltejs/kit" in entry)) continue;
|
|
4741
|
+
f.followUps.push(
|
|
4742
|
+
`${code(name)} declares a SvelteKit 2 peer; overridden (\`overrides\` in package.json). Check it works and watch for an update that supports SvelteKit 3.`
|
|
4743
|
+
);
|
|
4744
|
+
}
|
|
4745
|
+
if (scan.unchecked.length > 0) {
|
|
4746
|
+
f.followUps.push(
|
|
4747
|
+
`Could not ask the npm registry whether these declare a SvelteKit 2 peer: ${scan.unchecked.map(code).join(", ")}. If the install fails with an ERESOLVE naming one, add \`"overrides": { "<package>": { "@sveltejs/kit": "${kit}" } }\` to package.json.`
|
|
4748
|
+
);
|
|
4749
|
+
}
|
|
4750
|
+
return f;
|
|
4751
|
+
}
|
|
4124
4752
|
function depRange(data, name) {
|
|
4125
4753
|
return data.devDependencies?.[name] ?? data.dependencies?.[name];
|
|
4126
4754
|
}
|
|
4127
4755
|
var STALE_LOCK_ENTRY = /(^|\/)node_modules\/(@sveltejs\/[^/]+|sveltekit-superforms|sveltekit-flash-message|formsnap|@velastack\/[^/]+|sveltekit-negotiate)$/;
|
|
4128
4756
|
function lockfileFixup(root) {
|
|
4129
4757
|
const f = fixup("package-lock.json");
|
|
4130
|
-
const lockPath =
|
|
4131
|
-
if (!
|
|
4758
|
+
const lockPath = path23.join(root, "package-lock.json");
|
|
4759
|
+
if (!fs25.existsSync(lockPath)) {
|
|
4132
4760
|
for (const other of ["pnpm-lock.yaml", "yarn.lock", "bun.lock", "bun.lockb"]) {
|
|
4133
|
-
if (
|
|
4761
|
+
if (fs25.existsSync(path23.join(root, other))) {
|
|
4134
4762
|
f.warnings.push(
|
|
4135
4763
|
`${other} still pins SvelteKit 2 packages; if the install fails, update @sveltejs/* with your package manager`
|
|
4136
4764
|
);
|
|
@@ -4140,7 +4768,7 @@ function lockfileFixup(root) {
|
|
|
4140
4768
|
}
|
|
4141
4769
|
const { data, indent } = readJson(lockPath);
|
|
4142
4770
|
const packages = data.packages;
|
|
4143
|
-
const project = readJson(
|
|
4771
|
+
const project = readJson(path23.join(root, "package.json")).data;
|
|
4144
4772
|
const lockedKit = packages?.["node_modules/@sveltejs/kit"]?.version;
|
|
4145
4773
|
const kit2Lock = lockedKit !== void 0 && (minVersion(lockedKit)?.major ?? 0) < 3;
|
|
4146
4774
|
const removed = [];
|
|
@@ -4172,19 +4800,24 @@ function belowFloor(project, key, entry) {
|
|
|
4172
4800
|
return Boolean(floor && locked && compareVersions(locked, floor) < 0);
|
|
4173
4801
|
}
|
|
4174
4802
|
function readJson(file) {
|
|
4175
|
-
const text19 =
|
|
4803
|
+
const text19 = fs25.readFileSync(file, "utf8");
|
|
4176
4804
|
return {
|
|
4177
4805
|
data: JSON.parse(text19),
|
|
4178
4806
|
indent: text19.match(/^[{[]\s*\n([\t ]+)/)?.[1] ?? " "
|
|
4179
4807
|
};
|
|
4180
4808
|
}
|
|
4181
4809
|
function writeJson(file, data, indent) {
|
|
4182
|
-
|
|
4810
|
+
fs25.writeFileSync(file, `${JSON.stringify(data, null, indent)}
|
|
4183
4811
|
`);
|
|
4184
4812
|
}
|
|
4185
4813
|
function collectFollowUps(root, sv) {
|
|
4186
4814
|
const items = [];
|
|
4187
|
-
const files = [...sourceFiles(
|
|
4815
|
+
const files = [...sourceFiles(path23.join(root, "src")), ...sourceFiles(path23.join(root, "test"))];
|
|
4816
|
+
for (const spread of sv.dropped) {
|
|
4817
|
+
items.push(
|
|
4818
|
+
`${code(spread.file)}: sv dropped ${code(spread.text)} when it moved the config into \`sveltekit({...})\` (it skips spread properties). Add it back there if it is still needed.`
|
|
4819
|
+
);
|
|
4820
|
+
}
|
|
4188
4821
|
for (const failure of sv.failures) {
|
|
4189
4822
|
if (failure.file) {
|
|
4190
4823
|
items.push(
|
|
@@ -4197,8 +4830,8 @@ function collectFollowUps(root, sv) {
|
|
|
4197
4830
|
}
|
|
4198
4831
|
}
|
|
4199
4832
|
for (const file of files) {
|
|
4200
|
-
const source =
|
|
4201
|
-
const rel =
|
|
4833
|
+
const source = fs25.readFileSync(file, "utf8");
|
|
4834
|
+
const rel = path23.relative(root, file).split(path23.sep).join("/");
|
|
4202
4835
|
const lines = source.split("\n");
|
|
4203
4836
|
const locals = envImports(source).filter((i) => !i.local.includes(".")).map((i) => i.local);
|
|
4204
4837
|
if (locals.length > 0) {
|
|
@@ -4212,23 +4845,36 @@ function collectFollowUps(root, sv) {
|
|
|
4212
4845
|
);
|
|
4213
4846
|
}
|
|
4214
4847
|
}
|
|
4215
|
-
|
|
4848
|
+
lines.forEach((line, i) => {
|
|
4849
|
+
const at = code(`${rel}:${i + 1}`);
|
|
4216
4850
|
if (/data-sveltekit-(?:noscroll|keepfocus)\b|data-sveltekit-reset=["']false["']/.test(line)) {
|
|
4217
4851
|
items.push(
|
|
4218
|
-
`${
|
|
4852
|
+
`${at}: ${code(line.trim())}. \`data-sveltekit-noscroll\` and \`data-sveltekit-keepfocus\` are now one \`data-sveltekit-reset\` attribute; write \`data-sveltekit-reset={false}\`: svelte-check rejects the string \`"false"\`.`
|
|
4219
4853
|
);
|
|
4220
4854
|
}
|
|
4221
4855
|
if (/(?<![\w$])ORIGIN(?![\w$])/.test(line) && !line.includes(MIGRATION_TASK_MARKER)) {
|
|
4222
4856
|
items.push(
|
|
4223
|
-
`${
|
|
4857
|
+
`${at}: ${code(line.trim())}. adapter-node 6 no longer reads \`ORIGIN\`; the origin comes from \`paths.origin\` (baked in at build time) or the request.`
|
|
4224
4858
|
);
|
|
4225
4859
|
}
|
|
4226
|
-
}
|
|
4860
|
+
});
|
|
4861
|
+
}
|
|
4862
|
+
for (const file of textFiles(path23.join(root, "src"))) {
|
|
4863
|
+
const rel = path23.relative(root, file).split(path23.sep).join("/");
|
|
4864
|
+
const source = fs25.readFileSync(file, "utf8");
|
|
4865
|
+
if (!source.includes("svelte.config.js")) continue;
|
|
4866
|
+
source.split("\n").forEach((line, i) => {
|
|
4867
|
+
if (!line.includes("svelte.config.js")) return;
|
|
4868
|
+
const excerpt = line.trim().length > 100 ? `${line.trim().slice(0, 97)}...` : line.trim();
|
|
4869
|
+
items.push(
|
|
4870
|
+
`${code(`${rel}:${i + 1}`)}: ${code(excerpt)}. It names \`svelte.config.js\`, which a SvelteKit 3 project no longer has: the config is the \`sveltekit({...})\` argument in vite.config.`
|
|
4871
|
+
);
|
|
4872
|
+
});
|
|
4227
4873
|
}
|
|
4228
4874
|
const vite = inspectViteSveltekit(root);
|
|
4229
4875
|
if (vite?.inlineArg) {
|
|
4230
4876
|
const config = vite.inlineArg.getText();
|
|
4231
|
-
const rel =
|
|
4877
|
+
const rel = path23.basename(vite.filePath);
|
|
4232
4878
|
if (/\borigin\s*:\s*['"`]/.test(config)) {
|
|
4233
4879
|
items.push(
|
|
4234
4880
|
`\`${rel}\`: \`paths.origin\` is a literal. It is baked into the build, so every host serving this app gets that origin; leave it unset for a multi-host deploy (vela sets it from VELA_ORIGIN on single-host deploys).`
|
|
@@ -4242,11 +4888,22 @@ function collectFollowUps(root, sv) {
|
|
|
4242
4888
|
}
|
|
4243
4889
|
return items;
|
|
4244
4890
|
}
|
|
4245
|
-
var
|
|
4891
|
+
var BINARY_EXTENSIONS = /\.(?:png|jpe?g|gif|webp|avif|ico|bmp|tiff?|woff2?|ttf|otf|eot|pdf|zip|gz|tgz|mp[34]|webm|mov|wav|ogg|wasm|db|sqlite3?)$/i;
|
|
4892
|
+
function textFiles(dir) {
|
|
4893
|
+
if (!fs25.existsSync(dir)) return [];
|
|
4894
|
+
return fs25.globSync("**/*", {
|
|
4895
|
+
cwd: dir,
|
|
4896
|
+
exclude: (name) => name === "node_modules" || name === ".svelte-kit"
|
|
4897
|
+
}).filter((rel) => !BINARY_EXTENSIONS.test(rel)).map((rel) => path23.join(dir, rel)).filter((file) => {
|
|
4898
|
+
const stat = fs25.statSync(file);
|
|
4899
|
+
return stat.isFile() && stat.size < 2e6;
|
|
4900
|
+
});
|
|
4901
|
+
}
|
|
4902
|
+
var SV_FAILURE_ITEM = /sv's `[^`]+` task (could not parse it|failed)|: sv dropped `/;
|
|
4246
4903
|
function previousSvFollowUps(root) {
|
|
4247
|
-
const file =
|
|
4248
|
-
if (!
|
|
4249
|
-
const content =
|
|
4904
|
+
const file = path23.join(root, MIGRATION_TASKS_FILE);
|
|
4905
|
+
if (!fs25.existsSync(file)) return [];
|
|
4906
|
+
const content = fs25.readFileSync(file, "utf8");
|
|
4250
4907
|
const start = content.indexOf(FOLLOW_UPS_HEADING);
|
|
4251
4908
|
if (start === -1) return [];
|
|
4252
4909
|
const end = content.indexOf("\n## ", start + FOLLOW_UPS_HEADING.length);
|
|
@@ -4261,11 +4918,11 @@ function escape(text19) {
|
|
|
4261
4918
|
return text19.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4262
4919
|
}
|
|
4263
4920
|
function writeFollowUps(root, items, generic) {
|
|
4264
|
-
const file =
|
|
4265
|
-
const exists =
|
|
4921
|
+
const file = path23.join(root, MIGRATION_TASKS_FILE);
|
|
4922
|
+
const exists = fs25.existsSync(file);
|
|
4266
4923
|
const all = [...items, ...generic];
|
|
4267
4924
|
if (!exists && items.length === 0) return;
|
|
4268
|
-
const original = exists ?
|
|
4925
|
+
const original = exists ? fs25.readFileSync(file, "utf8") : "# SvelteKit 3 migration tasks\n";
|
|
4269
4926
|
let content = original;
|
|
4270
4927
|
const start = content.indexOf(FOLLOW_UPS_HEADING);
|
|
4271
4928
|
if (start !== -1) {
|
|
@@ -4287,17 +4944,17 @@ function writeFollowUps(root, items, generic) {
|
|
|
4287
4944
|
${body}` : `${content.slice(0, final)}${body}
|
|
4288
4945
|
${content.slice(final)}`;
|
|
4289
4946
|
}
|
|
4290
|
-
if (content !== original)
|
|
4947
|
+
if (content !== original) fs25.writeFileSync(file, content);
|
|
4291
4948
|
}
|
|
4292
4949
|
function summarizeMigrationTasks(root) {
|
|
4293
|
-
const file =
|
|
4950
|
+
const file = path23.join(root, MIGRATION_TASKS_FILE);
|
|
4294
4951
|
const markerComments = countMarkers(root);
|
|
4295
|
-
if (!
|
|
4952
|
+
if (!fs25.existsSync(file))
|
|
4296
4953
|
return markerComments > 0 ? { sections: [], filesToReview: 0, markerComments } : null;
|
|
4297
4954
|
const sections = [];
|
|
4298
4955
|
let current = null;
|
|
4299
4956
|
let inFiles = false;
|
|
4300
|
-
for (const line of
|
|
4957
|
+
for (const line of fs25.readFileSync(file, "utf8").split("\n")) {
|
|
4301
4958
|
if (line.startsWith("## ")) {
|
|
4302
4959
|
current = null;
|
|
4303
4960
|
inFiles = false;
|
|
@@ -4317,13 +4974,13 @@ function summarizeMigrationTasks(root) {
|
|
|
4317
4974
|
}
|
|
4318
4975
|
function countMarkers(root) {
|
|
4319
4976
|
let count = 0;
|
|
4320
|
-
const files = [...sourceFiles(
|
|
4321
|
-
for (const entry of
|
|
4977
|
+
const files = [...sourceFiles(path23.join(root, "src")), ...sourceFiles(path23.join(root, "test"))];
|
|
4978
|
+
for (const entry of fs25.readdirSync(root, { withFileTypes: true })) {
|
|
4322
4979
|
if (entry.isFile() && /\.(ts|js|mts|mjs)$/.test(entry.name))
|
|
4323
|
-
files.push(
|
|
4980
|
+
files.push(path23.join(root, entry.name));
|
|
4324
4981
|
}
|
|
4325
4982
|
for (const file of files) {
|
|
4326
|
-
count +=
|
|
4983
|
+
count += fs25.readFileSync(file, "utf8").split(MIGRATION_TASK_MARKER).length - 1;
|
|
4327
4984
|
}
|
|
4328
4985
|
return count;
|
|
4329
4986
|
}
|
|
@@ -4332,18 +4989,18 @@ async function install(root) {
|
|
|
4332
4989
|
return installDependencies(agent, root, { exitOnFailure: false });
|
|
4333
4990
|
}
|
|
4334
4991
|
async function formatProject(root) {
|
|
4335
|
-
const bin =
|
|
4336
|
-
if (!
|
|
4992
|
+
const bin = path23.join(root, "node_modules", ".bin", "prettier");
|
|
4993
|
+
if (!fs25.existsSync(bin)) return;
|
|
4337
4994
|
await x2(bin, ["--write", "--ignore-unknown", "."], {
|
|
4338
4995
|
nodeOptions: { cwd: root, stdio: "ignore" }
|
|
4339
4996
|
});
|
|
4340
4997
|
}
|
|
4341
4998
|
async function formatChanged(root, dirtyBefore) {
|
|
4342
|
-
const bin =
|
|
4999
|
+
const bin = path23.join(root, "node_modules", ".bin", "prettier");
|
|
4343
5000
|
const changed = gitDirty(root);
|
|
4344
|
-
if (!changed || !
|
|
5001
|
+
if (!changed || !fs25.existsSync(bin)) return [];
|
|
4345
5002
|
const files = changed.filter(
|
|
4346
|
-
(f) => !dirtyBefore.has(f) &&
|
|
5003
|
+
(f) => !dirtyBefore.has(f) && fs25.existsSync(path23.join(root, f)) && fs25.statSync(path23.join(root, f)).isFile()
|
|
4347
5004
|
);
|
|
4348
5005
|
if (files.length === 0) return [];
|
|
4349
5006
|
const result = await x2(bin, ["--write", "--ignore-unknown", ...files], {
|
|
@@ -4353,8 +5010,8 @@ async function formatChanged(root, dirtyBefore) {
|
|
|
4353
5010
|
}
|
|
4354
5011
|
|
|
4355
5012
|
// src/lib/kit3-template-support.ts
|
|
4356
|
-
import
|
|
4357
|
-
import
|
|
5013
|
+
import fs26 from "node:fs";
|
|
5014
|
+
import path24 from "node:path";
|
|
4358
5015
|
var CMS = "@velastack/cms";
|
|
4359
5016
|
var REPEATER_REMOVED_IN = { major: 0, minor: 5, patch: 0, prerelease: [] };
|
|
4360
5017
|
var SOURCE_FILE = /\.(svelte|svx|md|[cm]?[jt]s)$/;
|
|
@@ -4381,11 +5038,11 @@ Pick another template, or create the SvelteKit 2 version with
|
|
|
4381
5038
|
}
|
|
4382
5039
|
function cmsRange(dir) {
|
|
4383
5040
|
for (const file of ["package.template.json", "package.json"]) {
|
|
4384
|
-
const pkgPath =
|
|
4385
|
-
if (!
|
|
5041
|
+
const pkgPath = path24.join(dir, file);
|
|
5042
|
+
if (!fs26.existsSync(pkgPath)) continue;
|
|
4386
5043
|
let pkg;
|
|
4387
5044
|
try {
|
|
4388
|
-
pkg = JSON.parse(
|
|
5045
|
+
pkg = JSON.parse(fs26.readFileSync(pkgPath, "utf8"));
|
|
4389
5046
|
} catch {
|
|
4390
5047
|
return void 0;
|
|
4391
5048
|
}
|
|
@@ -4394,15 +5051,15 @@ function cmsRange(dir) {
|
|
|
4394
5051
|
return void 0;
|
|
4395
5052
|
}
|
|
4396
5053
|
function findRepeaterImport(dir) {
|
|
4397
|
-
const src =
|
|
4398
|
-
if (!
|
|
4399
|
-
const entries =
|
|
5054
|
+
const src = path24.join(dir, "src");
|
|
5055
|
+
if (!fs26.existsSync(src)) return void 0;
|
|
5056
|
+
const entries = fs26.readdirSync(src, { recursive: true, withFileTypes: true });
|
|
4400
5057
|
for (const entry of entries) {
|
|
4401
5058
|
if (!entry.isFile() || !SOURCE_FILE.test(entry.name)) continue;
|
|
4402
|
-
const file =
|
|
4403
|
-
const text19 =
|
|
5059
|
+
const file = path24.join(entry.parentPath, entry.name);
|
|
5060
|
+
const text19 = fs26.readFileSync(file, "utf8");
|
|
4404
5061
|
if (text19.includes("CmsRepeater") && REPEATER_IMPORT.test(text19)) {
|
|
4405
|
-
return
|
|
5062
|
+
return path24.relative(dir, file);
|
|
4406
5063
|
}
|
|
4407
5064
|
}
|
|
4408
5065
|
return void 0;
|
|
@@ -4461,15 +5118,15 @@ var create = new Command3("create").description("scaffold a new velastack projec
|
|
|
4461
5118
|
return runCommand(async () => {
|
|
4462
5119
|
const listing = await listAllTemplates();
|
|
4463
5120
|
const options = parseOptions(optionsSchema2(listing), rawOpts);
|
|
4464
|
-
const { directory, packageManager: packageManager2, installed, migrated, name, template, link: link2 } = await createProject2(projectPath, options, listing);
|
|
4465
|
-
const relative =
|
|
5121
|
+
const { directory, packageManager: packageManager2, installed: installed2, migrated, name, template, link: link2 } = await createProject2(projectPath, options, listing);
|
|
5122
|
+
const relative = path25.relative(process13.cwd(), directory);
|
|
4466
5123
|
const pm = packageManager2 ?? (await detect4({ cwd: directory }))?.name ?? getUserAgent() ?? "npm";
|
|
4467
5124
|
const nextSteps = [];
|
|
4468
5125
|
if (relative !== "") {
|
|
4469
5126
|
const hasSpaces = relative.includes(" ");
|
|
4470
5127
|
nextSteps.push(`\`cd ${hasSpaces ? `"${relative}"` : relative}\``);
|
|
4471
5128
|
}
|
|
4472
|
-
if (!
|
|
5129
|
+
if (!installed2) {
|
|
4473
5130
|
const resolved = resolveCommand3(pm, "install", []);
|
|
4474
5131
|
if (resolved) {
|
|
4475
5132
|
nextSteps.push(
|
|
@@ -4524,7 +5181,7 @@ async function createProject2(cwdArg, options, listing) {
|
|
|
4524
5181
|
resolved.cleanup();
|
|
4525
5182
|
}
|
|
4526
5183
|
const { directory: projectPath, name, credentials, link: link2 } = scaffolded;
|
|
4527
|
-
if (!
|
|
5184
|
+
if (!fs27.existsSync(path25.join(projectPath, "package.json"))) {
|
|
4528
5185
|
throw new Error(`Template ${template.name} is missing package.template.json`);
|
|
4529
5186
|
}
|
|
4530
5187
|
if (link2.linked) {
|
|
@@ -4534,14 +5191,14 @@ async function createProject2(cwdArg, options, listing) {
|
|
|
4534
5191
|
const migrated = await migrateKit2Template(projectPath, template.name);
|
|
4535
5192
|
p10.log.success("Project created");
|
|
4536
5193
|
let packageManager2;
|
|
4537
|
-
let
|
|
5194
|
+
let installed2 = false;
|
|
4538
5195
|
if (options.install !== false) {
|
|
4539
5196
|
const pm = typeof options.install === "string" ? options.install : await packageManagerPrompt(projectPath);
|
|
4540
5197
|
if (pm) {
|
|
4541
5198
|
const builds = template.backend ? ["esbuild", "pocketbase-server"] : ["esbuild"];
|
|
4542
5199
|
addPnpmBuildDependencies(projectPath, pm, builds);
|
|
4543
|
-
|
|
4544
|
-
if (migrated &&
|
|
5200
|
+
installed2 = await installDependencies(pm, projectPath);
|
|
5201
|
+
if (migrated && installed2) await formatProject(projectPath);
|
|
4545
5202
|
packageManager2 = pm;
|
|
4546
5203
|
}
|
|
4547
5204
|
}
|
|
@@ -4568,7 +5225,7 @@ async function createProject2(cwdArg, options, listing) {
|
|
|
4568
5225
|
);
|
|
4569
5226
|
p10.log.success("PocketBase initialized");
|
|
4570
5227
|
}
|
|
4571
|
-
return { directory: projectPath, packageManager: packageManager2, installed, migrated, name, template, link: link2 };
|
|
5228
|
+
return { directory: projectPath, packageManager: packageManager2, installed: installed2, migrated, name, template, link: link2 };
|
|
4572
5229
|
}
|
|
4573
5230
|
async function resolveCreatableTemplate(template) {
|
|
4574
5231
|
if (template.source === "remote") p10.log.step(`Downloading template ${template.name}...`);
|
|
@@ -4583,7 +5240,7 @@ async function resolveCreatableTemplate(template) {
|
|
|
4583
5240
|
async function scaffoldProject(cwdArg, options, template, resolved, onCancel2) {
|
|
4584
5241
|
let directory;
|
|
4585
5242
|
if (cwdArg) {
|
|
4586
|
-
directory =
|
|
5243
|
+
directory = path25.resolve(cwdArg);
|
|
4587
5244
|
} else {
|
|
4588
5245
|
const answer = await p10.text({
|
|
4589
5246
|
message: "Where would you like your project to be created?",
|
|
@@ -4591,16 +5248,16 @@ async function scaffoldProject(cwdArg, options, template, resolved, onCancel2) {
|
|
|
4591
5248
|
defaultValue: "./"
|
|
4592
5249
|
});
|
|
4593
5250
|
if (p10.isCancel(answer)) onCancel2();
|
|
4594
|
-
directory =
|
|
5251
|
+
directory = path25.resolve(answer);
|
|
4595
5252
|
}
|
|
4596
|
-
if (
|
|
5253
|
+
if (fs27.existsSync(directory) && fs27.readdirSync(directory).filter((f) => !f.startsWith(".git")).length > 0) {
|
|
4597
5254
|
const force = await p10.confirm({
|
|
4598
5255
|
message: "Directory not empty. Continue?",
|
|
4599
5256
|
initialValue: false
|
|
4600
5257
|
});
|
|
4601
5258
|
if (p10.isCancel(force) || !force) onCancel2();
|
|
4602
5259
|
}
|
|
4603
|
-
const dirName =
|
|
5260
|
+
const dirName = path25.basename(directory);
|
|
4604
5261
|
const { name } = await p10.group(
|
|
4605
5262
|
{
|
|
4606
5263
|
name: () => {
|
|
@@ -4634,7 +5291,7 @@ async function migrateKit2Template(projectPath, templateName2) {
|
|
|
4634
5291
|
try {
|
|
4635
5292
|
result = await runKit3Migration(projectPath, { gitCheck: false, install: false, quiet: true });
|
|
4636
5293
|
} catch (e) {
|
|
4637
|
-
const relative =
|
|
5294
|
+
const relative = path25.relative(process13.cwd(), projectPath) || ".";
|
|
4638
5295
|
throw new Error(
|
|
4639
5296
|
`Could not migrate template ${templateName2} to SvelteKit 3: ${e.message}
|
|
4640
5297
|
|
|
@@ -4645,11 +5302,11 @@ The project is in ${projectPath}. Finish the migration by hand with
|
|
|
4645
5302
|
);
|
|
4646
5303
|
}
|
|
4647
5304
|
const tasks = result.tasks;
|
|
4648
|
-
const tasksFile =
|
|
4649
|
-
if (
|
|
4650
|
-
|
|
5305
|
+
const tasksFile = path25.join(projectPath, MIGRATION_TASKS_FILE);
|
|
5306
|
+
if (fs27.existsSync(tasksFile) && !tasks?.filesToReview && result.followUps.length === 0) {
|
|
5307
|
+
fs27.rmSync(tasksFile);
|
|
4651
5308
|
}
|
|
4652
|
-
const left =
|
|
5309
|
+
const left = fs27.existsSync(tasksFile);
|
|
4653
5310
|
p10.log.success(
|
|
4654
5311
|
`Migrated to SvelteKit 3${left ? `; ${MIGRATION_TASKS_FILE} lists what to check by hand` : ""}.`
|
|
4655
5312
|
);
|
|
@@ -4743,7 +5400,7 @@ ${FREE_CMS_HINT}.`, "CMS");
|
|
|
4743
5400
|
}
|
|
4744
5401
|
function hasScript(directory, name) {
|
|
4745
5402
|
try {
|
|
4746
|
-
const pkg = JSON.parse(
|
|
5403
|
+
const pkg = JSON.parse(fs27.readFileSync(path25.join(directory, "package.json"), "utf8"));
|
|
4747
5404
|
return typeof pkg.scripts?.[name] === "string";
|
|
4748
5405
|
} catch {
|
|
4749
5406
|
return false;
|
|
@@ -4758,7 +5415,7 @@ import { Command as Command4 } from "commander";
|
|
|
4758
5415
|
import * as p16 from "@clack/prompts";
|
|
4759
5416
|
|
|
4760
5417
|
// src/lib/pattern-runner.ts
|
|
4761
|
-
import
|
|
5418
|
+
import path26 from "node:path";
|
|
4762
5419
|
import * as p11 from "@clack/prompts";
|
|
4763
5420
|
import { bySlug as bySlug2 } from "@velastack/patterns";
|
|
4764
5421
|
|
|
@@ -4777,7 +5434,7 @@ Then run this again.`
|
|
|
4777
5434
|
|
|
4778
5435
|
// src/lib/pattern-runner.ts
|
|
4779
5436
|
function toRelative(root, filePath) {
|
|
4780
|
-
return
|
|
5437
|
+
return path26.isAbsolute(filePath) ? path26.relative(root, filePath) : filePath;
|
|
4781
5438
|
}
|
|
4782
5439
|
var isSuccess = (f) => (f.status ?? "success") === "success";
|
|
4783
5440
|
async function runPattern(slug2, argv, input, report4, after) {
|
|
@@ -4859,10 +5516,10 @@ async function runPattern(slug2, argv, input, report4, after) {
|
|
|
4859
5516
|
}
|
|
4860
5517
|
|
|
4861
5518
|
// src/lib/form-ui.ts
|
|
4862
|
-
import
|
|
5519
|
+
import path27 from "node:path";
|
|
4863
5520
|
var UIS = ["shadcn", "plain"];
|
|
4864
5521
|
function detectFormInput(root) {
|
|
4865
|
-
const pkg = readPackageJson(
|
|
5522
|
+
const pkg = readPackageJson(path27.join(root, "package.json"));
|
|
4866
5523
|
const hasDep = (name) => Boolean(pkg.dependencies?.[name] || pkg.devDependencies?.[name]);
|
|
4867
5524
|
return {
|
|
4868
5525
|
flash: hasDep("sveltekit-flash-message"),
|
|
@@ -4884,8 +5541,8 @@ function resolveFormInput(root, detectedUi, requested) {
|
|
|
4884
5541
|
}
|
|
4885
5542
|
|
|
4886
5543
|
// src/lib/ai-flow.ts
|
|
4887
|
-
import
|
|
4888
|
-
import
|
|
5544
|
+
import fs28 from "node:fs";
|
|
5545
|
+
import path28 from "node:path";
|
|
4889
5546
|
import * as p15 from "@clack/prompts";
|
|
4890
5547
|
import pc4 from "picocolors";
|
|
4891
5548
|
|
|
@@ -5160,15 +5817,15 @@ function specToArgv(spec) {
|
|
|
5160
5817
|
return collectionSpecToArgv(spec);
|
|
5161
5818
|
}
|
|
5162
5819
|
function writeLayoutSidecar(workspaceRootDir, modelName, layout) {
|
|
5163
|
-
const dir =
|
|
5820
|
+
const dir = path28.join(
|
|
5164
5821
|
workspaceRootDir,
|
|
5165
5822
|
hasBackend(workspaceRootDir) ? DATA_DIR : ".vela",
|
|
5166
5823
|
"ai-form-layouts"
|
|
5167
5824
|
);
|
|
5168
|
-
|
|
5169
|
-
const file =
|
|
5170
|
-
|
|
5171
|
-
return
|
|
5825
|
+
fs28.mkdirSync(dir, { recursive: true });
|
|
5826
|
+
const file = path28.join(dir, `${modelName}.json`);
|
|
5827
|
+
fs28.writeFileSync(file, JSON.stringify(layout, null, 2) + "\n");
|
|
5828
|
+
return path28.relative(workspaceRootDir, file);
|
|
5172
5829
|
}
|
|
5173
5830
|
|
|
5174
5831
|
// src/commands/generate/form.ts
|
|
@@ -5890,8 +6547,8 @@ import * as p21 from "@clack/prompts";
|
|
|
5890
6547
|
import pc6 from "picocolors";
|
|
5891
6548
|
|
|
5892
6549
|
// src/lib/deploy-config.ts
|
|
5893
|
-
import
|
|
5894
|
-
import
|
|
6550
|
+
import fs29 from "node:fs";
|
|
6551
|
+
import path29 from "node:path";
|
|
5895
6552
|
import crypto from "node:crypto";
|
|
5896
6553
|
import { pathToFileURL } from "node:url";
|
|
5897
6554
|
var CONFIG_BASENAMES = [
|
|
@@ -5902,8 +6559,8 @@ var CONFIG_BASENAMES = [
|
|
|
5902
6559
|
];
|
|
5903
6560
|
function findConfigFile(workspaceRootDir) {
|
|
5904
6561
|
for (const name of CONFIG_BASENAMES) {
|
|
5905
|
-
const file =
|
|
5906
|
-
if (
|
|
6562
|
+
const file = path29.join(workspaceRootDir, name);
|
|
6563
|
+
if (fs29.existsSync(file)) return file;
|
|
5907
6564
|
}
|
|
5908
6565
|
return null;
|
|
5909
6566
|
}
|
|
@@ -5911,49 +6568,49 @@ async function loadDeployConfig(workspaceRootDir) {
|
|
|
5911
6568
|
const file = findConfigFile(workspaceRootDir);
|
|
5912
6569
|
if (!file) return {};
|
|
5913
6570
|
if (file.endsWith(".json")) {
|
|
5914
|
-
return JSON.parse(
|
|
6571
|
+
return JSON.parse(fs29.readFileSync(file, "utf8"));
|
|
5915
6572
|
}
|
|
5916
6573
|
const url = file.endsWith(".ts") ? await transpileToTemp(file) : pathToFileURL(file).href;
|
|
5917
6574
|
try {
|
|
5918
6575
|
const mod = await import(url);
|
|
5919
6576
|
const config = mod.default;
|
|
5920
6577
|
if (!config || typeof config !== "object") {
|
|
5921
|
-
throw new Error(`${
|
|
6578
|
+
throw new Error(`${path29.basename(file)} must export a config object as its default export.`);
|
|
5922
6579
|
}
|
|
5923
6580
|
return config;
|
|
5924
6581
|
} finally {
|
|
5925
|
-
if (url !== pathToFileURL(file).href)
|
|
6582
|
+
if (url !== pathToFileURL(file).href) fs29.rmSync(new URL(url), { force: true });
|
|
5926
6583
|
}
|
|
5927
6584
|
}
|
|
5928
6585
|
async function transpileToTemp(file) {
|
|
5929
6586
|
const { ts: ts2 } = await import("ts-morph");
|
|
5930
|
-
const source =
|
|
6587
|
+
const source = fs29.readFileSync(file, "utf8");
|
|
5931
6588
|
const { outputText } = ts2.transpileModule(source, {
|
|
5932
6589
|
compilerOptions: { module: ts2.ModuleKind.ESNext, target: ts2.ScriptTarget.ES2022 }
|
|
5933
6590
|
});
|
|
5934
|
-
const temp =
|
|
5935
|
-
|
|
6591
|
+
const temp = path29.join(
|
|
6592
|
+
path29.dirname(file),
|
|
5936
6593
|
`.velastack.config.${crypto.randomBytes(4).toString("hex")}.mjs`
|
|
5937
6594
|
);
|
|
5938
|
-
|
|
6595
|
+
fs29.writeFileSync(temp, outputText);
|
|
5939
6596
|
return pathToFileURL(temp).href;
|
|
5940
6597
|
}
|
|
5941
6598
|
function projectFilePath(workspaceRootDir) {
|
|
5942
|
-
return
|
|
6599
|
+
return path29.join(workspaceRootDir, ".vela", "project.json");
|
|
5943
6600
|
}
|
|
5944
6601
|
function readProjectFile(workspaceRootDir) {
|
|
5945
6602
|
const file = projectFilePath(workspaceRootDir);
|
|
5946
|
-
if (!
|
|
6603
|
+
if (!fs29.existsSync(file)) return {};
|
|
5947
6604
|
try {
|
|
5948
|
-
return JSON.parse(
|
|
6605
|
+
return JSON.parse(fs29.readFileSync(file, "utf8"));
|
|
5949
6606
|
} catch {
|
|
5950
6607
|
return {};
|
|
5951
6608
|
}
|
|
5952
6609
|
}
|
|
5953
6610
|
function writeProjectFile(workspaceRootDir, data) {
|
|
5954
6611
|
const file = projectFilePath(workspaceRootDir);
|
|
5955
|
-
|
|
5956
|
-
|
|
6612
|
+
fs29.mkdirSync(path29.dirname(file), { recursive: true });
|
|
6613
|
+
fs29.writeFileSync(file, JSON.stringify(data, null, 2) + "\n");
|
|
5957
6614
|
}
|
|
5958
6615
|
function resolveAppIdentity(workspaceRootDir, config = {}) {
|
|
5959
6616
|
const project = readProjectFile(workspaceRootDir);
|
|
@@ -5978,11 +6635,11 @@ function readAppIdentity(workspaceRootDir, config = {}) {
|
|
|
5978
6635
|
}
|
|
5979
6636
|
function defaultProjectName(workspaceRootDir) {
|
|
5980
6637
|
try {
|
|
5981
|
-
const pkg = readPackageJson(
|
|
6638
|
+
const pkg = readPackageJson(path29.join(workspaceRootDir, "package.json"));
|
|
5982
6639
|
if (typeof pkg.name === "string" && pkg.name.trim()) return pkg.name.trim();
|
|
5983
6640
|
} catch {
|
|
5984
6641
|
}
|
|
5985
|
-
return
|
|
6642
|
+
return path29.basename(workspaceRootDir);
|
|
5986
6643
|
}
|
|
5987
6644
|
function slug(value) {
|
|
5988
6645
|
return value.toLowerCase().replace(/^@/, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 32) || "app";
|
|
@@ -6053,15 +6710,15 @@ function randomSuffix() {
|
|
|
6053
6710
|
}
|
|
6054
6711
|
|
|
6055
6712
|
// src/lib/artifact.ts
|
|
6056
|
-
import
|
|
6057
|
-
import
|
|
6713
|
+
import fs31 from "node:fs";
|
|
6714
|
+
import path31 from "node:path";
|
|
6058
6715
|
import { detect as detect5 } from "package-manager-detector";
|
|
6059
6716
|
import { resolveCommand as resolveCommand4 } from "package-manager-detector/commands";
|
|
6060
6717
|
|
|
6061
6718
|
// src/lib/ssh.ts
|
|
6062
|
-
import
|
|
6719
|
+
import fs30 from "node:fs";
|
|
6063
6720
|
import os4 from "node:os";
|
|
6064
|
-
import
|
|
6721
|
+
import path30 from "node:path";
|
|
6065
6722
|
import crypto3 from "node:crypto";
|
|
6066
6723
|
import process16 from "node:process";
|
|
6067
6724
|
import { spawn as spawn3 } from "node:child_process";
|
|
@@ -6104,9 +6761,9 @@ var SshSession = class {
|
|
|
6104
6761
|
}
|
|
6105
6762
|
async open() {
|
|
6106
6763
|
if (this.controlPath) return;
|
|
6107
|
-
const dir =
|
|
6108
|
-
|
|
6109
|
-
const socket =
|
|
6764
|
+
const dir = path30.join(os4.tmpdir(), "vela-ssh");
|
|
6765
|
+
fs30.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
6766
|
+
const socket = path30.join(dir, `${crypto3.randomBytes(6).toString("hex")}.sock`);
|
|
6110
6767
|
this.controlPath = socket;
|
|
6111
6768
|
const args = [
|
|
6112
6769
|
...this.sshArgs(),
|
|
@@ -6396,11 +7053,11 @@ function collectArtifact(cwd, config = {}) {
|
|
|
6396
7053
|
const outputDir = config.outputDir ?? DEFAULT_OUTPUT_DIR;
|
|
6397
7054
|
const entries = [];
|
|
6398
7055
|
const add2 = (rel, remoteDir = "") => {
|
|
6399
|
-
const localPath =
|
|
6400
|
-
if (
|
|
7056
|
+
const localPath = path31.join(cwd, rel);
|
|
7057
|
+
if (fs31.existsSync(localPath)) entries.push({ localPath, remoteDir });
|
|
6401
7058
|
};
|
|
6402
|
-
const buildPath =
|
|
6403
|
-
if (!
|
|
7059
|
+
const buildPath = path31.join(cwd, outputDir);
|
|
7060
|
+
if (!fs31.existsSync(path31.join(buildPath, "index.js"))) {
|
|
6404
7061
|
throw new BuildError(
|
|
6405
7062
|
`No ${outputDir}/index.js to deploy.
|
|
6406
7063
|
|
|
@@ -6414,19 +7071,19 @@ matches where it writes), then deploy again.`
|
|
|
6414
7071
|
for (const lockfile of [NPM_LOCKFILE, ...FOREIGN_LOCKFILES]) add2(lockfile);
|
|
6415
7072
|
add2(".npmrc");
|
|
6416
7073
|
add2(MIGRATIONS_DIR);
|
|
6417
|
-
const hooks =
|
|
6418
|
-
if (
|
|
7074
|
+
const hooks = path31.join(cwd, DATA_DIR, "hooks");
|
|
7075
|
+
if (fs31.existsSync(hooks)) entries.push({ localPath: hooks, remoteDir: "hooks" });
|
|
6419
7076
|
for (const extra of config.include ?? []) add2(extra);
|
|
6420
7077
|
return entries;
|
|
6421
7078
|
}
|
|
6422
7079
|
var NPM_LOCKFILE = "package-lock.json";
|
|
6423
7080
|
var FOREIGN_LOCKFILES = ["pnpm-lock.yaml", "yarn.lock", "bun.lock", "bun.lockb"];
|
|
6424
7081
|
function hasLockfile(cwd) {
|
|
6425
|
-
return
|
|
7082
|
+
return fs31.existsSync(path31.join(cwd, NPM_LOCKFILE));
|
|
6426
7083
|
}
|
|
6427
7084
|
function foreignLockfile(cwd) {
|
|
6428
7085
|
if (hasLockfile(cwd)) return void 0;
|
|
6429
|
-
return FOREIGN_LOCKFILES.find((name) =>
|
|
7086
|
+
return FOREIGN_LOCKFILES.find((name) => fs31.existsSync(path31.join(cwd, name)));
|
|
6430
7087
|
}
|
|
6431
7088
|
async function gitSha(cwd) {
|
|
6432
7089
|
const result = await spawnCapture("git", ["rev-parse", "HEAD"], { cwd });
|
|
@@ -6465,8 +7122,8 @@ function sshOptionsFrom(options) {
|
|
|
6465
7122
|
|
|
6466
7123
|
// src/lib/remote.ts
|
|
6467
7124
|
import crypto4 from "node:crypto";
|
|
6468
|
-
import
|
|
6469
|
-
import
|
|
7125
|
+
import fs32 from "node:fs";
|
|
7126
|
+
import path32 from "node:path";
|
|
6470
7127
|
import process17 from "node:process";
|
|
6471
7128
|
var VELA_ROOT = "/var/lib/vela";
|
|
6472
7129
|
var VELA_ETC = "/etc/vela";
|
|
@@ -6479,19 +7136,19 @@ function instanceHasBackend(state) {
|
|
|
6479
7136
|
return state.backend ?? Boolean(state.pbPort);
|
|
6480
7137
|
}
|
|
6481
7138
|
function serverTemplatesDir() {
|
|
6482
|
-
return
|
|
7139
|
+
return path32.join(templatesDir(), "server");
|
|
6483
7140
|
}
|
|
6484
7141
|
var DIGEST_LENGTH = 12;
|
|
6485
7142
|
function serverScriptsDigest(dir = serverTemplatesDir()) {
|
|
6486
7143
|
const hash = crypto4.createHash("sha256");
|
|
6487
7144
|
for (const file of listFiles(dir).sort()) {
|
|
6488
|
-
hash.update(file).update("\0").update(
|
|
7145
|
+
hash.update(file).update("\0").update(fs32.readFileSync(path32.join(dir, file))).update("\0");
|
|
6489
7146
|
}
|
|
6490
7147
|
return hash.digest("hex").slice(0, DIGEST_LENGTH);
|
|
6491
7148
|
}
|
|
6492
7149
|
function listFiles(root, prefix = "") {
|
|
6493
7150
|
const files = [];
|
|
6494
|
-
for (const entry of
|
|
7151
|
+
for (const entry of fs32.readdirSync(path32.join(root, prefix), { withFileTypes: true })) {
|
|
6495
7152
|
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
6496
7153
|
if (entry.isDirectory()) files.push(...listFiles(root, rel));
|
|
6497
7154
|
else if (entry.isFile()) files.push(rel);
|
|
@@ -6610,7 +7267,7 @@ var remotePaths = {
|
|
|
6610
7267
|
};
|
|
6611
7268
|
|
|
6612
7269
|
// src/lib/remote-env.ts
|
|
6613
|
-
import
|
|
7270
|
+
import fs33 from "node:fs";
|
|
6614
7271
|
import dotenv from "dotenv";
|
|
6615
7272
|
var KEY_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
6616
7273
|
function isValidKey(key) {
|
|
@@ -6658,7 +7315,7 @@ function quote(value) {
|
|
|
6658
7315
|
return `"${escaped}"`;
|
|
6659
7316
|
}
|
|
6660
7317
|
function readLocalEnvFile(file) {
|
|
6661
|
-
const parsed = dotenv.parse(
|
|
7318
|
+
const parsed = dotenv.parse(fs33.readFileSync(file));
|
|
6662
7319
|
const result = {};
|
|
6663
7320
|
for (const [key, value] of Object.entries(parsed)) {
|
|
6664
7321
|
if (isValidKey(key)) result[key] = value;
|
|
@@ -6984,17 +7641,17 @@ function envFilePath(workspaceRootDir) {
|
|
|
6984
7641
|
import pc8 from "picocolors";
|
|
6985
7642
|
|
|
6986
7643
|
// src/lib/local-env.ts
|
|
6987
|
-
import
|
|
7644
|
+
import fs34 from "node:fs";
|
|
6988
7645
|
import * as p22 from "@clack/prompts";
|
|
6989
7646
|
import pc7 from "picocolors";
|
|
6990
7647
|
function readLocalEnv(envFile) {
|
|
6991
|
-
if (!
|
|
7648
|
+
if (!fs34.existsSync(envFile)) return {};
|
|
6992
7649
|
return readLocalEnvFile(envFile);
|
|
6993
7650
|
}
|
|
6994
7651
|
function editLocalEnv(envFile, edit) {
|
|
6995
|
-
const before =
|
|
7652
|
+
const before = fs34.existsSync(envFile) ? fs34.readFileSync(envFile, "utf8") : "";
|
|
6996
7653
|
const after = edit(before);
|
|
6997
|
-
if (after !== before)
|
|
7654
|
+
if (after !== before) fs34.writeFileSync(envFile, after);
|
|
6998
7655
|
}
|
|
6999
7656
|
function setLocalEnv(envFile, key, value) {
|
|
7000
7657
|
editLocalEnv(envFile, (content) => upsertEnvVar(content, key, value));
|
|
@@ -7131,8 +7788,8 @@ Set ${pc8.cyan("POCKETBASE_SUPERUSER_EMAIL")} and ${pc8.cyan("POCKETBASE_SUPERUS
|
|
|
7131
7788
|
}
|
|
7132
7789
|
|
|
7133
7790
|
// src/lib/s3-settings.ts
|
|
7134
|
-
import
|
|
7135
|
-
import
|
|
7791
|
+
import fs35 from "node:fs";
|
|
7792
|
+
import path33 from "node:path";
|
|
7136
7793
|
var VIRTUAL_HOSTED = [/\.amazonaws\.com$/i, /\.r2\.cloudflarestorage\.com$/i];
|
|
7137
7794
|
function defaultForcePathStyle(endpoint) {
|
|
7138
7795
|
let host;
|
|
@@ -7170,18 +7827,18 @@ async function hasLocalUploads(session, instance, workspaceRootDir) {
|
|
|
7170
7827
|
});
|
|
7171
7828
|
return result.stdout.trim().length > 0;
|
|
7172
7829
|
}
|
|
7173
|
-
return hasFile(
|
|
7830
|
+
return hasFile(path33.join(workspaceRootDir, DATA_DIR, "storage"));
|
|
7174
7831
|
}
|
|
7175
7832
|
function hasFile(dir) {
|
|
7176
7833
|
let entries;
|
|
7177
7834
|
try {
|
|
7178
|
-
entries =
|
|
7835
|
+
entries = fs35.readdirSync(dir, { withFileTypes: true });
|
|
7179
7836
|
} catch {
|
|
7180
7837
|
return false;
|
|
7181
7838
|
}
|
|
7182
7839
|
for (const entry of entries) {
|
|
7183
7840
|
if (entry.isFile()) return true;
|
|
7184
|
-
if (entry.isDirectory() && hasFile(
|
|
7841
|
+
if (entry.isDirectory() && hasFile(path33.join(dir, entry.name))) return true;
|
|
7185
7842
|
}
|
|
7186
7843
|
return false;
|
|
7187
7844
|
}
|
|
@@ -7356,10 +8013,10 @@ import * as p25 from "@clack/prompts";
|
|
|
7356
8013
|
import pc10 from "picocolors";
|
|
7357
8014
|
|
|
7358
8015
|
// src/lib/adapter.ts
|
|
7359
|
-
import
|
|
7360
|
-
import
|
|
8016
|
+
import fs36 from "node:fs";
|
|
8017
|
+
import path34 from "node:path";
|
|
7361
8018
|
import {
|
|
7362
|
-
SyntaxKind as
|
|
8019
|
+
SyntaxKind as SyntaxKind4
|
|
7363
8020
|
} from "ts-morph";
|
|
7364
8021
|
import { detect as detect6 } from "package-manager-detector";
|
|
7365
8022
|
var ADAPTER_NODE2 = "@sveltejs/adapter-node";
|
|
@@ -7382,7 +8039,7 @@ function resolveKitTarget(root) {
|
|
|
7382
8039
|
const svelteConfig = findSvelteConfig(root);
|
|
7383
8040
|
if (svelteConfig) {
|
|
7384
8041
|
throw new AdapterError(
|
|
7385
|
-
`${
|
|
8042
|
+
`${path34.basename(svelteConfig)} found: this looks like a SvelteKit 2 project, and
|
|
7386
8043
|
SvelteKit 3 reads its config only from sveltekit({...}) in vite.config.
|
|
7387
8044
|
|
|
7388
8045
|
Migrate it first:`,
|
|
@@ -7400,7 +8057,7 @@ Migrate it first:`,
|
|
|
7400
8057
|
};
|
|
7401
8058
|
}
|
|
7402
8059
|
if (vite?.sveltekitCall) {
|
|
7403
|
-
const name =
|
|
8060
|
+
const name = path34.basename(vite.filePath);
|
|
7404
8061
|
if (vite.nonObjectArg) {
|
|
7405
8062
|
throw new AdapterError(`${name} passes sveltekit() something other than an object literal.`);
|
|
7406
8063
|
}
|
|
@@ -7431,15 +8088,15 @@ function inspectAdapter(target) {
|
|
|
7431
8088
|
const base2 = { file: target.filePath };
|
|
7432
8089
|
const prop = target.kit.getProperty("adapter");
|
|
7433
8090
|
if (!prop) return { info: { ...base2, kind: "none" } };
|
|
7434
|
-
if (prop.getKind() !==
|
|
8091
|
+
if (prop.getKind() !== SyntaxKind4.PropertyAssignment) {
|
|
7435
8092
|
return { info: { ...base2, kind: "other" } };
|
|
7436
8093
|
}
|
|
7437
|
-
const init = prop.asKindOrThrow(
|
|
7438
|
-
if (!init || init.getKind() !==
|
|
8094
|
+
const init = prop.asKindOrThrow(SyntaxKind4.PropertyAssignment).getInitializer();
|
|
8095
|
+
if (!init || init.getKind() !== SyntaxKind4.CallExpression) {
|
|
7439
8096
|
return { info: { ...base2, kind: "other" } };
|
|
7440
8097
|
}
|
|
7441
|
-
const callee = init.asKindOrThrow(
|
|
7442
|
-
if (callee.getKind() !==
|
|
8098
|
+
const callee = init.asKindOrThrow(SyntaxKind4.CallExpression).getExpression();
|
|
8099
|
+
if (callee.getKind() !== SyntaxKind4.Identifier) {
|
|
7443
8100
|
return { info: { ...base2, kind: "other" } };
|
|
7444
8101
|
}
|
|
7445
8102
|
const importDecl = importOf(target.sourceFile, callee.getText());
|
|
@@ -7453,7 +8110,7 @@ function detectAdapter(root) {
|
|
|
7453
8110
|
async function ensureNodeAdapter(root, { install: install2 = true } = {}) {
|
|
7454
8111
|
const target = resolveKitTarget(root);
|
|
7455
8112
|
const { info, importDecl } = inspectAdapter(target);
|
|
7456
|
-
const name =
|
|
8113
|
+
const name = path34.basename(target.filePath);
|
|
7457
8114
|
const outcome = {
|
|
7458
8115
|
previous: info.kind,
|
|
7459
8116
|
removedDeps: [],
|
|
@@ -7486,8 +8143,8 @@ vela deploy runs the app as a Node server, which needs ${ADAPTER_NODE2}:`
|
|
|
7486
8143
|
break;
|
|
7487
8144
|
}
|
|
7488
8145
|
if (outcome.configFile) saveTarget(target);
|
|
7489
|
-
const pkgPath =
|
|
7490
|
-
if (
|
|
8146
|
+
const pkgPath = path34.join(root, "package.json");
|
|
8147
|
+
if (fs36.existsSync(pkgPath)) {
|
|
7491
8148
|
const pkg = readPackageJson(pkgPath);
|
|
7492
8149
|
const { changed, removed } = adoptNodeAdapter(pkg);
|
|
7493
8150
|
if (changed) {
|
|
@@ -7524,8 +8181,8 @@ The config and package.json are already updated: run \`${agent} install\`, then
|
|
|
7524
8181
|
}
|
|
7525
8182
|
function switchImport(target, importDecl) {
|
|
7526
8183
|
importDecl.setModuleSpecifier(ADAPTER_NODE2);
|
|
7527
|
-
const prop = target.kit.getPropertyOrThrow("adapter").asKindOrThrow(
|
|
7528
|
-
const call = prop.getInitializerIfKindOrThrow(
|
|
8184
|
+
const prop = target.kit.getPropertyOrThrow("adapter").asKindOrThrow(SyntaxKind4.PropertyAssignment);
|
|
8185
|
+
const call = prop.getInitializerIfKindOrThrow(SyntaxKind4.CallExpression);
|
|
7529
8186
|
for (let i = call.getArguments().length - 1; i >= 0; i--) call.removeArgument(i);
|
|
7530
8187
|
dropAdapterAutoComments(target);
|
|
7531
8188
|
}
|
|
@@ -7547,7 +8204,7 @@ function addAdapter(target) {
|
|
|
7547
8204
|
const taken = importOf(target.sourceFile, "adapter") ?? target.sourceFile.getVariableDeclaration("adapter");
|
|
7548
8205
|
if (taken) {
|
|
7549
8206
|
throw new AdapterError(
|
|
7550
|
-
`${
|
|
8207
|
+
`${path34.basename(target.filePath)} already binds the name \`adapter\` to something that is not the SvelteKit adapter.`
|
|
7551
8208
|
);
|
|
7552
8209
|
}
|
|
7553
8210
|
target.sourceFile.addImportDeclaration({
|
|
@@ -8531,10 +9188,10 @@ var NEXT_STEPS = [
|
|
|
8531
9188
|
`Run \`vela ui base <color>\` to change the palette (${BASE_COLORS.join(", ")}), or \`vela ui list\` to see what else is available.`
|
|
8532
9189
|
];
|
|
8533
9190
|
function uiAddReport(requested, outcome) {
|
|
8534
|
-
const { installed, skipped, packages } = outcome;
|
|
9191
|
+
const { installed: installed2, skipped, packages } = outcome;
|
|
8535
9192
|
const report4 = {
|
|
8536
|
-
summary:
|
|
8537
|
-
componentsAdded:
|
|
9193
|
+
summary: installed2.length > 0 ? `Added ${installed2.length} UI component(s).` : `All ${new Set(requested).size} requested component(s) are already present.`,
|
|
9194
|
+
componentsAdded: installed2,
|
|
8538
9195
|
packagesInstalled: packages,
|
|
8539
9196
|
nextSteps: [...NEXT_STEPS]
|
|
8540
9197
|
};
|
|
@@ -8606,13 +9263,13 @@ import { listComponents } from "@velastack/patterns";
|
|
|
8606
9263
|
|
|
8607
9264
|
// src/lib/ui-list.ts
|
|
8608
9265
|
function uiListReport(result) {
|
|
8609
|
-
const
|
|
9266
|
+
const installed2 = new Set(result.installed);
|
|
8610
9267
|
const registryUi = result.registry.filter((item) => item.type === "registry:ui").map((item) => item.name).sort();
|
|
8611
9268
|
const sections = [
|
|
8612
9269
|
{ label: `Installed (${result.installed.length})`, items: result.installed },
|
|
8613
9270
|
{
|
|
8614
9271
|
label: "Vela components",
|
|
8615
|
-
items: result.custom.map((name) =>
|
|
9272
|
+
items: result.custom.map((name) => installed2.has(name) ? `${name} (installed)` : name)
|
|
8616
9273
|
}
|
|
8617
9274
|
];
|
|
8618
9275
|
if (!result.registryUnavailable) {
|
|
@@ -8776,14 +9433,14 @@ var ui = new Command55("ui").description("generate ui components").configureHelp
|
|
|
8776
9433
|
import { Command as Command58 } from "commander";
|
|
8777
9434
|
|
|
8778
9435
|
// src/commands/legal/terms.ts
|
|
8779
|
-
import
|
|
9436
|
+
import path36 from "node:path";
|
|
8780
9437
|
import { Command as Command56 } from "commander";
|
|
8781
9438
|
import * as p38 from "@clack/prompts";
|
|
8782
9439
|
|
|
8783
9440
|
// src/commands/legal/shared.ts
|
|
8784
9441
|
import process26 from "node:process";
|
|
8785
|
-
import
|
|
8786
|
-
import
|
|
9442
|
+
import fs37 from "node:fs";
|
|
9443
|
+
import path35 from "node:path";
|
|
8787
9444
|
import * as p37 from "@clack/prompts";
|
|
8788
9445
|
function siteFields(site) {
|
|
8789
9446
|
const url = site?.url && !isLocalUrl(site.url) ? site.url : void 0;
|
|
@@ -9065,16 +9722,16 @@ function writeLegalPage(root, dir, page) {
|
|
|
9065
9722
|
|
|
9066
9723
|
${html}`;
|
|
9067
9724
|
}
|
|
9068
|
-
const pagePath =
|
|
9069
|
-
|
|
9070
|
-
|
|
9725
|
+
const pagePath = path35.join(root, dir, "+page.svelte");
|
|
9726
|
+
fs37.mkdirSync(path35.dirname(pagePath), { recursive: true });
|
|
9727
|
+
fs37.writeFileSync(pagePath, html);
|
|
9071
9728
|
const written = [pagePath];
|
|
9072
9729
|
if (metaTags) {
|
|
9073
|
-
const loaderPath =
|
|
9074
|
-
|
|
9730
|
+
const loaderPath = path35.join(root, dir, "+page.ts");
|
|
9731
|
+
fs37.writeFileSync(loaderPath, pageMetaTagsLoader(page.title, page.description));
|
|
9075
9732
|
written.push(loaderPath);
|
|
9076
9733
|
}
|
|
9077
|
-
return written.map((file) =>
|
|
9734
|
+
return written.map((file) => path35.relative(root, file));
|
|
9078
9735
|
}
|
|
9079
9736
|
|
|
9080
9737
|
// src/commands/legal/terms.ts
|
|
@@ -9471,7 +10128,7 @@ async function termsAction() {
|
|
|
9471
10128
|
});
|
|
9472
10129
|
const [relativeTermsPage, ...rest] = writeLegalPage(
|
|
9473
10130
|
workspaceRootDir,
|
|
9474
|
-
|
|
10131
|
+
path36.join(publicRoutesDir, LEGAL_DIR, "terms"),
|
|
9475
10132
|
{
|
|
9476
10133
|
html,
|
|
9477
10134
|
title: "Terms of Service",
|
|
@@ -9491,7 +10148,7 @@ async function termsAction() {
|
|
|
9491
10148
|
var terms = new Command56("terms").description("generate placeholder terms and conditions").configureHelp(helpConfig).action(() => runCommand(termsAction, "Failed to generate terms and conditions."));
|
|
9492
10149
|
|
|
9493
10150
|
// src/commands/legal/privacy.ts
|
|
9494
|
-
import
|
|
10151
|
+
import path37 from "node:path";
|
|
9495
10152
|
import { Command as Command57 } from "commander";
|
|
9496
10153
|
import * as p39 from "@clack/prompts";
|
|
9497
10154
|
var mapLabels = {
|
|
@@ -10207,7 +10864,7 @@ async function privacyAction() {
|
|
|
10207
10864
|
});
|
|
10208
10865
|
const [relativePrivacyPage, ...rest] = writeLegalPage(
|
|
10209
10866
|
workspaceRootDir,
|
|
10210
|
-
|
|
10867
|
+
path37.join(publicRoutesDir, LEGAL_DIR, "privacy"),
|
|
10211
10868
|
{
|
|
10212
10869
|
html,
|
|
10213
10870
|
title: "Privacy Policy",
|
|
@@ -10236,8 +10893,8 @@ import { Command as Command64 } from "commander";
|
|
|
10236
10893
|
import { Command as Command59 } from "commander";
|
|
10237
10894
|
|
|
10238
10895
|
// src/lib/data.ts
|
|
10239
|
-
import
|
|
10240
|
-
import
|
|
10896
|
+
import fs38 from "node:fs";
|
|
10897
|
+
import path38 from "node:path";
|
|
10241
10898
|
import { ClientResponseError } from "pocketbase";
|
|
10242
10899
|
|
|
10243
10900
|
// src/lib/collections.ts
|
|
@@ -10274,14 +10931,14 @@ function dependencyOrder(collections2, startingCollectionId) {
|
|
|
10274
10931
|
|
|
10275
10932
|
// src/lib/data.ts
|
|
10276
10933
|
function dataDir(cwd, kind) {
|
|
10277
|
-
return
|
|
10934
|
+
return path38.join(cwd, DATA_DIR, kind);
|
|
10278
10935
|
}
|
|
10279
10936
|
function getDataFiles(cwd, kind) {
|
|
10280
10937
|
const dir = dataDir(cwd, kind);
|
|
10281
|
-
if (!
|
|
10282
|
-
return
|
|
10938
|
+
if (!fs38.existsSync(dir)) return [];
|
|
10939
|
+
return fs38.readdirSync(dir).filter((file) => file.endsWith(".json")).sort((a, b) => a.localeCompare(b)).map((file) => ({
|
|
10283
10940
|
collectionName: file.replace(/\.json$/i, "").replace(/^\d+[-_]?/, ""),
|
|
10284
|
-
filePath:
|
|
10941
|
+
filePath: path38.join(dir, file)
|
|
10285
10942
|
}));
|
|
10286
10943
|
}
|
|
10287
10944
|
function getSeedFiles(cwd) {
|
|
@@ -10291,7 +10948,7 @@ function getFixtureFiles(cwd) {
|
|
|
10291
10948
|
return getDataFiles(cwd, "fixtures");
|
|
10292
10949
|
}
|
|
10293
10950
|
function readRecords(filePath) {
|
|
10294
|
-
return JSON.parse(
|
|
10951
|
+
return JSON.parse(fs38.readFileSync(filePath, "utf8"));
|
|
10295
10952
|
}
|
|
10296
10953
|
function readSeedIds(cwd) {
|
|
10297
10954
|
const ids = /* @__PURE__ */ new Map();
|
|
@@ -10328,7 +10985,7 @@ function describeError(e) {
|
|
|
10328
10985
|
return e instanceof Error ? e.message : String(e);
|
|
10329
10986
|
}
|
|
10330
10987
|
function label3(cwd, filePath, count) {
|
|
10331
|
-
return `${
|
|
10988
|
+
return `${path38.relative(cwd, filePath)} (${count} records)`;
|
|
10332
10989
|
}
|
|
10333
10990
|
async function createRecords(pb, kind, cwd, { collectionName, filePath }) {
|
|
10334
10991
|
const records = readRecords(filePath);
|
|
@@ -10336,7 +10993,7 @@ async function createRecords(pb, kind, cwd, { collectionName, filePath }) {
|
|
|
10336
10993
|
try {
|
|
10337
10994
|
await pb.collection(collectionName).create(record);
|
|
10338
10995
|
} catch (e) {
|
|
10339
|
-
throw new DataLoadError(kind,
|
|
10996
|
+
throw new DataLoadError(kind, path38.relative(cwd, filePath), index, e);
|
|
10340
10997
|
}
|
|
10341
10998
|
}
|
|
10342
10999
|
return records.length;
|
|
@@ -10510,8 +11167,8 @@ var reset = new Command61("reset").description("clear and reload fixtures").conf
|
|
|
10510
11167
|
);
|
|
10511
11168
|
|
|
10512
11169
|
// src/commands/fixtures/generate.ts
|
|
10513
|
-
import
|
|
10514
|
-
import
|
|
11170
|
+
import fs39 from "node:fs";
|
|
11171
|
+
import path39 from "node:path";
|
|
10515
11172
|
import { Command as Command62, InvalidArgumentError } from "commander";
|
|
10516
11173
|
import * as p40 from "@clack/prompts";
|
|
10517
11174
|
import { annotate } from "annotate-json-schema";
|
|
@@ -10548,9 +11205,9 @@ async function loadCollections(pb) {
|
|
|
10548
11205
|
}
|
|
10549
11206
|
async function generateFixtureFiles(pb, workspaceRootDir, opts) {
|
|
10550
11207
|
const fixturesDir = dataDir(workspaceRootDir, "fixtures");
|
|
10551
|
-
|
|
10552
|
-
for (const file of
|
|
10553
|
-
if (file.endsWith(".json"))
|
|
11208
|
+
fs39.mkdirSync(fixturesDir, { recursive: true });
|
|
11209
|
+
for (const file of fs39.readdirSync(fixturesDir)) {
|
|
11210
|
+
if (file.endsWith(".json")) fs39.unlinkSync(path39.join(fixturesDir, file));
|
|
10554
11211
|
}
|
|
10555
11212
|
if (opts.seed !== void 0) faker.seed(opts.seed);
|
|
10556
11213
|
const generator = createGenerator({
|
|
@@ -10617,8 +11274,8 @@ async function generateFixtureFiles(pb, workspaceRootDir, opts) {
|
|
|
10617
11274
|
items.push(record);
|
|
10618
11275
|
}
|
|
10619
11276
|
const filename = `${padZeros(fileIndex, 2)}-${collection.name}.json`;
|
|
10620
|
-
|
|
10621
|
-
writtenFiles.push(`${
|
|
11277
|
+
fs39.writeFileSync(path39.join(fixturesDir, filename), JSON.stringify(items, null, 2));
|
|
11278
|
+
writtenFiles.push(`${path39.join(DATA_DIR, "fixtures", filename)} (${items.length} records)`);
|
|
10622
11279
|
fileIndex++;
|
|
10623
11280
|
}
|
|
10624
11281
|
return { writtenFiles, warnings };
|
|
@@ -10765,8 +11422,8 @@ var load2 = new Command65("load").description("load seeds into the database").op
|
|
|
10765
11422
|
);
|
|
10766
11423
|
|
|
10767
11424
|
// src/commands/seeds/save.ts
|
|
10768
|
-
import
|
|
10769
|
-
import
|
|
11425
|
+
import fs40 from "node:fs";
|
|
11426
|
+
import path40 from "node:path";
|
|
10770
11427
|
import { Command as Command66 } from "commander";
|
|
10771
11428
|
var padZeros2 = (num, length) => num.toString().padStart(length, "0");
|
|
10772
11429
|
function filterSystemFields(record, systemFieldNames) {
|
|
@@ -10786,10 +11443,10 @@ var save = new Command66("save").description("save the current data as seeds").o
|
|
|
10786
11443
|
if (existing.length > 0 && !opts.force) {
|
|
10787
11444
|
throw new Error("Existing seed files found in data/seeds. Pass --force to overwrite.");
|
|
10788
11445
|
}
|
|
10789
|
-
|
|
11446
|
+
fs40.mkdirSync(seedsPath, { recursive: true });
|
|
10790
11447
|
if (opts.force) {
|
|
10791
|
-
for (const file of
|
|
10792
|
-
if (file.endsWith(".json"))
|
|
11448
|
+
for (const file of fs40.readdirSync(seedsPath)) {
|
|
11449
|
+
if (file.endsWith(".json")) fs40.unlinkSync(path40.join(seedsPath, file));
|
|
10793
11450
|
}
|
|
10794
11451
|
}
|
|
10795
11452
|
const saved = [];
|
|
@@ -10818,13 +11475,13 @@ var save = new Command66("save").description("save the current data as seeds").o
|
|
|
10818
11475
|
const filtered = records.map(
|
|
10819
11476
|
(r) => filterSystemFields(r, systemFieldNames)
|
|
10820
11477
|
);
|
|
10821
|
-
const relativeSeedPath =
|
|
11478
|
+
const relativeSeedPath = path40.join(
|
|
10822
11479
|
DATA_DIR,
|
|
10823
11480
|
"seeds",
|
|
10824
11481
|
`${padZeros2(count, 2)}-${collectionName}.json`
|
|
10825
11482
|
);
|
|
10826
|
-
const seedPath =
|
|
10827
|
-
|
|
11483
|
+
const seedPath = path40.join(workspaceRootDir, relativeSeedPath);
|
|
11484
|
+
fs40.writeFileSync(seedPath, JSON.stringify(filtered, null, 2));
|
|
10828
11485
|
saved.push(`${relativeSeedPath} (${filtered.length} records)`);
|
|
10829
11486
|
count++;
|
|
10830
11487
|
}
|
|
@@ -10962,7 +11619,7 @@ import { Command as Command78 } from "commander";
|
|
|
10962
11619
|
import { Command as Command72 } from "commander";
|
|
10963
11620
|
|
|
10964
11621
|
// src/lib/migrate.ts
|
|
10965
|
-
import
|
|
11622
|
+
import path41 from "node:path";
|
|
10966
11623
|
import process27 from "node:process";
|
|
10967
11624
|
import { x as x3 } from "tinyexec";
|
|
10968
11625
|
function migrateRoot() {
|
|
@@ -10976,9 +11633,9 @@ async function runPocketbaseMigrate(args) {
|
|
|
10976
11633
|
binaryPath,
|
|
10977
11634
|
[
|
|
10978
11635
|
"--dir",
|
|
10979
|
-
|
|
11636
|
+
path41.join(cwd, DATA_DIR),
|
|
10980
11637
|
"--migrationsDir",
|
|
10981
|
-
|
|
11638
|
+
path41.join(cwd, MIGRATIONS_DIR),
|
|
10982
11639
|
"migrate",
|
|
10983
11640
|
...args
|
|
10984
11641
|
],
|
|
@@ -11026,8 +11683,8 @@ var down = new Command73("down").alias("rollback").description("revert the last
|
|
|
11026
11683
|
);
|
|
11027
11684
|
|
|
11028
11685
|
// src/commands/migrate/create.ts
|
|
11029
|
-
import
|
|
11030
|
-
import
|
|
11686
|
+
import fs41 from "node:fs";
|
|
11687
|
+
import path42 from "node:path";
|
|
11031
11688
|
import { Command as Command74 } from "commander";
|
|
11032
11689
|
var create2 = new Command74("create").alias("new").description("create a new blank migration").argument("<name>", "migration name (snake_case)").configureHelp(helpConfig).action(
|
|
11033
11690
|
(name) => runCommand(async () => {
|
|
@@ -11038,7 +11695,7 @@ var create2 = new Command74("create").alias("new").description("create a new bla
|
|
|
11038
11695
|
const added = [...after].filter((f) => !before.has(f));
|
|
11039
11696
|
reportResult({
|
|
11040
11697
|
summary: `Created blank migration ${name}.`,
|
|
11041
|
-
filesCreated: added.map((f) =>
|
|
11698
|
+
filesCreated: added.map((f) => path42.join(MIGRATIONS_DIR, f)),
|
|
11042
11699
|
nextSteps: [
|
|
11043
11700
|
`Open the new file in ${MIGRATIONS_DIR}/ and fill in the up/down handlers.`,
|
|
11044
11701
|
"Run `vela migrate up` to apply the migration once the handlers are written."
|
|
@@ -11047,14 +11704,14 @@ var create2 = new Command74("create").alias("new").description("create a new bla
|
|
|
11047
11704
|
}, "Failed to create migration.")
|
|
11048
11705
|
);
|
|
11049
11706
|
function listMigrationFiles(cwd) {
|
|
11050
|
-
const dir =
|
|
11051
|
-
if (!
|
|
11052
|
-
return new Set(
|
|
11707
|
+
const dir = path42.join(cwd, MIGRATIONS_DIR);
|
|
11708
|
+
if (!fs41.existsSync(dir)) return /* @__PURE__ */ new Set();
|
|
11709
|
+
return new Set(fs41.readdirSync(dir).filter((f) => /\.[jt]s$/.test(f)));
|
|
11053
11710
|
}
|
|
11054
11711
|
|
|
11055
11712
|
// src/commands/migrate/collections.ts
|
|
11056
|
-
import
|
|
11057
|
-
import
|
|
11713
|
+
import fs42 from "node:fs";
|
|
11714
|
+
import path43 from "node:path";
|
|
11058
11715
|
import { Command as Command75 } from "commander";
|
|
11059
11716
|
var collections = new Command75("collections").alias("snapshot").description("snapshot local collections into a new migration").configureHelp(helpConfig).action(
|
|
11060
11717
|
() => runCommand(async () => {
|
|
@@ -11071,7 +11728,7 @@ var collections = new Command75("collections").alias("snapshot").description("sn
|
|
|
11071
11728
|
}
|
|
11072
11729
|
reportResult({
|
|
11073
11730
|
summary: "Snapshotted local collections into a new migration.",
|
|
11074
|
-
filesCreated: added.map((f) =>
|
|
11731
|
+
filesCreated: added.map((f) => path43.join(MIGRATIONS_DIR, f)),
|
|
11075
11732
|
nextSteps: [
|
|
11076
11733
|
`Review the generated snapshot in ${MIGRATIONS_DIR}/.`,
|
|
11077
11734
|
"Commit the snapshot so teammates pick up the new schema.",
|
|
@@ -11081,9 +11738,9 @@ var collections = new Command75("collections").alias("snapshot").description("sn
|
|
|
11081
11738
|
}, "Failed to snapshot collections.")
|
|
11082
11739
|
);
|
|
11083
11740
|
function listMigrationFiles2(cwd) {
|
|
11084
|
-
const dir =
|
|
11085
|
-
if (!
|
|
11086
|
-
return new Set(
|
|
11741
|
+
const dir = path43.join(cwd, MIGRATIONS_DIR);
|
|
11742
|
+
if (!fs42.existsSync(dir)) return /* @__PURE__ */ new Set();
|
|
11743
|
+
return new Set(fs42.readdirSync(dir).filter((f) => /\.[jt]s$/.test(f)));
|
|
11087
11744
|
}
|
|
11088
11745
|
|
|
11089
11746
|
// src/commands/migrate/history-sync.ts
|
|
@@ -11099,14 +11756,14 @@ var historySync = new Command76("history-sync").description("drop _migrations ro
|
|
|
11099
11756
|
);
|
|
11100
11757
|
|
|
11101
11758
|
// src/commands/migrate/sveltekit-3.ts
|
|
11102
|
-
import
|
|
11759
|
+
import path44 from "node:path";
|
|
11103
11760
|
import process28 from "node:process";
|
|
11104
11761
|
import { Command as Command77 } from "commander";
|
|
11105
11762
|
import * as p45 from "@clack/prompts";
|
|
11106
11763
|
import pc15 from "picocolors";
|
|
11107
11764
|
var sveltekit3 = new Command77("sveltekit-3").description("upgrade a SvelteKit 2 project to SvelteKit 3 (sv migrate, then the vela steps)").option("--cwd <path>", "the project to migrate (default: the current project)").option("--no-install", "skip installing dependencies").option("--force", "run even when the git working tree has uncommitted changes").option("--skip-sv", "only run the vela steps (sv has already been run)").configureHelp(helpConfig).action(
|
|
11108
11765
|
(options) => runCommand(async () => {
|
|
11109
|
-
const root = options.cwd ?
|
|
11766
|
+
const root = options.cwd ? path44.resolve(options.cwd) : findWorkspaceRoot() ?? process28.cwd();
|
|
11110
11767
|
p45.intro(pc15.bgCyan(pc15.black(" vela migrate sveltekit-3 ")));
|
|
11111
11768
|
const result = await runKit3Migration(root, {
|
|
11112
11769
|
install: options.install,
|
|
@@ -11123,7 +11780,7 @@ function printReport(root, result) {
|
|
|
11123
11780
|
sections.push({ label: "Build output removed first", items: result.sv.cleared });
|
|
11124
11781
|
}
|
|
11125
11782
|
for (const fixup2 of changed) sections.push({ label: fixup2.name, items: fixup2.details });
|
|
11126
|
-
const summary = result.mode === "repair" ? changed.length > 0 ? "Already on SvelteKit 3; brought the vela setup up to date." : "Already on SvelteKit 3; nothing left to change." : `Migrated ${
|
|
11783
|
+
const summary = result.mode === "repair" ? changed.length > 0 ? "Already on SvelteKit 3; brought the vela setup up to date." : "Already on SvelteKit 3; nothing left to change." : `Migrated ${path44.basename(root)} to SvelteKit 3.`;
|
|
11127
11784
|
reportResult({ summary, sections });
|
|
11128
11785
|
const tasks = result.tasks;
|
|
11129
11786
|
if (tasks && (tasks.sections.length > 0 || tasks.markerComments > 0)) {
|
|
@@ -11141,16 +11798,31 @@ function printReport(root, result) {
|
|
|
11141
11798
|
format: (line) => line
|
|
11142
11799
|
});
|
|
11143
11800
|
}
|
|
11144
|
-
|
|
11801
|
+
p45.note(
|
|
11802
|
+
nextStepsFor(result).map((s) => `- ${s}`).join("\n"),
|
|
11803
|
+
"Next steps",
|
|
11804
|
+
{
|
|
11805
|
+
format: (line) => line
|
|
11806
|
+
}
|
|
11807
|
+
);
|
|
11808
|
+
}
|
|
11809
|
+
function nextStepsFor(result) {
|
|
11810
|
+
const tasks = result.tasks;
|
|
11811
|
+
const open = [];
|
|
11145
11812
|
if (tasks && (tasks.sections.length > 0 || result.followUps.length > 0)) {
|
|
11146
|
-
|
|
11813
|
+
open.push(`Work through ${MIGRATION_TASKS_FILE}, then delete it.`);
|
|
11147
11814
|
}
|
|
11148
11815
|
if (tasks?.markerComments) {
|
|
11149
|
-
|
|
11816
|
+
open.push("Search the code for `@migration-task` and resolve each comment.");
|
|
11150
11817
|
}
|
|
11818
|
+
const changed = result.fixups.some((f) => f.changed);
|
|
11819
|
+
if (!result.sv.ran && !changed) {
|
|
11820
|
+
return ["Nothing left to change.", ...open];
|
|
11821
|
+
}
|
|
11822
|
+
const nextSteps = [...open];
|
|
11151
11823
|
if (result.installed === null) {
|
|
11152
11824
|
nextSteps.push(
|
|
11153
|
-
"Install dependencies (`npm install`), then format what changed (`npx prettier --write .`): sv could not format without node_modules."
|
|
11825
|
+
result.sv.ran ? "Install dependencies (`npm install`), then format what changed (`npx prettier --write .`): sv could not format without node_modules." : "Install dependencies (`npm install`), then format what changed (`npx prettier --write .`)."
|
|
11154
11826
|
);
|
|
11155
11827
|
}
|
|
11156
11828
|
if (result.installed === false) {
|
|
@@ -11159,21 +11831,35 @@ function printReport(root, result) {
|
|
|
11159
11831
|
nextSteps.push("Run `npm run check`, `vela test:server` and `npm run build`.");
|
|
11160
11832
|
nextSteps.push(...result.genericFollowUps);
|
|
11161
11833
|
nextSteps.push("Review the diff and commit it.");
|
|
11162
|
-
|
|
11834
|
+
return nextSteps;
|
|
11163
11835
|
}
|
|
11164
11836
|
|
|
11165
11837
|
// src/commands/migrate.ts
|
|
11166
11838
|
var migrate = new Command78("migrate").description("manage database migrations (and `migrate sveltekit-3` to upgrade SvelteKit)").configureHelp(helpConfig).action(() => runCommand(runMigrateUp, "Failed to run migrations.")).addCommand(up).addCommand(down).addCommand(create2).addCommand(collections).addCommand(historySync).addCommand(sveltekit3);
|
|
11167
11839
|
|
|
11168
11840
|
// src/commands/dev.ts
|
|
11169
|
-
import
|
|
11170
|
-
import
|
|
11171
|
-
import
|
|
11841
|
+
import fs43 from "node:fs";
|
|
11842
|
+
import path46 from "node:path";
|
|
11843
|
+
import process31 from "node:process";
|
|
11172
11844
|
import { performance } from "node:perf_hooks";
|
|
11173
11845
|
import { Command as Command79, InvalidArgumentError as InvalidArgumentError4 } from "commander";
|
|
11174
11846
|
import pc17 from "picocolors";
|
|
11175
11847
|
import PocketBase4 from "pocketbase";
|
|
11176
11848
|
|
|
11849
|
+
// src/lib/terminate.ts
|
|
11850
|
+
import process29 from "node:process";
|
|
11851
|
+
var TERMINATING_SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
11852
|
+
var EXIT_CODES = { SIGINT: 0, SIGTERM: 143, SIGHUP: 129 };
|
|
11853
|
+
function onTerminate(cleanup, proc = process29) {
|
|
11854
|
+
proc.on("exit", cleanup);
|
|
11855
|
+
for (const signal of TERMINATING_SIGNALS) {
|
|
11856
|
+
proc.on(signal, () => {
|
|
11857
|
+
cleanup();
|
|
11858
|
+
proc.exit(EXIT_CODES[signal]);
|
|
11859
|
+
});
|
|
11860
|
+
}
|
|
11861
|
+
}
|
|
11862
|
+
|
|
11177
11863
|
// src/lib/pocketbase-log-filter.ts
|
|
11178
11864
|
import { Transform } from "node:stream";
|
|
11179
11865
|
var ANSI2 = /\x1b\[[0-9;]*m/g;
|
|
@@ -11199,8 +11885,8 @@ function createPocketbaseLogFilter() {
|
|
|
11199
11885
|
}
|
|
11200
11886
|
|
|
11201
11887
|
// src/lib/vite.ts
|
|
11202
|
-
import
|
|
11203
|
-
import
|
|
11888
|
+
import path45 from "node:path";
|
|
11889
|
+
import process30 from "node:process";
|
|
11204
11890
|
import { createRequire as createRequire3 } from "node:module";
|
|
11205
11891
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
11206
11892
|
import pc16 from "picocolors";
|
|
@@ -11219,18 +11905,18 @@ function viteVersionError(version) {
|
|
|
11219
11905
|
}
|
|
11220
11906
|
function resolveProjectVite(cwd) {
|
|
11221
11907
|
try {
|
|
11222
|
-
return createRequire3(
|
|
11908
|
+
return createRequire3(path45.join(cwd, "package.json")).resolve("vite");
|
|
11223
11909
|
} catch {
|
|
11224
11910
|
return null;
|
|
11225
11911
|
}
|
|
11226
11912
|
}
|
|
11227
|
-
async function loadVite(cwd =
|
|
11913
|
+
async function loadVite(cwd = process30.cwd()) {
|
|
11228
11914
|
const entry = resolveProjectVite(cwd);
|
|
11229
11915
|
const vite = entry ? await import(pathToFileURL2(entry).href) : await import("vite");
|
|
11230
11916
|
const error = viteVersionError(vite.version);
|
|
11231
11917
|
if (error) {
|
|
11232
11918
|
console.error(`${pc16.redBright("\u2717")} ${error}`);
|
|
11233
|
-
|
|
11919
|
+
process30.exit(1);
|
|
11234
11920
|
}
|
|
11235
11921
|
return vite;
|
|
11236
11922
|
}
|
|
@@ -11244,41 +11930,37 @@ function parsePort(value) {
|
|
|
11244
11930
|
return port;
|
|
11245
11931
|
}
|
|
11246
11932
|
var dev = new Command79("dev").description("start the development server").option("--open [path]", "open the app in a browser once the server is ready").option("--host [host]", "expose the server on the network").option("--port <port>", "port to listen on", parsePort).option("--strictPort", "exit if the port is already in use instead of taking the next one").option("--cors", "enable CORS").option("--force", "re-bundle dependencies, ignoring the optimizer cache").option("--all-sql", "also print the auth lookup PocketBase runs on every request").configureHelp(helpConfig).action(async (options) => {
|
|
11247
|
-
const cwd =
|
|
11933
|
+
const cwd = process31.cwd();
|
|
11248
11934
|
warnIfKit2(findWorkspaceRoot(cwd) ?? cwd, (m) => console.warn(pc17.yellow(`\u25B2 ${m}`)));
|
|
11249
|
-
|
|
11935
|
+
process31.env.VELA_DATA_DIR ??= localDataDir(cwd);
|
|
11250
11936
|
const startTime = performance.now();
|
|
11251
11937
|
const { createServer, version } = await loadVite(cwd);
|
|
11252
|
-
const viteMetadataDir =
|
|
11253
|
-
const viteMetadataFile =
|
|
11938
|
+
const viteMetadataDir = path46.join(cwd, "node_modules", ".vite");
|
|
11939
|
+
const viteMetadataFile = path46.join(viteMetadataDir, "_pocketbase_metadata.json");
|
|
11254
11940
|
let pbProc;
|
|
11255
11941
|
const backend3 = hasBackend(cwd);
|
|
11256
|
-
const needsStart = backend3 && !
|
|
11942
|
+
const needsStart = backend3 && !process31.env.POCKETBASE_URL;
|
|
11257
11943
|
const cleanup = () => {
|
|
11258
11944
|
if (pbProc?.pid) pbProc.kill();
|
|
11259
|
-
if (
|
|
11945
|
+
if (fs43.existsSync(viteMetadataFile)) fs43.rmSync(viteMetadataFile);
|
|
11260
11946
|
};
|
|
11261
11947
|
if (needsStart) {
|
|
11262
|
-
const dataDir2 =
|
|
11948
|
+
const dataDir2 = path46.join(cwd, DATA_DIR);
|
|
11263
11949
|
const started = await startPocketbaseServe({
|
|
11264
11950
|
dataDir: dataDir2,
|
|
11265
11951
|
migrationsDir: MIGRATIONS_DIR,
|
|
11266
|
-
hooksDir:
|
|
11952
|
+
hooksDir: path46.join(dataDir2, "hooks"),
|
|
11267
11953
|
dev: true,
|
|
11268
11954
|
stdio: "pipe"
|
|
11269
11955
|
});
|
|
11270
11956
|
pbProc = started.proc;
|
|
11271
|
-
|
|
11272
|
-
if (options.allSql) pbProc.stdout?.pipe(
|
|
11273
|
-
else pbProc.stdout?.pipe(createPocketbaseLogFilter()).pipe(
|
|
11274
|
-
pbProc.stderr?.pipe(
|
|
11957
|
+
process31.env.POCKETBASE_URL = started.url;
|
|
11958
|
+
if (options.allSql) pbProc.stdout?.pipe(process31.stdout);
|
|
11959
|
+
else pbProc.stdout?.pipe(createPocketbaseLogFilter()).pipe(process31.stdout);
|
|
11960
|
+
pbProc.stderr?.pipe(process31.stderr);
|
|
11275
11961
|
pbProc.on("error", (err) => console.error("PocketBase error:", err));
|
|
11276
11962
|
pbProc.on("exit", (code2) => console.log(`PocketBase exited with code ${code2}`));
|
|
11277
|
-
|
|
11278
|
-
process30.on("SIGINT", () => {
|
|
11279
|
-
cleanup();
|
|
11280
|
-
process30.exit(0);
|
|
11281
|
-
});
|
|
11963
|
+
onTerminate(cleanup);
|
|
11282
11964
|
}
|
|
11283
11965
|
const serverOptions = {};
|
|
11284
11966
|
if (options.open !== void 0) serverOptions.open = options.open;
|
|
@@ -11295,19 +11977,19 @@ var dev = new Command79("dev").description("start the development server").optio
|
|
|
11295
11977
|
if (!backend3) return;
|
|
11296
11978
|
const { address, port: vitePort } = server.httpServer.address();
|
|
11297
11979
|
const viteHost = address === "::1" ? "localhost" : address;
|
|
11298
|
-
await
|
|
11299
|
-
await
|
|
11980
|
+
await fs43.promises.mkdir(viteMetadataDir, { recursive: true });
|
|
11981
|
+
await fs43.promises.writeFile(
|
|
11300
11982
|
viteMetadataFile,
|
|
11301
11983
|
JSON.stringify({
|
|
11302
|
-
pocketbaseUrl:
|
|
11984
|
+
pocketbaseUrl: process31.env.POCKETBASE_URL,
|
|
11303
11985
|
vitePort,
|
|
11304
11986
|
viteHost
|
|
11305
11987
|
})
|
|
11306
11988
|
);
|
|
11307
|
-
const pb = new PocketBase4(
|
|
11989
|
+
const pb = new PocketBase4(process31.env.POCKETBASE_URL);
|
|
11308
11990
|
await pb.collection("_superusers").authWithPassword(
|
|
11309
|
-
|
|
11310
|
-
|
|
11991
|
+
process31.env.POCKETBASE_SUPERUSER_EMAIL,
|
|
11992
|
+
process31.env.POCKETBASE_SUPERUSER_PASSWORD
|
|
11311
11993
|
);
|
|
11312
11994
|
const site = await readSite(cwd);
|
|
11313
11995
|
await pb.settings.update({
|
|
@@ -11326,7 +12008,7 @@ var dev = new Command79("dev").description("start the development server").optio
|
|
|
11326
12008
|
await startWatchingTypes(cwd, pb);
|
|
11327
12009
|
});
|
|
11328
12010
|
await server.listen();
|
|
11329
|
-
const hasExistingLogs =
|
|
12011
|
+
const hasExistingLogs = process31.stdout.bytesWritten > 0 || process31.stderr.bytesWritten > 0;
|
|
11330
12012
|
const startupDurationString = pc17.dim(
|
|
11331
12013
|
`ready in ${pc17.reset(pc17.bold(Math.ceil(performance.now() - startTime)))} ms`
|
|
11332
12014
|
);
|
|
@@ -11341,18 +12023,18 @@ var dev = new Command79("dev").description("start the development server").optio
|
|
|
11341
12023
|
});
|
|
11342
12024
|
async function startWatchingTypes(cwd, pb) {
|
|
11343
12025
|
const { processTypes } = await import("@velastack/pocketbase-codegen");
|
|
11344
|
-
const typesDir =
|
|
11345
|
-
const pocketbaseDir =
|
|
11346
|
-
const pocketbaseTypes =
|
|
12026
|
+
const typesDir = path46.resolve(cwd, ".svelte-kit", "types");
|
|
12027
|
+
const pocketbaseDir = path46.join(typesDir, "pocketbase");
|
|
12028
|
+
const pocketbaseTypes = path46.join(pocketbaseDir, "$types.d.ts");
|
|
11347
12029
|
const regenerate = () => processTypes(pb, typesDir).catch(() => {
|
|
11348
12030
|
});
|
|
11349
12031
|
await regenerate();
|
|
11350
12032
|
void (async () => {
|
|
11351
12033
|
for (; ; ) {
|
|
11352
12034
|
try {
|
|
11353
|
-
await
|
|
11354
|
-
for await (const event of
|
|
11355
|
-
if (event.eventType === "rename" && event.filename === "$types.d.ts" && !
|
|
12035
|
+
await fs43.promises.mkdir(pocketbaseDir, { recursive: true });
|
|
12036
|
+
for await (const event of fs43.promises.watch(pocketbaseDir)) {
|
|
12037
|
+
if (event.eventType === "rename" && event.filename === "$types.d.ts" && !fs43.existsSync(pocketbaseTypes)) {
|
|
11356
12038
|
setTimeout(regenerate, 100);
|
|
11357
12039
|
}
|
|
11358
12040
|
}
|
|
@@ -11364,9 +12046,9 @@ async function startWatchingTypes(cwd, pb) {
|
|
|
11364
12046
|
}
|
|
11365
12047
|
|
|
11366
12048
|
// src/commands/build.ts
|
|
11367
|
-
import
|
|
11368
|
-
import
|
|
11369
|
-
import
|
|
12049
|
+
import fs44 from "node:fs";
|
|
12050
|
+
import path47 from "node:path";
|
|
12051
|
+
import process33 from "node:process";
|
|
11370
12052
|
import { Command as Command80 } from "commander";
|
|
11371
12053
|
import * as p46 from "@clack/prompts";
|
|
11372
12054
|
import pc18 from "picocolors";
|
|
@@ -11381,10 +12063,10 @@ function applyBuildEnv(cwd, env2 = process.env) {
|
|
|
11381
12063
|
}
|
|
11382
12064
|
|
|
11383
12065
|
// src/lib/origin.ts
|
|
11384
|
-
import
|
|
12066
|
+
import process32 from "node:process";
|
|
11385
12067
|
function resolveOrigin(workspaceRootDir, envTag, config = {}) {
|
|
11386
12068
|
const domain = readBinding(workspaceRootDir, envTag)?.domain ?? config.deploy?.domain;
|
|
11387
|
-
return buildOrigin(splitHosts(domain), domain,
|
|
12069
|
+
return buildOrigin(splitHosts(domain), domain, process32.env.VELA_ORIGIN);
|
|
11388
12070
|
}
|
|
11389
12071
|
function buildOrigin(directHosts, primaryUrl, envOverride) {
|
|
11390
12072
|
if (envOverride !== void 0) return normalizeOrigin(envOverride);
|
|
@@ -11407,34 +12089,30 @@ function splitHosts(value) {
|
|
|
11407
12089
|
}
|
|
11408
12090
|
|
|
11409
12091
|
// src/commands/build.ts
|
|
11410
|
-
var PRERENDERED_DIR =
|
|
12092
|
+
var PRERENDERED_DIR = path47.join(".svelte-kit", "output", "prerendered");
|
|
11411
12093
|
var build = new Command80("build").description("build the app").configureHelp(helpConfig).option("-t, --target <target>", "which copy of the app to build for", PRODUCTION_TARGET).action(async (options) => {
|
|
11412
|
-
const cwd =
|
|
12094
|
+
const cwd = process33.cwd();
|
|
11413
12095
|
warnIfKit2(findWorkspaceRoot(cwd) ?? cwd, (m) => p46.log.warn(m));
|
|
11414
12096
|
applyBuildEnv(cwd);
|
|
11415
12097
|
const origin = await originForBuild(cwd, options.target);
|
|
11416
|
-
if (origin)
|
|
12098
|
+
if (origin) process33.env.VELA_ORIGIN = origin;
|
|
11417
12099
|
let pbProc;
|
|
11418
|
-
const needsStart = hasBackend(cwd) && !
|
|
12100
|
+
const needsStart = hasBackend(cwd) && !process33.env.POCKETBASE_URL;
|
|
11419
12101
|
const cleanup = () => {
|
|
11420
12102
|
if (pbProc?.pid) pbProc.kill();
|
|
11421
12103
|
};
|
|
11422
12104
|
if (needsStart) {
|
|
11423
12105
|
await ensureSuperuser(cwd);
|
|
11424
|
-
const dataDir2 =
|
|
12106
|
+
const dataDir2 = path47.join(cwd, DATA_DIR);
|
|
11425
12107
|
const started = await startPocketbaseServe({
|
|
11426
12108
|
dataDir: dataDir2,
|
|
11427
12109
|
migrationsDir: MIGRATIONS_DIR,
|
|
11428
|
-
hooksDir:
|
|
12110
|
+
hooksDir: path47.join(dataDir2, "hooks"),
|
|
11429
12111
|
dev: true
|
|
11430
12112
|
});
|
|
11431
12113
|
pbProc = started.proc;
|
|
11432
|
-
|
|
11433
|
-
|
|
11434
|
-
process32.on("SIGINT", () => {
|
|
11435
|
-
cleanup();
|
|
11436
|
-
process32.exit(0);
|
|
11437
|
-
});
|
|
12114
|
+
process33.env.POCKETBASE_URL = started.url;
|
|
12115
|
+
onTerminate(cleanup);
|
|
11438
12116
|
}
|
|
11439
12117
|
try {
|
|
11440
12118
|
const pm = (await detect7({ cwd }))?.name ?? "npm";
|
|
@@ -11464,9 +12142,9 @@ async function originForBuild(cwd, target) {
|
|
|
11464
12142
|
}
|
|
11465
12143
|
}
|
|
11466
12144
|
function warnIfPrerendered(cwd) {
|
|
11467
|
-
const dir =
|
|
11468
|
-
if (!
|
|
11469
|
-
if (
|
|
12145
|
+
const dir = path47.join(cwd, PRERENDERED_DIR);
|
|
12146
|
+
if (!fs44.existsSync(dir) || fs44.readdirSync(dir).length === 0) return;
|
|
12147
|
+
if (process33.env.VELA_ORIGIN === "") {
|
|
11470
12148
|
p46.log.warn(
|
|
11471
12149
|
`Prerendered pages were built with no origin, on purpose: this app is served on
|
|
11472
12150
|
several hosts (or on none yet), and baking one in would make the others render
|
|
@@ -11488,41 +12166,37 @@ Set one with ${pc18.cyan("vela deploy --domain example.com")}, or pass ${pc18.cy
|
|
|
11488
12166
|
}
|
|
11489
12167
|
|
|
11490
12168
|
// src/commands/preview.ts
|
|
11491
|
-
import
|
|
11492
|
-
import
|
|
11493
|
-
import
|
|
12169
|
+
import fs45 from "node:fs";
|
|
12170
|
+
import path48 from "node:path";
|
|
12171
|
+
import process34 from "node:process";
|
|
11494
12172
|
import { Command as Command81 } from "commander";
|
|
11495
12173
|
import * as p47 from "@clack/prompts";
|
|
11496
12174
|
import pc19 from "picocolors";
|
|
11497
12175
|
import { x as x5 } from "tinyexec";
|
|
11498
12176
|
import { detect as detect8 } from "package-manager-detector";
|
|
11499
12177
|
import { resolveCommand as resolveCommand6 } from "package-manager-detector/commands";
|
|
11500
|
-
var ADAPTER_NODE_MODULE =
|
|
12178
|
+
var ADAPTER_NODE_MODULE = path48.join("build", "adapter-node.js");
|
|
11501
12179
|
var preview = new Command81("preview").description("preview the built app").configureHelp(helpConfig).action(async () => {
|
|
11502
|
-
const cwd =
|
|
11503
|
-
|
|
12180
|
+
const cwd = process34.cwd();
|
|
12181
|
+
process34.env.VELA_DATA_DIR ??= localDataDir(cwd);
|
|
11504
12182
|
warnIfKit2(findWorkspaceRoot(cwd) ?? cwd, (m) => p47.log.warn(m));
|
|
11505
12183
|
warnIfOriginBaked(cwd);
|
|
11506
12184
|
let pbProc;
|
|
11507
|
-
const needsStart = hasBackend(cwd) && !
|
|
12185
|
+
const needsStart = hasBackend(cwd) && !process34.env.POCKETBASE_URL;
|
|
11508
12186
|
const cleanup = () => {
|
|
11509
12187
|
if (pbProc?.pid) pbProc.kill();
|
|
11510
12188
|
};
|
|
11511
12189
|
if (needsStart) {
|
|
11512
|
-
const dataDir2 =
|
|
12190
|
+
const dataDir2 = path48.join(cwd, DATA_DIR);
|
|
11513
12191
|
const started = await startPocketbaseServe({
|
|
11514
12192
|
dataDir: dataDir2,
|
|
11515
12193
|
migrationsDir: MIGRATIONS_DIR,
|
|
11516
|
-
hooksDir:
|
|
12194
|
+
hooksDir: path48.join(dataDir2, "hooks"),
|
|
11517
12195
|
dev: true
|
|
11518
12196
|
});
|
|
11519
12197
|
pbProc = started.proc;
|
|
11520
|
-
|
|
11521
|
-
|
|
11522
|
-
process33.on("SIGINT", () => {
|
|
11523
|
-
cleanup();
|
|
11524
|
-
process33.exit(0);
|
|
11525
|
-
});
|
|
12198
|
+
process34.env.POCKETBASE_URL = started.url;
|
|
12199
|
+
onTerminate(cleanup);
|
|
11526
12200
|
}
|
|
11527
12201
|
try {
|
|
11528
12202
|
const pm = (await detect8({ cwd }))?.name ?? "npm";
|
|
@@ -11550,7 +12224,7 @@ function bakedOrigin(source) {
|
|
|
11550
12224
|
function warnIfOriginBaked(cwd) {
|
|
11551
12225
|
let source;
|
|
11552
12226
|
try {
|
|
11553
|
-
source =
|
|
12227
|
+
source = fs45.readFileSync(path48.join(cwd, ADAPTER_NODE_MODULE), "utf8");
|
|
11554
12228
|
} catch {
|
|
11555
12229
|
return;
|
|
11556
12230
|
}
|
|
@@ -11566,12 +12240,12 @@ set empty so no domain is baked in.`
|
|
|
11566
12240
|
}
|
|
11567
12241
|
|
|
11568
12242
|
// src/commands/sync.ts
|
|
11569
|
-
import
|
|
12243
|
+
import path49 from "node:path";
|
|
11570
12244
|
import { Command as Command82 } from "commander";
|
|
11571
12245
|
var sync = new Command82("sync").description("sync types from the database").configureHelp(helpConfig).action(
|
|
11572
12246
|
() => runCommand(async () => {
|
|
11573
12247
|
const { workspaceRootDir } = await getWorkspace();
|
|
11574
|
-
const typesDir =
|
|
12248
|
+
const typesDir = path49.join(workspaceRootDir, ".svelte-kit", "types");
|
|
11575
12249
|
const { processTypes } = await import("@velastack/pocketbase-codegen");
|
|
11576
12250
|
await withPocketbase(workspaceRootDir, async (pb) => {
|
|
11577
12251
|
await processTypes(pb, typesDir);
|
|
@@ -11638,32 +12312,32 @@ var provision = addSshOptions(
|
|
|
11638
12312
|
);
|
|
11639
12313
|
|
|
11640
12314
|
// src/commands/deploy.ts
|
|
11641
|
-
import
|
|
11642
|
-
import
|
|
11643
|
-
import
|
|
12315
|
+
import path51 from "node:path";
|
|
12316
|
+
import fs47 from "node:fs";
|
|
12317
|
+
import process36 from "node:process";
|
|
11644
12318
|
import { Command as Command84, Option as Option2 } from "commander";
|
|
11645
12319
|
import * as p49 from "@clack/prompts";
|
|
11646
12320
|
import pc21 from "picocolors";
|
|
11647
12321
|
import * as v10 from "valibot";
|
|
11648
12322
|
|
|
11649
12323
|
// src/lib/pocketbase-settings.ts
|
|
11650
|
-
import
|
|
11651
|
-
import
|
|
11652
|
-
import
|
|
12324
|
+
import fs46 from "node:fs";
|
|
12325
|
+
import path50 from "node:path";
|
|
12326
|
+
import process35 from "node:process";
|
|
11653
12327
|
import PocketBase5 from "pocketbase";
|
|
11654
12328
|
var COPIED_KEYS = ["senderName", "senderAddress"];
|
|
11655
12329
|
async function readLocalMeta(cwd) {
|
|
11656
|
-
const dataDir2 =
|
|
11657
|
-
if (!
|
|
11658
|
-
const email2 =
|
|
11659
|
-
const password11 =
|
|
12330
|
+
const dataDir2 = path50.join(cwd, DATA_DIR);
|
|
12331
|
+
if (!fs46.existsSync(dataDir2)) return null;
|
|
12332
|
+
const email2 = process35.env.POCKETBASE_SUPERUSER_EMAIL;
|
|
12333
|
+
const password11 = process35.env.POCKETBASE_SUPERUSER_PASSWORD;
|
|
11660
12334
|
if (!email2 || !password11) return null;
|
|
11661
12335
|
let proc;
|
|
11662
12336
|
try {
|
|
11663
12337
|
const started = await startPocketbaseServe({
|
|
11664
12338
|
dataDir: dataDir2,
|
|
11665
12339
|
migrationsDir: MIGRATIONS_DIR,
|
|
11666
|
-
hooksDir:
|
|
12340
|
+
hooksDir: path50.join(dataDir2, "hooks")
|
|
11667
12341
|
});
|
|
11668
12342
|
proc = started.proc;
|
|
11669
12343
|
const pb = new PocketBase5(started.url);
|
|
@@ -11738,7 +12412,7 @@ var deploy = addLockWaitOption(
|
|
|
11738
12412
|
const options = parseOptions(OptionsSchema3, raw);
|
|
11739
12413
|
const backend3 = hasBackend();
|
|
11740
12414
|
p49.intro(pc21.bgCyan(pc21.black(" vela deploy ")));
|
|
11741
|
-
assertKit3(findWorkspaceRoot() ??
|
|
12415
|
+
assertKit3(findWorkspaceRoot() ?? process36.cwd(), "vela deploy");
|
|
11742
12416
|
if (options.build !== false) {
|
|
11743
12417
|
const { workspaceRootDir } = await getWorkspace();
|
|
11744
12418
|
await prepareAdapter(workspaceRootDir);
|
|
@@ -11802,7 +12476,7 @@ with DNS of your own pointing at ${ctx.server}.`
|
|
|
11802
12476
|
);
|
|
11803
12477
|
}
|
|
11804
12478
|
if (options.build !== false) {
|
|
11805
|
-
const origin = buildOrigin(directHosts, primaryUrl,
|
|
12479
|
+
const origin = buildOrigin(directHosts, primaryUrl, process36.env.VELA_ORIGIN);
|
|
11806
12480
|
let buildEnv = {
|
|
11807
12481
|
VELA_ORIGIN: origin ?? ""
|
|
11808
12482
|
};
|
|
@@ -11949,11 +12623,11 @@ ${pc21.cyan(err.snippet)}` : err.message);
|
|
|
11949
12623
|
const has = current.kind === "auto" ? `is on ${ADAPTER_AUTO}` : "has no SvelteKit adapter configured";
|
|
11950
12624
|
const confirmed = await p49.confirm({
|
|
11951
12625
|
message: `This project ${has}, and vela deploy runs the app as a Node server.
|
|
11952
|
-
Switch it to ${ADAPTER_NODE2}? This edits ${
|
|
12626
|
+
Switch it to ${ADAPTER_NODE2}? This edits ${path51.basename(current.file)} and package.json.`
|
|
11953
12627
|
});
|
|
11954
12628
|
if (p49.isCancel(confirmed) || !confirmed) {
|
|
11955
12629
|
p49.cancel("Nothing was changed, and nothing was deployed.");
|
|
11956
|
-
|
|
12630
|
+
process36.exit(0);
|
|
11957
12631
|
}
|
|
11958
12632
|
}
|
|
11959
12633
|
const outcome = await ensureNodeAdapter(workspaceRootDir, { install: false }).catch(rethrow);
|
|
@@ -12116,7 +12790,7 @@ async function uploadRelease(session, instance, release, entries) {
|
|
|
12116
12790
|
}
|
|
12117
12791
|
function isDirectory(target) {
|
|
12118
12792
|
try {
|
|
12119
|
-
return
|
|
12793
|
+
return fs47.statSync(target).isDirectory();
|
|
12120
12794
|
} catch {
|
|
12121
12795
|
return false;
|
|
12122
12796
|
}
|
|
@@ -12124,7 +12798,7 @@ function isDirectory(target) {
|
|
|
12124
12798
|
async function reportEmptyEnvironment(session, instance, workspaceRootDir) {
|
|
12125
12799
|
const remote = await readRemoteEnv(session, instance);
|
|
12126
12800
|
if (Object.keys(remote).length > 0) return;
|
|
12127
|
-
if (!
|
|
12801
|
+
if (!fs47.existsSync(path51.join(workspaceRootDir, ".env"))) return;
|
|
12128
12802
|
p49.log.warn(
|
|
12129
12803
|
`This app has no production environment variables yet.
|
|
12130
12804
|
|
|
@@ -12161,8 +12835,8 @@ async function serverTimeOrLocal(session) {
|
|
|
12161
12835
|
}
|
|
12162
12836
|
|
|
12163
12837
|
// src/commands/link.ts
|
|
12164
|
-
import
|
|
12165
|
-
import
|
|
12838
|
+
import path52 from "node:path";
|
|
12839
|
+
import process37 from "node:process";
|
|
12166
12840
|
import { Command as Command85 } from "commander";
|
|
12167
12841
|
import * as p50 from "@clack/prompts";
|
|
12168
12842
|
var CREATE_NEW = "__new__";
|
|
@@ -12203,7 +12877,7 @@ async function pickExistingProject(projects) {
|
|
|
12203
12877
|
});
|
|
12204
12878
|
if (p50.isCancel(choice)) {
|
|
12205
12879
|
p50.cancel("Operation cancelled.");
|
|
12206
|
-
|
|
12880
|
+
process37.exit(0);
|
|
12207
12881
|
}
|
|
12208
12882
|
return choice;
|
|
12209
12883
|
}
|
|
@@ -12218,18 +12892,18 @@ async function promptProjectName(workspaceRootDir) {
|
|
|
12218
12892
|
});
|
|
12219
12893
|
if (p50.isCancel(value)) {
|
|
12220
12894
|
p50.cancel("Operation cancelled.");
|
|
12221
|
-
|
|
12895
|
+
process37.exit(0);
|
|
12222
12896
|
}
|
|
12223
12897
|
return value.trim();
|
|
12224
12898
|
}
|
|
12225
12899
|
function defaultProjectName2(workspaceRootDir) {
|
|
12226
12900
|
try {
|
|
12227
|
-
const pkg = readPackageJson(
|
|
12901
|
+
const pkg = readPackageJson(path52.join(workspaceRootDir, "package.json"));
|
|
12228
12902
|
const name = pkg.name;
|
|
12229
12903
|
if (typeof name === "string" && name.trim()) return name.trim();
|
|
12230
12904
|
} catch {
|
|
12231
12905
|
}
|
|
12232
|
-
return
|
|
12906
|
+
return path52.basename(workspaceRootDir);
|
|
12233
12907
|
}
|
|
12234
12908
|
|
|
12235
12909
|
// src/commands/env.ts
|
|
@@ -12273,7 +12947,7 @@ function report(keys, where) {
|
|
|
12273
12947
|
}
|
|
12274
12948
|
|
|
12275
12949
|
// src/commands/env/set.ts
|
|
12276
|
-
import
|
|
12950
|
+
import process38 from "node:process";
|
|
12277
12951
|
import { Command as Command87 } from "commander";
|
|
12278
12952
|
import * as p52 from "@clack/prompts";
|
|
12279
12953
|
import pc23 from "picocolors";
|
|
@@ -12315,7 +12989,7 @@ async function promptValue(key) {
|
|
|
12315
12989
|
});
|
|
12316
12990
|
if (p52.isCancel(value)) {
|
|
12317
12991
|
p52.cancel("Operation cancelled.");
|
|
12318
|
-
|
|
12992
|
+
process38.exit(0);
|
|
12319
12993
|
}
|
|
12320
12994
|
return value;
|
|
12321
12995
|
}
|
|
@@ -12360,9 +13034,9 @@ var envUnset = addTargetOptions(
|
|
|
12360
13034
|
);
|
|
12361
13035
|
|
|
12362
13036
|
// src/commands/env/import.ts
|
|
12363
|
-
import
|
|
12364
|
-
import
|
|
12365
|
-
import
|
|
13037
|
+
import fs48 from "node:fs";
|
|
13038
|
+
import path53 from "node:path";
|
|
13039
|
+
import process39 from "node:process";
|
|
12366
13040
|
import { Command as Command89 } from "commander";
|
|
12367
13041
|
import * as p54 from "@clack/prompts";
|
|
12368
13042
|
import pc25 from "picocolors";
|
|
@@ -12407,10 +13081,10 @@ var envImport = addTargetOptions(
|
|
|
12407
13081
|
)
|
|
12408
13082
|
);
|
|
12409
13083
|
function resolve(file) {
|
|
12410
|
-
return
|
|
13084
|
+
return path53.resolve(process39.cwd(), file);
|
|
12411
13085
|
}
|
|
12412
13086
|
function read(resolved, shown) {
|
|
12413
|
-
if (!
|
|
13087
|
+
if (!fs48.existsSync(resolved)) throw new Error(`${shown} does not exist.`);
|
|
12414
13088
|
const incoming = readLocalEnvFile(resolved);
|
|
12415
13089
|
if (Object.keys(incoming).length === 0) p54.log.info(`${shown} has no variables to import.`);
|
|
12416
13090
|
return incoming;
|
|
@@ -12567,7 +13241,7 @@ var logs = addTargetOptions(
|
|
|
12567
13241
|
import { Command as Command95 } from "commander";
|
|
12568
13242
|
|
|
12569
13243
|
// src/commands/admin/create.ts
|
|
12570
|
-
import
|
|
13244
|
+
import process40 from "node:process";
|
|
12571
13245
|
import { Command as Command94 } from "commander";
|
|
12572
13246
|
import * as p57 from "@clack/prompts";
|
|
12573
13247
|
import pc28 from "picocolors";
|
|
@@ -12642,7 +13316,7 @@ async function upsertSuperuser2(pb, email2, password11) {
|
|
|
12642
13316
|
});
|
|
12643
13317
|
if (p57.isCancel(confirmed) || !confirmed) {
|
|
12644
13318
|
p57.cancel("Operation cancelled.");
|
|
12645
|
-
|
|
13319
|
+
process40.exit(0);
|
|
12646
13320
|
}
|
|
12647
13321
|
await pb.collection("_superusers").update(existing, { password: password11, passwordConfirm: password11 });
|
|
12648
13322
|
p57.log.success(`Password updated for ${pc28.cyan(email2)}, you can sign in now`);
|
|
@@ -12666,7 +13340,7 @@ async function promptEmail() {
|
|
|
12666
13340
|
});
|
|
12667
13341
|
if (p57.isCancel(value)) {
|
|
12668
13342
|
p57.cancel("Operation cancelled.");
|
|
12669
|
-
|
|
13343
|
+
process40.exit(0);
|
|
12670
13344
|
}
|
|
12671
13345
|
return value.trim();
|
|
12672
13346
|
}
|
|
@@ -12677,7 +13351,7 @@ async function promptPassword2() {
|
|
|
12677
13351
|
});
|
|
12678
13352
|
if (p57.isCancel(value)) {
|
|
12679
13353
|
p57.cancel("Operation cancelled.");
|
|
12680
|
-
|
|
13354
|
+
process40.exit(0);
|
|
12681
13355
|
}
|
|
12682
13356
|
const again = await p57.password({
|
|
12683
13357
|
message: "Password again",
|
|
@@ -12685,7 +13359,7 @@ async function promptPassword2() {
|
|
|
12685
13359
|
});
|
|
12686
13360
|
if (p57.isCancel(again)) {
|
|
12687
13361
|
p57.cancel("Operation cancelled.");
|
|
12688
|
-
|
|
13362
|
+
process40.exit(0);
|
|
12689
13363
|
}
|
|
12690
13364
|
return value;
|
|
12691
13365
|
}
|
|
@@ -12697,8 +13371,8 @@ var admin = new Command95("admin").description("manage admin panel logins").conf
|
|
|
12697
13371
|
import { Command as Command101 } from "commander";
|
|
12698
13372
|
|
|
12699
13373
|
// src/commands/backup/create.ts
|
|
12700
|
-
import
|
|
12701
|
-
import
|
|
13374
|
+
import fs49 from "node:fs";
|
|
13375
|
+
import path54 from "node:path";
|
|
12702
13376
|
import { Command as Command96 } from "commander";
|
|
12703
13377
|
import * as p58 from "@clack/prompts";
|
|
12704
13378
|
import pc29 from "picocolors";
|
|
@@ -12852,12 +13526,12 @@ Your bucket's own versioning is what protects the uploaded files.`
|
|
|
12852
13526
|
}, "Failed to create the backup.")
|
|
12853
13527
|
);
|
|
12854
13528
|
async function download(ctx, key, outputDir) {
|
|
12855
|
-
const dir =
|
|
12856
|
-
|
|
12857
|
-
const destination =
|
|
13529
|
+
const dir = path54.resolve(ctx.workspaceRootDir, outputDir);
|
|
13530
|
+
fs49.mkdirSync(dir, { recursive: true });
|
|
13531
|
+
const destination = path54.join(dir, key);
|
|
12858
13532
|
if (!ctx.session) {
|
|
12859
|
-
|
|
12860
|
-
return
|
|
13533
|
+
fs49.copyFileSync(path54.join(ctx.workspaceRootDir, "data", "backups", key), destination);
|
|
13534
|
+
return path54.relative(ctx.workspaceRootDir, destination);
|
|
12861
13535
|
}
|
|
12862
13536
|
const spinner8 = p58.spinner();
|
|
12863
13537
|
spinner8.start(`Downloading ${key}`);
|
|
@@ -12868,7 +13542,7 @@ async function download(ctx, key, outputDir) {
|
|
|
12868
13542
|
throw error;
|
|
12869
13543
|
}
|
|
12870
13544
|
spinner8.stop(`Downloaded ${key}`);
|
|
12871
|
-
return
|
|
13545
|
+
return path54.relative(ctx.workspaceRootDir, destination);
|
|
12872
13546
|
}
|
|
12873
13547
|
|
|
12874
13548
|
// src/commands/backup/list.ts
|
|
@@ -12902,8 +13576,8 @@ Take one with ${pc30.cyan("vela backup create")}.`
|
|
|
12902
13576
|
);
|
|
12903
13577
|
|
|
12904
13578
|
// src/commands/backup/download.ts
|
|
12905
|
-
import
|
|
12906
|
-
import
|
|
13579
|
+
import fs50 from "node:fs";
|
|
13580
|
+
import path55 from "node:path";
|
|
12907
13581
|
import { Command as Command98 } from "commander";
|
|
12908
13582
|
import * as p60 from "@clack/prompts";
|
|
12909
13583
|
import pc31 from "picocolors";
|
|
@@ -12930,11 +13604,11 @@ Run ${pc31.cyan("vela backup list")} to see what it does have.`
|
|
|
12930
13604
|
Fetch it from the bucket directly \u2014 vela does not hold its credentials.`
|
|
12931
13605
|
);
|
|
12932
13606
|
}
|
|
12933
|
-
const dir =
|
|
12934
|
-
|
|
12935
|
-
const destination =
|
|
13607
|
+
const dir = path55.resolve(ctx.workspaceRootDir, options.output);
|
|
13608
|
+
fs50.mkdirSync(dir, { recursive: true });
|
|
13609
|
+
const destination = path55.join(dir, key);
|
|
12936
13610
|
if (!ctx.session) {
|
|
12937
|
-
|
|
13611
|
+
fs50.copyFileSync(path55.join(ctx.workspaceRootDir, "data", "backups", key), destination);
|
|
12938
13612
|
} else {
|
|
12939
13613
|
const spinner8 = p60.spinner();
|
|
12940
13614
|
spinner8.start(`Downloading ${key} (${formatBytes(found.size)})`);
|
|
@@ -12948,14 +13622,14 @@ Fetch it from the bucket directly \u2014 vela does not hold its credentials.`
|
|
|
12948
13622
|
}
|
|
12949
13623
|
reportResult({
|
|
12950
13624
|
summary: `Saved ${key} from ${ctx.targetName}.`,
|
|
12951
|
-
filesCreated: [
|
|
13625
|
+
filesCreated: [path55.relative(ctx.workspaceRootDir, destination)]
|
|
12952
13626
|
});
|
|
12953
13627
|
});
|
|
12954
13628
|
}, "Failed to download the backup.")
|
|
12955
13629
|
);
|
|
12956
13630
|
|
|
12957
13631
|
// src/commands/backup/delete.ts
|
|
12958
|
-
import
|
|
13632
|
+
import process41 from "node:process";
|
|
12959
13633
|
import { Command as Command99 } from "commander";
|
|
12960
13634
|
import * as p61 from "@clack/prompts";
|
|
12961
13635
|
import pc32 from "picocolors";
|
|
@@ -12981,7 +13655,7 @@ Run ${pc32.cyan("vela backup list")} to see what it does have.`
|
|
|
12981
13655
|
});
|
|
12982
13656
|
if (p61.isCancel(confirmed) || !confirmed) {
|
|
12983
13657
|
p61.cancel("Operation cancelled.");
|
|
12984
|
-
|
|
13658
|
+
process41.exit(0);
|
|
12985
13659
|
}
|
|
12986
13660
|
}
|
|
12987
13661
|
await ctx.pb.backups.delete(key);
|
|
@@ -13043,9 +13717,9 @@ Set one with ${pc33.cyan('vela backup schedule "0 3 * * *"')}.`
|
|
|
13043
13717
|
var backup = new Command101("backup").description("back up the database and uploads, locally or on a target").configureHelp(helpConfig).addCommand(backupCreate).addCommand(backupList).addCommand(backupDownload).addCommand(backupDelete).addCommand(backupSchedule);
|
|
13044
13718
|
|
|
13045
13719
|
// src/commands/restore.ts
|
|
13046
|
-
import
|
|
13047
|
-
import
|
|
13048
|
-
import
|
|
13720
|
+
import fs51 from "node:fs";
|
|
13721
|
+
import path56 from "node:path";
|
|
13722
|
+
import process42 from "node:process";
|
|
13049
13723
|
import { Command as Command102 } from "commander";
|
|
13050
13724
|
import * as p63 from "@clack/prompts";
|
|
13051
13725
|
import pc34 from "picocolors";
|
|
@@ -13074,7 +13748,7 @@ Run \`vela deploy\` first, then restore.`
|
|
|
13074
13748
|
`${ctx.targetName} was deployed without a database, so there is nothing to restore.`
|
|
13075
13749
|
);
|
|
13076
13750
|
}
|
|
13077
|
-
const local = source &&
|
|
13751
|
+
const local = source && fs51.existsSync(source) ? source : void 0;
|
|
13078
13752
|
const key = local ? void 0 : await resolveKey(ctx, source);
|
|
13079
13753
|
if (!options.yes) {
|
|
13080
13754
|
await confirm14(ctx.appName, ctx.targetName, ctx.envTag, local ?? key);
|
|
@@ -13097,7 +13771,7 @@ Run \`vela deploy\` first, then restore.`
|
|
|
13097
13771
|
});
|
|
13098
13772
|
p63.log.success(
|
|
13099
13773
|
`Restored ${pc34.cyan(`${ctx.appName} (${ctx.targetName})`)} from ${pc34.cyan(
|
|
13100
|
-
local ?
|
|
13774
|
+
local ? path56.basename(local) : key
|
|
13101
13775
|
)}.`
|
|
13102
13776
|
);
|
|
13103
13777
|
if (result?.storageCarriedOver) {
|
|
@@ -13157,27 +13831,27 @@ Take one with ${pc34.cyan("vela backup create")}, or pass the path to an archive
|
|
|
13157
13831
|
});
|
|
13158
13832
|
if (p63.isCancel(chosen)) {
|
|
13159
13833
|
p63.cancel("Operation cancelled.");
|
|
13160
|
-
|
|
13834
|
+
process42.exit(0);
|
|
13161
13835
|
}
|
|
13162
13836
|
return chosen;
|
|
13163
13837
|
}
|
|
13164
13838
|
async function stage(ctx, file) {
|
|
13165
13839
|
const dir = remotePaths.restoreStage(ctx.instance);
|
|
13166
|
-
const remote = `${dir}/${
|
|
13840
|
+
const remote = `${dir}/${path56.basename(file)}`;
|
|
13167
13841
|
const spinner8 = p63.spinner();
|
|
13168
|
-
spinner8.start(`Uploading ${
|
|
13842
|
+
spinner8.start(`Uploading ${path56.basename(file)}`);
|
|
13169
13843
|
try {
|
|
13170
13844
|
await ctx.session.script(`mkdir -p "$1"`, { args: [dir] });
|
|
13171
13845
|
await ctx.session.upload([file], dir);
|
|
13172
13846
|
} catch (error) {
|
|
13173
|
-
spinner8.stop(`Could not upload ${
|
|
13847
|
+
spinner8.stop(`Could not upload ${path56.basename(file)}.`);
|
|
13174
13848
|
throw error;
|
|
13175
13849
|
}
|
|
13176
|
-
spinner8.stop(`Uploaded ${
|
|
13850
|
+
spinner8.stop(`Uploaded ${path56.basename(file)}`);
|
|
13177
13851
|
return remote;
|
|
13178
13852
|
}
|
|
13179
13853
|
async function confirm14(appName, targetName, envTag, from) {
|
|
13180
|
-
const what = `${pc34.cyan(`${appName} (${targetName})`)} from ${pc34.cyan(
|
|
13854
|
+
const what = `${pc34.cyan(`${appName} (${targetName})`)} from ${pc34.cyan(path56.basename(from))}`;
|
|
13181
13855
|
if (isProd(envTag)) {
|
|
13182
13856
|
const answer = await p63.text({
|
|
13183
13857
|
message: `This replaces the database and uploads of ${what}. Type the app name to confirm`,
|
|
@@ -13185,7 +13859,7 @@ async function confirm14(appName, targetName, envTag, from) {
|
|
|
13185
13859
|
});
|
|
13186
13860
|
if (p63.isCancel(answer)) {
|
|
13187
13861
|
p63.cancel("Operation cancelled.");
|
|
13188
|
-
|
|
13862
|
+
process42.exit(0);
|
|
13189
13863
|
}
|
|
13190
13864
|
return;
|
|
13191
13865
|
}
|
|
@@ -13195,7 +13869,7 @@ async function confirm14(appName, targetName, envTag, from) {
|
|
|
13195
13869
|
});
|
|
13196
13870
|
if (p63.isCancel(ok) || !ok) {
|
|
13197
13871
|
p63.cancel("Operation cancelled.");
|
|
13198
|
-
|
|
13872
|
+
process42.exit(0);
|
|
13199
13873
|
}
|
|
13200
13874
|
}
|
|
13201
13875
|
|
|
@@ -13288,37 +13962,37 @@ Release and domain are shown from what this project recorded.`
|
|
|
13288
13962
|
}
|
|
13289
13963
|
|
|
13290
13964
|
// src/commands/test.ts
|
|
13291
|
-
import
|
|
13292
|
-
import
|
|
13965
|
+
import path57 from "node:path";
|
|
13966
|
+
import process43 from "node:process";
|
|
13293
13967
|
import { Command as Command104 } from "commander";
|
|
13294
13968
|
import PocketBase6 from "pocketbase";
|
|
13295
13969
|
import pc36 from "picocolors";
|
|
13296
13970
|
import { x as x6 } from "tinyexec";
|
|
13297
13971
|
import { detect as detect9 } from "package-manager-detector";
|
|
13298
13972
|
import { resolveCommand as resolveCommand7 } from "package-manager-detector/commands";
|
|
13299
|
-
import
|
|
13973
|
+
import fs52 from "node:fs";
|
|
13300
13974
|
var testServer = new Command104("test:server").description("run server tests").allowUnknownOption(true).allowExcessArguments(true).configureHelp(helpConfig).action(async (_opts, cmd) => {
|
|
13301
|
-
const cwd =
|
|
13975
|
+
const cwd = process43.cwd();
|
|
13302
13976
|
warnIfKit2(cwd, (m) => console.warn(pc36.yellow(`\u25B2 ${m}`)));
|
|
13303
13977
|
const email2 = `test-${Math.random().toString(36).slice(2)}@example.com`;
|
|
13304
13978
|
const password11 = "password";
|
|
13305
|
-
const testDataDir =
|
|
13306
|
-
|
|
13979
|
+
const testDataDir = path57.join(cwd, "test-data");
|
|
13980
|
+
fs52.rmSync(testDataDir, { recursive: true, force: true });
|
|
13307
13981
|
const { stop, url } = await launchPocketbase(cwd, {
|
|
13308
13982
|
dir: testDataDir,
|
|
13309
|
-
migrationsDir:
|
|
13983
|
+
migrationsDir: path57.join(cwd, MIGRATIONS_DIR),
|
|
13310
13984
|
// The app's PocketBase hooks (slug generation, personal teams, …) are part
|
|
13311
13985
|
// of its behaviour; the suite runs against the same server dev and build
|
|
13312
13986
|
// start, so it loads them from the same place.
|
|
13313
|
-
hooksDir:
|
|
13987
|
+
hooksDir: path57.join(cwd, DATA_DIR, "hooks"),
|
|
13314
13988
|
email: email2,
|
|
13315
13989
|
password: password11
|
|
13316
13990
|
});
|
|
13317
|
-
|
|
13318
|
-
|
|
13319
|
-
|
|
13320
|
-
|
|
13321
|
-
|
|
13991
|
+
process43.env.POCKETBASE_URL = url;
|
|
13992
|
+
process43.env.POCKETBASE_SUPERUSER_EMAIL = email2;
|
|
13993
|
+
process43.env.POCKETBASE_SUPERUSER_PASSWORD = password11;
|
|
13994
|
+
process43.env.VELA_DATA_DIR = testDataDir;
|
|
13995
|
+
process43.env.TEST = "true";
|
|
13322
13996
|
console.log(`${pc36.greenBright("\u2713")} Created test database`);
|
|
13323
13997
|
let vite;
|
|
13324
13998
|
let cleanedUp = false;
|
|
@@ -13326,11 +14000,11 @@ var testServer = new Command104("test:server").description("run server tests").a
|
|
|
13326
14000
|
if (cleanedUp) return;
|
|
13327
14001
|
cleanedUp = true;
|
|
13328
14002
|
stop();
|
|
13329
|
-
|
|
14003
|
+
fs52.rmSync(testDataDir, { recursive: true, force: true });
|
|
13330
14004
|
};
|
|
13331
14005
|
const cleanup = async () => {
|
|
13332
14006
|
if (cleanedUp) return;
|
|
13333
|
-
|
|
14007
|
+
process43.emit("sveltekit:shutdown", 0);
|
|
13334
14008
|
await vite?.close().catch(() => {
|
|
13335
14009
|
});
|
|
13336
14010
|
cleanupSync();
|
|
@@ -13338,13 +14012,19 @@ var testServer = new Command104("test:server").description("run server tests").a
|
|
|
13338
14012
|
const fail = async (message) => {
|
|
13339
14013
|
console.error(`${pc36.redBright("\u2717")} ${message}`);
|
|
13340
14014
|
await cleanup();
|
|
13341
|
-
|
|
14015
|
+
process43.exit(1);
|
|
13342
14016
|
};
|
|
13343
|
-
|
|
13344
|
-
|
|
13345
|
-
|
|
13346
|
-
|
|
13347
|
-
|
|
14017
|
+
process43.on("exit", cleanupSync);
|
|
14018
|
+
for (const [signal, code2] of [
|
|
14019
|
+
["SIGINT", 130],
|
|
14020
|
+
["SIGTERM", 143],
|
|
14021
|
+
["SIGHUP", 129]
|
|
14022
|
+
]) {
|
|
14023
|
+
process43.on(signal, () => {
|
|
14024
|
+
cleanupSync();
|
|
14025
|
+
process43.exit(code2);
|
|
14026
|
+
});
|
|
14027
|
+
}
|
|
13348
14028
|
const pb = new PocketBase6(url);
|
|
13349
14029
|
try {
|
|
13350
14030
|
await authWithRetries(pb, email2, password11);
|
|
@@ -13371,7 +14051,7 @@ var testServer = new Command104("test:server").description("run server tests").a
|
|
|
13371
14051
|
});
|
|
13372
14052
|
const vitePort = await findFreePort();
|
|
13373
14053
|
await vite.listen(vitePort);
|
|
13374
|
-
|
|
14054
|
+
process43.env.VITE_TEST_URL = `http://localhost:${vitePort}`;
|
|
13375
14055
|
console.log(`${pc36.greenBright("\u2713")} Started Vite: http://localhost:${vitePort}`);
|
|
13376
14056
|
console.log(`${pc36.greenBright("\u2713")} Started PocketBase: ${url}`);
|
|
13377
14057
|
const extraArgs = (cmd.parent?.args ?? []).slice(1);
|
|
@@ -13392,15 +14072,15 @@ var testServer = new Command104("test:server").description("run server tests").a
|
|
|
13392
14072
|
const resolvedArgs = resolved.args.slice();
|
|
13393
14073
|
if (pm === "npm") resolvedArgs.unshift("--yes");
|
|
13394
14074
|
const result = await x6(resolved.command, resolvedArgs, {
|
|
13395
|
-
nodeOptions: { cwd, stdio: "inherit", env: { ...
|
|
14075
|
+
nodeOptions: { cwd, stdio: "inherit", env: { ...process43.env, CI: "1" } }
|
|
13396
14076
|
});
|
|
13397
|
-
|
|
14077
|
+
process43.exitCode = result.exitCode ?? 1;
|
|
13398
14078
|
} catch (e) {
|
|
13399
14079
|
console.error(`${pc36.redBright("\u2717")} ${e.message}`);
|
|
13400
|
-
|
|
14080
|
+
process43.exitCode = 1;
|
|
13401
14081
|
} finally {
|
|
13402
14082
|
await cleanup();
|
|
13403
|
-
|
|
14083
|
+
process43.exit(process43.exitCode ?? 0);
|
|
13404
14084
|
}
|
|
13405
14085
|
});
|
|
13406
14086
|
function describeLoadFailure(e) {
|
|
@@ -13429,8 +14109,8 @@ function stubPagesPlugin() {
|
|
|
13429
14109
|
}
|
|
13430
14110
|
|
|
13431
14111
|
// src/commands/routes.ts
|
|
13432
|
-
import
|
|
13433
|
-
import
|
|
14112
|
+
import fs53 from "node:fs";
|
|
14113
|
+
import path58 from "node:path";
|
|
13434
14114
|
import { Command as Command105 } from "commander";
|
|
13435
14115
|
var HTTP_METHODS = /* @__PURE__ */ new Set([
|
|
13436
14116
|
"GET",
|
|
@@ -13444,30 +14124,30 @@ var HTTP_METHODS = /* @__PURE__ */ new Set([
|
|
|
13444
14124
|
]);
|
|
13445
14125
|
var routes = new Command105("routes").description("list routes").configureHelp(helpConfig).action(async () => {
|
|
13446
14126
|
const { workspaceRootDir, routesDir } = await getWorkspace();
|
|
13447
|
-
const routesRoot =
|
|
14127
|
+
const routesRoot = path58.join(workspaceRootDir, routesDir);
|
|
13448
14128
|
const found = walk(routesRoot, routesRoot).filter((r) => r.methods.length > 0);
|
|
13449
14129
|
found.sort((a, b) => a.urlPattern.localeCompare(b.urlPattern));
|
|
13450
14130
|
printTable(found);
|
|
13451
14131
|
});
|
|
13452
14132
|
function walk(root, dir) {
|
|
13453
|
-
const entries =
|
|
14133
|
+
const entries = fs53.readdirSync(dir, { withFileTypes: true });
|
|
13454
14134
|
const routes2 = [];
|
|
13455
14135
|
const hasLeaf = entries.some((e) => e.isFile() && isRouteFile(e.name));
|
|
13456
14136
|
if (hasLeaf) {
|
|
13457
|
-
const id = "/" +
|
|
14137
|
+
const id = "/" + path58.relative(root, dir).split(path58.sep).filter(Boolean).join("/");
|
|
13458
14138
|
const urlPattern = id.replace(/\([^)]+\)\/?/g, "").replace(/\/$/, "") || "/";
|
|
13459
14139
|
const methods = /* @__PURE__ */ new Set();
|
|
13460
14140
|
for (const entry of entries) {
|
|
13461
14141
|
if (!entry.isFile()) continue;
|
|
13462
14142
|
if (entry.name.endsWith("+page.svelte")) methods.add("GET");
|
|
13463
14143
|
if (entry.name.endsWith("+server.ts") || entry.name.endsWith("+server.js") || entry.name.endsWith("+page.server.ts") || entry.name.endsWith("+page.server.js")) {
|
|
13464
|
-
extractMethods(
|
|
14144
|
+
extractMethods(path58.join(dir, entry.name)).forEach((m) => methods.add(m));
|
|
13465
14145
|
}
|
|
13466
14146
|
}
|
|
13467
14147
|
routes2.push({ id: id || "/", urlPattern, methods: [...methods] });
|
|
13468
14148
|
}
|
|
13469
14149
|
for (const entry of entries) {
|
|
13470
|
-
if (entry.isDirectory()) routes2.push(...walk(root,
|
|
14150
|
+
if (entry.isDirectory()) routes2.push(...walk(root, path58.join(dir, entry.name)));
|
|
13471
14151
|
}
|
|
13472
14152
|
return routes2;
|
|
13473
14153
|
}
|
|
@@ -13476,7 +14156,7 @@ function isRouteFile(name) {
|
|
|
13476
14156
|
}
|
|
13477
14157
|
function extractMethods(file) {
|
|
13478
14158
|
try {
|
|
13479
|
-
const content =
|
|
14159
|
+
const content = fs53.readFileSync(file, "utf8");
|
|
13480
14160
|
const methods = [];
|
|
13481
14161
|
const exportRegex = /export\s+(?:const|async\s+function|function)\s+(\w+)/g;
|
|
13482
14162
|
let match;
|
|
@@ -13517,17 +14197,17 @@ function printTable(routes2) {
|
|
|
13517
14197
|
}
|
|
13518
14198
|
|
|
13519
14199
|
// src/commands/i18n.ts
|
|
13520
|
-
import
|
|
13521
|
-
import
|
|
13522
|
-
import
|
|
14200
|
+
import fs54 from "node:fs";
|
|
14201
|
+
import path59 from "node:path";
|
|
14202
|
+
import process44 from "node:process";
|
|
13523
14203
|
import { Command as Command106 } from "commander";
|
|
13524
14204
|
import { x as x7 } from "tinyexec";
|
|
13525
14205
|
import { detect as detect10 } from "package-manager-detector";
|
|
13526
14206
|
import { resolveCommand as resolveCommand8 } from "package-manager-detector/commands";
|
|
13527
14207
|
var WUCHALE_CONFIG_NAMES = ["js", "mjs", "ts", "mts"].map((ext) => `wuchale.config.${ext}`);
|
|
13528
14208
|
async function runWuchale(extraArgs) {
|
|
13529
|
-
const cwd = findWorkspaceRoot() ??
|
|
13530
|
-
if (!WUCHALE_CONFIG_NAMES.some((name) =>
|
|
14209
|
+
const cwd = findWorkspaceRoot() ?? process44.cwd();
|
|
14210
|
+
if (!WUCHALE_CONFIG_NAMES.some((name) => fs54.existsSync(path59.join(cwd, name)))) {
|
|
13531
14211
|
throw new Error("No wuchale config found. Run `vela enable i18n` to set up i18n.");
|
|
13532
14212
|
}
|
|
13533
14213
|
const pm = (await detect10({ cwd }))?.name ?? "npm";
|
|
@@ -13549,7 +14229,7 @@ var i18n3 = new Command106("i18n").description("i18n utilities").configureHelp(h
|
|
|
13549
14229
|
import { Command as Command112 } from "commander";
|
|
13550
14230
|
|
|
13551
14231
|
// src/commands/cms/deploy.ts
|
|
13552
|
-
import
|
|
14232
|
+
import process45 from "node:process";
|
|
13553
14233
|
import { Command as Command107 } from "commander";
|
|
13554
14234
|
import * as p65 from "@clack/prompts";
|
|
13555
14235
|
import pc37 from "picocolors";
|
|
@@ -13615,7 +14295,7 @@ function resolveProjectId(explicit) {
|
|
|
13615
14295
|
}
|
|
13616
14296
|
return explicit;
|
|
13617
14297
|
}
|
|
13618
|
-
const root = findWorkspaceRoot(
|
|
14298
|
+
const root = findWorkspaceRoot(process45.cwd());
|
|
13619
14299
|
const link2 = root ? readProjectConfig(root) : null;
|
|
13620
14300
|
if (!link2) {
|
|
13621
14301
|
throw new Error(
|
|
@@ -13655,15 +14335,15 @@ import pc39 from "picocolors";
|
|
|
13655
14335
|
|
|
13656
14336
|
// src/lib/cms-backend.ts
|
|
13657
14337
|
import { createRequire as createRequire4 } from "node:module";
|
|
13658
|
-
import
|
|
13659
|
-
import
|
|
14338
|
+
import path60 from "node:path";
|
|
14339
|
+
import process46 from "node:process";
|
|
13660
14340
|
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
13661
14341
|
import pc38 from "picocolors";
|
|
13662
14342
|
var DEFAULT_PROJECT = "default";
|
|
13663
14343
|
async function loadBackendModule(root) {
|
|
13664
14344
|
let entry;
|
|
13665
14345
|
try {
|
|
13666
|
-
entry = createRequire4(
|
|
14346
|
+
entry = createRequire4(path60.join(root, "package.json")).resolve("@velastack/cms/backend");
|
|
13667
14347
|
} catch {
|
|
13668
14348
|
throw new Error(
|
|
13669
14349
|
`@velastack/cms is not installed in this project.
|
|
@@ -13673,7 +14353,7 @@ Run ${pc38.cyan("vela enable cms")} first.`
|
|
|
13673
14353
|
}
|
|
13674
14354
|
return await import(pathToFileURL3(entry).href);
|
|
13675
14355
|
}
|
|
13676
|
-
async function withCmsBackend(fn, cwd =
|
|
14356
|
+
async function withCmsBackend(fn, cwd = process46.cwd()) {
|
|
13677
14357
|
const root = findWorkspaceRoot(cwd);
|
|
13678
14358
|
if (!root) {
|
|
13679
14359
|
throw new Error("Could not find workspace root (no package.json found)");
|
|
@@ -13681,8 +14361,8 @@ async function withCmsBackend(fn, cwd = process45.cwd()) {
|
|
|
13681
14361
|
const { createCmsBackend } = await loadBackendModule(root);
|
|
13682
14362
|
const dataDir2 = localDataDir(root);
|
|
13683
14363
|
const backend3 = createCmsBackend({
|
|
13684
|
-
dbPath:
|
|
13685
|
-
uploadDir:
|
|
14364
|
+
dbPath: path60.join(dataDir2, "cms.sqlite"),
|
|
14365
|
+
uploadDir: path60.join(dataDir2, "uploads")
|
|
13686
14366
|
});
|
|
13687
14367
|
try {
|
|
13688
14368
|
return await fn(backend3);
|
|
@@ -13760,7 +14440,7 @@ var cms2 = new Command112("cms").description("manage the CMS").configureHelp(hel
|
|
|
13760
14440
|
import { Command as Command116 } from "commander";
|
|
13761
14441
|
|
|
13762
14442
|
// src/commands/workflows/list.ts
|
|
13763
|
-
import
|
|
14443
|
+
import process47 from "node:process";
|
|
13764
14444
|
import { Command as Command113, InvalidArgumentError as InvalidArgumentError5 } from "commander";
|
|
13765
14445
|
import * as p69 from "@clack/prompts";
|
|
13766
14446
|
import pc42 from "picocolors";
|
|
@@ -13838,7 +14518,7 @@ function formatRun(run, nameWidth) {
|
|
|
13838
14518
|
}
|
|
13839
14519
|
var workflowsList = new Command113("list").description("list recent workflow runs").option("--status <status>", `only runs in this state (${STATUSES.join(", ")})`, parseStatus).option("--name <workflow>", "only runs of this workflow").option("--limit <n>", "how many to show", parseLimit, 50).configureHelp(helpConfig).action(
|
|
13840
14520
|
(options) => runCommand(async () => {
|
|
13841
|
-
await withPocketbase(
|
|
14521
|
+
await withPocketbase(process47.cwd(), async (pb) => {
|
|
13842
14522
|
const runs = await listRuns(pb, {
|
|
13843
14523
|
status: options.status,
|
|
13844
14524
|
workflowName: options.name,
|
|
@@ -13859,7 +14539,7 @@ Start one from server code with ${pc42.cyan("<workflow>.run(input)")}, or with $
|
|
|
13859
14539
|
);
|
|
13860
14540
|
|
|
13861
14541
|
// src/commands/workflows/run.ts
|
|
13862
|
-
import
|
|
14542
|
+
import process48 from "node:process";
|
|
13863
14543
|
import { Command as Command114, InvalidArgumentError as InvalidArgumentError6 } from "commander";
|
|
13864
14544
|
import * as p70 from "@clack/prompts";
|
|
13865
14545
|
import pc43 from "picocolors";
|
|
@@ -13872,7 +14552,7 @@ function parseInput(value) {
|
|
|
13872
14552
|
}
|
|
13873
14553
|
var workflowsRun = new Command114("run").description("start a run of a workflow; the running app picks it up").argument("<name>", "the workflow name, as in its defineWorkflow spec").argument("[input]", "the run input as JSON", parseInput).configureHelp(helpConfig).action(
|
|
13874
14554
|
(name, input) => runCommand(async () => {
|
|
13875
|
-
await withPocketbase(
|
|
14555
|
+
await withPocketbase(process48.cwd(), async (pb) => {
|
|
13876
14556
|
const run = await createRun(pb, name, input);
|
|
13877
14557
|
p70.log.success(
|
|
13878
14558
|
`Queued ${pc43.cyan(name)} as run ${pc43.bold(run.id)}.
|
|
@@ -13884,13 +14564,13 @@ It runs once the app is up (${pc43.cyan("vela dev")}); ${pc43.cyan("vela workflo
|
|
|
13884
14564
|
);
|
|
13885
14565
|
|
|
13886
14566
|
// src/commands/workflows/cancel.ts
|
|
13887
|
-
import
|
|
14567
|
+
import process49 from "node:process";
|
|
13888
14568
|
import { Command as Command115 } from "commander";
|
|
13889
14569
|
import * as p71 from "@clack/prompts";
|
|
13890
14570
|
import pc44 from "picocolors";
|
|
13891
14571
|
var workflowsCancel = new Command115("cancel").description("cancel a pending or running workflow run").argument("<run-id>", "the run id from `vela workflows list`").configureHelp(helpConfig).action(
|
|
13892
14572
|
(id) => runCommand(async () => {
|
|
13893
|
-
await withPocketbase(
|
|
14573
|
+
await withPocketbase(process49.cwd(), async (pb) => {
|
|
13894
14574
|
const run = await cancelRun(pb, id);
|
|
13895
14575
|
p71.log.success(`Canceled run ${pc44.bold(run.id)} of ${pc44.cyan(run.workflowName)}.`);
|
|
13896
14576
|
});
|
|
@@ -13962,16 +14642,16 @@ var BACKEND_OPTIONAL_COMMANDS = /* @__PURE__ */ new Set(["dev", "build", "previe
|
|
|
13962
14642
|
var SELF_CREDENTIALED_COMMANDS = /* @__PURE__ */ new Set(["test:server"]);
|
|
13963
14643
|
var program = new Command117().name(package_default.name).description(package_default.description).version(package_default.version, "-v, --version").configureHelp(helpConfig);
|
|
13964
14644
|
program.hook("preAction", (_thisCommand, actionCommand) => {
|
|
13965
|
-
const envRoot = findWorkspaceRoot() ??
|
|
14645
|
+
const envRoot = findWorkspaceRoot() ?? process50.cwd();
|
|
13966
14646
|
dotenv2.config({ path: nodePath.join(envRoot, ".env"), quiet: true });
|
|
13967
|
-
const
|
|
13968
|
-
if (NO_BACKEND_COMMMANDS.has(
|
|
13969
|
-
const top =
|
|
14647
|
+
const path61 = getCommandPath(actionCommand);
|
|
14648
|
+
if (NO_BACKEND_COMMMANDS.has(path61)) return;
|
|
14649
|
+
const top = path61.split(" ", 1)[0];
|
|
13970
14650
|
if (NO_BACKEND_COMMMANDS.has(top)) return;
|
|
13971
14651
|
if (!hasBackend()) {
|
|
13972
14652
|
if (BACKEND_OPTIONAL_COMMANDS.has(top)) return;
|
|
13973
14653
|
p72.log.error(
|
|
13974
|
-
`${pc45.cyan(`vela ${
|
|
14654
|
+
`${pc45.cyan(`vela ${path61}`)} needs a backend, and this project does not have one.
|
|
13975
14655
|
|
|
13976
14656
|
There is no PocketBase database here for it to talk to.
|
|
13977
14657
|
|
|
@@ -13979,10 +14659,10 @@ To add one, run ${pc45.cyan("vela enable backend")}.`
|
|
|
13979
14659
|
);
|
|
13980
14660
|
p72.log.message();
|
|
13981
14661
|
p72.cancel("Operation failed.");
|
|
13982
|
-
|
|
14662
|
+
process50.exit(1);
|
|
13983
14663
|
}
|
|
13984
|
-
if (SELF_CREDENTIALED_COMMANDS.has(
|
|
13985
|
-
if (!
|
|
14664
|
+
if (SELF_CREDENTIALED_COMMANDS.has(path61)) return;
|
|
14665
|
+
if (!process50.env.POCKETBASE_SUPERUSER_EMAIL || !process50.env.POCKETBASE_SUPERUSER_PASSWORD) {
|
|
13986
14666
|
p72.log.error(
|
|
13987
14667
|
`PocketBase superuser credentials are required.
|
|
13988
14668
|
|
|
@@ -13993,7 +14673,7 @@ To set up an existing project, run ${pc45.cyan("vela bless")}.`
|
|
|
13993
14673
|
);
|
|
13994
14674
|
p72.log.message();
|
|
13995
14675
|
p72.cancel("Operation failed.");
|
|
13996
|
-
|
|
14676
|
+
process50.exit(1);
|
|
13997
14677
|
}
|
|
13998
14678
|
});
|
|
13999
14679
|
function getCommandPath(cmd) {
|
|
@@ -14046,5 +14726,5 @@ for (const command of [
|
|
|
14046
14726
|
}
|
|
14047
14727
|
|
|
14048
14728
|
// src/bin.ts
|
|
14049
|
-
program.parse(normalizeArgv(
|
|
14729
|
+
program.parse(normalizeArgv(process51.argv.slice(2)), { from: "user" });
|
|
14050
14730
|
//# sourceMappingURL=bin.js.map
|