Skip to content

Commit e2d1683

Browse files
committed
add swc
1 parent 4f5feec commit e2d1683

File tree

4 files changed

+581
-3
lines changed

4 files changed

+581
-3
lines changed

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
SOURCE_FILES := index.ts
22
DIST_FILES := dist/index.js
33

4+
ifeq ($(shell sed --version 2>/dev/null | grep -q GNU && echo gnu),gnu)
5+
SED_INPLACE := sed -i
6+
else
7+
SED_INPLACE := sed -i ''
8+
endif
9+
410
node_modules: package-lock.json
511
npm install --no-save
612
@touch node_modules
@@ -26,11 +32,16 @@ test: node_modules build
2632
test-update: node_modules build
2733
npx vitest -u
2834

35+
.PHONY: hashbang
36+
hashbang:
37+
@$(SED_INPLACE) "1s/.*/\#\!\/usr\/bin\/env node/" dist/index.js
38+
2939
.PHONY: build
3040
build: node_modules $(DIST_FILES)
3141

3242
$(DIST_FILES): $(SOURCE_FILES) package-lock.json vite.config.ts
3343
npx vite build
44+
@$(MAKE) --no-print-directory hashbang
3445
chmod +x $(DIST_FILES)
3546

3647
.PHONY: publish

index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
#!/usr/bin/env node
1+
#!/usr/bin/env -S node --import @swc-node/register/esm-register
22
import {execa} from "execa";
33
import minimist from "minimist";
44
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"};
8+
import pkg from "./package.json" with {type: "json"};
99
import type {Opts as MinimistOpts} from "minimist";
1010

1111
export type SemverLevel = "patch" | "minor" | "major";
1212

13-
const packageVersion = version || "0.0.0";
13+
const packageVersion = pkg.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/, ""));

0 commit comments

Comments
 (0)