Skip to content

Commit

Permalink
fix(cli): skip unsupported version of lock file
Browse files Browse the repository at this point in the history
  • Loading branch information
hasundue committed Aug 2, 2024
1 parent 76e56c2 commit 6442621
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 4 deletions.
55 changes: 55 additions & 0 deletions cli/fixtures/deno.lock.future

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ main.action(async function (options, ...source) {

const lock = options.lock === false
? undefined
: options.lock ?? await findLock();
: await findLock(options.lock);

source = source.length ? source : config ? [] : await findSource();

Expand Down
19 changes: 19 additions & 0 deletions cli/main_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ describe("CLI", () => {
);
});

it("should ignore an unsupported version of lockfile with a warning", async () => {
const { stdout, stderr } = await molt("--lock deno.lock.future");
assertEquals(
stdout,
dedent`
📦 @conventional-commits/parser ^0.3.0 → ^0.4.0
📦 deno.land/std 0.222.0 → 0.224.0
`,
);
assertEquals(
stderr,
dedent`
Unsupported lockfile version: '4'. Please update the lock file manually.
Collecting dependencies
Fetching updates
`,
);
});

it("should filter dependencies with `--only`", async () => {
const { stdout } = await molt("--only flag");
assertEquals(
Expand Down
16 changes: 13 additions & 3 deletions cli/src/files.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { VERSION } from "@molt/core/locks";
import { exists } from "@std/fs";
import { parse } from "@std/jsonc";

Expand All @@ -16,10 +17,19 @@ async function hasImports(config: string): Promise<boolean> {
return jsonc !== null && typeof jsonc === "object" && "imports" in jsonc;
}

export async function findLock() {
if (await exists("deno.lock")) {
return "deno.lock";
export async function findLock(path?: string) {
path ??= await exists("deno.lock") ? "deno.lock" : undefined;
if (!path) {
return;
}
const { version } = JSON.parse(await Deno.readTextFile(path));
if (version !== VERSION) {
console.warn(
`Unsupported lockfile version: '${version}'. Please update the lock file manually.`,
);
return;
}
return path;
}

export async function findSource() {
Expand Down

0 comments on commit 6442621

Please sign in to comment.