Skip to content

Commit

Permalink
feat!: insert latest semver into unversioned deps
Browse files Browse the repository at this point in the history
  • Loading branch information
hasundue committed Oct 29, 2023
1 parent 7c26162 commit 01ef96a
Show file tree
Hide file tree
Showing 17 changed files with 729 additions and 158 deletions.
25 changes: 14 additions & 11 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { URI } from "./lib/uri.ts";
import { DependencyUpdate } from "./lib/update.ts";
import { FileUpdate } from "./lib/file.ts";
import { GitCommitSequence } from "./lib/git.ts";
import { parseSemVer, resolveLatestSemVer } from "./lib/dependency.ts";
import { parseSemVer, resolveLatestURL } from "./lib/dependency.ts";

const { gray, yellow, bold, cyan } = colors;

Expand Down Expand Up @@ -163,7 +163,7 @@ function _list(updates: DependencyUpdate[]) {
distinct(
list.map((u) => {
const source = URI.relative(u.map?.source ?? u.referrer);
return ` ${source} ` + gray(u.version.from);
return ` ${source} ` + gray(u.version.from ?? "");
}),
).forEach((line) => console.log(line));
}
Expand Down Expand Up @@ -328,6 +328,17 @@ function _formatPrefix(prefix: string | undefined) {
return prefix ? prefix.trimEnd() + " " : "";
}

async function _version() {
const version = parseSemVer(import.meta.url) ??
await $.progress("Fetching version info").with(async () => {
const url = await resolveLatestURL(
new URL("https://deno.land/x/molt/cli.ts"),
);
return url ? parseSemVer(url.href) : undefined;
}) ?? "unknown";
console.log(version);
}

const main = new Command()
.name("molt")
.description("A tool for updating dependencies in Deno projects")
Expand All @@ -337,15 +348,7 @@ const main = new Command()
.versionOption(
"-v, --version",
"Print version info.",
async function () {
const version = parseSemVer(import.meta.url) ??
await $.progress("Fetching version info").with(() => {
return resolveLatestSemVer(
new URL("https://deno.land/x/molt@0.0.0/cli.ts"),
);
}) ?? "unknown";
console.log(version);
},
_version,
)
.command("check", checkCommand)
.command("update", updateCommand);
Expand Down
5 changes: 3 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"tasks": {
"cache": "deno cache ./lib/*/*.ts --reload --lock",
"cache": "deno cache ./lib/*/*.ts --lock",
"lock": "deno task -q cache --lock-write && git add deno.lock",
"check": "deno check ./*.ts ./lib/*/*.ts",
"check": "deno check ./*.ts ./lib/**/*.ts",
"test": "deno test -A --no-check",
"test:update": "deno task -q test -- --update",
"dev": "deno fmt && deno lint && deno task lock && deno task -q check && deno task -q test",
"install": "deno install -f --name molt --allow-env --allow-read --allow-net --allow-write=. --allow-run=git,deno cli.ts",
"run:molt": "deno run --allow-env --allow-read --allow-write --allow-net=deno.land,registry.npmjs.org --allow-run=git,deno ./cli.ts",
Expand Down
40 changes: 40 additions & 0 deletions deno.lock

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

51 changes: 51 additions & 0 deletions lib/__snapshots__/file_test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
export const snapshot = {};

snapshot[`writeAll > direct import 1`] = `
'import { VERSION } from "https://deno.land/std@0.204.0/version.ts";
import { createGraph } from "https://deno.land/x/deno_graph@0.59.1/mod.ts";
import { emojify } from "npm:node-emoji@2.1.0";
import { noop } from "./lib.ts";
'
`;

snapshot[`writeAll > direct import 2`] = `
'import { VERSION } from "https://deno.land/std@0.204.0/version.ts";
export const noop = () => {};
'
`;

snapshot[`writeAll > import map 1`] = `
'{
"imports": {
"std/": "https://deno.land/std@0.200.0/",
"deno_graph": "https://deno.land/x/deno_graph@0.59.1/mod.ts",
"node-emoji": "npm:node-emoji@2.1.0",
"/": "./"
}
}'
`;

snapshot[`writeAll > import map 2`] = `
'import { VERSION } from "https://deno.land/std@0.204.0/version.ts";
export const noop = () => {};
'
`;

snapshot[`writeAll > import map with no resolve 1`] = `
'import {} from "https://deno.land/std@0.204.0/version.ts";
'
`;

snapshot[`writeAll > unversioned specifiers 1`] = `
'import { VERSION } from "https://deno.land/std@0.204.0/version.ts";
import { createGraph } from "https://deno.land/x/deno_graph@0.59.1/mod.ts";
import { emojify } from "npm:node-emoji@2.1.0";
import { noop } from "./lib.ts";
'
`;

snapshot[`writeAll > unversioned specifiers 2`] = `
'import { VERSION } from "https://deno.land/std@0.204.0/version.ts";
export const noop = () => {};
'
`;
40 changes: 40 additions & 0 deletions lib/__snapshots__/git_test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export const snapshot = {};

snapshot[`commitAll() > no grouping 1`] = `
FileSystemFake(2) [Map] {
"file:///home/shun/molt/test/fixtures/direct-import/lib.ts" => 'import { VERSION } from "https://deno.land/std@0.204.0/version.ts";
export const noop = () => {};
',
"file:///home/shun/molt/test/fixtures/direct-import/mod.ts" => 'import { VERSION } from "https://deno.land/std@0.204.0/version.ts";
import { createGraph } from "https://deno.land/x/deno_graph@0.59.1/mod.ts";
import { emojify } from "npm:node-emoji@2.1.0";
import { noop } from "./lib.ts";
',
}
`;

snapshot[`commitAll() > group by dependency name 1`] = `
FileSystemFake(2) [Map] {
"file:///home/shun/molt/test/fixtures/direct-import/lib.ts" => 'import { VERSION } from "https://deno.land/std@0.204.0/version.ts";
export const noop = () => {};
',
"file:///home/shun/molt/test/fixtures/direct-import/mod.ts" => 'import { VERSION } from "https://deno.land/std@0.200.0/version.ts";
import { createGraph } from "https://deno.land/x/deno_graph@0.50.0/mod.ts";
import { emojify } from "npm:node-emoji@2.1.0";
import { noop } from "./lib.ts";
',
}
`;

snapshot[`commitAll() > group by module (file) name 1`] = `
FileSystemFake(2) [Map] {
"file:///home/shun/molt/test/fixtures/direct-import/lib.ts" => 'import { VERSION } from "https://deno.land/std@0.204.0/version.ts";
export const noop = () => {};
',
"file:///home/shun/molt/test/fixtures/direct-import/mod.ts" => 'import { VERSION } from "https://deno.land/std@0.204.0/version.ts";
import { createGraph } from "https://deno.land/x/deno_graph@0.59.1/mod.ts";
import { emojify } from "npm:node-emoji@2.1.0";
import { noop } from "./lib.ts";
',
}
`;
Loading

0 comments on commit 01ef96a

Please sign in to comment.