Skip to content

Commit 3029b9a

Browse files
authored
fix: skip service tagging when no top-level name configured (#10658)
1 parent 31ec996 commit 3029b9a

File tree

4 files changed

+91
-1
lines changed

4 files changed

+91
-1
lines changed

.changeset/bumpy-islands-slide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Fixed an issue with service tags not being applied properly to Workers when the Wrangler configuration file did not include a top-level `name` property.

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13658,6 +13658,40 @@ export default{
1365813658
await runWrangler("deploy");
1365913659
});
1366013660

13661+
test("no top-level name", async ({ expect }) => {
13662+
mockUploadWorkerRequest({ expectedScriptName: "test-name-production" });
13663+
mockGetScriptWithTags(["some-tag", "cf:service=undefined"]);
13664+
13665+
writeWranglerConfig({
13666+
name: undefined,
13667+
main: "./index.js",
13668+
env: {
13669+
production: {
13670+
name: "test-name-production",
13671+
},
13672+
},
13673+
});
13674+
13675+
expect.assertions(2);
13676+
let requestCount = 0;
13677+
mockPatchScriptSettings(async ({ request }) => {
13678+
requestCount++;
13679+
if (requestCount === 2) {
13680+
await expect(request.json()).resolves.toEqual({
13681+
tags: ["some-tag"],
13682+
});
13683+
}
13684+
});
13685+
13686+
await runWrangler("deploy --env production");
13687+
13688+
expect(std.warn).toMatchInlineSnapshot(`
13689+
"▲ [WARNING] No top-level \`name\` has been defined in Wrangler configuration. Add a top-level \`name\` to group this Worker together with its sibling environments in the Cloudflare dashboard.
13690+
13691+
"
13692+
`);
13693+
});
13694+
1366113695
test("displays warning when error updating tags", async ({ expect }) => {
1366213696
mockUploadWorkerRequest({ expectedScriptName: "test-name-production" });
1366313697
mockGetScriptWithTags([

packages/wrangler/src/__tests__/versions/versions.upload.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,35 @@ describe("versions upload", () => {
628628
expect(tagsUpdateHandler.isUsed).toBeFalsy();
629629
});
630630

631+
test("no top-level name", async ({ expect }) => {
632+
mockGetScriptWithTags(["some-tag", "cf:service=undefined"]);
633+
634+
writeWranglerConfig({
635+
name: undefined,
636+
main: "./index.js",
637+
env: {
638+
production: {
639+
name: "test-name-production",
640+
},
641+
},
642+
});
643+
644+
expect.assertions(2);
645+
mockPatchScriptSettings(async ({ request }) => {
646+
await expect(request.json()).resolves.toEqual({
647+
tags: ["some-tag"],
648+
});
649+
});
650+
651+
await runWrangler("versions upload --env production");
652+
653+
expect(std.warn).toMatchInlineSnapshot(`
654+
"▲ [WARNING] No top-level \`name\` has been defined in Wrangler configuration. Add a top-level \`name\` to group this Worker together with its sibling environments in the Cloudflare dashboard.
655+
656+
"
657+
`);
658+
});
659+
631660
test("displays warning when error updating tags", async ({ expect }) => {
632661
mockGetScriptWithTags([
633662
"some-tag",

packages/wrangler/src/environments/index.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,29 @@ export async function applyServiceAndEnvironmentTags(
1818
) {
1919
tags ??= [];
2020
const env = config.targetEnvironment;
21-
const serviceTag = `${SERVICE_TAG_PREFIX}${config.topLevelName}`;
21+
const serviceName = config.topLevelName;
22+
23+
if (!serviceName) {
24+
logger.warn(
25+
"No top-level `name` has been defined in Wrangler configuration. Add a top-level `name` to group this Worker together with its sibling environments in the Cloudflare dashboard."
26+
);
27+
28+
if (tags.some((tag) => tag.startsWith(SERVICE_TAG_PREFIX))) {
29+
try {
30+
return await patchNonVersionedScriptSettings(
31+
config,
32+
accountId,
33+
scriptName,
34+
{
35+
tags: tags.filter((tag) => !tag.startsWith(SERVICE_TAG_PREFIX)),
36+
}
37+
);
38+
} catch {}
39+
}
40+
return;
41+
}
42+
43+
const serviceTag = `${SERVICE_TAG_PREFIX}${serviceName}`;
2244
const environmentTag = env ? `${ENVIRONMENT_TAG_PREFIX}${env}` : null;
2345

2446
const hasMissingServiceTag = !tags.includes(serviceTag);

0 commit comments

Comments
 (0)