wrangler 0.0.0-e6733a3 → 0.0.0-e6ada079

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.

Potentially problematic release.


This version of wrangler might be problematic. Click here for more details.

Files changed (119) hide show
  1. package/README.md +47 -16
  2. package/bin/wrangler.js +94 -31
  3. package/config-schema.json +3100 -0
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +154 -82
  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 +19 -0
  11. package/templates/gitignore +170 -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 +134 -0
  17. package/templates/middleware/loader-sw.ts +229 -0
  18. package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
  19. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  20. package/templates/middleware/middleware-pretty-error.ts +40 -0
  21. package/templates/middleware/middleware-scheduled.ts +15 -0
  22. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  23. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  24. package/templates/modules-watch-stub.js +4 -0
  25. package/templates/new-worker-scheduled.js +17 -0
  26. package/templates/new-worker-scheduled.ts +32 -0
  27. package/templates/new-worker.js +15 -0
  28. package/templates/new-worker.ts +33 -0
  29. package/templates/no-op-worker.js +10 -0
  30. package/templates/pages-dev-pipeline.ts +32 -0
  31. package/templates/pages-dev-util.ts +55 -0
  32. package/templates/pages-shim.ts +9 -0
  33. package/templates/pages-template-plugin.ts +190 -0
  34. package/templates/pages-template-worker.ts +198 -0
  35. package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
  36. package/templates/startDevWorker/ProxyWorker.ts +334 -0
  37. package/templates/tsconfig-sanity.ts +11 -0
  38. package/templates/tsconfig.init.json +22 -0
  39. package/templates/tsconfig.json +8 -0
  40. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  41. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  42. package/wrangler-dist/ProxyWorker.js +240 -0
  43. package/wrangler-dist/ProxyWorker.js.map +6 -0
  44. package/wrangler-dist/cli.d.ts +26391 -0
  45. package/wrangler-dist/cli.js +204293 -116652
  46. package/wrangler-dist/wasm-sync.wasm +0 -0
  47. package/import_meta_url.js +0 -3
  48. package/miniflare-config-stubs/.env.empty +0 -0
  49. package/miniflare-config-stubs/package.empty.json +0 -1
  50. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  51. package/pages/functions/buildWorker.ts +0 -62
  52. package/pages/functions/filepath-routing.test.ts +0 -39
  53. package/pages/functions/filepath-routing.ts +0 -221
  54. package/pages/functions/identifiers.ts +0 -78
  55. package/pages/functions/routes.ts +0 -158
  56. package/pages/functions/template-worker.ts +0 -144
  57. package/src/__tests__/clipboardy-mock.js +0 -4
  58. package/src/__tests__/dev.test.tsx +0 -66
  59. package/src/__tests__/index.test.ts +0 -287
  60. package/src/__tests__/jest.setup.ts +0 -22
  61. package/src/__tests__/kv.test.ts +0 -1098
  62. package/src/__tests__/mock-cfetch.ts +0 -171
  63. package/src/__tests__/mock-dialogs.ts +0 -65
  64. package/src/__tests__/run-in-tmp.ts +0 -19
  65. package/src/__tests__/run-wrangler.ts +0 -32
  66. package/src/api/form_data.ts +0 -131
  67. package/src/api/preview.ts +0 -128
  68. package/src/api/worker.ts +0 -155
  69. package/src/cfetch/index.ts +0 -102
  70. package/src/cfetch/internal.ts +0 -69
  71. package/src/cli.ts +0 -9
  72. package/src/config.ts +0 -487
  73. package/src/dev.tsx +0 -771
  74. package/src/dialogs.tsx +0 -77
  75. package/src/index.tsx +0 -1974
  76. package/src/inspect.ts +0 -524
  77. package/src/kv.tsx +0 -267
  78. package/src/module-collection.ts +0 -64
  79. package/src/pages.tsx +0 -1031
  80. package/src/proxy.ts +0 -294
  81. package/src/publish.ts +0 -358
  82. package/src/sites.tsx +0 -114
  83. package/src/tail.tsx +0 -73
  84. package/src/user.tsx +0 -1025
  85. package/static-asset-facade.js +0 -47
  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
  119. package/wrangler-dist/cli.js.map +0 -7
@@ -1,144 +0,0 @@
1
- import { match } from "path-to-regexp";
2
- import type { HTTPMethod } from "./routes";
3
-
4
- /* TODO: Grab these from @cloudflare/workers-types instead */
5
- type Params<P extends string = string> = Record<P, string | string[]>;
6
-
7
- type EventContext<Env, P extends string, Data> = {
8
- request: Request;
9
- waitUntil: (promise: Promise<unknown>) => void;
10
- next: (input?: Request | string, init?: RequestInit) => Promise<Response>;
11
- env: Env & { ASSETS: { fetch: typeof fetch } };
12
- params: Params<P>;
13
- data: Data;
14
- };
15
-
16
- declare type PagesFunction<
17
- Env = unknown,
18
- P extends string = string,
19
- Data extends Record<string, unknown> = Record<string, unknown>
20
- > = (context: EventContext<Env, P, Data>) => Response | Promise<Response>;
21
- /* end @cloudflare/workers-types */
22
-
23
- type RouteHandler = {
24
- routePath: string;
25
- methods: HTTPMethod[];
26
- modules: PagesFunction[];
27
- middlewares: PagesFunction[];
28
- };
29
-
30
- // inject `routes` via ESBuild
31
- declare const routes: RouteHandler[];
32
- // define `__FALLBACK_SERVICE__` via ESBuild
33
- declare const __FALLBACK_SERVICE__: string;
34
-
35
- // expect an ASSETS fetcher binding pointing to the asset-server stage
36
- type Env = {
37
- [name: string]: unknown;
38
- ASSETS: { fetch(url: string, init: RequestInit): Promise<Response> };
39
- };
40
-
41
- type WorkerContext = {
42
- waitUntil: (promise: Promise<unknown>) => void;
43
- };
44
-
45
- // eslint-disable-next-line @typescript-eslint/no-unused-vars -- `env` can be used by __FALLBACK_SERVICE_FETCH__
46
- function* executeRequest(request: Request, env: Env) {
47
- const requestPath = new URL(request.url).pathname;
48
-
49
- // First, iterate through the routes (backwards) and execute "middlewares" on partial route matches
50
- for (const route of [...routes].reverse()) {
51
- if (
52
- route.methods.length &&
53
- !route.methods.includes(request.method as HTTPMethod)
54
- ) {
55
- continue;
56
- }
57
-
58
- const routeMatcher = match(route.routePath, { end: false });
59
- const matchResult = routeMatcher(requestPath);
60
- if (matchResult) {
61
- for (const handler of route.middlewares.flat()) {
62
- yield {
63
- handler,
64
- params: matchResult.params as Params,
65
- };
66
- }
67
- }
68
- }
69
-
70
- // Then look for the first exact route match and execute its "modules"
71
- for (const route of routes) {
72
- if (
73
- route.methods.length &&
74
- !route.methods.includes(request.method as HTTPMethod)
75
- ) {
76
- continue;
77
- }
78
-
79
- const routeMatcher = match(route.routePath, { end: true });
80
- const matchResult = routeMatcher(requestPath);
81
- if (matchResult && route.modules.length) {
82
- for (const handler of route.modules.flat()) {
83
- yield {
84
- handler,
85
- params: matchResult.params as Params,
86
- };
87
- }
88
- break;
89
- }
90
- }
91
-
92
- // Finally, yield to the fallback service (`env.ASSETS.fetch` in Pages' case)
93
- return {
94
- handler: () =>
95
- __FALLBACK_SERVICE__
96
- ? // @ts-expect-error expecting __FALLBACK_SERVICE__ to be the name of a service binding, so fetch should be defined
97
- env[__FALLBACK_SERVICE__].fetch(request)
98
- : fetch(request),
99
- params: {} as Params,
100
- };
101
- }
102
-
103
- export default {
104
- async fetch(request: Request, env: Env, workerContext: WorkerContext) {
105
- const handlerIterator = executeRequest(request, env);
106
- const data = {}; // arbitrary data the user can set between functions
107
- const next = async (input?: RequestInfo, init?: RequestInit) => {
108
- if (input !== undefined) {
109
- request = new Request(input, init);
110
- }
111
-
112
- const { value } = handlerIterator.next();
113
- if (value) {
114
- const { handler, params } = value;
115
- const context: EventContext<
116
- unknown,
117
- string,
118
- Record<string, unknown>
119
- > = {
120
- request: new Request(request.clone()),
121
- next,
122
- params,
123
- data,
124
- env,
125
- waitUntil: workerContext.waitUntil.bind(workerContext),
126
- };
127
-
128
- const response = await handler(context);
129
-
130
- // https://fetch.spec.whatwg.org/#null-body-status
131
- return new Response(
132
- [101, 204, 205, 304].includes(response.status) ? null : response.body,
133
- response
134
- );
135
- }
136
- };
137
-
138
- try {
139
- return next();
140
- } catch (err) {
141
- return new Response("Internal Error", { status: 500 });
142
- }
143
- },
144
- };
@@ -1,4 +0,0 @@
1
- // We use this mock during tests because we're having trouble
2
- // properly compiling clipboardy for jest
3
- // We can revisit this if and when we write tests that test
4
- // the copying part of `dev`
@@ -1,66 +0,0 @@
1
- import { render } from "ink-testing-library";
2
- import patchConsole from "patch-console";
3
- import React from "react";
4
- import Dev from "../dev";
5
- import type { DevProps } from "../dev";
6
-
7
- describe("Dev component", () => {
8
- let restoreConsole;
9
- beforeEach(() => (restoreConsole = patchConsole(() => {})));
10
- afterEach(() => restoreConsole());
11
-
12
- it("should throw if format is service-worker and there is a public directory", () => {
13
- const { lastFrame } = renderDev({
14
- format: "service-worker",
15
- accountId: "some-account-id",
16
- public: "some/public/path",
17
- });
18
- expect(lastFrame()).toMatchInlineSnapshot(`
19
- "Something went wrong:
20
- You cannot use the service worker format with a \`public\` directory."
21
- `);
22
- });
23
- });
24
-
25
- /**
26
- * Helper function to make it easier to setup and render the `Dev` component.
27
- *
28
- * All the `Dev` props are optional here, with sensible defaults for testing.
29
- */
30
- function renderDev({
31
- name,
32
- entry = "some/entry.ts",
33
- port,
34
- format,
35
- accountId,
36
- initialMode = "remote",
37
- jsxFactory,
38
- jsxFragment,
39
- bindings = {},
40
- public: publicDir,
41
- site,
42
- compatibilityDate,
43
- compatibilityFlags,
44
- usageModel,
45
- buildCommand = {},
46
- }: Partial<DevProps>) {
47
- return render(
48
- <Dev
49
- name={name}
50
- entry={entry}
51
- port={port}
52
- buildCommand={buildCommand}
53
- format={format}
54
- initialMode={initialMode}
55
- jsxFactory={jsxFactory}
56
- jsxFragment={jsxFragment}
57
- accountId={accountId}
58
- site={site}
59
- public={publicDir}
60
- compatibilityDate={compatibilityDate}
61
- compatibilityFlags={compatibilityFlags}
62
- usageModel={usageModel}
63
- bindings={bindings}
64
- />
65
- );
66
- }
@@ -1,287 +0,0 @@
1
- import * as fsp from "node:fs/promises";
2
- import * as TOML from "@iarna/toml";
3
- import { mockConfirm } from "./mock-dialogs";
4
- import { runWrangler } from "./run-wrangler";
5
- import { runInTempDir } from "./run-in-tmp";
6
- import * as fs from "node:fs";
7
-
8
- describe("wrangler", () => {
9
- runInTempDir();
10
-
11
- describe("no command", () => {
12
- it("should display a list of available commands", async () => {
13
- const { stdout, stderr } = await runWrangler();
14
-
15
- expect(stdout).toMatchInlineSnapshot(`
16
- "wrangler
17
-
18
- Commands:
19
- wrangler init [name] 📥 Create a wrangler.toml configuration file
20
- wrangler dev <filename> 👂 Start a local server for developing your worker
21
- wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
22
- wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker.
23
- wrangler secret 🤫 Generate a secret that can be referenced in the worker script
24
- wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
25
- wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
26
- wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
27
- wrangler pages ⚡️ Configure Cloudflare Pages
28
-
29
- Flags:
30
- -c, --config Path to .toml configuration file [string]
31
- -h, --help Show help [boolean]
32
- -v, --version Show version number [boolean]
33
-
34
- Options:
35
- -l, --local Run on my machine [boolean] [default: false]"
36
- `);
37
-
38
- expect(stderr).toMatchInlineSnapshot(`""`);
39
- });
40
- });
41
-
42
- describe("invalid command", () => {
43
- it("should display an error", async () => {
44
- const { error, stdout, stderr } = await runWrangler("invalid-command");
45
-
46
- expect(stdout).toMatchInlineSnapshot(`""`);
47
- expect(stderr).toMatchInlineSnapshot(`
48
- "wrangler
49
-
50
- Commands:
51
- wrangler init [name] 📥 Create a wrangler.toml configuration file
52
- wrangler dev <filename> 👂 Start a local server for developing your worker
53
- wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
54
- wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker.
55
- wrangler secret 🤫 Generate a secret that can be referenced in the worker script
56
- wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
57
- wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
58
- wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
59
- wrangler pages ⚡️ Configure Cloudflare Pages
60
-
61
- Flags:
62
- -c, --config Path to .toml configuration file [string]
63
- -h, --help Show help [boolean]
64
- -v, --version Show version number [boolean]
65
-
66
- Options:
67
- -l, --local Run on my machine [boolean] [default: false]
68
-
69
- Unknown command: invalid-command."
70
- `);
71
- expect(error).toMatchInlineSnapshot(
72
- `[Error: Unknown command: invalid-command.]`
73
- );
74
- });
75
- });
76
-
77
- describe("init", () => {
78
- it("should create a wrangler.toml", async () => {
79
- mockConfirm({
80
- text: "No package.json found. Would you like to create one?",
81
- result: false,
82
- });
83
- await runWrangler("init");
84
- const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
85
- expect(typeof parsed.compatibility_date).toBe("string");
86
- expect(fs.existsSync("./package.json")).toBe(false);
87
- expect(fs.existsSync("./tsconfig.json")).toBe(false);
88
- });
89
-
90
- it("should display warning when wrangler.toml already exists, and exit if user does not want to carry on", async () => {
91
- fs.writeFileSync("./wrangler.toml", "", "utf-8");
92
- mockConfirm({
93
- text: "Do you want to continue initializing this project?",
94
- result: false,
95
- });
96
- const { warnings } = await runWrangler("init");
97
- expect(warnings).toContain("wrangler.toml file already exists!");
98
- const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
99
- expect(typeof parsed.compatibility_date).toBe("undefined");
100
- });
101
-
102
- it("should display warning when wrangler.toml already exists, but continue if user does want to carry on", async () => {
103
- fs.writeFileSync("./wrangler.toml", "", "utf-8");
104
- mockConfirm(
105
- {
106
- text: "Do you want to continue initializing this project?",
107
- result: true,
108
- },
109
- {
110
- text: "No package.json found. Would you like to create one?",
111
- result: false,
112
- }
113
- );
114
- const { warnings } = await runWrangler("init");
115
- expect(warnings).toContain("wrangler.toml file already exists!");
116
- const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
117
- expect(typeof parsed.compatibility_date).toBe("string");
118
- });
119
-
120
- it("should create a package.json if none is found and user confirms", async () => {
121
- mockConfirm(
122
- {
123
- text: "No package.json found. Would you like to create one?",
124
- result: true,
125
- },
126
- {
127
- text: "Would you like to use typescript?",
128
- result: false,
129
- }
130
- );
131
- await runWrangler("init");
132
- expect(fs.existsSync("./package.json")).toBe(true);
133
- const packageJson = JSON.parse(
134
- fs.readFileSync("./package.json", "utf-8")
135
- );
136
- expect(packageJson.name).toEqual("worker"); // TODO: should we infer the name from the directory?
137
- expect(packageJson.version).toEqual("0.0.1");
138
- expect(fs.existsSync("./tsconfig.json")).toBe(false);
139
- });
140
-
141
- it("should not touch an existing package.json in the same directory", async () => {
142
- mockConfirm({
143
- text: "Would you like to use typescript?",
144
- result: false,
145
- });
146
-
147
- fs.writeFileSync(
148
- "./package.json",
149
- JSON.stringify({ name: "test", version: "1.0.0" }),
150
- "utf-8"
151
- );
152
-
153
- await runWrangler("init");
154
- const packageJson = JSON.parse(
155
- fs.readFileSync("./package.json", "utf-8")
156
- );
157
- expect(packageJson.name).toEqual("test");
158
- expect(packageJson.version).toEqual("1.0.0");
159
- });
160
-
161
- it("should not touch an existing package.json in an ancestor directory", async () => {
162
- mockConfirm({
163
- text: "Would you like to use typescript?",
164
- result: false,
165
- });
166
-
167
- fs.writeFileSync(
168
- "./package.json",
169
- JSON.stringify({ name: "test", version: "1.0.0" }),
170
- "utf-8"
171
- );
172
-
173
- fs.mkdirSync("./sub-1/sub-2", { recursive: true });
174
- process.chdir("./sub-1/sub-2");
175
-
176
- await runWrangler("init");
177
- expect(fs.existsSync("./package.json")).toBe(false);
178
- expect(fs.existsSync("../../package.json")).toBe(true);
179
-
180
- const packageJson = JSON.parse(
181
- fs.readFileSync("../../package.json", "utf-8")
182
- );
183
- expect(packageJson.name).toEqual("test");
184
- expect(packageJson.version).toEqual("1.0.0");
185
- });
186
-
187
- it("should create a tsconfig.json and install `workers-types` if none is found and user confirms", async () => {
188
- mockConfirm(
189
- {
190
- text: "No package.json found. Would you like to create one?",
191
- result: true,
192
- },
193
- {
194
- text: "Would you like to use typescript?",
195
- result: true,
196
- }
197
- );
198
- await runWrangler("init");
199
- expect(fs.existsSync("./tsconfig.json")).toBe(true);
200
- const tsconfigJson = JSON.parse(
201
- fs.readFileSync("./tsconfig.json", "utf-8")
202
- );
203
- expect(tsconfigJson.compilerOptions.types).toEqual([
204
- "@cloudflare/workers-types",
205
- ]);
206
- const packageJson = JSON.parse(
207
- fs.readFileSync("./package.json", "utf-8")
208
- );
209
- expect(packageJson.devDependencies).toEqual({
210
- "@cloudflare/workers-types": expect.any(String),
211
- });
212
- });
213
-
214
- it("should not touch an existing tsconfig.json in the same directory", async () => {
215
- fs.writeFileSync(
216
- "./package.json",
217
- JSON.stringify({ name: "test", version: "1.0.0" }),
218
- "utf-8"
219
- );
220
- fs.writeFileSync(
221
- "./tsconfig.json",
222
- JSON.stringify({ compilerOptions: {} }),
223
- "utf-8"
224
- );
225
-
226
- await runWrangler("init");
227
- const tsconfigJson = JSON.parse(
228
- fs.readFileSync("./tsconfig.json", "utf-8")
229
- );
230
- expect(tsconfigJson.compilerOptions).toEqual({});
231
- });
232
-
233
- it("should not touch an existing package.json in an ancestor directory", async () => {
234
- fs.writeFileSync(
235
- "./package.json",
236
- JSON.stringify({ name: "test", version: "1.0.0" }),
237
- "utf-8"
238
- );
239
- fs.writeFileSync(
240
- "./tsconfig.json",
241
- JSON.stringify({ compilerOptions: {} }),
242
- "utf-8"
243
- );
244
-
245
- fs.mkdirSync("./sub-1/sub-2", { recursive: true });
246
- process.chdir("./sub-1/sub-2");
247
-
248
- await runWrangler("init");
249
- expect(fs.existsSync("./tsconfig.json")).toBe(false);
250
- expect(fs.existsSync("../../tsconfig.json")).toBe(true);
251
-
252
- const tsconfigJson = JSON.parse(
253
- fs.readFileSync("../../tsconfig.json", "utf-8")
254
- );
255
- expect(tsconfigJson.compilerOptions).toEqual({});
256
- });
257
-
258
- it("should error if `--type` is used", async () => {
259
- const { error } = await runWrangler("init --type");
260
- expect(error).toMatchInlineSnapshot(
261
- `[Error: The --type option is no longer supported.]`
262
- );
263
- });
264
-
265
- it("should error if `--type javascript` is used", async () => {
266
- const { error } = await runWrangler("init --type javascript");
267
- expect(error).toMatchInlineSnapshot(
268
- `[Error: The --type option is no longer supported.]`
269
- );
270
- });
271
-
272
- it("should error if `--type rust` is used", async () => {
273
- const { error } = await runWrangler("init --type rust");
274
- expect(error).toMatchInlineSnapshot(
275
- `[Error: The --type option is no longer supported.]`
276
- );
277
- });
278
-
279
- it("should error if `--type webpack` is used", async () => {
280
- const { error } = await runWrangler("init --type webpack");
281
- expect(error).toMatchInlineSnapshot(`
282
- [Error: The --type option is no longer supported.
283
- If you wish to use webpack then you will need to create a custom build.]
284
- `);
285
- });
286
- });
287
- });
@@ -1,22 +0,0 @@
1
- import { mockFetchInternal } from "./mock-cfetch";
2
- import { confirm, prompt } from "../dialogs";
3
- import { fetchInternal } from "../cfetch/internal";
4
-
5
- jest.mock("../cfetch/internal");
6
- (fetchInternal as jest.Mock).mockImplementation(mockFetchInternal);
7
-
8
- jest.mock("../dialogs");
9
-
10
- // By default (if not configured by mockConfirm()) calls to `confirm()` should throw.
11
- (confirm as jest.Mock).mockImplementation(() => {
12
- throw new Error(
13
- "Unexpected call to `confirm()`. You should use `mockConfirm()` to mock calls to `confirm()` with expectations. Search the codebase for `mockConfirm` to learn more."
14
- );
15
- });
16
-
17
- // By default (if not configured by mockPrompt()) calls to `prompt()` should throw.
18
- (prompt as jest.Mock).mockImplementation(() => {
19
- throw new Error(
20
- "Unexpected call to `prompt()`. You should use `mockPrompt()` to mock calls to `prompt()` with expectations. Search the codebase for `mockPrompt` to learn more."
21
- );
22
- });