@bino0216/nitro-cloudflare-dev 0.2.5 → 0.2.7
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 +4 -4
- package/dist/index.d.mts +14 -9
- package/dist/index.d.ts +14 -9
- package/dist/index.mjs +6 -7
- package/dist/runtime/plugin.dev.d.ts +1 -1
- package/dist/runtime/plugin.dev.mjs +18 -9
- package/package.json +6 -10
package/README.md
CHANGED
|
@@ -17,18 +17,18 @@ For **Nuxt** update `nuxt.config.ts`:
|
|
|
17
17
|
|
|
18
18
|
```js
|
|
19
19
|
export default defineNuxtConfig({
|
|
20
|
-
modules: [
|
|
21
|
-
})
|
|
20
|
+
modules: ['nitro-cloudflare-dev'],
|
|
21
|
+
})
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
For **Nitro** update `nitro.config.ts`:
|
|
25
25
|
|
|
26
26
|
```js
|
|
27
|
-
import nitroCloudflareBindings from
|
|
27
|
+
import nitroCloudflareBindings from 'nitro-cloudflare-dev'
|
|
28
28
|
|
|
29
29
|
export default defineNitroConfig({
|
|
30
30
|
modules: [nitroCloudflareBindings],
|
|
31
|
-
})
|
|
31
|
+
})
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
## Configuration and persistence
|
package/dist/index.d.mts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { PlatformProxy } from 'wrangler';
|
|
2
2
|
|
|
3
|
-
declare module
|
|
3
|
+
declare module 'h3' {
|
|
4
4
|
interface H3EventContext {
|
|
5
|
-
cf: PlatformProxy[
|
|
5
|
+
cf: PlatformProxy['cf'];
|
|
6
6
|
cloudflare: {
|
|
7
7
|
request: Request & {
|
|
8
|
-
cf: PlatformProxy[
|
|
8
|
+
cf: PlatformProxy['cf'];
|
|
9
9
|
};
|
|
10
|
-
env: PlatformProxy[
|
|
11
|
-
context: PlatformProxy[
|
|
10
|
+
env: PlatformProxy['env'];
|
|
11
|
+
context: PlatformProxy['ctx'];
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
interface RemoteBinding {
|
|
17
|
-
type:
|
|
17
|
+
type: 'r2' | 'kv' | 'd1';
|
|
18
18
|
name: string;
|
|
19
19
|
bucketName?: string;
|
|
20
20
|
databaseId?: string;
|
|
@@ -25,16 +25,21 @@ interface CloudflareDevOptions {
|
|
|
25
25
|
environment?: string;
|
|
26
26
|
persistDir?: string;
|
|
27
27
|
silent?: boolean;
|
|
28
|
-
|
|
28
|
+
remoteCredentials?: {
|
|
29
29
|
accountId?: string;
|
|
30
30
|
apiToken?: string;
|
|
31
|
+
r2?: {
|
|
32
|
+
accessKeyId: string;
|
|
33
|
+
secretAccessKey: string;
|
|
34
|
+
};
|
|
31
35
|
};
|
|
32
36
|
}
|
|
33
|
-
declare module
|
|
37
|
+
declare module 'nitropack' {
|
|
34
38
|
interface NitroOptions {
|
|
35
39
|
cloudflareDev?: CloudflareDevOptions;
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
42
|
declare function nitroCloudflareDev(arg1: unknown, arg2: unknown): void;
|
|
39
43
|
|
|
40
|
-
export {
|
|
44
|
+
export { nitroCloudflareDev as default };
|
|
45
|
+
export type { CloudflareDevOptions, RemoteBinding };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { PlatformProxy } from 'wrangler';
|
|
2
2
|
|
|
3
|
-
declare module
|
|
3
|
+
declare module 'h3' {
|
|
4
4
|
interface H3EventContext {
|
|
5
|
-
cf: PlatformProxy[
|
|
5
|
+
cf: PlatformProxy['cf'];
|
|
6
6
|
cloudflare: {
|
|
7
7
|
request: Request & {
|
|
8
|
-
cf: PlatformProxy[
|
|
8
|
+
cf: PlatformProxy['cf'];
|
|
9
9
|
};
|
|
10
|
-
env: PlatformProxy[
|
|
11
|
-
context: PlatformProxy[
|
|
10
|
+
env: PlatformProxy['env'];
|
|
11
|
+
context: PlatformProxy['ctx'];
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
interface RemoteBinding {
|
|
17
|
-
type:
|
|
17
|
+
type: 'r2' | 'kv' | 'd1';
|
|
18
18
|
name: string;
|
|
19
19
|
bucketName?: string;
|
|
20
20
|
databaseId?: string;
|
|
@@ -25,16 +25,21 @@ interface CloudflareDevOptions {
|
|
|
25
25
|
environment?: string;
|
|
26
26
|
persistDir?: string;
|
|
27
27
|
silent?: boolean;
|
|
28
|
-
|
|
28
|
+
remoteCredentials?: {
|
|
29
29
|
accountId?: string;
|
|
30
30
|
apiToken?: string;
|
|
31
|
+
r2?: {
|
|
32
|
+
accessKeyId: string;
|
|
33
|
+
secretAccessKey: string;
|
|
34
|
+
};
|
|
31
35
|
};
|
|
32
36
|
}
|
|
33
|
-
declare module
|
|
37
|
+
declare module 'nitropack' {
|
|
34
38
|
interface NitroOptions {
|
|
35
39
|
cloudflareDev?: CloudflareDevOptions;
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
42
|
declare function nitroCloudflareDev(arg1: unknown, arg2: unknown): void;
|
|
39
43
|
|
|
40
|
-
export {
|
|
44
|
+
export { nitroCloudflareDev as default };
|
|
45
|
+
export type { CloudflareDevOptions, RemoteBinding };
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { resolve, relative } from 'node:path';
|
|
2
1
|
import { promises } from 'node:fs';
|
|
3
|
-
import {
|
|
2
|
+
import { resolve, relative } from 'node:path';
|
|
4
3
|
import { consola } from 'consola';
|
|
5
4
|
import { colorize } from 'consola/utils';
|
|
5
|
+
import { fileURLToPath } from 'mlly';
|
|
6
6
|
import { findFile } from 'pkg-types';
|
|
7
7
|
|
|
8
8
|
function parseTomlBindings(content, key) {
|
|
@@ -150,7 +150,9 @@ async function nitroModule(nitro) {
|
|
|
150
150
|
if (gitIgnorePath && persistDir === ".wrangler/state/v3") {
|
|
151
151
|
const gitIgnore = await promises.readFile(gitIgnorePath, "utf8");
|
|
152
152
|
if (!gitIgnore.includes(".wrangler/state/v3")) {
|
|
153
|
-
await promises.writeFile(gitIgnorePath, gitIgnore
|
|
153
|
+
await promises.writeFile(gitIgnorePath, `${gitIgnore}
|
|
154
|
+
.wrangler/state/v3
|
|
155
|
+
`).catch(() => {
|
|
154
156
|
});
|
|
155
157
|
addedToGitIgnore = true;
|
|
156
158
|
}
|
|
@@ -174,10 +176,7 @@ Remote bindings: ${remoteBindings.map((b) => `${b.name} (${b.type})`).join(", ")
|
|
|
174
176
|
persistDir,
|
|
175
177
|
environment: nitro.options.cloudflareDev?.environment,
|
|
176
178
|
remoteBindings,
|
|
177
|
-
remoteCredentials:
|
|
178
|
-
accountId: nitro.options.cloudflareDev?.remote?.accountId || process.env.CF_ACCOUNT_ID,
|
|
179
|
-
apiToken: nitro.options.cloudflareDev?.remote?.apiToken || process.env.CF_API_TOKEN
|
|
180
|
-
}
|
|
179
|
+
remoteCredentials: nitro.options.cloudflareDev?.remoteCredentials
|
|
181
180
|
};
|
|
182
181
|
nitro.options.externals.inline = nitro.options.externals.inline || [];
|
|
183
182
|
nitro.options.externals.inline.push(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getRequestURL, useRuntimeConfig } from "#imports";
|
|
2
2
|
const _proxy = _getPlatformProxy().catch((error) => {
|
|
3
3
|
console.error("Failed to initialize wrangler bindings proxy", error);
|
|
4
4
|
return _createStubProxy();
|
|
@@ -47,29 +47,38 @@ async function _getPlatformProxy() {
|
|
|
47
47
|
proxyOptions.environment = runtimeConfig.wrangler.environment;
|
|
48
48
|
}
|
|
49
49
|
const proxy = await getPlatformProxy(proxyOptions);
|
|
50
|
-
|
|
50
|
+
const { accountId, apiToken, r2 } = remoteCredentials;
|
|
51
|
+
if (!accountId || !apiToken) {
|
|
52
|
+
console.warn("config remoteCredentials is empty. then remote is not working");
|
|
53
|
+
}
|
|
54
|
+
if (remoteBindings.length > 0 && accountId && apiToken) {
|
|
55
|
+
const config = { accountId, apiToken };
|
|
51
56
|
const { createR2Binding, createKVBinding, createD1Binding } = await import("openwrangler");
|
|
52
|
-
const bindingsConfig = {
|
|
53
|
-
accountId: remoteCredentials.accountId,
|
|
54
|
-
apiToken: remoteCredentials.apiToken
|
|
55
|
-
};
|
|
56
57
|
for (const binding of remoteBindings) {
|
|
57
58
|
switch (binding.type) {
|
|
58
59
|
case "r2": {
|
|
59
60
|
if (binding.bucketName) {
|
|
60
|
-
|
|
61
|
+
if (r2) {
|
|
62
|
+
proxy.env[binding.name] = createR2Binding({
|
|
63
|
+
...config,
|
|
64
|
+
r2AccessKeyId: r2.accessKeyId,
|
|
65
|
+
r2SecretAccessKey: r2.secretAccessKey
|
|
66
|
+
}, binding.bucketName);
|
|
67
|
+
} else {
|
|
68
|
+
console.warn("remoteCredentials r2 is empty, then remote is not working");
|
|
69
|
+
}
|
|
61
70
|
}
|
|
62
71
|
break;
|
|
63
72
|
}
|
|
64
73
|
case "kv": {
|
|
65
74
|
if (binding.namespaceId) {
|
|
66
|
-
proxy.env[binding.name] = createKVBinding(
|
|
75
|
+
proxy.env[binding.name] = createKVBinding(config, binding.namespaceId);
|
|
67
76
|
}
|
|
68
77
|
break;
|
|
69
78
|
}
|
|
70
79
|
case "d1": {
|
|
71
80
|
if (binding.databaseId) {
|
|
72
|
-
proxy.env[binding.name] = createD1Binding(
|
|
81
|
+
proxy.env[binding.name] = createD1Binding(config, binding.databaseId);
|
|
73
82
|
}
|
|
74
83
|
break;
|
|
75
84
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bino0216/nitro-cloudflare-dev",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.2.7",
|
|
3
5
|
"private": false,
|
|
4
|
-
"version": "0.2.5",
|
|
5
6
|
"description": "POC module to enable access to the Cloudflare runtime bindings in development server of Nitro and Nuxt",
|
|
6
|
-
"repository": "pi0/nitro-cloudflare-dev",
|
|
7
7
|
"license": "MIT",
|
|
8
|
+
"repository": "pi0/nitro-cloudflare-dev",
|
|
8
9
|
"sideEffects": false,
|
|
9
|
-
"type": "module",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
@@ -22,14 +22,11 @@
|
|
|
22
22
|
"files": [
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
|
-
"resolutions": {
|
|
26
|
-
"@binochoi/nitro-cloudflare-dev": "workspace:*"
|
|
27
|
-
},
|
|
28
25
|
"dependencies": {
|
|
29
26
|
"consola": "^3.4.0",
|
|
30
27
|
"mlly": "^1.7.4",
|
|
31
|
-
"
|
|
32
|
-
"
|
|
28
|
+
"pkg-types": "^2.1.0",
|
|
29
|
+
"openwrangler": "0.0.5"
|
|
33
30
|
},
|
|
34
31
|
"devDependencies": {
|
|
35
32
|
"@cloudflare/workers-types": "^4.20250303.0",
|
|
@@ -44,8 +41,7 @@
|
|
|
44
41
|
"nuxt": "^3.15.4",
|
|
45
42
|
"prettier": "^3.5.3",
|
|
46
43
|
"typescript": "^5.8.2",
|
|
47
|
-
"unbuild": "^3.5.0"
|
|
48
|
-
"wrangler": "^3.113.0"
|
|
44
|
+
"unbuild": "^3.5.0"
|
|
49
45
|
},
|
|
50
46
|
"publishConfig": {
|
|
51
47
|
"access": "public"
|