@kodycodes/cli 1.23.1 → 1.23.2

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 (39) hide show
  1. package/README.md +26 -0
  2. package/dist/dev/dev-bundler.d.ts +25 -0
  3. package/dist/dev/dev-bundler.js +51 -0
  4. package/dist/dev/dev-bundler.js.map +1 -0
  5. package/dist/dev/dev-events.d.ts +50 -0
  6. package/dist/dev/dev-events.js +81 -0
  7. package/dist/dev/dev-events.js.map +1 -0
  8. package/dist/dev/dev-protocol.d.ts +13 -0
  9. package/dist/dev/dev-protocol.js +14 -0
  10. package/dist/dev/dev-protocol.js.map +1 -0
  11. package/dist/dev/dev-watcher.d.ts +20 -0
  12. package/dist/dev/dev-watcher.js +108 -0
  13. package/dist/dev/dev-watcher.js.map +1 -0
  14. package/dist/dev/error-page.d.ts +21 -0
  15. package/dist/dev/error-page.js +64 -0
  16. package/dist/dev/error-page.js.map +1 -0
  17. package/dist/dev/process-reaper.d.ts +40 -0
  18. package/dist/dev/process-reaper.js +144 -0
  19. package/dist/dev/process-reaper.js.map +1 -0
  20. package/dist/dev/stack-trace.d.ts +11 -0
  21. package/dist/dev/stack-trace.js +56 -0
  22. package/dist/dev/stack-trace.js.map +1 -0
  23. package/dist/dev/workerd-process.d.ts +28 -0
  24. package/dist/dev/workerd-process.js +118 -0
  25. package/dist/dev/workerd-process.js.map +1 -0
  26. package/dist/dev-command.js +17 -4
  27. package/dist/dev-command.js.map +1 -1
  28. package/dist/help.js +5 -0
  29. package/dist/help.js.map +1 -1
  30. package/dist/local-bundle.d.ts +43 -3
  31. package/dist/local-bundle.js +94 -33
  32. package/dist/local-bundle.js.map +1 -1
  33. package/dist/package-app-dev.d.ts +16 -3
  34. package/dist/package-app-dev.js +389 -192
  35. package/dist/package-app-dev.js.map +1 -1
  36. package/dist/package-local-runtime-source.d.ts +8 -0
  37. package/dist/package-local-runtime-source.js +69 -5
  38. package/dist/package-local-runtime-source.js.map +1 -1
  39. package/package.json +3 -1
@@ -1,64 +1,125 @@
1
1
  import * as esbuild from 'esbuild';
2
- import { resolve } from 'node:path';
2
+ import { relative, resolve } from 'node:path';
3
+ /** Thrown when esbuild fails; `diagnostics` keeps the structured locations. */
4
+ export class BundleError extends Error {
5
+ diagnostics;
6
+ constructor(message, diagnostics) {
7
+ super(message);
8
+ this.name = 'BundleError';
9
+ this.diagnostics = diagnostics;
10
+ }
11
+ }
12
+ /**
13
+ * esbuild options shared by one-shot bundles and `kody dev` rebuilds: follow
14
+ * relative imports and npm packages, keep `kody:*` external for package-graph
15
+ * + runtime binding, and leave `node:*` external for workerd `nodejs_compat`.
16
+ */
17
+ export function localBundleOptions(entry) {
18
+ return {
19
+ absWorkingDir: process.cwd(),
20
+ entryPoints: [entry],
21
+ bundle: true,
22
+ write: false,
23
+ format: 'esm',
24
+ platform: 'neutral',
25
+ target: 'esnext',
26
+ logLevel: 'silent',
27
+ packages: 'bundle',
28
+ external: ['kody:*', 'node:*'],
29
+ };
30
+ }
3
31
  /**
4
32
  * Bundle a `--file` entry for local workerd the same way hosted execute /
5
- * publish resolves code: follow relative imports and npm packages, keep
6
- * `kody:*` external for package-graph + runtime binding, and leave `node:*`
7
- * external for workerd `nodejs_compat` (same as unbundled `--code`).
33
+ * publish resolves code.
8
34
  */
9
35
  export async function bundleLocalUserModule(modulePath) {
10
36
  const entry = resolve(modulePath);
11
37
  let result;
12
38
  try {
13
- result = await esbuild.build({
14
- absWorkingDir: process.cwd(),
15
- entryPoints: [entry],
16
- bundle: true,
17
- write: false,
18
- format: 'esm',
19
- platform: 'neutral',
20
- target: 'esnext',
21
- logLevel: 'silent',
22
- packages: 'bundle',
23
- external: ['kody:*', 'node:*'],
24
- });
39
+ result = await esbuild.build(localBundleOptions(entry));
25
40
  }
26
41
  catch (error) {
27
- throw new Error(formatBundleError(modulePath, error));
42
+ throw createBundleError(modulePath, error);
28
43
  }
29
44
  const output = result.outputFiles?.[0];
30
45
  if (output === undefined) {
31
- throw new Error(`Could not bundle ${modulePath} for local execute: esbuild produced no output.`);
46
+ throw new BundleError(`Could not bundle ${modulePath}: esbuild produced no output.`, []);
32
47
  }
33
48
  if (result.errors.length > 0) {
34
- throw new Error(formatBundleError(modulePath, { errors: result.errors }));
49
+ throw createBundleError(modulePath, { errors: result.errors });
35
50
  }
36
51
  return output.text;
37
52
  }
38
- function formatBundleError(modulePath, error) {
39
- const details = bundleErrorDetails(error);
40
- const header = `Could not bundle ${modulePath} for local execute.`;
53
+ /**
54
+ * `workingDir` is esbuild's `absWorkingDir` (locations are relative to it);
55
+ * `displayRoot` is what reported paths are relative to.
56
+ */
57
+ export function createBundleError(modulePath, error, paths = {
58
+ workingDir: process.cwd(),
59
+ displayRoot: process.cwd(),
60
+ }) {
61
+ const diagnostics = bundleDiagnostics(error, paths);
62
+ const details = diagnostics.map(formatBundleDiagnostic).join('\n');
63
+ const header = `Could not bundle ${modulePath}.`;
41
64
  const body = details.length > 0 ? `${header}\n${details}` : header;
65
+ const messages = diagnostics.map((item) => item.message).join('\n');
42
66
  // Only when the unresolved specifier itself is kody:@ (not a path that happens
43
67
  // to contain that substring).
44
- if (/Could not resolve ["']kody:@/i.test(details)) {
45
- return `${body}\nfix: Map the dependency in .kody/deps.json (or package.json#kody.localDeps), keep it in this package's exports, or log in so published package-graph can supply it.`;
68
+ if (/Could not resolve ["']kody:@/i.test(messages)) {
69
+ return new BundleError(`${body}\nfix: Map the dependency in .kody/deps.json (or package.json#kody.localDeps), keep it in this package's exports, or log in so published package-graph can supply it.`, diagnostics);
46
70
  }
47
71
  if (/Could not resolve|Cannot find module|ENOENT/i.test(body)) {
48
- return `${body}\nfix: Run \`npm install\` in the package directory (and any local deps), then retry.`;
72
+ return new BundleError(`${body}\nfix: Run \`npm install\` in the package directory (and any local deps), then retry.`, diagnostics);
49
73
  }
50
- return body;
74
+ return new BundleError(body, diagnostics);
75
+ }
76
+ /** `file:line:col: message` followed by an indented code frame. */
77
+ export function formatBundleDiagnostic(item) {
78
+ const where = item.file !== null
79
+ ? `${item.file}${item.line !== null ? `:${item.line}` : ''}${item.col !== null ? `:${item.col}` : ''}: `
80
+ : '';
81
+ return `${where}${item.message}${item.frame ? `\n${item.frame}` : ''}`;
51
82
  }
52
- function bundleErrorDetails(error) {
83
+ function bundleDiagnostics(error, paths) {
53
84
  if (isEsbuildFailure(error)) {
54
85
  return error.errors
55
- .map((item) => item.text.trim())
56
- .filter((text) => text.length > 0)
57
- .join('\n');
86
+ .filter((item) => item.text.trim().length > 0)
87
+ .map((item) => toDiagnostic(item, paths));
58
88
  }
59
- if (error instanceof Error)
60
- return error.message;
61
- return String(error);
89
+ return [
90
+ {
91
+ file: null,
92
+ line: null,
93
+ col: null,
94
+ message: error instanceof Error ? error.message : String(error),
95
+ frame: null,
96
+ },
97
+ ];
98
+ }
99
+ function toDiagnostic(item, paths) {
100
+ const location = item.location;
101
+ if (!location) {
102
+ return { file: null, line: null, col: null, message: item.text.trim(), frame: null };
103
+ }
104
+ const absolute = resolve(paths.workingDir, location.file);
105
+ const fromRoot = relative(paths.displayRoot, absolute);
106
+ const file = fromRoot && !fromRoot.startsWith('..') ? fromRoot : absolute;
107
+ return {
108
+ file,
109
+ line: location.line,
110
+ col: location.column + 1,
111
+ message: item.text.trim(),
112
+ frame: codeFrame(location),
113
+ };
114
+ }
115
+ function codeFrame(location) {
116
+ if (!location.lineText)
117
+ return null;
118
+ const gutter = String(location.line);
119
+ const pad = ' '.repeat(gutter.length);
120
+ const caretWidth = Math.max(1, Math.min(location.length || 1, location.lineText.length));
121
+ return (` ${gutter} | ${location.lineText}\n` +
122
+ ` ${pad} | ${' '.repeat(location.column)}${'^'.repeat(caretWidth)}`);
62
123
  }
63
124
  function isEsbuildFailure(error) {
64
125
  return (typeof error === 'object' &&
@@ -1 +1 @@
1
- {"version":3,"file":"local-bundle.js","sourceRoot":"","sources":["../src/local-bundle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAA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,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAA;IACxF,OAAO,CACN,KAAK,MAAM,MAAM,QAAQ,CAAC,QAAQ,IAAI;QACtC,KAAK,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CACpE,CAAA;AACF,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc;IACvC,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,QAAQ,IAAI,KAAK;QACjB,KAAK,CAAC,OAAO,CAAE,KAA6B,CAAC,MAAM,CAAC,CACpD,CAAA;AACF,CAAC"}
@@ -1,8 +1,14 @@
1
1
  /**
2
2
  * Long-running `kody dev` app server: bundles `kody.app.entry` the same way
3
- * local-bundle/publish does for esbuild, serves via workerd, strips the mount
4
- * at the Node proxy, and rebuilds on file changes.
3
+ * local-bundle/publish does for esbuild, serves via workerd behind a Node
4
+ * proxy that strips the mount, and rebuilds on file changes.
5
+ *
6
+ * Each successful rebuild starts a new workerd "generation" and only swaps the
7
+ * proxy over once it is listening; the previous generation drains in-flight
8
+ * requests and is then stopped. Requests that arrive mid-rebuild wait for it,
9
+ * so a save is never answered by a 503 or a stale bundle.
5
10
  */
11
+ import { type DevEvent } from './dev/dev-events.js';
6
12
  import { type PackageLocalContext } from './package-local-runtime-source.js';
7
13
  import type { KodyPackageManifest } from './package-manifest.js';
8
14
  import type { KodyTarget } from './target.js';
@@ -35,10 +41,17 @@ export type PackageAppDevOptions = {
35
41
  passthroughHosts?: ReadonlyArray<string>;
36
42
  workerdPath?: string;
37
43
  fetchFn?: typeof fetch;
38
- /** Hot reload via fs.watch (default true). One-shot `dev fetch` turns this off. */
44
+ /**
45
+ * Rebuild on file changes (default true). One-shot `dev fetch` turns this
46
+ * off, which also makes an initial build failure throw.
47
+ */
39
48
  watch?: boolean;
49
+ /** Quiet period after the last file event before rebuilding. */
50
+ debounceMs?: number;
40
51
  onStatus?: (message: string) => void;
41
52
  onError?: (message: string) => void;
53
+ /** Rebuilds, build/runtime errors, and app logs. */
54
+ onEvent?: (event: DevEvent) => void;
42
55
  };
43
56
  export type PackageAppDevServer = {
44
57
  url: string;