@incajs/cli 0.0.4 → 0.0.6

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/README.md CHANGED
@@ -23,7 +23,10 @@ bootstrapping; it wins outright when both exist.
23
23
  ## Commands
24
24
 
25
25
  - **`inca dev`** — watches your app and opens a live-reloading window,
26
- reloading on every change.
26
+ reloading on every change. `--experimental-hmr` (or
27
+ `INCA_EXPERIMENTAL_HMR=1`) opts into experimental, module-granular
28
+ hot reloading instead — see the
29
+ [HMR guide](https://tom96da.github.io/incajs/guide/hmr).
27
30
  - **`inca build`** — bundles your app for production, once, with no
28
31
  window opened.
29
32
  - **`inca package`** — builds your app, then packages it with a
@@ -57,11 +60,13 @@ once it is packaged.
57
60
 
58
61
  ## Requirements
59
62
 
60
- `inca`'s host binary is pulled in automatically as a platform-specific
61
- optional dependency (Linux and macOS on x64/arm64; Windows isn't
62
- supported yet) — neither Cargo nor Rust are needed. Set `INCA_HOST_BIN`
63
- to use a specific binary instead, e.g. on a platform with no published
64
- one yet, or a custom build.
63
+ A prebuilt binary is pulled in automatically as a platform-specific
64
+ optional dependency — neither Cargo nor Rust are needed. See
65
+ [Host binary](https://tom96da.github.io/incajs/guide/#host-binary) for
66
+ per-platform support.
67
+
68
+ Set `INCA_HOST_BIN` to use a specific binary instead, e.g. on a
69
+ platform with no published one yet, or a custom build.
65
70
 
66
71
  ## How it works
67
72
 
@@ -3,38 +3,6 @@ export interface Watcher {
3
3
  /** Stops watching and releases the underlying build process. */
4
4
  close(): Promise<void>;
5
5
  }
6
- /** Options for {@link Bundler.watch}. */
7
- export interface BundlerOptions {
8
- /** The app's own entry point — may import `.vue` files. */
9
- entry: string;
10
- /** Where the build's output is written. */
11
- outDir: string;
12
- /**
13
- * Values the built app carries for `inca-host` to read — its name, id
14
- * and window. Any JSON-serializable object.
15
- */
16
- runtimeConfig?: unknown;
17
- /** `"development"` keeps a framework's own warnings; `"production"` strips them. */
18
- mode: "development" | "production";
19
- /** Called after each successful (re)build, with what it wrote. */
20
- onBuild: (output: BuildOutput) => void;
21
- /** Called instead of `onBuild` when a (re)build fails. */
22
- onError: (error: {
23
- message: string;
24
- stack: string | null;
25
- code?: string | null;
26
- }) => void;
27
- /** Where the bundler's own output goes. Defaults to `process.stdout`. */
28
- stdout?: NodeJS.WritableStream;
29
- /** Where the bundler's warnings and errors go. Defaults to `process.stderr`. */
30
- stderr?: NodeJS.WritableStream;
31
- /**
32
- * Drops the bundler's progress output and size report, leaving the
33
- * per-build summary. Set it when the build has to stay silent: part of
34
- * that output goes to the process's own stdout, not to `stdout` above.
35
- */
36
- quiet?: boolean;
37
- }
38
6
  /** Options for {@link Bundler.build}. */
39
7
  export interface BuildOptions {
40
8
  /** The app's own entry point — may import `.vue` files. */
@@ -57,6 +25,19 @@ export interface BuildOptions {
57
25
  */
58
26
  quiet?: boolean;
59
27
  }
28
+ /** Options for {@link Bundler.watch}. */
29
+ export interface BundlerOptions extends BuildOptions {
30
+ /** `"development"` keeps a framework's own warnings; `"production"` strips them. */
31
+ mode: "development" | "production";
32
+ /** Called after each successful (re)build, with what it wrote. */
33
+ onBuild: (output: BuildOutput) => void;
34
+ /** Called instead of `onBuild` when a (re)build fails. */
35
+ onError: (error: {
36
+ message: string;
37
+ stack: string | null;
38
+ code?: string | null;
39
+ }) => void;
40
+ }
60
41
  /** What a build wrote — the result of {@link Bundler.build}, and every {@link BundlerOptions.onBuild} call. */
61
42
  export interface BuildOutput {
62
43
  /** Directory holding every file this build emitted. */
@@ -71,6 +52,59 @@ export interface BuildOutput {
71
52
  at: number;
72
53
  };
73
54
  }
55
+ /**
56
+ * A failed HMR update's detail — the same fields a Rollup/Vite plugin
57
+ * error carries beyond `message`/`stack`, when it has them.
58
+ */
59
+ export interface UpdateError {
60
+ message: string;
61
+ stack?: string | null;
62
+ plugin?: string | null;
63
+ id?: string | null;
64
+ frame?: string | null;
65
+ loc?: {
66
+ line: number;
67
+ column: number;
68
+ } | null;
69
+ }
70
+ /** Options for {@link Bundler.hmr}. */
71
+ export interface HmrOptions {
72
+ /** The app's own entry point — may import `.vue` files. */
73
+ entry: string;
74
+ /** The app's root directory — where its dev-only scratch files are written. */
75
+ cwd: string;
76
+ /**
77
+ * Values the built app carries for `inca-host` to read — its name, id
78
+ * and window. Any JSON-serializable object.
79
+ */
80
+ runtimeConfig?: unknown;
81
+ /** Overrides where the synthesized entry imports `hmr-runtime.js` from. Test-only. */
82
+ runtimePath?: string;
83
+ /** Where the bundler's own output goes. Defaults to `process.stdout`. */
84
+ stdout?: NodeJS.WritableStream;
85
+ /** Where the bundler's warnings and errors go. Defaults to `process.stderr`. */
86
+ stderr?: NodeJS.WritableStream;
87
+ /** Drops per-update/reload logging; warnings and errors still surface. */
88
+ quiet?: boolean;
89
+ /** Delivers a bundler payload to the running app over the dev channel. */
90
+ notify: (payload: unknown) => void;
91
+ /** Called in place of forwarding a whole-app reload payload to the app. */
92
+ reload: () => void;
93
+ /** Called when an update the app fetched failed to compile. */
94
+ onError: (error: UpdateError) => void;
95
+ /** Called after a successful update, with the file that changed and how long it took. */
96
+ onUpdate?: (info: {
97
+ file: string;
98
+ took: number;
99
+ }) => void;
100
+ }
101
+ /** A running HMR session — the value {@link Bundler.hmr} resolves to. */
102
+ export interface HmrChannel extends Watcher {
103
+ /** The synthesized entry `inca-host` evaluates for this session. */
104
+ entryFile: string;
105
+ /** Feeds a payload the running app sent back into the bundler's dev server. */
106
+ dispatch: (payload: unknown) => void;
107
+ }
74
108
  /**
75
109
  * The contract a bundler adapter satisfies. Supporting another bundler
76
110
  * means adding a sibling adapter module and injecting its `Bundler` here —
@@ -80,4 +114,9 @@ export interface Bundler {
80
114
  watch(options: BundlerOptions): Promise<Watcher>;
81
115
  /** One-shot production build, used by `inca build` — rejects on failure. */
82
116
  build(options: BuildOptions): Promise<BuildOutput>;
117
+ /**
118
+ * Module-granular dev updates, used by `inca dev --experimental-hmr`.
119
+ * Optional — a bundler adapter with no HMR support simply omits it.
120
+ */
121
+ hmr?(options: HmrOptions): Promise<HmrChannel>;
83
122
  }
@@ -1,5 +1,4 @@
1
1
  import { BuildOptions, BuildOutput } from '../types.mts';
2
- export type { BuildOptions, BuildOutput } from '../types.mts';
3
2
  /**
4
3
  * Builds `entry` into a minified, production build under `outDir` once, and
5
4
  * rejects on failure rather than reporting it through a callback. Never
@@ -1,4 +1,5 @@
1
1
  import { Plugin } from 'vite';
2
+ import { BuildOutput } from '../types.mts';
2
3
  /** What one (re)build actually wrote, relative to its own `outDir`. */
3
4
  export interface CapturedOutput {
4
5
  /** The emitted chunk marked as this build's entry. */
@@ -6,6 +7,8 @@ export interface CapturedOutput {
6
7
  /** Every emitted file, as the bundler reported it. */
7
8
  files: readonly string[];
8
9
  }
10
+ /** Resolves `captured`'s paths against `outDir` into a {@link BuildOutput}. */
11
+ export declare function toBuildOutput(outDir: string, captured: CapturedOutput, changed?: BuildOutput["changed"]): BuildOutput;
9
12
  /**
10
13
  * A Vite plugin reporting `sink` the files a build wrote once they land on
11
14
  * disk, via `writeBundle` — the one hook that fires uniformly for a
@@ -1,6 +1,12 @@
1
1
  import { Plugin } from 'vite';
2
2
  /** The file a build writes its app's config to, beside the entry. */
3
3
  export declare const CONFIG_FILE_NAME = "inca.json";
4
+ /**
5
+ * Serializes `config` the way `inca.json` is written: `undefined` for
6
+ * anything that shouldn't produce a file — `undefined` itself, or an
7
+ * object with no keys.
8
+ */
9
+ export declare function serializeConfig(config: unknown): string | undefined;
4
10
  /**
5
11
  * Writes `config` to `inca.json` beside the entry, for `inca-host` to read
6
12
  * when it starts the app.
@@ -0,0 +1,7 @@
1
+ import { HmrChannel, HmrOptions } from '../types.mts';
2
+ /**
3
+ * Starts a Vite dev server driving the app over its dev channel instead of
4
+ * a browser: a `"client"` environment with a custom {@link HotChannel}
5
+ * standing in for the WebSocket server `server.ws: false` disables.
6
+ */
7
+ export declare function hmr({ entry, cwd, runtimeConfig, runtimePath, stdout, stderr, quiet, notify, reload, onError, onUpdate, }: HmrOptions): Promise<HmrChannel>;
@@ -1,2 +1,3 @@
1
1
  export { build } from './build.mts';
2
+ export { hmr } from './hmr.mts';
2
3
  export { watch } from './watch.mts';
@@ -1,7 +1,8 @@
1
1
  import { Logger } from 'vite';
2
2
  /**
3
3
  * A Vite {@link Logger} writing to the given streams: `info` to `stdout`,
4
- * `warn` and `error` to `stderr`. Messages arrive fully formatted and are
5
- * written as they are; Vite's own `LogOptions` are ignored.
4
+ * `warn`/`error` to `stderr`, all unfiltered by Vite's own `LogOptions` — a
5
+ * custom logger bypasses those. `quiet` drops `info` only; `warn`/`error`
6
+ * still write, since they report something broken, not just what changed.
6
7
  */
7
- export declare function streamLogger(stdout: NodeJS.WritableStream, stderr: NodeJS.WritableStream): Logger;
8
+ export declare function streamLogger(stdout: NodeJS.WritableStream, stderr: NodeJS.WritableStream, quiet?: boolean): Logger;
@@ -1,5 +1,4 @@
1
1
  import { BundlerOptions, Watcher } from '../types.mts';
2
- export type { Watcher } from '../types.mts';
3
2
  /**
4
3
  * Builds `entry` into a build under `outDir` and rebuilds it on every
5
4
  * change, calling `onBuild` with what each rebuild wrote. Never starts,