@nativescript/vite 0.0.1-alpha.0 → 0.0.1-alpha.2

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 (55) hide show
  1. package/dist/configuration/base.js +178 -71
  2. package/dist/helpers/external-configs.js +1 -1
  3. package/dist/helpers/global-defines.d.ts +1 -0
  4. package/dist/helpers/global-defines.js +2 -0
  5. package/dist/helpers/main-entry-hmr-includes.d.ts +1 -0
  6. package/dist/helpers/main-entry-hmr-includes.js +18 -0
  7. package/dist/helpers/main-entry.d.ts +3 -3
  8. package/dist/helpers/main-entry.js +61 -54
  9. package/dist/helpers/module-runner-patch.d.ts +3 -0
  10. package/dist/helpers/module-runner-patch.js +65 -0
  11. package/dist/helpers/ns-cli-plugins.d.ts +4 -14
  12. package/dist/helpers/ns-cli-plugins.js +124 -101
  13. package/dist/helpers/package-platform-aliases.d.ts +1 -1
  14. package/dist/helpers/package-platform-aliases.js +4 -4
  15. package/dist/helpers/preserve-imports.d.ts +2 -0
  16. package/dist/helpers/preserve-imports.js +19 -0
  17. package/dist/helpers/ts-config-paths.d.ts +1 -1
  18. package/dist/helpers/ts-config-paths.js +6 -4
  19. package/dist/hmr/client-vue.d.ts +6 -0
  20. package/dist/hmr/client-vue.js +563 -0
  21. package/dist/hmr/component-tracker.d.ts +23 -0
  22. package/dist/hmr/component-tracker.js +193 -0
  23. package/dist/hmr/css-handler.d.ts +4 -0
  24. package/dist/hmr/css-handler.js +77 -0
  25. package/dist/hmr/message-handler.d.ts +1 -0
  26. package/dist/hmr/message-handler.js +590 -0
  27. package/dist/hmr/nsv-hooks.d.ts +2 -0
  28. package/dist/hmr/nsv-hooks.js +481 -0
  29. package/dist/hmr/plugin-vue.d.ts +2 -0
  30. package/dist/hmr/plugin-vue.js +38 -0
  31. package/dist/hmr/plugins/index.d.ts +1 -0
  32. package/dist/hmr/plugins/index.js +16 -0
  33. package/dist/hmr/plugins/plugin-vue.d.ts +2 -0
  34. package/dist/hmr/plugins/plugin-vue.js +41 -0
  35. package/dist/hmr/plugins/websocket-vue.d.ts +2 -0
  36. package/dist/hmr/plugins/websocket-vue.js +882 -0
  37. package/dist/hmr/runtime-vue.d.ts +13 -0
  38. package/dist/hmr/runtime-vue.js +2306 -0
  39. package/dist/hmr/types.d.ts +24 -0
  40. package/dist/hmr/types.js +2 -0
  41. package/dist/hmr/websocket-vue.d.ts +2 -0
  42. package/dist/hmr/websocket-vue.js +875 -0
  43. package/dist/shims/node-module.d.ts +5 -0
  44. package/dist/shims/node-module.js +12 -0
  45. package/package.json +2 -1
  46. package/dist/configuration/old-without-merge-base.d.ts +0 -13
  47. package/dist/configuration/old-without-merge-base.js +0 -249
  48. package/dist/hmr/hmr-angular.d.ts +0 -1
  49. package/dist/hmr/hmr-angular.js +0 -34
  50. package/dist/hmr/hmr-bridge.d.ts +0 -18
  51. package/dist/hmr/hmr-bridge.js +0 -154
  52. package/dist/hmr/hmr-client.d.ts +0 -5
  53. package/dist/hmr/hmr-client.js +0 -93
  54. package/dist/hmr/hmr-server.d.ts +0 -20
  55. package/dist/hmr/hmr-server.js +0 -179
@@ -1,19 +1,9 @@
1
- export declare function hmrPlugin(targetMode: string): {
2
- name: string;
3
- buildStart(): void;
4
- watchChange(id: any, { event }: {
5
- event: any;
6
- }): void;
7
- handleHotUpdate({ file, server, timestamp }: {
8
- file: any;
9
- server: any;
10
- timestamp: any;
11
- }): any[];
12
- };
13
- export declare function cliPlugin(targetMode: string, cliFlags: any): {
1
+ export declare function cliPlugin(distOutputFolder: string, isDevMode: boolean, verboseLogs: boolean, hmrActive: boolean): {
14
2
  name: string;
3
+ apply: string;
15
4
  enforce: "post";
16
5
  configResolved(config: any): void;
17
- buildStart(): void;
6
+ generateBundle(options: any, bundle: any): void;
7
+ writeBundle(options: any, bundle: any): void;
18
8
  closeBundle(): void;
19
9
  };
@@ -1,133 +1,156 @@
1
1
  import path from "path";
2
- import { readdirSync, statSync } from "fs";
3
- // NativeScript HMR integration - track changes for incremental builds
4
- // Track changed files globally for HMR
5
- let changedFilesTracker = new Set();
2
+ import { readdirSync, statSync, existsSync, mkdirSync } from "fs";
6
3
  let isInitialBuild = true;
7
- export function hmrPlugin(targetMode) {
8
- return {
9
- name: "nativescript-hmr",
10
- buildStart() {
11
- if (targetMode === "development") {
12
- console.log("🔥 Vite: Build started");
13
- // Don't clear changedFilesTracker here - we need it for writeBundle
14
- // We'll clear it in writeBundle after using it
15
- }
16
- },
17
- // Use watchChange hook to track file changes in build mode
18
- watchChange(id, { event }) {
19
- if (targetMode === "development") {
20
- const relativePath = path.relative(process.cwd(), id);
21
- // Only track changes in src directory and config files
22
- const shouldTrack = relativePath.startsWith("src/");
23
- if (!shouldTrack) {
24
- return; // Ignore changes to build outputs, platforms, node_modules, etc.
25
- }
26
- console.log(`🔥 File ${event}:`, relativePath);
27
- // Track the changed file
28
- changedFilesTracker.add(relativePath);
29
- // Log the type of change for debugging
30
- if (id.endsWith(".css") || id.endsWith(".scss")) {
31
- console.log("🔥 CSS file change detected");
32
- }
33
- else if (id.endsWith(".html")) {
34
- console.log("🔥 HTML template change detected");
35
- }
36
- else if (id.endsWith(".ts") && !id.endsWith(".d.ts")) {
37
- console.log("🔥 TypeScript file change detected");
38
- }
39
- }
40
- },
41
- // Keep handleHotUpdate for completeness, but it won't fire in build mode
42
- handleHotUpdate({ file, server, timestamp }) {
43
- if (targetMode === "development") {
44
- const relativePath = path.relative(process.cwd(), file);
45
- // Only handle HMR for src directory and config files
46
- const shouldHandle = relativePath.startsWith("src/");
47
- if (!shouldHandle) {
48
- return []; // Ignore HMR for build outputs, platforms, node_modules, etc.
49
- }
50
- console.log("🔥 HMR update detected for:", relativePath);
51
- console.log("🔥 Note: This only fires in dev server mode, not build mode");
52
- return;
53
- }
54
- },
55
- };
56
- }
57
- // NativeScript CLI integration - including IPC communication for HMR
58
- export function cliPlugin(targetMode, cliFlags) {
4
+ // NativeScript CLI integration for live reloads, non-HMR rebuilds
5
+ export function cliPlugin(distOutputFolder, isDevMode, verboseLogs, hmrActive) {
6
+ // Capture emitted files directly from Rollup hooks to avoid relying on FS state
7
+ const lastBundleFiles = new Set();
8
+ let lastOutDir;
9
+ // This plugin should not trigger NativeScript CLI rebuild/refresh cycles when HMR is active
59
10
  return {
60
11
  name: "nativescript-cli-integration",
12
+ apply: "build",
61
13
  // Ensure we run after other plugins (like vite-plugin-static-copy)
62
14
  enforce: "post",
63
15
  // Resolve build outDir so we can read final outputs after all plugins finish
64
16
  configResolved(config) {
65
- // no-op, but we keep reference on the closure via getOutDir
66
- getOutDir = () => path.resolve(config.root ?? process.cwd(), config.build?.outDir ?? "dist");
17
+ // Under HMR, when not initial build; skip - HMR client handles everything
18
+ if (hmrActive && !isInitialBuild)
19
+ return;
20
+ },
21
+ // buildStart() {
22
+ // if (hmrActive && !isInitialBuild) {
23
+ // if (debug) {
24
+ // console.log(
25
+ // "🔥 [cliPlugin] HMR active — suppressing CLI IPC + rebuild triggers",
26
+ // );
27
+ // }
28
+ // return;
29
+ // }
30
+ // if (isDevMode) {
31
+ // console.log("🔥 Vite: Build started");
32
+ // }
33
+ // },
34
+ // Use Rollup hook to record emitted file names (relative to output dir)
35
+ generateBundle(options, bundle) {
36
+ // Under HMR, still capture files on initial build
37
+ if (hmrActive && !isInitialBuild)
38
+ return;
39
+ try {
40
+ const keys = Object.keys(bundle);
41
+ for (const k of keys)
42
+ lastBundleFiles.add(k);
43
+ // Remember outDir/file from Rollup options if provided
44
+ lastOutDir =
45
+ options.dir ||
46
+ (options.file && path.dirname(options.file)) ||
47
+ undefined;
48
+ if (verboseLogs) {
49
+ console.log(`[cliPlugin] generateBundle: files=${keys.length}, dir=${lastOutDir ?? "(unknown)"}`);
50
+ if (keys.length) {
51
+ console.log("[cliPlugin] bundle keys:", keys);
52
+ }
53
+ }
54
+ }
55
+ catch {
56
+ // noop
57
+ }
67
58
  },
68
- buildStart() {
69
- if (targetMode === "development") {
70
- console.log("🔥 Vite: Build started");
59
+ // called only when writing to disk
60
+ writeBundle(options, bundle) {
61
+ // Under HMR, still capture files on initial build
62
+ if (hmrActive && !isInitialBuild)
63
+ return;
64
+ try {
65
+ const keys = Object.keys(bundle);
66
+ for (const k of keys)
67
+ lastBundleFiles.add(k);
68
+ lastOutDir =
69
+ options.dir ||
70
+ (options.file && path.dirname(options.file)) ||
71
+ lastOutDir;
72
+ if (verboseLogs) {
73
+ console.log(`[cliPlugin] writeBundle: files=${keys.length}, dir=${lastOutDir ?? "(unknown)"}`);
74
+ }
75
+ }
76
+ catch {
77
+ // noop
71
78
  }
72
79
  },
73
80
  // Defer CLI notification until after all plugins (including static copy) are done.
74
81
  closeBundle() {
75
- if (targetMode !== "development")
82
+ if (hmrActive && !isInitialBuild) {
83
+ // Reset trackers to avoid leaking state between builds even if no-op
84
+ lastBundleFiles.clear();
85
+ lastOutDir = undefined;
86
+ return;
87
+ }
88
+ if (!isDevMode)
76
89
  return;
77
90
  const buildType = isInitialBuild ? "initial" : "incremental";
78
- console.log(`🔥 NativeScript: ${buildType} build completed`);
79
- // After static copy has finished, read actual dist contents
80
- const distDir = getOutDir();
81
- const emittedFiles = listFilesFlat(distDir);
82
- // Determine what changed
83
- const changedFilesList = Array.from(changedFilesTracker);
84
- const hasHTMLChanges = changedFilesList.some((f) => f.endsWith(".html"));
85
- const hasCSSChanges = changedFilesList.some((f) => f.endsWith(".css") || f.endsWith(".scss"));
86
- const hasComponentChanges = changedFilesList.some((f) => f.includes(".component."));
87
- const canUseHMR = !isInitialBuild &&
88
- changedFilesList.length > 0 &&
89
- (hasHTMLChanges || hasCSSChanges || hasComponentChanges);
90
- const isHMR = canUseHMR && cliFlags.hmr;
91
- if (changedFilesList.length > 0) {
92
- console.log("🔥 Changed files triggered rebuild:", changedFilesList);
93
- console.log("🔥 Can use HMR:", canUseHMR);
91
+ if (verboseLogs) {
92
+ console.log(`NativeScript: ${buildType} build completed.`);
94
93
  }
95
- if (changedFilesList.some((f) => f.endsWith(".ts"))) {
96
- console.log("🔥 TypeScript changes detected - full rebuild required");
94
+ // Determine outDir and ensure it exists in dev for a clean start
95
+ const distDir = lastOutDir || distOutputFolder;
96
+ if (!existsSync(distDir)) {
97
+ try {
98
+ mkdirSync(distDir, { recursive: true });
99
+ }
100
+ catch {
101
+ // ignore; listing will just return []
102
+ }
97
103
  }
98
- if (hasCSSChanges) {
99
- console.log("🔥 CSS changes detected - could be optimized for HMR in future");
104
+ // Prefer Rollup-reported bundle files; fall back to FS scan
105
+ const emittedFiles = lastBundleFiles.size
106
+ ? Array.from(lastBundleFiles)
107
+ : listFilesFlat(distDir);
108
+ if (verboseLogs) {
109
+ console.log(`[cliPlugin] closeBundle: distDir=${distDir}, captured=${lastBundleFiles.size}, fsScan=${emittedFiles.length}`);
100
110
  }
101
- if (hasHTMLChanges) {
102
- console.log("🔥 HTML template changes detected - using HMR");
111
+ if (verboseLogs) {
112
+ console.log(`Emitted ${emittedFiles.length} files in ${buildType} build.`);
103
113
  }
104
- console.log(`🔥 Emitted ${emittedFiles.length} files in ${buildType} build`);
105
114
  if (process.send) {
106
- const message = {
107
- emittedFiles,
108
- chunkFiles: emittedFiles.filter((f) => f.includes("chunk") || f.includes("vendor")),
109
- hash: Date.now().toString(),
110
- isHMR: isHMR && !isInitialBuild,
111
- changedFiles: changedFilesList,
112
- buildType,
113
- timestamp: Date.now(),
115
+ const sendMessage = (files) => {
116
+ const message = {
117
+ emittedFiles: files,
118
+ chunkFiles: files.filter((f) => f.includes("chunk") || f.includes("vendor")),
119
+ hash: Date.now().toString(),
120
+ isHMR: false,
121
+ buildType,
122
+ timestamp: Date.now(),
123
+ };
124
+ if (verboseLogs) {
125
+ console.log(`Sending ${buildType} build notification to CLI.`);
126
+ }
127
+ process.send(message);
114
128
  };
115
- console.log(`🔥 Sending ${buildType} build notification to CLI (isHMR: ${message.isHMR})`);
116
- if (changedFilesList.length > 0) {
117
- console.log("🔥 IPC includes changed files:", changedFilesList);
129
+ if (emittedFiles.length === 0) {
130
+ // Allow a short delay for any late FS writes by other post plugins
131
+ setTimeout(() => {
132
+ const rescanned = listFilesFlat(distDir);
133
+ if (verboseLogs) {
134
+ console.log(`[cliPlugin] delayed rescan found ${rescanned.length} files in ${distDir}`);
135
+ }
136
+ sendMessage(rescanned);
137
+ }, 50);
138
+ }
139
+ else {
140
+ sendMessage(emittedFiles);
118
141
  }
119
- process.send(message);
120
142
  }
121
143
  if (isInitialBuild) {
122
144
  isInitialBuild = false;
123
- console.log("🔥 Initial build complete - subsequent changes will trigger fast rebuilds");
145
+ if (verboseLogs) {
146
+ console.log("Initial build complete - subsequent changes will trigger fast rebuilds");
147
+ }
124
148
  }
125
- changedFilesTracker.clear();
149
+ lastBundleFiles.clear();
150
+ lastOutDir = undefined;
126
151
  },
127
152
  };
128
153
  }
129
- // Helper to get outDir resolved at runtime
130
- let getOutDir = () => path.resolve(process.cwd(), "dist");
131
154
  // Recursively list files under a directory and return relative paths
132
155
  function listFilesFlat(rootDir) {
133
156
  const results = [];
@@ -1,4 +1,4 @@
1
- export declare function packagePlatformAliases(tsConfigData: any, platform: string, debugViteLogs?: boolean): {
1
+ export declare function packagePlatformAliases(tsConfigData: any, platform: string, verboseLogs?: boolean): {
2
2
  find: RegExp;
3
3
  replacement: (id: any) => any;
4
4
  };
@@ -3,7 +3,7 @@ import fs from "fs";
3
3
  import { findPackageInNodeModules } from "./module-resolution.js";
4
4
  import { getProjectRootPath } from "./project.js";
5
5
  const projectRoot = getProjectRootPath();
6
- export function packagePlatformAliases(tsConfigData, platform, debugViteLogs) {
6
+ export function packagePlatformAliases(tsConfigData, platform, verboseLogs) {
7
7
  // packages used via core transient dependencies and other vite support
8
8
  const commonSkips = [
9
9
  "source-map-js",
@@ -39,7 +39,7 @@ export function packagePlatformAliases(tsConfigData, platform, debugViteLogs) {
39
39
  // Try platform-specific file first
40
40
  const platformFile = path.join(packagePath, `${mainField}.${platform}.js`);
41
41
  if (fs.existsSync(platformFile)) {
42
- if (debugViteLogs) {
42
+ if (verboseLogs) {
43
43
  console.log(`✅ Alias resolver: ${packageName} -> ${mainField}.${platform}.js (extensionless)`);
44
44
  }
45
45
  return platformFile;
@@ -47,7 +47,7 @@ export function packagePlatformAliases(tsConfigData, platform, debugViteLogs) {
47
47
  // Fallback to .js
48
48
  const jsFile = path.join(packagePath, `${mainField}.js`);
49
49
  if (fs.existsSync(jsFile)) {
50
- if (debugViteLogs) {
50
+ if (verboseLogs) {
51
51
  console.log(`✅ Alias resolver: ${packageName} -> ${mainField}.js (extensionless)`);
52
52
  }
53
53
  return jsFile;
@@ -61,7 +61,7 @@ export function packagePlatformAliases(tsConfigData, platform, debugViteLogs) {
61
61
  // Try platform-specific file first
62
62
  const platformFile = path.join(packagePath, `${baseName}.${platform}${ext}`);
63
63
  if (fs.existsSync(platformFile)) {
64
- if (debugViteLogs) {
64
+ if (verboseLogs) {
65
65
  console.log(`✅ Alias resolver: ${packageName} -> ${baseName}.${platform}${ext} (missing main)`);
66
66
  }
67
67
  return platformFile;
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from 'vite';
2
+ export declare function preserveImportsPlugin(): Plugin;
@@ -0,0 +1,19 @@
1
+ // Marks modules imported with `?ns-keep` as side-effectful so Rollup won't tree-shake them.
2
+ export function preserveImportsPlugin() {
3
+ return {
4
+ name: 'ns-preserve-imports',
5
+ // run early so downstream plugins see the preserved flag
6
+ enforce: 'pre',
7
+ async transform(code, id) {
8
+ if (id.includes('?ns-keep')) {
9
+ return {
10
+ code,
11
+ map: null,
12
+ // ensure side effects are preserved even if bindings are unused
13
+ moduleSideEffects: true,
14
+ };
15
+ }
16
+ return null;
17
+ },
18
+ };
19
+ }
@@ -1,4 +1,4 @@
1
- export declare const getTsConfigData: (debugViteLogs: boolean, platform: string) => {
1
+ export declare const getTsConfigData: (verboseLogs: boolean, platform: string) => {
2
2
  data: any;
3
3
  aliases: any[];
4
4
  };
@@ -134,7 +134,9 @@ function createTsConfigAliases(paths, baseUrl, platform, debugViteLogs) {
134
134
  const resolvedDestination = path.isAbsolute(destination)
135
135
  ? destination
136
136
  : path.resolve(projectRoot, baseUrl, destination);
137
- console.log(`📁 Creating wildcard alias: ${aliasKey} -> ${resolvedDestination}`);
137
+ // console.log(
138
+ // `📁 Creating wildcard alias: ${aliasKey} -> ${resolvedDestination}`,
139
+ // );
138
140
  aliases.push({
139
141
  find: new RegExp(`^${aliasKey.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?:/(.*))?$`),
140
142
  replacement: (match, subpath) => {
@@ -219,7 +221,7 @@ function createTsConfigAliases(paths, baseUrl, platform, debugViteLogs) {
219
221
  }
220
222
  // Get TypeScript path configuration
221
223
  let tsConfigData;
222
- export const getTsConfigData = (debugViteLogs, platform) => {
224
+ export const getTsConfigData = (verboseLogs, platform) => {
223
225
  tsConfigPath = getProjectFilePath("tsconfig.app.json");
224
226
  if (!fs.existsSync(tsConfigPath)) {
225
227
  tsConfigPath = getProjectFilePath("tsconfig.json");
@@ -227,11 +229,11 @@ export const getTsConfigData = (debugViteLogs, platform) => {
227
229
  if (!tsConfigData) {
228
230
  tsConfigData = getTsConfigPaths();
229
231
  }
230
- if (debugViteLogs) {
232
+ if (verboseLogs) {
231
233
  console.log("📁 Loaded TypeScript path configuration");
232
234
  }
233
235
  const aliases = createTsConfigAliases(tsConfigData.paths, tsConfigData.baseUrl, platform);
234
- if (aliases.length > 0 && debugViteLogs) {
236
+ if (aliases.length > 0 && verboseLogs) {
235
237
  console.log("📁 Created TypeScript path aliases:", aliases.length);
236
238
  }
237
239
  return {
@@ -0,0 +1,6 @@
1
+ export declare function initHmrClient(opts?: {
2
+ wsUrl?: string;
3
+ }): void;
4
+ export default function startViteHMR(opts?: {
5
+ wsUrl?: string;
6
+ }): void;