@ic-reactor/vite-plugin 0.7.1 → 0.7.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 +27 -9
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +4 -4
- package/src/index.test.ts +42 -11
- package/src/index.ts +1 -1
package/README.md
CHANGED
|
@@ -38,12 +38,12 @@ pnpm add @ic-reactor/react @tanstack/react-query @icp-sdk/core
|
|
|
38
38
|
// vite.config.ts
|
|
39
39
|
import { defineConfig } from "vite"
|
|
40
40
|
import react from "@vitejs/plugin-react"
|
|
41
|
-
import {
|
|
41
|
+
import { icReactor } from "@ic-reactor/vite-plugin"
|
|
42
42
|
|
|
43
43
|
export default defineConfig({
|
|
44
44
|
plugins: [
|
|
45
45
|
react(),
|
|
46
|
-
|
|
46
|
+
icReactor({
|
|
47
47
|
canisters: [
|
|
48
48
|
{
|
|
49
49
|
name: "backend",
|
|
@@ -87,6 +87,23 @@ function MyComponent() {
|
|
|
87
87
|
}
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
+
### Reactor Mode (per canister)
|
|
91
|
+
|
|
92
|
+
By default, generated hooks use `DisplayReactor` (backward compatible). Set `mode` on a canister to choose the generated reactor class (`Reactor`, `DisplayReactor`, `CandidReactor`, `CandidDisplayReactor`, or `MetadataDisplayReactor`).
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
icReactor({
|
|
96
|
+
canisters: [
|
|
97
|
+
{ name: "backend", didFile: "./backend/backend.did" },
|
|
98
|
+
{
|
|
99
|
+
name: "workflow_engine",
|
|
100
|
+
mode: "Reactor",
|
|
101
|
+
didFile: "./workflow/workflow_engine.did",
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
})
|
|
105
|
+
```
|
|
106
|
+
|
|
90
107
|
## Configuration
|
|
91
108
|
|
|
92
109
|
### Plugin Options
|
|
@@ -100,13 +117,14 @@ function MyComponent() {
|
|
|
100
117
|
|
|
101
118
|
### Canister Config
|
|
102
119
|
|
|
103
|
-
| Option | Type
|
|
104
|
-
| :------------------ |
|
|
105
|
-
| `name` | `string`
|
|
106
|
-
| `didFile` | `string`
|
|
107
|
-
| `outDir` | `string`
|
|
108
|
-
| `clientManagerPath` | `string`
|
|
109
|
-
| `
|
|
120
|
+
| Option | Type | Description | Required |
|
|
121
|
+
| :------------------ | :------------------------------------------------------------------------------------------------------- | :---------------------------------------------- | :------- |
|
|
122
|
+
| `name` | `string` | Name of the canister (used for variable names). | Yes |
|
|
123
|
+
| `didFile` | `string` | Path to the `.did` file. | Yes |
|
|
124
|
+
| `outDir` | `string` | Override output directory for this canister. | No |
|
|
125
|
+
| `clientManagerPath` | `string` | Override client manager path. | No |
|
|
126
|
+
| `mode` | `"Reactor" \| "DisplayReactor" \| "CandidReactor" \| "CandidDisplayReactor" \| "MetadataDisplayReactor"` | Reactor class for generated hooks. | No |
|
|
127
|
+
| `canisterId` | `string` | Optional fixed canister ID. | No |
|
|
110
128
|
|
|
111
129
|
## Local Development (Environment Injection)
|
|
112
130
|
|
package/dist/index.cjs
CHANGED
|
@@ -30,7 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
|
|
33
|
+
icReactor: () => icReactor
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(index_exports);
|
|
36
36
|
var import_node_path = __toESM(require("path"), 1);
|
|
@@ -78,7 +78,7 @@ function buildIcEnvCookie(canisterIds, rootKey) {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
// src/index.ts
|
|
81
|
-
function
|
|
81
|
+
function icReactor(options) {
|
|
82
82
|
const {
|
|
83
83
|
canisters,
|
|
84
84
|
outDir = "src/declarations",
|
|
@@ -191,5 +191,5 @@ function icReactorPlugin(options) {
|
|
|
191
191
|
}
|
|
192
192
|
// Annotate the CommonJS export names for ESM import in node:
|
|
193
193
|
0 && (module.exports = {
|
|
194
|
-
|
|
194
|
+
icReactor
|
|
195
195
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -31,6 +31,6 @@ interface IcReactorPluginOptions {
|
|
|
31
31
|
*/
|
|
32
32
|
injectEnvironment?: boolean;
|
|
33
33
|
}
|
|
34
|
-
declare function
|
|
34
|
+
declare function icReactor(options: IcReactorPluginOptions): any;
|
|
35
35
|
|
|
36
|
-
export { type IcReactorPluginOptions,
|
|
36
|
+
export { type IcReactorPluginOptions, icReactor };
|
package/dist/index.d.ts
CHANGED
|
@@ -31,6 +31,6 @@ interface IcReactorPluginOptions {
|
|
|
31
31
|
*/
|
|
32
32
|
injectEnvironment?: boolean;
|
|
33
33
|
}
|
|
34
|
-
declare function
|
|
34
|
+
declare function icReactor(options: IcReactorPluginOptions): any;
|
|
35
35
|
|
|
36
|
-
export { type IcReactorPluginOptions,
|
|
36
|
+
export { type IcReactorPluginOptions, icReactor };
|
package/dist/index.js
CHANGED
|
@@ -46,7 +46,7 @@ function buildIcEnvCookie(canisterIds, rootKey) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
// src/index.ts
|
|
49
|
-
function
|
|
49
|
+
function icReactor(options) {
|
|
50
50
|
const {
|
|
51
51
|
canisters,
|
|
52
52
|
outDir = "src/declarations",
|
|
@@ -158,5 +158,5 @@ function icReactorPlugin(options) {
|
|
|
158
158
|
return plugin;
|
|
159
159
|
}
|
|
160
160
|
export {
|
|
161
|
-
|
|
161
|
+
icReactor
|
|
162
162
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/vite-plugin",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "Vite plugin for zero-config IC reactor generation from Candid files",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -37,14 +37,14 @@
|
|
|
37
37
|
"url": "https://github.com/B3Pay/ic-reactor/issues"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@ic-reactor/codegen": "0.7.
|
|
40
|
+
"@ic-reactor/codegen": "0.7.2"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"vite": "^4.2.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@icp-sdk/bindgen": "^0.2.
|
|
47
|
-
"@types/node": "^25.
|
|
46
|
+
"@icp-sdk/bindgen": "^0.2.2",
|
|
47
|
+
"@types/node": "^25.3.0",
|
|
48
48
|
"tsup": "^8.5.1",
|
|
49
49
|
"typescript": "^5.9.3",
|
|
50
50
|
"vitest": "^4.0.18"
|
package/src/index.test.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from "vitest"
|
|
2
|
-
import
|
|
2
|
+
import * as vitePluginModule from "./index"
|
|
3
|
+
import type { IcReactorPluginOptions } from "./index"
|
|
3
4
|
import path from "path"
|
|
4
5
|
import { execFileSync } from "child_process"
|
|
5
6
|
import { runCanisterPipeline } from "@ic-reactor/codegen"
|
|
6
7
|
|
|
8
|
+
const createVitePlugin =
|
|
9
|
+
(vitePluginModule as any).icReactor ??
|
|
10
|
+
(vitePluginModule as any).icReactorPlugin
|
|
11
|
+
|
|
7
12
|
// Mock internal dependencies
|
|
8
13
|
vi.mock("@ic-reactor/codegen", () => ({
|
|
9
14
|
runCanisterPipeline: vi.fn(),
|
|
@@ -24,7 +29,7 @@ vi.mock("fs", () => ({
|
|
|
24
29
|
},
|
|
25
30
|
}))
|
|
26
31
|
|
|
27
|
-
describe("
|
|
32
|
+
describe("icReactor", () => {
|
|
28
33
|
const mockOptions: IcReactorPluginOptions = {
|
|
29
34
|
canisters: [
|
|
30
35
|
{
|
|
@@ -63,7 +68,7 @@ describe("icReactorPlugin", () => {
|
|
|
63
68
|
})
|
|
64
69
|
|
|
65
70
|
it("should return correct plugin structure", () => {
|
|
66
|
-
const plugin =
|
|
71
|
+
const plugin = createVitePlugin(mockOptions)
|
|
67
72
|
expect(plugin.name).toBe("ic-reactor-plugin")
|
|
68
73
|
expect(plugin.buildStart).toBeDefined()
|
|
69
74
|
expect(plugin.handleHotUpdate).toBeDefined()
|
|
@@ -92,7 +97,7 @@ describe("icReactorPlugin", () => {
|
|
|
92
97
|
}
|
|
93
98
|
)
|
|
94
99
|
|
|
95
|
-
const plugin =
|
|
100
|
+
const plugin = createVitePlugin(mockOptions)
|
|
96
101
|
const config = (plugin as any).config({}, { command: "serve" })
|
|
97
102
|
|
|
98
103
|
expect(config.server.headers["Set-Cookie"]).toContain("ic_env=")
|
|
@@ -110,7 +115,7 @@ describe("icReactorPlugin", () => {
|
|
|
110
115
|
throw new Error("Command not found")
|
|
111
116
|
})
|
|
112
117
|
|
|
113
|
-
const plugin =
|
|
118
|
+
const plugin = createVitePlugin(mockOptions)
|
|
114
119
|
const config = (plugin as any).config({}, { command: "serve" })
|
|
115
120
|
|
|
116
121
|
expect(config.server.headers).toBeUndefined()
|
|
@@ -118,7 +123,7 @@ describe("icReactorPlugin", () => {
|
|
|
118
123
|
})
|
|
119
124
|
|
|
120
125
|
it("should return empty config for build command", () => {
|
|
121
|
-
const plugin =
|
|
126
|
+
const plugin = createVitePlugin(mockOptions)
|
|
122
127
|
const config = (plugin as any).config({}, { command: "build" })
|
|
123
128
|
|
|
124
129
|
expect(config).toEqual({})
|
|
@@ -127,7 +132,7 @@ describe("icReactorPlugin", () => {
|
|
|
127
132
|
|
|
128
133
|
describe("buildStart", () => {
|
|
129
134
|
it("should generate declarations and reactor file", async () => {
|
|
130
|
-
const plugin =
|
|
135
|
+
const plugin = createVitePlugin(mockOptions)
|
|
131
136
|
await (plugin.buildStart as any)()
|
|
132
137
|
|
|
133
138
|
expect(runCanisterPipeline).toHaveBeenCalledWith({
|
|
@@ -150,7 +155,7 @@ describe("icReactorPlugin", () => {
|
|
|
150
155
|
error: "Failed to generate",
|
|
151
156
|
})
|
|
152
157
|
|
|
153
|
-
const plugin =
|
|
158
|
+
const plugin = createVitePlugin(mockOptions)
|
|
154
159
|
await (plugin.buildStart as any)()
|
|
155
160
|
|
|
156
161
|
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
@@ -159,11 +164,37 @@ describe("icReactorPlugin", () => {
|
|
|
159
164
|
|
|
160
165
|
consoleErrorSpy.mockRestore()
|
|
161
166
|
})
|
|
167
|
+
|
|
168
|
+
it("should pass canister mode through to codegen via canister config", async () => {
|
|
169
|
+
const plugin = createVitePlugin({
|
|
170
|
+
canisters: [
|
|
171
|
+
{
|
|
172
|
+
...mockOptions.canisters[0],
|
|
173
|
+
mode: "Reactor",
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
outDir: mockOptions.outDir,
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
await (plugin.buildStart as any)()
|
|
180
|
+
|
|
181
|
+
expect(runCanisterPipeline).toHaveBeenCalledWith({
|
|
182
|
+
canisterConfig: {
|
|
183
|
+
...mockOptions.canisters[0],
|
|
184
|
+
mode: "Reactor",
|
|
185
|
+
},
|
|
186
|
+
projectRoot: expect.any(String),
|
|
187
|
+
globalConfig: {
|
|
188
|
+
outDir: "src/declarations",
|
|
189
|
+
clientManagerPath: "../../clients",
|
|
190
|
+
},
|
|
191
|
+
})
|
|
192
|
+
})
|
|
162
193
|
})
|
|
163
194
|
|
|
164
195
|
describe("handleHotUpdate", () => {
|
|
165
196
|
it("should register configured .did files with the watcher", () => {
|
|
166
|
-
const plugin =
|
|
197
|
+
const plugin = createVitePlugin(mockOptions)
|
|
167
198
|
;(plugin.configureServer as any)(mockServer)
|
|
168
199
|
|
|
169
200
|
expect(mockServer.watcher.add).toHaveBeenCalledWith([
|
|
@@ -172,7 +203,7 @@ describe("icReactorPlugin", () => {
|
|
|
172
203
|
})
|
|
173
204
|
|
|
174
205
|
it("should restart server when .did file changes", async () => {
|
|
175
|
-
const plugin =
|
|
206
|
+
const plugin = createVitePlugin(mockOptions)
|
|
176
207
|
const ctx = {
|
|
177
208
|
file: "/absolute/path/to/src/declarations/test.did",
|
|
178
209
|
server: mockServer,
|
|
@@ -193,7 +224,7 @@ describe("icReactorPlugin", () => {
|
|
|
193
224
|
})
|
|
194
225
|
|
|
195
226
|
it("should ignore other files", () => {
|
|
196
|
-
const plugin =
|
|
227
|
+
const plugin = createVitePlugin(mockOptions)
|
|
197
228
|
const ctx = {
|
|
198
229
|
file: "/some/other/file.ts",
|
|
199
230
|
server: mockServer,
|
package/src/index.ts
CHANGED
|
@@ -39,7 +39,7 @@ export interface IcReactorPluginOptions {
|
|
|
39
39
|
injectEnvironment?: boolean
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export function
|
|
42
|
+
export function icReactor(options: IcReactorPluginOptions): any {
|
|
43
43
|
const {
|
|
44
44
|
canisters,
|
|
45
45
|
outDir = "src/declarations",
|