@gjsify/cli 0.5.1 → 0.6.0

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.
@@ -78,6 +78,20 @@ export declare function runWatch(finalOpts: BundlerOptions): Promise<RolldownWat
78
78
  */
79
79
  export declare function runBundle(finalOpts: BundlerOptions): Promise<RolldownOutput>;
80
80
  export declare function shouldUseNative(): Promise<boolean>;
81
+ /**
82
+ * Walk parent directories from `startDir` (and optionally a second anchor
83
+ * `bundleDir`) looking for `node_modules/@gjsify/rolldown-native/package.json`.
84
+ * Returns the package root path (parent of its `package.json`) on the first
85
+ * hit, or null when nothing is found within 12 levels.
86
+ *
87
+ * This is a raw `existsSync`-based probe that bypasses both `createRequire`
88
+ * (whose GJS polyfill may not walk the full chain when anchored inside a
89
+ * sub-package dir) and `findWorkspaceRoot` (which requires `discoverWorkspaces`
90
+ * to map the sub-package to a workspace member, a step that can fail under
91
+ * the GJS polyfill stack). Used by `tryLoadNative` as an explicit fallback
92
+ * when the standard `resolveNpmPackage` anchors miss.
93
+ */
94
+ export declare function findRolldownNativeDir(startDir: string, bundleDir?: string): string | null;
81
95
  /**
82
96
  * Sanitize fields the JSON encoder can't ship to the Rust deserializer.
83
97
  *
@@ -27,7 +27,7 @@
27
27
  // at hook-call time. The current gjsify plugin set doesn't use any
28
28
  // of those, so we don't gate on it; future incompatibilities surface
29
29
  // as build errors rather than silent wrong behavior.
30
- import { promises as fs } from 'node:fs';
30
+ import { promises as fs, existsSync } from 'node:fs';
31
31
  import * as path from 'node:path';
32
32
  import { createRequire } from 'node:module';
33
33
  import { pathToFileURL } from 'node:url';
@@ -199,6 +199,39 @@ export async function shouldUseNative() {
199
199
  const native = await tryLoadNative();
200
200
  return native !== null;
201
201
  }
202
+ /**
203
+ * Walk parent directories from `startDir` (and optionally a second anchor
204
+ * `bundleDir`) looking for `node_modules/@gjsify/rolldown-native/package.json`.
205
+ * Returns the package root path (parent of its `package.json`) on the first
206
+ * hit, or null when nothing is found within 12 levels.
207
+ *
208
+ * This is a raw `existsSync`-based probe that bypasses both `createRequire`
209
+ * (whose GJS polyfill may not walk the full chain when anchored inside a
210
+ * sub-package dir) and `findWorkspaceRoot` (which requires `discoverWorkspaces`
211
+ * to map the sub-package to a workspace member, a step that can fail under
212
+ * the GJS polyfill stack). Used by `tryLoadNative` as an explicit fallback
213
+ * when the standard `resolveNpmPackage` anchors miss.
214
+ */
215
+ export function findRolldownNativeDir(startDir, bundleDir) {
216
+ const relPath = path.join('node_modules', '@gjsify', 'rolldown-native', 'package.json');
217
+ const dirsToSearch = [startDir];
218
+ if (bundleDir && bundleDir !== startDir)
219
+ dirsToSearch.push(bundleDir);
220
+ for (const anchor of dirsToSearch) {
221
+ let dir = anchor;
222
+ for (let i = 0; i < 12; i++) {
223
+ const candidate = path.join(dir, relPath);
224
+ if (existsSync(candidate)) {
225
+ return path.join(dir, 'node_modules', '@gjsify', 'rolldown-native');
226
+ }
227
+ const parent = path.resolve(dir, '..');
228
+ if (parent === dir)
229
+ break;
230
+ dir = parent;
231
+ }
232
+ }
233
+ return null;
234
+ }
202
235
  async function tryLoadNative() {
203
236
  if (_nativeProbe)
204
237
  return _nativeProbe;
@@ -229,7 +262,36 @@ async function tryLoadNative() {
229
262
  // install dir, anchoring solely at `import.meta.url`
230
263
  // misses node_modules layouts where the user's cwd
231
264
  // or the workspace root carries the package instead.
232
- const resolved = resolveNpmPackage(specifier, { bundleUrl: import.meta.url }) ??
265
+ //
266
+ // When `resolveNpmPackage`'s standard anchors all miss
267
+ // (e.g. invoked from a package subdir whose own
268
+ // node_modules doesn't carry the optional-peer
269
+ // `@gjsify/rolldown-native`), fall back to a raw
270
+ // `existsSync`-based parent-dir walk — it bypasses
271
+ // both the GJS `createRequire` polyfill's walk
272
+ // limitations and `findWorkspaceRoot`'s dependency on
273
+ // `discoverWorkspaces`, both of which can fail to map a
274
+ // sub-package dir up to the hoisted workspace root.
275
+ const bundleDir = path.dirname(new URL(import.meta.url).pathname);
276
+ const resolvedFromNpm = resolveNpmPackage(specifier, { bundleUrl: import.meta.url });
277
+ const resolvedFromFs = resolvedFromNpm
278
+ ? null
279
+ : (() => {
280
+ const pkgDir = findRolldownNativeDir(process.cwd(), bundleDir);
281
+ if (!pkgDir)
282
+ return null;
283
+ // Resolve the package entry via createRequire anchored
284
+ // inside the found package dir so we get the correct
285
+ // exports-map / main field entry point.
286
+ try {
287
+ return createRequire(pathToFileURL(path.join(pkgDir, '__gjsify_resolve__.js')).href).resolve(specifier);
288
+ }
289
+ catch {
290
+ return null;
291
+ }
292
+ })();
293
+ const resolved = resolvedFromNpm ??
294
+ resolvedFromFs ??
233
295
  createRequire(import.meta.url).resolve(specifier);
234
296
  target = pathToFileURL(resolved).href;
235
297
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/cli",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "CLI for Gjsify",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -120,19 +120,19 @@
120
120
  "cli"
121
121
  ],
122
122
  "dependencies": {
123
- "@gjsify/buffer": "^0.5.1",
124
- "@gjsify/create-app": "^0.5.1",
125
- "@gjsify/node-globals": "^0.5.1",
126
- "@gjsify/node-polyfills": "^0.5.1",
127
- "@gjsify/npm-registry": "^0.5.1",
128
- "@gjsify/resolve-npm": "^0.5.1",
129
- "@gjsify/rolldown-plugin-gjsify": "^0.5.1",
130
- "@gjsify/rolldown-plugin-pnp": "^0.5.1",
131
- "@gjsify/semver": "^0.5.1",
132
- "@gjsify/tar": "^0.5.1",
133
- "@gjsify/tsc": "^0.5.1",
134
- "@gjsify/web-polyfills": "^0.5.1",
135
- "@gjsify/workspace": "^0.5.1",
123
+ "@gjsify/buffer": "^0.6.0",
124
+ "@gjsify/create-app": "^0.6.0",
125
+ "@gjsify/node-globals": "^0.6.0",
126
+ "@gjsify/node-polyfills": "^0.6.0",
127
+ "@gjsify/npm-registry": "^0.6.0",
128
+ "@gjsify/resolve-npm": "^0.6.0",
129
+ "@gjsify/rolldown-plugin-gjsify": "^0.6.0",
130
+ "@gjsify/rolldown-plugin-pnp": "^0.6.0",
131
+ "@gjsify/semver": "^0.6.0",
132
+ "@gjsify/tar": "^0.6.0",
133
+ "@gjsify/tsc": "^0.6.0",
134
+ "@gjsify/web-polyfills": "^0.6.0",
135
+ "@gjsify/workspace": "^0.6.0",
136
136
  "cosmiconfig": "^9.0.2",
137
137
  "get-tsconfig": "^4.14.0",
138
138
  "pkg-types": "^2.3.1",
@@ -140,13 +140,13 @@
140
140
  "yargs": "^18.0.0"
141
141
  },
142
142
  "devDependencies": {
143
- "@gjsify/unit": "^0.5.1",
143
+ "@gjsify/unit": "^0.6.0",
144
144
  "@types/yargs": "^17.0.35",
145
145
  "typescript": "^6.0.3"
146
146
  },
147
147
  "peerDependencies": {
148
- "@gjsify/oxfmt-native": "^0.5.1",
149
- "@gjsify/rolldown-native": "^0.5.1"
148
+ "@gjsify/oxfmt-native": "^0.6.0",
149
+ "@gjsify/rolldown-native": "^0.6.0"
150
150
  },
151
151
  "peerDependenciesMeta": {
152
152
  "@gjsify/oxfmt-native": {