zitejs 0.10.0-start.13 → 0.10.0-start.15

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 (41) hide show
  1. package/dist/cjs/check/index.d.ts +18 -6
  2. package/dist/cjs/check/index.js +57 -20
  3. package/dist/cjs/check/start/routeTree.d.ts +8 -0
  4. package/dist/cjs/check/start/routeTree.js +111 -0
  5. package/dist/cjs/check/start/sourceRules.d.ts +3 -1
  6. package/dist/cjs/check/start/sourceRules.js +401 -12
  7. package/dist/cjs/check/start/tsgo.d.ts +2 -0
  8. package/dist/cjs/check/start/tsgo.js +35 -0
  9. package/dist/cjs/cli.js +1 -1
  10. package/dist/cjs/internal/appMode.d.ts +3 -0
  11. package/dist/cjs/internal/appMode.js +15 -0
  12. package/dist/cjs/upload/index.js +12 -2
  13. package/dist/cjs/upload/index.test.js +39 -0
  14. package/dist/esm/check/index.d.ts +18 -6
  15. package/dist/esm/check/index.js +57 -21
  16. package/dist/esm/check/start/routeTree.d.ts +8 -0
  17. package/dist/esm/check/start/routeTree.js +70 -0
  18. package/dist/esm/check/start/sourceRules.d.ts +3 -1
  19. package/dist/esm/check/start/sourceRules.js +401 -12
  20. package/dist/esm/check/start/tsgo.d.ts +2 -0
  21. package/dist/esm/check/start/tsgo.js +29 -0
  22. package/dist/esm/cli.js +1 -1
  23. package/dist/esm/internal/appMode.d.ts +3 -0
  24. package/dist/esm/internal/appMode.js +10 -0
  25. package/dist/esm/start/airtable/index.d.ts +1 -1
  26. package/dist/esm/start/airtable/index.js +14 -30
  27. package/dist/esm/start/credentials.d.ts +1 -18
  28. package/dist/esm/start/credentials.js +1 -29
  29. package/dist/esm/start/data/index.d.ts +2 -5
  30. package/dist/esm/start/data/index.js +4 -22
  31. package/dist/esm/start/outbound.js +3 -10
  32. package/dist/esm/start/router.d.ts +6 -1
  33. package/dist/esm/start/router.js +10 -4
  34. package/dist/esm/start/server.d.ts +2 -5
  35. package/dist/esm/start/server.js +5 -10
  36. package/dist/esm/start/types.d.ts +12 -15
  37. package/dist/esm/start/version.d.ts +1 -1
  38. package/dist/esm/start/version.js +1 -1
  39. package/dist/esm/upload/index.js +12 -2
  40. package/dist/esm/upload/index.test.js +39 -0
  41. package/package.json +1 -1
@@ -1,14 +1,24 @@
1
1
  import { type Problem } from './start/problem.js';
2
- type Step = {
3
- name: string;
2
+ /**
3
+ * A step's result. `unchecked` is why it couldn't answer at all (killed, out of
4
+ * memory, a tool missing): nothing for the app to fix, so it carries no output.
5
+ */
6
+ type StepResult = {
4
7
  ok: boolean;
5
8
  output?: string;
9
+ unchecked?: string;
6
10
  };
11
+ type Step = {
12
+ name: string;
13
+ } & StepResult;
7
14
  /** One app's check, as `--json` reports it. */
8
15
  export type AppCheck = {
9
16
  path: string;
10
17
  runtime: 'classic' | 'start';
18
+ /** False when something in it needs fixing. */
11
19
  ok: boolean;
20
+ /** Set when a step couldn't run to an answer, so the app wasn't fully checked. */
21
+ unchecked?: true;
12
22
  steps: Step[];
13
23
  problems: Problem[];
14
24
  };
@@ -23,11 +33,13 @@ export declare class Reporter {
23
33
  readonly apps: AppCheck[];
24
34
  constructor(json: boolean);
25
35
  app(path: string, runtime: AppCheck['runtime'], heading: boolean): AppCheck;
26
- step(app: AppCheck, name: string, result: {
27
- ok: boolean;
28
- output?: string;
29
- }): boolean;
36
+ step(app: AppCheck, name: string, result: StepResult): boolean;
30
37
  problems(app: AppCheck, problems: Problem[]): void;
31
38
  }
39
+ /**
40
+ * Runs a tool to its answer, or says why it gave none: a kill (a signal, or an
41
+ * exit of 128 and up with nothing printed) is a sandbox limit, not the app's.
42
+ */
43
+ export declare function runTool(file: string, args: string[], cwd: string): StepResult;
32
44
  export declare function runCheck(args?: string[]): Promise<void>;
33
45
  export {};
@@ -1,4 +1,4 @@
1
- import { execFileSync } from 'child_process';
1
+ import { execFileSync, spawnSync } from 'child_process';
2
2
  import { existsSync, readdirSync, readFileSync } from 'fs';
3
3
  import { join, relative } from 'path';
4
4
  import { listEndpointNames, listSourceDirs } from '../sourceRoots.js';
@@ -86,6 +86,13 @@ export class Reporter {
86
86
  return app;
87
87
  }
88
88
  step(app, name, result) {
89
+ if (result.unchecked) {
90
+ app.steps.push({ name, ok: false, unchecked: result.unchecked });
91
+ app.unchecked = true;
92
+ if (!this.json)
93
+ console.log(` ${name} ... unchecked: ${result.unchecked}`);
94
+ return false;
95
+ }
89
96
  const output = result.output?.trim();
90
97
  app.steps.push({ name, ok: result.ok, ...(output && !result.ok && { output }) });
91
98
  if (!result.ok)
@@ -134,28 +141,53 @@ const isInternalApp = (appPath) => {
134
141
  }
135
142
  };
136
143
  /**
137
- * A Start app: `vite build` first, since it regenerates the route tree tsc
138
- * reads, then tsc, then describe, which reports what the platform's build
139
- * refuses, read the same way, then the source hints.
144
+ * Runs a tool to its answer, or says why it gave none: a kill (a signal, or an
145
+ * exit of 128 and up with nothing printed) is a sandbox limit, not the app's.
146
+ */
147
+ export function runTool(file, args, cwd) {
148
+ const result = spawnSync(file, args, { cwd, encoding: 'utf-8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 64 * 1024 * 1024 });
149
+ const output = (result.stderr ?? '') + (result.stdout ?? '');
150
+ if (result.error)
151
+ return { ok: false, unchecked: `couldn't run: ${result.error.message}` };
152
+ if (result.signal)
153
+ return { ok: false, unchecked: `killed by ${result.signal}` };
154
+ if (result.status !== null && result.status >= 128 && !output.trim()) {
155
+ return { ok: false, unchecked: `exited ${result.status} with no output` };
156
+ }
157
+ return { ok: result.status === 0, output };
158
+ }
159
+ const isMissingModule = (err) => err?.code === 'MODULE_NOT_FOUND';
160
+ /**
161
+ * A Start app, in about a second: its route tree regenerated as `vite build`
162
+ * writes it, a tsgo typecheck, which reads that tree, then the source rules.
163
+ * Neither a build nor describe: the platform's build is where access is decided
164
+ * and enforced, and these only say early what it would refuse.
140
165
  */
141
166
  async function checkStartApp(reporter, app, appPath) {
142
- if (!reporter.step(app, 'vite build', run('npx', ['vite', 'build'], appPath)))
143
- return;
144
- // --pretty for `file:line:col - error` lines, the shape the platform re-roots.
145
- reporter.step(app, 'tsc --noEmit', run('npx', ['tsc', '--noEmit', '--pretty', '-p', 'tsconfig.app.json'], appPath));
146
- const { describedProblems } = await import('./start/describeRules.js');
147
- const { sourceProblems } = await import('./start/sourceRules.js');
167
+ const { regenerateRouteTree } = await import('./start/routeTree.js');
168
+ let routeTree = { ok: true };
148
169
  try {
149
- const { describeBuiltApp } = await import('../start/describeBuilt.js');
150
- const description = (await describeBuiltApp(appPath));
151
- const problems = describedProblems(description, { internal: isInternalApp(appPath) });
152
- reporter.step(app, 'describe', { ok: !problems.some(p => p.severity === 'error') });
153
- reporter.problems(app, problems);
170
+ await regenerateRouteTree(appPath);
154
171
  }
155
172
  catch (err) {
156
- reporter.step(app, 'describe', { ok: false, output: err instanceof Error ? err.message : String(err) });
173
+ const message = err instanceof Error ? err.message : String(err);
174
+ routeTree = isMissingModule(err)
175
+ ? { ok: false, unchecked: `the app's TanStack Start isn't installed: ${message}` }
176
+ : { ok: false, output: message };
177
+ }
178
+ if (reporter.step(app, 'route tree', routeTree)) {
179
+ const { findTsgo } = await import('./start/tsgo.js');
180
+ const tsgo = findTsgo(appPath);
181
+ reporter.step(app, 'tsgo --noEmit', !existsSync(join(appPath, 'tsconfig.app.json'))
182
+ ? { ok: false, output: `no ${join(appPath, 'tsconfig.app.json')}` }
183
+ : !tsgo
184
+ ? { ok: false, unchecked: "tsgo isn't installed (npm install -g @typescript/native-preview)" }
185
+ : // --pretty for `file:line:col - error` lines, the shape the platform re-roots. Two checkers, not
186
+ // four, hold half the type graph: a large app fits the sandbox's memory.
187
+ runTool(process.execPath, [tsgo, '--noEmit', '--pretty', '-p', 'tsconfig.app.json', '--checkers', '2'], appPath));
157
188
  }
158
- const hints = sourceProblems(readAppSources(appPath));
189
+ const { sourceProblems } = await import('./start/sourceRules.js');
190
+ const hints = sourceProblems(readAppSources(appPath), { internal: isInternalApp(appPath) });
159
191
  reporter.step(app, 'source', { ok: !hints.some(p => p.severity === 'error') });
160
192
  reporter.problems(app, hints);
161
193
  }
@@ -206,14 +238,18 @@ export async function runCheck(args = process.argv.slice(3)) {
206
238
  }
207
239
  };
208
240
  await (json ? withStdoutOnStderr(checkAll) : checkAll());
209
- const allPassed = reporter.apps.every(app => app.ok);
241
+ const failed = reporter.apps.some(app => !app.ok);
242
+ const unchecked = reporter.apps.some(app => app.unchecked);
210
243
  if (json) {
211
- process.stdout.write(`${JSON.stringify({ ok: allPassed, apps: reporter.apps })}\n`);
244
+ process.stdout.write(`${JSON.stringify({ ok: !failed && !unchecked, ...(unchecked && { unchecked: true }), apps: reporter.apps })}\n`);
212
245
  }
213
246
  else {
214
247
  console.log('');
215
- console.log(allPassed ? 'All apps pass.' : 'Some apps failed.');
248
+ console.log(failed ? 'Some apps failed.' : unchecked ? 'Some apps were not fully checked.' : 'All apps pass.');
216
249
  }
217
- if (!allPassed)
250
+ // 3: nothing to fix, but not everything ran.
251
+ if (failed)
218
252
  process.exit(1);
253
+ if (unchecked)
254
+ process.exit(3);
219
255
  }
@@ -0,0 +1,8 @@
1
+ /** Start's footer (start-plugin-core route-tree-footer), which types the router and start instance for `@tanstack/react-start`. */
2
+ export declare const startRouteTreeFooter: (generatedRouteTree: string, routerFile: string, startFile: string | undefined) => string[];
3
+ /**
4
+ * Regenerates the route tree with the router generator the app's own
5
+ * `@tanstack/react-start` builds with, configured as zitejs's Start plugin
6
+ * configures it, so the file is the one `vite build` writes, byte for byte.
7
+ */
8
+ 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
+ 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
+ }
@@ -1,3 +1,5 @@
1
1
  import type { Problem } from "./problem.js";
2
2
  /** Every source hint for one Start app, given its files by app-relative path. */
3
- export declare function sourceProblems(sources: Record<string, string>): Problem[];
3
+ export declare function sourceProblems(sources: Record<string, string>, { internal }?: {
4
+ internal?: boolean;
5
+ }): Problem[];