Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fix-corrupt-manifest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@taskless/cli": patch
---

Fix crash during init when `.taskless/taskless.json` contains corrupt or unparseable JSON. The CLI now treats a corrupt manifest the same as a missing one, allowing migrations to re-run and rewrite it.

Add `module` and `exports` fields to package.json to ensure ESM resolution works correctly on older Node versions or when package.json resolution is incomplete.
6 changes: 6 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
"typecheck": "tsc --noEmit"
},
"type": "module",
"module": "./dist/index.js",
"exports": {
".": {
"import": "./dist/index.js"
}
},
"files": [
"dist"
],
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/filesystem/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ async function readManifest(directory: string): Promise<TasklessManifest> {
) {
return { version: 0 };
}
// Treat corrupt/unparseable manifest as version 0 so migrations re-run
if (error instanceof SyntaxError) {
return { version: 0 };
}
throw error;
}
}
Expand Down
21 changes: 21 additions & 0 deletions packages/cli/test/bootstrap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,27 @@ describe("ensureTasklessDirectory", () => {
expect(rulesStat.isDirectory()).toBe(true);
});

it("recovers from a corrupt taskless.json manifest", async () => {
const tasklessDirectory = join(temporaryDirectory, ".taskless");
await mkdir(tasklessDirectory, { recursive: true });

// Write corrupt JSON that would cause "unexpected token *"
await writeFile(
join(tasklessDirectory, "taskless.json"),
"***not-json***",
"utf8"
);

// Should not throw — treats corrupt manifest as version 0
await ensureTasklessDirectory(temporaryDirectory);

// Manifest should be rewritten with a valid version
const manifest = JSON.parse(
await readFile(join(tasklessDirectory, "taskless.json"), "utf8")
) as { version: number };
expect(manifest.version).toBeGreaterThan(0);
});

it("is idempotent — re-running after completion succeeds without errors", async () => {
await ensureTasklessDirectory(temporaryDirectory);
await ensureTasklessDirectory(temporaryDirectory);
Expand Down
Loading