@nativescript/vite 0.0.1-alpha.1 → 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.
- package/dist/configuration/base.js +134 -36
- package/dist/helpers/external-configs.js +1 -1
- package/dist/helpers/global-defines.d.ts +1 -0
- package/dist/helpers/global-defines.js +2 -0
- package/dist/helpers/main-entry-hmr-includes.d.ts +1 -0
- package/dist/helpers/main-entry-hmr-includes.js +18 -0
- package/dist/helpers/main-entry.d.ts +2 -2
- package/dist/helpers/main-entry.js +58 -94
- package/dist/helpers/module-runner-patch.d.ts +3 -0
- package/dist/helpers/module-runner-patch.js +65 -0
- package/dist/helpers/ns-cli-plugins.d.ts +1 -14
- package/dist/helpers/ns-cli-plugins.js +54 -107
- package/dist/helpers/package-platform-aliases.d.ts +1 -1
- package/dist/helpers/package-platform-aliases.js +4 -4
- package/dist/helpers/ts-config-paths.d.ts +1 -1
- package/dist/helpers/ts-config-paths.js +3 -3
- package/dist/hmr/client-vue.d.ts +6 -0
- package/dist/hmr/client-vue.js +563 -0
- package/dist/hmr/component-tracker.d.ts +23 -0
- package/dist/hmr/component-tracker.js +193 -0
- package/dist/hmr/css-handler.d.ts +4 -0
- package/dist/hmr/css-handler.js +77 -0
- package/dist/hmr/message-handler.d.ts +1 -0
- package/dist/hmr/message-handler.js +590 -0
- package/dist/hmr/nsv-hooks.d.ts +2 -0
- package/dist/hmr/nsv-hooks.js +481 -0
- package/dist/hmr/plugin-vue.d.ts +2 -0
- package/dist/hmr/plugin-vue.js +38 -0
- package/dist/hmr/plugins/index.d.ts +1 -0
- package/dist/hmr/plugins/index.js +16 -0
- package/dist/hmr/plugins/plugin-vue.d.ts +2 -0
- package/dist/hmr/plugins/plugin-vue.js +41 -0
- package/dist/hmr/plugins/websocket-vue.d.ts +2 -0
- package/dist/hmr/plugins/websocket-vue.js +882 -0
- package/dist/hmr/runtime-vue.d.ts +13 -0
- package/dist/hmr/runtime-vue.js +2306 -0
- package/dist/hmr/types.d.ts +24 -0
- package/dist/hmr/types.js +2 -0
- package/dist/hmr/websocket-vue.d.ts +2 -0
- package/dist/hmr/websocket-vue.js +875 -0
- package/dist/shims/node-module.d.ts +5 -0
- package/dist/shims/node-module.js +12 -0
- package/package.json +2 -1
- package/dist/configuration/old-without-merge-base.d.ts +0 -13
- package/dist/configuration/old-without-merge-base.js +0 -249
- package/dist/helpers/side-effects.d.ts +0 -14
- package/dist/helpers/side-effects.js +0 -69
- package/dist/hmr/hmr-angular.d.ts +0 -1
- package/dist/hmr/hmr-angular.js +0 -34
- package/dist/hmr/hmr-bridge.d.ts +0 -18
- package/dist/hmr/hmr-bridge.js +0 -154
- package/dist/hmr/hmr-client.d.ts +0 -5
- package/dist/hmr/hmr-client.js +0 -93
- package/dist/hmr/hmr-server.d.ts +0 -20
- package/dist/hmr/hmr-server.js +0 -179
|
@@ -1,65 +1,12 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { readdirSync, statSync, existsSync, mkdirSync } from "fs";
|
|
3
|
-
// NativeScript HMR integration - track changes for incremental builds
|
|
4
|
-
// Track changed files globally for HMR
|
|
5
|
-
let changedFilesTracker = new Set();
|
|
6
3
|
let isInitialBuild = true;
|
|
7
|
-
|
|
8
|
-
|
|
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) {
|
|
59
6
|
// Capture emitted files directly from Rollup hooks to avoid relying on FS state
|
|
60
7
|
const lastBundleFiles = new Set();
|
|
61
8
|
let lastOutDir;
|
|
62
|
-
|
|
9
|
+
// This plugin should not trigger NativeScript CLI rebuild/refresh cycles when HMR is active
|
|
63
10
|
return {
|
|
64
11
|
name: "nativescript-cli-integration",
|
|
65
12
|
apply: "build",
|
|
@@ -67,16 +14,28 @@ export function cliPlugin(targetMode, cliFlags) {
|
|
|
67
14
|
enforce: "post",
|
|
68
15
|
// Resolve build outDir so we can read final outputs after all plugins finish
|
|
69
16
|
configResolved(config) {
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
buildStart() {
|
|
74
|
-
if (targetMode === "development") {
|
|
75
|
-
console.log("🔥 Vite: Build started");
|
|
76
|
-
}
|
|
17
|
+
// Under HMR, when not initial build; skip - HMR client handles everything
|
|
18
|
+
if (hmrActive && !isInitialBuild)
|
|
19
|
+
return;
|
|
77
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
|
+
// },
|
|
78
34
|
// Use Rollup hook to record emitted file names (relative to output dir)
|
|
79
35
|
generateBundle(options, bundle) {
|
|
36
|
+
// Under HMR, still capture files on initial build
|
|
37
|
+
if (hmrActive && !isInitialBuild)
|
|
38
|
+
return;
|
|
80
39
|
try {
|
|
81
40
|
const keys = Object.keys(bundle);
|
|
82
41
|
for (const k of keys)
|
|
@@ -86,10 +45,10 @@ export function cliPlugin(targetMode, cliFlags) {
|
|
|
86
45
|
options.dir ||
|
|
87
46
|
(options.file && path.dirname(options.file)) ||
|
|
88
47
|
undefined;
|
|
89
|
-
if (
|
|
90
|
-
console.log(
|
|
48
|
+
if (verboseLogs) {
|
|
49
|
+
console.log(`[cliPlugin] generateBundle: files=${keys.length}, dir=${lastOutDir ?? "(unknown)"}`);
|
|
91
50
|
if (keys.length) {
|
|
92
|
-
console.log("
|
|
51
|
+
console.log("[cliPlugin] bundle keys:", keys);
|
|
93
52
|
}
|
|
94
53
|
}
|
|
95
54
|
}
|
|
@@ -97,8 +56,11 @@ export function cliPlugin(targetMode, cliFlags) {
|
|
|
97
56
|
// noop
|
|
98
57
|
}
|
|
99
58
|
},
|
|
100
|
-
//
|
|
59
|
+
// called only when writing to disk
|
|
101
60
|
writeBundle(options, bundle) {
|
|
61
|
+
// Under HMR, still capture files on initial build
|
|
62
|
+
if (hmrActive && !isInitialBuild)
|
|
63
|
+
return;
|
|
102
64
|
try {
|
|
103
65
|
const keys = Object.keys(bundle);
|
|
104
66
|
for (const k of keys)
|
|
@@ -107,8 +69,8 @@ export function cliPlugin(targetMode, cliFlags) {
|
|
|
107
69
|
options.dir ||
|
|
108
70
|
(options.file && path.dirname(options.file)) ||
|
|
109
71
|
lastOutDir;
|
|
110
|
-
if (
|
|
111
|
-
console.log(
|
|
72
|
+
if (verboseLogs) {
|
|
73
|
+
console.log(`[cliPlugin] writeBundle: files=${keys.length}, dir=${lastOutDir ?? "(unknown)"}`);
|
|
112
74
|
}
|
|
113
75
|
}
|
|
114
76
|
catch {
|
|
@@ -117,12 +79,20 @@ export function cliPlugin(targetMode, cliFlags) {
|
|
|
117
79
|
},
|
|
118
80
|
// Defer CLI notification until after all plugins (including static copy) are done.
|
|
119
81
|
closeBundle() {
|
|
120
|
-
if (
|
|
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)
|
|
121
89
|
return;
|
|
122
90
|
const buildType = isInitialBuild ? "initial" : "incremental";
|
|
123
|
-
|
|
91
|
+
if (verboseLogs) {
|
|
92
|
+
console.log(`NativeScript: ${buildType} build completed.`);
|
|
93
|
+
}
|
|
124
94
|
// Determine outDir and ensure it exists in dev for a clean start
|
|
125
|
-
const distDir = lastOutDir ||
|
|
95
|
+
const distDir = lastOutDir || distOutputFolder;
|
|
126
96
|
if (!existsSync(distDir)) {
|
|
127
97
|
try {
|
|
128
98
|
mkdirSync(distDir, { recursive: true });
|
|
@@ -135,46 +105,24 @@ export function cliPlugin(targetMode, cliFlags) {
|
|
|
135
105
|
const emittedFiles = lastBundleFiles.size
|
|
136
106
|
? Array.from(lastBundleFiles)
|
|
137
107
|
: listFilesFlat(distDir);
|
|
138
|
-
if (
|
|
139
|
-
console.log(
|
|
140
|
-
}
|
|
141
|
-
// Determine what changed
|
|
142
|
-
const changedFilesList = Array.from(changedFilesTracker);
|
|
143
|
-
const hasHTMLChanges = changedFilesList.some((f) => f.endsWith(".html"));
|
|
144
|
-
const hasCSSChanges = changedFilesList.some((f) => f.endsWith(".css") || f.endsWith(".scss"));
|
|
145
|
-
const hasComponentChanges = changedFilesList.some((f) => f.includes(".component."));
|
|
146
|
-
const canUseHMR = !isInitialBuild &&
|
|
147
|
-
changedFilesList.length > 0 &&
|
|
148
|
-
(hasHTMLChanges || hasCSSChanges || hasComponentChanges);
|
|
149
|
-
const isHMR = canUseHMR && cliFlags.hmr;
|
|
150
|
-
if (changedFilesList.length > 0) {
|
|
151
|
-
console.log("🔥 Changed files triggered rebuild:", changedFilesList);
|
|
152
|
-
console.log("🔥 Can use HMR:", canUseHMR);
|
|
108
|
+
if (verboseLogs) {
|
|
109
|
+
console.log(`[cliPlugin] closeBundle: distDir=${distDir}, captured=${lastBundleFiles.size}, fsScan=${emittedFiles.length}`);
|
|
153
110
|
}
|
|
154
|
-
if (
|
|
155
|
-
console.log(
|
|
111
|
+
if (verboseLogs) {
|
|
112
|
+
console.log(`Emitted ${emittedFiles.length} files in ${buildType} build.`);
|
|
156
113
|
}
|
|
157
|
-
if (hasCSSChanges) {
|
|
158
|
-
console.log("🔥 CSS changes detected - could be optimized for HMR in future");
|
|
159
|
-
}
|
|
160
|
-
if (hasHTMLChanges) {
|
|
161
|
-
console.log("🔥 HTML template changes detected - using HMR");
|
|
162
|
-
}
|
|
163
|
-
console.log(`🔥 Emitted ${emittedFiles.length} files in ${buildType} build`);
|
|
164
114
|
if (process.send) {
|
|
165
115
|
const sendMessage = (files) => {
|
|
166
116
|
const message = {
|
|
167
117
|
emittedFiles: files,
|
|
168
118
|
chunkFiles: files.filter((f) => f.includes("chunk") || f.includes("vendor")),
|
|
169
119
|
hash: Date.now().toString(),
|
|
170
|
-
isHMR:
|
|
171
|
-
changedFiles: changedFilesList,
|
|
120
|
+
isHMR: false,
|
|
172
121
|
buildType,
|
|
173
122
|
timestamp: Date.now(),
|
|
174
123
|
};
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
console.log("🔥 IPC includes changed files:", changedFilesList);
|
|
124
|
+
if (verboseLogs) {
|
|
125
|
+
console.log(`Sending ${buildType} build notification to CLI.`);
|
|
178
126
|
}
|
|
179
127
|
process.send(message);
|
|
180
128
|
};
|
|
@@ -182,8 +130,8 @@ export function cliPlugin(targetMode, cliFlags) {
|
|
|
182
130
|
// Allow a short delay for any late FS writes by other post plugins
|
|
183
131
|
setTimeout(() => {
|
|
184
132
|
const rescanned = listFilesFlat(distDir);
|
|
185
|
-
if (
|
|
186
|
-
console.log(
|
|
133
|
+
if (verboseLogs) {
|
|
134
|
+
console.log(`[cliPlugin] delayed rescan found ${rescanned.length} files in ${distDir}`);
|
|
187
135
|
}
|
|
188
136
|
sendMessage(rescanned);
|
|
189
137
|
}, 50);
|
|
@@ -194,16 +142,15 @@ export function cliPlugin(targetMode, cliFlags) {
|
|
|
194
142
|
}
|
|
195
143
|
if (isInitialBuild) {
|
|
196
144
|
isInitialBuild = false;
|
|
197
|
-
|
|
145
|
+
if (verboseLogs) {
|
|
146
|
+
console.log("Initial build complete - subsequent changes will trigger fast rebuilds");
|
|
147
|
+
}
|
|
198
148
|
}
|
|
199
|
-
changedFilesTracker.clear();
|
|
200
149
|
lastBundleFiles.clear();
|
|
201
150
|
lastOutDir = undefined;
|
|
202
151
|
},
|
|
203
152
|
};
|
|
204
153
|
}
|
|
205
|
-
// Helper to get outDir resolved at runtime
|
|
206
|
-
let getOutDir = () => path.resolve(process.cwd(), "dist");
|
|
207
154
|
// Recursively list files under a directory and return relative paths
|
|
208
155
|
function listFilesFlat(rootDir) {
|
|
209
156
|
const results = [];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function packagePlatformAliases(tsConfigData: any, platform: string,
|
|
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,
|
|
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 (
|
|
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 (
|
|
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 (
|
|
64
|
+
if (verboseLogs) {
|
|
65
65
|
console.log(`✅ Alias resolver: ${packageName} -> ${baseName}.${platform}${ext} (missing main)`);
|
|
66
66
|
}
|
|
67
67
|
return platformFile;
|
|
@@ -221,7 +221,7 @@ function createTsConfigAliases(paths, baseUrl, platform, debugViteLogs) {
|
|
|
221
221
|
}
|
|
222
222
|
// Get TypeScript path configuration
|
|
223
223
|
let tsConfigData;
|
|
224
|
-
export const getTsConfigData = (
|
|
224
|
+
export const getTsConfigData = (verboseLogs, platform) => {
|
|
225
225
|
tsConfigPath = getProjectFilePath("tsconfig.app.json");
|
|
226
226
|
if (!fs.existsSync(tsConfigPath)) {
|
|
227
227
|
tsConfigPath = getProjectFilePath("tsconfig.json");
|
|
@@ -229,11 +229,11 @@ export const getTsConfigData = (debugViteLogs, platform) => {
|
|
|
229
229
|
if (!tsConfigData) {
|
|
230
230
|
tsConfigData = getTsConfigPaths();
|
|
231
231
|
}
|
|
232
|
-
if (
|
|
232
|
+
if (verboseLogs) {
|
|
233
233
|
console.log("📁 Loaded TypeScript path configuration");
|
|
234
234
|
}
|
|
235
235
|
const aliases = createTsConfigAliases(tsConfigData.paths, tsConfigData.baseUrl, platform);
|
|
236
|
-
if (aliases.length > 0 &&
|
|
236
|
+
if (aliases.length > 0 && verboseLogs) {
|
|
237
237
|
console.log("📁 Created TypeScript path aliases:", aliases.length);
|
|
238
238
|
}
|
|
239
239
|
return {
|