wrangler 0.0.0-e33294b0 → 0.0.0-e3c036d7
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 +1 -1
- package/miniflare-dist/index.mjs +21 -4
- package/package.json +8 -8
- package/src/__tests__/configuration.test.ts +235 -6
- package/src/__tests__/d1/execute.test.ts +1 -1
- package/src/__tests__/dev.test.tsx +16 -1
- package/src/__tests__/guess-worker-format.test.ts +35 -0
- package/src/__tests__/init.test.ts +8 -7
- package/src/__tests__/middleware.test.ts +2 -1
- package/src/__tests__/pages/functions-build.test.ts +51 -0
- package/src/__tests__/publish.test.ts +122 -8
- package/src/__tests__/test-old-node-version.js +3 -3
- package/src/__tests__/tsconfig.tsbuildinfo +1 -1
- package/src/__tests__/type-generation.test.ts +1 -0
- package/src/__tests__/user.test.ts +1 -1
- package/src/api/dev.ts +3 -4
- package/src/api/pages/publish.tsx +7 -0
- package/src/bundle.ts +23 -9
- package/src/config/environment.ts +9 -4
- package/src/config/index.ts +12 -2
- package/src/config/validation-helpers.ts +1 -1
- package/src/config/validation.ts +58 -4
- package/src/create-worker-preview.ts +19 -8
- package/src/create-worker-upload-form.ts +10 -2
- package/src/dev/dev.tsx +4 -4
- package/src/dev/local.tsx +17 -20
- package/src/dev/start-server.ts +10 -8
- package/src/dev/use-esbuild.ts +9 -5
- package/src/dev/validate-dev-props.ts +9 -0
- package/src/dev.tsx +27 -13
- package/src/entry.ts +1 -2
- package/src/index.ts +1 -1
- package/src/init.ts +1 -0
- package/src/inspect.ts +16 -1
- package/src/miniflare-cli/assets.ts +8 -7
- package/src/miniflare-cli/index.ts +1 -1
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
- package/src/pages/build.ts +25 -5
- package/src/pages/buildFunctions.ts +7 -4
- package/src/pages/dev.ts +18 -8
- package/src/pages/functions/buildPlugin.ts +10 -3
- package/src/pages/functions/buildWorker.ts +12 -6
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
- package/src/paths.ts +1 -1
- package/src/publish/index.ts +1 -1
- package/src/publish/publish.ts +19 -8
- package/src/r2/helpers.ts +1 -0
- package/src/secret/index.ts +1 -1
- package/src/type-generation.ts +1 -1
- package/src/user/user.ts +1 -1
- package/src/worker.ts +8 -1
- package/templates/d1-beta-facade.js +2 -2
- package/templates/gitignore +1 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +17 -5
- package/templates/pages-template-plugin.ts +7 -3
- package/templates/tsconfig.tsbuildinfo +1 -1
- package/wrangler-dist/cli.d.ts +522 -6
- package/wrangler-dist/cli.js +11004 -4192
|
@@ -326,7 +326,7 @@ describe("publish", () => {
|
|
|
326
326
|
await expect(runWrangler("publish index.js")).rejects.toThrowError();
|
|
327
327
|
|
|
328
328
|
expect(std.err).toMatchInlineSnapshot(`
|
|
329
|
-
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mIn a non-interactive environment, it's necessary to set a CLOUDFLARE_API_TOKEN environment variable for wrangler to work. Please go to https://developers.cloudflare.com/api/
|
|
329
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mIn a non-interactive environment, it's necessary to set a CLOUDFLARE_API_TOKEN environment variable for wrangler to work. Please go to https://developers.cloudflare.com/fundamentals/api/get-started/create-token/ for instructions on how to create an api token, and assign its value to CLOUDFLARE_API_TOKEN.[0m
|
|
330
330
|
|
|
331
331
|
"
|
|
332
332
|
`);
|
|
@@ -4559,6 +4559,10 @@ addEventListener('fetch', event => {});`
|
|
|
4559
4559
|
data: 1337,
|
|
4560
4560
|
},
|
|
4561
4561
|
],
|
|
4562
|
+
metadata: {
|
|
4563
|
+
extra_data: "interesting value",
|
|
4564
|
+
more_data: "dubious value",
|
|
4565
|
+
},
|
|
4562
4566
|
},
|
|
4563
4567
|
vars: {
|
|
4564
4568
|
ENV_VAR_ONE: 123,
|
|
@@ -4603,6 +4607,10 @@ addEventListener('fetch', event => {});`
|
|
|
4603
4607
|
|
|
4604
4608
|
mockUploadWorkerRequest({
|
|
4605
4609
|
expectedType: "sw",
|
|
4610
|
+
expectedUnsafeMetaData: {
|
|
4611
|
+
extra_data: "interesting value",
|
|
4612
|
+
more_data: "dubious value",
|
|
4613
|
+
},
|
|
4606
4614
|
expectedBindings: [
|
|
4607
4615
|
{ json: 123, name: "ENV_VAR_ONE", type: "json" },
|
|
4608
4616
|
{
|
|
@@ -4726,6 +4734,9 @@ addEventListener('fetch', event => {});`
|
|
|
4726
4734
|
- Wasm Modules:
|
|
4727
4735
|
- WASM_MODULE_ONE: some_wasm.wasm
|
|
4728
4736
|
- WASM_MODULE_TWO: more_wasm.wasm
|
|
4737
|
+
- Unsafe Metadata:
|
|
4738
|
+
- extra_data: interesting value
|
|
4739
|
+
- more_data: dubious value
|
|
4729
4740
|
Uploaded test-name (TIMINGS)
|
|
4730
4741
|
Published test-name (TIMINGS)
|
|
4731
4742
|
https://test-name.test-sub-domain.workers.dev
|
|
@@ -4794,6 +4805,7 @@ addEventListener('fetch', event => {});`
|
|
|
4794
4805
|
data: 1337,
|
|
4795
4806
|
},
|
|
4796
4807
|
],
|
|
4808
|
+
metadata: undefined,
|
|
4797
4809
|
},
|
|
4798
4810
|
vars: {
|
|
4799
4811
|
ENV_VAR_ONE: 123,
|
|
@@ -4907,6 +4919,7 @@ addEventListener('fetch', event => {});`
|
|
|
4907
4919
|
data: 1337,
|
|
4908
4920
|
},
|
|
4909
4921
|
],
|
|
4922
|
+
metadata: undefined,
|
|
4910
4923
|
},
|
|
4911
4924
|
// text_blobs, vars, wasm_modules and data_blobs are fine because they're object literals,
|
|
4912
4925
|
// and by definition cannot have two keys of the same name
|
|
@@ -5055,6 +5068,7 @@ addEventListener('fetch', event => {});`
|
|
|
5055
5068
|
data: null,
|
|
5056
5069
|
},
|
|
5057
5070
|
],
|
|
5071
|
+
metadata: undefined,
|
|
5058
5072
|
},
|
|
5059
5073
|
vars: {
|
|
5060
5074
|
ENV_VAR_ONE: 123,
|
|
@@ -5992,6 +6006,7 @@ addEventListener('fetch', event => {});`
|
|
|
5992
6006
|
param: "binding-param",
|
|
5993
6007
|
},
|
|
5994
6008
|
],
|
|
6009
|
+
metadata: undefined,
|
|
5995
6010
|
},
|
|
5996
6011
|
});
|
|
5997
6012
|
writeWorkerSource();
|
|
@@ -6036,6 +6051,7 @@ addEventListener('fetch', event => {});`
|
|
|
6036
6051
|
text: "text",
|
|
6037
6052
|
},
|
|
6038
6053
|
],
|
|
6054
|
+
metadata: undefined,
|
|
6039
6055
|
},
|
|
6040
6056
|
});
|
|
6041
6057
|
writeWorkerSource();
|
|
@@ -6489,9 +6505,22 @@ addEventListener('fetch', event => {});`
|
|
|
6489
6505
|
`);
|
|
6490
6506
|
});
|
|
6491
6507
|
|
|
6492
|
-
it("should output to target
|
|
6508
|
+
it("should output to target es2022 even if tsconfig says otherwise", async () => {
|
|
6493
6509
|
writeWranglerToml();
|
|
6494
6510
|
writeWorkerSource();
|
|
6511
|
+
fs.writeFileSync(
|
|
6512
|
+
"./index.js",
|
|
6513
|
+
`
|
|
6514
|
+
import { foo } from "./another";
|
|
6515
|
+
const topLevelAwait = await new Promise((resolve) => setTimeout(resolve, 0));
|
|
6516
|
+
|
|
6517
|
+
export default {
|
|
6518
|
+
async fetch(request) {
|
|
6519
|
+
|
|
6520
|
+
return new Response("Hello world!");
|
|
6521
|
+
},
|
|
6522
|
+
};`
|
|
6523
|
+
);
|
|
6495
6524
|
fs.writeFileSync(
|
|
6496
6525
|
"tsconfig.json",
|
|
6497
6526
|
JSON.stringify({
|
|
@@ -6502,8 +6531,14 @@ addEventListener('fetch', event => {});`
|
|
|
6502
6531
|
})
|
|
6503
6532
|
);
|
|
6504
6533
|
mockSubDomainRequest();
|
|
6534
|
+
/**
|
|
6535
|
+
* When we compile with es2022, we should preserve the export statement and top level await
|
|
6536
|
+
* If you attempt to target es2020 top level await will cause a build error
|
|
6537
|
+
* @error Build failed with 1 error:
|
|
6538
|
+
* index.js:3:25: ERROR: Top-level await is not available in the configured target environment ("es2020")
|
|
6539
|
+
*/
|
|
6505
6540
|
mockUploadWorkerRequest({
|
|
6506
|
-
expectedEntry: "export {", //
|
|
6541
|
+
expectedEntry: "export {", // check that the export is preserved
|
|
6507
6542
|
});
|
|
6508
6543
|
await runWrangler("publish index.js"); // this would throw if we tried to compile with es5
|
|
6509
6544
|
expect(std).toMatchInlineSnapshot(`
|
|
@@ -6639,7 +6674,7 @@ export default{
|
|
|
6639
6674
|
"err": "",
|
|
6640
6675
|
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
6641
6676
|
--dry-run: exiting now.",
|
|
6642
|
-
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling
|
|
6677
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.[0m
|
|
6643
6678
|
|
|
6644
6679
|
",
|
|
6645
6680
|
}
|
|
@@ -6686,7 +6721,7 @@ export default{
|
|
|
6686
6721
|
"err": "",
|
|
6687
6722
|
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
6688
6723
|
--dry-run: exiting now.",
|
|
6689
|
-
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling
|
|
6724
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.[0m
|
|
6690
6725
|
|
|
6691
6726
|
",
|
|
6692
6727
|
}
|
|
@@ -6694,6 +6729,78 @@ export default{
|
|
|
6694
6729
|
});
|
|
6695
6730
|
});
|
|
6696
6731
|
|
|
6732
|
+
describe("`nodejs_compat` compatibility flag", () => {
|
|
6733
|
+
it('when absent, should error on any "external" `node:*` imports', async () => {
|
|
6734
|
+
writeWranglerToml();
|
|
6735
|
+
fs.writeFileSync(
|
|
6736
|
+
"index.js",
|
|
6737
|
+
`
|
|
6738
|
+
import AsyncHooks from 'node:async_hooks';
|
|
6739
|
+
console.log(AsyncHooks);
|
|
6740
|
+
export default {}
|
|
6741
|
+
`
|
|
6742
|
+
);
|
|
6743
|
+
let err: esbuild.BuildFailure | undefined;
|
|
6744
|
+
try {
|
|
6745
|
+
await runWrangler("publish index.js --dry-run"); // expecting this to throw, as node compatibility isn't enabled
|
|
6746
|
+
} catch (e) {
|
|
6747
|
+
err = e as esbuild.BuildFailure;
|
|
6748
|
+
}
|
|
6749
|
+
expect(
|
|
6750
|
+
esbuild.formatMessagesSync(err?.errors ?? [], { kind: "error" }).join()
|
|
6751
|
+
).toMatch(/Could not resolve "node:async_hooks"/);
|
|
6752
|
+
});
|
|
6753
|
+
|
|
6754
|
+
it('when present, should support any "external" `node:*` imports', async () => {
|
|
6755
|
+
writeWranglerToml();
|
|
6756
|
+
fs.writeFileSync(
|
|
6757
|
+
"index.js",
|
|
6758
|
+
`
|
|
6759
|
+
import AsyncHooks from 'node:async_hooks';
|
|
6760
|
+
console.log(AsyncHooks);
|
|
6761
|
+
export default {}
|
|
6762
|
+
`
|
|
6763
|
+
);
|
|
6764
|
+
|
|
6765
|
+
await runWrangler(
|
|
6766
|
+
"publish index.js --dry-run --outdir=dist --compatibility-flag=nodejs_compat"
|
|
6767
|
+
);
|
|
6768
|
+
|
|
6769
|
+
expect(std).toMatchInlineSnapshot(`
|
|
6770
|
+
Object {
|
|
6771
|
+
"debug": "",
|
|
6772
|
+
"err": "",
|
|
6773
|
+
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
6774
|
+
--dry-run: exiting now.",
|
|
6775
|
+
"warn": "",
|
|
6776
|
+
}
|
|
6777
|
+
`);
|
|
6778
|
+
expect(fs.readFileSync("dist/index.js", { encoding: "utf-8" })).toContain(
|
|
6779
|
+
`import AsyncHooks from "node:async_hooks";`
|
|
6780
|
+
);
|
|
6781
|
+
});
|
|
6782
|
+
|
|
6783
|
+
it("should conflict with the --node-compat option", async () => {
|
|
6784
|
+
writeWranglerToml();
|
|
6785
|
+
fs.writeFileSync(
|
|
6786
|
+
"index.js",
|
|
6787
|
+
`
|
|
6788
|
+
import AsyncHooks from 'node:async_hooks';
|
|
6789
|
+
console.log(AsyncHooks);
|
|
6790
|
+
export default {}
|
|
6791
|
+
`
|
|
6792
|
+
);
|
|
6793
|
+
|
|
6794
|
+
await expect(
|
|
6795
|
+
runWrangler(
|
|
6796
|
+
"publish index.js --dry-run --outdir=dist --compatibility-flag=nodejs_compat --node-compat"
|
|
6797
|
+
)
|
|
6798
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
6799
|
+
`"The \`nodejs_compat\` compatibility flag cannot be used in conjunction with the legacy \`--node-compat\` flag. If you want to use the Workers runtime Node.js compatibility features, please remove the \`--node-compat\` argument from your CLI command or \`node_compat = true\` from your config file."`
|
|
6800
|
+
);
|
|
6801
|
+
});
|
|
6802
|
+
});
|
|
6803
|
+
|
|
6697
6804
|
describe("bundle reporter", () => {
|
|
6698
6805
|
it("should print the bundle size", async () => {
|
|
6699
6806
|
fs.writeFileSync(
|
|
@@ -7106,7 +7213,7 @@ export default{
|
|
|
7106
7213
|
"publish index.js --no-bundle --node-compat --dry-run --outdir dist"
|
|
7107
7214
|
);
|
|
7108
7215
|
expect(std.warn).toMatchInlineSnapshot(`
|
|
7109
|
-
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling
|
|
7216
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.[0m
|
|
7110
7217
|
|
|
7111
7218
|
|
|
7112
7219
|
[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1m\`--node-compat\` and \`--no-bundle\` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process.[0m
|
|
@@ -7126,7 +7233,7 @@ export default{
|
|
|
7126
7233
|
fs.writeFileSync("index.js", scriptContent);
|
|
7127
7234
|
await runWrangler("publish index.js --dry-run --outdir dist");
|
|
7128
7235
|
expect(std.warn).toMatchInlineSnapshot(`
|
|
7129
|
-
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling
|
|
7236
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.[0m
|
|
7130
7237
|
|
|
7131
7238
|
|
|
7132
7239
|
[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1m\`--node-compat\` and \`--no-bundle\` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process.[0m
|
|
@@ -7448,7 +7555,7 @@ function mockLastDeploymentRequest() {
|
|
|
7448
7555
|
function mockUploadWorkerRequest(
|
|
7449
7556
|
options: {
|
|
7450
7557
|
available_on_subdomain?: boolean;
|
|
7451
|
-
expectedEntry?: string;
|
|
7558
|
+
expectedEntry?: string | RegExp;
|
|
7452
7559
|
expectedMainModule?: string;
|
|
7453
7560
|
expectedType?: "esm" | "sw";
|
|
7454
7561
|
expectedBindings?: unknown;
|
|
@@ -7456,6 +7563,7 @@ function mockUploadWorkerRequest(
|
|
|
7456
7563
|
expectedCompatibilityDate?: string;
|
|
7457
7564
|
expectedCompatibilityFlags?: string[];
|
|
7458
7565
|
expectedMigrations?: CfWorkerInit["migrations"];
|
|
7566
|
+
expectedUnsafeMetaData?: Record<string, string>;
|
|
7459
7567
|
env?: string;
|
|
7460
7568
|
legacyEnv?: boolean;
|
|
7461
7569
|
sendScriptIds?: boolean;
|
|
@@ -7475,6 +7583,7 @@ function mockUploadWorkerRequest(
|
|
|
7475
7583
|
env = undefined,
|
|
7476
7584
|
legacyEnv = false,
|
|
7477
7585
|
expectedMigrations,
|
|
7586
|
+
expectedUnsafeMetaData,
|
|
7478
7587
|
sendScriptIds,
|
|
7479
7588
|
keepVars,
|
|
7480
7589
|
} = options;
|
|
@@ -7544,6 +7653,11 @@ function mockUploadWorkerRequest(
|
|
|
7544
7653
|
if ("expectedMigrations" in options) {
|
|
7545
7654
|
expect(metadata.migrations).toEqual(expectedMigrations);
|
|
7546
7655
|
}
|
|
7656
|
+
if (expectedUnsafeMetaData !== undefined) {
|
|
7657
|
+
Object.keys(expectedUnsafeMetaData).forEach((key) => {
|
|
7658
|
+
expect(metadata[key]).toEqual(expectedUnsafeMetaData[key]);
|
|
7659
|
+
});
|
|
7660
|
+
}
|
|
7547
7661
|
for (const [name, content] of Object.entries(expectedModules)) {
|
|
7548
7662
|
expect(formBody.get(name)).toEqual(content);
|
|
7549
7663
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// this test has to be run with a version of
|
|
1
|
+
// this test has to be run with a version of Node.js older than 16.13 to pass
|
|
2
2
|
|
|
3
3
|
const { spawn } = require("child_process");
|
|
4
4
|
const path = require("path");
|
|
@@ -11,7 +11,7 @@ const wranglerProcess = spawn(
|
|
|
11
11
|
{ stdio: "pipe" }
|
|
12
12
|
);
|
|
13
13
|
|
|
14
|
-
const messageToMatch = "Wrangler requires at least
|
|
14
|
+
const messageToMatch = "Wrangler requires at least Node.js v16.13.0";
|
|
15
15
|
|
|
16
16
|
wranglerProcess.once("exit", (code) => {
|
|
17
17
|
try {
|
|
@@ -25,7 +25,7 @@ wranglerProcess.once("exit", (code) => {
|
|
|
25
25
|
} catch (err) {
|
|
26
26
|
console.error("Error:", err);
|
|
27
27
|
throw new Error(
|
|
28
|
-
"This test has to be run with a version of
|
|
28
|
+
"This test has to be run with a version of Node.js under 16.13 to pass"
|
|
29
29
|
);
|
|
30
30
|
}
|
|
31
31
|
});
|