@ic-reactor/vite-plugin 0.5.1 → 0.7.0
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 +2 -2
- package/src/index.test.ts +36 -10
- 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",
|
|
@@ -185,5 +185,5 @@ function icReactorPlugin(options) {
|
|
|
185
185
|
}
|
|
186
186
|
// Annotate the CommonJS export names for ESM import in node:
|
|
187
187
|
0 && (module.exports = {
|
|
188
|
-
|
|
188
|
+
icReactor
|
|
189
189
|
});
|
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",
|
|
@@ -152,5 +152,5 @@ function icReactorPlugin(options) {
|
|
|
152
152
|
return plugin;
|
|
153
153
|
}
|
|
154
154
|
export {
|
|
155
|
-
|
|
155
|
+
icReactor
|
|
156
156
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/vite-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
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,7 +37,7 @@
|
|
|
37
37
|
"url": "https://github.com/B3Pay/ic-reactor/issues"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@ic-reactor/codegen": "0.
|
|
40
|
+
"@ic-reactor/codegen": "0.7.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"vite": "^4.2.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"
|
package/src/index.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from "vitest"
|
|
2
|
-
import {
|
|
2
|
+
import { icReactor, type IcReactorPluginOptions } from "./index"
|
|
3
3
|
import path from "path"
|
|
4
4
|
import { execFileSync } from "child_process"
|
|
5
5
|
import { runCanisterPipeline } from "@ic-reactor/codegen"
|
|
@@ -24,7 +24,7 @@ vi.mock("fs", () => ({
|
|
|
24
24
|
},
|
|
25
25
|
}))
|
|
26
26
|
|
|
27
|
-
describe("
|
|
27
|
+
describe("icReactor", () => {
|
|
28
28
|
const mockOptions: IcReactorPluginOptions = {
|
|
29
29
|
canisters: [
|
|
30
30
|
{
|
|
@@ -60,7 +60,7 @@ describe("icReactorPlugin", () => {
|
|
|
60
60
|
})
|
|
61
61
|
|
|
62
62
|
it("should return correct plugin structure", () => {
|
|
63
|
-
const plugin =
|
|
63
|
+
const plugin = icReactor(mockOptions)
|
|
64
64
|
expect(plugin.name).toBe("ic-reactor-plugin")
|
|
65
65
|
expect(plugin.buildStart).toBeDefined()
|
|
66
66
|
expect(plugin.handleHotUpdate).toBeDefined()
|
|
@@ -89,7 +89,7 @@ describe("icReactorPlugin", () => {
|
|
|
89
89
|
}
|
|
90
90
|
)
|
|
91
91
|
|
|
92
|
-
const plugin =
|
|
92
|
+
const plugin = icReactor(mockOptions)
|
|
93
93
|
const config = (plugin as any).config({}, { command: "serve" })
|
|
94
94
|
|
|
95
95
|
expect(config.server.headers["Set-Cookie"]).toContain("ic_env=")
|
|
@@ -107,7 +107,7 @@ describe("icReactorPlugin", () => {
|
|
|
107
107
|
throw new Error("Command not found")
|
|
108
108
|
})
|
|
109
109
|
|
|
110
|
-
const plugin =
|
|
110
|
+
const plugin = icReactor(mockOptions)
|
|
111
111
|
const config = (plugin as any).config({}, { command: "serve" })
|
|
112
112
|
|
|
113
113
|
expect(config.server.headers).toBeUndefined()
|
|
@@ -115,7 +115,7 @@ describe("icReactorPlugin", () => {
|
|
|
115
115
|
})
|
|
116
116
|
|
|
117
117
|
it("should return empty config for build command", () => {
|
|
118
|
-
const plugin =
|
|
118
|
+
const plugin = icReactor(mockOptions)
|
|
119
119
|
const config = (plugin as any).config({}, { command: "build" })
|
|
120
120
|
|
|
121
121
|
expect(config).toEqual({})
|
|
@@ -124,7 +124,7 @@ describe("icReactorPlugin", () => {
|
|
|
124
124
|
|
|
125
125
|
describe("buildStart", () => {
|
|
126
126
|
it("should generate declarations and reactor file", async () => {
|
|
127
|
-
const plugin =
|
|
127
|
+
const plugin = icReactor(mockOptions)
|
|
128
128
|
await (plugin.buildStart as any)()
|
|
129
129
|
|
|
130
130
|
expect(runCanisterPipeline).toHaveBeenCalledWith({
|
|
@@ -147,7 +147,7 @@ describe("icReactorPlugin", () => {
|
|
|
147
147
|
error: "Failed to generate",
|
|
148
148
|
})
|
|
149
149
|
|
|
150
|
-
const plugin =
|
|
150
|
+
const plugin = icReactor(mockOptions)
|
|
151
151
|
await (plugin.buildStart as any)()
|
|
152
152
|
|
|
153
153
|
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
@@ -156,11 +156,37 @@ describe("icReactorPlugin", () => {
|
|
|
156
156
|
|
|
157
157
|
consoleErrorSpy.mockRestore()
|
|
158
158
|
})
|
|
159
|
+
|
|
160
|
+
it("should pass canister mode through to codegen via canister config", async () => {
|
|
161
|
+
const plugin = icReactor({
|
|
162
|
+
canisters: [
|
|
163
|
+
{
|
|
164
|
+
...mockOptions.canisters[0],
|
|
165
|
+
mode: "Reactor",
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
outDir: mockOptions.outDir,
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
await (plugin.buildStart as any)()
|
|
172
|
+
|
|
173
|
+
expect(runCanisterPipeline).toHaveBeenCalledWith({
|
|
174
|
+
canisterConfig: {
|
|
175
|
+
...mockOptions.canisters[0],
|
|
176
|
+
mode: "Reactor",
|
|
177
|
+
},
|
|
178
|
+
projectRoot: expect.any(String),
|
|
179
|
+
globalConfig: {
|
|
180
|
+
outDir: "src/declarations",
|
|
181
|
+
clientManagerPath: "../../clients",
|
|
182
|
+
},
|
|
183
|
+
})
|
|
184
|
+
})
|
|
159
185
|
})
|
|
160
186
|
|
|
161
187
|
describe("handleHotUpdate", () => {
|
|
162
188
|
it("should restart server when .did file changes", async () => {
|
|
163
|
-
const plugin =
|
|
189
|
+
const plugin = icReactor(mockOptions)
|
|
164
190
|
const ctx = {
|
|
165
191
|
file: "/absolute/path/to/src/declarations/test.did",
|
|
166
192
|
server: mockServer,
|
|
@@ -181,7 +207,7 @@ describe("icReactorPlugin", () => {
|
|
|
181
207
|
})
|
|
182
208
|
|
|
183
209
|
it("should ignore other files", () => {
|
|
184
|
-
const plugin =
|
|
210
|
+
const plugin = icReactor(mockOptions)
|
|
185
211
|
const ctx = {
|
|
186
212
|
file: "/some/other/file.ts",
|
|
187
213
|
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",
|