wrangler 0.0.0-ee6b413 → 0.0.0-ee6c421

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.
Files changed (55) hide show
  1. package/bin/wrangler.js +6 -6
  2. package/miniflare-dist/index.mjs +10 -2
  3. package/package.json +65 -62
  4. package/src/__tests__/config-cache-without-cache-dir.test.ts +38 -0
  5. package/src/__tests__/config-cache.test.ts +6 -0
  6. package/src/__tests__/configuration.test.ts +923 -764
  7. package/src/__tests__/dev.test.tsx +208 -186
  8. package/src/__tests__/helpers/run-in-tmp.ts +11 -4
  9. package/src/__tests__/https-options.test.ts +1 -1
  10. package/src/__tests__/index.test.ts +120 -118
  11. package/src/__tests__/kv.test.ts +33 -2
  12. package/src/__tests__/publish.test.ts +1552 -1453
  13. package/src/__tests__/pubsub.test.ts +100 -9
  14. package/src/__tests__/secret.test.ts +84 -78
  15. package/src/__tests__/tail.test.ts +8 -0
  16. package/src/__tests__/user.test.ts +2 -5
  17. package/src/__tests__/whoami.test.tsx +32 -2
  18. package/src/__tests__/worker-namespace.test.ts +327 -0
  19. package/src/api/dev.ts +52 -0
  20. package/src/api/index.ts +1 -0
  21. package/src/cli.ts +21 -7
  22. package/src/config/environment.ts +23 -0
  23. package/src/config/index.ts +13 -0
  24. package/src/config/validation.ts +88 -15
  25. package/src/config-cache.ts +70 -31
  26. package/src/create-worker-preview.ts +96 -26
  27. package/src/create-worker-upload-form.ts +9 -0
  28. package/src/dev/dev.tsx +16 -2
  29. package/src/dev/local.tsx +40 -21
  30. package/src/dev/remote.tsx +116 -16
  31. package/src/dev/use-esbuild.ts +55 -22
  32. package/src/dev.tsx +228 -160
  33. package/src/entry.ts +1 -1
  34. package/src/{__tests__/helpers/faye-websocket.d.ts → faye-websocket.d.ts} +0 -0
  35. package/src/https-options.ts +7 -4
  36. package/src/index.tsx +193 -141
  37. package/src/is-interactive.ts +12 -0
  38. package/src/kv.ts +23 -1
  39. package/src/miniflare-cli/index.ts +13 -1
  40. package/src/package-manager.ts +45 -0
  41. package/src/pages/upload.tsx +24 -12
  42. package/src/preview.ts +31 -0
  43. package/src/publish.ts +69 -31
  44. package/src/pubsub/pubsub-commands.tsx +464 -491
  45. package/src/sites.tsx +5 -5
  46. package/src/user/choose-account.tsx +2 -2
  47. package/src/user/user.tsx +74 -40
  48. package/src/whoami.tsx +21 -7
  49. package/src/worker-namespace.ts +190 -0
  50. package/src/worker.ts +10 -2
  51. package/templates/static-asset-facade.js +11 -5
  52. package/templates/tsconfig.json +2 -2
  53. package/wrangler-dist/cli.d.ts +298 -0
  54. package/wrangler-dist/cli.js +119230 -118815
  55. package/src/preview.tsx +0 -150
package/bin/wrangler.js CHANGED
@@ -6,6 +6,10 @@ const os = require("os");
6
6
  const semiver = require("semiver");
7
7
 
8
8
  const MIN_NODE_VERSION = "16.7.0";
9
+ const debug =
10
+ process.env["WRANGLER_LOG"] === "debug"
11
+ ? (...args) => console.log(...args)
12
+ : () => {};
9
13
 
10
14
  let wranglerProcess;
11
15
 
@@ -52,9 +56,6 @@ Consider using a Node.js version manager such as https://volta.sh/ or https://gi
52
56
  return spawn(
53
57
  process.execPath,
54
58
  [
55
- ...(semiver(process.versions.node, "18.0.0") >= 0
56
- ? ["--no-experimental-fetch"] // TODO: remove this when https://github.com/cloudflare/wrangler2/issues/834 is properly fixed
57
- : []),
58
59
  "--no-warnings",
59
60
  "--experimental-vm-modules",
60
61
  ...process.execArgv,
@@ -87,9 +88,8 @@ function runDelegatedWrangler() {
87
88
  } = JSON.parse(fs.readFileSync(packageJsonPath));
88
89
  const resolvedBinaryPath = path.resolve(packageJsonPath, "..", binaryPath);
89
90
 
90
- console.log(
91
- `Delegating to locally-installed version of wrangler @ v${version}`
92
- );
91
+ debug(`Delegating to locally-installed version of wrangler @ v${version}`);
92
+
93
93
  // this call to `spawn` is simpler because the delegated version will do all
94
94
  // of the other work.
95
95
  return spawn(
@@ -4846,6 +4846,13 @@ var getRequestContextCheckOptions = async () => {
4846
4846
  };
4847
4847
 
4848
4848
  // src/miniflare-cli/index.ts
4849
+ var NoOpLog = class extends Log {
4850
+ log() {
4851
+ }
4852
+ error(message) {
4853
+ throw message;
4854
+ }
4855
+ };
4849
4856
  async function main() {
4850
4857
  const args = await yargs_default(hideBin(process.argv)).help(false).version(false).option("log", {
4851
4858
  choices: enumKeys(LogLevel)
@@ -4854,9 +4861,9 @@ async function main() {
4854
4861
  const requestContextCheckOptions = await getRequestContextCheckOptions();
4855
4862
  const config = {
4856
4863
  ...JSON.parse(args._[0] ?? "{}"),
4857
- ...requestContextCheckOptions,
4858
- log: new Log(logLevel)
4864
+ ...requestContextCheckOptions
4859
4865
  };
4866
+ config.log = config.disableLogs ? new NoOpLog() : new Log(logLevel);
4860
4867
  if (logLevel > LogLevel.INFO) {
4861
4868
  console.log("OPTIONS:\n", JSON.stringify(config, null, 2));
4862
4869
  }
@@ -4864,6 +4871,7 @@ async function main() {
4864
4871
  try {
4865
4872
  await mf.startServer();
4866
4873
  await mf.startScheduler();
4874
+ process.send && process.send("ready");
4867
4875
  } catch (e) {
4868
4876
  mf.log.error(e);
4869
4877
  process.exitCode = 1;
package/package.json CHANGED
@@ -1,17 +1,7 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "0.0.0-ee6b413",
4
- "author": "wrangler@cloudflare.com",
3
+ "version": "0.0.0-ee6c421",
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
- "license": "MIT OR Apache-2.0",
11
- "bugs": {
12
- "url": "https://github.com/cloudflare/wrangler2/issues"
13
- },
14
- "homepage": "https://github.com/cloudflare/wrangler2#readme",
15
5
  "keywords": [
16
6
  "wrangler",
17
7
  "cloudflare",
@@ -28,31 +18,87 @@
28
18
  "webassembly",
29
19
  "rust",
30
20
  "emscripten",
31
- "rust",
32
21
  "typescript",
33
22
  "graphql",
34
23
  "router",
35
24
  "http",
36
25
  "cli"
37
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
+ "moduleNameMapper": {
65
+ "clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js",
66
+ "miniflare/cli": "<rootDir>/../../node_modules/miniflare/dist/src/cli.js"
67
+ },
68
+ "restoreMocks": true,
69
+ "setupFilesAfterEnv": [
70
+ "<rootDir>/src/__tests__/jest.setup.ts"
71
+ ],
72
+ "testRegex": ".*.(test|spec)\\.[jt]sx?$",
73
+ "testTimeout": 30000,
74
+ "transform": {
75
+ "^.+\\.c?(t|j)sx?$": [
76
+ "esbuild-jest",
77
+ {
78
+ "sourcemap": true
79
+ }
80
+ ]
81
+ },
82
+ "transformIgnorePatterns": [
83
+ "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)"
84
+ ]
85
+ },
38
86
  "dependencies": {
39
87
  "@cloudflare/kv-asset-handler": "^0.2.0",
40
88
  "@esbuild-plugins/node-globals-polyfill": "^0.1.1",
41
89
  "@esbuild-plugins/node-modules-polyfill": "^0.1.4",
42
90
  "blake3-wasm": "^2.1.5",
43
- "esbuild": "0.14.34",
44
- "miniflare": "^2.5.1",
91
+ "esbuild": "0.14.47",
92
+ "miniflare": "^2.6.0",
45
93
  "nanoid": "^3.3.3",
46
94
  "path-to-regexp": "^6.2.0",
47
95
  "selfsigned": "^2.0.1",
48
96
  "semiver": "^1.1.0",
49
97
  "xxhash-wasm": "^1.0.1"
50
98
  },
51
- "optionalDependencies": {
52
- "fsevents": "~2.3.2"
53
- },
54
99
  "devDependencies": {
55
100
  "@iarna/toml": "^3.0.0",
101
+ "@microsoft/api-extractor": "^7.28.3",
56
102
  "@types/command-exists": "^1.2.0",
57
103
  "@types/glob-to-regexp": "0.4.1",
58
104
  "@types/mime": "^2.0.3",
@@ -105,53 +151,10 @@
105
151
  "ws": "^8.5.0",
106
152
  "yargs": "^17.4.1"
107
153
  },
108
- "files": [
109
- "src",
110
- "bin",
111
- "miniflare-config-stubs",
112
- "miniflare-dist",
113
- "wrangler-dist",
114
- "templates",
115
- "vendor",
116
- "import_meta_url.js",
117
- "kv-asset-handler.js",
118
- "Cloudflare_CA.pem"
119
- ],
120
- "scripts": {
121
- "clean": "rm -rf wrangler-dist miniflare-dist",
122
- "check:type": "tsc",
123
- "bundle": "node -r esbuild-register scripts/bundle.ts",
124
- "build": "npm run clean && npm run bundle",
125
- "dev": "npm run clean && concurrently -c black,blue 'npm run bundle -- --watch' 'npm run check:type -- --watch --preserveWatchOutput'",
126
- "prepublishOnly": "SOURCEMAPS=false npm run build",
127
- "start": "npm run bundle && NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
128
- "test": "jest --silent=false --verbose=true",
129
- "test-watch": "npm run test -- --runInBand --testTimeout=50000 --watch"
154
+ "optionalDependencies": {
155
+ "fsevents": "~2.3.2"
130
156
  },
131
157
  "engines": {
132
158
  "node": ">=16.7.0"
133
- },
134
- "jest": {
135
- "restoreMocks": true,
136
- "testTimeout": 30000,
137
- "testRegex": ".*.(test|spec)\\.[jt]sx?$",
138
- "transformIgnorePatterns": [
139
- "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)"
140
- ],
141
- "moduleNameMapper": {
142
- "clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js",
143
- "miniflare/cli": "<rootDir>/../../node_modules/miniflare/dist/src/cli.js"
144
- },
145
- "transform": {
146
- "^.+\\.c?(t|j)sx?$": [
147
- "esbuild-jest",
148
- {
149
- "sourcemap": true
150
- }
151
- ]
152
- },
153
- "setupFilesAfterEnv": [
154
- "<rootDir>/src/__tests__/jest.setup.ts"
155
- ]
156
159
  }
157
160
  }
@@ -0,0 +1,38 @@
1
+ import { getConfigCache, saveToConfigCache } from "../config-cache";
2
+ import { mockConsoleMethods } from "./helpers/mock-console";
3
+ import { runInTempDir } from "./helpers/run-in-tmp";
4
+
5
+ interface PagesConfigCache {
6
+ account_id: string;
7
+ pages_project_name: string;
8
+ }
9
+
10
+ describe("config cache", () => {
11
+ runInTempDir();
12
+ mockConsoleMethods();
13
+ // In this set of tests, we don't create a node_modules folder
14
+ const pagesConfigCacheFilename = "pages-config-cache.json";
15
+
16
+ it("should return an empty config if no file exists", () => {
17
+ expect(
18
+ getConfigCache<PagesConfigCache>(pagesConfigCacheFilename)
19
+ ).toMatchInlineSnapshot(`Object {}`);
20
+ });
21
+
22
+ it("should ignore attempts to cache values ", () => {
23
+ saveToConfigCache<PagesConfigCache>(pagesConfigCacheFilename, {
24
+ account_id: "some-account-id",
25
+ pages_project_name: "foo",
26
+ });
27
+ expect(getConfigCache<PagesConfigCache>(pagesConfigCacheFilename)).toEqual(
28
+ {}
29
+ );
30
+
31
+ saveToConfigCache<PagesConfigCache>(pagesConfigCacheFilename, {
32
+ pages_project_name: "bar",
33
+ });
34
+ expect(getConfigCache<PagesConfigCache>(pagesConfigCacheFilename)).toEqual(
35
+ {}
36
+ );
37
+ });
38
+ });
@@ -1,4 +1,6 @@
1
+ import { mkdirSync } from "node:fs";
1
2
  import { getConfigCache, saveToConfigCache } from "../config-cache";
3
+ import { mockConsoleMethods } from "./helpers/mock-console";
2
4
  import { runInTempDir } from "./helpers/run-in-tmp";
3
5
 
4
6
  interface PagesConfigCache {
@@ -8,6 +10,10 @@ interface PagesConfigCache {
8
10
 
9
11
  describe("config cache", () => {
10
12
  runInTempDir();
13
+ mockConsoleMethods();
14
+ beforeEach(() => {
15
+ mkdirSync("node_modules");
16
+ });
11
17
 
12
18
  const pagesConfigCacheFilename = "pages-config-cache.json";
13
19