@supatype/cli 0.1.9 → 0.1.11
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/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-test.log +139 -136
- package/.turbo/turbo-typecheck.log +1 -1
- package/dist/cli-install-method.d.ts +8 -0
- package/dist/cli-install-method.d.ts.map +1 -1
- package/dist/cli-install-method.js +10 -0
- package/dist/cli-install-method.js.map +1 -1
- package/dist/cli-version-embedded.d.ts.map +1 -1
- package/dist/cli-version-embedded.js +1 -1
- package/dist/cli-version-embedded.js.map +1 -1
- package/dist/commands/add.js +3 -2
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/db.d.ts.map +1 -1
- package/dist/commands/db.js +3 -2
- package/dist/commands/db.js.map +1 -1
- package/dist/commands/functions.d.ts.map +1 -1
- package/dist/commands/functions.js +3 -2
- package/dist/commands/functions.js.map +1 -1
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/generate.js +15 -18
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +16 -5
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/internal.d.ts.map +1 -1
- package/dist/commands/internal.js +37 -0
- package/dist/commands/internal.js.map +1 -1
- package/dist/commands/push.d.ts.map +1 -1
- package/dist/commands/push.js +15 -10
- package/dist/commands/push.js.map +1 -1
- package/dist/config.d.ts +22 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +34 -15
- package/dist/config.js.map +1 -1
- package/dist/resolve-api-url.d.ts.map +1 -1
- package/dist/resolve-api-url.js +3 -2
- package/dist/resolve-api-url.js.map +1 -1
- package/dist/tsx-runner.d.ts +12 -0
- package/dist/tsx-runner.d.ts.map +1 -1
- package/dist/tsx-runner.js +35 -1
- package/dist/tsx-runner.js.map +1 -1
- package/dist/type-generation.d.ts +24 -0
- package/dist/type-generation.d.ts.map +1 -0
- package/dist/type-generation.js +44 -0
- package/dist/type-generation.js.map +1 -0
- package/package.json +1 -1
- package/src/cli-install-method.ts +11 -0
- package/src/cli-version-embedded.ts +1 -1
- package/src/commands/add.ts +3 -2
- package/src/commands/db.ts +3 -2
- package/src/commands/functions.ts +3 -2
- package/src/commands/generate.ts +13 -21
- package/src/commands/init.ts +16 -5
- package/src/commands/internal.ts +37 -0
- package/src/commands/push.ts +14 -8
- package/src/config.ts +36 -15
- package/src/resolve-api-url.ts +3 -2
- package/src/tsx-runner.ts +40 -1
- package/src/type-generation.ts +60 -0
- package/tests/app-command.test.ts +12 -2
- package/tests/config-load-failure.test.ts +44 -0
- package/tsconfig.tsbuildinfo +1 -1
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,qBAAqB,CAAA;AAE5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAE9D,YAAY,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAEhE,+EAA+E;AAC/E,MAAM,MAAM,cAAc,GAAG,qBAAqB,CAAA;AAElD,MAAM,WAAW,iBAAiB;IAChC,iHAAiH;IACjH,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,2EAA2E;IAC3E,MAAM,EAAE,MAAM,CAAA;IACd,sDAAsD;IACtD,GAAG,CAAC,EAAE;QACJ,kEAAkE;QAClE,UAAU,EAAE,MAAM,CAAA;QAClB,+BAA+B;QAC/B,IAAI,EAAE,MAAM,CAAA;KACb,CAAA;IACD,GAAG,CAAC,EAAE;QACJ,gFAAgF;QAChF,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAA;QAC1B,+EAA+E;QAC/E,KAAK,CAAC,EAAE,MAAM,CAAA;KACf,CAAA;IACD;;;;OAIG;IACH,QAAQ,CAAC,EAAE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MAAM,CAAC,CAAA;IAC5B,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACjC;AAED,iEAAiE;AACjE,wBAAgB,YAAY,CAAC,MAAM,EAAE,qBAAqB,GAAG,qBAAqB,CAEjF;AAiCD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,GAAE,MAAsB,GAAG,qBAAqB,CA+B7E;AAcD;;;;;;;;;GASG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;gBAEf,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAK/C;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAExD;AAqED,2EAA2E;AAC3E,wBAAgB,aAAa,CAC3B,UAAU,EAAE,MAAM,EAClB,GAAG,GAAE,MAAsB,GAC1B,oBAAoB,CActB"}
|
package/dist/config.js
CHANGED
|
@@ -2,7 +2,7 @@ import { existsSync, readFileSync, writeFileSync, unlinkSync } from "node:fs";
|
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
-
import {
|
|
5
|
+
import { importModuleAsJson } from "./tsx-runner.js";
|
|
6
6
|
import { readEnvFile } from "./env-file.js";
|
|
7
7
|
import { mergeProjectConfig, validateProjectConfig, } from "./project-config.js";
|
|
8
8
|
import { extractSchemaAstFromTypes } from "./type-extractor.js";
|
|
@@ -75,29 +75,53 @@ export function loadConfig(cwd = process.cwd()) {
|
|
|
75
75
|
function configLoadEnv(cwd) {
|
|
76
76
|
return { ...readEnvFile(cwd), ...process.env };
|
|
77
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* A config file exists but could not be evaluated.
|
|
80
|
+
*
|
|
81
|
+
* Distinct from absence on purpose. Six call sites catch config loading so the CLI still works
|
|
82
|
+
* outside a project, and while they treated both cases the same, a config that failed to load
|
|
83
|
+
* looked exactly like no config at all. That is how a standalone binary that could not read any
|
|
84
|
+
* config shipped in v0.1.9 and still appeared to function: `status` printed a stack of stopped
|
|
85
|
+
* services, and `db check` fell back to DATABASE_URL from .env and reported a connection error.
|
|
86
|
+
* Those call sites should swallow absence and re-throw this.
|
|
87
|
+
*/
|
|
88
|
+
export class ConfigLoadError extends Error {
|
|
89
|
+
configPath;
|
|
90
|
+
constructor(configPath, detail) {
|
|
91
|
+
super(`Failed to load ${configPath}:\n${detail}`);
|
|
92
|
+
this.name = "ConfigLoadError";
|
|
93
|
+
this.configPath = configPath;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Re-throw a config that exists but could not be read; swallow anything else.
|
|
98
|
+
*
|
|
99
|
+
* For the call sites that catch config loading so the CLI still works outside a project. They
|
|
100
|
+
* want to ignore absence, not breakage, and treating the two alike is what let a standalone
|
|
101
|
+
* binary that could read no config at all still look like it was working.
|
|
102
|
+
*/
|
|
103
|
+
export function rethrowIfConfigBroken(err) {
|
|
104
|
+
if (err instanceof ConfigLoadError)
|
|
105
|
+
throw err;
|
|
106
|
+
}
|
|
78
107
|
function loadFirstTsConfig(cwd, candidates) {
|
|
79
108
|
for (const candidate of candidates) {
|
|
80
109
|
const configPath = resolve(cwd, candidate);
|
|
81
110
|
if (!existsSync(configPath))
|
|
82
111
|
continue;
|
|
83
112
|
const urlPath = "file:///" + configPath.replace(/\\/g, "/");
|
|
84
|
-
const
|
|
85
|
-
const mod = await import(${JSON.stringify(urlPath)})
|
|
86
|
-
const config = mod.default ?? mod
|
|
87
|
-
process.stdout.write(JSON.stringify(config))
|
|
88
|
-
`;
|
|
89
|
-
const result = evalTsSnippet(snippet, { cwd, env: configLoadEnv(cwd) });
|
|
113
|
+
const result = importModuleAsJson(urlPath, { cwd, env: configLoadEnv(cwd) });
|
|
90
114
|
if (result.exitCode === 0) {
|
|
91
115
|
return JSON.parse(result.stdout);
|
|
92
116
|
}
|
|
93
117
|
const failure = result.stderr || result.stdout;
|
|
94
118
|
if (!shouldStripCliImportOnLoadFailure(failure)) {
|
|
95
|
-
throw new
|
|
119
|
+
throw new ConfigLoadError(candidate, failure);
|
|
96
120
|
}
|
|
97
121
|
const fallback = loadTsConfigWithoutCliImport(configPath, cwd);
|
|
98
122
|
if (fallback !== null)
|
|
99
123
|
return fallback;
|
|
100
|
-
throw new
|
|
124
|
+
throw new ConfigLoadError(candidate, failure);
|
|
101
125
|
}
|
|
102
126
|
return null;
|
|
103
127
|
}
|
|
@@ -125,12 +149,7 @@ function loadTsConfigWithoutCliImport(configPath, cwd) {
|
|
|
125
149
|
writeFileSync(tmpPath, wrapper, "utf8");
|
|
126
150
|
try {
|
|
127
151
|
const urlPath = "file:///" + tmpPath.replace(/\\/g, "/");
|
|
128
|
-
const
|
|
129
|
-
const mod = await import(${JSON.stringify(urlPath)})
|
|
130
|
-
const config = mod.default ?? mod
|
|
131
|
-
process.stdout.write(JSON.stringify(config))
|
|
132
|
-
`;
|
|
133
|
-
const result = evalTsSnippet(snippet, { cwd, env: configLoadEnv(cwd) });
|
|
152
|
+
const result = importModuleAsJson(urlPath, { cwd, env: configLoadEnv(cwd) });
|
|
134
153
|
if (result.exitCode !== 0)
|
|
135
154
|
return null;
|
|
136
155
|
return JSON.parse(result.stdout);
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"config.js","sour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AAE,EAAE,GAAG,EAAE,GAAG,EAAE,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QAC5E,IAAI,MAAM,CAAC,QAAQ,KAAK,CAAC;YAAE,OAAO,IAAI,CAAA;QACtC,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAA4B,CAAA;IAC7D,CAAC;YAAS,CAAC;QACT,IAAI,CAAC;YACH,UAAU,CAAC,OAAO,CAAC,CAAA;QACrB,CAAC;QAAC,MAAM,CAAC;YACP,wBAAwB;QAC1B,CAAC;IACH,CAAC;AACH,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,aAAa,CAC3B,UAAkB,EAClB,MAAc,OAAO,CAAC,GAAG,EAAE;IAE3B,MAAM,SAAS,GAAG,yBAAyB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;IAC5D,IAAI,SAAS,KAAK,IAAI;QAAE,OAAO,SAAS,CAAA;IAExC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,CAAA;IACxC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,0BAA0B,OAAO,EAAE,CAAC,CAAA;IACtD,CAAC;IAED,MAAM,IAAI,KAAK,CACb,oDAAoD;QAClD,6CAA6C,OAAO,IAAI;QACxD,+FAA+F,CAClG,CAAA;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-api-url.d.ts","sourceRoot":"","sources":["../src/resolve-api-url.ts"],"names":[],"mappings":"AAAA;;GAEG;AAeH,sDAAsD;AACtD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"resolve-api-url.d.ts","sourceRoot":"","sources":["../src/resolve-api-url.ts"],"names":[],"mappings":"AAAA;;GAEG;AAeH,sDAAsD;AACtD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAyBxD"}
|
package/dist/resolve-api-url.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Resolve the project API base URL (Kong gateway or direct server) for CLI HTTP calls.
|
|
3
3
|
*/
|
|
4
|
-
import { loadConfig } from "./config.js";
|
|
4
|
+
import { loadConfig, rethrowIfConfigBroken } from "./config.js";
|
|
5
5
|
import { readEnvValue } from "./env-file.js";
|
|
6
6
|
import { serverBaseUrl } from "./project-config.js";
|
|
7
7
|
const API_URL_ENV_KEYS = [
|
|
@@ -30,7 +30,8 @@ export function resolveProjectApiUrl(cwd) {
|
|
|
30
30
|
return fromConfig.replace(/\/+$/, "");
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
catch {
|
|
33
|
+
catch (err) {
|
|
34
|
+
rethrowIfConfigBroken(err);
|
|
34
35
|
// No supatype.config: fall through to PORT default.
|
|
35
36
|
}
|
|
36
37
|
const port = readEnvValue(cwd, "PORT", "54321").trim() || "54321";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-api-url.js","sourceRoot":"","sources":["../src/resolve-api-url.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"resolve-api-url.js","sourceRoot":"","sources":["../src/resolve-api-url.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD,MAAM,gBAAgB,GAAG;IACvB,cAAc;IACd,kBAAkB;IAClB,qBAAqB;IACrB,0BAA0B;IAC1B,UAAU;IACV,kBAAkB;CACV,CAAA;AAEV,sDAAsD;AACtD,MAAM,UAAU,oBAAoB,CAAC,GAAW;IAC9C,KAAK,MAAM,GAAG,IAAI,gBAAgB,EAAE,CAAC;QACnC,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAA;QAC/C,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;QAClC,CAAC;IACH,CAAC;IAED,MAAM,QAAQ,GAAG,YAAY,CAAC,GAAG,EAAE,oBAAoB,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAA;IACnE,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,oBAAoB,QAAQ,EAAE,CAAA;IACvC,CAAC;IAED,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAA;QACjD,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;QACvC,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,qBAAqB,CAAC,GAAG,CAAC,CAAA;QAC1B,oDAAoD;IACtD,CAAC;IAED,MAAM,IAAI,GAAG,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,IAAI,OAAO,CAAA;IACjE,OAAO,oBAAoB,IAAI,EAAE,CAAA;AACnC,CAAC"}
|
package/dist/tsx-runner.d.ts
CHANGED
|
@@ -15,4 +15,16 @@ export declare function runTsFile(filePath: string, opts?: SpawnSyncOptions): Ru
|
|
|
15
15
|
* The snippet should write JSON to process.stdout.
|
|
16
16
|
*/
|
|
17
17
|
export declare function evalTsSnippet(snippet: string, opts?: SpawnSyncOptions): RunResult;
|
|
18
|
+
/**
|
|
19
|
+
* Import a module and return its default export as JSON text.
|
|
20
|
+
*
|
|
21
|
+
* Two interpreters, one contract. Under Node this writes a snippet and runs it through tsx, as
|
|
22
|
+
* it always has. As a compiled binary it re-executes itself, because there is no node_modules to
|
|
23
|
+
* resolve tsx from, no writable directory beside the executable, and on a `curl | sh` machine no
|
|
24
|
+
* Node either: the previous behaviour failed with
|
|
25
|
+
* `ENOENT: open '/$bunfs/root/supatype-eval-....mts'` and broke init, update, dev and push.
|
|
26
|
+
*
|
|
27
|
+
* Callers get the same stdout, stderr and exit code either way.
|
|
28
|
+
*/
|
|
29
|
+
export declare function importModuleAsJson(target: string, opts?: SpawnSyncOptions): RunResult;
|
|
18
30
|
//# sourceMappingURL=tsx-runner.d.ts.map
|
package/dist/tsx-runner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tsx-runner.d.ts","sourceRoot":"","sources":["../src/tsx-runner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAa,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"tsx-runner.d.ts","sourceRoot":"","sources":["../src/tsx-runner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAa,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAsCrE,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,yDAAyD;AACzD,wBAAgB,SAAS,CACvB,QAAQ,EAAE,MAAM,EAChB,IAAI,GAAE,gBAAqB,GAC1B,SAAS,CAaX;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,gBAAqB,GAC1B,SAAS,CAgBX;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,IAAI,GAAE,gBAAqB,GAC1B,SAAS,CAoBX"}
|
package/dist/tsx-runner.js
CHANGED
|
@@ -8,6 +8,7 @@ import { resolve, dirname } from "node:path";
|
|
|
8
8
|
import { createRequire } from "node:module";
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
10
|
import { writeFileSync, unlinkSync } from "node:fs";
|
|
11
|
+
import { isCompiledBinary } from "./cli-install-method.js";
|
|
11
12
|
const _require = createRequire(import.meta.url);
|
|
12
13
|
// The CLI's own source directory, workspace packages are
|
|
13
14
|
// resolvable from here. Eval snippets are written here so ESM resolution finds them.
|
|
@@ -32,7 +33,9 @@ function findTsxBin() {
|
|
|
32
33
|
const TSX_BIN = findTsxBin();
|
|
33
34
|
/** Run a TypeScript file with tsx and capture output. */
|
|
34
35
|
export function runTsFile(filePath, opts = {}) {
|
|
35
|
-
|
|
36
|
+
// Same split as importModuleAsJson: the binary interprets TypeScript itself, Node uses tsx.
|
|
37
|
+
const argv = isCompiledBinary() ? ["_run-ts", filePath] : [TSX_BIN, filePath];
|
|
38
|
+
const result = spawnSync(process.execPath, argv, {
|
|
36
39
|
encoding: "utf8",
|
|
37
40
|
maxBuffer: 50 * 1024 * 1024,
|
|
38
41
|
...opts,
|
|
@@ -66,4 +69,35 @@ export function evalTsSnippet(snippet, opts = {}) {
|
|
|
66
69
|
}
|
|
67
70
|
}
|
|
68
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Import a module and return its default export as JSON text.
|
|
74
|
+
*
|
|
75
|
+
* Two interpreters, one contract. Under Node this writes a snippet and runs it through tsx, as
|
|
76
|
+
* it always has. As a compiled binary it re-executes itself, because there is no node_modules to
|
|
77
|
+
* resolve tsx from, no writable directory beside the executable, and on a `curl | sh` machine no
|
|
78
|
+
* Node either: the previous behaviour failed with
|
|
79
|
+
* `ENOENT: open '/$bunfs/root/supatype-eval-....mts'` and broke init, update, dev and push.
|
|
80
|
+
*
|
|
81
|
+
* Callers get the same stdout, stderr and exit code either way.
|
|
82
|
+
*/
|
|
83
|
+
export function importModuleAsJson(target, opts = {}) {
|
|
84
|
+
if (isCompiledBinary()) {
|
|
85
|
+
const result = spawnSync(process.execPath, ["_print-module", target], {
|
|
86
|
+
encoding: "utf8",
|
|
87
|
+
maxBuffer: 50 * 1024 * 1024,
|
|
88
|
+
...opts,
|
|
89
|
+
});
|
|
90
|
+
return {
|
|
91
|
+
stdout: String(result.stdout ?? ""),
|
|
92
|
+
stderr: String(result.stderr ?? ""),
|
|
93
|
+
exitCode: result.status ?? 1,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const snippet = `
|
|
97
|
+
const mod = await import(${JSON.stringify(target)})
|
|
98
|
+
const config = mod.default ?? mod
|
|
99
|
+
process.stdout.write(JSON.stringify(config))
|
|
100
|
+
`;
|
|
101
|
+
return evalTsSnippet(snippet, opts);
|
|
102
|
+
}
|
|
69
103
|
//# sourceMappingURL=tsx-runner.js.map
|
package/dist/tsx-runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tsx-runner.js","sourceRoot":"","sources":["../src/tsx-runner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAyB,MAAM,oBAAoB,CAAA;AACrE,OAAO,EAAc,YAAY,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"tsx-runner.js","sourceRoot":"","sources":["../src/tsx-runner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAyB,MAAM,oBAAoB,CAAA;AACrE,OAAO,EAAc,YAAY,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,a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AAO;YACL,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;YACnC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;YACnC,QAAQ,EAAE,MAAM,CAAC,MAAM,IAAI,CAAC;SAC7B,CAAA;IACH,CAAC;IAED,MAAM,OAAO,GAAG;2BACS,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;;;CAGhD,CAAA;IACC,OAAO,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;AACrC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write a project's generated types to disk.
|
|
3
|
+
*
|
|
4
|
+
* `push` used to send `types_path` and `client_path` to the engine and read only `message`,
|
|
5
|
+
* expecting the engine to write the files. It does not write them, so with `output.types`
|
|
6
|
+
* configured the generated TypeScript was printed to the terminal and nothing reached disk:
|
|
7
|
+
* `supatype push` claims to generate types and produced none. `supatype generate` had it right
|
|
8
|
+
* all along, and this is that logic, shared, so the two cannot disagree again.
|
|
9
|
+
*
|
|
10
|
+
* Each path is optional and an absent one is skipped, because the two callers differ on purpose:
|
|
11
|
+
* `generate` falls back to defaults and always writes, while `push` writes only what the project
|
|
12
|
+
* asked for and must not start creating files in projects that never configured any.
|
|
13
|
+
*/
|
|
14
|
+
export interface GenerateTypesRequest {
|
|
15
|
+
cwd: string;
|
|
16
|
+
ast: unknown;
|
|
17
|
+
/** Relative path for the database types, from `output.types`. */
|
|
18
|
+
typesPath?: string | undefined;
|
|
19
|
+
/** Relative path for the client augmentation, from `output.client`. */
|
|
20
|
+
clientPath?: string | undefined;
|
|
21
|
+
}
|
|
22
|
+
/** Writes what was asked for and returns one message per file, for the caller to report. */
|
|
23
|
+
export declare function writeGeneratedTypes(req: GenerateTypesRequest): Promise<string[]>;
|
|
24
|
+
//# sourceMappingURL=type-generation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-generation.d.ts","sourceRoot":"","sources":["../src/type-generation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAOH,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,OAAO,CAAA;IACZ,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC9B,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAChC;AAED,4FAA4F;AAC5F,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA8BtF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write a project's generated types to disk.
|
|
3
|
+
*
|
|
4
|
+
* `push` used to send `types_path` and `client_path` to the engine and read only `message`,
|
|
5
|
+
* expecting the engine to write the files. It does not write them, so with `output.types`
|
|
6
|
+
* configured the generated TypeScript was printed to the terminal and nothing reached disk:
|
|
7
|
+
* `supatype push` claims to generate types and produced none. `supatype generate` had it right
|
|
8
|
+
* all along, and this is that logic, shared, so the two cannot disagree again.
|
|
9
|
+
*
|
|
10
|
+
* Each path is optional and an absent one is skipped, because the two callers differ on purpose:
|
|
11
|
+
* `generate` falls back to defaults and always writes, while `push` writes only what the project
|
|
12
|
+
* asked for and must not start creating files in projects that never configured any.
|
|
13
|
+
*/
|
|
14
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
15
|
+
import { dirname, resolve } from "node:path";
|
|
16
|
+
import { generateClientAugmentation } from "./augmentation-generator.js";
|
|
17
|
+
import { ensureEngine, engineRequest } from "./engine-client.js";
|
|
18
|
+
/** Writes what was asked for and returns one message per file, for the caller to report. */
|
|
19
|
+
export async function writeGeneratedTypes(req) {
|
|
20
|
+
const written = [];
|
|
21
|
+
if (req.typesPath !== undefined && req.typesPath !== "") {
|
|
22
|
+
await ensureEngine();
|
|
23
|
+
const result = await engineRequest("/generate", { ast: req.ast, lang: "typescript" });
|
|
24
|
+
// `code` is the field the engine fills; `message` is the older shape. Reading only `message`
|
|
25
|
+
// and printing it is how the generated file ended up in the terminal.
|
|
26
|
+
const code = result.code ?? result.message;
|
|
27
|
+
if (code === undefined) {
|
|
28
|
+
throw new Error("Engine returned no output for type generation.");
|
|
29
|
+
}
|
|
30
|
+
const outPath = resolve(req.cwd, req.typesPath);
|
|
31
|
+
mkdirSync(dirname(outPath), { recursive: true });
|
|
32
|
+
writeFileSync(outPath, code, "utf8");
|
|
33
|
+
written.push(`Types written to ${req.typesPath}`);
|
|
34
|
+
}
|
|
35
|
+
// Generated locally from the AST, so it needs no engine round trip.
|
|
36
|
+
if (req.clientPath !== undefined && req.clientPath !== "") {
|
|
37
|
+
const outPath = resolve(req.cwd, req.clientPath);
|
|
38
|
+
mkdirSync(dirname(outPath), { recursive: true });
|
|
39
|
+
writeFileSync(outPath, generateClientAugmentation(req.ast), "utf8");
|
|
40
|
+
written.push(`Client augmentation written to ${req.clientPath}`);
|
|
41
|
+
}
|
|
42
|
+
return written;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=type-generation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-generation.js","sourceRoot":"","sources":["../src/type-generation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAA;AACxE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAWhE,4FAA4F;AAC5F,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,GAAyB;IACjE,MAAM,OAAO,GAAa,EAAE,CAAA;IAE5B,IAAI,GAAG,CAAC,SAAS,KAAK,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AAA;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -23,6 +23,17 @@ const EMBEDDED_FS_PATH = /(^|\/)(\$bunfs|~BUN)\//i
|
|
|
23
23
|
* it is only correct to prefer it when argv[1] is an embedded path. Under Node the script path
|
|
24
24
|
* is what identifies the install.
|
|
25
25
|
*/
|
|
26
|
+
/**
|
|
27
|
+
* True when this process is a compiled single-file binary rather than Node running our JS.
|
|
28
|
+
*
|
|
29
|
+
* The distinction decides capability, not cosmetics: a compiled binary carries the Bun runtime
|
|
30
|
+
* and can import TypeScript directly, while it has no node_modules to resolve tsx from and no
|
|
31
|
+
* writable directory beside itself. A machine that installed with `curl | sh` has no Node at all.
|
|
32
|
+
*/
|
|
33
|
+
export function isCompiledBinary(): boolean {
|
|
34
|
+
return EMBEDDED_FS_PATH.test(normalizePath(process.argv[1] ?? ""))
|
|
35
|
+
}
|
|
36
|
+
|
|
26
37
|
export function runningBinaryPath(): string {
|
|
27
38
|
const main = normalizePath(process.argv[1] ?? "")
|
|
28
39
|
return EMBEDDED_FS_PATH.test(main) ? process.execPath : (process.argv[1] ?? "")
|
|
@@ -9,4 +9,4 @@
|
|
|
9
9
|
// Annotated `string`, not left to inference: once a release stamps a value here, the
|
|
10
10
|
// inferred literal type makes the `!== ""` test in cliPackageVersion() a compile error
|
|
11
11
|
// (TS2367, no overlap), so the build would only fail during a release.
|
|
12
|
-
export const EMBEDDED_CLI_VERSION: string = "0.1.
|
|
12
|
+
export const EMBEDDED_CLI_VERSION: string = "0.1.11"
|
package/src/commands/add.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Command } from "commander"
|
|
2
2
|
import { p, runClackFlow } from "../ui/clack.js"
|
|
3
|
-
import { loadConfig } from "../config.js"
|
|
3
|
+
import { loadConfig, rethrowIfConfigBroken } from "../config.js"
|
|
4
4
|
import { selfHostTlsEnabled } from "../project-config.js"
|
|
5
5
|
import { updateServerConfigInProject } from "../app-config.js"
|
|
6
6
|
import { ensureNotCancelled } from "../ui/prompts.js"
|
|
@@ -82,7 +82,8 @@ function printDomainNextSteps(cwd: string, domain: string): void {
|
|
|
82
82
|
let tlsActive = true
|
|
83
83
|
try {
|
|
84
84
|
tlsActive = selfHostTlsEnabled(loadConfig(cwd))
|
|
85
|
-
} catch {
|
|
85
|
+
} catch (err) {
|
|
86
|
+
rethrowIfConfigBroken(err)
|
|
86
87
|
// config re-load is best-effort for the warning below
|
|
87
88
|
}
|
|
88
89
|
|
package/src/commands/db.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import type { Command } from "commander"
|
|
9
|
-
import { loadConfig } from "../config.js"
|
|
9
|
+
import { loadConfig, rethrowIfConfigBroken } from "../config.js"
|
|
10
10
|
import { connectionString } from "../project-config.js"
|
|
11
11
|
import { loadProjectLink } from "../link.js"
|
|
12
12
|
import { resolveTarget } from "../resolve-target.js"
|
|
@@ -153,7 +153,8 @@ export function registerDb(program: Command): void {
|
|
|
153
153
|
const config = loadConfig(cwd)
|
|
154
154
|
url = url ?? connectionString(config)
|
|
155
155
|
schema = schema ?? config.schema?.pg_schema ?? "public"
|
|
156
|
-
} catch {
|
|
156
|
+
} catch (err) {
|
|
157
|
+
rethrowIfConfigBroken(err)
|
|
157
158
|
// Runnable outside a project, which is the point, an operator should be able to check a
|
|
158
159
|
// database before committing to any config at all.
|
|
159
160
|
url = url ?? process.env["DATABASE_URL"]
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import { resolve, join, basename, relative, isAbsolute } from "node:path"
|
|
12
12
|
import { spawnSync, execSync } from "node:child_process"
|
|
13
13
|
import { localKongBaseUrl } from "../local-gateway.js"
|
|
14
|
-
import { loadConfig } from "../config.js"
|
|
14
|
+
import { loadConfig, rethrowIfConfigBroken } from "../config.js"
|
|
15
15
|
import { ensureBinary } from "../ensure-binary.js"
|
|
16
16
|
import {
|
|
17
17
|
functionsPathCandidatesFromProject,
|
|
@@ -532,7 +532,8 @@ async function deployCloud(cwd: string, fns: DiscoveredFunction[], env?: string)
|
|
|
532
532
|
export function serviceRoleRoutesFor(cwd: string): string[] | undefined {
|
|
533
533
|
try {
|
|
534
534
|
return serviceRoleRoutes(loadConfig(cwd))
|
|
535
|
-
} catch {
|
|
535
|
+
} catch (err) {
|
|
536
|
+
rethrowIfConfigBroken(err)
|
|
536
537
|
return undefined
|
|
537
538
|
}
|
|
538
539
|
}
|
package/src/commands/generate.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import type { Command } from "commander"
|
|
2
|
-
import { mkdirSync, writeFileSync } from "node:fs"
|
|
3
|
-
import { resolve, dirname } from "node:path"
|
|
4
2
|
import { loadConfig, loadSchemaAst } from "../config.js"
|
|
5
3
|
import { hooksPathFromProject, schemaPathFromProject } from "../project-config.js"
|
|
6
|
-
import { ensureEngine, engineRequest } from "../engine-client.js"
|
|
7
|
-
import { generateClientAugmentation } from "../augmentation-generator.js"
|
|
8
4
|
import { writeHooksModule } from "../model-hooks.js"
|
|
5
|
+
import { writeGeneratedTypes } from "../type-generation.js"
|
|
9
6
|
import { error, info } from "../ui/messages.js"
|
|
10
7
|
|
|
11
8
|
export function registerGenerate(program: Command): void {
|
|
@@ -20,29 +17,24 @@ export function registerGenerate(program: Command): void {
|
|
|
20
17
|
const outputTypesPath = config.output?.types ?? "types/database.ts"
|
|
21
18
|
const outputClientPath = config.output?.client ?? "supatype/generated/index.d.ts"
|
|
22
19
|
|
|
23
|
-
await ensureEngine()
|
|
24
20
|
info("Loading schema...")
|
|
25
21
|
const ast = loadSchemaAst(schemaPath, cwd)
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
// Shared with push, which used to delegate the writing to the engine and produce no files.
|
|
24
|
+
// Unlike push, this command always writes: the defaults above are the point of running it.
|
|
25
|
+
try {
|
|
26
|
+
const written = await writeGeneratedTypes({
|
|
27
|
+
cwd,
|
|
28
|
+
ast,
|
|
29
|
+
typesPath: outputTypesPath,
|
|
30
|
+
clientPath: outputClientPath,
|
|
31
|
+
})
|
|
32
|
+
for (const message of written) info(message)
|
|
33
|
+
} catch (err) {
|
|
34
|
+
error(err instanceof Error ? err.message : String(err))
|
|
32
35
|
process.exit(1)
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
const outPath = resolve(cwd, outputTypesPath)
|
|
36
|
-
mkdirSync(dirname(outPath), { recursive: true })
|
|
37
|
-
writeFileSync(outPath, typesCode, "utf8")
|
|
38
|
-
info(`Types written to ${outputTypesPath}`)
|
|
39
|
-
|
|
40
|
-
const augmentationOutPath = resolve(cwd, outputClientPath)
|
|
41
|
-
const augmentationCode = generateClientAugmentation(ast)
|
|
42
|
-
mkdirSync(dirname(augmentationOutPath), { recursive: true })
|
|
43
|
-
writeFileSync(augmentationOutPath, augmentationCode, "utf8")
|
|
44
|
-
info(`Client augmentation written to ${outputClientPath}`)
|
|
45
|
-
|
|
46
38
|
const hooksPath = writeHooksModule(cwd, hooksPathFromProject(config, cwd), ast)
|
|
47
39
|
if (hooksPath !== null) info(`Hook handler types written to ${hooksPath}`)
|
|
48
40
|
})
|
package/src/commands/init.ts
CHANGED
|
@@ -816,7 +816,22 @@ function packageJsonTemplate(opts: ScaffoldOptions, deps: InitDependencyVersions
|
|
|
816
816
|
if (opts.helloFunction) {
|
|
817
817
|
scripts.push(` "functions": "supatype functions serve"`)
|
|
818
818
|
}
|
|
819
|
-
|
|
819
|
+
// Both are development-time only, so they belong in devDependencies. Validated end to end
|
|
820
|
+
// against a real database: schema/index.ts imports @supatype/types with `import type`, which is
|
|
821
|
+
// erased at build; supatype.config.ts imports defineConfig, which only the CLI evaluates; and
|
|
822
|
+
// seed.ts is run by `tsx seed.ts`. Nothing `supatype push` or `supatype generate` writes refers
|
|
823
|
+
// to either package: the generated types import nothing, and the client augmentation declares a
|
|
824
|
+
// module for @supatype/client, which stays a real dependency.
|
|
825
|
+
//
|
|
826
|
+
// In dependencies they were installed by `npm install --omit=dev`, so every production install
|
|
827
|
+
// of a Supatype app pulled the whole CLI toolchain (ink, react, typescript, ts-morph, pg, tsx)
|
|
828
|
+
// to support three files that never run in production.
|
|
829
|
+
const devDeps = [
|
|
830
|
+
` "@supatype/cli": "^${deps.cli}"`,
|
|
831
|
+
` "@supatype/types": "^${deps.types}"`,
|
|
832
|
+
` "tsx": "^4.19.2"`,
|
|
833
|
+
` "typescript": "^5"`,
|
|
834
|
+
]
|
|
820
835
|
if (opts.app.viteDevUrl) {
|
|
821
836
|
devDeps.push(` "vite": "^6"`)
|
|
822
837
|
}
|
|
@@ -827,10 +842,6 @@ function packageJsonTemplate(opts: ScaffoldOptions, deps: InitDependencyVersions
|
|
|
827
842
|
"scripts": {
|
|
828
843
|
${scripts.join(",\n")}
|
|
829
844
|
},
|
|
830
|
-
"dependencies": {
|
|
831
|
-
"@supatype/cli": "^${deps.cli}",
|
|
832
|
-
"@supatype/types": "^${deps.types}"
|
|
833
|
-
},
|
|
834
845
|
"devDependencies": {
|
|
835
846
|
${devDeps.join(",\n")}
|
|
836
847
|
}
|
package/src/commands/internal.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type { Command } from "commander"
|
|
6
|
+
import { resolve } from "node:path"
|
|
7
|
+
import { pathToFileURL } from "node:url"
|
|
6
8
|
import { downloadAll } from "../binary-cache.js"
|
|
7
9
|
import { error, info } from "../ui/messages.js"
|
|
8
10
|
|
|
@@ -20,4 +22,39 @@ export function registerInternalCommands(program: Command): void {
|
|
|
20
22
|
process.exit(1)
|
|
21
23
|
}
|
|
22
24
|
})
|
|
25
|
+
|
|
26
|
+
// Interpreter for the standalone binary. It carries the Bun runtime, so it can import
|
|
27
|
+
// TypeScript directly; what it cannot do is spawn `node` with `tsx`, because a machine that
|
|
28
|
+
// installed with `curl | sh` has neither, and neither is embedded. So the binary re-executes
|
|
29
|
+
// itself for these two jobs rather than reaching for a toolchain that is not there.
|
|
30
|
+
//
|
|
31
|
+
// Hidden and prefixed, like _postinstall: they are an implementation detail of config loading,
|
|
32
|
+
// not commands anyone should run.
|
|
33
|
+
program
|
|
34
|
+
.command("_print-module <target>", { hidden: true })
|
|
35
|
+
.description("Import a module and print its default export as JSON")
|
|
36
|
+
.action(async (target: string) => {
|
|
37
|
+
try {
|
|
38
|
+
const href = target.startsWith("file:") ? target : pathToFileURL(resolve(target)).href
|
|
39
|
+
const mod = (await import(href)) as { default?: unknown }
|
|
40
|
+
const value = mod.default ?? mod
|
|
41
|
+
process.stdout.write(JSON.stringify(value))
|
|
42
|
+
} catch (err) {
|
|
43
|
+
// stderr, because the caller parses stdout as JSON and a message there would corrupt it.
|
|
44
|
+
process.stderr.write(err instanceof Error ? (err.stack ?? err.message) : String(err))
|
|
45
|
+
process.exit(1)
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
program
|
|
50
|
+
.command("_run-ts <file>", { hidden: true })
|
|
51
|
+
.description("Execute a TypeScript file for its side effects")
|
|
52
|
+
.action(async (file: string) => {
|
|
53
|
+
try {
|
|
54
|
+
await import(pathToFileURL(resolve(file)).href)
|
|
55
|
+
} catch (err) {
|
|
56
|
+
process.stderr.write(err instanceof Error ? (err.stack ?? err.message) : String(err))
|
|
57
|
+
process.exit(1)
|
|
58
|
+
}
|
|
59
|
+
})
|
|
23
60
|
}
|
package/src/commands/push.ts
CHANGED
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
import { confirm, logSkippedConfirm } from "../ui/confirm.js"
|
|
39
39
|
import { info, plain } from "../ui/messages.js"
|
|
40
40
|
import { withSpinner } from "../ui/progress.js"
|
|
41
|
+
import { writeGeneratedTypes } from "../type-generation.js"
|
|
41
42
|
import { isInteractive } from "../ui/interactive.js"
|
|
42
43
|
|
|
43
44
|
const DEV_JWT_SECRET = "super-secret-jwt-token-with-at-least-32-characters-long"
|
|
@@ -247,14 +248,19 @@ async function generateTypesLocal(ast: unknown, config: SupatypeProjectConfig):
|
|
|
247
248
|
if (syncManifestHooks(cwd, ast)) info("Hook map written to .supatype/manifest.json")
|
|
248
249
|
|
|
249
250
|
if (!config.output?.types && !config.output?.client) return
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
251
|
+
// The CLI writes these, it does not ask the engine to. Passing types_path and client_path and
|
|
252
|
+
// reading only `message` meant the generated TypeScript was printed to the terminal and no file
|
|
253
|
+
// was ever created, so `push` reported success and produced nothing.
|
|
254
|
+
const written = await withSpinner("Generating types", async () => {
|
|
255
|
+
const messages = await writeGeneratedTypes({
|
|
256
|
+
cwd,
|
|
257
|
+
ast,
|
|
258
|
+
typesPath: config.output?.types,
|
|
259
|
+
clientPath: config.output?.client,
|
|
260
|
+
})
|
|
261
|
+
return messages
|
|
262
|
+
})
|
|
263
|
+
for (const message of written) info(message)
|
|
258
264
|
}
|
|
259
265
|
|
|
260
266
|
async function provisionLocalStorage(ast: unknown, config: SupatypeProjectConfig): Promise<void> {
|