unplugin-cloudflare-tunnel 0.0.3 → 0.0.5
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/.github/README.md +141 -0
- package/dist/api.d.mts +37 -37
- package/dist/api.mjs +2 -4
- package/dist/astro.mjs +3 -5
- package/dist/esbuild.d.mts +2 -3
- package/dist/esbuild.mjs +1 -4
- package/dist/farm.d.mts +0 -1
- package/dist/farm.mjs +1 -4
- package/dist/index.d.mts +39 -39
- package/dist/index.mjs +24 -31
- package/dist/rolldown.d.mts +3681 -3
- package/dist/rolldown.mjs +1 -4
- package/dist/rollup.d.mts +2 -3
- package/dist/rollup.mjs +1 -4
- package/dist/rspack.d.mts +2 -3
- package/dist/rspack.mjs +1 -4
- package/dist/{schemas-CwcXCIyR.mjs → schemas-Cpk3vGGi.mjs} +46 -195
- package/dist/schemas-DKJtFAG_.d.mts +702 -0
- package/dist/virtual.d.mts +0 -1
- package/dist/vite.d.mts +2 -3
- package/dist/vite.mjs +1 -4
- package/dist/webpack.d.mts +2 -3
- package/dist/webpack.mjs +1 -4
- package/package.json +37 -25
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# unplugin-cloudflare-tunnel
|
|
2
|
+
|
|
3
|
+
[](https://npm.im/unplugin-cloudflare-tunnel)
|
|
4
|
+
[](https://pkg.pr.new/~/o-az/unplugin-cloudflare-tunnel)
|
|
5
|
+
|
|
6
|
+
A plugin that automatically creates and manages Cloudflare tunnels for local development.
|
|
7
|
+
Available for:
|
|
8
|
+
|
|
9
|
+
- [Vite](https://vite.dev),
|
|
10
|
+
- [Rspack](https://rspack.rs)
|
|
11
|
+
- [Webpack](https://webpack.js.org)
|
|
12
|
+
- [Astro](https://astro.build) <sup>soon</sup>
|
|
13
|
+
- [Farm](https://farmfe.org) <sup>soon</sup>
|
|
14
|
+
- [esbuild](https://esbuild.github.io) <sup>soon</sup>
|
|
15
|
+
- [Rollup](https://rollupjs.org) <sup>soon</sup>
|
|
16
|
+
- [Rolldown](https://rolldown.rs) <sup>soon</sup>
|
|
17
|
+
|
|
18
|
+
> [!NOTE]
|
|
19
|
+
> This is under active development.
|
|
20
|
+
> If you have any suggestions, I'm all ears, please open an issue.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
unplugin-cloudflare-tunnel
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm add unplugin-cloudflare-tunnel
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
<details>
|
|
33
|
+
<summary>Vite</summary><br>
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
// vite.config.ts
|
|
37
|
+
import CloudflareTunnel from 'unplugin-cloudflare-tunnel/vite'
|
|
38
|
+
|
|
39
|
+
export default defineConfig({
|
|
40
|
+
plugins: [
|
|
41
|
+
CloudflareTunnel(),
|
|
42
|
+
],
|
|
43
|
+
})
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Example in [./example/vite.config.ts](../example/vite.config.ts): `bun --filter example dev:vite`
|
|
47
|
+
|
|
48
|
+
<br></details>
|
|
49
|
+
|
|
50
|
+
<details>
|
|
51
|
+
<summary>Rspack</summary><br>
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
// rspack.config.mjs
|
|
55
|
+
import CloudflareTunnel from 'unplugin-cloudflare-tunnel/rspack'
|
|
56
|
+
|
|
57
|
+
export default {
|
|
58
|
+
/* ... */
|
|
59
|
+
plugins: [
|
|
60
|
+
CloudflareTunnel(),
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Example in [./example/rspack.config.ts](../example/rspack.config.ts): `bun --filter example dev:rspack`
|
|
66
|
+
|
|
67
|
+
<br></details>
|
|
68
|
+
|
|
69
|
+
<details>
|
|
70
|
+
<summary>Webpack</summary><br>
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
// webpack.config.js
|
|
74
|
+
module.exports = {
|
|
75
|
+
/* ... */
|
|
76
|
+
plugins: [
|
|
77
|
+
require('unplugin-cloudflare-tunnel/webpack')({
|
|
78
|
+
CloudflareTunnel(),
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Example in [./example/webpack.config.ts](../example/webpack.config.ts): `bun --filter example dev:webpack`
|
|
84
|
+
|
|
85
|
+
<br></details>
|
|
86
|
+
|
|
87
|
+
## Virtual Module: Access Tunnel URL
|
|
88
|
+
|
|
89
|
+
> [!NOTE]
|
|
90
|
+
> This feature is only available in Vite and Vite-based frameworks (i.e., Astro)
|
|
91
|
+
|
|
92
|
+
The plugin provides a virtual module that allows you to access the tunnel URL in your application code during development. This is useful for:
|
|
93
|
+
|
|
94
|
+
- Displaying the tunnel URL in your UI
|
|
95
|
+
- Sharing the URL with users
|
|
96
|
+
- Debugging and logging
|
|
97
|
+
- Building features that need the public URL
|
|
98
|
+
|
|
99
|
+
### Usage
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { getTunnelUrl } from 'virtual:unplugin-cloudflare-tunnel'
|
|
103
|
+
|
|
104
|
+
// Get the current tunnel URL
|
|
105
|
+
const tunnelUrl = getTunnelUrl()
|
|
106
|
+
console.log('Public tunnel URL:', tunnelUrl)
|
|
107
|
+
|
|
108
|
+
// Example: Copy tunnel URL to clipboard
|
|
109
|
+
const shareButton = document.getElementById('share')
|
|
110
|
+
shareButton.onclick = () => {
|
|
111
|
+
navigator.clipboard.writeText(getTunnelUrl())
|
|
112
|
+
alert('Tunnel URL copied!')
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### TypeScript Support
|
|
117
|
+
|
|
118
|
+
To get TypeScript support for the virtual module, add a reference to the types:
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
// In your tsconfig.json or a .d.ts file
|
|
122
|
+
/// <reference types="unplugin-cloudflare-tunnel/virtual" />
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Or create a `virtual.d.ts` file in your project:
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
/// <reference types="unplugin-cloudflare-tunnel/virtual" />
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Return Value
|
|
132
|
+
|
|
133
|
+
- **Quick tunnel mode**: Returns a random URL like `https://abc-123.trycloudflare.com`
|
|
134
|
+
- **Named tunnel mode**: Returns your custom domain URL like `https://dev.example.com`
|
|
135
|
+
- **Plugin disabled**: Returns an empty string `""`
|
|
136
|
+
|
|
137
|
+
### Notes
|
|
138
|
+
|
|
139
|
+
- The virtual module is only available during development mode
|
|
140
|
+
- In production builds, the virtual module will not be available
|
|
141
|
+
- The URL is automatically updated if the port changes or tunnel restarts
|
package/dist/api.d.mts
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { a as ZodMiniObject, c as ZodMiniUnknown, i as ZodMiniNumber, n as ZodMiniBoolean, o as ZodMiniOptional, r as ZodMiniNullable, s as ZodMiniString, t as ZodMiniArray, u as $strip } from "./schemas-DKJtFAG_.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/api.d.ts
|
|
4
|
-
declare const CloudflareErrorSchema:
|
|
5
|
-
code:
|
|
6
|
-
message:
|
|
7
|
-
},
|
|
8
|
-
declare const CloudflareApiResponseSchema:
|
|
9
|
-
success:
|
|
10
|
-
errors:
|
|
11
|
-
code:
|
|
12
|
-
message:
|
|
13
|
-
},
|
|
14
|
-
messages:
|
|
15
|
-
result:
|
|
16
|
-
},
|
|
17
|
-
declare const AccountSchema:
|
|
18
|
-
id:
|
|
19
|
-
name:
|
|
20
|
-
},
|
|
21
|
-
declare const ZoneSchema:
|
|
22
|
-
id:
|
|
23
|
-
name:
|
|
24
|
-
},
|
|
25
|
-
declare const TunnelSchema:
|
|
26
|
-
id:
|
|
27
|
-
name:
|
|
28
|
-
account_tag:
|
|
29
|
-
created_at:
|
|
30
|
-
connections:
|
|
31
|
-
},
|
|
32
|
-
declare const DNSRecordSchema:
|
|
33
|
-
id:
|
|
34
|
-
type:
|
|
35
|
-
name:
|
|
36
|
-
content:
|
|
37
|
-
proxied:
|
|
38
|
-
comment:
|
|
39
|
-
},
|
|
4
|
+
declare const CloudflareErrorSchema: ZodMiniObject<{
|
|
5
|
+
code: ZodMiniNumber<number>;
|
|
6
|
+
message: ZodMiniString<string>;
|
|
7
|
+
}, $strip>;
|
|
8
|
+
declare const CloudflareApiResponseSchema: ZodMiniObject<{
|
|
9
|
+
success: ZodMiniBoolean<boolean>;
|
|
10
|
+
errors: ZodMiniOptional<ZodMiniArray<ZodMiniObject<{
|
|
11
|
+
code: ZodMiniNumber<number>;
|
|
12
|
+
message: ZodMiniString<string>;
|
|
13
|
+
}, $strip>>>;
|
|
14
|
+
messages: ZodMiniOptional<ZodMiniArray<ZodMiniString<string>>>;
|
|
15
|
+
result: ZodMiniUnknown;
|
|
16
|
+
}, $strip>;
|
|
17
|
+
declare const AccountSchema: ZodMiniObject<{
|
|
18
|
+
id: ZodMiniString<string>;
|
|
19
|
+
name: ZodMiniString<string>;
|
|
20
|
+
}, $strip>;
|
|
21
|
+
declare const ZoneSchema: ZodMiniObject<{
|
|
22
|
+
id: ZodMiniString<string>;
|
|
23
|
+
name: ZodMiniString<string>;
|
|
24
|
+
}, $strip>;
|
|
25
|
+
declare const TunnelSchema: ZodMiniObject<{
|
|
26
|
+
id: ZodMiniString<string>;
|
|
27
|
+
name: ZodMiniString<string>;
|
|
28
|
+
account_tag: ZodMiniString<string>;
|
|
29
|
+
created_at: ZodMiniString<string>;
|
|
30
|
+
connections: ZodMiniOptional<ZodMiniArray<ZodMiniUnknown>>;
|
|
31
|
+
}, $strip>;
|
|
32
|
+
declare const DNSRecordSchema: ZodMiniObject<{
|
|
33
|
+
id: ZodMiniString<string>;
|
|
34
|
+
type: ZodMiniString<string>;
|
|
35
|
+
name: ZodMiniString<string>;
|
|
36
|
+
content: ZodMiniString<string>;
|
|
37
|
+
proxied: ZodMiniBoolean<boolean>;
|
|
38
|
+
comment: ZodMiniOptional<ZodMiniNullable<ZodMiniString<string>>>;
|
|
39
|
+
}, $strip>;
|
|
40
40
|
declare function normalizeAddress(address: string | {
|
|
41
41
|
address?: string;
|
|
42
42
|
port?: number;
|
package/dist/api.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { a as number, c as string, i as nullish, l as unknown, n as array, o as object, r as boolean, s as optional } from "./schemas-
|
|
1
|
+
import { a as number, c as string, i as nullish, l as unknown, n as array, o as object, r as boolean, s as optional } from "./schemas-Cpk3vGGi.mjs";
|
|
2
2
|
import NodeFS from "node:fs/promises";
|
|
3
3
|
import { install } from "cloudflared";
|
|
4
|
-
|
|
5
4
|
//#region src/api.ts
|
|
6
5
|
const CloudflareErrorSchema = object({
|
|
7
6
|
code: number(),
|
|
@@ -54,6 +53,5 @@ async function ensureCloudflaredBinary(binPath) {
|
|
|
54
53
|
function getLocalTarget(host, port) {
|
|
55
54
|
return `http://${host.includes(":") ? `[${host}]` : host}:${port}`;
|
|
56
55
|
}
|
|
57
|
-
|
|
58
56
|
//#endregion
|
|
59
|
-
export { AccountSchema, CloudflareApiResponseSchema, CloudflareErrorSchema, DNSRecordSchema, TunnelSchema, ZoneSchema, ensureCloudflaredBinary, getLocalTarget, normalizeAddress };
|
|
57
|
+
export { AccountSchema, CloudflareApiResponseSchema, CloudflareErrorSchema, DNSRecordSchema, TunnelSchema, ZoneSchema, ensureCloudflaredBinary, getLocalTarget, normalizeAddress };
|
package/dist/astro.mjs
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { CloudflareTunnel } from "./index.mjs";
|
|
3
2
|
//#region src/astro.ts
|
|
4
3
|
var astro_default = (options) => ({
|
|
5
4
|
name: "unplugin-cloudflare-tunnel",
|
|
6
5
|
hooks: { "astro:config:setup": async (astro) => {
|
|
7
6
|
astro.config.vite.plugins ||= [];
|
|
8
|
-
astro.config.vite.plugins.push(
|
|
7
|
+
astro.config.vite.plugins.push(CloudflareTunnel.vite(options));
|
|
9
8
|
} }
|
|
10
9
|
});
|
|
11
|
-
|
|
12
10
|
//#endregion
|
|
13
|
-
export { astro_default as default };
|
|
11
|
+
export { astro_default as default };
|
package/dist/esbuild.d.mts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { CloudflareTunnelOptions } from "./index.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _$esbuild from "esbuild";
|
|
3
3
|
|
|
4
4
|
//#region src/esbuild.d.ts
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* This entry file is for esbuild plugin.
|
|
8
7
|
*
|
|
@@ -19,6 +18,6 @@ import * as esbuild0 from "esbuild";
|
|
|
19
18
|
* build({ plugins: [Starter()] })
|
|
20
19
|
```
|
|
21
20
|
*/
|
|
22
|
-
declare const esbuild: (options?: CloudflareTunnelOptions | undefined) =>
|
|
21
|
+
declare const esbuild: (options?: CloudflareTunnelOptions | undefined) => _$esbuild.Plugin;
|
|
23
22
|
//#endregion
|
|
24
23
|
export { esbuild as default, esbuild as "module.exports" };
|
package/dist/esbuild.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CloudflareTunnel } from "./index.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/esbuild.ts
|
|
4
3
|
/**
|
|
5
4
|
* This entry file is for esbuild plugin.
|
|
@@ -18,7 +17,5 @@ import { CloudflareTunnel } from "./index.mjs";
|
|
|
18
17
|
```
|
|
19
18
|
*/
|
|
20
19
|
const esbuild = CloudflareTunnel.esbuild;
|
|
21
|
-
var esbuild_default = esbuild;
|
|
22
|
-
|
|
23
20
|
//#endregion
|
|
24
|
-
export {
|
|
21
|
+
export { esbuild as default, esbuild as "module.exports" };
|
package/dist/farm.d.mts
CHANGED
package/dist/farm.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CloudflareTunnel } from "./index.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/farm.ts
|
|
4
3
|
/**
|
|
5
4
|
* This entry file is for Farm plugin.
|
|
@@ -20,7 +19,5 @@ import { CloudflareTunnel } from "./index.mjs";
|
|
|
20
19
|
* ```
|
|
21
20
|
*/
|
|
22
21
|
const farm = CloudflareTunnel.farm;
|
|
23
|
-
var farm_default = farm;
|
|
24
|
-
|
|
25
22
|
//#endregion
|
|
26
|
-
export {
|
|
23
|
+
export { farm as default, farm as "module.exports" };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { a as ZodMiniObject, c as ZodMiniUnknown, i as ZodMiniNumber, l as output, n as ZodMiniBoolean, o as ZodMiniOptional, r as ZodMiniNullable, s as ZodMiniString, t as ZodMiniArray, u as $strip } from "./schemas-DKJtFAG_.mjs";
|
|
1
2
|
import { UnpluginInstance } from "unplugin";
|
|
2
|
-
import * as z from "zod/mini";
|
|
3
3
|
|
|
4
4
|
//#region src/index.d.ts
|
|
5
5
|
/**
|
|
@@ -13,45 +13,45 @@ import * as z from "zod/mini";
|
|
|
13
13
|
* @version 1.0.0
|
|
14
14
|
* @license MIT
|
|
15
15
|
*/
|
|
16
|
-
declare const CloudflareApiResponseSchema:
|
|
17
|
-
success:
|
|
18
|
-
errors:
|
|
19
|
-
code:
|
|
20
|
-
message:
|
|
21
|
-
},
|
|
22
|
-
messages:
|
|
23
|
-
result:
|
|
24
|
-
},
|
|
25
|
-
declare const AccountSchema:
|
|
26
|
-
id:
|
|
27
|
-
name:
|
|
28
|
-
},
|
|
29
|
-
declare const ZoneSchema:
|
|
30
|
-
id:
|
|
31
|
-
name:
|
|
32
|
-
},
|
|
33
|
-
declare const TunnelSchema:
|
|
34
|
-
id:
|
|
35
|
-
name:
|
|
36
|
-
account_tag:
|
|
37
|
-
created_at:
|
|
38
|
-
connections:
|
|
39
|
-
},
|
|
40
|
-
declare const DNSRecordSchema:
|
|
41
|
-
id:
|
|
42
|
-
type:
|
|
43
|
-
name:
|
|
44
|
-
content:
|
|
45
|
-
proxied:
|
|
46
|
-
comment:
|
|
47
|
-
},
|
|
48
|
-
type CloudflareApiResponse<T = unknown> =
|
|
16
|
+
declare const CloudflareApiResponseSchema: ZodMiniObject<{
|
|
17
|
+
success: ZodMiniBoolean<boolean>;
|
|
18
|
+
errors: ZodMiniOptional<ZodMiniArray<ZodMiniObject<{
|
|
19
|
+
code: ZodMiniNumber<number>;
|
|
20
|
+
message: ZodMiniString<string>;
|
|
21
|
+
}, $strip>>>;
|
|
22
|
+
messages: ZodMiniOptional<ZodMiniArray<ZodMiniString<string>>>;
|
|
23
|
+
result: ZodMiniUnknown;
|
|
24
|
+
}, $strip>;
|
|
25
|
+
declare const AccountSchema: ZodMiniObject<{
|
|
26
|
+
id: ZodMiniString<string>;
|
|
27
|
+
name: ZodMiniString<string>;
|
|
28
|
+
}, $strip>;
|
|
29
|
+
declare const ZoneSchema: ZodMiniObject<{
|
|
30
|
+
id: ZodMiniString<string>;
|
|
31
|
+
name: ZodMiniString<string>;
|
|
32
|
+
}, $strip>;
|
|
33
|
+
declare const TunnelSchema: ZodMiniObject<{
|
|
34
|
+
id: ZodMiniString<string>;
|
|
35
|
+
name: ZodMiniString<string>;
|
|
36
|
+
account_tag: ZodMiniString<string>;
|
|
37
|
+
created_at: ZodMiniString<string>;
|
|
38
|
+
connections: ZodMiniOptional<ZodMiniArray<ZodMiniUnknown>>;
|
|
39
|
+
}, $strip>;
|
|
40
|
+
declare const DNSRecordSchema: ZodMiniObject<{
|
|
41
|
+
id: ZodMiniString<string>;
|
|
42
|
+
type: ZodMiniString<string>;
|
|
43
|
+
name: ZodMiniString<string>;
|
|
44
|
+
content: ZodMiniString<string>;
|
|
45
|
+
proxied: ZodMiniBoolean<boolean>;
|
|
46
|
+
comment: ZodMiniOptional<ZodMiniNullable<ZodMiniString<string>>>;
|
|
47
|
+
}, $strip>;
|
|
48
|
+
type CloudflareApiResponse<T = unknown> = output<typeof CloudflareApiResponseSchema> & {
|
|
49
49
|
result: T;
|
|
50
50
|
};
|
|
51
|
-
type Account =
|
|
52
|
-
type Zone =
|
|
53
|
-
type Tunnel =
|
|
54
|
-
type DNSRecord =
|
|
51
|
+
type Account = output<typeof AccountSchema>;
|
|
52
|
+
type Zone = output<typeof ZoneSchema>;
|
|
53
|
+
type Tunnel = output<typeof TunnelSchema>;
|
|
54
|
+
type DNSRecord = output<typeof DNSRecordSchema>;
|
|
55
55
|
/**
|
|
56
56
|
* Base configuration options shared between named and quick tunnel modes
|
|
57
57
|
*/
|
|
@@ -103,7 +103,7 @@ interface NamedTunnelOptions extends BaseTunnelOptions {
|
|
|
103
103
|
*
|
|
104
104
|
* Fallback priority:
|
|
105
105
|
* 1. Provided apiToken option
|
|
106
|
-
* 2.
|
|
106
|
+
* 2. CLOUDFLARE_API_TOKEN environment variable
|
|
107
107
|
*/
|
|
108
108
|
apiToken?: string;
|
|
109
109
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { a as number, c as string, i as nullish, l as unknown, n as array, o as object, r as boolean, s as optional, t as any } from "./schemas-
|
|
1
|
+
import { a as number, c as string, i as nullish, l as unknown, n as array, o as object, r as boolean, s as optional, t as any } from "./schemas-Cpk3vGGi.mjs";
|
|
2
2
|
import { createUnplugin } from "unplugin";
|
|
3
3
|
import NodeFS from "node:fs/promises";
|
|
4
4
|
import { bin, install } from "cloudflared";
|
|
5
5
|
import * as NodeChildProcess from "node:child_process";
|
|
6
|
-
|
|
7
6
|
//#region src/index.ts
|
|
8
7
|
/**
|
|
9
8
|
* @fileoverview Cloudflare Tunnel Unplugin
|
|
@@ -42,8 +41,7 @@ const ANSI = {
|
|
|
42
41
|
blue: "\x1B[34m",
|
|
43
42
|
yellow: "\x1B[33m"
|
|
44
43
|
};
|
|
45
|
-
const
|
|
46
|
-
const ANSI_STYLE_SEQUENCE_REGEX = new RegExp(`${ANSI_ESCAPE}\\[[0-9;]*m`, "g");
|
|
44
|
+
const ANSI_STYLE_SEQUENCE_REGEX = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
|
|
47
45
|
function stripAnsi(text) {
|
|
48
46
|
return text.replace(ANSI_STYLE_SEQUENCE_REGEX, "");
|
|
49
47
|
}
|
|
@@ -176,10 +174,7 @@ const unpluginFactory = (options = {}) => {
|
|
|
176
174
|
globalState.__lastAnnouncedTunnelKey = params.key;
|
|
177
175
|
const cols = process.stdout.columns ?? 80;
|
|
178
176
|
const maxWidth = Math.max(10, cols - 2);
|
|
179
|
-
const
|
|
180
|
-
const header = (() => {
|
|
181
|
-
return `${colorize("[", ANSI.yellow)}${headerText}${colorize("]", ANSI.yellow)}`;
|
|
182
|
-
})();
|
|
177
|
+
const header = `${colorize("[", ANSI.yellow)}unplugin-cloudflare-tunnel${colorize("]", ANSI.yellow)}`;
|
|
183
178
|
const urlLine = colorize(params.url, ANSI.blue + ANSI.bold);
|
|
184
179
|
const localLine = params.localTarget ? makeLocalDisplay(params.localTarget) : "";
|
|
185
180
|
const headerPlainLen = stripAnsi(header).length;
|
|
@@ -192,12 +187,12 @@ const unpluginFactory = (options = {}) => {
|
|
|
192
187
|
return `${" ".repeat(pad)}${text}`;
|
|
193
188
|
};
|
|
194
189
|
if (cols < 70) {
|
|
195
|
-
const out
|
|
196
|
-
out
|
|
197
|
-
out
|
|
198
|
-
if (localLine) out
|
|
199
|
-
out
|
|
200
|
-
console.log(out
|
|
190
|
+
const out = [];
|
|
191
|
+
out.push("");
|
|
192
|
+
out.push(`${header} ${colorize("Tunnel URL", ANSI.bold)} ${urlLine}`);
|
|
193
|
+
if (localLine) out.push(`${header} ${colorize("Local", ANSI.dim + ANSI.bold)} ${localLine}`);
|
|
194
|
+
out.push("");
|
|
195
|
+
console.log(out.join("\n"));
|
|
201
196
|
return;
|
|
202
197
|
}
|
|
203
198
|
const out = [];
|
|
@@ -236,12 +231,12 @@ const unpluginFactory = (options = {}) => {
|
|
|
236
231
|
if (sslOption) {
|
|
237
232
|
if (!sslOption.startsWith("*.") && sslOption !== hostname) throw new Error("[unplugin-cloudflare-tunnel] ssl option must either be a wildcard (e.g., '*.example.com') or exactly match the hostname");
|
|
238
233
|
}
|
|
239
|
-
const trackSslCertificate = (certificateId, hosts, tunnelName
|
|
234
|
+
const trackSslCertificate = (certificateId, hosts, tunnelName, timestamp = (/* @__PURE__ */ new Date()).toISOString()) => {
|
|
240
235
|
const trackingKey = `ssl-cert-${certificateId}`;
|
|
241
236
|
globalState[trackingKey] = {
|
|
242
237
|
id: certificateId,
|
|
243
238
|
hosts,
|
|
244
|
-
tunnelName
|
|
239
|
+
tunnelName,
|
|
245
240
|
timestamp,
|
|
246
241
|
pluginVersion: "1.0.0"
|
|
247
242
|
};
|
|
@@ -371,7 +366,7 @@ const unpluginFactory = (options = {}) => {
|
|
|
371
366
|
if (logFile) cloudflaredArgs.push("--logfile", logFile);
|
|
372
367
|
cloudflaredArgs.push("--url", localTarget);
|
|
373
368
|
debugLog("Spawning quick tunnel:", bin, cloudflaredArgs);
|
|
374
|
-
const child
|
|
369
|
+
const child = NodeChildProcess.spawn(bin, cloudflaredArgs, {
|
|
375
370
|
stdio: [
|
|
376
371
|
"ignore",
|
|
377
372
|
"pipe",
|
|
@@ -381,27 +376,27 @@ const unpluginFactory = (options = {}) => {
|
|
|
381
376
|
windowsHide: true,
|
|
382
377
|
shell: process.platform === "win32"
|
|
383
378
|
});
|
|
384
|
-
debugLog(`[unplugin-cloudflare-tunnel] Quick tunnel process spawned with PID: ${child
|
|
379
|
+
debugLog(`[unplugin-cloudflare-tunnel] Quick tunnel process spawned with PID: ${child.pid}`);
|
|
385
380
|
return new Promise((resolve, reject) => {
|
|
386
381
|
let urlFound = false;
|
|
387
382
|
const timeout = setTimeout(() => {
|
|
388
383
|
if (!urlFound) reject(/* @__PURE__ */ new Error("Quick tunnel URL not found in output within 30 seconds"));
|
|
389
384
|
}, 3e4);
|
|
390
|
-
child
|
|
385
|
+
child.stdout?.on("data", (data) => {
|
|
391
386
|
const output = data.toString();
|
|
392
387
|
if (!globalState.shuttingDown || debug) {
|
|
393
388
|
if (effectiveLogLevel === "debug" || effectiveLogLevel === "info") console.log(`[cloudflared stdout] ${output.trim()}`);
|
|
394
389
|
else for (const line of output.split("\n")) if (!INFO_LOG_REGEX.test(line)) console.log(`[cloudflared stdout] ${line.trim()}`);
|
|
395
390
|
}
|
|
396
391
|
});
|
|
397
|
-
child
|
|
392
|
+
child.stderr?.on("data", (data) => {
|
|
398
393
|
const error = data.toString().trim();
|
|
399
394
|
const urlMatch = error.match(/https:\/\/[a-zA-Z0-9-]+\.trycloudflare\.com/);
|
|
400
395
|
if (urlMatch && !urlFound) {
|
|
401
396
|
urlFound = true;
|
|
402
397
|
clearTimeout(timeout);
|
|
403
398
|
resolve({
|
|
404
|
-
child
|
|
399
|
+
child,
|
|
405
400
|
url: urlMatch[0]
|
|
406
401
|
});
|
|
407
402
|
}
|
|
@@ -414,11 +409,11 @@ const unpluginFactory = (options = {}) => {
|
|
|
414
409
|
else for (const line of error.split("\n")) if (!INFO_LOG_REGEX.test(line)) console.error(`[cloudflared stderr] ${line.trim()}`);
|
|
415
410
|
}
|
|
416
411
|
});
|
|
417
|
-
child
|
|
412
|
+
child.on("error", (error) => {
|
|
418
413
|
clearTimeout(timeout);
|
|
419
414
|
reject(/* @__PURE__ */ new Error(`Failed to start quick tunnel process: ${error.message}`));
|
|
420
415
|
});
|
|
421
|
-
child
|
|
416
|
+
child.on("exit", (code, signal) => {
|
|
422
417
|
clearTimeout(timeout);
|
|
423
418
|
if (!urlFound) reject(/* @__PURE__ */ new Error(`Quick tunnel process exited before URL was found (code: ${code}, signal: ${signal})`));
|
|
424
419
|
});
|
|
@@ -527,10 +522,10 @@ const unpluginFactory = (options = {}) => {
|
|
|
527
522
|
debugLog("[unplugin-cloudflare-tunnel] Starting quick tunnel mode...");
|
|
528
523
|
debugLog("Quick tunnel mode - no API token or hostname required");
|
|
529
524
|
await ensureCloudflaredBinary(bin);
|
|
530
|
-
const localTarget
|
|
531
|
-
debugLog("← Quick tunnel connecting to local target", localTarget
|
|
525
|
+
const localTarget = getLocalTarget(serverHost, port);
|
|
526
|
+
debugLog("← Quick tunnel connecting to local target", localTarget);
|
|
532
527
|
try {
|
|
533
|
-
const { child: quickChild, url } = await spawnQuickTunnel(localTarget
|
|
528
|
+
const { child: quickChild, url } = await spawnQuickTunnel(localTarget);
|
|
534
529
|
tunnelUrl = url;
|
|
535
530
|
child = quickChild;
|
|
536
531
|
globalState.child = child;
|
|
@@ -586,8 +581,8 @@ const unpluginFactory = (options = {}) => {
|
|
|
586
581
|
}
|
|
587
582
|
}
|
|
588
583
|
debugLog("[unplugin-cloudflare-tunnel] Starting named tunnel mode...");
|
|
589
|
-
const apiToken = providedApiToken || process.env.
|
|
590
|
-
if (!apiToken) throw new Error("[unplugin-cloudflare-tunnel] API token is required. Provide it via 'apiToken' option or set the
|
|
584
|
+
const apiToken = providedApiToken || process.env.CLOUDFLARE_API_TOKEN;
|
|
585
|
+
if (!apiToken) throw new Error("[unplugin-cloudflare-tunnel] API token is required. Provide it via 'apiToken' option or set the CLOUDFLARE_API_TOKEN environment variable. Get your token at: https://dash.cloudflare.com/profile/api-tokens");
|
|
591
586
|
debugLog(`[unplugin-cloudflare-tunnel] Using port ${port}${userProvidedPort === port ? " (user-provided)" : " (from bundler config)"}`);
|
|
592
587
|
await ensureCloudflaredBinary(bin);
|
|
593
588
|
const accounts = await cf(apiToken, "GET", "/accounts", void 0, array(AccountSchema));
|
|
@@ -1012,7 +1007,5 @@ function getLocalTarget(host, port) {
|
|
|
1012
1007
|
return `http://${host.includes(":") ? `[${host}]` : host}:${port}`;
|
|
1013
1008
|
}
|
|
1014
1009
|
const CloudflareTunnel = createUnplugin(unpluginFactory);
|
|
1015
|
-
var src_default = CloudflareTunnel;
|
|
1016
|
-
|
|
1017
1010
|
//#endregion
|
|
1018
|
-
export { CloudflareTunnel,
|
|
1011
|
+
export { CloudflareTunnel, CloudflareTunnel as default };
|