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