@gjsify/vite-plugin-gjsify 0.64.17-next.292 → 0.64.18
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/lib/index.js +69 -13
- package/package.json +9 -10
package/lib/index.js
CHANGED
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
import { createRequire } from 'node:module';
|
|
41
41
|
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
42
42
|
import * as nodePath from 'node:path';
|
|
43
|
-
import { gjsImportsEmptyPlugin, giRendererPlugin, platformResolvePlugin, nativescriptSuffixChain, browserSuffixChain, BROWSER_REFUSED_SUFFIXES, detectNativescriptPlatform, nativescriptPlatformDefines, cssAsStringPlugin, gresourcePlugin, gschemaPlugin, GSCHEMA_REGISTER, nativescriptLocalePlugin, nativescriptGiSelectionPlugin, } from '@gjsify/rolldown-plugin-gjsify';
|
|
43
|
+
import { gjsImportsEmptyPlugin, giRendererPlugin, platformResolvePlugin, nativescriptSuffixChain, NATIVESCRIPT_PLATFORMS, browserSuffixChain, BROWSER_REFUSED_SUFFIXES, detectNativescriptPlatform, nativescriptPlatformDefines, cssAsStringPlugin, gresourcePlugin, gschemaPlugin, GSCHEMA_REGISTER, nativescriptLocalePlugin, nativescriptGiSelectionPlugin, } from '@gjsify/rolldown-plugin-gjsify';
|
|
44
44
|
import blueprintPlugin from '@gjsify/vite-plugin-blueprint';
|
|
45
45
|
import { deepkitPlugin } from '@gjsify/rolldown-plugin-deepkit';
|
|
46
46
|
import { ALIASES_NODE_FOR_NATIVESCRIPT, GI_RENDERERS } from '@gjsify/resolve-npm';
|
|
@@ -298,14 +298,45 @@ function nativescriptXmlnsBarrelsPlugin() {
|
|
|
298
298
|
},
|
|
299
299
|
};
|
|
300
300
|
}
|
|
301
|
+
const ENGINE_SOURCE_EXT_RE = /\.(?:[cm]?[jt]s)$/;
|
|
302
|
+
const NS_VARIANT_SUFFIXES = [...NATIVESCRIPT_PLATFORMS, 'native'];
|
|
303
|
+
/**
|
|
304
|
+
* The file the build's platform resolution would pick for `stem` — `<stem>.<suffix>.<ext>`
|
|
305
|
+
* for the first suffix of `chain` present in `entries`, else `<stem>.<ext>` — or undefined
|
|
306
|
+
* when only other platforms' variants exist.
|
|
307
|
+
*/
|
|
308
|
+
function pickPlatformVariant(entries, stem, chain) {
|
|
309
|
+
for (const prefix of [...chain.map((suffix) => `${stem}.${suffix}`), stem]) {
|
|
310
|
+
const hit = entries.find((entry) => ENGINE_SOURCE_EXT_RE.test(entry) && entry.replace(ENGINE_SOURCE_EXT_RE, '') === prefix);
|
|
311
|
+
if (hit)
|
|
312
|
+
return hit;
|
|
313
|
+
}
|
|
314
|
+
return undefined;
|
|
315
|
+
}
|
|
301
316
|
/**
|
|
302
317
|
* The app modules that pick the GObject engine (ADR 0110): those importing
|
|
303
318
|
* `@gjsify/adwaita-gobject-native` or calling `usePureJsGObjectEngine`. Root-relative
|
|
304
319
|
* specs, sorted, so the generated import order is deterministic.
|
|
320
|
+
*
|
|
321
|
+
* An opt-in is imported as the PLATFORM VARIANT the app's own import would resolve to.
|
|
322
|
+
* The hoisted import is an absolute path, which no platform resolution touches, so taking
|
|
323
|
+
* the scanned file as-is put Android's `engine.ts` — real GObject through node-gi — into an
|
|
324
|
+
* iOS bundle beside the `engine.ios.ts` meant to replace it, and the app died at launch on a
|
|
325
|
+
* node-gi that iOS does not have. The variant itself need not contain the opt-in: iOS's
|
|
326
|
+
* pure-JS default is an empty slot, so its `engine.ios.ts` may select nothing.
|
|
305
327
|
*/
|
|
306
|
-
function collectEngineOptIns(appDir, root) {
|
|
328
|
+
function collectEngineOptIns(appDir, root, platform) {
|
|
307
329
|
const optInRe = /from\s*["']@gjsify\/adwaita-gobject-native["']|\busePureJsGObjectEngine\s*\(/;
|
|
308
|
-
const
|
|
330
|
+
const chain = nativescriptSuffixChain(platform);
|
|
331
|
+
const specs = new Set();
|
|
332
|
+
const addVariant = (dir, entry, entries) => {
|
|
333
|
+
const name = entry.replace(ENGINE_SOURCE_EXT_RE, '');
|
|
334
|
+
const dot = name.lastIndexOf('.');
|
|
335
|
+
const stem = dot > 0 && NS_VARIANT_SUFFIXES.includes(name.slice(dot + 1)) ? name.slice(0, dot) : name;
|
|
336
|
+
const picked = pickPlatformVariant(entries, stem, chain);
|
|
337
|
+
if (picked)
|
|
338
|
+
specs.add('/' + nodePath.relative(root, nodePath.join(dir, picked)).split(nodePath.sep).join('/'));
|
|
339
|
+
};
|
|
309
340
|
const walk = (dir) => {
|
|
310
341
|
let entries;
|
|
311
342
|
try {
|
|
@@ -329,7 +360,7 @@ function collectEngineOptIns(appDir, root) {
|
|
|
329
360
|
walk(full);
|
|
330
361
|
continue;
|
|
331
362
|
}
|
|
332
|
-
if (
|
|
363
|
+
if (!ENGINE_SOURCE_EXT_RE.test(entry) || /\.d\.[cm]?ts$/.test(entry))
|
|
333
364
|
continue;
|
|
334
365
|
let src;
|
|
335
366
|
try {
|
|
@@ -339,11 +370,11 @@ function collectEngineOptIns(appDir, root) {
|
|
|
339
370
|
continue;
|
|
340
371
|
}
|
|
341
372
|
if (optInRe.test(src))
|
|
342
|
-
|
|
373
|
+
addVariant(dir, entry, entries);
|
|
343
374
|
}
|
|
344
375
|
};
|
|
345
376
|
walk(appDir);
|
|
346
|
-
return specs.sort();
|
|
377
|
+
return [...specs].sort();
|
|
347
378
|
}
|
|
348
379
|
/**
|
|
349
380
|
* Evaluate the app's GObject-engine opt-in before ANY other app module.
|
|
@@ -359,7 +390,7 @@ function collectEngineOptIns(appDir, root) {
|
|
|
359
390
|
* Prepends a side-effect import of each opt-in module to the bundler context; it is
|
|
360
391
|
* registered after the xmlns plugin, so its import ends up first.
|
|
361
392
|
*/
|
|
362
|
-
function nativescriptEngineFirstPlugin() {
|
|
393
|
+
function nativescriptEngineFirstPlugin(platform) {
|
|
363
394
|
const BUNDLER_CONTEXT_ID = '\0virtual:ns-bundler-context';
|
|
364
395
|
let root = process.cwd();
|
|
365
396
|
let appDir;
|
|
@@ -372,7 +403,7 @@ function nativescriptEngineFirstPlugin() {
|
|
|
372
403
|
transform(code, id) {
|
|
373
404
|
if (id !== BUNDLER_CONTEXT_ID || !appDir)
|
|
374
405
|
return null;
|
|
375
|
-
const optIns = collectEngineOptIns(appDir, root);
|
|
406
|
+
const optIns = collectEngineOptIns(appDir, root, platform);
|
|
376
407
|
if (optIns.length === 0)
|
|
377
408
|
return null;
|
|
378
409
|
const imports = optIns.map((spec) => `import ${JSON.stringify(spec)};`).join('\n');
|
|
@@ -400,15 +431,25 @@ export function gjsifyNativescript(options = {}) {
|
|
|
400
431
|
// `@gjsify/<X>` target. Generated from `ALIASES_NODE_FOR_NATIVESCRIPT` so
|
|
401
432
|
// the single source-of-truth in `@gjsify/resolve-npm` drives every build,
|
|
402
433
|
// matching the Rolldown-side `app/nativescript.ts` composition.
|
|
434
|
+
// Target platform from the env NS' CLI sets when it spawns the bundler
|
|
435
|
+
// (else `undefined` → `.native`-only resolution + neutral defines).
|
|
436
|
+
const platform = detectNativescriptPlatform();
|
|
403
437
|
const nodePrefixAliases = {};
|
|
404
438
|
for (const [bare, target] of Object.entries(ALIASES_NODE_FOR_NATIVESCRIPT)) {
|
|
405
439
|
nodePrefixAliases[bare] = target;
|
|
406
440
|
nodePrefixAliases[`node:${bare}`] = target;
|
|
407
441
|
}
|
|
442
|
+
// `gettext` is curated for Android (`@gjsify/node-gi/gettext`, real GLib gettext via
|
|
443
|
+
// node-gi), but node-gi has no iOS/visionOS payload and its index.js loads
|
|
444
|
+
// `libnode_gi.so` at MODULE EVAL — before any call, so merely bundling the real
|
|
445
|
+
// answer crashes every non-Android NS app at import time. Same override + same reason
|
|
446
|
+
// as the Rolldown-side `app/nativescript.ts` composition; an undetected platform gets
|
|
447
|
+
// the safe default too.
|
|
448
|
+
if (platform !== 'android') {
|
|
449
|
+
nodePrefixAliases.gettext = '@gjsify/native-platform/gettext-fallback';
|
|
450
|
+
nodePrefixAliases['node:gettext'] = '@gjsify/native-platform/gettext-fallback';
|
|
451
|
+
}
|
|
408
452
|
const optimizeDepsExclude = ['@gjsify/unit', ...(options.optimizeDepsExclude ?? [])];
|
|
409
|
-
// Target platform from the env NS' CLI sets when it spawns the bundler
|
|
410
|
-
// (else `undefined` → `.native`-only resolution + neutral defines).
|
|
411
|
-
const platform = detectNativescriptPlatform();
|
|
412
453
|
const configPlugin = {
|
|
413
454
|
name: 'gjsify-nativescript-config',
|
|
414
455
|
config(userConfig, env) {
|
|
@@ -457,7 +498,7 @@ export function gjsifyNativescript(options = {}) {
|
|
|
457
498
|
nativescriptXmlnsBarrelsPlugin(),
|
|
458
499
|
// The app's GObject-engine opt-in (ADR 0110) ahead of everything the bundler
|
|
459
500
|
// context imports. AFTER the xmlns plugin, so its prepend lands on top.
|
|
460
|
-
nativescriptEngineFirstPlugin(),
|
|
501
|
+
nativescriptEngineFirstPlugin(platform),
|
|
461
502
|
// NO blueprintPlugin — Blueprint is GTK-specific
|
|
462
503
|
// NO cssAsStringPlugin — NS handles CSS via @nativescript/core
|
|
463
504
|
// `import bytes from './x.gresource.xml'` (ADR 0116 §§ 1, 7), as `--app nativescript`;
|
|
@@ -469,9 +510,24 @@ export function gjsifyNativescript(options = {}) {
|
|
|
469
510
|
// ADR 0117 § 2's gate, on this path too: the NS CLI drives Vite, so without this
|
|
470
511
|
// `giNamespaces` is a key the config loader accepts and nothing acts on.
|
|
471
512
|
...(options.giNamespaces
|
|
472
|
-
? [
|
|
513
|
+
? [
|
|
514
|
+
nativescriptGiSelectionPlugin({
|
|
515
|
+
declared: options.giNamespaces,
|
|
516
|
+
installed: appDependencyNames(process.cwd()),
|
|
517
|
+
}),
|
|
518
|
+
]
|
|
473
519
|
: []),
|
|
474
520
|
deepkitPlugin({ reflection: options.reflection }),
|
|
475
521
|
configPlugin,
|
|
476
522
|
];
|
|
477
523
|
}
|
|
524
|
+
/** The app's `dependencies` + `devDependencies` names, or `[]` when there is no readable manifest. */
|
|
525
|
+
function appDependencyNames(root) {
|
|
526
|
+
try {
|
|
527
|
+
const manifest = JSON.parse(readFileSync(nodePath.join(root, 'package.json'), 'utf8'));
|
|
528
|
+
return [...Object.keys(manifest.dependencies ?? {}), ...Object.keys(manifest.devDependencies ?? {})];
|
|
529
|
+
}
|
|
530
|
+
catch {
|
|
531
|
+
return [];
|
|
532
|
+
}
|
|
533
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/vite-plugin-gjsify",
|
|
3
|
-
"version": "0.64.
|
|
3
|
+
"version": "0.64.18",
|
|
4
4
|
"description": "Vite plugin presets mirroring `gjsify build --app browser` / `--app nativescript` — dev (Vite/HMR) parity with the gjsify CLI targets.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
],
|
|
44
44
|
"license": "MIT",
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@gjsify/empty": "0.64.
|
|
47
|
-
"@gjsify/resolve-npm": "0.64.
|
|
48
|
-
"@gjsify/rolldown-plugin-deepkit": "0.64.
|
|
49
|
-
"@gjsify/rolldown-plugin-gjsify": "0.64.
|
|
50
|
-
"@gjsify/vite-plugin-blueprint": "0.64.
|
|
46
|
+
"@gjsify/empty": "^0.64.18",
|
|
47
|
+
"@gjsify/resolve-npm": "^0.64.18",
|
|
48
|
+
"@gjsify/rolldown-plugin-deepkit": "^0.64.18",
|
|
49
|
+
"@gjsify/rolldown-plugin-gjsify": "^0.64.18",
|
|
50
|
+
"@gjsify/vite-plugin-blueprint": "^0.64.18"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"vite": "^8.1.3"
|
|
@@ -58,14 +58,13 @@
|
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@gjsify/cli": "0.64.
|
|
62
|
-
"@gjsify/unit": "0.64.
|
|
61
|
+
"@gjsify/cli": "^0.64.18",
|
|
62
|
+
"@gjsify/unit": "^0.64.18",
|
|
63
63
|
"@types/node": "^25.9.2",
|
|
64
64
|
"typescript": "^6.0.3",
|
|
65
65
|
"vite": "^8.1.3"
|
|
66
66
|
},
|
|
67
67
|
"gjsify": {
|
|
68
68
|
"tier": 1
|
|
69
|
-
}
|
|
70
|
-
"gitHead": "1cd14727f5a53991fbdee0f38eedea4dd8fdecdd"
|
|
69
|
+
}
|
|
71
70
|
}
|