@varlock/cloudflare-integration 0.0.0 → 0.0.1
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 +17 -0
- package/bin/varlock-wrangler.js +2 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +1692 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +1 -0
- package/dist/init.js +38 -0
- package/dist/init.js.map +1 -0
- package/dist/varlock-wrangler.d.ts +2 -0
- package/dist/varlock-wrangler.js +430 -0
- package/dist/varlock-wrangler.js.map +1 -0
- package/package.json +61 -5
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
import { existsSync, watch, writeFileSync, unlinkSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { tmpdir } from 'os';
|
|
4
|
+
import { randomBytes } from 'crypto';
|
|
5
|
+
import { spawn, execSync } from 'child_process';
|
|
6
|
+
import { execSyncVarlock } from 'varlock/exec-sync-varlock';
|
|
7
|
+
|
|
8
|
+
// src/varlock-wrangler.ts
|
|
9
|
+
var isWindows = process.platform === "win32";
|
|
10
|
+
var debugEnabled = !!process.env.VARLOCK_DEBUG;
|
|
11
|
+
function debug(...args) {
|
|
12
|
+
if (debugEnabled) console.log("[varlock-wrangler]", ...args);
|
|
13
|
+
}
|
|
14
|
+
function getExecPrefix() {
|
|
15
|
+
const ua = process.env.npm_config_user_agent || "";
|
|
16
|
+
if (ua.startsWith("pnpm/")) return "pnpm exec ";
|
|
17
|
+
if (ua.startsWith("yarn/")) return "yarn exec ";
|
|
18
|
+
if (ua.startsWith("bun/")) return "bunx ";
|
|
19
|
+
if (ua.startsWith("npm/")) return "npx ";
|
|
20
|
+
return "";
|
|
21
|
+
}
|
|
22
|
+
function spawnWrangler(args) {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
const child = spawn("wrangler", args, {
|
|
25
|
+
stdio: "inherit",
|
|
26
|
+
shell: isWindows
|
|
27
|
+
});
|
|
28
|
+
child.on("error", (err) => {
|
|
29
|
+
if (err.code === "ENOENT") {
|
|
30
|
+
console.error("Error: wrangler not found. Install it with your package manager:");
|
|
31
|
+
console.error(" Install it with your package manager, e.g.: npm install wrangler");
|
|
32
|
+
}
|
|
33
|
+
reject(err);
|
|
34
|
+
});
|
|
35
|
+
child.on("exit", (code, signal) => {
|
|
36
|
+
resolve(code ?? (signal ? 1 : 0));
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function loadSerializedGraph() {
|
|
41
|
+
const serializedGraphJson = execSyncVarlock("load --format json-full --compact", {
|
|
42
|
+
showLogsOnError: true
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
json: serializedGraphJson,
|
|
46
|
+
graph: JSON.parse(serializedGraphJson)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function tmpPath(prefix) {
|
|
50
|
+
return join(tmpdir(), `${prefix}-${randomBytes(8).toString("hex")}`);
|
|
51
|
+
}
|
|
52
|
+
function createServingTempFile(prefix) {
|
|
53
|
+
const filePath = tmpPath(prefix);
|
|
54
|
+
if (!isWindows) {
|
|
55
|
+
execSync(`mkfifo -m 0600 "${filePath}"`);
|
|
56
|
+
}
|
|
57
|
+
function cleanup() {
|
|
58
|
+
try {
|
|
59
|
+
unlinkSync(filePath);
|
|
60
|
+
} catch {
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function startServing(getContent) {
|
|
64
|
+
if (isWindows) {
|
|
65
|
+
writeFileSync(filePath, getContent());
|
|
66
|
+
return {
|
|
67
|
+
update(content) {
|
|
68
|
+
writeFileSync(filePath, content);
|
|
69
|
+
},
|
|
70
|
+
stop() {
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const fifoServer = spawn(process.execPath, [
|
|
75
|
+
"-e",
|
|
76
|
+
`
|
|
77
|
+
const fs = require('fs');
|
|
78
|
+
const path = ${JSON.stringify(filePath)};
|
|
79
|
+
let content = '';
|
|
80
|
+
process.stdin.on('data', d => content += d);
|
|
81
|
+
process.stdin.on('end', () => {
|
|
82
|
+
(function serve() {
|
|
83
|
+
try { fs.writeFileSync(path, content); setImmediate(serve); }
|
|
84
|
+
catch { process.exit(); }
|
|
85
|
+
})();
|
|
86
|
+
});
|
|
87
|
+
`
|
|
88
|
+
], {
|
|
89
|
+
stdio: ["pipe", "ignore", "ignore"]
|
|
90
|
+
});
|
|
91
|
+
fifoServer.stdin.write(getContent());
|
|
92
|
+
fifoServer.stdin.end();
|
|
93
|
+
return {
|
|
94
|
+
/** Kill and respawn the FIFO server with new content */
|
|
95
|
+
update(content) {
|
|
96
|
+
fifoServer.kill();
|
|
97
|
+
const replacement = startServing(() => content);
|
|
98
|
+
this.stop = replacement.stop;
|
|
99
|
+
this.update = replacement.update;
|
|
100
|
+
},
|
|
101
|
+
stop() {
|
|
102
|
+
fifoServer.kill();
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
filePath,
|
|
108
|
+
cleanup,
|
|
109
|
+
startServing
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
var CF_SECRET_MAX_BYTES = 5120;
|
|
113
|
+
function chunkString(str, maxBytes) {
|
|
114
|
+
const chunks = [];
|
|
115
|
+
let current = "";
|
|
116
|
+
let currentBytes = 0;
|
|
117
|
+
for (const char of str) {
|
|
118
|
+
const charBytes = Buffer.byteLength(char);
|
|
119
|
+
if (currentBytes + charBytes > maxBytes && current) {
|
|
120
|
+
chunks.push(current);
|
|
121
|
+
current = "";
|
|
122
|
+
currentBytes = 0;
|
|
123
|
+
}
|
|
124
|
+
current += char;
|
|
125
|
+
currentBytes += charBytes;
|
|
126
|
+
}
|
|
127
|
+
if (current) chunks.push(current);
|
|
128
|
+
return chunks;
|
|
129
|
+
}
|
|
130
|
+
function formatEnvLine(key, value) {
|
|
131
|
+
if (!value.includes("'")) {
|
|
132
|
+
return `${key}='${value}'`;
|
|
133
|
+
}
|
|
134
|
+
const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n");
|
|
135
|
+
return `${key}="${escaped}"`;
|
|
136
|
+
}
|
|
137
|
+
function addVarlockEnvToRecord(record, json) {
|
|
138
|
+
if (Buffer.byteLength(json) <= CF_SECRET_MAX_BYTES) {
|
|
139
|
+
record.__VARLOCK_ENV = json;
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const chunks = chunkString(json, CF_SECRET_MAX_BYTES);
|
|
143
|
+
record.__VARLOCK_ENV_CHUNKS = String(chunks.length);
|
|
144
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
145
|
+
record[`__VARLOCK_ENV_${i}`] = chunks[i];
|
|
146
|
+
}
|
|
147
|
+
debug(`__VARLOCK_ENV split into ${chunks.length} chunks (${Buffer.byteLength(json)} bytes)`);
|
|
148
|
+
}
|
|
149
|
+
function addVarlockEnvToLines(lines, json) {
|
|
150
|
+
if (Buffer.byteLength(json) <= CF_SECRET_MAX_BYTES) {
|
|
151
|
+
lines.push(formatEnvLine("__VARLOCK_ENV", json));
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const chunks = chunkString(json, CF_SECRET_MAX_BYTES);
|
|
155
|
+
lines.push(formatEnvLine("__VARLOCK_ENV_CHUNKS", String(chunks.length)));
|
|
156
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
157
|
+
lines.push(formatEnvLine(`__VARLOCK_ENV_${i}`, chunks[i]));
|
|
158
|
+
}
|
|
159
|
+
debug(`__VARLOCK_ENV split into ${chunks.length} chunks (${Buffer.byteLength(json)} bytes)`);
|
|
160
|
+
}
|
|
161
|
+
function formatEnvFileContent(graph) {
|
|
162
|
+
const lines = [
|
|
163
|
+
"# \u26A0\uFE0F AUTO-GENERATED BY VARLOCK \u2014 DO NOT EDIT",
|
|
164
|
+
`# ${isWindows ? "This is a temporary file and will be cleaned up automatically." : "This file is served via a named pipe (FIFO) and exists only in memory."}`,
|
|
165
|
+
"# Your .env files and .env.schema are the source of truth.",
|
|
166
|
+
"# See https://varlock.dev/integrations/cloudflare/ for details.",
|
|
167
|
+
""
|
|
168
|
+
];
|
|
169
|
+
for (const key in graph.graph.config) {
|
|
170
|
+
const item = graph.graph.config[key];
|
|
171
|
+
if (item.value === void 0) continue;
|
|
172
|
+
const strValue = typeof item.value === "string" ? item.value : JSON.stringify(item.value);
|
|
173
|
+
lines.push(formatEnvLine(key, strValue));
|
|
174
|
+
}
|
|
175
|
+
addVarlockEnvToLines(lines, graph.json);
|
|
176
|
+
return lines.join("\n");
|
|
177
|
+
}
|
|
178
|
+
function isDeployCommand(args) {
|
|
179
|
+
if (args[0] === "deploy") return true;
|
|
180
|
+
if (args[0] === "versions" && args[1] === "upload") return true;
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
function isTypesCommand(args) {
|
|
184
|
+
return args[0] === "types";
|
|
185
|
+
}
|
|
186
|
+
async function handleDeploy(args) {
|
|
187
|
+
if (args.includes("--secrets-file")) {
|
|
188
|
+
console.error("Error: --secrets-file is managed automatically by varlock-wrangler.");
|
|
189
|
+
console.error("Remove --secrets-file from your command and let varlock handle it.");
|
|
190
|
+
process.exitCode = 1;
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
let loaded;
|
|
194
|
+
try {
|
|
195
|
+
loaded = loadSerializedGraph();
|
|
196
|
+
} catch {
|
|
197
|
+
console.error("Failed to resolve environment variables");
|
|
198
|
+
process.exitCode = 1;
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const varFlags = [];
|
|
202
|
+
const secretsObj = {};
|
|
203
|
+
for (const key in loaded.graph.config) {
|
|
204
|
+
const item = loaded.graph.config[key];
|
|
205
|
+
if (item.value === void 0) continue;
|
|
206
|
+
const strValue = typeof item.value === "string" ? item.value : JSON.stringify(item.value);
|
|
207
|
+
if (item.isSensitive) {
|
|
208
|
+
secretsObj[key] = strValue;
|
|
209
|
+
} else {
|
|
210
|
+
varFlags.push("--var", `${key}:${strValue}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
addVarlockEnvToRecord(secretsObj, loaded.json);
|
|
214
|
+
const tmp = createServingTempFile("varlock-secrets");
|
|
215
|
+
const content = JSON.stringify(secretsObj);
|
|
216
|
+
debug("deploy: starting FIFO serve");
|
|
217
|
+
const handle = tmp.startServing(() => content);
|
|
218
|
+
process.on("SIGINT", () => {
|
|
219
|
+
handle.stop();
|
|
220
|
+
tmp.cleanup();
|
|
221
|
+
process.exit(1);
|
|
222
|
+
});
|
|
223
|
+
process.on("SIGTERM", () => {
|
|
224
|
+
handle.stop();
|
|
225
|
+
tmp.cleanup();
|
|
226
|
+
process.exit(1);
|
|
227
|
+
});
|
|
228
|
+
const varCount = varFlags.length / 2;
|
|
229
|
+
const secretCount = Object.keys(secretsObj).filter((k) => !k.startsWith("__VARLOCK_ENV")).length;
|
|
230
|
+
console.log(`\x1B[36m\u2728 Deploying with varlock: ${varCount} var${varCount !== 1 ? "s" : ""}, ${secretCount} secret${secretCount !== 1 ? "s" : ""} \u{1F9D9}\u{1F512}\x1B[0m`);
|
|
231
|
+
let exitCode = 0;
|
|
232
|
+
try {
|
|
233
|
+
debug("deploy: spawning wrangler");
|
|
234
|
+
exitCode = await spawnWrangler([...args, ...varFlags, "--secrets-file", tmp.filePath, "--keep-vars=false"]);
|
|
235
|
+
debug("deploy: wrangler exited with code", exitCode);
|
|
236
|
+
} finally {
|
|
237
|
+
debug("deploy: cleaning up");
|
|
238
|
+
handle.stop();
|
|
239
|
+
tmp.cleanup();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
async function handleTypes(args) {
|
|
243
|
+
debug("types: resolving env");
|
|
244
|
+
let loaded;
|
|
245
|
+
try {
|
|
246
|
+
loaded = loadSerializedGraph();
|
|
247
|
+
} catch {
|
|
248
|
+
console.error("Failed to resolve environment variables");
|
|
249
|
+
process.exitCode = 1;
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
debug("types: resolved", Object.keys(loaded.graph.config).length, "env vars");
|
|
253
|
+
const envFileLines = [];
|
|
254
|
+
for (const key in loaded.graph.config) {
|
|
255
|
+
envFileLines.push(`${key}=`);
|
|
256
|
+
}
|
|
257
|
+
const tmp = createServingTempFile("varlock-types-env");
|
|
258
|
+
debug("types: starting FIFO serve");
|
|
259
|
+
const handle = tmp.startServing(() => envFileLines.join("\n"));
|
|
260
|
+
let exitCode = 0;
|
|
261
|
+
try {
|
|
262
|
+
debug("types: spawning wrangler");
|
|
263
|
+
exitCode = await spawnWrangler([...args, "--env-file", tmp.filePath]);
|
|
264
|
+
debug("types: wrangler exited with code", exitCode);
|
|
265
|
+
} finally {
|
|
266
|
+
debug("types: cleaning up");
|
|
267
|
+
handle.stop();
|
|
268
|
+
tmp.cleanup();
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
async function handleDev(args) {
|
|
272
|
+
if (existsSync(".dev.vars")) {
|
|
273
|
+
console.error([
|
|
274
|
+
"Error: a .dev.vars file was detected in your project.",
|
|
275
|
+
"This conflicts with varlock-wrangler which manages env vars automatically.",
|
|
276
|
+
"Remove .dev.vars and define your variables in .env files with a .env.schema instead."
|
|
277
|
+
].join("\n"));
|
|
278
|
+
process.exitCode = 1;
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
debug("dev: resolving env");
|
|
282
|
+
let loaded;
|
|
283
|
+
try {
|
|
284
|
+
loaded = loadSerializedGraph();
|
|
285
|
+
} catch (err) {
|
|
286
|
+
console.error("Failed to resolve environment variables");
|
|
287
|
+
console.error(err);
|
|
288
|
+
process.exitCode = 1;
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
debug("dev: resolved", Object.keys(loaded.graph.config).length, "env vars");
|
|
292
|
+
const tmp = createServingTempFile("varlock-dev-env");
|
|
293
|
+
debug("dev: created FIFO at", tmp.filePath);
|
|
294
|
+
let cachedContent = formatEnvFileContent(loaded);
|
|
295
|
+
let wranglerChild;
|
|
296
|
+
const watchers = [];
|
|
297
|
+
debug("dev: starting FIFO serve");
|
|
298
|
+
const handle = tmp.startServing(() => cachedContent);
|
|
299
|
+
function cleanup() {
|
|
300
|
+
handle.stop();
|
|
301
|
+
for (const w of watchers) w.close();
|
|
302
|
+
tmp.cleanup();
|
|
303
|
+
}
|
|
304
|
+
process.on("SIGINT", () => {
|
|
305
|
+
wranglerChild?.kill();
|
|
306
|
+
cleanup();
|
|
307
|
+
process.exit(1);
|
|
308
|
+
});
|
|
309
|
+
process.on("SIGTERM", () => {
|
|
310
|
+
wranglerChild?.kill();
|
|
311
|
+
cleanup();
|
|
312
|
+
process.exit(1);
|
|
313
|
+
});
|
|
314
|
+
let restartTimeout;
|
|
315
|
+
function scheduleRestart() {
|
|
316
|
+
if (restartTimeout) clearTimeout(restartTimeout);
|
|
317
|
+
restartTimeout = setTimeout(() => {
|
|
318
|
+
try {
|
|
319
|
+
const freshLoaded = loadSerializedGraph();
|
|
320
|
+
cachedContent = formatEnvFileContent(freshLoaded);
|
|
321
|
+
handle.update(cachedContent);
|
|
322
|
+
console.log("[varlock-wrangler] env changed, restarting wrangler...");
|
|
323
|
+
wranglerChild?.kill();
|
|
324
|
+
} catch (err) {
|
|
325
|
+
console.error("[varlock-wrangler] failed to re-resolve env:", err.message);
|
|
326
|
+
}
|
|
327
|
+
}, 300);
|
|
328
|
+
}
|
|
329
|
+
if (loaded.graph.basePath) {
|
|
330
|
+
for (const source of loaded.graph.sources) {
|
|
331
|
+
if (!source.enabled || !source.path) continue;
|
|
332
|
+
const fullPath = join(loaded.graph.basePath, source.path);
|
|
333
|
+
try {
|
|
334
|
+
const w = watch(fullPath, () => scheduleRestart());
|
|
335
|
+
watchers.push(w);
|
|
336
|
+
debug("dev: watching", fullPath);
|
|
337
|
+
} catch {
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
try {
|
|
342
|
+
while (true) {
|
|
343
|
+
debug("dev: spawning wrangler");
|
|
344
|
+
wranglerChild = spawn("wrangler", [...args, "--env-file", tmp.filePath], {
|
|
345
|
+
stdio: ["inherit", "pipe", "pipe"],
|
|
346
|
+
shell: isWindows,
|
|
347
|
+
// force color output since piped stdio loses TTY detection
|
|
348
|
+
env: { ...process.env, FORCE_COLOR: "1" }
|
|
349
|
+
});
|
|
350
|
+
const tmpBasename = tmp.filePath.split(/[/\\]/).pop();
|
|
351
|
+
const loadCmd = `${getExecPrefix()}varlock load`;
|
|
352
|
+
const envVarCount = Object.keys(loaded.graph.config).length;
|
|
353
|
+
let shownVarlockNotice = false;
|
|
354
|
+
const varlockNotice = `\x1B[36m\u2728 ${envVarCount} env var${envVarCount !== 1 ? "s" : ""} managed by varlock \u{1F9D9}\u{1F512}\x1B[0m
|
|
355
|
+
\x1B[2m run \`${loadCmd}\` to inspect\x1B[0m
|
|
356
|
+
`;
|
|
357
|
+
const rewriteOutput = (stream) => (chunk) => {
|
|
358
|
+
let str = chunk.toString();
|
|
359
|
+
if (str.includes(tmpBasename)) {
|
|
360
|
+
str = str.replace(/.*varlock-dev-env-[a-f0-9]+.*\n?/g, "");
|
|
361
|
+
}
|
|
362
|
+
if (str.includes("Environment Variable")) {
|
|
363
|
+
if (!shownVarlockNotice) {
|
|
364
|
+
str = str.replace(/.*Environment Variable.*\n?/, varlockNotice);
|
|
365
|
+
shownVarlockNotice = true;
|
|
366
|
+
}
|
|
367
|
+
str = str.replace(/.*Environment Variable.*\n?/g, "");
|
|
368
|
+
}
|
|
369
|
+
if (str.includes("wrangler types")) {
|
|
370
|
+
str = str.replace(/wrangler types/g, "varlock-wrangler types");
|
|
371
|
+
}
|
|
372
|
+
if (str) stream.write(str);
|
|
373
|
+
};
|
|
374
|
+
wranglerChild.stdout?.on("data", rewriteOutput(process.stdout));
|
|
375
|
+
wranglerChild.stderr?.on("data", rewriteOutput(process.stderr));
|
|
376
|
+
const child = wranglerChild;
|
|
377
|
+
const exitCode = await new Promise((resolve) => {
|
|
378
|
+
child.on("error", (err) => {
|
|
379
|
+
if (err.code === "ENOENT") {
|
|
380
|
+
console.error("Error: wrangler not found. Install it with your package manager:");
|
|
381
|
+
console.error(" Install it with your package manager, e.g.: npm install wrangler");
|
|
382
|
+
}
|
|
383
|
+
resolve(1);
|
|
384
|
+
});
|
|
385
|
+
child.on("exit", (code, signal) => {
|
|
386
|
+
resolve(code ?? (signal ? 1 : 0));
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
if (!restartTimeout) {
|
|
390
|
+
debug("dev: wrangler exited with code", exitCode);
|
|
391
|
+
process.exitCode = exitCode;
|
|
392
|
+
break;
|
|
393
|
+
}
|
|
394
|
+
debug("dev: restarting wrangler due to env change");
|
|
395
|
+
}
|
|
396
|
+
} finally {
|
|
397
|
+
cleanup();
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
async function main() {
|
|
401
|
+
const args = process.argv.slice(2);
|
|
402
|
+
if (args.length === 0) {
|
|
403
|
+
console.log("varlock-wrangler: a drop-in replacement for `wrangler` that injects resolved env");
|
|
404
|
+
console.log("Usage: varlock-wrangler <wrangler-command> [options]");
|
|
405
|
+
console.log("");
|
|
406
|
+
console.log("Enhanced commands:");
|
|
407
|
+
console.log(" dev - injects resolved env via named pipe (no secrets on disk)");
|
|
408
|
+
console.log(" deploy / versions upload - uploads env as Cloudflare vars and secrets");
|
|
409
|
+
console.log(" types - generates types including varlock-managed env vars");
|
|
410
|
+
console.log("");
|
|
411
|
+
console.log("All other commands are passed through to wrangler unchanged.");
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
if (isDeployCommand(args)) {
|
|
415
|
+
await handleDeploy(args);
|
|
416
|
+
} else if (isTypesCommand(args)) {
|
|
417
|
+
await handleTypes(args);
|
|
418
|
+
} else if (args[0] === "dev") {
|
|
419
|
+
await handleDev(args);
|
|
420
|
+
} else {
|
|
421
|
+
const exitCode = await spawnWrangler(args);
|
|
422
|
+
process.exitCode = exitCode;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
main().catch((err) => {
|
|
426
|
+
console.error("varlock-wrangler: unexpected error:", err);
|
|
427
|
+
process.exitCode = 1;
|
|
428
|
+
});
|
|
429
|
+
//# sourceMappingURL=varlock-wrangler.js.map
|
|
430
|
+
//# sourceMappingURL=varlock-wrangler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/varlock-wrangler.ts"],"names":[],"mappings":";;;;;;;;AAYA,IAAM,SAAA,GAAY,QAAQ,QAAA,KAAa,OAAA;AACvC,IAAM,YAAA,GAAe,CAAC,CAAC,OAAA,CAAQ,GAAA,CAAI,aAAA;AACnC,SAAS,SAAS,IAAA,EAAkB;AAClC,EAAA,IAAI,YAAA,EAAc,OAAA,CAAQ,GAAA,CAAI,oBAAA,EAAsB,GAAG,IAAI,CAAA;AAC7D;AAGA,SAAS,aAAA,GAAwB;AAC/B,EAAA,MAAM,EAAA,GAAK,OAAA,CAAQ,GAAA,CAAI,qBAAA,IAAyB,EAAA;AAChD,EAAA,IAAI,EAAA,CAAG,UAAA,CAAW,OAAO,CAAA,EAAG,OAAO,YAAA;AACnC,EAAA,IAAI,EAAA,CAAG,UAAA,CAAW,OAAO,CAAA,EAAG,OAAO,YAAA;AACnC,EAAA,IAAI,EAAA,CAAG,UAAA,CAAW,MAAM,CAAA,EAAG,OAAO,OAAA;AAClC,EAAA,IAAI,EAAA,CAAG,UAAA,CAAW,MAAM,CAAA,EAAG,OAAO,MAAA;AAClC,EAAA,OAAO,EAAA;AACT;AAIA,SAAS,cAAc,IAAA,EAAsC;AAC3D,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,EAAS,MAAA,KAAW;AACtC,IAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,UAAA,EAAY,IAAA,EAAM;AAAA,MACpC,KAAA,EAAO,SAAA;AAAA,MACP,KAAA,EAAO;AAAA,KACR,CAAA;AACD,IAAA,KAAA,CAAM,EAAA,CAAG,OAAA,EAAS,CAAC,GA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EL,IAAA,MAAM,QAAA,GAAW,MAAM,aAAA,CAAc,IAAI,CAAA;AACzC,IAAA,OAAA,CAAQ,QAAA,GAAW,QAAA;AAAA,EACrB;AACF;AAEA,IAAA,EAAK,CAAE,KAAA,CAAM,CAAC,GAAA,KAAQ;AACpB,EAAA,OAAA,CAAQ,KAAA,CAAM,uCAAuC,GAAG,CAAA;AACxD,EAAA,OAAA,CAAQ,QAAA,GAAW,CAAA;AACrB,CAAC,CAAA","file":"varlock-wrangler.js","sourcesContent":["/* eslint-disable no-console */\n\nimport {\n writeFileSync, unlinkSync, watch, existsSync,\n} from 'node:fs';\nimport { join } from 'node:path';\nimport { tmpdir } from 'node:os';\nimport { randomBytes } from 'node:crypto';\nimport { spawn, execSync } from 'node:child_process';\n\nimport { execSyncVarlock } from 'varlock/exec-sync-varlock';\n\nconst isWindows = process.platform === 'win32';\nconst debugEnabled = !!process.env.VARLOCK_DEBUG;\nfunction debug(...args: Array<any>) {\n if (debugEnabled) console.log('[varlock-wrangler]', ...args);\n}\n\n/** Detect the package manager exec command from npm_config_user_agent */\nfunction getExecPrefix(): string {\n const ua = process.env.npm_config_user_agent || '';\n if (ua.startsWith('pnpm/')) return 'pnpm exec ';\n if (ua.startsWith('yarn/')) return 'yarn exec ';\n if (ua.startsWith('bun/')) return 'bunx ';\n if (ua.startsWith('npm/')) return 'npx ';\n return '';\n}\n\n// --- shared helpers ---\n\nfunction spawnWrangler(args: Array<string>): Promise<number> {\n return new Promise((resolve, reject) => {\n const child = spawn('wrangler', args, {\n stdio: 'inherit',\n shell: isWindows,\n });\n child.on('error', (err) => {\n if ((err as any).code === 'ENOENT') {\n console.error('Error: wrangler not found. Install it with your package manager:');\n console.error(' Install it with your package manager, e.g.: npm install wrangler');\n }\n reject(err);\n });\n child.on('exit', (code, signal) => {\n resolve(code ?? (signal ? 1 : 0));\n });\n });\n}\n\nfunction loadSerializedGraph() {\n const serializedGraphJson = execSyncVarlock('load --format json-full --compact', {\n showLogsOnError: true,\n });\n return {\n json: serializedGraphJson,\n graph: JSON.parse(serializedGraphJson) as {\n basePath?: string,\n sources: Array<{ label: string, enabled: boolean, path?: string }>,\n config: Record<string, { value: unknown, isSensitive: boolean }>,\n },\n };\n}\n\nfunction tmpPath(prefix: string) {\n return join(tmpdir(), `${prefix}-${randomBytes(8).toString('hex')}`);\n}\n\n/**\n * Creates a named pipe (FIFO) for long-running commands (dev).\n * On Unix: data only exists in a kernel buffer — secrets never touch disk.\n * On Windows: falls back to a regular temp file.\n */\nfunction createServingTempFile(prefix: string) {\n const filePath = tmpPath(prefix);\n\n if (!isWindows) {\n execSync(`mkfifo -m 0600 \"${filePath}\"`);\n }\n\n function cleanup() {\n try {\n unlinkSync(filePath);\n } catch {\n // may already be deleted\n }\n }\n\n /**\n * Start serving content via the FIFO (or write a regular file on Windows).\n * On Unix: spawns a child process that writes to the FIFO in a loop.\n * Using a child process means the blocked libuv thread lives in the child —\n * killing the child cleanly releases it, allowing our main process to exit.\n * On Windows: writes a regular file, with refresh() to update it.\n */\n function startServing(getContent: () => string) {\n if (isWindows) {\n writeFileSync(filePath, getContent());\n return {\n update(content: string) { writeFileSync(filePath, content); },\n stop() {\n /* noop on Windows */\n },\n };\n }\n\n // spawn a child process to serve the FIFO\n // the child reads content from stdin, then writes it to the FIFO in a loop\n const fifoServer = spawn(process.execPath, [\n '-e', `\n const fs = require('fs');\n const path = ${JSON.stringify(filePath)};\n let content = '';\n process.stdin.on('data', d => content += d);\n process.stdin.on('end', () => {\n (function serve() {\n try { fs.writeFileSync(path, content); setImmediate(serve); }\n catch { process.exit(); }\n })();\n });\n `,\n ], {\n stdio: ['pipe', 'ignore', 'ignore'],\n });\n fifoServer.stdin!.write(getContent());\n fifoServer.stdin!.end();\n\n return {\n /** Kill and respawn the FIFO server with new content */\n update(content: string) {\n fifoServer.kill();\n const replacement = startServing(() => content);\n // swap the stop/update methods on this handle\n this.stop = replacement.stop;\n this.update = replacement.update;\n },\n stop() {\n fifoServer.kill();\n },\n };\n }\n\n return {\n filePath, cleanup, startServing,\n };\n}\n\n// Cloudflare secrets are limited to 5KB each.\n// __VARLOCK_ENV can exceed this, so we split it into chunks.\nconst CF_SECRET_MAX_BYTES = 5120;\n\n/**\n * Split a string into chunks where each chunk's UTF-8 byte length ≤ maxBytes.\n * Unlike slicing a Buffer, this never splits a multi-byte character.\n */\nfunction chunkString(str: string, maxBytes: number): Array<string> {\n const chunks: Array<string> = [];\n let current = '';\n let currentBytes = 0;\n for (const char of str) {\n const charBytes = Buffer.byteLength(char);\n if (currentBytes + charBytes > maxBytes && current) {\n chunks.push(current);\n current = '';\n currentBytes = 0;\n }\n current += char;\n currentBytes += charBytes;\n }\n if (current) chunks.push(current);\n return chunks;\n}\n\nfunction formatEnvLine(key: string, value: string): string {\n if (!value.includes(\"'\")) {\n // single quotes — literal, no escaping needed\n return `${key}='${value}'`;\n }\n // fall back to double quotes with escaping\n const escaped = value.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"').replace(/\\n/g, '\\\\n');\n return `${key}=\"${escaped}\"`;\n}\n\n/**\n * Adds __VARLOCK_ENV to a key-value record, splitting into chunks if needed.\n * If the value fits in one secret: sets __VARLOCK_ENV directly.\n * If too large: sets __VARLOCK_ENV_CHUNKS=N and __VARLOCK_ENV_0, __VARLOCK_ENV_1, etc.\n */\nfunction addVarlockEnvToRecord(record: Record<string, string>, json: string) {\n if (Buffer.byteLength(json) <= CF_SECRET_MAX_BYTES) {\n record.__VARLOCK_ENV = json;\n return;\n }\n const chunks = chunkString(json, CF_SECRET_MAX_BYTES);\n record.__VARLOCK_ENV_CHUNKS = String(chunks.length);\n for (let i = 0; i < chunks.length; i++) {\n record[`__VARLOCK_ENV_${i}`] = chunks[i];\n }\n debug(`__VARLOCK_ENV split into ${chunks.length} chunks (${Buffer.byteLength(json)} bytes)`);\n}\n\n/**\n * Adds __VARLOCK_ENV lines to a dotenv-format array, splitting into chunks if needed.\n */\nfunction addVarlockEnvToLines(lines: Array<string>, json: string) {\n if (Buffer.byteLength(json) <= CF_SECRET_MAX_BYTES) {\n lines.push(formatEnvLine('__VARLOCK_ENV', json));\n return;\n }\n const chunks = chunkString(json, CF_SECRET_MAX_BYTES);\n lines.push(formatEnvLine('__VARLOCK_ENV_CHUNKS', String(chunks.length)));\n for (let i = 0; i < chunks.length; i++) {\n lines.push(formatEnvLine(`__VARLOCK_ENV_${i}`, chunks[i]));\n }\n debug(`__VARLOCK_ENV split into ${chunks.length} chunks (${Buffer.byteLength(json)} bytes)`);\n}\n\nfunction formatEnvFileContent(graph: ReturnType<typeof loadSerializedGraph>) {\n // output as dotenv format using single quotes — single-quoted values are\n // treated as literal strings with no escape processing, which avoids issues\n // with double quotes in JSON blobs and special characters in values.\n // values containing single quotes are double-quoted with escaping instead.\n const lines: Array<string> = [\n '# ⚠️ AUTO-GENERATED BY VARLOCK — DO NOT EDIT',\n `# ${isWindows ? 'This is a temporary file and will be cleaned up automatically.' : 'This file is served via a named pipe (FIFO) and exists only in memory.'}`,\n '# Your .env files and .env.schema are the source of truth.',\n '# See https://varlock.dev/integrations/cloudflare/ for details.',\n '',\n ];\n for (const key in graph.graph.config) {\n const item = graph.graph.config[key];\n if (item.value === undefined) continue;\n const strValue = typeof item.value === 'string' ? item.value : JSON.stringify(item.value);\n lines.push(formatEnvLine(key, strValue));\n }\n // include __VARLOCK_ENV for the varlock runtime (compact JSON, no newlines)\n // split into chunks if it exceeds CF's 5KB secret limit\n addVarlockEnvToLines(lines, graph.json);\n return lines.join('\\n');\n}\n\n// --- command detection ---\n\nfunction isDeployCommand(args: Array<string>) {\n if (args[0] === 'deploy') return true;\n if (args[0] === 'versions' && args[1] === 'upload') return true;\n return false;\n}\n\nfunction isTypesCommand(args: Array<string>) {\n return args[0] === 'types';\n}\n\n// --- command handlers ---\n\nasync function handleDeploy(args: Array<string>) {\n if (args.includes('--secrets-file')) {\n console.error('Error: --secrets-file is managed automatically by varlock-wrangler.');\n console.error('Remove --secrets-file from your command and let varlock handle it.');\n process.exitCode = 1;\n return;\n }\n\n let loaded;\n try {\n loaded = loadSerializedGraph();\n } catch {\n console.error('Failed to resolve environment variables');\n process.exitCode = 1;\n return;\n }\n\n // split resolved vars into:\n // - non-sensitive → --var flags (visible in CF dashboard as environment variables)\n // - sensitive → --secrets-file (stored as CF secrets)\n // - __VARLOCK_ENV blob → always a secret (contains full graph including sensitive values)\n const varFlags: Array<string> = [];\n const secretsObj: Record<string, string> = {};\n\n for (const key in loaded.graph.config) {\n const item = loaded.graph.config[key];\n if (item.value === undefined) continue;\n const strValue = typeof item.value === 'string' ? item.value : JSON.stringify(item.value);\n\n if (item.isSensitive) {\n secretsObj[key] = strValue;\n } else {\n // wrangler splits KEY:VALUE on the first `:` only, so colons in values are safe\n // spawn args array passes newlines/special chars without shell escaping issues\n varFlags.push('--var', `${key}:${strValue}`);\n }\n }\n // split into chunks if it exceeds CF's 5KB secret limit\n addVarlockEnvToRecord(secretsObj, loaded.json);\n\n const tmp = createServingTempFile('varlock-secrets');\n const content = JSON.stringify(secretsObj);\n debug('deploy: starting FIFO serve');\n const handle = tmp.startServing(() => content);\n\n process.on('SIGINT', () => {\n handle.stop();\n tmp.cleanup();\n process.exit(1);\n });\n process.on('SIGTERM', () => {\n handle.stop();\n tmp.cleanup();\n process.exit(1);\n });\n\n const varCount = varFlags.length / 2; // each var is two entries: --var, KEY:VALUE\n // count only user secrets (exclude __VARLOCK_ENV and chunk keys)\n const secretCount = Object.keys(secretsObj).filter((k) => !k.startsWith('__VARLOCK_ENV')).length;\n console.log(`\\x1b[36m✨ Deploying with varlock: ${varCount} var${varCount !== 1 ? 's' : ''}, ${secretCount} secret${secretCount !== 1 ? 's' : ''} 🧙🔒\\x1b[0m`);\n\n let exitCode = 0;\n try {\n debug('deploy: spawning wrangler');\n exitCode = await spawnWrangler([...args, ...varFlags, '--secrets-file', tmp.filePath, '--keep-vars=false']);\n debug('deploy: wrangler exited with code', exitCode);\n } finally {\n debug('deploy: cleaning up');\n handle.stop();\n tmp.cleanup();\n }\n}\n\nasync function handleTypes(args: Array<string>) {\n debug('types: resolving env');\n let loaded;\n try {\n loaded = loadSerializedGraph();\n } catch {\n console.error('Failed to resolve environment variables');\n process.exitCode = 1;\n return;\n }\n\n debug('types: resolved', Object.keys(loaded.graph.config).length, 'env vars');\n // generate a temp env file with just key names (no real values)\n // wrangler types reads this to discover which vars to include in the Env interface\n const envFileLines: Array<string> = [];\n for (const key in loaded.graph.config) {\n envFileLines.push(`${key}=`);\n }\n\n const tmp = createServingTempFile('varlock-types-env');\n debug('types: starting FIFO serve');\n const handle = tmp.startServing(() => envFileLines.join('\\n'));\n\n let exitCode = 0;\n try {\n debug('types: spawning wrangler');\n exitCode = await spawnWrangler([...args, '--env-file', tmp.filePath]);\n debug('types: wrangler exited with code', exitCode);\n } finally {\n debug('types: cleaning up');\n handle.stop();\n tmp.cleanup();\n }\n}\n\nasync function handleDev(args: Array<string>) {\n // .dev.vars would conflict with our env injection via --env-file\n if (existsSync('.dev.vars')) {\n console.error([\n 'Error: a .dev.vars file was detected in your project.',\n 'This conflicts with varlock-wrangler which manages env vars automatically.',\n 'Remove .dev.vars and define your variables in .env files with a .env.schema instead.',\n ].join('\\n'));\n process.exitCode = 1;\n return;\n }\n\n debug('dev: resolving env');\n let loaded;\n try {\n loaded = loadSerializedGraph();\n } catch (err) {\n console.error('Failed to resolve environment variables');\n console.error(err);\n process.exitCode = 1;\n return;\n }\n debug('dev: resolved', Object.keys(loaded.graph.config).length, 'env vars');\n\n const tmp = createServingTempFile('varlock-dev-env');\n debug('dev: created FIFO at', tmp.filePath);\n\n let cachedContent = formatEnvFileContent(loaded);\n let wranglerChild: ReturnType<typeof spawn> | undefined;\n const watchers: Array<ReturnType<typeof watch>> = [];\n\n debug('dev: starting FIFO serve');\n const handle = tmp.startServing(() => cachedContent);\n\n function cleanup() {\n handle.stop();\n for (const w of watchers) w.close();\n tmp.cleanup();\n }\n\n process.on('SIGINT', () => {\n wranglerChild?.kill();\n cleanup();\n process.exit(1);\n });\n process.on('SIGTERM', () => {\n wranglerChild?.kill();\n cleanup();\n process.exit(1);\n });\n\n // watch env source files for changes and restart wrangler with fresh data\n let restartTimeout: ReturnType<typeof setTimeout> | undefined;\n function scheduleRestart() {\n // debounce — multiple files may change at once\n if (restartTimeout) clearTimeout(restartTimeout);\n restartTimeout = setTimeout(() => {\n try {\n const freshLoaded = loadSerializedGraph();\n cachedContent = formatEnvFileContent(freshLoaded);\n handle.update(cachedContent);\n console.log('[varlock-wrangler] env changed, restarting wrangler...');\n wranglerChild?.kill();\n } catch (err) {\n console.error('[varlock-wrangler] failed to re-resolve env:', (err as Error).message);\n }\n }, 300);\n }\n\n // set up watchers on env source files\n if (loaded.graph.basePath) {\n for (const source of loaded.graph.sources) {\n if (!source.enabled || !source.path) continue;\n const fullPath = join(loaded.graph.basePath, source.path);\n try {\n const w = watch(fullPath, () => scheduleRestart());\n watchers.push(w);\n debug('dev: watching', fullPath);\n } catch {\n // file may not exist yet (e.g., optional env-specific file)\n }\n }\n }\n\n try {\n // outer loop: (re)spawn wrangler each time it exits\n // on env file changes, the watcher kills wrangler, which causes it to respawn\n // with the fresh data (FIFO serves fresh content, Windows file is refreshed)\n while (true) {\n debug('dev: spawning wrangler');\n wranglerChild = spawn('wrangler', [...args, '--env-file', tmp.filePath], {\n stdio: ['inherit', 'pipe', 'pipe'],\n shell: isWindows,\n // force color output since piped stdio loses TTY detection\n env: { ...process.env, FORCE_COLOR: '1' },\n });\n\n // pipe wrangler output with rewrites:\n // - replace FIFO path reference with a friendlier message\n // - strip env var binding rows (other bindings like KV, D1 are preserved)\n const tmpBasename = tmp.filePath.split(/[/\\\\]/).pop()!;\n const loadCmd = `${getExecPrefix()}varlock load`;\n const envVarCount = Object.keys(loaded.graph.config).length;\n let shownVarlockNotice = false;\n const varlockNotice = `\\x1b[36m✨ ${envVarCount} env var${envVarCount !== 1 ? 's' : ''} managed by varlock 🧙🔒\\x1b[0m\\n`\n + `\\x1b[2m run \\`${loadCmd}\\` to inspect\\x1b[0m\\n`;\n const rewriteOutput = (stream: NodeJS.WriteStream) => (chunk: Buffer) => {\n let str = chunk.toString();\n // strip the FIFO path line entirely\n if (str.includes(tmpBasename)) {\n str = str.replace(/.*varlock-dev-env-[a-f0-9]+.*\\n?/g, '');\n }\n // replace env var binding rows with a single varlock notice\n // (other bindings like KV, D1 are preserved)\n if (str.includes('Environment Variable')) {\n if (!shownVarlockNotice) {\n str = str.replace(/.*Environment Variable.*\\n?/, varlockNotice);\n shownVarlockNotice = true;\n }\n str = str.replace(/.*Environment Variable.*\\n?/g, '');\n }\n // rewrite wrangler types hint to use varlock-wrangler\n if (str.includes('wrangler types')) {\n str = str.replace(/wrangler types/g, 'varlock-wrangler types');\n }\n if (str) stream.write(str);\n };\n wranglerChild.stdout?.on('data', rewriteOutput(process.stdout));\n wranglerChild.stderr?.on('data', rewriteOutput(process.stderr));\n\n const child = wranglerChild;\n const exitCode = await new Promise<number>((resolve) => {\n child.on('error', (err) => {\n if ((err as any).code === 'ENOENT') {\n console.error('Error: wrangler not found. Install it with your package manager:');\n console.error(' Install it with your package manager, e.g.: npm install wrangler');\n }\n resolve(1);\n });\n child.on('exit', (code, signal) => {\n resolve(code ?? (signal ? 1 : 0));\n });\n });\n\n // if wrangler exited on its own (not killed by us for restart), stop\n if (!restartTimeout) {\n debug('dev: wrangler exited with code', exitCode);\n process.exitCode = exitCode;\n break;\n }\n debug('dev: restarting wrangler due to env change');\n }\n } finally {\n cleanup();\n }\n}\n\n// --- main ---\n\nasync function main() {\n const args = process.argv.slice(2);\n\n if (args.length === 0) {\n console.log('varlock-wrangler: a drop-in replacement for `wrangler` that injects resolved env');\n console.log('Usage: varlock-wrangler <wrangler-command> [options]');\n console.log('');\n console.log('Enhanced commands:');\n console.log(' dev - injects resolved env via named pipe (no secrets on disk)');\n console.log(' deploy / versions upload - uploads env as Cloudflare vars and secrets');\n console.log(' types - generates types including varlock-managed env vars');\n console.log('');\n console.log('All other commands are passed through to wrangler unchanged.');\n return;\n }\n\n if (isDeployCommand(args)) {\n await handleDeploy(args);\n } else if (isTypesCommand(args)) {\n await handleTypes(args);\n } else if (args[0] === 'dev') {\n await handleDev(args);\n } else {\n // pass through to wrangler unchanged\n const exitCode = await spawnWrangler(args);\n process.exitCode = exitCode;\n }\n}\n\nmain().catch((err) => {\n console.error('varlock-wrangler: unexpected error:', err);\n process.exitCode = 1;\n});\n"]}
|
package/package.json
CHANGED
|
@@ -1,13 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlock/cloudflare-integration",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "0.0.
|
|
3
|
+
"description": "Cloudflare Workers integration for varlock - deploy secrets via wrangler and auto-configure Vite",
|
|
4
|
+
"version": "0.0.1",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/dmno-dev/varlock.git",
|
|
8
8
|
"directory": "packages/integrations/cloudflare"
|
|
9
9
|
},
|
|
10
|
-
"
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"types": "dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./dist/index.js",
|
|
15
|
+
"./init": "./dist/init.js"
|
|
16
|
+
},
|
|
17
|
+
"bin": {
|
|
18
|
+
"varlock-wrangler": "./bin/varlock-wrangler.js"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"/bin",
|
|
22
|
+
"/dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"dev": "tsup --watch",
|
|
26
|
+
"build": "tsup"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"varlock",
|
|
30
|
+
"cloudflare",
|
|
31
|
+
"cloudflare-workers",
|
|
32
|
+
"wrangler",
|
|
33
|
+
"env",
|
|
34
|
+
".env",
|
|
35
|
+
"environment variables",
|
|
36
|
+
"secrets",
|
|
37
|
+
"varlock-integration"
|
|
38
|
+
],
|
|
11
39
|
"author": "dmno-dev",
|
|
12
|
-
"license": "MIT"
|
|
13
|
-
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=22"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"varlock": "^0.7.0",
|
|
46
|
+
"vite": ">=5",
|
|
47
|
+
"wrangler": ">=3",
|
|
48
|
+
"@cloudflare/vite-plugin": ">=1"
|
|
49
|
+
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"vite": {
|
|
52
|
+
"optional": true
|
|
53
|
+
},
|
|
54
|
+
"wrangler": {
|
|
55
|
+
"optional": true
|
|
56
|
+
},
|
|
57
|
+
"@cloudflare/vite-plugin": {
|
|
58
|
+
"optional": true
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@types/node": "25.3.2",
|
|
63
|
+
"@varlock/vite-integration": "^0.2.8",
|
|
64
|
+
"tsup": "^8.5.1",
|
|
65
|
+
"varlock": "^0.7.0",
|
|
66
|
+
"vite": "^7.1.0",
|
|
67
|
+
"vitest": "^4.0.18"
|
|
68
|
+
}
|
|
69
|
+
}
|