@ic-reactor/vite-plugin 0.15.1 → 4.0.0-beta.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.
- package/README.md +141 -173
- package/dist/index.cjs +534 -207
- package/dist/index.d.cts +88 -30
- package/dist/index.d.ts +88 -30
- package/dist/index.js +534 -211
- package/package.json +6 -8
- package/src/generate.ts +594 -0
- package/src/index.ts +456 -430
- package/llms.txt +0 -156
package/dist/index.d.cts
CHANGED
|
@@ -1,38 +1,53 @@
|
|
|
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
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
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
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*
|
|
33
|
-
*
|
|
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.
|
|
34
45
|
*/
|
|
35
|
-
|
|
46
|
+
canisters?: Record<string, {
|
|
47
|
+
didFile?: string;
|
|
48
|
+
outDir?: string;
|
|
49
|
+
canisterId?: string;
|
|
50
|
+
}>;
|
|
36
51
|
/**
|
|
37
52
|
* Inject the local IC environment under `vite dev` and `vite preview`: set
|
|
38
53
|
* the `ic_env` cookie on each response and proxy `/api` to the network the
|
|
@@ -45,6 +60,8 @@ interface IcReactorPluginOptions {
|
|
|
45
60
|
* network needs a restart. An `/api` proxy that the Vite config or another
|
|
46
61
|
* plugin sets is left alone.
|
|
47
62
|
*
|
|
63
|
+
* Never injected in mode `"test"` (Vitest's), where `icp` is not run at all.
|
|
64
|
+
*
|
|
48
65
|
* Default: true
|
|
49
66
|
*/
|
|
50
67
|
injectEnvironment?: boolean;
|
|
@@ -52,13 +69,54 @@ interface IcReactorPluginOptions {
|
|
|
52
69
|
* Abort the Vite run when a canister fails to generate.
|
|
53
70
|
*
|
|
54
71
|
* Default: `true` under `vite build`, `false` under `vite dev`. A build that
|
|
55
|
-
* silently ships the bindings left over from the last successful run is
|
|
56
|
-
* than no build at all, while a dev server has to survive the broken
|
|
57
|
-
* intermediate states of a `.did` file being edited
|
|
58
|
-
*
|
|
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.
|
|
59
77
|
*/
|
|
60
78
|
failOnError?: boolean;
|
|
61
79
|
}
|
|
62
|
-
|
|
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;
|
|
63
121
|
|
|
64
122
|
export { type IcReactorPluginOptions, icReactor };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,38 +1,53 @@
|
|
|
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
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
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
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*
|
|
33
|
-
*
|
|
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.
|
|
34
45
|
*/
|
|
35
|
-
|
|
46
|
+
canisters?: Record<string, {
|
|
47
|
+
didFile?: string;
|
|
48
|
+
outDir?: string;
|
|
49
|
+
canisterId?: string;
|
|
50
|
+
}>;
|
|
36
51
|
/**
|
|
37
52
|
* Inject the local IC environment under `vite dev` and `vite preview`: set
|
|
38
53
|
* the `ic_env` cookie on each response and proxy `/api` to the network the
|
|
@@ -45,6 +60,8 @@ interface IcReactorPluginOptions {
|
|
|
45
60
|
* network needs a restart. An `/api` proxy that the Vite config or another
|
|
46
61
|
* plugin sets is left alone.
|
|
47
62
|
*
|
|
63
|
+
* Never injected in mode `"test"` (Vitest's), where `icp` is not run at all.
|
|
64
|
+
*
|
|
48
65
|
* Default: true
|
|
49
66
|
*/
|
|
50
67
|
injectEnvironment?: boolean;
|
|
@@ -52,13 +69,54 @@ interface IcReactorPluginOptions {
|
|
|
52
69
|
* Abort the Vite run when a canister fails to generate.
|
|
53
70
|
*
|
|
54
71
|
* Default: `true` under `vite build`, `false` under `vite dev`. A build that
|
|
55
|
-
* silently ships the bindings left over from the last successful run is
|
|
56
|
-
* than no build at all, while a dev server has to survive the broken
|
|
57
|
-
* intermediate states of a `.did` file being edited
|
|
58
|
-
*
|
|
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.
|
|
59
77
|
*/
|
|
60
78
|
failOnError?: boolean;
|
|
61
79
|
}
|
|
62
|
-
|
|
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;
|
|
63
121
|
|
|
64
122
|
export { type IcReactorPluginOptions, icReactor };
|