wrangler 0.0.13 → 0.0.14
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/package.json +2 -1
- package/src/__tests__/dev.test.tsx +2 -0
- package/src/__tests__/jest.setup.ts +7 -0
- package/src/__tests__/logout.test.ts +64 -0
- package/src/__tests__/publish.test.ts +31 -0
- package/src/__tests__/secret.test.ts +206 -0
- package/src/__tests__/whoami.test.tsx +1 -1
- package/src/dev.tsx +15 -9
- package/src/index.tsx +59 -45
- package/src/inspect.ts +6 -1
- package/src/pages.tsx +1 -0
- package/src/proxy.ts +29 -3
- package/src/publish.ts +3 -3
- package/wrangler-dist/cli.js +88 -56
- package/wrangler-dist/cli.js.map +2 -2
package/src/inspect.ts
CHANGED
|
@@ -315,9 +315,14 @@ export default function useInspector(props: InspectorProps) {
|
|
|
315
315
|
};
|
|
316
316
|
}, [
|
|
317
317
|
props.inspectorUrl,
|
|
318
|
-
retryRemoteWebSocketConnectionSigil,
|
|
319
318
|
props.logToTerminal,
|
|
320
319
|
wsServer,
|
|
320
|
+
// We use a state value as a sigil to trigger a retry of the
|
|
321
|
+
// remote websocket connection. It's not used inside the effect,
|
|
322
|
+
// so react-hooks/exhaustive-deps doesn't complain if it's not
|
|
323
|
+
// included in the dependency array. But its presence is critical,
|
|
324
|
+
// so do NOT remove it from the dependency list.
|
|
325
|
+
retryRemoteWebSocketConnectionSigil,
|
|
321
326
|
]);
|
|
322
327
|
|
|
323
328
|
/**
|
package/src/pages.tsx
CHANGED
package/src/proxy.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type {
|
|
|
11
11
|
import WebSocket from "faye-websocket";
|
|
12
12
|
import serveStatic from "serve-static";
|
|
13
13
|
import type { CfPreviewToken } from "./api/preview";
|
|
14
|
-
import { useEffect, useRef } from "react";
|
|
14
|
+
import { useEffect, useRef, useState } from "react";
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* `usePreviewServer` is a React hook that creates a local development
|
|
@@ -80,6 +80,17 @@ export function usePreviewServer({
|
|
|
80
80
|
{ request: IncomingMessage; response: ServerResponse }[]
|
|
81
81
|
>([]);
|
|
82
82
|
|
|
83
|
+
/**
|
|
84
|
+
* The session doesn't last forever, and will evetually drop
|
|
85
|
+
* (usually within 5-15 minutes). When that happens, we simply
|
|
86
|
+
* restart the effect, effectively restarting the server. We use
|
|
87
|
+
* a state sigil as an effect dependency to do so.
|
|
88
|
+
*/
|
|
89
|
+
const [retryServerSetupSigil, setRetryServerSetupSigil] = useState<number>(0);
|
|
90
|
+
function retryServerSetup() {
|
|
91
|
+
setRetryServerSetupSigil((x) => x + 1);
|
|
92
|
+
}
|
|
93
|
+
|
|
83
94
|
useEffect(() => {
|
|
84
95
|
// If we don't have a token, that means either we're just starting up,
|
|
85
96
|
// or we're refreshing the token.
|
|
@@ -119,6 +130,11 @@ export function usePreviewServer({
|
|
|
119
130
|
const remote = connect(`https://${previewToken.host}`);
|
|
120
131
|
cleanupListeners.push(() => remote.destroy());
|
|
121
132
|
|
|
133
|
+
// As mentioned above, the session may die at any point,
|
|
134
|
+
// so we need to restart the effect.
|
|
135
|
+
remote.on("close", retryServerSetup);
|
|
136
|
+
cleanupListeners.push(() => remote.off("close", retryServerSetup));
|
|
137
|
+
|
|
122
138
|
/** HTTP/2 -> HTTP/2 */
|
|
123
139
|
const handleStream = createStreamHandler(previewToken, remote, port);
|
|
124
140
|
proxy.on("stream", handleStream);
|
|
@@ -209,9 +225,19 @@ export function usePreviewServer({
|
|
|
209
225
|
cleanupListeners.push(() => proxy.off("upgrade", handleUpgrade));
|
|
210
226
|
|
|
211
227
|
return () => {
|
|
212
|
-
cleanupListeners.forEach((
|
|
228
|
+
cleanupListeners.forEach((cleanup) => cleanup());
|
|
213
229
|
};
|
|
214
|
-
}, [
|
|
230
|
+
}, [
|
|
231
|
+
previewToken,
|
|
232
|
+
publicRoot,
|
|
233
|
+
port,
|
|
234
|
+
proxy,
|
|
235
|
+
// We use a state value as a sigil to trigger reconnecting the server.
|
|
236
|
+
// It's not used inside the effect, so react-hooks/exhaustive-deps
|
|
237
|
+
// doesn't complain if it's not included in the dependency array.
|
|
238
|
+
// But its presence is critical, so Do NOT remove it from the dependency list.
|
|
239
|
+
retryServerSetupSigil,
|
|
240
|
+
]);
|
|
215
241
|
|
|
216
242
|
// Start/stop the server whenever the
|
|
217
243
|
// containing component is mounted/unmounted.
|
package/src/publish.ts
CHANGED
|
@@ -3,7 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { readFile } from "node:fs/promises";
|
|
4
4
|
import * as esbuild from "esbuild";
|
|
5
5
|
import type { Metafile } from "esbuild";
|
|
6
|
-
import {
|
|
6
|
+
import { execaCommand } from "execa";
|
|
7
7
|
import tmp from "tmp-promise";
|
|
8
8
|
import type { CfWorkerInit } from "./api/worker";
|
|
9
9
|
import { toFormData } from "./api/form_data";
|
|
@@ -114,8 +114,8 @@ export default async function publish(props: Props): Promise<void> {
|
|
|
114
114
|
if (props.config.build?.command) {
|
|
115
115
|
// TODO: add a deprecation message here?
|
|
116
116
|
console.log("running:", props.config.build.command);
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
await execaCommand(props.config.build.command, {
|
|
118
|
+
shell: true,
|
|
119
119
|
stdout: "inherit",
|
|
120
120
|
stderr: "inherit",
|
|
121
121
|
...(props.config.build?.cwd && { cwd: props.config.build.cwd }),
|
package/wrangler-dist/cli.js
CHANGED
|
@@ -1359,7 +1359,7 @@ var require_react_development = __commonJS({
|
|
|
1359
1359
|
}
|
|
1360
1360
|
return dispatcher.useContext(Context, unstable_observedBits);
|
|
1361
1361
|
}
|
|
1362
|
-
function
|
|
1362
|
+
function useState5(initialState) {
|
|
1363
1363
|
var dispatcher = resolveDispatcher();
|
|
1364
1364
|
return dispatcher.useState(initialState);
|
|
1365
1365
|
}
|
|
@@ -1947,7 +1947,7 @@ var require_react_development = __commonJS({
|
|
|
1947
1947
|
exports2.useMemo = useMemo;
|
|
1948
1948
|
exports2.useReducer = useReducer;
|
|
1949
1949
|
exports2.useRef = useRef4;
|
|
1950
|
-
exports2.useState =
|
|
1950
|
+
exports2.useState = useState5;
|
|
1951
1951
|
exports2.version = ReactVersion;
|
|
1952
1952
|
})();
|
|
1953
1953
|
}
|
|
@@ -68789,7 +68789,7 @@ var require_backend = __commonJS({
|
|
|
68789
68789
|
});
|
|
68790
68790
|
return a2;
|
|
68791
68791
|
},
|
|
68792
|
-
useState: function
|
|
68792
|
+
useState: function useState5(a2) {
|
|
68793
68793
|
var b2 = B2();
|
|
68794
68794
|
a2 = b2 !== null ? b2.memoizedState : typeof a2 === "function" ? a2() : a2;
|
|
68795
68795
|
w2.push({
|
|
@@ -83408,10 +83408,10 @@ var require_command = __commonJS({
|
|
|
83408
83408
|
var getEscapedCommand2 = (file, args2) => {
|
|
83409
83409
|
return normalizeArgs2(file, args2).map((arg2) => escapeArg2(arg2)).join(" ");
|
|
83410
83410
|
};
|
|
83411
|
-
var
|
|
83411
|
+
var SPACES_REGEXP2 = / +/g;
|
|
83412
83412
|
var parseCommand3 = (command2) => {
|
|
83413
83413
|
const tokens = [];
|
|
83414
|
-
for (const token of command2.trim().split(
|
|
83414
|
+
for (const token of command2.trim().split(SPACES_REGEXP2)) {
|
|
83415
83415
|
const previousToken = tokens[tokens.length - 1];
|
|
83416
83416
|
if (previousToken && previousToken.endsWith("\\")) {
|
|
83417
83417
|
tokens[tokens.length - 1] = `${previousToken.slice(0, -1)} ${token}`;
|
|
@@ -107858,6 +107858,19 @@ var escapeArg = (arg2) => {
|
|
|
107858
107858
|
};
|
|
107859
107859
|
var joinCommand = (file, args2) => normalizeArgs(file, args2).join(" ");
|
|
107860
107860
|
var getEscapedCommand = (file, args2) => normalizeArgs(file, args2).map((arg2) => escapeArg(arg2)).join(" ");
|
|
107861
|
+
var SPACES_REGEXP = / +/g;
|
|
107862
|
+
var parseCommand = (command2) => {
|
|
107863
|
+
const tokens = [];
|
|
107864
|
+
for (const token of command2.trim().split(SPACES_REGEXP)) {
|
|
107865
|
+
const previousToken = tokens[tokens.length - 1];
|
|
107866
|
+
if (previousToken && previousToken.endsWith("\\")) {
|
|
107867
|
+
tokens[tokens.length - 1] = `${previousToken.slice(0, -1)} ${token}`;
|
|
107868
|
+
} else {
|
|
107869
|
+
tokens.push(token);
|
|
107870
|
+
}
|
|
107871
|
+
}
|
|
107872
|
+
return tokens;
|
|
107873
|
+
};
|
|
107861
107874
|
|
|
107862
107875
|
// ../../node_modules/execa/index.js
|
|
107863
107876
|
var DEFAULT_MAX_BUFFER = 1e3 * 1e3 * 100;
|
|
@@ -107977,6 +107990,10 @@ function execa5(file, args2, options) {
|
|
|
107977
107990
|
spawned.all = makeAllStream(spawned, parsed.options);
|
|
107978
107991
|
return mergePromise(spawned, handlePromiseOnce);
|
|
107979
107992
|
}
|
|
107993
|
+
function execaCommand(command2, options) {
|
|
107994
|
+
const [file, ...args2] = parseCommand(command2);
|
|
107995
|
+
return execa5(file, args2, options);
|
|
107996
|
+
}
|
|
107980
107997
|
|
|
107981
107998
|
// node_modules/node-fetch/src/index.js
|
|
107982
107999
|
init_import_meta_url();
|
|
@@ -112185,7 +112202,7 @@ var import_http = __toModule(require("http"));
|
|
|
112185
112202
|
var import_react2 = __toModule(require_react());
|
|
112186
112203
|
|
|
112187
112204
|
// package.json
|
|
112188
|
-
var version = "0.0.
|
|
112205
|
+
var version = "0.0.14";
|
|
112189
112206
|
|
|
112190
112207
|
// src/inspect.ts
|
|
112191
112208
|
function useInspector(props) {
|
|
@@ -112336,9 +112353,9 @@ function useInspector(props) {
|
|
|
112336
112353
|
};
|
|
112337
112354
|
}, [
|
|
112338
112355
|
props.inspectorUrl,
|
|
112339
|
-
retryRemoteWebSocketConnectionSigil,
|
|
112340
112356
|
props.logToTerminal,
|
|
112341
|
-
wsServer
|
|
112357
|
+
wsServer,
|
|
112358
|
+
retryRemoteWebSocketConnectionSigil
|
|
112342
112359
|
]);
|
|
112343
112360
|
const messageBufferRef = (0, import_react2.useRef)([]);
|
|
112344
112361
|
(0, import_react2.useEffect)(() => {
|
|
@@ -112552,6 +112569,10 @@ function usePreviewServer({
|
|
|
112552
112569
|
const proxy = proxyServer.current ??= createProxyServer();
|
|
112553
112570
|
const streamBufferRef = (0, import_react3.useRef)([]);
|
|
112554
112571
|
const requestResponseBufferRef = (0, import_react3.useRef)([]);
|
|
112572
|
+
const [retryServerSetupSigil, setRetryServerSetupSigil] = (0, import_react3.useState)(0);
|
|
112573
|
+
function retryServerSetup() {
|
|
112574
|
+
setRetryServerSetupSigil((x3) => x3 + 1);
|
|
112575
|
+
}
|
|
112555
112576
|
(0, import_react3.useEffect)(() => {
|
|
112556
112577
|
if (!previewToken2) {
|
|
112557
112578
|
const cleanupListeners2 = [];
|
|
@@ -112573,6 +112594,8 @@ function usePreviewServer({
|
|
|
112573
112594
|
const assetPath = typeof publicRoot === "string" ? publicRoot : null;
|
|
112574
112595
|
const remote = (0, import_node_http22.connect)(`https://${previewToken2.host}`);
|
|
112575
112596
|
cleanupListeners.push(() => remote.destroy());
|
|
112597
|
+
remote.on("close", retryServerSetup);
|
|
112598
|
+
cleanupListeners.push(() => remote.off("close", retryServerSetup));
|
|
112576
112599
|
const handleStream = createStreamHandler(previewToken2, remote, port);
|
|
112577
112600
|
proxy.on("stream", handleStream);
|
|
112578
112601
|
cleanupListeners.push(() => proxy.off("stream", handleStream));
|
|
@@ -112626,9 +112649,15 @@ function usePreviewServer({
|
|
|
112626
112649
|
proxy.on("upgrade", handleUpgrade);
|
|
112627
112650
|
cleanupListeners.push(() => proxy.off("upgrade", handleUpgrade));
|
|
112628
112651
|
return () => {
|
|
112629
|
-
cleanupListeners.forEach((
|
|
112652
|
+
cleanupListeners.forEach((cleanup) => cleanup());
|
|
112630
112653
|
};
|
|
112631
|
-
}, [
|
|
112654
|
+
}, [
|
|
112655
|
+
previewToken2,
|
|
112656
|
+
publicRoot,
|
|
112657
|
+
port,
|
|
112658
|
+
proxy,
|
|
112659
|
+
retryServerSetupSigil
|
|
112660
|
+
]);
|
|
112632
112661
|
(0, import_react3.useEffect)(() => {
|
|
112633
112662
|
proxy.listen(port);
|
|
112634
112663
|
console.log(`\u2B23 Listening at http://localhost:${port}`);
|
|
@@ -112970,7 +112999,8 @@ function Dev(props) {
|
|
|
112970
112999
|
bindings: props.bindings,
|
|
112971
113000
|
site: props.assetPaths,
|
|
112972
113001
|
public: props.public,
|
|
112973
|
-
port
|
|
113002
|
+
port,
|
|
113003
|
+
enableLocalPersistence: props.enableLocalPersistence
|
|
112974
113004
|
}) : /* @__PURE__ */ import_react4.default.createElement(Remote, {
|
|
112975
113005
|
name: props.name,
|
|
112976
113006
|
bundle,
|
|
@@ -113025,7 +113055,8 @@ function Local(props) {
|
|
|
113025
113055
|
bundle: props.bundle,
|
|
113026
113056
|
format: props.format,
|
|
113027
113057
|
bindings: props.bindings,
|
|
113028
|
-
port: props.port
|
|
113058
|
+
port: props.port,
|
|
113059
|
+
enableLocalPersistence: props.enableLocalPersistence
|
|
113029
113060
|
});
|
|
113030
113061
|
useInspector({ inspectorUrl, port: 9229, logToTerminal: false });
|
|
113031
113062
|
return null;
|
|
@@ -113062,9 +113093,7 @@ function useLocalWorker(props) {
|
|
|
113062
113093
|
import_node_path8.default.join(__dirname, "../miniflare-config-stubs/package.empty.json"),
|
|
113063
113094
|
"--port",
|
|
113064
113095
|
port.toString(),
|
|
113065
|
-
"--kv-persist",
|
|
113066
|
-
"--cache-persist",
|
|
113067
|
-
"--do-persist",
|
|
113096
|
+
...props.enableLocalPersistence ? ["--kv-persist", "--cache-persist", "--do-persist"] : [],
|
|
113068
113097
|
...Object.entries(bindings.vars || {}).flatMap(([key2, value]) => {
|
|
113069
113098
|
return ["--binding", `${key2}=${value}`];
|
|
113070
113099
|
}),
|
|
@@ -113164,18 +113193,19 @@ function useCustomBuild(expectedEntry, props) {
|
|
|
113164
113193
|
return;
|
|
113165
113194
|
let cmd, interval;
|
|
113166
113195
|
console.log("running:", command2);
|
|
113167
|
-
|
|
113168
|
-
cmd = execa5(commandPieces[0], commandPieces.slice(1), {
|
|
113196
|
+
cmd = execaCommand(command2, {
|
|
113169
113197
|
...cwd && { cwd },
|
|
113198
|
+
shell: true,
|
|
113170
113199
|
stderr: "inherit",
|
|
113171
113200
|
stdout: "inherit"
|
|
113172
113201
|
});
|
|
113173
113202
|
if (watch_dir) {
|
|
113174
|
-
(0, import_chokidar.watch)(watch_dir, { persistent: true, ignoreInitial: true }).on("all", (_event,
|
|
113175
|
-
console.log(`The file ${
|
|
113203
|
+
(0, import_chokidar.watch)(watch_dir, { persistent: true, ignoreInitial: true }).on("all", (_event, filePath) => {
|
|
113204
|
+
console.log(`The file ${filePath} changed, restarting build...`);
|
|
113176
113205
|
cmd.kill();
|
|
113177
|
-
cmd =
|
|
113206
|
+
cmd = execaCommand(command2, {
|
|
113178
113207
|
...cwd && { cwd },
|
|
113208
|
+
shell: true,
|
|
113179
113209
|
stderr: "inherit",
|
|
113180
113210
|
stdout: "inherit"
|
|
113181
113211
|
});
|
|
@@ -122963,6 +122993,7 @@ var pages = (yargs) => {
|
|
|
122963
122993
|
}
|
|
122964
122994
|
}`
|
|
122965
122995
|
};
|
|
122996
|
+
scriptReadyResolve();
|
|
122966
122997
|
}
|
|
122967
122998
|
}
|
|
122968
122999
|
const { Miniflare, Log, LogLevel } = await import("miniflare");
|
|
@@ -123142,8 +123173,8 @@ async function publish(props) {
|
|
|
123142
123173
|
const destination = await import_tmp_promise2.default.dir({ unsafeCleanup: true });
|
|
123143
123174
|
if (props.config.build?.command) {
|
|
123144
123175
|
console.log("running:", props.config.build.command);
|
|
123145
|
-
|
|
123146
|
-
|
|
123176
|
+
await execaCommand(props.config.build.command, {
|
|
123177
|
+
shell: true,
|
|
123147
123178
|
stdout: "inherit",
|
|
123148
123179
|
stderr: "inherit",
|
|
123149
123180
|
...props.config.build?.cwd && { cwd: props.config.build.cwd }
|
|
@@ -123510,7 +123541,7 @@ ${err2.message ?? err2}`);
|
|
|
123510
123541
|
wrangler: version
|
|
123511
123542
|
}
|
|
123512
123543
|
}, null, " ") + "\n");
|
|
123513
|
-
await execa5("npm", ["install"
|
|
123544
|
+
await execa5("npm", ["install"], {
|
|
123514
123545
|
stdio: "inherit"
|
|
123515
123546
|
});
|
|
123516
123547
|
console.log(`\u2728 Created package.json`);
|
|
@@ -123523,12 +123554,7 @@ ${err2.message ?? err2}`);
|
|
|
123523
123554
|
if (!(packageJson.devDependencies?.wrangler || packageJson.dependencies?.wrangler)) {
|
|
123524
123555
|
const shouldInstall = await confirm("Would you like to install wrangler into your package.json?");
|
|
123525
123556
|
if (shouldInstall) {
|
|
123526
|
-
await execa5("npm", [
|
|
123527
|
-
"install",
|
|
123528
|
-
`wrangler@${version}`,
|
|
123529
|
-
"--save-dev",
|
|
123530
|
-
"--prefer-offline"
|
|
123531
|
-
], {
|
|
123557
|
+
await execa5("npm", ["install", `wrangler@${version}`, "--save-dev"], {
|
|
123532
123558
|
stdio: "inherit"
|
|
123533
123559
|
});
|
|
123534
123560
|
console.log(`\u2728 Installed wrangler`);
|
|
@@ -123554,12 +123580,7 @@ ${err2.message ?? err2}`);
|
|
|
123554
123580
|
types: ["@cloudflare/workers-types"]
|
|
123555
123581
|
}
|
|
123556
123582
|
}, null, " ") + "\n");
|
|
123557
|
-
await execa5("npm", [
|
|
123558
|
-
"install",
|
|
123559
|
-
"@cloudflare/workers-types",
|
|
123560
|
-
"--save-dev",
|
|
123561
|
-
"--prefer-offline"
|
|
123562
|
-
], { stdio: "inherit" });
|
|
123583
|
+
await execa5("npm", ["install", "@cloudflare/workers-types", "--save-dev"], { stdio: "inherit" });
|
|
123563
123584
|
console.log(`\u2728 Created tsconfig.json, installed @cloudflare/workers-types into devDependencies`);
|
|
123564
123585
|
pathToTSConfig = import_posix.default.join(process.cwd(), "tsconfig.json");
|
|
123565
123586
|
}
|
|
@@ -123568,12 +123589,7 @@ ${err2.message ?? err2}`);
|
|
|
123568
123589
|
if (!(packageJson.devDependencies?.["@cloudflare/workers-types"] || packageJson.dependencies?.["@cloudflare/workers-types"])) {
|
|
123569
123590
|
const shouldInstall = await confirm("Would you like to install the type definitions for Workers into your package.json?");
|
|
123570
123591
|
if (shouldInstall) {
|
|
123571
|
-
await execa5("npm", [
|
|
123572
|
-
"install",
|
|
123573
|
-
"@cloudflare/workers-types",
|
|
123574
|
-
"--save-dev",
|
|
123575
|
-
"--prefer-offline"
|
|
123576
|
-
], {
|
|
123592
|
+
await execa5("npm", ["install", "@cloudflare/workers-types", "--save-dev"], {
|
|
123577
123593
|
stdio: "inherit"
|
|
123578
123594
|
});
|
|
123579
123595
|
console.log(`\u2728 Installed @cloudflare/workers-types.
|
|
@@ -123693,6 +123709,9 @@ Please add "@cloudflare/workers-types" to compilerOptions.types in your tsconfig
|
|
|
123693
123709
|
}).option("jsx-fragment", {
|
|
123694
123710
|
describe: "The function that is called for each JSX fragment",
|
|
123695
123711
|
type: "string"
|
|
123712
|
+
}).option("experimental-enable-local-persistence", {
|
|
123713
|
+
describe: "Enable persistence for this session (only for local mode)",
|
|
123714
|
+
type: "boolean"
|
|
123696
123715
|
});
|
|
123697
123716
|
}, async (args2) => {
|
|
123698
123717
|
const { filename, format: format3 } = args2;
|
|
@@ -123734,6 +123753,7 @@ Please add "@cloudflare/workers-types" to compilerOptions.types in your tsconfig
|
|
|
123734
123753
|
initialMode: args2.local ? "local" : "remote",
|
|
123735
123754
|
jsxFactory: args2["jsx-factory"] || envRootObj?.jsx_factory,
|
|
123736
123755
|
jsxFragment: args2["jsx-fragment"] || envRootObj?.jsx_fragment,
|
|
123756
|
+
enableLocalPersistence: args2["experimental-enable-local-persistence"] || false,
|
|
123737
123757
|
accountId: config.account_id,
|
|
123738
123758
|
assetPaths: getAssetPaths(config, args2.site, args2.siteInclude, args2.siteExclude),
|
|
123739
123759
|
port: args2.port || config.dev?.port,
|
|
@@ -124015,14 +124035,14 @@ Please add "@cloudflare/workers-types" to compilerOptions.types in your tsconfig
|
|
|
124015
124035
|
describe: "Binds the secret to the script of the specific environment."
|
|
124016
124036
|
});
|
|
124017
124037
|
}, async (args2) => {
|
|
124018
|
-
if (args2.local) {
|
|
124019
|
-
throw new NotImplementedError("--local not implemented for this command yet");
|
|
124020
|
-
}
|
|
124021
124038
|
const config = args2.config;
|
|
124022
124039
|
const scriptName = args2.name || config.name;
|
|
124023
124040
|
if (!scriptName) {
|
|
124024
124041
|
throw new Error("Missing script name");
|
|
124025
124042
|
}
|
|
124043
|
+
if (args2.local) {
|
|
124044
|
+
console.warn("`wrangler secret put` is a no-op in --local mode");
|
|
124045
|
+
}
|
|
124026
124046
|
if (!args2.local) {
|
|
124027
124047
|
const loggedIn = await loginOrRefreshIfRequired();
|
|
124028
124048
|
if (!loggedIn) {
|
|
@@ -124037,6 +124057,10 @@ Please add "@cloudflare/workers-types" to compilerOptions.types in your tsconfig
|
|
|
124037
124057
|
}
|
|
124038
124058
|
}
|
|
124039
124059
|
const secretValue = await prompt("Enter a secret value:", "password");
|
|
124060
|
+
if (args2.local) {
|
|
124061
|
+
return;
|
|
124062
|
+
}
|
|
124063
|
+
console.log(`\u{1F300} Creating the secret for script ${scriptName}`);
|
|
124040
124064
|
async function submitSecret() {
|
|
124041
124065
|
return await fetchResult(`/accounts/${config.account_id}/workers/scripts/${scriptName}/secrets/`, {
|
|
124042
124066
|
method: "PUT",
|
|
@@ -124049,7 +124073,7 @@ Please add "@cloudflare/workers-types" to compilerOptions.types in your tsconfig
|
|
|
124049
124073
|
});
|
|
124050
124074
|
}
|
|
124051
124075
|
try {
|
|
124052
|
-
|
|
124076
|
+
await submitSecret();
|
|
124053
124077
|
} catch (e3) {
|
|
124054
124078
|
if (e3.code === 10007) {
|
|
124055
124079
|
await fetchResult(`/accounts/${config.account_id}/workers/scripts/${scriptName}`, {
|
|
@@ -124068,9 +124092,10 @@ Please add "@cloudflare/workers-types" to compilerOptions.types in your tsconfig
|
|
|
124068
124092
|
modules: []
|
|
124069
124093
|
})
|
|
124070
124094
|
});
|
|
124071
|
-
|
|
124095
|
+
await submitSecret();
|
|
124072
124096
|
}
|
|
124073
124097
|
}
|
|
124098
|
+
console.log(`\u2728 Success! Uploaded secret ${args2.key}`);
|
|
124074
124099
|
}).command("delete <key>", "Delete a secret variable from a script", (yargs) => {
|
|
124075
124100
|
return yargs.positional("key", {
|
|
124076
124101
|
describe: "The variable name to be accessible in the script.",
|
|
@@ -124083,14 +124108,14 @@ Please add "@cloudflare/workers-types" to compilerOptions.types in your tsconfig
|
|
|
124083
124108
|
describe: "Binds the secret to the script of the specific environment."
|
|
124084
124109
|
});
|
|
124085
124110
|
}, async (args2) => {
|
|
124086
|
-
if (args2.local) {
|
|
124087
|
-
throw new NotImplementedError("--local not implemented for this command yet");
|
|
124088
|
-
}
|
|
124089
124111
|
const config = args2.config;
|
|
124090
124112
|
const scriptName = args2.name || config.name;
|
|
124091
124113
|
if (!scriptName) {
|
|
124092
124114
|
throw new Error("Missing script name");
|
|
124093
124115
|
}
|
|
124116
|
+
if (args2.local) {
|
|
124117
|
+
console.warn("`wrangler secret delete` is a no-op in --local mode");
|
|
124118
|
+
}
|
|
124094
124119
|
if (!args2.local) {
|
|
124095
124120
|
const loggedIn = await loginOrRefreshIfRequired();
|
|
124096
124121
|
if (!loggedIn) {
|
|
@@ -124104,9 +124129,13 @@ Please add "@cloudflare/workers-types" to compilerOptions.types in your tsconfig
|
|
|
124104
124129
|
}
|
|
124105
124130
|
}
|
|
124106
124131
|
}
|
|
124107
|
-
if (await confirm(
|
|
124108
|
-
console.log(
|
|
124109
|
-
|
|
124132
|
+
if (await confirm(`Are you sure you want to permanently delete the variable ${args2.key} on the script ${scriptName}?`)) {
|
|
124133
|
+
console.log(`\u{1F300} Deleting the secret ${args2.key} on script ${scriptName}.`);
|
|
124134
|
+
if (args2.local) {
|
|
124135
|
+
return;
|
|
124136
|
+
}
|
|
124137
|
+
await fetchResult(`/accounts/${config.account_id}/workers/scripts/${scriptName}/secrets/${args2.key}`, { method: "DELETE" });
|
|
124138
|
+
console.log(`\u2728 Success! Deleted secret ${args2.key}`);
|
|
124110
124139
|
}
|
|
124111
124140
|
}).command("list", "List all secrets for a script", (yargs) => {
|
|
124112
124141
|
return yargs.option("name", {
|
|
@@ -124117,14 +124146,14 @@ Please add "@cloudflare/workers-types" to compilerOptions.types in your tsconfig
|
|
|
124117
124146
|
describe: "Binds the secret to the script of the specific environment."
|
|
124118
124147
|
});
|
|
124119
124148
|
}, async (args2) => {
|
|
124120
|
-
if (args2.local) {
|
|
124121
|
-
throw new NotImplementedError("--local not implemented for this command yet");
|
|
124122
|
-
}
|
|
124123
124149
|
const config = args2.config;
|
|
124124
124150
|
const scriptName = args2.name || config.name;
|
|
124125
124151
|
if (!scriptName) {
|
|
124126
124152
|
throw new Error("Missing script name");
|
|
124127
124153
|
}
|
|
124154
|
+
if (args2.local) {
|
|
124155
|
+
console.warn("`wrangler secret list` is a no-op in --local mode");
|
|
124156
|
+
}
|
|
124128
124157
|
if (!args2.local) {
|
|
124129
124158
|
const loggedIn = await loginOrRefreshIfRequired();
|
|
124130
124159
|
if (!loggedIn) {
|
|
@@ -124138,7 +124167,10 @@ Please add "@cloudflare/workers-types" to compilerOptions.types in your tsconfig
|
|
|
124138
124167
|
}
|
|
124139
124168
|
}
|
|
124140
124169
|
}
|
|
124141
|
-
|
|
124170
|
+
if (args2.local) {
|
|
124171
|
+
return;
|
|
124172
|
+
}
|
|
124173
|
+
console.log(JSON.stringify(await fetchResult(`/accounts/${config.account_id}/workers/scripts/${scriptName}/secrets`), null, " "));
|
|
124142
124174
|
});
|
|
124143
124175
|
});
|
|
124144
124176
|
wrangler.command("kv:namespace", "\u{1F5C2}\uFE0F Interact with your Workers KV Namespaces", (namespaceYargs) => {
|