Skip to content

Commit 55206b1

Browse files
committed
convert to typescript
1 parent 44ed8a8 commit 55206b1

File tree

7 files changed

+212
-997
lines changed

7 files changed

+212
-997
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ jobs:
66
strategy:
77
fail-fast: false
88
matrix:
9+
node: [20, 22]
910
os: [ubuntu-latest, macos-latest, windows-latest]
1011
runs-on: ${{matrix.os}}
1112
steps:
1213
- uses: actions/checkout@v4
1314
- uses: actions/setup-node@v4
1415
with:
15-
node-version: latest
16+
node-version: ${{matrix.node}}
1617
- run: make lint test

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ build: node_modules $(DIST_FILES)
3131

3232
$(DIST_FILES): $(SOURCE_FILES) package-lock.json vite.config.ts
3333
npx vite build
34+
chmod +x $(DIST_FILES)
3435

3536
.PHONY: publish
3637
publish: node_modules

versions.test.ts renamed to index.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import {execa} from "execa";
22
import {readFileSync} from "node:fs";
33
import {readFile, writeFile, unlink} from "node:fs/promises";
44
import {parse as parseToml} from "toml";
5-
import type {SemverLevel} from "./versions.ts";
5+
import type {SemverLevel} from "./index.ts";
66

7+
const distFile = "dist/index.js";
78
const pkgFile = new URL("package.json", import.meta.url);
89
const pyFile = new URL("fixtures/pyproject.toml", import.meta.url);
910
const testFile = new URL("testfile", import.meta.url);
@@ -31,7 +32,7 @@ afterAll(async () => {
3132

3233
test("version", async () => {
3334
const {version: expected} = JSON.parse(readFileSync(new URL("package.json", import.meta.url), "utf8"));
34-
const {stdout, exitCode} = await execa("node", ["dist/versions.js", "-v"]);
35+
const {stdout, exitCode} = await execa("node", [distFile, "-v"]);
3536
expect(stdout).toEqual(expected);
3637
expect(exitCode).toEqual(0);
3738
});
@@ -58,7 +59,7 @@ test("semver", () => {
5859
});
5960

6061
async function run(args: string) {
61-
return await execa(`node dist/versions.js ${args}`, {shell: true});
62+
return await execa(`node ${distFile} ${args}`, {shell: true});
6263
}
6364

6465
async function verify(version: string) {

versions.ts renamed to index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import {basename, dirname, join, relative} from "node:path";
55
import {cwd, exit as doExit} from "node:process";
66
import {platform} from "node:os";
77
import {readFileSync, writeFileSync, accessSync, truncateSync, statSync} from "node:fs";
8+
import {version} from "./package.json" with {type: "json"};
89
import type {Opts as MinimistOpts} from "minimist";
910

1011
export type SemverLevel = "patch" | "minor" | "major";
1112

12-
// @ts-ignore
13-
const packageVersion = import.meta.VERSION || "0.0.0";
13+
const packageVersion = version || "0.0.0";
1414
const esc = (str: string) => str.replace(/[|\\{}()[\]^$+*?.-]/g, "\\$&");
1515
const semverRe = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
1616
const isSemver = (str: string) => semverRe.test(str.replace(/^v/, ""));
@@ -229,7 +229,7 @@ function joinStrings(strings: (string | undefined)[], separator: string) {
229229
function exit(err?: Error | string | void) {
230230
if (err instanceof Error) {
231231
console.info(String(err.stack || err.message || err).trim());
232-
} else {
232+
} else if (err) {
233233
console.info(err);
234234
}
235235
doExit(err ? 1 : 0);

0 commit comments

Comments
 (0)