wrangler 0.0.0-bc28bea → 0.0.0-bcd066d

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 (118) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +1 -1
  3. package/bin/wrangler.js +97 -8
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +13 -6
  6. package/src/__tests__/configuration.test.ts +652 -229
  7. package/src/__tests__/dev.test.tsx +372 -79
  8. package/src/__tests__/helpers/mock-cfetch.ts +2 -2
  9. package/src/__tests__/helpers/mock-console.ts +11 -1
  10. package/src/__tests__/helpers/mock-dialogs.ts +74 -11
  11. package/src/__tests__/helpers/mock-process.ts +24 -0
  12. package/src/__tests__/index.test.ts +81 -72
  13. package/src/__tests__/init.test.ts +991 -515
  14. package/src/__tests__/jest.setup.ts +38 -0
  15. package/src/__tests__/kv.test.ts +259 -149
  16. package/src/__tests__/logger.test.ts +26 -0
  17. package/src/__tests__/package-manager.test.ts +154 -7
  18. package/src/__tests__/pages.test.ts +969 -56
  19. package/src/__tests__/parse.test.ts +5 -1
  20. package/src/__tests__/publish.test.ts +1665 -342
  21. package/src/__tests__/r2.test.ts +55 -36
  22. package/src/__tests__/secret.test.ts +39 -4
  23. package/src/__tests__/user.test.ts +1 -0
  24. package/src/__tests__/whoami.test.tsx +34 -0
  25. package/src/abort.d.ts +3 -0
  26. package/src/bundle-reporter.tsx +29 -0
  27. package/src/bundle.ts +42 -7
  28. package/src/cfetch/index.ts +21 -4
  29. package/src/cfetch/internal.ts +25 -20
  30. package/src/config/config.ts +11 -2
  31. package/src/config/environment.ts +41 -15
  32. package/src/config/index.ts +162 -0
  33. package/src/config/validation-helpers.ts +10 -1
  34. package/src/config/validation.ts +234 -78
  35. package/src/create-worker-preview.ts +32 -22
  36. package/src/create-worker-upload-form.ts +22 -8
  37. package/src/dev/dev.tsx +48 -67
  38. package/src/dev/local.tsx +16 -7
  39. package/src/dev/remote.tsx +57 -21
  40. package/src/dev/use-esbuild.ts +1 -7
  41. package/src/dialogs.tsx +48 -0
  42. package/src/durable.ts +102 -0
  43. package/src/entry.ts +71 -10
  44. package/src/generate-auth-url.ts +33 -0
  45. package/src/generate-random-state.ts +16 -0
  46. package/src/git-client.ts +42 -0
  47. package/src/index.tsx +585 -345
  48. package/src/inspect.ts +39 -0
  49. package/src/kv.ts +116 -27
  50. package/src/logger.ts +8 -1
  51. package/src/open-in-browser.ts +3 -12
  52. package/src/package-manager.ts +50 -3
  53. package/src/pages/build.tsx +202 -0
  54. package/src/pages/constants.ts +7 -0
  55. package/src/pages/deployments.tsx +101 -0
  56. package/src/pages/dev.tsx +948 -0
  57. package/{pages → src/pages}/functions/buildPlugin.ts +14 -1
  58. package/{pages → src/pages}/functions/buildWorker.ts +15 -2
  59. package/{pages → src/pages}/functions/filepath-routing.test.ts +3 -3
  60. package/{pages → src/pages}/functions/filepath-routing.ts +2 -2
  61. package/{pages → src/pages}/functions/identifiers.ts +0 -0
  62. package/{pages → src/pages}/functions/routes.ts +1 -6
  63. package/src/pages/index.tsx +84 -0
  64. package/src/pages/projects.tsx +157 -0
  65. package/src/pages/publish.tsx +325 -0
  66. package/src/pages/types.ts +40 -0
  67. package/src/pages/upload.tsx +363 -0
  68. package/src/pages/utils.ts +12 -0
  69. package/src/parse.ts +42 -5
  70. package/src/proxy.ts +62 -35
  71. package/src/publish.ts +407 -137
  72. package/src/sites.tsx +110 -31
  73. package/src/user.tsx +35 -26
  74. package/src/whoami.tsx +3 -2
  75. package/src/worker.ts +10 -1
  76. package/src/zones.ts +73 -0
  77. package/templates/new-worker-scheduled.js +17 -0
  78. package/templates/new-worker-scheduled.ts +32 -0
  79. package/templates/new-worker.ts +16 -1
  80. package/templates/no-op-worker.js +10 -0
  81. package/{pages/functions/template-plugin.ts → templates/pages-template-plugin.ts} +12 -3
  82. package/{pages/functions/template-worker.ts → templates/pages-template-worker.ts} +26 -8
  83. package/templates/static-asset-facade.js +2 -6
  84. package/wrangler-dist/cli.js +109786 -95971
  85. package/src/pages.tsx +0 -1875
  86. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  87. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  88. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  89. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  90. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  91. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  92. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  93. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  94. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  95. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  96. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  97. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  98. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  99. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  100. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  101. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  102. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  103. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  104. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  105. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  106. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  107. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  108. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  109. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  110. package/vendor/wrangler-mime/LICENSE +0 -21
  111. package/vendor/wrangler-mime/Mime.js +0 -97
  112. package/vendor/wrangler-mime/README.md +0 -187
  113. package/vendor/wrangler-mime/cli.js +0 -46
  114. package/vendor/wrangler-mime/index.js +0 -4
  115. package/vendor/wrangler-mime/lite.js +0 -4
  116. package/vendor/wrangler-mime/package.json +0 -52
  117. package/vendor/wrangler-mime/types/other.js +0 -1
  118. package/vendor/wrangler-mime/types/standard.js +0 -1
@@ -0,0 +1,18 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIC6zCCAkygAwIBAgIUI7b68p0pPrCBoW4ptlyvVcPItscwCgYIKoZIzj0EAwQw
3
+ gY0xCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T
4
+ YW4gRnJhbmNpc2NvMRgwFgYDVQQKEw9DbG91ZGZsYXJlLCBJbmMxNzA1BgNVBAMT
5
+ LkNsb3VkZmxhcmUgZm9yIFRlYW1zIEVDQyBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkw
6
+ HhcNMjAwMjA0MTYwNTAwWhcNMjUwMjAyMTYwNTAwWjCBjTELMAkGA1UEBhMCVVMx
7
+ EzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28xGDAW
8
+ BgNVBAoTD0Nsb3VkZmxhcmUsIEluYzE3MDUGA1UEAxMuQ2xvdWRmbGFyZSBmb3Ig
9
+ VGVhbXMgRUNDIENlcnRpZmljYXRlIEF1dGhvcml0eTCBmzAQBgcqhkjOPQIBBgUr
10
+ gQQAIwOBhgAEAVdXsX8tpA9NAQeEQalvUIcVaFNDvGsR69ysZxOraRWNGHLfq1mi
11
+ P6o3wtmtx/C2OXG01Cw7UFJbKl5MEDxnT2KoAdFSynSJOF2NDoe5LoZHbUW+yR3X
12
+ FDl+MF6JzZ590VLGo6dPBf06UsXbH7PvHH2XKtFt8bBXVNMa5a21RdmpD0Pho0Uw
13
+ QzAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBAjAdBgNVHQ4EFgQU
14
+ YBcQng1AEMMNteuRDAMG0/vgFe0wCgYIKoZIzj0EAwQDgYwAMIGIAkIBQU5OTA2h
15
+ YqmFk8paan5ezHVLcmcucsfYw4L/wmeEjCkczRmCVNm6L86LjhWU0v0wER0e+lHO
16
+ 3efvjbsu8gIGSagCQgEBnyYMP9gwg8l96QnQ1khFA1ljFlnqc2XgJHDSaAJC0gdz
17
+ +NV3JMeWaD2Rb32jc9r6/a7xY0u0ByqxBQ1OQ0dt7A==
18
+ -----END CERTIFICATE-----
package/README.md CHANGED
@@ -24,7 +24,7 @@ npx wrangler init my-worker
24
24
  # try it out
25
25
  cd my-worker && npm run start
26
26
  # and then publish it
27
- npm run publish
27
+ npm run deploy
28
28
  ```
29
29
 
30
30
  ## Installation:
package/bin/wrangler.js CHANGED
@@ -1,13 +1,18 @@
1
1
  #!/usr/bin/env node
2
- const { spawn } = require("node:child_process");
3
- const { join } = require("node:path");
2
+ const { spawn } = require("child_process");
3
+ const path = require("path");
4
+ const fs = require("fs");
5
+ const os = require("os");
4
6
  const semiver = require("semiver");
5
7
 
6
8
  const MIN_NODE_VERSION = "16.7.0";
7
9
 
8
10
  let wranglerProcess;
9
11
 
10
- async function main() {
12
+ /**
13
+ * Executes ../wrangler-dist/cli.js
14
+ */
15
+ function runWrangler() {
11
16
  if (semiver(process.versions.node, MIN_NODE_VERSION) < 0) {
12
17
  // Note Volta and nvm are also recommended in the official docs:
13
18
  // https://developers.cloudflare.com/workers/get-started/guide#2-install-the-workers-cli
@@ -20,7 +25,31 @@ Consider using a Node.js version manager such as https://volta.sh/ or https://gi
20
25
  return;
21
26
  }
22
27
 
23
- wranglerProcess = spawn(
28
+ let pathToCACerts = process.env.NODE_EXTRA_CA_CERTS;
29
+ if (pathToCACerts) {
30
+ // TODO:
31
+ // - should we log a warning here?
32
+ // - maybe we can generate a certificate that concatenates with ours?
33
+ //
34
+ // I do think it'll be rare that someone wants to add a cert AND
35
+ // use cloudflare WARP, but let's wait till the situation actually
36
+ // arises before we do anything about it
37
+ } else {
38
+ const osTempDir = os.tmpdir();
39
+ const certDir = path.join(osTempDir, "wrangler-cert");
40
+ const certPath = path.join(certDir, "Cloudflare_CA.pem");
41
+ // copy cert to the system temp dir if needed
42
+ if (!fs.existsSync(certPath)) {
43
+ fs.mkdirSync(certDir, { recursive: true });
44
+ fs.writeFileSync(
45
+ certPath,
46
+ fs.readFileSync(path.join(__dirname, "../Cloudflare_CA.pem"), "utf-8")
47
+ );
48
+ }
49
+ pathToCACerts = certPath;
50
+ }
51
+
52
+ return spawn(
24
53
  process.execPath,
25
54
  [
26
55
  ...(semiver(process.versions.node, "18.0.0") >= 0
@@ -29,20 +58,80 @@ Consider using a Node.js version manager such as https://volta.sh/ or https://gi
29
58
  "--no-warnings",
30
59
  "--experimental-vm-modules",
31
60
  ...process.execArgv,
32
- join(__dirname, "../wrangler-dist/cli.js"),
61
+ path.join(__dirname, "../wrangler-dist/cli.js"),
33
62
  ...process.argv.slice(2),
34
63
  ],
35
- { stdio: "inherit" }
64
+ {
65
+ stdio: "inherit",
66
+ env: {
67
+ ...process.env,
68
+ NODE_EXTRA_CA_CERTS: pathToCACerts,
69
+ },
70
+ }
36
71
  ).on("exit", (code) =>
37
72
  process.exit(code === undefined || code === null ? 0 : code)
38
73
  );
39
74
  }
40
75
 
76
+ /**
77
+ * Runs a locally-installed version of wrangler, delegating from this version.
78
+ * @throws {MODULE_NOT_FOUND} if there isn't a locally installed version of wrangler.
79
+ */
80
+ function runDelegatedWrangler() {
81
+ const packageJsonPath = require.resolve("wrangler/package.json", {
82
+ paths: [process.cwd()],
83
+ });
84
+ const {
85
+ bin: { wrangler: binaryPath },
86
+ version,
87
+ } = JSON.parse(fs.readFileSync(packageJsonPath));
88
+ const resolvedBinaryPath = path.resolve(packageJsonPath, "..", binaryPath);
89
+
90
+ console.log(
91
+ `Delegating to locally-installed version of wrangler @ v${version}`
92
+ );
93
+ // this call to `spawn` is simpler because the delegated version will do all
94
+ // of the other work.
95
+ return spawn(
96
+ process.execPath,
97
+ [resolvedBinaryPath, ...process.argv.slice(2)],
98
+ {
99
+ stdio: "inherit",
100
+ }
101
+ ).on("exit", (code) =>
102
+ process.exit(code === undefined || code === null ? 0 : code)
103
+ );
104
+ }
105
+
106
+ /**
107
+ * Indicates if this invocation of `wrangler` should delegate
108
+ * to a locally-installed version.
109
+ */
110
+ function shouldDelegate() {
111
+ try {
112
+ // `require.resolve` will throw if it can't find
113
+ // a locally-installed version of `wrangler`
114
+ const delegatedPackageJson = require.resolve("wrangler/package.json", {
115
+ paths: [process.cwd()],
116
+ });
117
+ const thisPackageJson = path.resolve(__dirname, "..", "package.json");
118
+ // if it's the same path, then we're already a local install -- no need to delegate
119
+ return thisPackageJson !== delegatedPackageJson;
120
+ } catch (e) {
121
+ // there's no local version to delegate to -- `require.resolve` threw
122
+ return false;
123
+ }
124
+ }
125
+
126
+ async function main() {
127
+ wranglerProcess = shouldDelegate() ? runDelegatedWrangler() : runWrangler();
128
+ }
129
+
41
130
  process.on("SIGINT", () => {
42
- wranglerProcess.kill();
131
+ wranglerProcess?.kill();
43
132
  });
44
133
  process.on("SIGTERM", () => {
45
- wranglerProcess.kill();
134
+ wranglerProcess?.kill();
46
135
  });
47
136
 
48
137
  void main();
@@ -0,0 +1 @@
1
+ export * from "@cloudflare/kv-asset-handler";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "0.0.0-bc28bea",
3
+ "version": "0.0.0-bcd066d",
4
4
  "author": "wrangler@cloudflare.com",
5
5
  "description": "Command-line interface for all things Cloudflare Workers",
6
6
  "bin": {
@@ -36,11 +36,12 @@
36
36
  "cli"
37
37
  ],
38
38
  "dependencies": {
39
+ "@cloudflare/kv-asset-handler": "^0.2.0",
39
40
  "@esbuild-plugins/node-globals-polyfill": "^0.1.1",
40
41
  "@esbuild-plugins/node-modules-polyfill": "^0.1.4",
41
42
  "blake3-wasm": "^2.1.5",
42
43
  "esbuild": "0.14.34",
43
- "miniflare": "2.4.0",
44
+ "miniflare": "^2.5.1",
44
45
  "nanoid": "^3.3.3",
45
46
  "path-to-regexp": "^6.2.0",
46
47
  "selfsigned": "^2.0.1",
@@ -62,10 +63,12 @@
62
63
  "@types/supports-color": "^8.1.1",
63
64
  "@types/ws": "^8.5.3",
64
65
  "@types/yargs": "^17.0.10",
66
+ "@webcontainer/env": "^1.0.1",
65
67
  "chokidar": "^3.5.3",
66
68
  "clipboardy": "^3.0.0",
67
69
  "cmd-shim": "^4.1.0",
68
70
  "command-exists": "^1.2.9",
71
+ "concurrently": "^7.2.2",
69
72
  "devtools-protocol": "^0.0.955664",
70
73
  "dotenv": "^16.0.0",
71
74
  "execa": "^6.1.0",
@@ -74,6 +77,7 @@
74
77
  "find-up": "^6.3.0",
75
78
  "get-port": "^6.1.2",
76
79
  "glob-to-regexp": "0.4.1",
80
+ "http-terminator": "^3.2.0",
77
81
  "ignore": "^5.2.0",
78
82
  "ink": "^3.2.0",
79
83
  "ink-select-input": "^4.2.1",
@@ -85,6 +89,7 @@
85
89
  "jest-websocket-mock": "^2.3.0",
86
90
  "mime": "^3.0.0",
87
91
  "open": "^8.4.0",
92
+ "p-queue": "^7.2.0",
88
93
  "pretty-bytes": "^6.0.0",
89
94
  "prompts": "^2.4.2",
90
95
  "react": "^17.0.2",
@@ -95,7 +100,7 @@
95
100
  "timeago.js": "^4.0.2",
96
101
  "tmp-promise": "^3.0.3",
97
102
  "ts-dedent": "^2.2.0",
98
- "undici": "^4.15.1",
103
+ "undici": "^5.5.1",
99
104
  "update-check": "^1.5.4",
100
105
  "ws": "^8.5.0",
101
106
  "yargs": "^17.4.1"
@@ -103,19 +108,21 @@
103
108
  "files": [
104
109
  "src",
105
110
  "bin",
106
- "pages",
107
111
  "miniflare-config-stubs",
108
112
  "miniflare-dist",
109
113
  "wrangler-dist",
110
114
  "templates",
111
115
  "vendor",
112
- "import_meta_url.js"
116
+ "import_meta_url.js",
117
+ "kv-asset-handler.js",
118
+ "Cloudflare_CA.pem"
113
119
  ],
114
120
  "scripts": {
115
121
  "clean": "rm -rf wrangler-dist miniflare-dist",
116
122
  "check:type": "tsc",
117
123
  "bundle": "node -r esbuild-register scripts/bundle.ts",
118
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'",
119
126
  "prepublishOnly": "SOURCEMAPS=false npm run build",
120
127
  "start": "npm run bundle && NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
121
128
  "test": "jest --silent=false --verbose=true",
@@ -129,7 +136,7 @@
129
136
  "testTimeout": 30000,
130
137
  "testRegex": ".*.(test|spec)\\.[jt]sx?$",
131
138
  "transformIgnorePatterns": [
132
- "node_modules/(?!find-up|locate-path|p-locate|p-limit|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)"
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)"
133
140
  ],
134
141
  "moduleNameMapper": {
135
142
  "clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js",