node-modules-tools 0.0.2 → 0.0.4

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.
@@ -2,12 +2,28 @@ import { relative, dirname } from 'pathe';
2
2
  import { x } from 'tinyexec';
3
3
 
4
4
  async function resolveRoot(options) {
5
- const raw = await x("pnpm", ["root", "-w"], { throwOnError: true, nodeOptions: { cwd: options.cwd } });
6
- return dirname(raw.stdout.trim());
5
+ let raw;
6
+ try {
7
+ raw = (await x("pnpm", ["root", "-w"], { throwOnError: true, nodeOptions: { cwd: options.cwd } })).stdout.trim();
8
+ } catch {
9
+ try {
10
+ raw = (await x("pnpm", ["root"], { throwOnError: true, nodeOptions: { cwd: options.cwd } })).stdout.trim();
11
+ } catch (err) {
12
+ console.error("Failed to resolve root directory");
13
+ console.error(err);
14
+ }
15
+ }
16
+ return raw ? dirname(raw) : options.cwd;
7
17
  }
8
18
  async function getPnpmVersion(options) {
9
- const raw = await x("pnpm", ["--version"], { throwOnError: true, nodeOptions: { cwd: options.cwd } });
10
- return raw.stdout.trim();
19
+ try {
20
+ const raw = await x("pnpm", ["--version"], { throwOnError: true, nodeOptions: { cwd: options.cwd } });
21
+ return raw.stdout.trim();
22
+ } catch (err) {
23
+ console.error("Failed to get pnpm version");
24
+ console.error(err);
25
+ return undefined;
26
+ }
11
27
  }
12
28
  async function getDependenciesTree(options) {
13
29
  const args = ["ls", "--json", "--no-optional", "--depth", String(options.depth)];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "node-modules-tools",
3
3
  "type": "module",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "description": "Tools for inspecting node_modules",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",