wrangler 0.0.0-e2a26a0 → 0.0.0-e2a6fa40

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 (128) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +47 -16
  3. package/bin/wrangler.js +118 -32
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +147 -78
  6. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  7. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  8. package/templates/__tests__/tsconfig.json +8 -0
  9. package/templates/checked-fetch.js +30 -0
  10. package/templates/facade.d.ts +17 -0
  11. package/templates/gitignore +172 -0
  12. package/templates/init-tests/test-jest-new-worker.js +23 -0
  13. package/templates/init-tests/test-vitest-new-worker.js +24 -0
  14. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  15. package/templates/middleware/common.ts +67 -0
  16. package/templates/middleware/loader-modules.ts +137 -0
  17. package/templates/middleware/loader-sw.ts +228 -0
  18. package/templates/middleware/middleware-d1-beta.d.ts +3 -0
  19. package/templates/middleware/middleware-miniflare3-json-error.ts +33 -0
  20. package/templates/middleware/middleware-multiworker-dev.d.ts +4 -0
  21. package/templates/middleware/middleware-multiworker-dev.ts +59 -0
  22. package/templates/middleware/middleware-pretty-error.ts +40 -0
  23. package/templates/middleware/middleware-scheduled.ts +15 -0
  24. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  25. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  26. package/templates/new-worker-scheduled.js +17 -0
  27. package/templates/new-worker-scheduled.ts +32 -0
  28. package/templates/new-worker.js +4 -4
  29. package/templates/new-worker.ts +22 -4
  30. package/templates/no-op-worker.js +10 -0
  31. package/templates/pages-dev-pipeline.ts +31 -0
  32. package/templates/pages-dev-util.ts +55 -0
  33. package/templates/pages-shim.ts +9 -0
  34. package/templates/pages-template-plugin.ts +190 -0
  35. package/templates/pages-template-worker.ts +198 -0
  36. package/templates/tsconfig-sanity.ts +11 -0
  37. package/templates/tsconfig.init.json +105 -0
  38. package/templates/tsconfig.json +8 -0
  39. package/wrangler-dist/cli.d.ts +1734 -0
  40. package/wrangler-dist/cli.js +139455 -113761
  41. package/wrangler-dist/wasm-sync.wasm +0 -0
  42. package/import_meta_url.js +0 -3
  43. package/miniflare-config-stubs/.env.empty +0 -0
  44. package/miniflare-config-stubs/package.empty.json +0 -1
  45. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  46. package/pages/functions/buildWorker.ts +0 -62
  47. package/pages/functions/filepath-routing.test.ts +0 -47
  48. package/pages/functions/filepath-routing.ts +0 -231
  49. package/pages/functions/identifiers.ts +0 -78
  50. package/pages/functions/routes.ts +0 -160
  51. package/pages/functions/template-worker.ts +0 -136
  52. package/src/__tests__/dev.test.tsx +0 -71
  53. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  54. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  55. package/src/__tests__/helpers/mock-account-id.ts +0 -30
  56. package/src/__tests__/helpers/mock-bin.ts +0 -33
  57. package/src/__tests__/helpers/mock-cfetch.ts +0 -207
  58. package/src/__tests__/helpers/mock-console.ts +0 -56
  59. package/src/__tests__/helpers/mock-dialogs.ts +0 -65
  60. package/src/__tests__/helpers/mock-kv.ts +0 -40
  61. package/src/__tests__/helpers/mock-user.ts +0 -27
  62. package/src/__tests__/helpers/run-in-tmp.ts +0 -29
  63. package/src/__tests__/helpers/run-wrangler.ts +0 -14
  64. package/src/__tests__/index.test.ts +0 -543
  65. package/src/__tests__/jest.setup.ts +0 -37
  66. package/src/__tests__/kv.test.ts +0 -1139
  67. package/src/__tests__/logout.test.ts +0 -50
  68. package/src/__tests__/package-manager.test.ts +0 -206
  69. package/src/__tests__/publish.test.ts +0 -1222
  70. package/src/__tests__/secret.test.ts +0 -210
  71. package/src/__tests__/whoami.test.tsx +0 -86
  72. package/src/api/form_data.ts +0 -134
  73. package/src/api/preview.ts +0 -128
  74. package/src/api/worker.ts +0 -155
  75. package/src/cfetch/index.ts +0 -102
  76. package/src/cfetch/internal.ts +0 -101
  77. package/src/cli.ts +0 -9
  78. package/src/config.ts +0 -641
  79. package/src/dev.tsx +0 -834
  80. package/src/dialogs.tsx +0 -77
  81. package/src/index.tsx +0 -2101
  82. package/src/inspect.ts +0 -596
  83. package/src/kv.tsx +0 -284
  84. package/src/module-collection.ts +0 -63
  85. package/src/package-manager.ts +0 -120
  86. package/src/pages.tsx +0 -1046
  87. package/src/paths.ts +0 -26
  88. package/src/proxy.ts +0 -370
  89. package/src/publish.ts +0 -410
  90. package/src/sites.tsx +0 -240
  91. package/src/tail.tsx +0 -73
  92. package/src/user.tsx +0 -1019
  93. package/src/whoami.tsx +0 -69
  94. package/templates/static-asset-facade.js +0 -47
  95. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  96. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  97. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  98. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  99. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  100. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  101. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  102. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  103. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  104. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  105. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  106. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  107. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  108. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  109. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  110. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  111. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  112. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  113. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  114. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  115. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  116. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  117. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  118. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  119. package/vendor/wrangler-mime/LICENSE +0 -21
  120. package/vendor/wrangler-mime/Mime.js +0 -97
  121. package/vendor/wrangler-mime/README.md +0 -187
  122. package/vendor/wrangler-mime/cli.js +0 -46
  123. package/vendor/wrangler-mime/index.js +0 -4
  124. package/vendor/wrangler-mime/lite.js +0 -4
  125. package/vendor/wrangler-mime/package.json +0 -52
  126. package/vendor/wrangler-mime/types/other.js +0 -1
  127. package/vendor/wrangler-mime/types/standard.js +0 -1
  128. package/wrangler-dist/cli.js.map +0 -7
package/src/kv.tsx DELETED
@@ -1,284 +0,0 @@
1
- import { URLSearchParams } from "node:url";
2
- import { fetchListResult, fetchResult, fetchKVGetValue } from "./cfetch";
3
- import type { Config } from "./config";
4
-
5
- type KvArgs = {
6
- binding?: string;
7
- "namespace-id"?: string;
8
- env?: string;
9
- preview?: boolean;
10
- config?: Config;
11
- };
12
-
13
- /**
14
- * Create a new namespace under the given `accountId` with the given `title`.
15
- *
16
- * @returns the generated id of the created namespace.
17
- */
18
- export async function createNamespace(
19
- accountId: string,
20
- title: string
21
- ): Promise<string> {
22
- const response = await fetchResult<{ id: string }>(
23
- `/accounts/${accountId}/storage/kv/namespaces`,
24
- {
25
- method: "POST",
26
- headers: {
27
- "Content-Type": "application/json",
28
- },
29
- body: JSON.stringify({
30
- title,
31
- }),
32
- }
33
- );
34
-
35
- return response.id;
36
- }
37
-
38
- /**
39
- * The information about a namespace that is returned from `listNamespaces()`.
40
- */
41
- export interface KVNamespaceInfo {
42
- id: string;
43
- title: string;
44
- supports_url_encoding?: boolean;
45
- }
46
-
47
- /**
48
- * Fetch a list of all the namespaces under the given `accountId`.
49
- */
50
- export async function listNamespaces(
51
- accountId: string
52
- ): Promise<KVNamespaceInfo[]> {
53
- const pageSize = 100;
54
- let page = 1;
55
- const results: KVNamespaceInfo[] = [];
56
- while (results.length % pageSize === 0) {
57
- const json = await fetchResult<KVNamespaceInfo[]>(
58
- `/accounts/${accountId}/storage/kv/namespaces`,
59
- {},
60
- new URLSearchParams({
61
- per_page: pageSize.toString(),
62
- order: "title",
63
- direction: "asc",
64
- page: page.toString(),
65
- })
66
- );
67
- page++;
68
- results.push(...json);
69
- if (json.length < pageSize) {
70
- break;
71
- }
72
- }
73
- return results;
74
- }
75
-
76
- export interface NamespaceKeyInfo {
77
- name: string;
78
- expiration?: number;
79
- metadata?: { [key: string]: unknown };
80
- }
81
-
82
- export async function listNamespaceKeys(
83
- accountId: string,
84
- namespaceId: string,
85
- prefix = ""
86
- ) {
87
- return await fetchListResult<NamespaceKeyInfo>(
88
- `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/keys`,
89
- {},
90
- new URLSearchParams({ prefix })
91
- );
92
- }
93
-
94
- export async function putKeyValue(
95
- accountId: string,
96
- namespaceId: string,
97
- key: string,
98
- value: string,
99
- args?: { expiration?: number; expiration_ttl?: number }
100
- ) {
101
- let searchParams: URLSearchParams | undefined;
102
- if (args) {
103
- searchParams = new URLSearchParams();
104
- if (args.expiration) {
105
- searchParams.set("expiration", `${args.expiration}`);
106
- }
107
- if (args.expiration_ttl) {
108
- searchParams.set("expiration_ttl", `${args.expiration_ttl}`);
109
- }
110
- }
111
- return await fetchResult(
112
- `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/values/${key}`,
113
- { method: "PUT", body: value },
114
- searchParams
115
- );
116
- }
117
-
118
- export async function getKeyValue(
119
- accountId: string,
120
- namespaceId: string,
121
- key: string
122
- ): Promise<string> {
123
- return await fetchKVGetValue(accountId, namespaceId, key);
124
- }
125
-
126
- export async function putBulkKeyValue(
127
- accountId: string,
128
- namespaceId: string,
129
- keyvalueStr: string
130
- ) {
131
- return await fetchResult(
132
- `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/bulk`,
133
- {
134
- method: "PUT",
135
- body: keyvalueStr,
136
- headers: { "Content-Type": "application/json" },
137
- }
138
- );
139
- }
140
-
141
- export async function deleteBulkKeyValue(
142
- accountId: string,
143
- namespaceId: string,
144
- keyStr: string
145
- ) {
146
- return await fetchResult(
147
- `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/bulk`,
148
- {
149
- method: "DELETE",
150
- body: keyStr,
151
- headers: { "Content-Type": "application/json" },
152
- }
153
- );
154
- }
155
-
156
- export function getNamespaceId({
157
- preview,
158
- binding,
159
- config,
160
- "namespace-id": namespaceId,
161
- env,
162
- }: KvArgs): string {
163
- // nice
164
- if (namespaceId) {
165
- return namespaceId;
166
- }
167
-
168
- // begin pre-flight checks
169
-
170
- // `--binding` is only valid if there's a wrangler configuration file.
171
- if (binding && !config) {
172
- throw new Error("--binding specified, but no config file was found.");
173
- }
174
-
175
- // there's no config. abort here
176
- if (!config) {
177
- throw new Error(
178
- "Failed to find a config file.\n" +
179
- "Either use --namespace-id to upload directly or create a configuration file with a binding."
180
- );
181
- }
182
-
183
- // they want to use an environment, actually
184
- if (env) {
185
- if (!config.env || !config.env[env]) {
186
- throw new Error(
187
- `Failed to find environment "${env}" in configuration file!`
188
- );
189
- }
190
-
191
- // TODO: either a bespoke arg type for this function to avoid `undefined`s or an `EnvOrConfig` type
192
- return getNamespaceId({
193
- binding,
194
- "namespace-id": namespaceId,
195
- env: undefined,
196
- preview,
197
- config: {
198
- env: undefined,
199
- build: undefined,
200
- name: undefined,
201
- account_id: undefined,
202
- ...config.env[env],
203
- },
204
- });
205
- }
206
-
207
- // there's no KV namespaces
208
- if (!config.kv_namespaces || config.kv_namespaces.length === 0) {
209
- throw new Error(
210
- "No KV Namespaces configured! Either use --namespace-id to upload directly or add a KV namespace to your wrangler config file."
211
- );
212
- }
213
-
214
- const namespace = config.kv_namespaces.find((ns) => ns.binding === binding);
215
-
216
- // we couldn't find a namespace with that binding
217
- if (!namespace) {
218
- throw new Error(
219
- `A namespace with binding name "${binding}" was not found in the configured "kv_namespaces".`
220
- );
221
- }
222
-
223
- // end pre-flight checks
224
-
225
- // we're in preview mode, `--preview true` or `--preview` was passed
226
- if (preview && namespace.preview_id) {
227
- namespaceId = namespace.preview_id;
228
- // We don't want to execute code below if preview is set to true, so we just return. Otherwise we will get errors!
229
- return namespaceId;
230
- } else if (preview) {
231
- throw new Error(
232
- `No preview ID found for ${binding}. Add one to your wrangler config file to use a separate namespace for previewing your worker.`
233
- );
234
- }
235
-
236
- // either `--preview false`, or preview wasn't passed
237
- // TODO: should we care? or should we just treat false and undefined the same
238
- const previewIsDefined = typeof preview !== "undefined";
239
-
240
- // --preview false was passed
241
- if (previewIsDefined && namespace.id) {
242
- namespaceId = namespace.id;
243
- // We don't want to execute code below if preview is set to true, so we just return. Otherwise we can get error!
244
- return namespaceId;
245
- } else if (previewIsDefined) {
246
- throw new Error(
247
- `No namespace ID found for ${binding}. Add one to your wrangler config file to use a separate namespace for previewing your worker.`
248
- );
249
- }
250
-
251
- // `--preview` wasn't passed
252
- const bindingHasOnlyOneId =
253
- (namespace.id && !namespace.preview_id) ||
254
- (!namespace.id && namespace.preview_id);
255
- if (bindingHasOnlyOneId) {
256
- namespaceId = namespace.id || namespace.preview_id;
257
- } else {
258
- throw new Error(
259
- `${binding} has both a namespace ID and a preview ID. Specify "--preview" or "--preview false" to avoid writing data to the wrong namespace.`
260
- );
261
- }
262
-
263
- // shouldn't happen. we should be able to prove this with strong typing.
264
- // TODO: when we add strongly typed commands, rewrite these checks so they're exhaustive
265
- if (!namespaceId) {
266
- throw Error(
267
- "Something went wrong trying to determine which namespace to upload to.\n" +
268
- "Please create a github issue with the command you just ran along with your wrangler configuration."
269
- );
270
- }
271
-
272
- return namespaceId;
273
- }
274
-
275
- /**
276
- * KV namespace binding names must be valid JS identifiers.
277
- */
278
- export function isValidNamespaceBinding(
279
- binding: string | undefined
280
- ): binding is string {
281
- return (
282
- typeof binding === "string" && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(binding)
283
- );
284
- }
@@ -1,63 +0,0 @@
1
- import crypto from "node:crypto";
2
- import { readFile } from "node:fs/promises";
3
- import path from "node:path";
4
- import type { CfModule } from "./api/worker";
5
- import type esbuild from "esbuild";
6
-
7
- // This is a combination of an esbuild plugin and a mutable array
8
- // that we use to collect module references from source code.
9
- // There will be modules that _shouldn't_ be inlined directly into
10
- // the bundle. (eg. wasm modules, some text files, etc). We can include
11
- // those files as modules in the multi part forker form upload. This
12
- // plugin+array is used to collect references to these modules, reference
13
- // them correctly in the bundle, and add them to the form upload.
14
-
15
- export default function makeModuleCollector(): {
16
- modules: CfModule[];
17
- plugin: esbuild.Plugin;
18
- } {
19
- const modules: CfModule[] = [];
20
- return {
21
- modules,
22
- plugin: {
23
- name: "wrangler-module-collector",
24
- setup(build) {
25
- build.onStart(() => {
26
- // reset the moduels collection
27
- modules.splice(0);
28
- });
29
-
30
- build.onResolve(
31
- // filter on "known" file types,
32
- // we can expand this list later
33
- { filter: /.*\.(wasm)$/ },
34
- async (args: esbuild.OnResolveArgs) => {
35
- // take the file and massage it to a
36
- // transportable/manageable format
37
- const filePath = path.join(args.resolveDir, args.path);
38
- const fileContent = await readFile(filePath);
39
- const fileHash = crypto
40
- .createHash("sha1")
41
- .update(fileContent)
42
- .digest("hex");
43
- const fileName = `${fileHash}-${path.basename(args.path)}`;
44
-
45
- // add the module to the array
46
- modules.push({
47
- name: fileName,
48
- content: fileContent,
49
- type: "compiled-wasm",
50
- });
51
-
52
- return {
53
- path: fileName, // change the reference to the changed module
54
- external: true, // mark it as external in the bundle
55
- namespace: "wrangler-module-collector-ns", // just a tag, this isn't strictly necessary
56
- watchFiles: [filePath], // we also add the file to esbuild's watch list
57
- };
58
- }
59
- );
60
- },
61
- },
62
- };
63
- }
@@ -1,120 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { join } from "node:path";
3
- import { execa, execaCommandSync } from "execa";
4
-
5
- export interface PackageManager {
6
- addDevDeps(...packages: string[]): Promise<void>;
7
- install(): Promise<void>;
8
- }
9
-
10
- export async function getPackageManager(root: string): Promise<PackageManager> {
11
- const [hasYarn, hasNpm] = await Promise.all([supportsYarn(), supportsNpm()]);
12
- const hasYarnLock = existsSync(join(root, "yarn.lock"));
13
- const hasNpmLock = existsSync(join(root, "package-lock.json"));
14
-
15
- if (hasNpmLock) {
16
- if (hasNpm) {
17
- console.log(
18
- "Using npm as package manager, as there is already a package-lock.json file."
19
- );
20
- return NpmPackageManager;
21
- } else if (hasYarn) {
22
- console.log("Using yarn as package manager.");
23
- console.warn(
24
- "There is already a package-lock.json file but could not find npm on the PATH."
25
- );
26
- return YarnPackageManager;
27
- }
28
- } else if (hasYarnLock) {
29
- if (hasYarn) {
30
- console.log(
31
- "Using yarn as package manager, as there is already a yarn.lock file."
32
- );
33
- return YarnPackageManager;
34
- } else if (hasNpm) {
35
- console.log("Using npm as package manager.");
36
- console.warn(
37
- "There is already a yarn.lock file but could not find yarn on the PATH."
38
- );
39
- return NpmPackageManager;
40
- }
41
- }
42
-
43
- if (hasNpm) {
44
- console.log("Using npm as package manager.");
45
- return NpmPackageManager;
46
- } else if (hasYarn) {
47
- console.log("Using yarn as package manager.");
48
- return YarnPackageManager;
49
- } else {
50
- throw new Error(
51
- "Unable to find a package manager. Supported managers are: npm and yarn."
52
- );
53
- }
54
- }
55
-
56
- /**
57
- * Get the name of the given `packageManager`.
58
- */
59
- export function getPackageManagerName(packageManager: unknown): string {
60
- return packageManager === NpmPackageManager
61
- ? "npm"
62
- : packageManager === YarnPackageManager
63
- ? "yarn"
64
- : "unknown";
65
- }
66
-
67
- /**
68
- * Manage packages using npm
69
- */
70
- const NpmPackageManager: PackageManager = {
71
- /** Add and install a new devDependency into the local package.json. */
72
- async addDevDeps(...packages: string[]): Promise<void> {
73
- await execa("npm", ["install", ...packages, "--save-dev"], {
74
- stdio: "inherit",
75
- });
76
- },
77
-
78
- /** Install all the dependencies in the local package.json. */
79
- async install(): Promise<void> {
80
- await execa("npm", ["install"], {
81
- stdio: "inherit",
82
- });
83
- },
84
- };
85
-
86
- /**
87
- * Manage packages using yarn
88
- */
89
- const YarnPackageManager: PackageManager = {
90
- /** Add and install a new devDependency into the local package.json. */
91
- async addDevDeps(...packages: string[]): Promise<void> {
92
- await execa("yarn", ["add", ...packages, "--dev"], {
93
- stdio: "inherit",
94
- });
95
- },
96
-
97
- /** Install all the dependencies in the local package.json. */
98
- async install(): Promise<void> {
99
- await execa("yarn", ["install"], {
100
- stdio: "inherit",
101
- });
102
- },
103
- };
104
-
105
- async function supports(name: string): Promise<boolean> {
106
- try {
107
- execaCommandSync(`${name} --version`, { stdio: "ignore" });
108
- return true;
109
- } catch {
110
- return false;
111
- }
112
- }
113
-
114
- function supportsYarn(): Promise<boolean> {
115
- return supports("yarn");
116
- }
117
-
118
- function supportsNpm(): Promise<boolean> {
119
- return supports("npm");
120
- }