Skip to content

Commit

Permalink
fix: warn if the site.entry-point configuration is found during pub…
Browse files Browse the repository at this point in the history
…lishing

Fixes #282
  • Loading branch information
petebacondarwin committed Jan 24, 2022
1 parent b63efe6 commit 80833a2
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 24 deletions.
7 changes: 7 additions & 0 deletions .changeset/lovely-elephants-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

fix: warn if the `site.entry-point` configuration is found during publishing

Fixes #282
101 changes: 77 additions & 24 deletions packages/wrangler/src/__tests__/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe("publish", () => {
});

it("should be able to use the `build.upload.main` config as the entry-point for ESM sources", async () => {
writeWranglerToml("./index.js");
writeWranglerToml({ main: "./index.js" });
writeEsmWorkerSource();
mockUploadWorkerRequest();
mockSubDomainRequest();
Expand All @@ -57,6 +57,35 @@ describe("publish", () => {
expect(stderr).toMatchInlineSnapshot(`""`);
expect(error).toMatchInlineSnapshot(`undefined`);
});

it("should warn if there is a `site.entry-point` configuration", async () => {
writeWranglerToml({
entryPoint: "./index.js",
});
writeEsmWorkerSource();
mockUploadWorkerRequest();
mockSubDomainRequest();

const { stdout, stderr, error, warnings } = await runWrangler(
"publish ./index.js"
);

expect(stripTimings(stdout)).toMatchInlineSnapshot(`
"Uploaded
test-name
(TIMINGS)
Deployed
test-name
(TIMINGS)
test-name.test-sub-domain.workers.dev"
`);
expect(stderr).toMatchInlineSnapshot(`""`);
expect(error).toMatchInlineSnapshot(`undefined`);
expect(warnings).toMatchInlineSnapshot(
`"Deprecation notice: The \`site.entry-point\` config field is no longer used. Please remove it from the \`wrangler.toml\` file."`
);
});
});

describe("asset upload", () => {
Expand All @@ -69,7 +98,7 @@ describe("publish", () => {
title: "__test-name_sites_assets",
id: "__test-name_sites_assets-id",
};
writeWranglerToml("./index.js", "assets");
writeWranglerToml({ main: "./index.js", bucket: "assets" });
writeEsmWorkerSource();
writeAssets(assets);
mockUploadWorkerRequest();
Expand Down Expand Up @@ -106,7 +135,7 @@ describe("publish", () => {
title: "__test-name_sites_assets",
id: "__test-name_sites_assets-id",
};
writeWranglerToml("./index.js", "assets");
writeWranglerToml({ main: "./index.js", bucket: "assets" });
writeEsmWorkerSource();
writeAssets(assets);
mockUploadWorkerRequest();
Expand Down Expand Up @@ -148,7 +177,7 @@ describe("publish", () => {
title: "__test-name_sites_assets",
id: "__test-name_sites_assets-id",
};
writeWranglerToml("./index.js", "assets");
writeWranglerToml({ main: "./index.js", bucket: "assets" });
writeEsmWorkerSource();
writeAssets(assets);
mockUploadWorkerRequest();
Expand Down Expand Up @@ -189,7 +218,7 @@ describe("publish", () => {
title: "__test-name_sites_assets",
id: "__test-name_sites_assets-id",
};
writeWranglerToml("./index.js", "assets");
writeWranglerToml({ main: "./index.js", bucket: "assets" });
writeEsmWorkerSource();
writeAssets(assets);
mockUploadWorkerRequest();
Expand Down Expand Up @@ -230,7 +259,11 @@ describe("publish", () => {
title: "__test-name_sites_assets",
id: "__test-name_sites_assets-id",
};
writeWranglerToml("./index.js", "assets", ["file-1.txt"]);
writeWranglerToml({
main: "./index.js",
bucket: "assets",
include: ["file-1.txt"],
});
writeEsmWorkerSource();
writeAssets(assets);
mockUploadWorkerRequest();
Expand Down Expand Up @@ -269,7 +302,11 @@ describe("publish", () => {
title: "__test-name_sites_assets",
id: "__test-name_sites_assets-id",
};
writeWranglerToml("./index.js", "assets", undefined, ["file-2.txt"]);
writeWranglerToml({
main: "./index.js",
bucket: "assets",
exclude: ["file-2.txt"],
});
writeEsmWorkerSource();
writeAssets(assets);
mockUploadWorkerRequest();
Expand Down Expand Up @@ -308,7 +345,11 @@ describe("publish", () => {
title: "__test-name_sites_assets",
id: "__test-name_sites_assets-id",
};
writeWranglerToml("./index.js", "assets", ["file-2.txt"]);
writeWranglerToml({
main: "./index.js",
bucket: "assets",
include: ["file-2.txt"],
});
writeEsmWorkerSource();
writeAssets(assets);
mockUploadWorkerRequest();
Expand Down Expand Up @@ -349,9 +390,11 @@ describe("publish", () => {
title: "__test-name_sites_assets",
id: "__test-name_sites_assets-id",
};
writeWranglerToml("./index.js", "assets", undefined, [
"assets/file-1.txt",
]);
writeWranglerToml({
main: "./index.js",
bucket: "assets",
exclude: ["assets/file-1.txt"],
});
writeEsmWorkerSource();
writeAssets(assets);
mockUploadWorkerRequest();
Expand Down Expand Up @@ -398,7 +441,7 @@ describe("publish", () => {
title: "__test-name_sites_assets",
id: "__test-name_sites_assets-id",
};
writeWranglerToml("./index.js", "assets");
writeWranglerToml({ main: "./index.js", bucket: "assets" });
writeEsmWorkerSource();
writeAssets(assets);
mockUploadWorkerRequest();
Expand Down Expand Up @@ -444,7 +487,7 @@ describe("publish", () => {
title: "__test-name_sites_assets",
id: "__test-name_sites_assets-id",
};
writeWranglerToml("./index.js", "assets");
writeWranglerToml({ main: "./index.js", bucket: "assets" });
writeEsmWorkerSource();
writeAssets(assets);
mockUploadWorkerRequest();
Expand Down Expand Up @@ -487,9 +530,11 @@ describe("publish", () => {
title: "__test-name_sites_assets",
id: "__test-name_sites_assets-id",
};
writeWranglerToml("./index.js", "assets", undefined, [
"assets/file-1.txt",
]);
writeWranglerToml({
main: "./index.js",
bucket: "assets",
exclude: ["assets/file-1.txt"],
});
writeEsmWorkerSource();
writeAssets(assets);
mockUploadWorkerRequest();
Expand Down Expand Up @@ -523,7 +568,7 @@ describe("publish", () => {
title: "__test-name_sites_assets",
id: "__test-name_sites_assets-id",
};
writeWranglerToml("./index.js", "assets");
writeWranglerToml({ main: "./index.js", bucket: "assets" });
writeEsmWorkerSource();
writeAssets([longFilePathAsset]);
mockUploadWorkerRequest();
Expand All @@ -550,22 +595,30 @@ describe("publish", () => {
});

/** Write a mock wrangler.toml file to disk. */
function writeWranglerToml(
main?: string,
bucket?: string,
include?: string[],
exclude?: string[]
) {
function writeWranglerToml({
main,
bucket,
include,
exclude,
entryPoint,
}: {
main?: string;
bucket?: string;
include?: string[];
exclude?: string[];
entryPoint?: string;
} = {}) {
fs.writeFileSync(
"./wrangler.toml",
[
`compatibility_date = "2022-01-12"`,
`name = "test-name"`,
main !== undefined ? `[build.upload]\nmain = "${main}"` : "",
bucket || include || exclude ? "[site]" : "",
bucket || include || exclude || entryPoint ? "[site]" : "",
bucket !== undefined ? `bucket = "${bucket}"` : "",
include !== undefined ? `include = ${JSON.stringify(include)}` : "",
exclude !== undefined ? `exclude = ${JSON.stringify(exclude)}` : "",
entryPoint !== undefined ? `entry-point = "${entryPoint}"` : "",
].join("\n"),
"utf-8"
);
Expand Down
6 changes: 6 additions & 0 deletions packages/wrangler/src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ export default async function publish(props: Props): Promise<void> {
file = path.resolve(path.dirname(__path__), build.upload.main);
}

if (config.site?.["entry-point"]) {
console.warn(
"Deprecation notice: The `site.entry-point` config field is no longer used. Please remove it from the `wrangler.toml` file."
);
}

if (props.legacyEnv) {
scriptName += props.env ? `-${props.env}` : "";
}
Expand Down

0 comments on commit 80833a2

Please sign in to comment.