Skip to content

Commit b56881b

Browse files
committed
fix(lib/packages): version agnostic loading of package.json
1 parent 9df173b commit b56881b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/packages.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import pkgJson from '../package.json' assert { type: 'json' }
21
import { createRequire } from 'node:module';
3-
import path from 'node:path';
2+
import { dirname, join, resolve } from 'node:path';
3+
import { readFileSync } from 'node:fs';
4+
import { fileURLToPath } from 'node:url';
5+
6+
const __dirname = dirname(fileURLToPath(import.meta.url));
7+
const pkgJson = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf8'));
48

59
const packages = {
610
'0http': { hasRouter: true, package: '0http' },
@@ -39,7 +43,7 @@ const _choices = []
3943
Object.keys(packages).forEach(pkg => {
4044
if (!packages[pkg].version) {
4145
const module = pkgJson.dependencies[pkg] ? pkg : packages[pkg].package
42-
const version = require(path.resolve(`node_modules/${module}/package.json`)).version
46+
const version = require(resolve(`node_modules/${module}/package.json`)).version
4347
packages[pkg].version = version
4448
}
4549
_choices.push(pkg)

0 commit comments

Comments
 (0)