fix --version

This commit is contained in:
silverwind 2021-04-20 21:29:45 +02:00
parent 91205d54fa
commit cb76cecf2c
Signed by untrusted user: silverwind
GPG Key ID: 2E62B41C93869443
5 changed files with 20 additions and 12 deletions

3
.gitignore vendored

@ -2,6 +2,5 @@
/node_modules
/npm-debug.log*
/package-lock.json
/updates
/updates.cjs
/yarn-error.log
/dist

@ -14,17 +14,17 @@ unittest: node_modules
NODE_OPTIONS="--experimental-vm-modules --no-warnings" yarn -s run jest --color --watchAll
build: node_modules
yarn -s run ncc build updates.js -q -m -o dist
@mv dist/index.js dist/updates.cjs
@rm -rf dist/updates
@chmod +x dist/updates.cjs
yarn -s run ncc build updates.js -q -m -o .
@mv index.js updates.cjs
@rm -rf updates
@chmod +x updates.cjs
publish: node_modules
git push -u --tags origin master
npm publish
update: node_modules build
node dist/updates.cjs -cu
node updates.cjs -cu
@rm yarn.lock
@yarn -s
@touch node_modules

@ -5,7 +5,7 @@
"author": "silverwind",
"repository": "silverwind/updates",
"license": "BSD-2-Clause",
"bin": "./dist/updates.cjs",
"bin": "./updates.cjs",
"type": "module",
"engines": {
"node": ">= 12.20.0"
@ -24,7 +24,7 @@
"packages"
],
"files": [
"dist"
"updates.cjs"
],
"devDependencies": {
"@babel/core": "7.13.16",

@ -12,7 +12,7 @@ const {writeFile, readFile} = fs.promises;
const testFile = resolve(__dirname, "fixtures/test.json");
const testPkg = JSON.parse(readFileSync(testFile, "utf8"));
const testDir = tempy.directory();
const script = join(__dirname, "dist/updates.cjs");
const script = join(__dirname, "updates.cjs");
const dependencyTypes = [
"dependencies",
@ -119,6 +119,13 @@ test("simple", async () => {
expect(exitCode).toEqual(0);
});
test("version", async () => {
const {stdout, stderr, exitCode} = await execa(script, ["-v"]);
expect(stderr).toEqual("");
expect(stdout).toMatch(/^[0-9]+\.[0-9]+\.[0-9]+$/);
expect(exitCode).toEqual(0);
});
if (process.env.CI) {
test("global", async () => {
await execa("npm", ["i", "-g", "."]);

@ -12,7 +12,7 @@ import semver from "semver";
import textTable from "text-table";
import {cwd as cwdFn, stdout, argv, env, exit} from "process";
import {fromUrl} from "hosted-git-info";
import {join, dirname, resolve} from "path";
import {join, dirname} from "path";
import {lstatSync, readFileSync, truncateSync, writeFileSync, accessSync} from "fs";
import {platform} from "os";
import {fileURLToPath} from "url";
@ -173,7 +173,9 @@ if (args.help) {
}
if (args.version) {
const {version} = JSON.parse(readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), "package.json"), "utf8"));
const dir = dirname(fileURLToPath(import.meta.url));
const pkgJson = join(dir, "./package.json"); // resolve acts weirdly here in compiled file
const {version} = JSON.parse(readFileSync(pkgJson, "utf8"));
console.info(version);
exit(0);
}