wrangler 2.0.1 → 2.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "author": "wrangler@cloudflare.com",
5
5
  "description": "Command-line interface for all things Cloudflare Workers",
6
6
  "bin": {
@@ -258,7 +258,7 @@ describe("pages", () => {
258
258
  🆙 Publish a directory of static assets as a Pages deployment
259
259
 
260
260
  Positionals:
261
- directory The directory of Pages Functions [string] [default: \\"functions\\"]
261
+ directory The directory of static files to upload [string]
262
262
 
263
263
  Flags:
264
264
  -c, --config Path to .toml configuration file [string]
@@ -267,11 +267,11 @@ describe("pages", () => {
267
267
  --legacy-env Use legacy environments [boolean]
268
268
 
269
269
  Options:
270
- --project-name The name of the project you want to list deployments for [string]
271
- --branch The branch of the project you want to list deployments for [string]
272
- --commit-hash The branch of the project you want to list deployments for [string]
273
- --commit-message The branch of the project you want to list deployments for [string]
274
- --commit-dirty The branch of the project you want to list deployments for [boolean]
270
+ --project-name The name of the project you want to deploy to [string]
271
+ --branch The name of the branch you want to deploy to [string]
272
+ --commit-hash The SHA to attach to this deployment [string]
273
+ --commit-message The commit message to attach to this deployment [string]
274
+ --commit-dirty Whether or not the workspace should be considered dirty for this deployment [boolean]
275
275
 
276
276
  🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose"
277
277
  `);
@@ -1,6 +1,7 @@
1
1
  import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
3
  import * as TOML from "@iarna/toml";
4
+ import * as esbuild from "esbuild";
4
5
  import { writeAuthConfigFile } from "../user";
5
6
  import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
6
7
  import {
@@ -878,6 +879,77 @@ export default{
878
879
  expect(std.err).toMatchInlineSnapshot(`""`);
879
880
  });
880
881
 
882
+ it("should preserve exports on a module format worker", async () => {
883
+ writeWranglerToml();
884
+ fs.writeFileSync(
885
+ "index.js",
886
+ `
887
+ export const abc = 123;
888
+ export const def = "show me the money";
889
+ export default {};`
890
+ );
891
+
892
+ await runWrangler("publish index.js --dry-run --outdir out");
893
+
894
+ expect(
895
+ (
896
+ await esbuild.build({
897
+ entryPoints: [path.resolve("./out/index.js")],
898
+ metafile: true,
899
+ write: false,
900
+ })
901
+ ).metafile?.outputs["index.js"].exports
902
+ ).toMatchInlineSnapshot(`
903
+ Array [
904
+ "abc",
905
+ "def",
906
+ "default",
907
+ ]
908
+ `);
909
+ expect(std).toMatchInlineSnapshot(`
910
+ Object {
911
+ "debug": "",
912
+ "err": "",
913
+ "out": "--dry-run: exiting now.",
914
+ "warn": "",
915
+ }
916
+ `);
917
+ });
918
+
919
+ it("should not preserve exports on a service-worker format worker", async () => {
920
+ writeWranglerToml();
921
+ fs.writeFileSync(
922
+ "index.js",
923
+ `
924
+ export const abc = 123;
925
+ export const def = "show me the money";
926
+ addEventListener('fetch', event => {});`
927
+ );
928
+
929
+ await runWrangler("publish index.js --dry-run --outdir out --minify");
930
+
931
+ expect(
932
+ (
933
+ await esbuild.build({
934
+ entryPoints: [path.resolve("./out/index.js")],
935
+ metafile: true,
936
+ write: false,
937
+ })
938
+ ).metafile?.outputs["index.js"].exports
939
+ ).toMatchInlineSnapshot(`Array []`);
940
+
941
+ expect(std).toMatchInlineSnapshot(`
942
+ Object {
943
+ "debug": "",
944
+ "err": "",
945
+ "out": "--dry-run: exiting now.",
946
+ "warn": "â–² [WARNING] The entrypoint index.js has exports like an ES Module, but hasn't defined a default export like a module worker normally would. Building the worker using \\"service-worker\\" format...
947
+
948
+ ",
949
+ }
950
+ `);
951
+ });
952
+
881
953
  it("should be able to transpile entry-points in sub-directories (sw)", async () => {
882
954
  writeWranglerToml();
883
955
  writeWorkerSource({ basePath: "./src", type: "sw" });
package/src/bundle.ts CHANGED
@@ -66,7 +66,7 @@ export async function bundleWorker(
66
66
  absWorkingDir: entry.directory,
67
67
  outdir: destination,
68
68
  external: ["__STATIC_CONTENT_MANIFEST"],
69
- format: "esm",
69
+ format: entry.format === "modules" ? "esm" : "iife",
70
70
  target: "es2020",
71
71
  sourcemap: true,
72
72
  minify,
package/src/pages.tsx CHANGED
@@ -804,34 +804,30 @@ const createDeployment: CommandModule<
804
804
  return yargs
805
805
  .positional("directory", {
806
806
  type: "string",
807
- default: "functions",
808
- description: "The directory of Pages Functions",
807
+ demandOption: true,
808
+ description: "The directory of static files to upload",
809
809
  })
810
810
  .options({
811
811
  "project-name": {
812
812
  type: "string",
813
- description:
814
- "The name of the project you want to list deployments for",
813
+ description: "The name of the project you want to deploy to",
815
814
  },
816
815
  branch: {
817
816
  type: "string",
818
- description:
819
- "The branch of the project you want to list deployments for",
817
+ description: "The name of the branch you want to deploy to",
820
818
  },
821
819
  "commit-hash": {
822
820
  type: "string",
823
- description:
824
- "The branch of the project you want to list deployments for",
821
+ description: "The SHA to attach to this deployment",
825
822
  },
826
823
  "commit-message": {
827
824
  type: "string",
828
- description:
829
- "The branch of the project you want to list deployments for",
825
+ description: "The commit message to attach to this deployment",
830
826
  },
831
827
  "commit-dirty": {
832
828
  type: "boolean",
833
829
  description:
834
- "The branch of the project you want to list deployments for",
830
+ "Whether or not the workspace should be considered dirty for this deployment",
835
831
  },
836
832
  })
837
833
  .epilogue(pagesBetaWarning);
@@ -844,6 +840,10 @@ const createDeployment: CommandModule<
844
840
  commitMessage,
845
841
  commitDirty,
846
842
  }) => {
843
+ if (!directory) {
844
+ throw new FatalError("Must specify a directory.", 1);
845
+ }
846
+
847
847
  const config = getConfigCache<PagesConfigCache>(
848
848
  PAGES_CONFIG_CACHE_FILENAME
849
849
  );
@@ -104810,7 +104810,7 @@ var yargs_default = Yargs;
104810
104810
 
104811
104811
  // package.json
104812
104812
  var name = "wrangler";
104813
- var version = "2.0.1";
104813
+ var version = "2.0.2";
104814
104814
  var author = "wrangler@cloudflare.com";
104815
104815
  var description = "Command-line interface for all things Cloudflare Workers";
104816
104816
  var bin = {
@@ -108792,7 +108792,7 @@ async function bundleWorker(entry, destination, options) {
108792
108792
  absWorkingDir: entry.directory,
108793
108793
  outdir: destination,
108794
108794
  external: ["__STATIC_CONTENT_MANIFEST"],
108795
- format: "esm",
108795
+ format: entry.format === "modules" ? "esm" : "iife",
108796
108796
  target: "es2020",
108797
108797
  sourcemap: true,
108798
108798
  minify,
@@ -110423,28 +110423,28 @@ var createDeployment = {
110423
110423
  builder: (yargs) => {
110424
110424
  return yargs.positional("directory", {
110425
110425
  type: "string",
110426
- default: "functions",
110427
- description: "The directory of Pages Functions"
110426
+ demandOption: true,
110427
+ description: "The directory of static files to upload"
110428
110428
  }).options({
110429
110429
  "project-name": {
110430
110430
  type: "string",
110431
- description: "The name of the project you want to list deployments for"
110431
+ description: "The name of the project you want to deploy to"
110432
110432
  },
110433
110433
  branch: {
110434
110434
  type: "string",
110435
- description: "The branch of the project you want to list deployments for"
110435
+ description: "The name of the branch you want to deploy to"
110436
110436
  },
110437
110437
  "commit-hash": {
110438
110438
  type: "string",
110439
- description: "The branch of the project you want to list deployments for"
110439
+ description: "The SHA to attach to this deployment"
110440
110440
  },
110441
110441
  "commit-message": {
110442
110442
  type: "string",
110443
- description: "The branch of the project you want to list deployments for"
110443
+ description: "The commit message to attach to this deployment"
110444
110444
  },
110445
110445
  "commit-dirty": {
110446
110446
  type: "boolean",
110447
- description: "The branch of the project you want to list deployments for"
110447
+ description: "Whether or not the workspace should be considered dirty for this deployment"
110448
110448
  }
110449
110449
  }).epilogue(pagesBetaWarning);
110450
110450
  },
@@ -110456,6 +110456,9 @@ var createDeployment = {
110456
110456
  commitMessage,
110457
110457
  commitDirty
110458
110458
  }) => {
110459
+ if (!directory) {
110460
+ throw new FatalError("Must specify a directory.", 1);
110461
+ }
110459
110462
  const config = getConfigCache(PAGES_CONFIG_CACHE_FILENAME);
110460
110463
  const accountId = await requireAuth(config);
110461
110464
  projectName ??= config.project_name;