From f14f98450a61ddf9ec2a63380e31db194d292508 Mon Sep 17 00:00:00 2001 From: Scott Doxey Date: Tue, 7 May 2024 15:20:39 -0400 Subject: [PATCH] Fixed issue with getting version from package.json --- bin/index.ts | 19 ++++--------------- tsconfig.json | 1 + 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/bin/index.ts b/bin/index.ts index 4369763..e9b85ed 100755 --- a/bin/index.ts +++ b/bin/index.ts @@ -1,8 +1,4 @@ -#!/usr/bin/env node - -import { readFile } from 'node:fs/promises'; -import { dirname, join } from 'node:path'; -import { fileURLToPath } from 'node:url'; +#!/usr/bin/env node --no-warnings import 'dotenv/config'; @@ -13,21 +9,14 @@ import parseCmdArgs from 'parse-cmd-args'; import { buildFiles } from '../src/build.js'; import { copyFiles } from '../src/copy.js'; +import pkg from '../package.json' assert { type: 'json' }; + const args = parseCmdArgs(null, { requireUserInput: false }); if (args.flags['--version'] || args.flags['-v']) { - process.stdout.write( - `${ - JSON.parse( - await readFile( - join(dirname(fileURLToPath(import.meta.url)), '../package.json'), - 'utf8' - ) - ).version - }\n` - ); + process.stdout.write(`${pkg.version}\n`); process.exit(); } else if (args.flags['--help'] || args.flags['-h']) { process.stdout.write(`Usage: onlybuild [options] diff --git a/tsconfig.json b/tsconfig.json index d5f24b3..480a1bf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,6 +4,7 @@ "module": "NodeNext", "esModuleInterop": true, "moduleResolution": "NodeNext", + "resolveJsonModule": true, "declaration": true, "outDir": "./dist", "strict": true