Skip to content

Commit

Permalink
fix: fails to publish due to empty migrations (#1937)
Browse files Browse the repository at this point in the history
* fix: fails to publish due to empty migrations
The Durable Objects migrations will no longer show in the auto generated config file.
  • Loading branch information
JacobMGEvans committed Sep 28, 2022
1 parent b88ccf4 commit 905fce4
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .changeset/blue-pots-thank.md
@@ -0,0 +1,8 @@
---
"wrangler": patch
---

fix: fails to publish due to empty migrations
After this change, `wrangler init --from-dash` will not attempt to add durable object migrations to `wrangler.toml` for Workers that don't have durable objects.

fixes #1854
99 changes: 99 additions & 0 deletions packages/wrangler/src/__tests__/init.test.ts
Expand Up @@ -2608,6 +2608,105 @@ describe("init", () => {
).rejects.toThrowError();
});

it("should not inlcude migrations in config file when none are necessary", async () => {
const mockDate = "1988-08-07";
jest
.spyOn(Date.prototype, "toISOString")
.mockImplementation(() => `${mockDate}T00:00:00.000Z`);
const mockData = {
id: "memory-crystal",
default_environment: {
environment: "test",
created_on: "1988-08-07",
modified_on: "1988-08-07",
script: {
id: "memory-crystal",
tag: "test-tag",
etag: "some-etag",
handlers: [],
modified_on: "1988-08-07",
created_on: "1988-08-07",
usage_model: "bundled",
compatibility_date: "1988-08-07",
},
},
environments: [],
};

setMockResponse(
`/accounts/:accountId/workers/services/:scriptName`,
"GET",
() => mockData
);
setMockResponse(
`/accounts/:accountId/workers/services/:scriptName/environments/:environment/bindings`,
"GET",
() => []
);
setMockResponse(
`/accounts/:accountId/workers/services/:scriptName/environments/:environment/routes`,
"GET",
() => []
);
setMockResponse(
`/accounts/:accountId/workers/services/:scriptName/environments/:environment`,
"GET",
() => mockServiceMetadata.default_environment
);
setMockResponse(
`/accounts/:accountId/workers/scripts/:scriptName/schedules`,
"GET",
() => {
return {
schedules: [],
};
}
);

setMockFetchDashScript({
accountId: "LCARS",
fromDashScriptName: "isolinear-optical-chip",
environment: mockServiceMetadata.default_environment.environment,
mockResponse: mockDashboardScript,
});

mockConfirm(
{
text: "Would you like to use git to manage this Worker?",
result: false,
},
{
text: "Would you like to use TypeScript?",
result: true,
},
{
text: "No package.json found. Would you like to create one?",
result: true,
},
{
text: "Would you like to install the type definitions for Workers into your package.json?",
result: true,
}
);

await runWrangler("init --from-dash isolinear-optical-chip");

checkFiles({
items: {
"isolinear-optical-chip/wrangler.toml": wranglerToml({
compatibility_date: "1988-08-07",
env: {},
main: "src/index.ts",
triggers: {
crons: [],
},
usage_model: "bundled",
name: "isolinear-optical-chip",
}),
},
});
});

it("should not continue if no worker name is provided", async () => {
await expect(
runWrangler("init --from-dash")
Expand Down
16 changes: 10 additions & 6 deletions packages/wrangler/src/init.ts
Expand Up @@ -946,12 +946,16 @@ async function getWorkerConfig(
new Date().toISOString().substring(0, 10),
...routeOrRoutesToConfig,
usage_model: serviceEnvMetadata.script.usage_model,
migrations: [
{
tag: serviceEnvMetadata.script.migration_tag,
new_classes: durableObjectClassNames,
},
],
...(durableObjectClassNames.length
? {
migrations: [
{
tag: serviceEnvMetadata.script.migration_tag,
new_classes: durableObjectClassNames,
},
],
}
: {}),
triggers: {
crons: cronTriggers.schedules.map((scheduled) => scheduled.cron),
},
Expand Down

0 comments on commit 905fce4

Please sign in to comment.