pentect 0.0.55 → 0.0.57
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.
- package/package.json +1 -1
- package/packaging/npm/bin/pentect.js +29 -1
package/package.json
CHANGED
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { dirname, resolve } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
3
6
|
import { ensureInstalled } from '../install.js';
|
|
4
7
|
|
|
8
|
+
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../../..');
|
|
9
|
+
|
|
10
|
+
function localProjectRoot() {
|
|
11
|
+
const candidate = resolve(packageRoot, '../..');
|
|
12
|
+
try {
|
|
13
|
+
const metadata = JSON.parse(readFileSync(resolve(candidate, 'package.json'), 'utf8'));
|
|
14
|
+
const sections = ['dependencies', 'devDependencies', 'optionalDependencies'];
|
|
15
|
+
if (sections.some((section) => Object.hasOwn(metadata[section] || {}, 'pentect'))) {
|
|
16
|
+
return candidate;
|
|
17
|
+
}
|
|
18
|
+
} catch {
|
|
19
|
+
// A global package has no owning project package.json above node_modules.
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
5
24
|
let executable;
|
|
6
25
|
try {
|
|
7
26
|
executable = await ensureInstalled();
|
|
@@ -10,7 +29,16 @@ try {
|
|
|
10
29
|
process.exit(1);
|
|
11
30
|
}
|
|
12
31
|
|
|
13
|
-
const
|
|
32
|
+
const projectRoot = localProjectRoot();
|
|
33
|
+
const result = spawnSync(executable, process.argv.slice(2), {
|
|
34
|
+
stdio: 'inherit',
|
|
35
|
+
env: {
|
|
36
|
+
...process.env,
|
|
37
|
+
PENTECT_NPM_PACKAGE_ROOT: packageRoot,
|
|
38
|
+
PENTECT_NPM_SCOPE: projectRoot ? 'local' : 'global',
|
|
39
|
+
...(projectRoot ? { PENTECT_NPM_PROJECT_ROOT: projectRoot } : {}),
|
|
40
|
+
},
|
|
41
|
+
});
|
|
14
42
|
if (result.error) {
|
|
15
43
|
console.error(`pentect: ${result.error.message}`);
|
|
16
44
|
process.exitCode = 1;
|