@cloudflare/vite-plugin 1.39.1 → 1.40.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/bin/cf-vite +2 -0
- package/dist/cf-vite.mjs +113 -0
- package/dist/dist-MawCthRW.mjs +5414 -0
- package/dist/dist-MawCthRW.mjs.map +1 -0
- package/dist/experimental-config.d.mts +1434 -0
- package/dist/experimental-config.d.mts.map +1 -0
- package/dist/experimental-config.mjs +202 -0
- package/dist/experimental-config.mjs.map +1 -0
- package/dist/index.d.mts +18 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +732 -318
- package/dist/index.mjs.map +1 -1
- package/dist/{package-CtWVkw4A.mjs → package-Bo9FlzHY.mjs} +15 -7
- package/dist/package-Bo9FlzHY.mjs.map +1 -0
- package/package.json +22 -13
- package/dist/package-CtWVkw4A.mjs.map +0 -1
package/bin/cf-vite
ADDED
package/dist/cf-vite.mjs
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { createServer } from "vite";
|
|
3
|
+
|
|
4
|
+
//#region src/cf-vite.ts
|
|
5
|
+
/**
|
|
6
|
+
* `cf-vite` delegate binary entry point for `@cloudflare/vite-plugin`.
|
|
7
|
+
*
|
|
8
|
+
* EXPERIMENTAL / internal: spawned by Cloudflare's "cf-dev" parent
|
|
9
|
+
* process, not invoked directly by end users. Contract may change.
|
|
10
|
+
*
|
|
11
|
+
* Usage: `<pkgRoot>/bin/cf-vite <verb> [flags...]`. `dev` is the only
|
|
12
|
+
* verb today; future verbs follow the same shape. Unknown/missing verbs
|
|
13
|
+
* exit 2 (also the parent's version-detection signal).
|
|
14
|
+
*
|
|
15
|
+
* Spawn contract for `dev`: parent uses `stdio: "inherit"` and forwards
|
|
16
|
+
* SIGINT/SIGTERM. Accepted flags mirror the sibling `cf-wrangler`
|
|
17
|
+
* delegate (`--config`, `--mode`, `--port`, `--host`, `--local`) so the
|
|
18
|
+
* parent can drive either impl interchangeably; everything else lives in
|
|
19
|
+
* the user's `vite.config.ts` / `wrangler.jsonc`. `cf-vite` boots Vite
|
|
20
|
+
* via `createServer()` against the user's own config (expected to
|
|
21
|
+
* include `cloudflare()`); flags are bridged to it as documented inline.
|
|
22
|
+
*
|
|
23
|
+
* Exit codes: 0 graceful, 2 unknown verb / parse error, 130 SIGINT,
|
|
24
|
+
* 143 SIGTERM.
|
|
25
|
+
*/
|
|
26
|
+
var ArgParseError = class extends Error {
|
|
27
|
+
constructor(message) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.name = "ArgParseError";
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
/** Strict argv parser; mirrors `cf-wrangler`'s flags (unknown → throw). */
|
|
33
|
+
function parseArgs$1(argv) {
|
|
34
|
+
let parsed;
|
|
35
|
+
try {
|
|
36
|
+
parsed = parseArgs({
|
|
37
|
+
args: argv,
|
|
38
|
+
options: {
|
|
39
|
+
config: { type: "string" },
|
|
40
|
+
mode: { type: "string" },
|
|
41
|
+
host: { type: "string" },
|
|
42
|
+
port: { type: "string" },
|
|
43
|
+
local: { type: "boolean" }
|
|
44
|
+
},
|
|
45
|
+
strict: true,
|
|
46
|
+
allowPositionals: false
|
|
47
|
+
});
|
|
48
|
+
} catch (err) {
|
|
49
|
+
throw new ArgParseError(err instanceof Error ? err.message : String(err));
|
|
50
|
+
}
|
|
51
|
+
const out = {};
|
|
52
|
+
if (parsed.values.config !== void 0) out.config = parsed.values.config;
|
|
53
|
+
if (parsed.values.mode !== void 0) out.mode = parsed.values.mode;
|
|
54
|
+
if (parsed.values.host !== void 0) out.host = parsed.values.host;
|
|
55
|
+
if (parsed.values.port !== void 0) {
|
|
56
|
+
const raw = parsed.values.port;
|
|
57
|
+
const n = Number(raw);
|
|
58
|
+
if (!Number.isInteger(n) || n < 0 || n > 65535) throw new ArgParseError(`--port expects an integer between 0 and 65535, got "${raw}"`);
|
|
59
|
+
out.port = n;
|
|
60
|
+
}
|
|
61
|
+
if (parsed.values.local !== void 0) out.local = parsed.values.local;
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
async function main() {
|
|
65
|
+
const verb = process.argv[2];
|
|
66
|
+
const userArgv = process.argv.slice(3);
|
|
67
|
+
if (verb !== "dev") {
|
|
68
|
+
process.stderr.write(`Error: unknown subcommand "${verb ?? ""}".\nUsage: cf-vite dev [args]\n`);
|
|
69
|
+
return 2;
|
|
70
|
+
}
|
|
71
|
+
let args;
|
|
72
|
+
try {
|
|
73
|
+
args = parseArgs$1(userArgv);
|
|
74
|
+
} catch (err) {
|
|
75
|
+
if (err instanceof ArgParseError) {
|
|
76
|
+
process.stderr.write(`Error: ${err.message}\n`);
|
|
77
|
+
return 2;
|
|
78
|
+
}
|
|
79
|
+
throw err;
|
|
80
|
+
}
|
|
81
|
+
if (args.config !== void 0) process.env.CLOUDFLARE_VITE_WRANGLER_CONFIG_PATH = args.config;
|
|
82
|
+
if (args.local) process.env.CLOUDFLARE_VITE_FORCE_LOCAL = "true";
|
|
83
|
+
const serverOptions = {};
|
|
84
|
+
if (args.port !== void 0) serverOptions.port = args.port;
|
|
85
|
+
if (args.host !== void 0) serverOptions.host = args.host;
|
|
86
|
+
const inlineConfig = { server: serverOptions };
|
|
87
|
+
if (args.mode !== void 0) inlineConfig.mode = args.mode;
|
|
88
|
+
const server = await createServer(inlineConfig);
|
|
89
|
+
await server.listen();
|
|
90
|
+
server.printUrls();
|
|
91
|
+
server.bindCLIShortcuts({ print: true });
|
|
92
|
+
let closing = false;
|
|
93
|
+
const shutdown = (signal) => {
|
|
94
|
+
if (closing) return;
|
|
95
|
+
closing = true;
|
|
96
|
+
(async () => {
|
|
97
|
+
try {
|
|
98
|
+
await server.close();
|
|
99
|
+
process.exit(0);
|
|
100
|
+
} catch {
|
|
101
|
+
process.exit(signal === "SIGINT" ? 130 : 143);
|
|
102
|
+
}
|
|
103
|
+
})();
|
|
104
|
+
};
|
|
105
|
+
process.on("SIGINT", () => shutdown("SIGINT"));
|
|
106
|
+
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
|
107
|
+
return new Promise(() => {});
|
|
108
|
+
}
|
|
109
|
+
const exitCode = await main();
|
|
110
|
+
process.exit(exitCode);
|
|
111
|
+
|
|
112
|
+
//#endregion
|
|
113
|
+
export { };
|