@nativescript/vite 8.0.0-alpha.32 → 8.0.0-alpha.34

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.
Files changed (53) hide show
  1. package/configuration/javascript.js +2 -15
  2. package/configuration/javascript.js.map +1 -1
  3. package/configuration/typescript.js +2 -13
  4. package/configuration/typescript.js.map +1 -1
  5. package/helpers/css-platform-plugin.d.ts +14 -0
  6. package/helpers/css-platform-plugin.js +43 -25
  7. package/helpers/css-platform-plugin.js.map +1 -1
  8. package/helpers/global-defines.d.ts +53 -0
  9. package/helpers/global-defines.js +59 -14
  10. package/helpers/global-defines.js.map +1 -1
  11. package/helpers/main-entry.js +29 -15
  12. package/helpers/main-entry.js.map +1 -1
  13. package/helpers/postcss-platform-config.d.ts +17 -1
  14. package/helpers/postcss-platform-config.js +17 -34
  15. package/helpers/postcss-platform-config.js.map +1 -1
  16. package/helpers/ui-registration.d.ts +21 -0
  17. package/helpers/ui-registration.js +156 -0
  18. package/helpers/ui-registration.js.map +1 -0
  19. package/hmr/client/index.js +7 -0
  20. package/hmr/client/index.js.map +1 -1
  21. package/hmr/frameworks/typescript/server/strategy.js +11 -1
  22. package/hmr/frameworks/typescript/server/strategy.js.map +1 -1
  23. package/hmr/helpers/ast-normalizer.d.ts +3 -1
  24. package/hmr/helpers/ast-normalizer.js +23 -4
  25. package/hmr/helpers/ast-normalizer.js.map +1 -1
  26. package/hmr/server/constants.js +7 -1
  27. package/hmr/server/constants.js.map +1 -1
  28. package/hmr/server/device-transform-helpers.js +43 -1
  29. package/hmr/server/device-transform-helpers.js.map +1 -1
  30. package/hmr/server/perf-instrumentation.d.ts +1 -1
  31. package/hmr/server/perf-instrumentation.js +2 -0
  32. package/hmr/server/perf-instrumentation.js.map +1 -1
  33. package/hmr/server/process-code-for-device.js +69 -19
  34. package/hmr/server/process-code-for-device.js.map +1 -1
  35. package/hmr/server/rewrite-imports.js +11 -0
  36. package/hmr/server/rewrite-imports.js.map +1 -1
  37. package/hmr/server/vite-plugin.js +12 -0
  38. package/hmr/server/vite-plugin.js.map +1 -1
  39. package/hmr/server/websocket-ns-m.js +6 -2
  40. package/hmr/server/websocket-ns-m.js.map +1 -1
  41. package/hmr/server/websocket-served-module-helpers.d.ts +43 -0
  42. package/hmr/server/websocket-served-module-helpers.js +109 -2
  43. package/hmr/server/websocket-served-module-helpers.js.map +1 -1
  44. package/hmr/shared/runtime/boot-placeholder-ui.d.ts +2 -2
  45. package/hmr/shared/runtime/boot-placeholder-ui.js +2 -2
  46. package/hmr/shared/runtime/boot-progress.d.ts +7 -3
  47. package/hmr/shared/runtime/boot-progress.js +8 -4
  48. package/hmr/shared/runtime/boot-progress.js.map +1 -1
  49. package/hmr/shared/runtime/root-placeholder.js +15 -0
  50. package/hmr/shared/runtime/root-placeholder.js.map +1 -1
  51. package/hmr/shared/runtime/session-bootstrap.js +1 -1
  52. package/hmr/shared/runtime/session-bootstrap.js.map +1 -1
  53. package/package.json +1 -1
@@ -5,7 +5,23 @@ interface PostCssConfigOptions {
5
5
  postcssImport: any;
6
6
  }
7
7
  /**
8
- * Builds PostCSS configuration with platform import rewriting + postcss-import fallback.
8
+ * Builds PostCSS configuration with a platform-aware postcss-import fallback.
9
+ *
10
+ * Reality check under Vite 8: whenever the compiled CSS still contains
11
+ * `@import`, Vite UNSHIFTS its own bundled postcss-import ahead of every
12
+ * user plugin in this config — so by the time these plugins run, the import
13
+ * rules have already been inlined (or the build already failed on an
14
+ * unresolvable specifier). Platform-variant rewriting (`foo.css` →
15
+ * `foo.ios.css`) therefore happens BEFORE Vite sees the CSS:
16
+ * - module pipeline: the `ns-css-platform` plugin's transform hook
17
+ * - direct `preprocessCSS()` callers: `rewritePlatformCssImports()`
18
+ * (both in helpers/css-platform-plugin.ts)
19
+ * A previous `ns-postcss-platform-import-rewrite` plugin here duplicated that
20
+ * rewrite at the postcss layer; it was unreachable and has been removed.
21
+ *
22
+ * The postcss-import fallback below is retained as defense-in-depth for
23
+ * preprocessor outputs (sass passes `@import "*.css"` through untouched) in
24
+ * case an app's plugin order ever bypasses Vite's internal inliner.
9
25
  */
10
26
  export declare function createPostCssConfig(opts: PostCssConfigOptions): "./postcss.config.js" | {
11
27
  plugins: any[];
@@ -2,7 +2,23 @@ import path from 'path';
2
2
  import { existsSync, readFileSync } from 'fs';
3
3
  import { findPackageInNodeModules } from './module-resolution.js';
4
4
  /**
5
- * Builds PostCSS configuration with platform import rewriting + postcss-import fallback.
5
+ * Builds PostCSS configuration with a platform-aware postcss-import fallback.
6
+ *
7
+ * Reality check under Vite 8: whenever the compiled CSS still contains
8
+ * `@import`, Vite UNSHIFTS its own bundled postcss-import ahead of every
9
+ * user plugin in this config — so by the time these plugins run, the import
10
+ * rules have already been inlined (or the build already failed on an
11
+ * unresolvable specifier). Platform-variant rewriting (`foo.css` →
12
+ * `foo.ios.css`) therefore happens BEFORE Vite sees the CSS:
13
+ * - module pipeline: the `ns-css-platform` plugin's transform hook
14
+ * - direct `preprocessCSS()` callers: `rewritePlatformCssImports()`
15
+ * (both in helpers/css-platform-plugin.ts)
16
+ * A previous `ns-postcss-platform-import-rewrite` plugin here duplicated that
17
+ * rewrite at the postcss layer; it was unreachable and has been removed.
18
+ *
19
+ * The postcss-import fallback below is retained as defense-in-depth for
20
+ * preprocessor outputs (sass passes `@import "*.css"` through untouched) in
21
+ * case an app's plugin order ever bypasses Vite's internal inliner.
6
22
  */
7
23
  export function createPostCssConfig(opts) {
8
24
  const { platform, projectRoot, themeCoreRoot, postcssImport } = opts;
@@ -10,39 +26,6 @@ export function createPostCssConfig(opts) {
10
26
  return './postcss.config.js';
11
27
  return {
12
28
  plugins: [
13
- {
14
- postcssPlugin: 'ns-postcss-platform-import-rewrite',
15
- Once(root) {
16
- try {
17
- const currentFile = root?.source?.input?.file;
18
- if (!currentFile)
19
- return;
20
- const currentDir = path.dirname(currentFile);
21
- root.walkAtRules('import', (rule) => {
22
- const m = /^\s*(?:url\()?["]?([^"')]+)["]?\)?/.exec(rule.params || '');
23
- if (!m)
24
- return;
25
- const spec = m[1];
26
- if (!spec || !(spec.startsWith('.') || spec.startsWith('/')))
27
- return;
28
- if (!spec.endsWith('.css'))
29
- return;
30
- const abs = path.isAbsolute(spec) ? spec : path.resolve(currentDir, spec);
31
- if (existsSync(abs))
32
- return;
33
- const ext = platform === 'android' ? '.android.css' : '.ios.css';
34
- const alt = abs.replace(/\.css$/, ext);
35
- if (existsSync(alt)) {
36
- let rel = path.relative(currentDir, alt).replace(/\\/g, '/');
37
- if (!rel.startsWith('.'))
38
- rel = './' + rel;
39
- rule.params = rule.params.replace(spec, rel);
40
- }
41
- });
42
- }
43
- catch { }
44
- },
45
- },
46
29
  postcssImport({
47
30
  resolve(id, basedir) {
48
31
  if (id.startsWith('.') || id.startsWith('/')) {
@@ -1 +1 @@
1
- {"version":3,"file":"postcss-platform-config.js","sourceRoot":"","sources":["../../../../packages/vite/helpers/postcss-platform-config.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AASlE;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAA0B;IAC7D,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC;IACrE,IAAI,CAAC,aAAa;QAAE,OAAO,qBAAqB,CAAC;IACjD,OAAO;QACN,OAAO,EAAE;YACR;gBACC,aAAa,EAAE,oCAAoC;gBACnD,IAAI,CAAC,IAAS;oBACb,IAAI,CAAC;wBACJ,MAAM,WAAW,GAAuB,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC;wBAClE,IAAI,CAAC,WAAW;4BAAE,OAAO;wBACzB,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;wBAC7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O,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;4BACjD,IAAI,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;gCACrB,OAAO,YAAY,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;4BACnC,CAAC;wBACF,CAAC;oBACF,CAAC;oBAAC,MAAM,CAAC,CAAA,CAAC;oBACV,OAAO,SAAgB,CAAC;gBACzB,CAAC;aACD,CAAC;SACF;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { Plugin } from 'vite';
2
+ /**
3
+ * Virtual module that registers @nativescript/core/ui with the bundler module
4
+ * registry (so the XML builder's `global.loadModule('@nativescript/core/ui')`
5
+ * resolves), registers short element names (Frame, StackLayout, …), imports the
6
+ * bundler context, and applies View prototype guards.
7
+ *
8
+ * The entry (`virtual:entry-with-polyfills`, see main-entry.ts) imports this
9
+ * module immediately after `bundle-entry-points`, so its body evaluates after
10
+ * core's entry points but before the user's main module.
11
+ *
12
+ * History: this code used to be string-injected by a `transform` hook in
13
+ * typescript.ts / javascript.ts that regex-matched the generated entry for the
14
+ * literal `import '@nativescript/core/bundle-entry-points';`. main-entry.ts
15
+ * later switched to `JSON.stringify(...)` (double quotes; a full dev-server URL
16
+ * under HMR) and the marker silently stopped matching — no injection, and every
17
+ * XML build failed with "Module 'Frame' not found". A dedicated virtual module
18
+ * cannot drift like that.
19
+ */
20
+ export declare const UI_REGISTRATION_VIRTUAL_ID = "virtual:ns-ui-registration";
21
+ export declare function createUiRegistrationPlugin(flavor: 'typescript' | 'javascript'): Plugin;
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Virtual module that registers @nativescript/core/ui with the bundler module
3
+ * registry (so the XML builder's `global.loadModule('@nativescript/core/ui')`
4
+ * resolves), registers short element names (Frame, StackLayout, …), imports the
5
+ * bundler context, and applies View prototype guards.
6
+ *
7
+ * The entry (`virtual:entry-with-polyfills`, see main-entry.ts) imports this
8
+ * module immediately after `bundle-entry-points`, so its body evaluates after
9
+ * core's entry points but before the user's main module.
10
+ *
11
+ * History: this code used to be string-injected by a `transform` hook in
12
+ * typescript.ts / javascript.ts that regex-matched the generated entry for the
13
+ * literal `import '@nativescript/core/bundle-entry-points';`. main-entry.ts
14
+ * later switched to `JSON.stringify(...)` (double quotes; a full dev-server URL
15
+ * under HMR) and the marker silently stopped matching — no injection, and every
16
+ * XML build failed with "Module 'Frame' not found". A dedicated virtual module
17
+ * cannot drift like that.
18
+ */
19
+ export const UI_REGISTRATION_VIRTUAL_ID = 'virtual:ns-ui-registration';
20
+ const RESOLVED_ID = '\0' + UI_REGISTRATION_VIRTUAL_ID;
21
+ // TypeScript flavor: statically import the core UI barrel (the ns-core-external
22
+ // plugin rewrites it to the canonical core URL under HMR) and register it plus
23
+ // per-element nicknames; guard flex/layout View accessors against early writes.
24
+ const TS_REGISTRATION_CODE = `import '@nativescript/core/ui/styling/style';
25
+ import '@nativescript/core/ui/styling/style-properties';
26
+ import * as __nsCoreUi from '@nativescript/core/ui';
27
+ import 'virtual:ns-bundler-context';
28
+ (function(){
29
+ try {
30
+ const __ui = __nsCoreUi;
31
+ if (global.registerModule) {
32
+ const existsFn = global.moduleExists ? (n) => global.moduleExists(n) : () => false;
33
+ if (!existsFn('@nativescript/core/ui')) {
34
+ try { global.registerModule('@nativescript/core/ui', () => __ui); } catch(_) {}
35
+ }
36
+ Object.keys(__ui || {}).forEach(k => {
37
+ if (k && k[0] === k[0].toUpperCase() && !existsFn(k)) {
38
+ try { global.registerModule(k, () => ({ [k]: __ui[k] })); } catch(_) {}
39
+ }
40
+ });
41
+ }
42
+ if (__ui && __ui.View) {
43
+ const View = __ui.View;
44
+ const props = ['order','flexGrow','flexShrink','flexWrapBefore','alignSelf'];
45
+ for (const p of props) {
46
+ const d = Object.getOwnPropertyDescriptor(View.prototype, p);
47
+ if (d && typeof d.set === 'function') {
48
+ const origSet = d.set;
49
+ Object.defineProperty(View.prototype, p, {
50
+ configurable: true,
51
+ enumerable: d.enumerable,
52
+ get: d.get,
53
+ set(value){
54
+ if (value === undefined || value === null) return;
55
+ if (!this || !this._style) {
56
+ try { if (this && !this._style) this._style = this.style; } catch(_) {}
57
+ if (!this || !this._style) return;
58
+ }
59
+ return origSet.call(this, value);
60
+ }
61
+ });
62
+ }
63
+ }
64
+ // Force layout invalidation for alignment/visibility/size property changes
65
+ const forceProps = ['horizontalAlignment','verticalAlignment','visibility','height','width'];
66
+ for (const p of forceProps) {
67
+ const d = Object.getOwnPropertyDescriptor(View.prototype, p);
68
+ if (d && typeof d.set === 'function') {
69
+ const orig = d.set;
70
+ Object.defineProperty(View.prototype, p, {
71
+ configurable: true,
72
+ enumerable: d.enumerable,
73
+ get: d.get,
74
+ set(value){
75
+ const prev = this[p];
76
+ try { orig.call(this, value); } finally {
77
+ if (prev !== value) { try { this && this.requestLayout && this.requestLayout(); } catch(_) {} }
78
+ }
79
+ }
80
+ });
81
+ }
82
+ }
83
+ }
84
+ } catch(_) {}
85
+ })();
86
+ `;
87
+ // JavaScript flavor: resolve the UI barrel via the runtime module registry
88
+ // (global.loadModule) instead of a static namespace import; flex guard only,
89
+ // plus short element name registration.
90
+ const JS_REGISTRATION_CODE = `// Ensure style system is initialized before any UI component modules register CSS properties
91
+ import '@nativescript/core/ui/styling/style';
92
+ import '@nativescript/core/ui/styling/style-properties';
93
+ import 'virtual:ns-bundler-context';
94
+ // Patch CSS accessors to be resilient to early default initializations before style exists
95
+ (function(){
96
+ try {
97
+ const __ui = (global.loadModule ? global.loadModule('@nativescript/core/ui') : (global.require ? global.require('@nativescript/core/ui') : null));
98
+ if (__ui && __ui.View) {
99
+ const View = __ui.View;
100
+ const props = ['order','flexGrow','flexShrink','flexWrapBefore','alignSelf'];
101
+ for (const p of props) {
102
+ const d = Object.getOwnPropertyDescriptor(View.prototype, p);
103
+ if (d && typeof d.set === 'function') {
104
+ const origSet = d.set;
105
+ Object.defineProperty(View.prototype, p, {
106
+ configurable: true,
107
+ enumerable: d.enumerable,
108
+ get: d.get,
109
+ set(value){
110
+ if (value === undefined || value === null) return;
111
+ if (!this || !this._style) {
112
+ try { if (this && !this._style) this._style = this.style; } catch(_) {}
113
+ if (!this || !this._style) return;
114
+ }
115
+ return origSet.call(this, value);
116
+ }
117
+ });
118
+ }
119
+ }
120
+ }
121
+ } catch(_) {}
122
+ })();
123
+ // Vite adjustment: register short core UI element module names (e.g. Frame, StackLayout)
124
+ // Some XML builder paths attempt to load 'Frame' directly instead of the barrel.
125
+ // We expose individual element names so global.loadModule('Frame') works.
126
+ try {
127
+ const __ui = (global.loadModule ? global.loadModule('@nativescript/core/ui') : (global.require ? global.require('@nativescript/core/ui') : null));
128
+ if (__ui && global.registerModule) {
129
+ const existsFn = global.moduleExists ? (n) => global.moduleExists(n) : () => false;
130
+ Object.keys(__ui).forEach(k => {
131
+ if (k && k[0] === k[0].toUpperCase() && !existsFn(k)) {
132
+ try {
133
+ global.registerModule(k, () => ({ [k]: __ui[k] }));
134
+ } catch (e) { /* swallow */ }
135
+ }
136
+ });
137
+ }
138
+ } catch(e) { /* ignore */ }
139
+ `;
140
+ export function createUiRegistrationPlugin(flavor) {
141
+ return {
142
+ name: `ns-ui-registration-${flavor === 'typescript' ? 'ts' : 'js'}`,
143
+ enforce: 'pre',
144
+ resolveId(id) {
145
+ if (id === UI_REGISTRATION_VIRTUAL_ID)
146
+ return RESOLVED_ID;
147
+ return null;
148
+ },
149
+ load(id) {
150
+ if (id !== RESOLVED_ID)
151
+ return null;
152
+ return { code: flavor === 'typescript' ? TS_REGISTRATION_CODE : JS_REGISTRATION_CODE, map: null };
153
+ },
154
+ };
155
+ }
156
+ //# sourceMappingURL=ui-registration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui-registration.js","sourceRoot":"","sources":["../../../../packages/vite/helpers/ui-registration.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,4BAA4B,CAAC;AACvE,MAAM,WAAW,GAAG,IAAI,GAAG,0BAA0B,CAAC;AAEtD,gFAAgF;AAChF,+EAA+E;AAC/E,gFAAgF;AAChF,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8D5B,CAAC;AAEF,2EAA2E;AAC3E,6EAA6E;AAC7E,wCAAwC;AACxC,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiD5B,CAAC;AAEF,MAAM,UAAU,0BAA0B,CAAC,MAAmC;IAC7E,OAAO;QACN,IAAI,EAAE,sBAAsB,MAAM,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE;QACnE,OAAO,EAAE,KAAK;QACd,SAAS,CAAC,EAAE;YACX,IAAI,EAAE,KAAK,0BAA0B;gBAAE,OAAO,WAAW,CAAC;YAC1D,OAAO,IAAI,CAAC;QACb,CAAC;QACD,IAAI,CAAC,EAAE;YACN,IAAI,EAAE,KAAK,WAAW;gBAAE,OAAO,IAAI,CAAC;YACpC,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,YAAY,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,oBAAoB,EAAE,GAAG,EAAE,IAAI,EAAS,CAAC;QAC1G,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -1266,6 +1266,13 @@ async function processQueue() {
1266
1266
  catch (e) {
1267
1267
  console.warn('[hmr][queue] TS flavor: resetRootView(app-root) failed', e);
1268
1268
  }
1269
+ // Tell the overlay the cycle is done — same as the solid path
1270
+ // above. Without this the applying overlay sticks at
1271
+ // 'received' (5%) forever even though the in-place navigate /
1272
+ // resetRootView already applied the update.
1273
+ setUpdateOverlayStage('complete', {
1274
+ detail: `Total ${Math.max(0, Date.now() - tQueueStart)}ms`,
1275
+ });
1269
1276
  break;
1270
1277
  }
1271
1278
  }