Skip to content

Commit 71b0fab

Browse files
fix: warn if the site.entry-point configuration is found during publishing
Also updates the message and adds a test for the error when there is no entry-point specified. Fixes #282
1 parent fe5dcfd commit 71b0fab

File tree

4 files changed

+129
-25
lines changed

4 files changed

+129
-25
lines changed
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
fix: warn if the `site.entry-point` configuration is found during publishing
6+
7+
Also updates the message and adds a test for the error when there is no entry-point specified.
8+
9+
Fixes #282

packages/wrangler/src/__tests__/publish.test.ts

+99-24
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe("publish", () => {
3737
});
3838

3939
it("should be able to use the `build.upload.main` config as the entry-point for ESM sources", async () => {
40-
writeWranglerToml("./index.js");
40+
writeWranglerToml({ main: "./index.js" });
4141
writeEsmWorkerSource();
4242
mockUploadWorkerRequest();
4343
mockSubDomainRequest();
@@ -105,6 +105,57 @@ describe("publish", () => {
105105
expect(stderr).toMatchInlineSnapshot(`""`);
106106
expect(error).toMatchInlineSnapshot(`undefined`);
107107
});
108+
109+
it("should warn if there is a `site.entry-point` configuration", async () => {
110+
writeWranglerToml({
111+
entryPoint: "./index.js",
112+
});
113+
writeEsmWorkerSource();
114+
mockUploadWorkerRequest();
115+
mockSubDomainRequest();
116+
117+
const { stdout, stderr, error, warnings } = await runWrangler(
118+
"publish ./index.js"
119+
);
120+
121+
expect(stripTimings(stdout)).toMatchInlineSnapshot(`
122+
"Uploaded
123+
test-name
124+
(TIMINGS)
125+
Deployed
126+
test-name
127+
(TIMINGS)
128+
129+
test-name.test-sub-domain.workers.dev"
130+
`);
131+
expect(stderr).toMatchInlineSnapshot(`""`);
132+
expect(error).toMatchInlineSnapshot(`undefined`);
133+
expect(warnings).toMatchInlineSnapshot(`
134+
"Deprecation notice: The \`site.entry-point\` config field is no longer used.
135+
The entry-point should be specified via the command line (e.g. \`wrangler publish path/to/script\`) or the \`build.upload.main\` config field.
136+
Please remove the \`site.entry-point\` field from the \`wrangler.toml\` file."
137+
`);
138+
});
139+
140+
it("should error if there is no entry-point specified", async () => {
141+
writeWranglerToml();
142+
writeEsmWorkerSource();
143+
mockUploadWorkerRequest();
144+
mockSubDomainRequest();
145+
146+
const { stdout, stderr, error } = await runWrangler("publish");
147+
148+
expect(stripTimings(stdout)).toMatchInlineSnapshot(`""`);
149+
expect(stderr).toMatchInlineSnapshot(`
150+
"Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler publish path/to/script\`) or the \`build.upload.main\` config field.
151+
152+
%s
153+
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
154+
`);
155+
expect(error).toMatchInlineSnapshot(
156+
`[Error: Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler publish path/to/script\`) or the \`build.upload.main\` config field.]`
157+
);
158+
});
108159
});
109160

110161
describe("asset upload", () => {
@@ -117,7 +168,7 @@ describe("publish", () => {
117168
title: "__test-name_sites_assets",
118169
id: "__test-name_sites_assets-id",
119170
};
120-
writeWranglerToml("./index.js", "assets");
171+
writeWranglerToml({ main: "./index.js", bucket: "assets" });
121172
writeEsmWorkerSource();
122173
writeAssets(assets);
123174
mockUploadWorkerRequest();
@@ -154,7 +205,7 @@ describe("publish", () => {
154205
title: "__test-name_sites_assets",
155206
id: "__test-name_sites_assets-id",
156207
};
157-
writeWranglerToml("./index.js", "assets");
208+
writeWranglerToml({ main: "./index.js", bucket: "assets" });
158209
writeEsmWorkerSource();
159210
writeAssets(assets);
160211
mockUploadWorkerRequest();
@@ -196,7 +247,7 @@ describe("publish", () => {
196247
title: "__test-name_sites_assets",
197248
id: "__test-name_sites_assets-id",
198249
};
199-
writeWranglerToml("./index.js", "assets");
250+
writeWranglerToml({ main: "./index.js", bucket: "assets" });
200251
writeEsmWorkerSource();
201252
writeAssets(assets);
202253
mockUploadWorkerRequest();
@@ -237,7 +288,7 @@ describe("publish", () => {
237288
title: "__test-name_sites_assets",
238289
id: "__test-name_sites_assets-id",
239290
};
240-
writeWranglerToml("./index.js", "assets");
291+
writeWranglerToml({ main: "./index.js", bucket: "assets" });
241292
writeEsmWorkerSource();
242293
writeAssets(assets);
243294
mockUploadWorkerRequest();
@@ -278,7 +329,11 @@ describe("publish", () => {
278329
title: "__test-name_sites_assets",
279330
id: "__test-name_sites_assets-id",
280331
};
281-
writeWranglerToml("./index.js", "assets", ["file-1.txt"]);
332+
writeWranglerToml({
333+
main: "./index.js",
334+
bucket: "assets",
335+
include: ["file-1.txt"],
336+
});
282337
writeEsmWorkerSource();
283338
writeAssets(assets);
284339
mockUploadWorkerRequest();
@@ -317,7 +372,11 @@ describe("publish", () => {
317372
title: "__test-name_sites_assets",
318373
id: "__test-name_sites_assets-id",
319374
};
320-
writeWranglerToml("./index.js", "assets", undefined, ["file-2.txt"]);
375+
writeWranglerToml({
376+
main: "./index.js",
377+
bucket: "assets",
378+
exclude: ["file-2.txt"],
379+
});
321380
writeEsmWorkerSource();
322381
writeAssets(assets);
323382
mockUploadWorkerRequest();
@@ -356,7 +415,11 @@ describe("publish", () => {
356415
title: "__test-name_sites_assets",
357416
id: "__test-name_sites_assets-id",
358417
};
359-
writeWranglerToml("./index.js", "assets", ["file-2.txt"]);
418+
writeWranglerToml({
419+
main: "./index.js",
420+
bucket: "assets",
421+
include: ["file-2.txt"],
422+
});
360423
writeEsmWorkerSource();
361424
writeAssets(assets);
362425
mockUploadWorkerRequest();
@@ -397,9 +460,11 @@ describe("publish", () => {
397460
title: "__test-name_sites_assets",
398461
id: "__test-name_sites_assets-id",
399462
};
400-
writeWranglerToml("./index.js", "assets", undefined, [
401-
"assets/file-1.txt",
402-
]);
463+
writeWranglerToml({
464+
main: "./index.js",
465+
bucket: "assets",
466+
exclude: ["assets/file-1.txt"],
467+
});
403468
writeEsmWorkerSource();
404469
writeAssets(assets);
405470
mockUploadWorkerRequest();
@@ -446,7 +511,7 @@ describe("publish", () => {
446511
title: "__test-name_sites_assets",
447512
id: "__test-name_sites_assets-id",
448513
};
449-
writeWranglerToml("./index.js", "assets");
514+
writeWranglerToml({ main: "./index.js", bucket: "assets" });
450515
writeEsmWorkerSource();
451516
writeAssets(assets);
452517
mockUploadWorkerRequest();
@@ -492,7 +557,7 @@ describe("publish", () => {
492557
title: "__test-name_sites_assets",
493558
id: "__test-name_sites_assets-id",
494559
};
495-
writeWranglerToml("./index.js", "assets");
560+
writeWranglerToml({ main: "./index.js", bucket: "assets" });
496561
writeEsmWorkerSource();
497562
writeAssets(assets);
498563
mockUploadWorkerRequest();
@@ -535,9 +600,11 @@ describe("publish", () => {
535600
title: "__test-name_sites_assets",
536601
id: "__test-name_sites_assets-id",
537602
};
538-
writeWranglerToml("./index.js", "assets", undefined, [
539-
"assets/file-1.txt",
540-
]);
603+
writeWranglerToml({
604+
main: "./index.js",
605+
bucket: "assets",
606+
exclude: ["assets/file-1.txt"],
607+
});
541608
writeEsmWorkerSource();
542609
writeAssets(assets);
543610
mockUploadWorkerRequest();
@@ -571,7 +638,7 @@ describe("publish", () => {
571638
title: "__test-name_sites_assets",
572639
id: "__test-name_sites_assets-id",
573640
};
574-
writeWranglerToml("./index.js", "assets");
641+
writeWranglerToml({ main: "./index.js", bucket: "assets" });
575642
writeEsmWorkerSource();
576643
writeAssets([longFilePathAsset]);
577644
mockUploadWorkerRequest();
@@ -598,22 +665,30 @@ describe("publish", () => {
598665
});
599666

600667
/** Write a mock wrangler.toml file to disk. */
601-
function writeWranglerToml(
602-
main?: string,
603-
bucket?: string,
604-
include?: string[],
605-
exclude?: string[]
606-
) {
668+
function writeWranglerToml({
669+
main,
670+
bucket,
671+
include,
672+
exclude,
673+
entryPoint,
674+
}: {
675+
main?: string;
676+
bucket?: string;
677+
include?: string[];
678+
exclude?: string[];
679+
entryPoint?: string;
680+
} = {}) {
607681
fs.writeFileSync(
608682
"./wrangler.toml",
609683
[
610684
`compatibility_date = "2022-01-12"`,
611685
`name = "test-name"`,
612686
main !== undefined ? `[build.upload]\nmain = "${main}"` : "",
613-
bucket || include || exclude ? "[site]" : "",
687+
bucket || include || exclude || entryPoint ? "[site]" : "",
614688
bucket !== undefined ? `bucket = "${bucket}"` : "",
615689
include !== undefined ? `include = ${JSON.stringify(include)}` : "",
616690
exclude !== undefined ? `exclude = ${JSON.stringify(exclude)}` : "",
691+
entryPoint !== undefined ? `entry-point = "${entryPoint}"` : "",
617692
].join("\n"),
618693
"utf-8"
619694
);

packages/wrangler/src/index.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,14 @@ export async function main(argv: string[]): Promise<void> {
494494
);
495495
}
496496

497+
if (config.site?.["entry-point"]) {
498+
console.warn(
499+
"Deprecation notice: The `site.entry-point` config field is no longer used.\n" +
500+
"The entry-point is specified via the command line (e.g. `wrangler dev path/to/script`).\n" +
501+
"Please remove the `site.entry-point` field from the `wrangler.toml` file."
502+
);
503+
}
504+
497505
if (!args.local) {
498506
// -- snip, extract --
499507
const loggedIn = await loginOrRefreshIfRequired();

packages/wrangler/src/publish.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,25 @@ export default async function publish(props: Props): Promise<void> {
7878
'You need to provide a name when publishing a worker. Either pass it as a cli arg with `--name <name>` or in your config file as `name = "<name>"`'
7979
);
8080

81+
if (config.site?.["entry-point"]) {
82+
console.warn(
83+
"Deprecation notice: The `site.entry-point` config field is no longer used.\n" +
84+
"The entry-point should be specified via the command line (e.g. `wrangler publish path/to/script`) or the `build.upload.main` config field.\n" +
85+
"Please remove the `site.entry-point` field from the `wrangler.toml` file."
86+
);
87+
}
88+
8189
let file: string;
8290
if (props.script) {
8391
// If the script name comes from the command line it is relative to the current working directory.
8492
file = path.resolve(props.script);
8593
} else {
8694
// If the script name comes from the config, then it is relative to the wrangler.toml file.
87-
assert(build?.upload?.main, "missing main file");
95+
if (build?.upload?.main === undefined) {
96+
throw new Error(
97+
"Missing entry-point: The entry-point should be specified via the command line (e.g. `wrangler publish path/to/script`) or the `build.upload.main` config field."
98+
);
99+
}
88100
file = path.resolve(path.dirname(__path__), build.upload.main);
89101
}
90102

0 commit comments

Comments
 (0)