@ic-reactor/vite-plugin 0.14.0 → 4.0.0-beta.1

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/index.d.cts CHANGED
@@ -1,38 +1,67 @@
1
1
  import { Plugin } from 'vite';
2
- import { CanisterConfig, CodegenTarget } from '@ic-reactor/codegen';
3
2
 
4
3
  /**
5
4
  * @ic-reactor/vite-plugin
6
5
  *
7
- * Vite plugin that:
8
- * 1. Generates hooks at build time (using @ic-reactor/codegen pipeline)
9
- * 2. Injects `ic_env` cookie for local development (via proxy)
10
- * 3. Hot-reloads when .did files change
6
+ * Vite plugin for an app built on a candid-core generated module.
7
+ *
8
+ * - Generation: at the start of a build or dev server, and when a `.did` file
9
+ * changes, it runs `candid-core-cli gen` in a child process (see
10
+ * generate.ts) and leaves candid-core's module as the generator wrote it. No
11
+ * wrapper files, hooks or reactors are generated.
12
+ * - Environment: under `vite dev` and `vite preview` it sets the `ic_env`
13
+ * cookie and proxies `/api` to the local IC network (see dev-environment.ts).
11
14
  */
12
15
 
16
+ /**
17
+ * The options of {@link icReactor}. Every one is optional: with none, the
18
+ * plugin generates nothing and, under `vite dev`, only injects the local IC
19
+ * environment, for no canister of the app's.
20
+ */
13
21
  interface IcReactorPluginOptions {
14
22
  /**
15
- * Canister configurations.
16
- * `name` is required for each canister.
17
- */
18
- canisters: CanisterConfig[];
19
- /**
20
- * Default output directory (relative to the Vite project root).
21
- * Default: "src/declarations"
22
- */
23
- outDir?: string;
24
- /**
25
- * Default client manager import path.
26
- * Default: "../../clients"
27
- */
28
- clientManagerPath?: string;
29
- /**
30
- * Default generated runtime target.
31
- * Default: "react"
23
+ * The app's canisters, by name: the canister's name in the `icp` project,
24
+ * which is also the name the `ic_env` cookie carries its ID under.
25
+ *
26
+ * - `didFile`: the canister's Candid interface, relative to the Vite root.
27
+ * The plugin runs `candid-core-cli gen` on it at the start of a build or
28
+ * dev server and again each time the file changes, regenerating only the
29
+ * canisters that name the file that changed. The generator names its
30
+ * output after the file, so `didFile: "../backend/ledger.did"` writes `ledger.ts` (the
31
+ * module: it exports `actor` and the type `Actor`) and
32
+ * `ledger.envelope.json` into `outDir`. Canisters that name the same
33
+ * `didFile` and `outDir` share that one module, which is generated once.
34
+ * Different `.did` files that would write the same module are refused:
35
+ * give one an `outDir` of its own. A canister without a `didFile`
36
+ * generates nothing and is only named in the cookie.
37
+ * - `outDir`: where the generator writes, relative to the Vite root.
38
+ * Default: `"src/canisters"`.
39
+ * - `canisterId`: a fixed ID for the cookie, which wins over the ID `icp`
40
+ * reports for the canister.
41
+ *
42
+ * The generator is the `@candid-core/cli` the app has installed, run as a
43
+ * child process so that a failure on one `.did` stops that process and not
44
+ * the dev server.
32
45
  */
33
- target?: CodegenTarget;
46
+ canisters?: Record<string, {
47
+ didFile?: string;
48
+ outDir?: string;
49
+ canisterId?: string;
50
+ }>;
34
51
  /**
35
- * Automatically inject `ic_env` cookie for local development?
52
+ * Inject the local IC environment under `vite dev` and `vite preview`: set
53
+ * the `ic_env` cookie on each response and proxy `/api` to the network the
54
+ * `icp` CLI reports.
55
+ *
56
+ * Until `icp` reports a network and every configured canister has an ID
57
+ * (a configured `canisterId` counts), each page load asks `icp` again, so a
58
+ * deploy after the server started needs only a reload. Once detection is
59
+ * complete, page loads run no `icp` command, and a redeploy into a fresh
60
+ * network needs a restart. An `/api` proxy that the Vite config or another
61
+ * plugin sets is left alone.
62
+ *
63
+ * Never injected in mode `"test"` (Vitest's), where `icp` is not run at all.
64
+ *
36
65
  * Default: true
37
66
  */
38
67
  injectEnvironment?: boolean;
@@ -40,13 +69,54 @@ interface IcReactorPluginOptions {
40
69
  * Abort the Vite run when a canister fails to generate.
41
70
  *
42
71
  * Default: `true` under `vite build`, `false` under `vite dev`. A build that
43
- * silently ships the bindings left over from the last successful run is worse
44
- * than no build at all, while a dev server has to survive the broken
45
- * intermediate states of a `.did` file being edited — there the failure is
46
- * reported to the terminal and the browser error overlay instead.
72
+ * silently ships the bindings left over from the last successful run is
73
+ * worse than no build at all, while a dev server has to survive the broken
74
+ * intermediate states of a `.did` file being edited: there the failure is
75
+ * logged and shown in the browser's error overlay, and the server keeps
76
+ * serving.
47
77
  */
48
78
  failOnError?: boolean;
49
79
  }
50
- declare function icReactor(options: IcReactorPluginOptions): Plugin;
80
+ /**
81
+ * The Vite plugin for an app built on a candid-core generated module.
82
+ *
83
+ * It does two things:
84
+ *
85
+ * - **Generates the module.** When a build or the dev server starts, and
86
+ * when a configured `.did` changes, it runs the app's `candid-core-cli gen`
87
+ * on each `didFile` and leaves the module as the generator wrote it: no
88
+ * wrapper files, hooks or reactors. The generator is WebAssembly, so it runs
89
+ * in a child process (the running Node binary on the CLI's bin script, never
90
+ * through a shell, killed after 60 seconds). A trap, a crash or a hang on a
91
+ * bad `.did` then ends that process and not the dev server: under
92
+ * `vite build` it fails the build with the CLI's own message, and under
93
+ * `vite dev` it is logged and shown in the error overlay while the server
94
+ * keeps serving. See {@link IcReactorPluginOptions.failOnError}.
95
+ * - **Injects the local IC environment.** Under `vite dev` and `vite preview`
96
+ * it sets the `ic_env` cookie, which carries the replica's root key and the
97
+ * canister IDs, and proxies `/api` to the local replica, so the app needs no
98
+ * configuration to find them. It asks the `icp` CLI for both, and is off in
99
+ * mode `"test"` (Vitest's), where `icp` is never run.
100
+ *
101
+ * The first thing it logs names where an agent reads how to use the library:
102
+ * `ic-reactor: agent guide at node_modules/@ic-reactor/core/llms.txt`.
103
+ *
104
+ * The plugin needs `@candid-core/cli`, at the exact release that pairs with
105
+ * the `@candid-core/schema` the generated modules import, installed in the
106
+ * app. It imports neither, and no `@ic-reactor` runtime package.
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * // vite.config.ts
111
+ * export default defineConfig({
112
+ * plugins: [
113
+ * icReactor({
114
+ * canisters: { ledger: { didFile: "../backend/ledger.did" } },
115
+ * }),
116
+ * ],
117
+ * })
118
+ * ```
119
+ */
120
+ declare function icReactor(options?: IcReactorPluginOptions): Plugin;
51
121
 
52
122
  export { type IcReactorPluginOptions, icReactor };
package/dist/index.d.ts CHANGED
@@ -1,38 +1,67 @@
1
1
  import { Plugin } from 'vite';
2
- import { CanisterConfig, CodegenTarget } from '@ic-reactor/codegen';
3
2
 
4
3
  /**
5
4
  * @ic-reactor/vite-plugin
6
5
  *
7
- * Vite plugin that:
8
- * 1. Generates hooks at build time (using @ic-reactor/codegen pipeline)
9
- * 2. Injects `ic_env` cookie for local development (via proxy)
10
- * 3. Hot-reloads when .did files change
6
+ * Vite plugin for an app built on a candid-core generated module.
7
+ *
8
+ * - Generation: at the start of a build or dev server, and when a `.did` file
9
+ * changes, it runs `candid-core-cli gen` in a child process (see
10
+ * generate.ts) and leaves candid-core's module as the generator wrote it. No
11
+ * wrapper files, hooks or reactors are generated.
12
+ * - Environment: under `vite dev` and `vite preview` it sets the `ic_env`
13
+ * cookie and proxies `/api` to the local IC network (see dev-environment.ts).
11
14
  */
12
15
 
16
+ /**
17
+ * The options of {@link icReactor}. Every one is optional: with none, the
18
+ * plugin generates nothing and, under `vite dev`, only injects the local IC
19
+ * environment, for no canister of the app's.
20
+ */
13
21
  interface IcReactorPluginOptions {
14
22
  /**
15
- * Canister configurations.
16
- * `name` is required for each canister.
17
- */
18
- canisters: CanisterConfig[];
19
- /**
20
- * Default output directory (relative to the Vite project root).
21
- * Default: "src/declarations"
22
- */
23
- outDir?: string;
24
- /**
25
- * Default client manager import path.
26
- * Default: "../../clients"
27
- */
28
- clientManagerPath?: string;
29
- /**
30
- * Default generated runtime target.
31
- * Default: "react"
23
+ * The app's canisters, by name: the canister's name in the `icp` project,
24
+ * which is also the name the `ic_env` cookie carries its ID under.
25
+ *
26
+ * - `didFile`: the canister's Candid interface, relative to the Vite root.
27
+ * The plugin runs `candid-core-cli gen` on it at the start of a build or
28
+ * dev server and again each time the file changes, regenerating only the
29
+ * canisters that name the file that changed. The generator names its
30
+ * output after the file, so `didFile: "../backend/ledger.did"` writes `ledger.ts` (the
31
+ * module: it exports `actor` and the type `Actor`) and
32
+ * `ledger.envelope.json` into `outDir`. Canisters that name the same
33
+ * `didFile` and `outDir` share that one module, which is generated once.
34
+ * Different `.did` files that would write the same module are refused:
35
+ * give one an `outDir` of its own. A canister without a `didFile`
36
+ * generates nothing and is only named in the cookie.
37
+ * - `outDir`: where the generator writes, relative to the Vite root.
38
+ * Default: `"src/canisters"`.
39
+ * - `canisterId`: a fixed ID for the cookie, which wins over the ID `icp`
40
+ * reports for the canister.
41
+ *
42
+ * The generator is the `@candid-core/cli` the app has installed, run as a
43
+ * child process so that a failure on one `.did` stops that process and not
44
+ * the dev server.
32
45
  */
33
- target?: CodegenTarget;
46
+ canisters?: Record<string, {
47
+ didFile?: string;
48
+ outDir?: string;
49
+ canisterId?: string;
50
+ }>;
34
51
  /**
35
- * Automatically inject `ic_env` cookie for local development?
52
+ * Inject the local IC environment under `vite dev` and `vite preview`: set
53
+ * the `ic_env` cookie on each response and proxy `/api` to the network the
54
+ * `icp` CLI reports.
55
+ *
56
+ * Until `icp` reports a network and every configured canister has an ID
57
+ * (a configured `canisterId` counts), each page load asks `icp` again, so a
58
+ * deploy after the server started needs only a reload. Once detection is
59
+ * complete, page loads run no `icp` command, and a redeploy into a fresh
60
+ * network needs a restart. An `/api` proxy that the Vite config or another
61
+ * plugin sets is left alone.
62
+ *
63
+ * Never injected in mode `"test"` (Vitest's), where `icp` is not run at all.
64
+ *
36
65
  * Default: true
37
66
  */
38
67
  injectEnvironment?: boolean;
@@ -40,13 +69,54 @@ interface IcReactorPluginOptions {
40
69
  * Abort the Vite run when a canister fails to generate.
41
70
  *
42
71
  * Default: `true` under `vite build`, `false` under `vite dev`. A build that
43
- * silently ships the bindings left over from the last successful run is worse
44
- * than no build at all, while a dev server has to survive the broken
45
- * intermediate states of a `.did` file being edited — there the failure is
46
- * reported to the terminal and the browser error overlay instead.
72
+ * silently ships the bindings left over from the last successful run is
73
+ * worse than no build at all, while a dev server has to survive the broken
74
+ * intermediate states of a `.did` file being edited: there the failure is
75
+ * logged and shown in the browser's error overlay, and the server keeps
76
+ * serving.
47
77
  */
48
78
  failOnError?: boolean;
49
79
  }
50
- declare function icReactor(options: IcReactorPluginOptions): Plugin;
80
+ /**
81
+ * The Vite plugin for an app built on a candid-core generated module.
82
+ *
83
+ * It does two things:
84
+ *
85
+ * - **Generates the module.** When a build or the dev server starts, and
86
+ * when a configured `.did` changes, it runs the app's `candid-core-cli gen`
87
+ * on each `didFile` and leaves the module as the generator wrote it: no
88
+ * wrapper files, hooks or reactors. The generator is WebAssembly, so it runs
89
+ * in a child process (the running Node binary on the CLI's bin script, never
90
+ * through a shell, killed after 60 seconds). A trap, a crash or a hang on a
91
+ * bad `.did` then ends that process and not the dev server: under
92
+ * `vite build` it fails the build with the CLI's own message, and under
93
+ * `vite dev` it is logged and shown in the error overlay while the server
94
+ * keeps serving. See {@link IcReactorPluginOptions.failOnError}.
95
+ * - **Injects the local IC environment.** Under `vite dev` and `vite preview`
96
+ * it sets the `ic_env` cookie, which carries the replica's root key and the
97
+ * canister IDs, and proxies `/api` to the local replica, so the app needs no
98
+ * configuration to find them. It asks the `icp` CLI for both, and is off in
99
+ * mode `"test"` (Vitest's), where `icp` is never run.
100
+ *
101
+ * The first thing it logs names where an agent reads how to use the library:
102
+ * `ic-reactor: agent guide at node_modules/@ic-reactor/core/llms.txt`.
103
+ *
104
+ * The plugin needs `@candid-core/cli`, at the exact release that pairs with
105
+ * the `@candid-core/schema` the generated modules import, installed in the
106
+ * app. It imports neither, and no `@ic-reactor` runtime package.
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * // vite.config.ts
111
+ * export default defineConfig({
112
+ * plugins: [
113
+ * icReactor({
114
+ * canisters: { ledger: { didFile: "../backend/ledger.did" } },
115
+ * }),
116
+ * ],
117
+ * })
118
+ * ```
119
+ */
120
+ declare function icReactor(options?: IcReactorPluginOptions): Plugin;
51
121
 
52
122
  export { type IcReactorPluginOptions, icReactor };