@ankhorage/devtools 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
3
|
import { createRequire } from 'node:module';
|
|
4
|
-
import { dirname, resolve } from 'node:path';
|
|
4
|
+
import { dirname, join, resolve } from 'node:path';
|
|
5
5
|
const require = createRequire(import.meta.url);
|
|
6
6
|
function isRecord(value) {
|
|
7
7
|
return typeof value === 'object' && value !== null;
|
|
8
8
|
}
|
|
9
|
+
function findPackageJsonPath(packageName) {
|
|
10
|
+
let currentDirectory = dirname(require.resolve(packageName));
|
|
11
|
+
while (currentDirectory !== dirname(currentDirectory)) {
|
|
12
|
+
const packageJsonPath = join(currentDirectory, 'package.json');
|
|
13
|
+
if (existsSync(packageJsonPath)) {
|
|
14
|
+
return packageJsonPath;
|
|
15
|
+
}
|
|
16
|
+
currentDirectory = dirname(currentDirectory);
|
|
17
|
+
}
|
|
18
|
+
throw new Error(`Could not find package metadata for ${packageName}.`);
|
|
19
|
+
}
|
|
9
20
|
function readPackageBinPath(packageName, binName) {
|
|
10
|
-
const packageJsonPath =
|
|
21
|
+
const packageJsonPath = findPackageJsonPath(packageName);
|
|
11
22
|
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
12
23
|
if (!isRecord(packageJson)) {
|
|
13
24
|
throw new Error(`Package metadata for ${packageName} is not an object.`);
|