@gjsify/nativescript-vite 0.59.1 → 0.60.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.
package/README.md CHANGED
@@ -17,6 +17,12 @@ It is a **thin composer** around the upstream `@nativescript/vite` integration.
17
17
 
18
18
  On top of the fixes, it spreads `@gjsify/vite-plugin-gjsify`'s `gjsifyNativescript()` preset: `gi://` → empty module, platform file resolution (`*.android` / `*.ios` / `*.native`), platform defines (`__ANDROID__` / `__IOS__` / `__APPLE__` / `__VISIONOS__` / `__DEV__`), and the node-builtin alias routing (incl. `module` → `@gjsify/module`).
19
19
 
20
+ ## Release-build minifier defaults
21
+
22
+ *2026-10-10.* A release build of Learn6502's Android app crashed on launch with `Class not found` for `com.tns.FragmentClass`, `com.tns.NativeScriptActivity` and `org.nativescript.NativeScriptLifecycleCallbacks`. The Android Static Binding Generator reads the bundle as text: the default oxc minifier writes `extend(\`com.tns.X\`, …)` with a template literal, and the syntax pass folds `__decorate([JavaProxy("…")], t)` into a comma expression. The generator recognises neither, skips the class without an error, and the native class never exists. Mangled class names also broke the `adw:Bin` → `AdwBin` check in `@gjsify/adwaita-nativescript` (that package now names its classes with a static `GTypeName`).
23
+
24
+ `defineNativescriptConfig()` therefore ships `build.minify: 'esbuild'` plus `esbuild: { minifySyntax: false, keepNames: true }` (`nativescriptReleaseMinify()`), unless upstream already disabled minification (debug builds). Whitespace and identifiers still shrink. `esbuild` has to be installed next to `vite` (an optional peer of Vite 8). Your own `build.minify` / `esbuild` in the `userConfig` argument wins, so a platform that wants another minifier keeps it.
25
+
20
26
  ## Install
21
27
 
22
28
  The package's only hard dependency is `@gjsify/vite-plugin-gjsify`. Everything from the NativeScript side is an **optional peer** — install it in your NativeScript app alongside the rest of your NS toolchain:
package/lib/index.d.ts CHANGED
@@ -54,6 +54,27 @@ export default defineNativescriptConfig;
54
54
  * drop chunks that already accumulated; from then on the names stay stable.
55
55
  */
56
56
  export declare function nativescriptSbgBundleSyncFix(): UserConfig;
57
+ /**
58
+ * Minifier defaults under which a RELEASE build of a NativeScript app still launches.
59
+ *
60
+ * Vite 8's default minifier (oxc) and esbuild's syntax pass rewrite two things the Android
61
+ * Static Binding Generator (SBG) reads LITERALLY from the bundle: oxc emits
62
+ * `extend("com.tns.X", …)` with a template literal, and the syntax pass folds
63
+ * `__decorate([JavaProxy("…")], t)` into a comma expression. The SBG recognises neither, skips
64
+ * the class without a word, and the app dies on launch with `Class not found` for
65
+ * `com.tns.FragmentClass` / `com.tns.NativeScriptActivity` /
66
+ * `org.nativescript.NativeScriptLifecycleCallbacks`. Mangled class names additionally break
67
+ * every check that compares a class name (`Adw.Bin` against `AdwBin`).
68
+ *
69
+ * So the release minifier is esbuild with `minifySyntax: false` (whitespace and identifiers
70
+ * still shrink) and `keepNames: true`. `esbuild` must be installed next to `vite` — it is an
71
+ * optional peer of Vite 8. A build that upstream already leaves unminified (`build.minify:
72
+ * false`, i.e. a debug build) gets nothing. The consumer's own `build.minify` / `esbuild`
73
+ * still wins, merged after this: a per-platform choice is never blocked.
74
+ *
75
+ * @param config the config the defaults are layered over.
76
+ */
77
+ export declare function nativescriptReleaseMinify(config?: UserConfig): UserConfig;
57
78
  /**
58
79
  * Pure core of {@link repointMistargetedCoreAlias} (exported for testing, since
59
80
  * the wrapper resolves the real `@nativescript/core` from disk).
package/lib/index.js CHANGED
@@ -48,7 +48,7 @@
48
48
  import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
49
49
  import module, { createRequire } from 'node:module';
50
50
  import { dirname, join } from 'node:path';
51
- import { fileURLToPath } from 'node:url';
51
+ import { fileURLToPath, pathToFileURL } from 'node:url';
52
52
  import { mergeConfig } from 'vite';
53
53
  import { gjsifyNativescript as gjsifyNativescriptTransforms } from '@gjsify/vite-plugin-gjsify';
54
54
  /**
@@ -96,10 +96,13 @@ export function defineNativescriptConfig(options = {}, userConfig) {
96
96
  // not accumulate stale, hashed chunk files the Android SBG then sees as a
97
97
  // duplicate native `extends` (see {@link nativescriptSbgBundleSyncFix}).
98
98
  const withSbgFix = mergeConfig(withTransforms, nativescriptSbgBundleSyncFix());
99
+ // Keep the strings and decorators NativeScript's static binding generator reads
100
+ // (see {@link nativescriptReleaseMinify}); a consumer's own `build.minify` wins below.
101
+ const withMinify = mergeConfig(withSbgFix, nativescriptReleaseMinify(withSbgFix));
99
102
  if (userConfig === undefined)
100
- return withSbgFix;
103
+ return withMinify;
101
104
  const resolved = typeof userConfig === 'function' ? await userConfig(env) : userConfig;
102
- return mergeConfig(withSbgFix, resolved);
105
+ return mergeConfig(withMinify, resolved);
103
106
  };
104
107
  }
105
108
  export default defineNativescriptConfig;
@@ -148,6 +151,34 @@ export function nativescriptSbgBundleSyncFix() {
148
151
  },
149
152
  };
150
153
  }
154
+ /**
155
+ * Minifier defaults under which a RELEASE build of a NativeScript app still launches.
156
+ *
157
+ * Vite 8's default minifier (oxc) and esbuild's syntax pass rewrite two things the Android
158
+ * Static Binding Generator (SBG) reads LITERALLY from the bundle: oxc emits
159
+ * `extend("com.tns.X", …)` with a template literal, and the syntax pass folds
160
+ * `__decorate([JavaProxy("…")], t)` into a comma expression. The SBG recognises neither, skips
161
+ * the class without a word, and the app dies on launch with `Class not found` for
162
+ * `com.tns.FragmentClass` / `com.tns.NativeScriptActivity` /
163
+ * `org.nativescript.NativeScriptLifecycleCallbacks`. Mangled class names additionally break
164
+ * every check that compares a class name (`Adw.Bin` against `AdwBin`).
165
+ *
166
+ * So the release minifier is esbuild with `minifySyntax: false` (whitespace and identifiers
167
+ * still shrink) and `keepNames: true`. `esbuild` must be installed next to `vite` — it is an
168
+ * optional peer of Vite 8. A build that upstream already leaves unminified (`build.minify:
169
+ * false`, i.e. a debug build) gets nothing. The consumer's own `build.minify` / `esbuild`
170
+ * still wins, merged after this: a per-platform choice is never blocked.
171
+ *
172
+ * @param config the config the defaults are layered over.
173
+ */
174
+ export function nativescriptReleaseMinify(config = {}) {
175
+ if (config.build?.minify === false)
176
+ return {};
177
+ return {
178
+ build: { minify: 'esbuild' },
179
+ esbuild: { minifySyntax: false, keepNames: true },
180
+ };
181
+ }
151
182
  /**
152
183
  * Repoint a mis-targeted `@nativescript/core` resolve.alias.
153
184
  *
@@ -253,7 +284,7 @@ async function loadUpstreamConfig(env) {
253
284
  for (const specifier of candidates) {
254
285
  let mod;
255
286
  try {
256
- mod = (await import(specifier));
287
+ mod = (await import(importSpecifierFor(specifier)));
257
288
  }
258
289
  catch (cause) {
259
290
  lastError = cause;
@@ -268,6 +299,29 @@ async function loadUpstreamConfig(env) {
268
299
  throw new Error('@gjsify/nativescript-vite requires the optional peer "@nativescript/vite" exporting `typescriptConfig` ' +
269
300
  '(install it alongside @nativescript/core in your NativeScript app).', { cause: lastError });
270
301
  }
302
+ /**
303
+ * Turn a bare specifier for an optional peer into one Node can load from THIS
304
+ * project. A bare `import()` resolves relative to this module's own file, which
305
+ * is wrong whenever `@gjsify/nativescript-vite` is a SYMLINK into a checkout
306
+ * (`file:` dependency, `npm link`, a workspace): the peer then gets looked up in
307
+ * the link TARGET's `node_modules`, not in the app's, and config-load dies with
308
+ * `ERR_MODULE_NOT_FOUND` even though the app installed the peer. Resolve from the
309
+ * project root (`process.cwd()` — where Vite runs the config) first and hand
310
+ * `import()` the concrete file URL; fall back to the bare specifier when the
311
+ * project-root lookup finds nothing, so the error message stays the peer's own.
312
+ */
313
+ function importSpecifierFor(specifier) {
314
+ const require = createRequire(import.meta.url);
315
+ try {
316
+ const entry = require.resolve(specifier, {
317
+ paths: [process.cwd(), dirname(fileURLToPath(import.meta.url))],
318
+ });
319
+ return pathToFileURL(entry).href;
320
+ }
321
+ catch {
322
+ return specifier;
323
+ }
324
+ }
271
325
  /** One-time guard so the missing-framework-peer stub notice prints at most once per process. */
272
326
  let stubbedPeersNoticeShown = false;
273
327
  /** Idempotency guard: register the Node resolve/load hooks at most once per process. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/nativescript-vite",
3
- "version": "0.59.1",
3
+ "version": "0.60.0",
4
4
  "description": "Vite 8 / Rolldown compatibility + gjsify transforms for building NativeScript apps — composes @nativescript/vite and fixes the pieces Rolldown rejects.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -39,13 +39,14 @@
39
39
  ],
40
40
  "license": "MIT",
41
41
  "dependencies": {
42
- "@gjsify/vite-plugin-gjsify": "^0.59.1"
42
+ "@gjsify/vite-plugin-gjsify": "^0.60.0"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@nativescript/canvas": "*",
46
46
  "@nativescript/canvas-polyfill": "*",
47
47
  "@nativescript/core": "*",
48
48
  "@nativescript/vite": "*",
49
+ "esbuild": "^0.27.0 || ^0.28.0",
49
50
  "nativescript": "*",
50
51
  "vite": "^8.1.3"
51
52
  },
@@ -62,6 +63,9 @@
62
63
  "@nativescript/vite": {
63
64
  "optional": true
64
65
  },
66
+ "esbuild": {
67
+ "optional": true
68
+ },
65
69
  "nativescript": {
66
70
  "optional": true
67
71
  },