wrangler 0.0.0-aed7e33 → 0.0.0-afb8958
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/wrangler.js +36 -5
- package/package.json +73 -64
- package/src/__tests__/configuration.test.ts +11 -7
- package/src/__tests__/dev.test.tsx +44 -0
- package/src/__tests__/helpers/run-in-tmp.ts +22 -23
- package/src/__tests__/https-options.test.ts +51 -18
- package/src/__tests__/index.test.ts +13 -13
- package/src/__tests__/jest.setup.ts +13 -0
- package/src/__tests__/kv.test.ts +33 -2
- package/src/__tests__/metrics.test.ts +445 -0
- package/src/__tests__/pages.test.ts +15 -8
- package/src/__tests__/publish.test.ts +49 -23
- package/src/__tests__/secret.test.ts +84 -78
- package/src/__tests__/tail.test.ts +8 -0
- package/src/__tests__/test-old-node-version.js +31 -0
- package/src/__tests__/user.test.ts +7 -7
- package/src/__tests__/whoami.test.tsx +11 -1
- package/src/bundle.ts +29 -9
- package/src/cli.ts +1 -1
- package/src/config/config.ts +8 -0
- package/src/config/validation.ts +9 -0
- package/src/config-cache.ts +2 -1
- package/src/dev/dev.tsx +28 -18
- package/src/dev/local.tsx +9 -4
- package/src/dev/remote.tsx +5 -1
- package/src/dev.tsx +7 -1
- package/src/entry.ts +0 -3
- package/src/{__tests__/helpers/faye-websocket.d.ts → faye-websocket.d.ts} +0 -0
- package/src/global-wrangler-config-path.ts +26 -0
- package/src/https-options.ts +8 -4
- package/src/index.tsx +120 -22
- package/src/kv.ts +23 -1
- package/src/metrics/index.ts +4 -0
- package/src/metrics/is-ci.ts +14 -0
- package/src/metrics/metrics-config.ts +239 -0
- package/src/metrics/metrics-dispatcher.ts +95 -0
- package/src/metrics/send-event.ts +92 -0
- package/src/package-manager.ts +45 -0
- package/src/pages/build.tsx +2 -0
- package/src/pages/deployments.tsx +6 -1
- package/src/pages/dev.tsx +4 -0
- package/src/pages/projects.tsx +7 -1
- package/src/pages/publish.tsx +3 -0
- package/src/pages/upload.tsx +26 -14
- package/src/publish.ts +28 -15
- package/src/pubsub/pubsub-commands.tsx +46 -0
- package/src/user/user.tsx +31 -21
- package/src/whoami.tsx +2 -1
- package/src/worker-namespace.ts +16 -0
- package/templates/static-asset-facade.js +11 -5
- package/templates/tsconfig.json +2 -2
- package/wrangler-dist/cli.d.ts +298 -0
- package/wrangler-dist/cli.js +2957 -1760
- package/src/wasi.ts +0 -85
package/bin/wrangler.js
CHANGED
|
@@ -3,7 +3,6 @@ const { spawn } = require("child_process");
|
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const os = require("os");
|
|
6
|
-
const semiver = require("semiver");
|
|
7
6
|
|
|
8
7
|
const MIN_NODE_VERSION = "16.7.0";
|
|
9
8
|
const debug =
|
|
@@ -21,8 +20,8 @@ function runWrangler() {
|
|
|
21
20
|
// Note Volta and nvm are also recommended in the official docs:
|
|
22
21
|
// https://developers.cloudflare.com/workers/get-started/guide#2-install-the-workers-cli
|
|
23
22
|
console.error(
|
|
24
|
-
`Wrangler requires at least
|
|
25
|
-
|
|
23
|
+
`Wrangler requires at least node.js v${MIN_NODE_VERSION}. You are using v${process.versions.node}. Please update your version of node.js.
|
|
24
|
+
|
|
26
25
|
Consider using a Node.js version manager such as https://volta.sh/ or https://github.com/nvm-sh/nvm.`
|
|
27
26
|
);
|
|
28
27
|
process.exitCode = 1;
|
|
@@ -128,10 +127,42 @@ async function main() {
|
|
|
128
127
|
}
|
|
129
128
|
|
|
130
129
|
process.on("SIGINT", () => {
|
|
131
|
-
wranglerProcess
|
|
130
|
+
wranglerProcess && wranglerProcess.kill();
|
|
132
131
|
});
|
|
133
132
|
process.on("SIGTERM", () => {
|
|
134
|
-
wranglerProcess
|
|
133
|
+
wranglerProcess && wranglerProcess.kill();
|
|
135
134
|
});
|
|
136
135
|
|
|
136
|
+
// semiver implementation via https://github.com/lukeed/semiver/blob/ae7eebe6053c96be63032b14fb0b68e2553fcac4/src/index.js
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
MIT License
|
|
140
|
+
|
|
141
|
+
Copyright (c) Luke Edwards <luke.edwards05@gmail.com> (lukeed.com)
|
|
142
|
+
|
|
143
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
144
|
+
|
|
145
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
146
|
+
|
|
147
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
148
|
+
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
var fn = new Intl.Collator(0, { numeric: 1 }).compare;
|
|
152
|
+
|
|
153
|
+
function semiver(a, b, bool) {
|
|
154
|
+
a = a.split(".");
|
|
155
|
+
b = b.split(".");
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
fn(a[0], b[0]) ||
|
|
159
|
+
fn(a[1], b[1]) ||
|
|
160
|
+
((b[2] = b.slice(2).join(".")),
|
|
161
|
+
(bool = /[.-]/.test((a[2] = a.slice(2).join(".")))),
|
|
162
|
+
bool == /[.-]/.test(b[2]) ? fn(a[2], b[2]) : bool ? -1 : 1)
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// end semiver implementation
|
|
167
|
+
|
|
137
168
|
void main();
|
package/package.json
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wrangler",
|
|
3
|
-
"version": "0.0.0-
|
|
4
|
-
"author": "wrangler@cloudflare.com",
|
|
3
|
+
"version": "0.0.0-afb8958",
|
|
5
4
|
"description": "Command-line interface for all things Cloudflare Workers",
|
|
6
|
-
"bin": {
|
|
7
|
-
"wrangler": "./bin/wrangler.js",
|
|
8
|
-
"wrangler2": "./bin/wrangler.js"
|
|
9
|
-
},
|
|
10
|
-
"main": "wrangler-dist/cli.js",
|
|
11
|
-
"license": "MIT OR Apache-2.0",
|
|
12
|
-
"bugs": {
|
|
13
|
-
"url": "https://github.com/cloudflare/wrangler2/issues"
|
|
14
|
-
},
|
|
15
|
-
"homepage": "https://github.com/cloudflare/wrangler2#readme",
|
|
16
5
|
"keywords": [
|
|
17
6
|
"wrangler",
|
|
18
7
|
"cloudflare",
|
|
@@ -29,32 +18,93 @@
|
|
|
29
18
|
"webassembly",
|
|
30
19
|
"rust",
|
|
31
20
|
"emscripten",
|
|
32
|
-
"rust",
|
|
33
21
|
"typescript",
|
|
34
22
|
"graphql",
|
|
35
23
|
"router",
|
|
36
24
|
"http",
|
|
37
25
|
"cli"
|
|
38
26
|
],
|
|
27
|
+
"homepage": "https://github.com/cloudflare/wrangler2#readme",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/cloudflare/wrangler2/issues"
|
|
30
|
+
},
|
|
31
|
+
"license": "MIT OR Apache-2.0",
|
|
32
|
+
"author": "wrangler@cloudflare.com",
|
|
33
|
+
"main": "wrangler-dist/cli.js",
|
|
34
|
+
"types": "wrangler-dist/cli.d.ts",
|
|
35
|
+
"bin": {
|
|
36
|
+
"wrangler": "./bin/wrangler.js",
|
|
37
|
+
"wrangler2": "./bin/wrangler.js"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"src",
|
|
41
|
+
"bin",
|
|
42
|
+
"miniflare-config-stubs",
|
|
43
|
+
"miniflare-dist",
|
|
44
|
+
"wrangler-dist",
|
|
45
|
+
"templates",
|
|
46
|
+
"vendor",
|
|
47
|
+
"import_meta_url.js",
|
|
48
|
+
"kv-asset-handler.js",
|
|
49
|
+
"Cloudflare_CA.pem"
|
|
50
|
+
],
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "npm run clean && npm run bundle && npm run emit-types",
|
|
53
|
+
"bundle": "node -r esbuild-register scripts/bundle.ts",
|
|
54
|
+
"check:type": "tsc",
|
|
55
|
+
"clean": "rm -rf wrangler-dist miniflare-dist emitted-types",
|
|
56
|
+
"dev": "npm run clean && concurrently -c black,blue 'npm run bundle -- --watch' 'npm run check:type -- --watch --preserveWatchOutput'",
|
|
57
|
+
"emit-types": "tsc -p tsconfig.emit.json && node -r esbuild-register scripts/emit-types.ts",
|
|
58
|
+
"prepublishOnly": "SOURCEMAPS=false npm run build",
|
|
59
|
+
"start": "npm run bundle && NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
|
|
60
|
+
"test": "jest --silent=false --verbose=true",
|
|
61
|
+
"test-watch": "npm run test -- --runInBand --testTimeout=50000 --watch"
|
|
62
|
+
},
|
|
63
|
+
"jest": {
|
|
64
|
+
"collectCoverage": true,
|
|
65
|
+
"coverageReporters": [
|
|
66
|
+
"json",
|
|
67
|
+
"html",
|
|
68
|
+
"text",
|
|
69
|
+
"cobertura"
|
|
70
|
+
],
|
|
71
|
+
"moduleNameMapper": {
|
|
72
|
+
"clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js",
|
|
73
|
+
"miniflare/cli": "<rootDir>/../../node_modules/miniflare/dist/src/cli.js"
|
|
74
|
+
},
|
|
75
|
+
"restoreMocks": true,
|
|
76
|
+
"setupFilesAfterEnv": [
|
|
77
|
+
"<rootDir>/src/__tests__/jest.setup.ts"
|
|
78
|
+
],
|
|
79
|
+
"testRegex": ".*.(test|spec)\\.[jt]sx?$",
|
|
80
|
+
"testTimeout": 30000,
|
|
81
|
+
"transform": {
|
|
82
|
+
"^.+\\.c?(t|j)sx?$": [
|
|
83
|
+
"esbuild-jest",
|
|
84
|
+
{
|
|
85
|
+
"sourcemap": true
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
},
|
|
89
|
+
"transformIgnorePatterns": [
|
|
90
|
+
"node_modules/(?!find-up|locate-path|p-locate|p-limit|p-timeout|p-queue|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream|get-port|supports-color|pretty-bytes)"
|
|
91
|
+
]
|
|
92
|
+
},
|
|
39
93
|
"dependencies": {
|
|
40
94
|
"@cloudflare/kv-asset-handler": "^0.2.0",
|
|
41
|
-
"@cloudflare/workers-wasi": "^0.0.5",
|
|
42
95
|
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
|
|
43
96
|
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
|
|
44
97
|
"blake3-wasm": "^2.1.5",
|
|
45
98
|
"esbuild": "0.14.47",
|
|
46
|
-
"miniflare": "^2.
|
|
99
|
+
"miniflare": "^2.6.0",
|
|
47
100
|
"nanoid": "^3.3.3",
|
|
48
101
|
"path-to-regexp": "^6.2.0",
|
|
49
102
|
"selfsigned": "^2.0.1",
|
|
50
|
-
"semiver": "^1.1.0",
|
|
51
103
|
"xxhash-wasm": "^1.0.1"
|
|
52
104
|
},
|
|
53
|
-
"optionalDependencies": {
|
|
54
|
-
"fsevents": "~2.3.2"
|
|
55
|
-
},
|
|
56
105
|
"devDependencies": {
|
|
57
106
|
"@iarna/toml": "^3.0.0",
|
|
107
|
+
"@microsoft/api-extractor": "^7.28.3",
|
|
58
108
|
"@types/command-exists": "^1.2.0",
|
|
59
109
|
"@types/glob-to-regexp": "0.4.1",
|
|
60
110
|
"@types/mime": "^2.0.3",
|
|
@@ -87,6 +137,7 @@
|
|
|
87
137
|
"ink-table": "^3.0.0",
|
|
88
138
|
"ink-testing-library": "^2.1.0",
|
|
89
139
|
"ink-text-input": "^4.0.3",
|
|
140
|
+
"is-ci": "^3.0.1",
|
|
90
141
|
"jest-fetch-mock": "^3.0.3",
|
|
91
142
|
"jest-websocket-mock": "^2.3.0",
|
|
92
143
|
"mime": "^3.0.0",
|
|
@@ -105,55 +156,13 @@
|
|
|
105
156
|
"undici": "^5.5.1",
|
|
106
157
|
"update-check": "^1.5.4",
|
|
107
158
|
"ws": "^8.5.0",
|
|
159
|
+
"xdg-app-paths": "^7.3.0",
|
|
108
160
|
"yargs": "^17.4.1"
|
|
109
161
|
},
|
|
110
|
-
"
|
|
111
|
-
"
|
|
112
|
-
"bin",
|
|
113
|
-
"miniflare-config-stubs",
|
|
114
|
-
"miniflare-dist",
|
|
115
|
-
"wrangler-dist",
|
|
116
|
-
"templates",
|
|
117
|
-
"vendor",
|
|
118
|
-
"import_meta_url.js",
|
|
119
|
-
"kv-asset-handler.js",
|
|
120
|
-
"Cloudflare_CA.pem"
|
|
121
|
-
],
|
|
122
|
-
"scripts": {
|
|
123
|
-
"clean": "rm -rf wrangler-dist miniflare-dist",
|
|
124
|
-
"check:type": "tsc",
|
|
125
|
-
"bundle": "node -r esbuild-register scripts/bundle.ts",
|
|
126
|
-
"build": "npm run clean && npm run bundle",
|
|
127
|
-
"dev": "npm run clean && concurrently -c black,blue 'npm run bundle -- --watch' 'npm run check:type -- --watch --preserveWatchOutput'",
|
|
128
|
-
"prepublishOnly": "SOURCEMAPS=false npm run build",
|
|
129
|
-
"start": "npm run bundle && NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
|
|
130
|
-
"test": "jest --silent=false --verbose=true",
|
|
131
|
-
"test-watch": "npm run test -- --runInBand --testTimeout=50000 --watch"
|
|
162
|
+
"optionalDependencies": {
|
|
163
|
+
"fsevents": "~2.3.2"
|
|
132
164
|
},
|
|
133
165
|
"engines": {
|
|
134
166
|
"node": ">=16.7.0"
|
|
135
|
-
},
|
|
136
|
-
"jest": {
|
|
137
|
-
"restoreMocks": true,
|
|
138
|
-
"testTimeout": 30000,
|
|
139
|
-
"testRegex": ".*.(test|spec)\\.[jt]sx?$",
|
|
140
|
-
"transformIgnorePatterns": [
|
|
141
|
-
"node_modules/(?!find-up|locate-path|p-locate|p-limit|p-timeout|p-queue|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream|get-port|supports-color|pretty-bytes)"
|
|
142
|
-
],
|
|
143
|
-
"moduleNameMapper": {
|
|
144
|
-
"clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js",
|
|
145
|
-
"miniflare/cli": "<rootDir>/../../node_modules/miniflare/dist/src/cli.js"
|
|
146
|
-
},
|
|
147
|
-
"transform": {
|
|
148
|
-
"^.+\\.c?(t|j)sx?$": [
|
|
149
|
-
"esbuild-jest",
|
|
150
|
-
{
|
|
151
|
-
"sourcemap": true
|
|
152
|
-
}
|
|
153
|
-
]
|
|
154
|
-
},
|
|
155
|
-
"setupFilesAfterEnv": [
|
|
156
|
-
"<rootDir>/src/__tests__/jest.setup.ts"
|
|
157
|
-
]
|
|
158
167
|
}
|
|
159
168
|
}
|
|
@@ -40,6 +40,7 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
40
40
|
tsconfig: undefined,
|
|
41
41
|
kv_namespaces: [],
|
|
42
42
|
legacy_env: true,
|
|
43
|
+
send_metrics: undefined,
|
|
43
44
|
main: undefined,
|
|
44
45
|
migrations: [],
|
|
45
46
|
name: undefined,
|
|
@@ -76,6 +77,7 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
76
77
|
it("should override config defaults with provided values", () => {
|
|
77
78
|
const expectedConfig: Partial<ConfigFields<RawDevConfig>> = {
|
|
78
79
|
legacy_env: true,
|
|
80
|
+
send_metrics: false,
|
|
79
81
|
dev: {
|
|
80
82
|
ip: "255.255.255.255",
|
|
81
83
|
port: 9999,
|
|
@@ -98,6 +100,7 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
98
100
|
it("should error on invalid top level fields", () => {
|
|
99
101
|
const expectedConfig = {
|
|
100
102
|
legacy_env: "FOO",
|
|
103
|
+
send_metrics: "BAD",
|
|
101
104
|
dev: {
|
|
102
105
|
ip: 222,
|
|
103
106
|
port: "FOO",
|
|
@@ -117,13 +120,14 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
117
120
|
);
|
|
118
121
|
expect(diagnostics.hasWarnings()).toBe(false);
|
|
119
122
|
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
123
|
+
"Processing wrangler configuration:
|
|
124
|
+
- Expected \\"legacy_env\\" to be of type boolean but got \\"FOO\\".
|
|
125
|
+
- Expected \\"send_metrics\\" to be of type boolean but got \\"BAD\\".
|
|
126
|
+
- Expected \\"dev.ip\\" to be of type string but got 222.
|
|
127
|
+
- Expected \\"dev.port\\" to be of type number but got \\"FOO\\".
|
|
128
|
+
- Expected \\"dev.local_protocol\\" field to be one of [\\"http\\",\\"https\\"] but got \\"wss\\".
|
|
129
|
+
- Expected \\"dev.upstream_protocol\\" field to be one of [\\"http\\",\\"https\\"] but got \\"ws\\"."
|
|
130
|
+
`);
|
|
127
131
|
});
|
|
128
132
|
|
|
129
133
|
it("should warn on and remove unexpected top level fields", () => {
|
|
@@ -1049,6 +1049,50 @@ describe("wrangler dev", () => {
|
|
|
1049
1049
|
}
|
|
1050
1050
|
`);
|
|
1051
1051
|
});
|
|
1052
|
+
|
|
1053
|
+
it("should default to true, without a warning", async () => {
|
|
1054
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
1055
|
+
await runWrangler("dev index.js");
|
|
1056
|
+
expect((Dev as jest.Mock).mock.calls[0][0].inspect).toEqual(true);
|
|
1057
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1058
|
+
Object {
|
|
1059
|
+
"debug": "",
|
|
1060
|
+
"err": "",
|
|
1061
|
+
"out": "",
|
|
1062
|
+
"warn": "",
|
|
1063
|
+
}
|
|
1064
|
+
`);
|
|
1065
|
+
});
|
|
1066
|
+
|
|
1067
|
+
it("should pass true, with a warning", async () => {
|
|
1068
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
1069
|
+
await runWrangler("dev index.js --inspect");
|
|
1070
|
+
expect((Dev as jest.Mock).mock.calls[0][0].inspect).toEqual(true);
|
|
1071
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1072
|
+
Object {
|
|
1073
|
+
"debug": "",
|
|
1074
|
+
"err": "",
|
|
1075
|
+
"out": "",
|
|
1076
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mPassing --inspect is unnecessary, now you can always connect to devtools.[0m
|
|
1077
|
+
|
|
1078
|
+
",
|
|
1079
|
+
}
|
|
1080
|
+
`);
|
|
1081
|
+
});
|
|
1082
|
+
|
|
1083
|
+
it("should pass false, without a warning", async () => {
|
|
1084
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
1085
|
+
await runWrangler("dev index.js --inspect false");
|
|
1086
|
+
expect((Dev as jest.Mock).mock.calls[0][0].inspect).toEqual(false);
|
|
1087
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1088
|
+
Object {
|
|
1089
|
+
"debug": "",
|
|
1090
|
+
"err": "",
|
|
1091
|
+
"out": "",
|
|
1092
|
+
"warn": "",
|
|
1093
|
+
}
|
|
1094
|
+
`);
|
|
1095
|
+
});
|
|
1052
1096
|
});
|
|
1053
1097
|
|
|
1054
1098
|
describe("service bindings", () => {
|
|
@@ -5,35 +5,34 @@ import { reinitialiseAuthTokens } from "../../user";
|
|
|
5
5
|
|
|
6
6
|
const originalCwd = process.cwd();
|
|
7
7
|
|
|
8
|
-
export function runInTempDir({ homedir }
|
|
8
|
+
export function runInTempDir({ homedir } = { homedir: "./home" }) {
|
|
9
9
|
let tmpDir: string;
|
|
10
10
|
|
|
11
|
-
beforeAll(() => {
|
|
12
|
-
if (tmpDir !== undefined) {
|
|
13
|
-
process.chdir(originalCwd);
|
|
14
|
-
fs.rmSync(tmpDir, { recursive: true });
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
|
|
18
11
|
beforeEach(() => {
|
|
19
|
-
|
|
12
|
+
// Use realpath because the temporary path can point to a symlink rather than the actual path.
|
|
13
|
+
tmpDir = fs.realpathSync(
|
|
14
|
+
fs.mkdtempSync(path.join(os.tmpdir(), "wrangler-tests"))
|
|
15
|
+
);
|
|
16
|
+
|
|
20
17
|
process.chdir(tmpDir);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
18
|
+
// The path that is returned from `homedir()` should be absolute.
|
|
19
|
+
const absHomedir = path.resolve(tmpDir, homedir);
|
|
20
|
+
// Override where the home directory is so that we can write our own user config,
|
|
21
|
+
// without destroying the real thing.
|
|
22
|
+
fs.mkdirSync(absHomedir, { recursive: true });
|
|
23
|
+
// Note it is very important that we use the "default" value from "node:os" (e.g. `import os from "node:os";`)
|
|
24
|
+
// rather than an alias to the module (e.g. `import * as os from "node:os";`).
|
|
25
|
+
// This is because the module gets transpiled so that the "method" `homedir()` gets converted to a
|
|
26
|
+
// getter that is not configurable (and so cannot be spied upon).
|
|
27
|
+
jest.spyOn(os, "homedir")?.mockReturnValue(absHomedir);
|
|
28
|
+
// Now that we have changed the home directory location, we must reinitialize the user auth state
|
|
29
|
+
reinitialiseAuthTokens();
|
|
33
30
|
});
|
|
34
31
|
|
|
35
32
|
afterEach(() => {
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
if (fs.existsSync(tmpDir)) {
|
|
34
|
+
process.chdir(originalCwd);
|
|
35
|
+
fs.rmSync(tmpDir, { recursive: true });
|
|
36
|
+
}
|
|
38
37
|
});
|
|
39
38
|
}
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import os from "node:os";
|
|
3
|
-
import
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { getGlobalWranglerConfigPath } from "../global-wrangler-config-path";
|
|
4
5
|
import { getHttpsOptions } from "../https-options";
|
|
5
6
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
6
7
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
7
8
|
|
|
8
9
|
describe("getHttpsOptions()", () => {
|
|
9
|
-
runInTempDir(
|
|
10
|
+
runInTempDir();
|
|
10
11
|
const std = mockConsoleMethods();
|
|
11
12
|
|
|
12
13
|
it("should use cached values if they have not expired", async () => {
|
|
13
|
-
fs.mkdirSync(resolve(
|
|
14
|
+
fs.mkdirSync(path.resolve(getGlobalWranglerConfigPath(), "local-cert"), {
|
|
14
15
|
recursive: true,
|
|
15
16
|
});
|
|
16
17
|
fs.writeFileSync(
|
|
17
|
-
resolve(
|
|
18
|
+
path.resolve(getGlobalWranglerConfigPath(), "local-cert/key.pem"),
|
|
18
19
|
"PRIVATE KEY"
|
|
19
20
|
);
|
|
20
21
|
fs.writeFileSync(
|
|
21
|
-
resolve(
|
|
22
|
+
path.resolve(getGlobalWranglerConfigPath(), "local-cert/cert.pem"),
|
|
22
23
|
"PUBLIC KEY"
|
|
23
24
|
);
|
|
24
25
|
const result = await getHttpsOptions();
|
|
@@ -32,11 +33,11 @@ describe("getHttpsOptions()", () => {
|
|
|
32
33
|
it("should generate and cache new keys if none are cached", async () => {
|
|
33
34
|
const result = await getHttpsOptions();
|
|
34
35
|
const key = fs.readFileSync(
|
|
35
|
-
resolve(
|
|
36
|
+
path.resolve(getGlobalWranglerConfigPath(), "local-cert/key.pem"),
|
|
36
37
|
"utf8"
|
|
37
38
|
);
|
|
38
39
|
const cert = fs.readFileSync(
|
|
39
|
-
resolve(
|
|
40
|
+
path.resolve(getGlobalWranglerConfigPath(), "local-cert/cert.pem"),
|
|
40
41
|
"utf8"
|
|
41
42
|
);
|
|
42
43
|
expect(result.key).toEqual(key);
|
|
@@ -49,28 +50,28 @@ describe("getHttpsOptions()", () => {
|
|
|
49
50
|
});
|
|
50
51
|
|
|
51
52
|
it("should generate and cache new keys if cached files have expired", async () => {
|
|
52
|
-
fs.mkdirSync(resolve(
|
|
53
|
+
fs.mkdirSync(path.resolve(getGlobalWranglerConfigPath(), "local-cert"), {
|
|
53
54
|
recursive: true,
|
|
54
55
|
});
|
|
55
56
|
const ORIGINAL_KEY = "EXPIRED PRIVATE KEY";
|
|
56
57
|
const ORIGINAL_CERT = "EXPIRED PUBLIC KEY";
|
|
57
58
|
fs.writeFileSync(
|
|
58
|
-
resolve(
|
|
59
|
+
path.resolve(getGlobalWranglerConfigPath(), "local-cert/key.pem"),
|
|
59
60
|
ORIGINAL_KEY
|
|
60
61
|
);
|
|
61
62
|
fs.writeFileSync(
|
|
62
|
-
resolve(
|
|
63
|
+
path.resolve(getGlobalWranglerConfigPath(), "local-cert/cert.pem"),
|
|
63
64
|
ORIGINAL_CERT
|
|
64
65
|
);
|
|
65
66
|
mockStatSync(/\.pem$/, { mtimeMs: new Date(2000).valueOf() });
|
|
66
67
|
|
|
67
68
|
const result = await getHttpsOptions();
|
|
68
69
|
const key = fs.readFileSync(
|
|
69
|
-
resolve(
|
|
70
|
+
path.resolve(getGlobalWranglerConfigPath(), "local-cert/key.pem"),
|
|
70
71
|
"utf8"
|
|
71
72
|
);
|
|
72
73
|
const cert = fs.readFileSync(
|
|
73
|
-
resolve(
|
|
74
|
+
path.resolve(getGlobalWranglerConfigPath(), "local-cert/cert.pem"),
|
|
74
75
|
"utf8"
|
|
75
76
|
);
|
|
76
77
|
expect(key).not.toEqual(ORIGINAL_KEY);
|
|
@@ -84,25 +85,57 @@ describe("getHttpsOptions()", () => {
|
|
|
84
85
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
85
86
|
});
|
|
86
87
|
|
|
88
|
+
it("should warn if not able to write to the cache (legacy config path)", async () => {
|
|
89
|
+
fs.mkdirSync(path.join(os.homedir(), ".wrangler"));
|
|
90
|
+
mockWriteFileSyncThrow(/\.pem$/);
|
|
91
|
+
await getHttpsOptions();
|
|
92
|
+
expect(
|
|
93
|
+
fs.existsSync(
|
|
94
|
+
path.resolve(getGlobalWranglerConfigPath(), "local-cert/key.pem")
|
|
95
|
+
)
|
|
96
|
+
).toBe(false);
|
|
97
|
+
expect(
|
|
98
|
+
fs.existsSync(
|
|
99
|
+
path.resolve(getGlobalWranglerConfigPath(), "local-cert/cert.pem")
|
|
100
|
+
)
|
|
101
|
+
).toBe(false);
|
|
102
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
103
|
+
`"Generating new self-signed certificate..."`
|
|
104
|
+
);
|
|
105
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
106
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mUnable to cache generated self-signed certificate in home/.wrangler/local-cert.[0m
|
|
107
|
+
|
|
108
|
+
ERROR: Cannot write file
|
|
109
|
+
|
|
110
|
+
"
|
|
111
|
+
`);
|
|
112
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
113
|
+
fs.rmSync(path.join(os.homedir(), ".wrangler"), { recursive: true });
|
|
114
|
+
});
|
|
115
|
+
|
|
87
116
|
it("should warn if not able to write to the cache", async () => {
|
|
88
117
|
mockWriteFileSyncThrow(/\.pem$/);
|
|
89
118
|
await getHttpsOptions();
|
|
90
119
|
expect(
|
|
91
|
-
fs.existsSync(
|
|
120
|
+
fs.existsSync(
|
|
121
|
+
path.resolve(getGlobalWranglerConfigPath(), "local-cert/key.pem")
|
|
122
|
+
)
|
|
92
123
|
).toBe(false);
|
|
93
124
|
expect(
|
|
94
|
-
fs.existsSync(
|
|
125
|
+
fs.existsSync(
|
|
126
|
+
path.resolve(getGlobalWranglerConfigPath(), "local-cert/cert.pem")
|
|
127
|
+
)
|
|
95
128
|
).toBe(false);
|
|
96
129
|
expect(std.out).toMatchInlineSnapshot(
|
|
97
130
|
`"Generating new self-signed certificate..."`
|
|
98
131
|
);
|
|
99
132
|
expect(std.warn).toMatchInlineSnapshot(`
|
|
100
|
-
|
|
133
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mUnable to cache generated self-signed certificate in test-xdg-config/local-cert.[0m
|
|
101
134
|
|
|
102
|
-
|
|
135
|
+
ERROR: Cannot write file
|
|
103
136
|
|
|
104
|
-
|
|
105
|
-
|
|
137
|
+
"
|
|
138
|
+
`);
|
|
106
139
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
107
140
|
});
|
|
108
141
|
});
|
|
@@ -35,7 +35,7 @@ describe("wrangler", () => {
|
|
|
35
35
|
wrangler dev [script] 👂 Start a local server for developing your worker
|
|
36
36
|
wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
|
|
37
37
|
wrangler tail [name] 🦚 Starts a log tailing session for a published Worker.
|
|
38
|
-
wrangler secret 🤫 Generate a secret that can be referenced in
|
|
38
|
+
wrangler secret 🤫 Generate a secret that can be referenced in a Worker
|
|
39
39
|
wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
|
|
40
40
|
wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
|
|
41
41
|
wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
|
|
@@ -74,7 +74,7 @@ describe("wrangler", () => {
|
|
|
74
74
|
wrangler dev [script] 👂 Start a local server for developing your worker
|
|
75
75
|
wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
|
|
76
76
|
wrangler tail [name] 🦚 Starts a log tailing session for a published Worker.
|
|
77
|
-
wrangler secret 🤫 Generate a secret that can be referenced in
|
|
77
|
+
wrangler secret 🤫 Generate a secret that can be referenced in a Worker
|
|
78
78
|
wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
|
|
79
79
|
wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
|
|
80
80
|
wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
|
|
@@ -123,20 +123,20 @@ describe("wrangler", () => {
|
|
|
123
123
|
await runWrangler("secret");
|
|
124
124
|
await endEventLoop();
|
|
125
125
|
expect(std.out).toMatchInlineSnapshot(`
|
|
126
|
-
|
|
126
|
+
"wrangler secret
|
|
127
127
|
|
|
128
|
-
|
|
128
|
+
🤫 Generate a secret that can be referenced in a Worker
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
Commands:
|
|
131
|
+
wrangler secret put <key> Create or update a secret variable for a Worker
|
|
132
|
+
wrangler secret delete <key> Delete a secret variable from a Worker
|
|
133
|
+
wrangler secret list List all secrets for a Worker
|
|
134
134
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
Flags:
|
|
136
|
+
-c, --config Path to .toml configuration file [string]
|
|
137
|
+
-h, --help Show help [boolean]
|
|
138
|
+
-v, --version Show version number [boolean]"
|
|
139
|
+
`);
|
|
140
140
|
});
|
|
141
141
|
|
|
142
142
|
it("no subcommand 'kv:namespace' should display a list of available subcommands", async () => {
|
|
@@ -105,3 +105,16 @@ jest.mock("../user/generate-random-state", () => {
|
|
|
105
105
|
generateRandomState: jest.fn().mockImplementation(() => "MOCK_STATE_PARAM"),
|
|
106
106
|
};
|
|
107
107
|
});
|
|
108
|
+
|
|
109
|
+
jest.mock("xdg-app-paths", () => {
|
|
110
|
+
return {
|
|
111
|
+
__esModule: true,
|
|
112
|
+
default: jest.fn().mockImplementation(() => {
|
|
113
|
+
return {
|
|
114
|
+
config() {
|
|
115
|
+
return jest.requireActual("node:path").resolve("test-xdg-config");
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}),
|
|
119
|
+
};
|
|
120
|
+
});
|