@gjsify/cli 0.1.13 → 0.1.15

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.
@@ -5,11 +5,17 @@ export interface NativePackage {
5
5
  prebuildsDir: string;
6
6
  }
7
7
  /**
8
- * Walk up the directory tree from `startDir` looking for a node_modules directory.
9
- * Returns all native packages found in the first node_modules encountered.
8
+ * Walk up the directory tree from `startDir` and merge native packages found
9
+ * in every `node_modules` encountered.
10
10
  *
11
- * Note: This intentionally stops at the first node_modules to match how Node.js
12
- * resolves packages from the perspective of the calling project.
11
+ * We keep walking past the first node_modules because yarn v4 / pnpm hoisting
12
+ * puts a project's direct deps in a local node_modules (often just `.cache/`
13
+ * or a subset) while hoisted transitive deps live in a root `node_modules`
14
+ * higher up. Node's own resolver also walks the chain — returning only the
15
+ * first hit would miss root-hoisted native packages.
16
+ *
17
+ * Deduplication: the first match for a given package name wins (closer
18
+ * node_modules shadows outer ones), matching Node.js resolution semantics.
13
19
  */
14
20
  export declare function detectNativePackages(startDir: string): NativePackage[];
15
21
  /**
@@ -85,27 +85,39 @@ function checkPackage(pkgDir, name, arch) {
85
85
  return { name, prebuildsDir };
86
86
  }
87
87
  /**
88
- * Walk up the directory tree from `startDir` looking for a node_modules directory.
89
- * Returns all native packages found in the first node_modules encountered.
88
+ * Walk up the directory tree from `startDir` and merge native packages found
89
+ * in every `node_modules` encountered.
90
90
  *
91
- * Note: This intentionally stops at the first node_modules to match how Node.js
92
- * resolves packages from the perspective of the calling project.
91
+ * We keep walking past the first node_modules because yarn v4 / pnpm hoisting
92
+ * puts a project's direct deps in a local node_modules (often just `.cache/`
93
+ * or a subset) while hoisted transitive deps live in a root `node_modules`
94
+ * higher up. Node's own resolver also walks the chain — returning only the
95
+ * first hit would miss root-hoisted native packages.
96
+ *
97
+ * Deduplication: the first match for a given package name wins (closer
98
+ * node_modules shadows outer ones), matching Node.js resolution semantics.
93
99
  */
94
100
  export function detectNativePackages(startDir) {
95
101
  const arch = nodeArchToLinuxArch(process.arch);
102
+ const merged = [];
103
+ const seen = new Set();
96
104
  let dir = resolve(startDir);
97
- // Walk up to filesystem root
98
105
  while (true) {
99
106
  const nodeModulesDir = join(dir, 'node_modules');
100
107
  if (existsSync(nodeModulesDir)) {
101
- return scanNodeModules(nodeModulesDir, arch);
108
+ for (const pkg of scanNodeModules(nodeModulesDir, arch)) {
109
+ if (seen.has(pkg.name))
110
+ continue;
111
+ seen.add(pkg.name);
112
+ merged.push(pkg);
113
+ }
102
114
  }
103
115
  const parent = resolve(dir, '..');
104
116
  if (parent === dir)
105
117
  break; // reached filesystem root
106
118
  dir = parent;
107
119
  }
108
- return [];
120
+ return merged;
109
121
  }
110
122
  /** Walk up from dir to find the nearest package.json. */
111
123
  function findNearestPackageJson(startDir) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/cli",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "CLI for Gjsify",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -23,16 +23,16 @@
23
23
  "cli"
24
24
  ],
25
25
  "dependencies": {
26
- "@gjsify/create-app": "^0.1.13",
27
- "@gjsify/esbuild-plugin-gjsify": "^0.1.13",
28
- "@gjsify/example-dom-adwaita-package-builder": "^0.1.13",
29
- "@gjsify/example-dom-canvas2d-fireworks": "^0.1.13",
30
- "@gjsify/example-dom-excalibur-jelly-jumper": "^0.1.13",
31
- "@gjsify/example-dom-three-geometry-teapot": "^0.1.13",
32
- "@gjsify/example-dom-three-postprocessing-pixel": "^0.1.13",
33
- "@gjsify/example-node-express-webserver": "^0.1.13",
34
- "@gjsify/node-polyfills": "^0.1.13",
35
- "@gjsify/web-polyfills": "^0.1.13",
26
+ "@gjsify/create-app": "^0.1.15",
27
+ "@gjsify/esbuild-plugin-gjsify": "^0.1.15",
28
+ "@gjsify/example-dom-adwaita-package-builder": "^0.1.15",
29
+ "@gjsify/example-dom-canvas2d-fireworks": "^0.1.15",
30
+ "@gjsify/example-dom-excalibur-jelly-jumper": "^0.1.15",
31
+ "@gjsify/example-dom-three-geometry-teapot": "^0.1.15",
32
+ "@gjsify/example-dom-three-postprocessing-pixel": "^0.1.15",
33
+ "@gjsify/example-node-express-webserver": "^0.1.15",
34
+ "@gjsify/node-polyfills": "^0.1.15",
35
+ "@gjsify/web-polyfills": "^0.1.15",
36
36
  "cosmiconfig": "^9.0.1",
37
37
  "esbuild": "^0.28.0",
38
38
  "get-tsconfig": "^4.14.0",
@@ -94,28 +94,39 @@ function checkPackage(pkgDir: string, name: string, arch: string): NativePackage
94
94
  }
95
95
 
96
96
  /**
97
- * Walk up the directory tree from `startDir` looking for a node_modules directory.
98
- * Returns all native packages found in the first node_modules encountered.
97
+ * Walk up the directory tree from `startDir` and merge native packages found
98
+ * in every `node_modules` encountered.
99
99
  *
100
- * Note: This intentionally stops at the first node_modules to match how Node.js
101
- * resolves packages from the perspective of the calling project.
100
+ * We keep walking past the first node_modules because yarn v4 / pnpm hoisting
101
+ * puts a project's direct deps in a local node_modules (often just `.cache/`
102
+ * or a subset) while hoisted transitive deps live in a root `node_modules`
103
+ * higher up. Node's own resolver also walks the chain — returning only the
104
+ * first hit would miss root-hoisted native packages.
105
+ *
106
+ * Deduplication: the first match for a given package name wins (closer
107
+ * node_modules shadows outer ones), matching Node.js resolution semantics.
102
108
  */
103
109
  export function detectNativePackages(startDir: string): NativePackage[] {
104
110
  const arch = nodeArchToLinuxArch(process.arch);
111
+ const merged: NativePackage[] = [];
112
+ const seen = new Set<string>();
105
113
  let dir = resolve(startDir);
106
114
 
107
- // Walk up to filesystem root
108
115
  while (true) {
109
116
  const nodeModulesDir = join(dir, 'node_modules');
110
117
  if (existsSync(nodeModulesDir)) {
111
- return scanNodeModules(nodeModulesDir, arch);
118
+ for (const pkg of scanNodeModules(nodeModulesDir, arch)) {
119
+ if (seen.has(pkg.name)) continue;
120
+ seen.add(pkg.name);
121
+ merged.push(pkg);
122
+ }
112
123
  }
113
124
  const parent = resolve(dir, '..');
114
125
  if (parent === dir) break; // reached filesystem root
115
126
  dir = parent;
116
127
  }
117
128
 
118
- return [];
129
+ return merged;
119
130
  }
120
131
 
121
132
  /** Walk up from dir to find the nearest package.json. */