zitejs 0.10.0-start.2 → 0.10.0-start.20
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/cjs/auth/index.d.ts +2 -2
- package/dist/cjs/auth/index.js +6 -0
- package/dist/cjs/auth/index.test.js +30 -0
- package/dist/cjs/auth/previewClaim.d.ts +7 -0
- package/dist/cjs/auth/previewClaim.js +16 -0
- package/dist/cjs/backend/index.d.ts +121 -3
- package/dist/cjs/backend/index.test.js +58 -0
- package/dist/cjs/bundle/index.d.ts +8 -0
- package/dist/cjs/bundle/index.js +9 -8
- package/dist/cjs/check/index.d.ts +45 -1
- package/dist/cjs/check/index.js +198 -109
- package/dist/cjs/check/start/problem.d.ts +11 -0
- package/dist/cjs/check/start/problem.js +5 -0
- package/dist/cjs/check/start/routeTree.d.ts +9 -0
- package/dist/cjs/check/start/routeTree.js +111 -0
- package/dist/cjs/check/start/sourceRules.d.ts +8 -0
- package/dist/cjs/check/start/sourceRules.js +1110 -0
- package/dist/cjs/check/start/tsgo.d.ts +2 -0
- package/dist/cjs/check/start/tsgo.js +35 -0
- package/dist/cjs/cli.js +1 -1
- package/dist/cjs/client/index.d.ts +24 -0
- package/dist/cjs/dev/index.js +14 -4
- package/dist/cjs/integrations/rules.d.ts +13 -0
- package/dist/cjs/integrations/rules.js +29 -0
- package/dist/cjs/integrations/rules.test.js +1 -0
- package/dist/cjs/internal/appMode.d.ts +3 -0
- package/dist/cjs/internal/appMode.js +15 -0
- package/dist/cjs/runtime/index.d.ts +13 -13
- package/dist/cjs/start/entries.d.ts +10 -4
- package/dist/cjs/start/entries.js +23 -6
- package/dist/cjs/steps/index.d.ts +78 -0
- package/dist/cjs/steps/index.js +507 -0
- package/dist/cjs/steps/index.test.d.ts +1 -0
- package/dist/cjs/steps/index.test.js +635 -0
- package/dist/cjs/sync/index.js +2 -1
- package/dist/cjs/sync/lib.d.ts +10 -3
- package/dist/cjs/sync/lib.js +35 -21
- package/dist/cjs/sync/lib.test.js +106 -36
- package/dist/cjs/types/fields.d.ts +8 -1
- package/dist/cjs/types/fields.js +7 -1
- package/dist/cjs/types/tables.d.ts +16 -0
- package/dist/cjs/upload/index.js +12 -2
- package/dist/cjs/upload/index.test.js +39 -0
- package/dist/cjs/vite/index.js +8 -3
- package/dist/cjs/vite/index.test.js +10 -2
- package/dist/esm/auth/index.d.ts +2 -2
- package/dist/esm/auth/index.js +6 -0
- package/dist/esm/auth/index.test.js +30 -0
- package/dist/esm/auth/previewClaim.d.ts +7 -0
- package/dist/esm/auth/previewClaim.js +12 -0
- package/dist/esm/backend/index.d.ts +121 -3
- package/dist/esm/backend/index.test.js +58 -0
- package/dist/esm/bundle/index.d.ts +8 -0
- package/dist/esm/bundle/index.js +8 -8
- package/dist/esm/check/index.d.ts +45 -1
- package/dist/esm/check/index.js +198 -113
- package/dist/esm/check/start/problem.d.ts +11 -0
- package/dist/esm/check/start/problem.js +1 -0
- package/dist/esm/check/start/routeTree.d.ts +9 -0
- package/dist/esm/check/start/routeTree.js +70 -0
- package/dist/esm/check/start/sourceRules.d.ts +8 -0
- package/dist/esm/check/start/sourceRules.js +1107 -0
- package/dist/esm/check/start/tsgo.d.ts +2 -0
- package/dist/esm/check/start/tsgo.js +29 -0
- package/dist/esm/cli.js +1 -1
- package/dist/esm/client/index.d.ts +24 -0
- package/dist/esm/dev/index.js +16 -6
- package/dist/esm/integrations/rules.d.ts +13 -0
- package/dist/esm/integrations/rules.js +29 -0
- package/dist/esm/integrations/rules.test.js +1 -0
- package/dist/esm/internal/appMode.d.ts +3 -0
- package/dist/esm/internal/appMode.js +10 -0
- package/dist/esm/runtime/index.d.ts +13 -13
- package/dist/esm/start/aiUsage.d.ts +23 -0
- package/dist/esm/start/aiUsage.js +146 -0
- package/dist/esm/start/airtable/arrayFields.d.ts +10 -0
- package/dist/esm/start/airtable/arrayFields.js +30 -0
- package/dist/esm/start/airtable/dispatch.d.ts +54 -0
- package/dist/esm/start/airtable/dispatch.js +483 -0
- package/dist/esm/start/airtable/formulas.d.ts +70 -0
- package/dist/esm/start/airtable/formulas.js +258 -0
- package/dist/esm/start/airtable/index.d.ts +8 -0
- package/dist/esm/start/airtable/index.js +54 -0
- package/dist/esm/start/authHooks.d.ts +7 -0
- package/dist/esm/start/authHooks.js +10 -0
- package/dist/esm/start/authHooksModule.d.ts +1 -0
- package/dist/esm/start/authHooksModule.js +3 -0
- package/dist/esm/start/clientErrorMessage.test.d.ts +1 -0
- package/dist/esm/start/clientErrorMessage.test.js +105 -0
- package/dist/esm/start/credentials.d.ts +2 -0
- package/dist/esm/start/credentials.js +2 -0
- package/dist/esm/start/data/baseRunner.d.ts +92 -0
- package/dist/esm/start/data/baseRunner.js +83 -0
- package/dist/esm/start/data/dispatch.d.ts +16 -0
- package/dist/esm/start/data/dispatch.js +198 -0
- package/dist/esm/start/data/index.d.ts +15 -0
- package/dist/esm/start/data/index.js +58 -0
- package/dist/esm/start/data/sqlNameMappings.d.ts +58 -0
- package/dist/esm/start/data/sqlNameMappings.js +92 -0
- package/dist/esm/start/data/transformations.d.ts +97 -0
- package/dist/esm/start/data/transformations.js +262 -0
- package/dist/esm/start/data/types.d.ts +91 -0
- package/dist/esm/start/data/types.js +14 -0
- package/dist/esm/start/describe.d.ts +35 -5
- package/dist/esm/start/describe.js +74 -22
- package/dist/esm/start/entries.d.ts +10 -4
- package/dist/esm/start/entries.js +21 -5
- package/dist/esm/start/errors.d.ts +63 -0
- package/dist/esm/start/errors.js +146 -0
- package/dist/esm/start/errors.test.d.ts +1 -0
- package/dist/esm/start/errors.test.js +23 -0
- package/dist/esm/start/factories.test-d.d.ts +1 -0
- package/dist/esm/start/factories.test-d.js +20 -0
- package/dist/esm/start/index.d.ts +32 -27
- package/dist/esm/start/index.js +77 -47
- package/dist/esm/start/instance.d.ts +4 -4
- package/dist/esm/start/instance.js +54 -11
- package/dist/esm/start/outbound.d.ts +11 -0
- package/dist/esm/start/outbound.js +398 -0
- package/dist/esm/start/previewClaim.d.ts +7 -0
- package/dist/esm/start/previewClaim.js +23 -0
- package/dist/esm/start/problems.js +1 -1
- package/dist/esm/start/quiet.d.ts +2 -0
- package/dist/esm/start/quiet.js +27 -0
- package/dist/esm/start/redactSecrets.d.ts +15 -0
- package/dist/esm/start/redactSecrets.js +154 -0
- package/dist/esm/start/redactSecrets.test.d.ts +1 -0
- package/dist/esm/start/redactSecrets.test.js +151 -0
- package/dist/esm/start/registration.d.ts +13 -0
- package/dist/esm/start/registration.js +21 -0
- package/dist/esm/start/registrationHash.d.ts +22 -0
- package/dist/esm/start/registrationHash.js +470 -0
- package/dist/esm/start/router.d.ts +18 -4
- package/dist/esm/start/router.js +134 -11
- package/dist/esm/start/runLog.d.ts +7 -4
- package/dist/esm/start/runLog.js +64 -6
- package/dist/esm/start/scope.d.ts +2 -2
- package/dist/esm/start/server.d.ts +40 -36
- package/dist/esm/start/server.js +320 -48
- package/dist/esm/start/steps.d.ts +28 -0
- package/dist/esm/start/steps.js +97 -0
- package/dist/esm/start/types.d.ts +178 -5
- package/dist/esm/start/version.d.ts +1 -0
- package/dist/esm/start/version.js +2 -0
- package/dist/esm/start/vite.js +88 -11
- package/dist/esm/start/worker.d.ts +6 -0
- package/dist/esm/start/worker.js +12 -0
- package/dist/esm/start/workflow.d.ts +42 -12
- package/dist/esm/start/workflow.js +3 -3
- package/dist/esm/start/workflow.test-d.js +41 -8
- package/dist/esm/start/workflowModules.js +1 -1
- package/dist/esm/start/workflowRun.d.ts +21 -8
- package/dist/esm/start/workflowRun.js +29 -8
- package/dist/esm/steps/index.d.ts +78 -0
- package/dist/esm/steps/index.js +502 -0
- package/dist/esm/steps/index.test.d.ts +1 -0
- package/dist/esm/steps/index.test.js +633 -0
- package/dist/esm/sync/index.js +2 -1
- package/dist/esm/sync/lib.d.ts +10 -3
- package/dist/esm/sync/lib.js +35 -21
- package/dist/esm/sync/lib.test.js +106 -36
- package/dist/esm/types/fields.d.ts +8 -1
- package/dist/esm/types/fields.js +6 -0
- package/dist/esm/types/tables.d.ts +16 -0
- package/dist/esm/upload/index.js +12 -2
- package/dist/esm/upload/index.test.js +39 -0
- package/dist/esm/vite/index.js +8 -3
- package/dist/esm/vite/index.test.js +10 -2
- package/package.json +37 -16
- package/dist/cjs/start/problems.d.ts +0 -19
- package/dist/cjs/start/problems.js +0 -11
package/dist/esm/check/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { execFileSync } from 'child_process';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { execFileSync, spawnSync } from 'child_process';
|
|
2
|
+
import * as esbuild from 'esbuild';
|
|
3
|
+
import { existsSync, readdirSync, readFileSync } from 'fs';
|
|
4
|
+
import { join, relative, resolve } from 'path';
|
|
5
|
+
import { bundleEndpoints } from '../bundle/index.js';
|
|
6
|
+
import { listEndpointNames, listSourceDirs, sourceRootOf } from '../sourceRoots.js';
|
|
7
|
+
import { formatProblem } from './start/problem.js';
|
|
5
8
|
/**
|
|
6
9
|
* An argument array, not a command string, so no shell is involved.
|
|
7
10
|
*
|
|
@@ -25,28 +28,9 @@ function run(file, args, cwd) {
|
|
|
25
28
|
return { ok: false, output: (e.stderr ?? '') + (e.stdout ?? '') };
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* still exits 0, so a non-empty `endpointErrors` is the only signal there is.
|
|
31
|
-
*/
|
|
32
|
-
function bundleFailures(output) {
|
|
33
|
-
const line = output
|
|
34
|
-
.trim()
|
|
35
|
-
.split('\n')
|
|
36
|
-
.reverse()
|
|
37
|
-
.find(l => l.startsWith('{'));
|
|
38
|
-
if (!line)
|
|
39
|
-
return ['bundle produced no result'];
|
|
40
|
-
let result;
|
|
41
|
-
try {
|
|
42
|
-
result = JSON.parse(line);
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
return [`could not parse bundle output: ${line.slice(0, 200)}`];
|
|
46
|
-
}
|
|
31
|
+
async function bundleFailures(root, appPath, endpointNames) {
|
|
32
|
+
const result = await bundleEndpoints(resolve(appPath), root, endpointNames, 'silent').finally(() => esbuild.stop());
|
|
47
33
|
const failures = [];
|
|
48
|
-
if (result.error)
|
|
49
|
-
failures.push(result.error);
|
|
50
34
|
for (const [name, err] of Object.entries(result.endpointErrors ?? {})) {
|
|
51
35
|
failures.push(`${name}: ${err}`);
|
|
52
36
|
}
|
|
@@ -57,41 +41,183 @@ function bundleFailures(output) {
|
|
|
57
41
|
}
|
|
58
42
|
const indent = (output) => output.trim().split('\n').map(l => ` ${l}`).join('\n');
|
|
59
43
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* refuses, read the same way.
|
|
44
|
+
* While `--json` checks, stdout carries only the report: app code that logs as
|
|
45
|
+
* it's described in-process goes to stderr instead.
|
|
63
46
|
*/
|
|
64
|
-
async
|
|
65
|
-
process.stdout.write
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
47
|
+
export const withStdoutOnStderr = async (run) => {
|
|
48
|
+
const write = process.stdout.write;
|
|
49
|
+
process.stdout.write = process.stderr.write.bind(process.stderr);
|
|
50
|
+
try {
|
|
51
|
+
return await run();
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
process.stdout.write = write;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
/** Prints as it goes, or with `--json` stays quiet and reports everything at the end. */
|
|
58
|
+
export class Reporter {
|
|
59
|
+
json;
|
|
60
|
+
apps = [];
|
|
61
|
+
constructor(json) {
|
|
62
|
+
this.json = json;
|
|
63
|
+
}
|
|
64
|
+
app(path, runtime, heading) {
|
|
65
|
+
const app = { path, runtime, ok: true, steps: [], problems: [] };
|
|
66
|
+
this.apps.push(app);
|
|
67
|
+
if (heading && !this.json)
|
|
68
|
+
console.log(`\n── ${path} ──`);
|
|
69
|
+
return app;
|
|
70
|
+
}
|
|
71
|
+
step(app, name, result) {
|
|
72
|
+
if (result.unchecked) {
|
|
73
|
+
app.steps.push({ name, ok: false, unchecked: result.unchecked });
|
|
74
|
+
app.unchecked = true;
|
|
75
|
+
if (!this.json)
|
|
76
|
+
console.log(` ${name} ... unchecked: ${result.unchecked}`);
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
const output = result.output?.trim();
|
|
80
|
+
app.steps.push({ name, ok: result.ok, ...(output && !result.ok && { output }) });
|
|
81
|
+
if (!result.ok)
|
|
82
|
+
app.ok = false;
|
|
83
|
+
if (!this.json) {
|
|
84
|
+
console.log(` ${name} ... ${result.ok ? '✓' : '✗'}`);
|
|
85
|
+
if (!result.ok && output)
|
|
86
|
+
console.log(indent(output));
|
|
87
|
+
}
|
|
88
|
+
return result.ok;
|
|
89
|
+
}
|
|
90
|
+
problems(app, problems) {
|
|
91
|
+
app.problems.push(...problems);
|
|
92
|
+
if (problems.some(p => p.severity === 'error'))
|
|
93
|
+
app.ok = false;
|
|
94
|
+
if (!this.json && problems.length)
|
|
95
|
+
console.log(problems.map(p => ` ${formatProblem(p)}`).join('\n'));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const SKIPPED_DIRS = new Set(['node_modules', 'dist', '.output', '.tanstack', '.wrangler']);
|
|
99
|
+
/** The app's own source, by app-relative path. */
|
|
100
|
+
function readAppSources(appPath) {
|
|
101
|
+
const sources = {};
|
|
102
|
+
const visit = (dir) => {
|
|
103
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
104
|
+
if (SKIPPED_DIRS.has(entry.name))
|
|
105
|
+
continue;
|
|
106
|
+
const full = join(dir, entry.name);
|
|
107
|
+
if (entry.isDirectory())
|
|
108
|
+
visit(full);
|
|
109
|
+
else if (/\.[cm]?[jt]sx?$/.test(entry.name))
|
|
110
|
+
sources[relative(appPath, full)] = readFileSync(full, 'utf-8');
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const src = join(appPath, 'src');
|
|
114
|
+
if (existsSync(src))
|
|
115
|
+
visit(src);
|
|
116
|
+
return sources;
|
|
117
|
+
}
|
|
118
|
+
const isInternalApp = (appPath) => {
|
|
119
|
+
try {
|
|
120
|
+
return JSON.parse(readFileSync(join(appPath, 'zite.config.json'), 'utf-8'))?.accessMode === 'internal';
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
70
123
|
return false;
|
|
71
124
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* tsgo's Node launcher rethrows its compiler's kill: an exit of 1 with Node's
|
|
128
|
+
* `Error: Command failed: …/tsgo …` dump, `signal: 'SIGKILL'` included. Matched
|
|
129
|
+
* at line start, since `--pretty` quotes source lines that could hold either.
|
|
130
|
+
*/
|
|
131
|
+
const launcherKill = (output) => /^Error: Command failed: \S*tsgo\b/m.test(output) ? output.match(/\bsignal: '(SIG[A-Z]+)'/)?.[1] : undefined;
|
|
132
|
+
/**
|
|
133
|
+
* Runs a tool to its answer, or says why it gave none: a kill (a signal, or an
|
|
134
|
+
* exit of 128 and up with nothing printed) is a sandbox limit, not the app's.
|
|
135
|
+
*/
|
|
136
|
+
export function runTool(file, args, cwd) {
|
|
137
|
+
const result = spawnSync(file, args, { cwd, encoding: 'utf-8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 64 * 1024 * 1024 });
|
|
138
|
+
const output = (result.stderr ?? '') + (result.stdout ?? '');
|
|
139
|
+
if (result.error)
|
|
140
|
+
return { ok: false, unchecked: `couldn't run: ${result.error.message}` };
|
|
141
|
+
const signal = result.signal ?? (result.status !== 0 ? launcherKill(output) : undefined);
|
|
142
|
+
if (signal)
|
|
143
|
+
return { ok: false, unchecked: `killed by ${signal}` };
|
|
144
|
+
if (result.status !== null && result.status >= 128 && !output.trim()) {
|
|
145
|
+
return { ok: false, unchecked: `exited ${result.status} with no output` };
|
|
146
|
+
}
|
|
147
|
+
return { ok: result.status === 0, output };
|
|
148
|
+
}
|
|
149
|
+
const isMissingModule = (err) => err?.code === 'MODULE_NOT_FOUND';
|
|
150
|
+
/**
|
|
151
|
+
* A Start app, in about a second: its route tree regenerated as `vite build`
|
|
152
|
+
* writes it, a tsgo typecheck, which reads that tree, then the source rules.
|
|
153
|
+
* Neither a build nor describe: the platform's build is where access is decided
|
|
154
|
+
* and enforced, and these only say early what it would refuse.
|
|
155
|
+
*/
|
|
156
|
+
async function checkStartApp(reporter, app, appPath) {
|
|
157
|
+
const { regenerateRouteTree } = await import('./start/routeTree.js');
|
|
158
|
+
let routeTree = { ok: true };
|
|
79
159
|
try {
|
|
80
|
-
|
|
81
|
-
const { descriptionProblems } = await import('../start/problems.js');
|
|
82
|
-
const problems = descriptionProblems((await describeBuiltApp(appPath)));
|
|
83
|
-
console.log(problems.length ? '✗' : '✓');
|
|
84
|
-
if (problems.length)
|
|
85
|
-
console.log(problems.map(p => ` ${p}`).join('\n'));
|
|
86
|
-
return tsc.ok && problems.length === 0;
|
|
160
|
+
await regenerateRouteTree(appPath);
|
|
87
161
|
}
|
|
88
162
|
catch (err) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
163
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
164
|
+
routeTree = isMissingModule(err)
|
|
165
|
+
? { ok: false, unchecked: `the app's TanStack Start isn't installed: ${message}` }
|
|
166
|
+
: { ok: false, output: message };
|
|
167
|
+
}
|
|
168
|
+
if (reporter.step(app, 'route tree', routeTree)) {
|
|
169
|
+
const { findTsgo } = await import('./start/tsgo.js');
|
|
170
|
+
const tsgo = findTsgo(appPath);
|
|
171
|
+
reporter.step(app, 'tsgo --noEmit', !existsSync(join(appPath, 'tsconfig.app.json'))
|
|
172
|
+
? { ok: false, output: `no ${join(appPath, 'tsconfig.app.json')}` }
|
|
173
|
+
: !tsgo
|
|
174
|
+
? { ok: false, unchecked: "tsgo isn't installed (npm install -g @typescript/native-preview)" }
|
|
175
|
+
: // --pretty for `file:line:col - error` lines, the shape the platform re-roots. Two checkers, not
|
|
176
|
+
// four, hold half the type graph: a large app fits the sandbox's memory.
|
|
177
|
+
runTool(process.execPath, [tsgo, '--noEmit', '--pretty', '-p', 'tsconfig.app.json', '--checkers', '2'], appPath));
|
|
178
|
+
}
|
|
179
|
+
const { sourceProblems } = await import('./start/sourceRules.js');
|
|
180
|
+
const root = sourceRootOf(appPath);
|
|
181
|
+
let hints;
|
|
182
|
+
try {
|
|
183
|
+
hints = sourceProblems(readAppSources(appPath), {
|
|
184
|
+
internal: isInternalApp(appPath),
|
|
185
|
+
kind: root && { apps: 'app', automations: 'automation' }[root],
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
// A rule's own bug is nothing for the app to fix, and mustn't cost the report the steps before it.
|
|
190
|
+
reporter.step(app, 'source', { ok: false, unchecked: `source rules failed: ${err instanceof Error ? err.message : String(err)}` });
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
reporter.step(app, 'source', { ok: !hints.some(p => p.severity === 'error') });
|
|
194
|
+
reporter.problems(app, hints);
|
|
195
|
+
}
|
|
196
|
+
async function checkClassicApp(reporter, app, root, appPath) {
|
|
197
|
+
// Only tsconfig.app.json compiles anything. The app's tsconfig.json is a
|
|
198
|
+
// solution-style config — `"files": []` plus a reference — so
|
|
199
|
+
// `tsc --noEmit -p tsconfig.json` type-checks zero files and exits 0. It
|
|
200
|
+
// used to be the fallback, which meant an app missing tsconfig.app.json
|
|
201
|
+
// reported a passing typecheck it never ran.
|
|
202
|
+
const tsconfigAppPath = join(appPath, 'tsconfig.app.json');
|
|
203
|
+
reporter.step(app, 'tsc --noEmit', existsSync(tsconfigAppPath)
|
|
204
|
+
? run('npx', ['tsc', '--noEmit', '-p', tsconfigAppPath], '.')
|
|
205
|
+
: { ok: false, output: `no ${tsconfigAppPath}` });
|
|
206
|
+
// Endpoints never reach vite — they are bundled separately for the lambda,
|
|
207
|
+
// against a different resolver. tsc and vite both pass on an endpoint whose
|
|
208
|
+
// `zitejs/*` alias has no generated file behind it; only the bundler knows.
|
|
209
|
+
const endpointNames = listEndpointNames(root, appPath);
|
|
210
|
+
if (endpointNames.length > 0) {
|
|
211
|
+
const failures = await bundleFailures(root, appPath, endpointNames);
|
|
212
|
+
reporter.step(app, 'bundle endpoints', { ok: failures.length === 0, output: failures.join('\n') });
|
|
213
|
+
}
|
|
214
|
+
if (existsSync(join(appPath, 'vite.config.ts'))) {
|
|
215
|
+
reporter.step(app, 'vite build', run('npx', ['vite', 'build'], appPath));
|
|
92
216
|
}
|
|
93
217
|
}
|
|
94
|
-
export async function runCheck() {
|
|
218
|
+
export async function runCheck(args = process.argv.slice(3)) {
|
|
219
|
+
const json = args.includes('--json');
|
|
220
|
+
const reporter = new Reporter(json);
|
|
95
221
|
const { isStartAppDir } = await import('../start/entries.js');
|
|
96
222
|
// Run inside a Start app, its own zitejs checks just that app: the workspace
|
|
97
223
|
// root's is a classic release that doesn't know Start.
|
|
@@ -101,72 +227,31 @@ export async function runCheck() {
|
|
|
101
227
|
console.error('No apps or automations found under apps/ or automations/.');
|
|
102
228
|
process.exit(1);
|
|
103
229
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
// Only tsconfig.app.json compiles anything. The app's tsconfig.json is a
|
|
113
|
-
// solution-style config — `"files": []` plus a reference — so
|
|
114
|
-
// `tsc --noEmit -p tsconfig.json` type-checks zero files and exits 0. It
|
|
115
|
-
// used to be the fallback, which meant an app missing tsconfig.app.json
|
|
116
|
-
// reported a passing typecheck it never ran.
|
|
117
|
-
const tsconfigAppPath = join(appPath, 'tsconfig.app.json');
|
|
118
|
-
if (!existsSync(tsconfigAppPath)) {
|
|
119
|
-
console.log(` tsc --noEmit ... ✗ (no ${tsconfigAppPath})`);
|
|
120
|
-
allPassed = false;
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
process.stdout.write(' tsc --noEmit ... ');
|
|
124
|
-
const tsc = run('npx', ['tsc', '--noEmit', '-p', tsconfigAppPath], '.');
|
|
125
|
-
if (tsc.ok) {
|
|
126
|
-
console.log('✓');
|
|
230
|
+
const checkAll = async () => {
|
|
231
|
+
if (inStartApp)
|
|
232
|
+
await checkStartApp(reporter, reporter.app('.', 'start', false), '.');
|
|
233
|
+
for (const { root, path: appPath } of appDirs) {
|
|
234
|
+
if (isStartAppDir(appPath)) {
|
|
235
|
+
await checkStartApp(reporter, reporter.app(appPath, 'start', true), appPath);
|
|
127
236
|
}
|
|
128
237
|
else {
|
|
129
|
-
|
|
130
|
-
console.log(tsc.output.trim().split('\n').map(l => ` ${l}`).join('\n'));
|
|
131
|
-
allPassed = false;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
// Endpoints never reach vite — they are bundled separately for the lambda,
|
|
135
|
-
// against a different resolver. tsc and vite both pass on an endpoint whose
|
|
136
|
-
// `zitejs/*` alias has no generated file behind it; only the bundler knows.
|
|
137
|
-
if (listEndpointNames(root, appPath).length > 0) {
|
|
138
|
-
process.stdout.write(' bundle endpoints ... ');
|
|
139
|
-
const bundle = run('npx', ['zitejs', 'bundle', '--app', app], '.');
|
|
140
|
-
const failures = bundle.ok ? bundleFailures(bundle.output) : [bundle.output];
|
|
141
|
-
if (failures.length === 0) {
|
|
142
|
-
console.log('✓');
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
console.log('✗');
|
|
146
|
-
console.log(failures.map(l => ` ${l}`).join('\n'));
|
|
147
|
-
allPassed = false;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
const viteConfig = join(appPath, 'vite.config.ts');
|
|
151
|
-
if (existsSync(viteConfig)) {
|
|
152
|
-
process.stdout.write(' vite build ... ');
|
|
153
|
-
const vite = run('npx', ['vite', 'build'], appPath);
|
|
154
|
-
if (vite.ok) {
|
|
155
|
-
console.log('✓');
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
console.log('✗');
|
|
159
|
-
console.log(vite.output.trim().split('\n').map(l => ` ${l}`).join('\n'));
|
|
160
|
-
allPassed = false;
|
|
238
|
+
await checkClassicApp(reporter, reporter.app(appPath, 'classic', true), root, appPath);
|
|
161
239
|
}
|
|
162
240
|
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
241
|
+
};
|
|
242
|
+
await (json ? withStdoutOnStderr(checkAll) : checkAll());
|
|
243
|
+
const failed = reporter.apps.some(app => !app.ok);
|
|
244
|
+
const unchecked = reporter.apps.some(app => app.unchecked);
|
|
245
|
+
if (json) {
|
|
246
|
+
process.stdout.write(`${JSON.stringify({ ok: !failed && !unchecked, ...(unchecked && { unchecked: true }), apps: reporter.apps })}\n`);
|
|
167
247
|
}
|
|
168
248
|
else {
|
|
169
|
-
console.log('
|
|
170
|
-
|
|
249
|
+
console.log('');
|
|
250
|
+
console.log(failed ? 'Some apps failed.' : unchecked ? 'Some apps were not fully checked.' : 'All apps pass.');
|
|
171
251
|
}
|
|
252
|
+
// 3: nothing to fix, but not everything ran.
|
|
253
|
+
if (failed)
|
|
254
|
+
process.exit(1);
|
|
255
|
+
if (unchecked)
|
|
256
|
+
process.exit(3);
|
|
172
257
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Severity = "error" | "warning";
|
|
2
|
+
/** One finding of `zitejs check`, named by its rule. Errors fail the check; warnings only report. */
|
|
3
|
+
export type Problem = {
|
|
4
|
+
rule: string;
|
|
5
|
+
severity: Severity;
|
|
6
|
+
/** App-relative. */
|
|
7
|
+
file?: string;
|
|
8
|
+
line?: number;
|
|
9
|
+
message: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const formatProblem: ({ rule, severity, file, line, message }: Problem) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const formatProblem = ({ rule, severity, file, line, message }) => `${severity} ${rule}${file ? ` ${file}${line ? `:${line}` : ""}` : ""}: ${message}`;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const ENTRY_EXTENSIONS: string[];
|
|
2
|
+
/** Start's footer (start-plugin-core route-tree-footer), which types the router and start instance for `@tanstack/react-start`. */
|
|
3
|
+
export declare const startRouteTreeFooter: (generatedRouteTree: string, routerFile: string, startFile: string | undefined) => string[];
|
|
4
|
+
/**
|
|
5
|
+
* Regenerates the route tree with the router generator the app's own
|
|
6
|
+
* `@tanstack/react-start` builds with, configured as zitejs's Start plugin
|
|
7
|
+
* configures it, so the file is the one `vite build` writes, byte for byte.
|
|
8
|
+
*/
|
|
9
|
+
export declare function regenerateRouteTree(appDir: string): Promise<void>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// `src/routeTree.gen.ts` as `vite build` writes it, without vite: tsgo types
|
|
2
|
+
// each `createFileRoute` from it, and only the generator may write it.
|
|
3
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { pathToFileURL } from "node:url";
|
|
7
|
+
import { START_INSTANCE_ENTRY } from "../../start/entries.js";
|
|
8
|
+
// As Start resolves its entries (start-plugin-core resolve-entries).
|
|
9
|
+
export const ENTRY_EXTENSIONS = [".ts", ".js", ".mts", ".mjs", ".tsx", ".jsx"];
|
|
10
|
+
const resolveEntry = (srcDirectory, name) => {
|
|
11
|
+
const base = path.resolve(srcDirectory, name);
|
|
12
|
+
if (existsSync(base) && statSync(base).isFile())
|
|
13
|
+
return base;
|
|
14
|
+
return ENTRY_EXTENSIONS.map((extension) => base + extension).find((file) => existsSync(file));
|
|
15
|
+
};
|
|
16
|
+
const importPath = (generatedRouteTree, file) => {
|
|
17
|
+
let relative = path.relative(path.dirname(generatedRouteTree), file);
|
|
18
|
+
if (!relative.startsWith("."))
|
|
19
|
+
relative = `./${relative}`;
|
|
20
|
+
return relative.split(path.sep).join("/");
|
|
21
|
+
};
|
|
22
|
+
/** Start's footer (start-plugin-core route-tree-footer), which types the router and start instance for `@tanstack/react-start`. */
|
|
23
|
+
export const startRouteTreeFooter = (generatedRouteTree, routerFile, startFile) => {
|
|
24
|
+
const blocks = [
|
|
25
|
+
`import type { getRouter } from '${importPath(generatedRouteTree, routerFile)}'`,
|
|
26
|
+
startFile
|
|
27
|
+
? `import type { startInstance } from '${importPath(generatedRouteTree, startFile)}'`
|
|
28
|
+
: "import type { createStart } from '@tanstack/react-start'",
|
|
29
|
+
"declare module '@tanstack/react-start' {\n interface Register {\n ssr: true\n router: Awaited<ReturnType<typeof getRouter>>",
|
|
30
|
+
...(startFile ? [" config: Awaited<ReturnType<typeof startInstance.getOptions>>"] : []),
|
|
31
|
+
" }\n}",
|
|
32
|
+
];
|
|
33
|
+
return [blocks.join("\n")];
|
|
34
|
+
};
|
|
35
|
+
/** A package's ESM entry, resolved from `fromFile` as Node would. */
|
|
36
|
+
const importPackage = async (fromFile, name) => {
|
|
37
|
+
const manifest = createRequire(fromFile).resolve(`${name}/package.json`);
|
|
38
|
+
const { exports, module, main } = JSON.parse(readFileSync(manifest, "utf-8"));
|
|
39
|
+
const root = exports?.["."] ?? exports;
|
|
40
|
+
const entry = root?.import?.default ?? root?.import ?? root?.default ?? module ?? main ?? "index.js";
|
|
41
|
+
return import(pathToFileURL(path.join(path.dirname(manifest), entry)).href);
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Regenerates the route tree with the router generator the app's own
|
|
45
|
+
* `@tanstack/react-start` builds with, configured as zitejs's Start plugin
|
|
46
|
+
* configures it, so the file is the one `vite build` writes, byte for byte.
|
|
47
|
+
*/
|
|
48
|
+
export async function regenerateRouteTree(appDir) {
|
|
49
|
+
const root = path.resolve(appDir);
|
|
50
|
+
const srcDirectory = path.join(root, "src");
|
|
51
|
+
const routesDirectory = path.join(srcDirectory, "routes");
|
|
52
|
+
if (!existsSync(routesDirectory))
|
|
53
|
+
return;
|
|
54
|
+
const generatedRouteTree = path.join(srcDirectory, "routeTree.gen.ts");
|
|
55
|
+
const routerFile = resolveEntry(srcDirectory, "router");
|
|
56
|
+
if (!routerFile)
|
|
57
|
+
throw new Error("src/router.tsx is missing: Start reads the app's router from it");
|
|
58
|
+
// zite() points Start's entry at the generated start instance, relative to src/.
|
|
59
|
+
const startFile = resolveEntry(srcDirectory, path.join("..", START_INSTANCE_ENTRY.replace(/\.ts$/, "")));
|
|
60
|
+
const startManifest = createRequire(path.join(root, "package.json")).resolve("@tanstack/react-start/package.json");
|
|
61
|
+
const coreManifest = createRequire(startManifest).resolve("@tanstack/start-plugin-core/package.json");
|
|
62
|
+
const { getConfig, Generator } = (await importPackage(coreManifest, "@tanstack/router-generator"));
|
|
63
|
+
const footer = startRouteTreeFooter(generatedRouteTree, routerFile, startFile);
|
|
64
|
+
const config = {
|
|
65
|
+
...getConfig({ routesDirectory, generatedRouteTree }, root),
|
|
66
|
+
target: "react",
|
|
67
|
+
routeTreeFileFooter: () => footer,
|
|
68
|
+
};
|
|
69
|
+
await new Generator({ config, root }).run();
|
|
70
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Problem } from "./problem.js";
|
|
2
|
+
/** Which a Start project is, when the check can tell from where it sits. */
|
|
3
|
+
export type SourceKind = "app" | "automation";
|
|
4
|
+
/** Every source hint for one Start app, given its files by app-relative path. */
|
|
5
|
+
export declare function sourceProblems(sources: Record<string, string>, { internal, kind }?: {
|
|
6
|
+
internal?: boolean;
|
|
7
|
+
kind?: SourceKind;
|
|
8
|
+
}): Problem[];
|