@ic-reactor/vite-plugin 0.9.0 → 0.10.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 +2 -2
- package/dist/index.cjs +19 -18
- package/dist/index.js +19 -18
- package/package.json +5 -5
- package/src/env.ts +2 -5
- package/src/index.test.ts +2 -2
- package/src/index.ts +24 -25
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ export default defineConfig({
|
|
|
31
31
|
|
|
32
32
|
```ts
|
|
33
33
|
// src/clients.ts
|
|
34
|
-
import { ClientManager } from "@ic-reactor/
|
|
34
|
+
import { ClientManager } from "@ic-reactor/core"
|
|
35
35
|
import { QueryClient } from "@tanstack/react-query"
|
|
36
36
|
|
|
37
37
|
export const queryClient = new QueryClient()
|
|
@@ -91,7 +91,7 @@ Supported `target` values:
|
|
|
91
91
|
|
|
92
92
|
When `injectEnvironment` is enabled during `vite dev`, the plugin:
|
|
93
93
|
|
|
94
|
-
1. asks `icp
|
|
94
|
+
1. asks `icp` for the local network status
|
|
95
95
|
2. resolves configured canister IDs
|
|
96
96
|
3. sets the `ic_env` cookie
|
|
97
97
|
4. proxies `/api` to the local replica
|
package/dist/index.cjs
CHANGED
|
@@ -102,7 +102,7 @@ function icReactor(options) {
|
|
|
102
102
|
name: "ic-reactor-plugin",
|
|
103
103
|
enforce: "pre",
|
|
104
104
|
// Run before other plugins
|
|
105
|
-
config(
|
|
105
|
+
config(_config, { command }) {
|
|
106
106
|
if (command !== "serve" || !injectEnvironment) {
|
|
107
107
|
return {};
|
|
108
108
|
}
|
|
@@ -152,26 +152,27 @@ function icReactor(options) {
|
|
|
152
152
|
console.log(
|
|
153
153
|
`[ic-reactor] Generating canister bindings for ${canisters.length} canisters...`
|
|
154
154
|
);
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
155
|
+
await Promise.allSettled(
|
|
156
|
+
canisters.map(async (canisterConfig) => {
|
|
157
|
+
try {
|
|
158
|
+
const result = await (0, import_codegen.runCanisterPipeline)({
|
|
159
|
+
canisterConfig,
|
|
160
|
+
projectRoot,
|
|
161
|
+
globalConfig
|
|
162
|
+
});
|
|
163
|
+
if (!result.success) {
|
|
164
|
+
console.error(
|
|
165
|
+
`[ic-reactor] Failed to generate ${canisterConfig.name}: ${result.error}`
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
} catch (err) {
|
|
163
169
|
console.error(
|
|
164
|
-
`[ic-reactor]
|
|
170
|
+
`[ic-reactor] Error generating ${canisterConfig.name}:`,
|
|
171
|
+
err
|
|
165
172
|
);
|
|
166
|
-
} else {
|
|
167
173
|
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
`[ic-reactor] Error generating ${canisterConfig.name}:`,
|
|
171
|
-
err
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
174
|
+
})
|
|
175
|
+
);
|
|
175
176
|
},
|
|
176
177
|
handleHotUpdate({ file, server }) {
|
|
177
178
|
if (file.endsWith(".did")) {
|
package/dist/index.js
CHANGED
|
@@ -70,7 +70,7 @@ function icReactor(options) {
|
|
|
70
70
|
name: "ic-reactor-plugin",
|
|
71
71
|
enforce: "pre",
|
|
72
72
|
// Run before other plugins
|
|
73
|
-
config(
|
|
73
|
+
config(_config, { command }) {
|
|
74
74
|
if (command !== "serve" || !injectEnvironment) {
|
|
75
75
|
return {};
|
|
76
76
|
}
|
|
@@ -120,26 +120,27 @@ function icReactor(options) {
|
|
|
120
120
|
console.log(
|
|
121
121
|
`[ic-reactor] Generating canister bindings for ${canisters.length} canisters...`
|
|
122
122
|
);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
123
|
+
await Promise.allSettled(
|
|
124
|
+
canisters.map(async (canisterConfig) => {
|
|
125
|
+
try {
|
|
126
|
+
const result = await runCanisterPipeline({
|
|
127
|
+
canisterConfig,
|
|
128
|
+
projectRoot,
|
|
129
|
+
globalConfig
|
|
130
|
+
});
|
|
131
|
+
if (!result.success) {
|
|
132
|
+
console.error(
|
|
133
|
+
`[ic-reactor] Failed to generate ${canisterConfig.name}: ${result.error}`
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
} catch (err) {
|
|
131
137
|
console.error(
|
|
132
|
-
`[ic-reactor]
|
|
138
|
+
`[ic-reactor] Error generating ${canisterConfig.name}:`,
|
|
139
|
+
err
|
|
133
140
|
);
|
|
134
|
-
} else {
|
|
135
141
|
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
`[ic-reactor] Error generating ${canisterConfig.name}:`,
|
|
139
|
-
err
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
142
|
+
})
|
|
143
|
+
);
|
|
143
144
|
},
|
|
144
145
|
handleHotUpdate({ file, server }) {
|
|
145
146
|
if (file.endsWith(".did")) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/vite-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.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,17 +37,17 @@
|
|
|
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.10.0"
|
|
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.
|
|
47
|
-
"@types/node": "^25.
|
|
46
|
+
"@icp-sdk/bindgen": "^0.3.0",
|
|
47
|
+
"@types/node": "^25.5.2",
|
|
48
48
|
"tsup": "^8.5.1",
|
|
49
49
|
"typescript": "^5.9.3",
|
|
50
|
-
"vitest": "^4.
|
|
50
|
+
"vitest": "^4.1.2"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"build": "tsup src/index.ts --format esm,cjs --dts --tsconfig tsconfig.json",
|
package/src/env.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Environment Injection Utilities
|
|
3
3
|
*
|
|
4
|
-
* Handles detecting the local IC environment
|
|
4
|
+
* Handles detecting the local IC environment via the `icp` CLI
|
|
5
5
|
* and building the `ic_env` cookie for the browser.
|
|
6
6
|
*/
|
|
7
7
|
|
|
@@ -15,16 +15,13 @@ export interface IcEnvironment {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* Detect the IC environment using the `icp`
|
|
18
|
+
* Detect the IC environment using the `icp` CLI.
|
|
19
19
|
*/
|
|
20
20
|
export function getIcEnvironmentInfo(
|
|
21
21
|
canisterNames: string[]
|
|
22
22
|
): IcEnvironment | null {
|
|
23
23
|
const environment = process.env.ICP_ENVIRONMENT || "local"
|
|
24
24
|
|
|
25
|
-
// We try `icp` first, but could fallback to `dfx` logic if needed.
|
|
26
|
-
// For now, assuming `icp` CLI is available based on previous code.
|
|
27
|
-
|
|
28
25
|
try {
|
|
29
26
|
const networkStatus = JSON.parse(
|
|
30
27
|
execFileSync("icp", ["network", "status", "-e", environment, "--json"], {
|
package/src/index.test.ts
CHANGED
|
@@ -78,7 +78,7 @@ describe("icReactor", () => {
|
|
|
78
78
|
describe("config", () => {
|
|
79
79
|
it("should set up API proxy and headers when icp-cli is available", () => {
|
|
80
80
|
;(execFileSync as any).mockImplementation(
|
|
81
|
-
(command: string, args: string[],
|
|
81
|
+
(command: string, args: string[], _options: any) => {
|
|
82
82
|
if (
|
|
83
83
|
command === "icp" &&
|
|
84
84
|
args.includes("network") &&
|
|
@@ -112,7 +112,7 @@ describe("icReactor", () => {
|
|
|
112
112
|
|
|
113
113
|
it("should prefer configured canisterId over CLI-discovered env values", () => {
|
|
114
114
|
;(execFileSync as any).mockImplementation(
|
|
115
|
-
(command: string, args: string[],
|
|
115
|
+
(command: string, args: string[], _options: any) => {
|
|
116
116
|
if (
|
|
117
117
|
command === "icp" &&
|
|
118
118
|
args.includes("network") &&
|
package/src/index.ts
CHANGED
|
@@ -78,7 +78,7 @@ export function icReactor(options: IcReactorPluginOptions): any {
|
|
|
78
78
|
name: "ic-reactor-plugin",
|
|
79
79
|
enforce: "pre", // Run before other plugins
|
|
80
80
|
|
|
81
|
-
config(
|
|
81
|
+
config(_config, { command }) {
|
|
82
82
|
if (command !== "serve" || !injectEnvironment) {
|
|
83
83
|
return {}
|
|
84
84
|
}
|
|
@@ -145,33 +145,32 @@ export function icReactor(options: IcReactorPluginOptions): any {
|
|
|
145
145
|
`[ic-reactor] Generating canister bindings for ${canisters.length} canisters...`
|
|
146
146
|
)
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
148
|
+
await Promise.allSettled(
|
|
149
|
+
canisters.map(async (canisterConfig) => {
|
|
150
|
+
try {
|
|
151
|
+
// If .did file is missing, we might want to attempt pulling it?
|
|
152
|
+
// For now, pipeline fails if missing. The old plugin logic to "download"
|
|
153
|
+
// is omitted for simplicity unless requested, to keep "codegen" pure.
|
|
154
|
+
|
|
155
|
+
const result = await runCanisterPipeline({
|
|
156
|
+
canisterConfig,
|
|
157
|
+
projectRoot,
|
|
158
|
+
globalConfig,
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
if (!result.success) {
|
|
162
|
+
console.error(
|
|
163
|
+
`[ic-reactor] Failed to generate ${canisterConfig.name}: ${result.error}`
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
} catch (err) {
|
|
161
167
|
console.error(
|
|
162
|
-
`[ic-reactor]
|
|
168
|
+
`[ic-reactor] Error generating ${canisterConfig.name}:`,
|
|
169
|
+
err
|
|
163
170
|
)
|
|
164
|
-
} else {
|
|
165
|
-
// Optional: log success
|
|
166
|
-
// console.log(`[ic-reactor] Generated ${canisterConfig.name} hooks`)
|
|
167
171
|
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
`[ic-reactor] Error generating ${canisterConfig.name}:`,
|
|
171
|
-
err
|
|
172
|
-
)
|
|
173
|
-
}
|
|
174
|
-
}
|
|
172
|
+
})
|
|
173
|
+
)
|
|
175
174
|
},
|
|
176
175
|
|
|
177
176
|
handleHotUpdate({ file, server }) {
|