Skip to content

Commit 6c5bc70

Browse files
authored
fix: init from dash using explicit usage model for standard accounts (#4521)
Co-authored-by: Zeb Piasecki <[email protected]>
1 parent a72f64c commit 6c5bc70

File tree

3 files changed

+86
-5
lines changed

3 files changed

+86
-5
lines changed

.changeset/heavy-cherries-fetch.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+
fix: init from dash specifying explicit usage model in wrangler.toml for standard users

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

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,7 +2647,6 @@ describe("init", () => {
26472647
triggers: {
26482648
crons: ["0 0 0 * * *"],
26492649
},
2650-
usage_model: "bundled",
26512650
vars: {
26522651
"ANOTHER-NAME": "thing-TEXT",
26532652
},
@@ -2701,11 +2700,13 @@ describe("init", () => {
27012700
expectedScriptName = "",
27022701
expectedEnvironment = "",
27032702
expectedCompatDate,
2703+
expectedStandardEnablement = true,
27042704
}: {
27052705
expectedAccountId: string;
27062706
expectedScriptName: string;
27072707
expectedEnvironment: string;
27082708
expectedCompatDate: string | undefined;
2709+
expectedStandardEnablement?: boolean;
27092710
}) {
27102711
msw.use(
27112712
rest.get(
@@ -2808,6 +2809,20 @@ describe("init", () => {
28082809
})
28092810
);
28102811
}
2812+
),
2813+
rest.get(
2814+
`*/accounts/:accountId/workers/standard`,
2815+
(req, res, ctx) => {
2816+
return res.once(
2817+
ctx.status(200),
2818+
ctx.json({
2819+
success: true,
2820+
errors: [],
2821+
messages: [],
2822+
result: { standard: expectedStandardEnablement },
2823+
})
2824+
);
2825+
}
28112826
)
28122827
);
28132828
}
@@ -2986,7 +3001,6 @@ describe("init", () => {
29863001
main = \\"src/index.ts\\"
29873002
compatibility_date = \\"1987-9-27\\"
29883003
route = \\"delta.quadrant\\"
2989-
usage_model = \\"bundled\\"
29903004
29913005
[[migrations]]
29923006
tag = \\"some-migration-tag\\"
@@ -3324,6 +3338,20 @@ describe("init", () => {
33243338
})
33253339
);
33263340
}
3341+
),
3342+
rest.get(
3343+
`*/accounts/:accountId/workers/standard`,
3344+
(req, res, ctx) => {
3345+
return res.once(
3346+
ctx.status(200),
3347+
ctx.json({
3348+
success: true,
3349+
errors: [],
3350+
messages: [],
3351+
result: { standard: true },
3352+
})
3353+
);
3354+
}
33273355
)
33283356
);
33293357

@@ -3358,7 +3386,6 @@ describe("init", () => {
33583386
triggers: {
33593387
crons: [],
33603388
},
3361-
usage_model: "bundled",
33623389
name: "isolinear-optical-chip",
33633390
tail_consumers: [{ service: "listener" }],
33643391
}),
@@ -3450,6 +3477,46 @@ describe("init", () => {
34503477
},
34513478
});
34523479
});
3480+
3481+
it("should have an explicit usage model for non-standard users", async () => {
3482+
mockSupportingDashRequests({
3483+
expectedAccountId: "LCARS",
3484+
expectedScriptName: "memory-crystal",
3485+
expectedEnvironment: "test",
3486+
expectedCompatDate: "1987-9-27",
3487+
expectedStandardEnablement: false,
3488+
});
3489+
setMockFetchDashScript(mockDashboardScript);
3490+
mockConfirm(
3491+
{
3492+
text: "Would you like to use git to manage this Worker?",
3493+
result: false,
3494+
},
3495+
{
3496+
text: "No package.json found. Would you like to create one?",
3497+
result: true,
3498+
},
3499+
{
3500+
text: "Would you like to use TypeScript?",
3501+
result: true,
3502+
}
3503+
);
3504+
3505+
await runWrangler(
3506+
"init isolinear-optical-chip --from-dash memory-crystal --no-delegate-c3"
3507+
);
3508+
3509+
expect(std.out).toContain("cd isolinear-optical-chip");
3510+
3511+
checkFiles({
3512+
items: {
3513+
"isolinear-optical-chip/wrangler.toml": wranglerToml({
3514+
...mockConfigExpected,
3515+
usage_model: "bundled",
3516+
}),
3517+
},
3518+
});
3519+
});
34533520
});
34543521
});
34553522
});

packages/wrangler/src/init.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ export type CronTriggersRes = {
122122
];
123123
};
124124

125+
export type StandardRes = {
126+
standard: boolean;
127+
reason: string;
128+
};
129+
125130
function isNpm(packageManager: PackageManager) {
126131
return packageManager.type === "npm";
127132
}
@@ -914,7 +919,7 @@ async function getWorkerConfig(
914919
environments: ServiceMetadataRes["environments"] | undefined;
915920
}
916921
): Promise<RawConfig> {
917-
const [bindings, routes, serviceEnvMetadata, cronTriggers] =
922+
const [bindings, routes, serviceEnvMetadata, cronTriggers, standard] =
918923
await Promise.all([
919924
fetchResult<WorkerMetadata["bindings"]>(
920925
`/accounts/${accountId}/workers/services/${fromDashScriptName}/environments/${defaultEnvironment}/bindings`
@@ -928,6 +933,7 @@ async function getWorkerConfig(
928933
fetchResult<CronTriggersRes>(
929934
`/accounts/${accountId}/workers/scripts/${fromDashScriptName}/schedules`
930935
),
936+
fetchResult<StandardRes>(`/accounts/${accountId}/workers/standard`),
931937
]).catch((e) => {
932938
throw new Error(
933939
`Error Occurred ${e}: Unable to fetch bindings, routes, or services metadata from the dashboard. Please try again later.`
@@ -960,7 +966,10 @@ async function getWorkerConfig(
960966
serviceEnvMetadata.script.compatibility_date ??
961967
new Date().toISOString().substring(0, 10),
962968
...routeOrRoutesToConfig,
963-
usage_model: serviceEnvMetadata.script.usage_model,
969+
usage_model:
970+
standard?.standard == true
971+
? undefined
972+
: serviceEnvMetadata.script.usage_model,
964973
placement:
965974
serviceEnvMetadata.script.placement_mode === "smart"
966975
? { mode: "smart" }

0 commit comments

Comments
 (0)