@ic-reactor/vite-plugin 0.9.0 → 0.11.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 CHANGED
@@ -31,7 +31,7 @@ export default defineConfig({
31
31
 
32
32
  ```ts
33
33
  // src/clients.ts
34
- import { ClientManager } from "@ic-reactor/react"
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,11 +91,18 @@ Supported `target` values:
91
91
 
92
92
  When `injectEnvironment` is enabled during `vite dev`, the plugin:
93
93
 
94
- 1. asks `icp-cli` for the local network status
95
- 2. resolves configured canister IDs
94
+ 1. asks `icp` for the local network status
95
+ 2. resolves canister IDs — `internet_identity` is added automatically if not
96
+ already in your canister list
96
97
  3. sets the `ic_env` cookie
97
98
  4. proxies `/api` to the local replica
98
99
 
100
+ If a canister has a `canisterId` set in the plugin config, that value overrides
101
+ the auto-detected ID for that canister.
102
+
103
+ Set the `ICP_ENVIRONMENT` environment variable to target a non-default network
104
+ (defaults to `"local"`).
105
+
99
106
  If environment detection fails, the plugin still falls back to proxying `/api`
100
107
  to `http://127.0.0.1:4943`, but it will not inject canister metadata.
101
108
 
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(config, { command }) {
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
- for (const canisterConfig of canisters) {
156
- try {
157
- const result = await (0, import_codegen.runCanisterPipeline)({
158
- canisterConfig,
159
- projectRoot,
160
- globalConfig
161
- });
162
- if (!result.success) {
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] Failed to generate ${canisterConfig.name}: ${result.error}`
170
+ `[ic-reactor] Error generating ${canisterConfig.name}:`,
171
+ err
165
172
  );
166
- } else {
167
173
  }
168
- } catch (err) {
169
- console.error(
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(config, { command }) {
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
- for (const canisterConfig of canisters) {
124
- try {
125
- const result = await runCanisterPipeline({
126
- canisterConfig,
127
- projectRoot,
128
- globalConfig
129
- });
130
- if (!result.success) {
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] Failed to generate ${canisterConfig.name}: ${result.error}`
138
+ `[ic-reactor] Error generating ${canisterConfig.name}:`,
139
+ err
133
140
  );
134
- } else {
135
141
  }
136
- } catch (err) {
137
- console.error(
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.9.0",
3
+ "version": "0.11.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.9.0"
40
+ "@ic-reactor/codegen": "0.11.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.2.2",
47
- "@types/node": "^25.3.5",
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.0.18"
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 (via `dfx` or `icp` CLI)
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` or `dfx` CLI.
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[], options: any) => {
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[], options: any) => {
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(config, { command }) {
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
- for (const canisterConfig of canisters) {
149
- try {
150
- // If .did file is missing, we might want to attempt pulling it?
151
- // For now, pipeline fails if missing. The old plugin logic to "download"
152
- // is omitted for simplicity unless requested, to keep "codegen" pure.
153
-
154
- const result = await runCanisterPipeline({
155
- canisterConfig,
156
- projectRoot,
157
- globalConfig,
158
- })
159
-
160
- if (!result.success) {
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] Failed to generate ${canisterConfig.name}: ${result.error}`
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
- } catch (err) {
169
- console.error(
170
- `[ic-reactor] Error generating ${canisterConfig.name}:`,
171
- err
172
- )
173
- }
174
- }
172
+ })
173
+ )
175
174
  },
176
175
 
177
176
  handleHotUpdate({ file, server }) {