@ic-reactor/vite-plugin 0.8.0 → 0.9.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 +10 -0
- package/dist/index.cjs +4 -2
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +4 -2
- package/package.json +2 -2
- package/src/index.test.ts +21 -0
- package/src/index.ts +13 -2
package/README.md
CHANGED
|
@@ -43,6 +43,9 @@ export const clientManager = new ClientManager({
|
|
|
43
43
|
|
|
44
44
|
The plugin generates files under `src/declarations/<canister>/` by default.
|
|
45
45
|
|
|
46
|
+
If you want non-React output, set `target: "core"` and install the matching
|
|
47
|
+
runtime package instead of `@ic-reactor/react`.
|
|
48
|
+
|
|
46
49
|
## Options
|
|
47
50
|
|
|
48
51
|
```ts
|
|
@@ -56,6 +59,7 @@ icReactor({
|
|
|
56
59
|
],
|
|
57
60
|
outDir: "src/declarations",
|
|
58
61
|
clientManagerPath: "../../clients",
|
|
62
|
+
target: "react",
|
|
59
63
|
injectEnvironment: true,
|
|
60
64
|
})
|
|
61
65
|
```
|
|
@@ -66,6 +70,7 @@ icReactor({
|
|
|
66
70
|
- `didFile`
|
|
67
71
|
- `outDir`
|
|
68
72
|
- `clientManagerPath`
|
|
73
|
+
- `target`
|
|
69
74
|
- `mode`
|
|
70
75
|
- `canisterId`
|
|
71
76
|
|
|
@@ -77,6 +82,11 @@ Supported `mode` values:
|
|
|
77
82
|
- `CandidDisplayReactor`
|
|
78
83
|
- `MetadataDisplayReactor`
|
|
79
84
|
|
|
85
|
+
Supported `target` values:
|
|
86
|
+
|
|
87
|
+
- `react` (default): generates the reactor plus bound React hooks
|
|
88
|
+
- `core`: generates only the typed reactor exports with no React dependency
|
|
89
|
+
|
|
80
90
|
## Local Development Behavior
|
|
81
91
|
|
|
82
92
|
When `injectEnvironment` is enabled during `vite dev`, the plugin:
|
package/dist/index.cjs
CHANGED
|
@@ -83,11 +83,13 @@ function icReactor(options) {
|
|
|
83
83
|
canisters,
|
|
84
84
|
outDir = "src/declarations",
|
|
85
85
|
clientManagerPath = "../../clients",
|
|
86
|
+
target = "react",
|
|
86
87
|
injectEnvironment = true
|
|
87
88
|
} = options;
|
|
88
89
|
const globalConfig = {
|
|
89
90
|
outDir,
|
|
90
|
-
clientManagerPath
|
|
91
|
+
clientManagerPath,
|
|
92
|
+
target
|
|
91
93
|
};
|
|
92
94
|
const projectRoot = process.cwd();
|
|
93
95
|
const resolveDidPath = (didFile) => import_node_path.default.normalize(
|
|
@@ -148,7 +150,7 @@ function icReactor(options) {
|
|
|
148
150
|
},
|
|
149
151
|
async buildStart() {
|
|
150
152
|
console.log(
|
|
151
|
-
`[ic-reactor] Generating
|
|
153
|
+
`[ic-reactor] Generating canister bindings for ${canisters.length} canisters...`
|
|
152
154
|
);
|
|
153
155
|
for (const canisterConfig of canisters) {
|
|
154
156
|
try {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CanisterConfig } from '@ic-reactor/codegen';
|
|
1
|
+
import { CanisterConfig, CodegenTarget } from '@ic-reactor/codegen';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @ic-reactor/vite-plugin
|
|
@@ -25,6 +25,11 @@ interface IcReactorPluginOptions {
|
|
|
25
25
|
* Default: "../../clients"
|
|
26
26
|
*/
|
|
27
27
|
clientManagerPath?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Default generated runtime target.
|
|
30
|
+
* Default: "react"
|
|
31
|
+
*/
|
|
32
|
+
target?: CodegenTarget;
|
|
28
33
|
/**
|
|
29
34
|
* Automatically inject `ic_env` cookie for local development?
|
|
30
35
|
* Default: true
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CanisterConfig } from '@ic-reactor/codegen';
|
|
1
|
+
import { CanisterConfig, CodegenTarget } from '@ic-reactor/codegen';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @ic-reactor/vite-plugin
|
|
@@ -25,6 +25,11 @@ interface IcReactorPluginOptions {
|
|
|
25
25
|
* Default: "../../clients"
|
|
26
26
|
*/
|
|
27
27
|
clientManagerPath?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Default generated runtime target.
|
|
30
|
+
* Default: "react"
|
|
31
|
+
*/
|
|
32
|
+
target?: CodegenTarget;
|
|
28
33
|
/**
|
|
29
34
|
* Automatically inject `ic_env` cookie for local development?
|
|
30
35
|
* Default: true
|
package/dist/index.js
CHANGED
|
@@ -51,11 +51,13 @@ function icReactor(options) {
|
|
|
51
51
|
canisters,
|
|
52
52
|
outDir = "src/declarations",
|
|
53
53
|
clientManagerPath = "../../clients",
|
|
54
|
+
target = "react",
|
|
54
55
|
injectEnvironment = true
|
|
55
56
|
} = options;
|
|
56
57
|
const globalConfig = {
|
|
57
58
|
outDir,
|
|
58
|
-
clientManagerPath
|
|
59
|
+
clientManagerPath,
|
|
60
|
+
target
|
|
59
61
|
};
|
|
60
62
|
const projectRoot = process.cwd();
|
|
61
63
|
const resolveDidPath = (didFile) => path.normalize(
|
|
@@ -116,7 +118,7 @@ function icReactor(options) {
|
|
|
116
118
|
},
|
|
117
119
|
async buildStart() {
|
|
118
120
|
console.log(
|
|
119
|
-
`[ic-reactor] Generating
|
|
121
|
+
`[ic-reactor] Generating canister bindings for ${canisters.length} canisters...`
|
|
120
122
|
);
|
|
121
123
|
for (const canisterConfig of canisters) {
|
|
122
124
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/vite-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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.9.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
|
@@ -181,6 +181,7 @@ describe("icReactor", () => {
|
|
|
181
181
|
globalConfig: {
|
|
182
182
|
outDir: "src/declarations",
|
|
183
183
|
clientManagerPath: "../../clients",
|
|
184
|
+
target: "react",
|
|
184
185
|
},
|
|
185
186
|
})
|
|
186
187
|
})
|
|
@@ -227,6 +228,26 @@ describe("icReactor", () => {
|
|
|
227
228
|
globalConfig: {
|
|
228
229
|
outDir: "src/declarations",
|
|
229
230
|
clientManagerPath: "../../clients",
|
|
231
|
+
target: "react",
|
|
232
|
+
},
|
|
233
|
+
})
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
it("should pass the configured runtime target to codegen", async () => {
|
|
237
|
+
const plugin = createVitePlugin({
|
|
238
|
+
...mockOptions,
|
|
239
|
+
target: "core",
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
await (plugin.buildStart as any)()
|
|
243
|
+
|
|
244
|
+
expect(runCanisterPipeline).toHaveBeenCalledWith({
|
|
245
|
+
canisterConfig: mockOptions.canisters[0],
|
|
246
|
+
projectRoot: expect.any(String),
|
|
247
|
+
globalConfig: {
|
|
248
|
+
outDir: "src/declarations",
|
|
249
|
+
clientManagerPath: "../../clients",
|
|
250
|
+
target: "core",
|
|
230
251
|
},
|
|
231
252
|
})
|
|
232
253
|
})
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
runCanisterPipeline,
|
|
14
14
|
type CanisterConfig,
|
|
15
15
|
type CodegenConfig,
|
|
16
|
+
type CodegenTarget,
|
|
16
17
|
} from "@ic-reactor/codegen"
|
|
17
18
|
import { getIcEnvironmentInfo, buildIcEnvCookie } from "./env.js"
|
|
18
19
|
|
|
@@ -32,6 +33,11 @@ export interface IcReactorPluginOptions {
|
|
|
32
33
|
* Default: "../../clients"
|
|
33
34
|
*/
|
|
34
35
|
clientManagerPath?: string
|
|
36
|
+
/**
|
|
37
|
+
* Default generated runtime target.
|
|
38
|
+
* Default: "react"
|
|
39
|
+
*/
|
|
40
|
+
target?: CodegenTarget
|
|
35
41
|
/**
|
|
36
42
|
* Automatically inject `ic_env` cookie for local development?
|
|
37
43
|
* Default: true
|
|
@@ -44,13 +50,18 @@ export function icReactor(options: IcReactorPluginOptions): any {
|
|
|
44
50
|
canisters,
|
|
45
51
|
outDir = "src/declarations",
|
|
46
52
|
clientManagerPath = "../../clients",
|
|
53
|
+
target = "react",
|
|
47
54
|
injectEnvironment = true,
|
|
48
55
|
} = options
|
|
49
56
|
|
|
50
57
|
// Construct a partial CodegenConfig to pass to the pipeline
|
|
51
|
-
const globalConfig: Pick<
|
|
58
|
+
const globalConfig: Pick<
|
|
59
|
+
CodegenConfig,
|
|
60
|
+
"outDir" | "clientManagerPath" | "target"
|
|
61
|
+
> = {
|
|
52
62
|
outDir,
|
|
53
63
|
clientManagerPath,
|
|
64
|
+
target,
|
|
54
65
|
}
|
|
55
66
|
const projectRoot = process.cwd()
|
|
56
67
|
const resolveDidPath = (didFile: string) =>
|
|
@@ -131,7 +142,7 @@ export function icReactor(options: IcReactorPluginOptions): any {
|
|
|
131
142
|
// ── Code Generation ──────────────────────────────────────────────────
|
|
132
143
|
|
|
133
144
|
console.log(
|
|
134
|
-
`[ic-reactor] Generating
|
|
145
|
+
`[ic-reactor] Generating canister bindings for ${canisters.length} canisters...`
|
|
135
146
|
)
|
|
136
147
|
|
|
137
148
|
for (const canisterConfig of canisters) {
|