nativescript 9.0.0-alpha.3 → 9.0.0-alpha.5

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.
@@ -1 +1,16 @@
1
- {"@jsdevtools/coverage-istanbul-loader":"3.0.5","karma":"6.4.4","karma-coverage":"2.2.1","karma-nativescript-launcher":"1.0.0","mocha":"11.7.1","karma-mocha":"2.0.1","karma-chai":"0.1.0","karma-jasmine":"4.0.2","karma-qunit":"4.2.1","@types/karma-chai":"0.1.7","@types/mocha":"10.0.10","@types/jasmine":"5.1.8","@types/qunit":"2.19.12","nyc":"17.1.0"}
1
+ {
2
+ "@jsdevtools/coverage-istanbul-loader": "3.0.5",
3
+ "karma": "6.4.4",
4
+ "karma-coverage": "2.2.1",
5
+ "karma-nativescript-launcher": "1.0.0",
6
+ "mocha": "11.7.1",
7
+ "karma-mocha": "2.0.1",
8
+ "karma-chai": "0.1.0",
9
+ "karma-jasmine": "4.0.2",
10
+ "karma-qunit": "4.2.1",
11
+ "@types/karma-chai": "0.1.7",
12
+ "@types/mocha": "10.0.10",
13
+ "@types/jasmine": "5.1.8",
14
+ "@types/qunit": "2.19.13",
15
+ "nyc": "17.1.0"
16
+ }
@@ -108,7 +108,7 @@ class HooksService {
108
108
  let inProc = false;
109
109
  if (!command) {
110
110
  command = hook.fullPath;
111
- if ([".mjs", ".js"].includes(path.extname(hook.fullPath).toLowerCase())) {
111
+ if ([".mjs", ".cjs", ".js"].includes(path.extname(hook.fullPath).toLowerCase())) {
112
112
  command = process.argv[0];
113
113
  inProc = isESM
114
114
  ? true
@@ -44,14 +44,87 @@ class BundlerCompilerService extends events_1.EventEmitter {
44
44
  prepareData.watch = true;
45
45
  try {
46
46
  const childProcess = await this.startBundleProcess(platformData, projectData, prepareData);
47
+ // Handle Vite differently from webpack
48
+ const isVite = this.getBundler() === "vite";
47
49
  childProcess.stdout.on("data", function (data) {
48
50
  process.stdout.write(data);
49
51
  });
50
52
  childProcess.stderr.on("data", function (data) {
51
53
  process.stderr.write(data);
52
54
  });
55
+ // For both Vite and webpack, we wait for the first build to complete
56
+ // Don't resolve immediately for Vite - wait for first IPC message
53
57
  childProcess.on("message", (message) => {
54
58
  this.$logger.trace(`Message from ${projectData.bundler}`, message);
59
+ // Handle Vite messages
60
+ if (isVite &&
61
+ message &&
62
+ message.emittedFiles) {
63
+ message = message;
64
+ console.log("Received Vite IPC message:", message);
65
+ // Copy Vite output files directly to platform destination
66
+ const distOutput = path.join(projectData.projectDir, "dist");
67
+ const destDir = path.join(platformData.appDestinationDirectoryPath, this.$options.hostProjectModuleName);
68
+ console.log(`🔥 Copying from ${distOutput} to ${destDir}`);
69
+ // For HMR updates, only copy changed files; for full builds, copy everything
70
+ if (message.isHMR &&
71
+ message.changedFiles &&
72
+ message.changedFiles.length > 0) {
73
+ console.log("🔥 HMR update - copying only changed files for:", message.changedFiles);
74
+ // For HTML template changes, we need to copy the component files that were rebuilt
75
+ let filesToCopy = message.emittedFiles;
76
+ // If we have HTML changes, identify which component files need copying
77
+ const hasHTMLChanges = message.changedFiles.some((f) => f.endsWith(".html"));
78
+ if (hasHTMLChanges) {
79
+ // Copy component-related files (the ones that would have been rebuilt due to template changes)
80
+ filesToCopy = message.emittedFiles.filter((f) => f.includes(".component") ||
81
+ f === "bundle.mjs" ||
82
+ f === "bundle.mjs.map");
83
+ console.log("🔥 HTML change detected - copying component files:", filesToCopy);
84
+ }
85
+ this.copyViteBundleToNative(distOutput, destDir, filesToCopy);
86
+ }
87
+ else {
88
+ console.log("🔥 Full build - copying all files");
89
+ this.copyViteBundleToNative(distOutput, destDir);
90
+ }
91
+ // Resolve the promise on first build completion
92
+ if (isFirstBundlerWatchCompilation) {
93
+ isFirstBundlerWatchCompilation = false;
94
+ console.log("Vite first build completed, resolving compileWithWatch");
95
+ resolve(childProcess);
96
+ }
97
+ // Transform Vite message to match webpack format
98
+ const files = message.emittedFiles.map((file) => path.join(platformData.appDestinationDirectoryPath, this.$options.hostProjectModuleName, file));
99
+ const data = {
100
+ files,
101
+ hasOnlyHotUpdateFiles: message.isHMR || false,
102
+ hmrData: {
103
+ hash: message.hash || "",
104
+ fallbackFiles: [],
105
+ },
106
+ platform: platformData.platformNameLowerCase,
107
+ };
108
+ this.$logger.info(`Vite build completed! Files copied to native platform.`);
109
+ // Send HMR notification to connected WebSocket clients first
110
+ this.notifyHMRClients({
111
+ type: message.isHMR ? "js-update" : "build-complete",
112
+ timestamp: Date.now(),
113
+ changedFiles: message.changedFiles || [],
114
+ buildType: message.buildType || "incremental",
115
+ isHMR: message.isHMR || false,
116
+ });
117
+ if (message.isHMR) {
118
+ console.log("🔥 Skipping BUNDLER_COMPILATION_COMPLETE for HMR update - app will not restart");
119
+ }
120
+ else {
121
+ // Only emit BUNDLER_COMPILATION_COMPLETE for non-HMR builds
122
+ // This prevents the CLI from restarting the app during HMR updates
123
+ console.log("🔥 Emitting BUNDLER_COMPILATION_COMPLETE for full build");
124
+ this.emit(constants_1.BUNDLER_COMPILATION_COMPLETE, data);
125
+ }
126
+ return;
127
+ }
55
128
  // if we are on webpack5 - we handle HMR in a slightly different way
56
129
  if (typeof message === "object" &&
57
130
  "version" in message &&
@@ -126,20 +199,6 @@ class BundlerCompilerService extends events_1.EventEmitter {
126
199
  childProcess.on("close", async (arg) => {
127
200
  const exitCode = typeof arg === "number" ? arg : arg && arg.code;
128
201
  this.$logger.trace(`${capitalizeFirstLetter(projectData.bundler)} process exited with code ${exitCode} when we expected it to be long living with watch.`);
129
- if (this.getBundler() === "vite" && exitCode === 0) {
130
- // note experimental: investigate watch mode
131
- const bundlePath = path.join(projectData.projectDir, "dist/bundle.js");
132
- console.log("bundlePath:", bundlePath);
133
- const data = {
134
- files: [bundlePath],
135
- hasOnlyHotUpdateFiles: false,
136
- hmrData: {},
137
- platform: platformData.platformNameLowerCase,
138
- };
139
- this.emit(constants_1.BUNDLER_COMPILATION_COMPLETE, data);
140
- resolve(1);
141
- return;
142
- }
143
202
  await this.$cleanupService.removeKillProcess(childProcess.pid.toString());
144
203
  const error = new Error(`Executing ${projectData.bundler} failed with exit code ${exitCode}.`);
145
204
  error.code = exitCode;
@@ -219,7 +278,12 @@ class BundlerCompilerService extends events_1.EventEmitter {
219
278
  const cliArgs = await this.buildEnvCommandLineParams(envData, platformData, projectData, prepareData);
220
279
  // Note: With Vite, we need `--` to prevent vite cli from erroring on unknown options.
221
280
  const envParams = isVite
222
- ? [`--mode=${platformData.platformNameLowerCase}`, "--", ...cliArgs]
281
+ ? [
282
+ `--mode=${platformData.platformNameLowerCase}`,
283
+ `--watch`,
284
+ "--",
285
+ ...cliArgs,
286
+ ]
223
287
  : cliArgs;
224
288
  const additionalNodeArgs = semver.major(process.version) <= 8 ? ["--harmony"] : [];
225
289
  if (await this.shouldUsePreserveSymlinksOption()) {
@@ -231,7 +295,7 @@ class BundlerCompilerService extends events_1.EventEmitter {
231
295
  const args = [
232
296
  ...additionalNodeArgs,
233
297
  this.getBundlerExecutablePath(projectData),
234
- this.isModernBundler(projectData) ? `build` : null,
298
+ isVite ? "build" : this.isModernBundler(projectData) ? `build` : null,
235
299
  `--config=${projectData.bundlerConfigPath}`,
236
300
  ...envParams,
237
301
  ].filter(Boolean);
@@ -240,7 +304,7 @@ class BundlerCompilerService extends events_1.EventEmitter {
240
304
  args.push("--watch");
241
305
  }
242
306
  }
243
- const stdio = prepareData.watch ? ["ipc"] : "inherit";
307
+ const stdio = prepareData.watch || isVite ? ["ipc"] : "inherit";
244
308
  const options = {
245
309
  cwd: projectData.projectDir,
246
310
  stdio,
@@ -483,6 +547,83 @@ class BundlerCompilerService extends events_1.EventEmitter {
483
547
  getBundler() {
484
548
  return this.$projectConfigService.getValue(`bundler`, "webpack");
485
549
  }
550
+ copyViteBundleToNative(distOutput, destDir, specificFiles = null) {
551
+ // Clean and copy Vite output to native platform folder
552
+ console.log(`Copying Vite bundle from "${distOutput}" to "${destDir}"`);
553
+ const fs = require("fs");
554
+ try {
555
+ if (specificFiles) {
556
+ // HMR mode: only copy specific files
557
+ console.log("🔥 HMR: Copying specific files:", specificFiles);
558
+ // Ensure destination directory exists
559
+ fs.mkdirSync(destDir, { recursive: true });
560
+ // Copy only the specified files
561
+ for (const file of specificFiles) {
562
+ const srcPath = path.join(distOutput, file);
563
+ const destPath = path.join(destDir, file);
564
+ if (!fs.existsSync(srcPath))
565
+ continue;
566
+ // create parent dirs
567
+ fs.mkdirSync(path.dirname(destPath), { recursive: true });
568
+ fs.copyFileSync(srcPath, destPath);
569
+ console.log(`🔥 HMR: Copied ${file}`);
570
+ }
571
+ }
572
+ else {
573
+ // Full build mode: clean and copy everything
574
+ console.log("🔥 Full build: Copying all files");
575
+ // Clean destination directory
576
+ if (fs.existsSync(destDir)) {
577
+ fs.rmSync(destDir, { recursive: true, force: true });
578
+ }
579
+ fs.mkdirSync(destDir, { recursive: true });
580
+ // Copy all files from dist to platform destination
581
+ if (fs.existsSync(distOutput)) {
582
+ this.copyRecursiveSync(distOutput, destDir, fs);
583
+ }
584
+ else {
585
+ this.$logger.warn(`Vite output directory does not exist: ${distOutput}`);
586
+ }
587
+ }
588
+ }
589
+ catch (error) {
590
+ this.$logger.warn(`Failed to copy Vite bundle: ${error.message}`);
591
+ }
592
+ }
593
+ notifyHMRClients(message) {
594
+ // Send WebSocket notification to HMR clients
595
+ try {
596
+ const WebSocket = require("ws");
597
+ // Try to connect to HMR bridge and send notification
598
+ const ws = new WebSocket("ws://localhost:24678");
599
+ ws.on("open", () => {
600
+ console.log("🔥 Sending HMR notification to bridge:", message.type);
601
+ ws.send(JSON.stringify(message));
602
+ ws.close();
603
+ });
604
+ ws.on("error", () => {
605
+ // HMR bridge not available, which is fine
606
+ console.log("🔥 HMR bridge not available (this is normal without HMR)");
607
+ });
608
+ }
609
+ catch (error) {
610
+ // WebSocket not available, which is fine
611
+ console.log("🔥 WebSocket not available for HMR notifications");
612
+ }
613
+ }
614
+ copyRecursiveSync(src, dest, fs) {
615
+ for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
616
+ const srcPath = path.join(src, entry.name);
617
+ const destPath = path.join(dest, entry.name);
618
+ if (entry.isDirectory()) {
619
+ fs.mkdirSync(destPath, { recursive: true });
620
+ this.copyRecursiveSync(srcPath, destPath, fs);
621
+ }
622
+ else if (entry.isFile() || entry.isSymbolicLink()) {
623
+ fs.copyFileSync(srcPath, destPath);
624
+ }
625
+ }
626
+ }
486
627
  }
487
628
  exports.BundlerCompilerService = BundlerCompilerService;
488
629
  __decorate([
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nativescript",
3
3
  "main": "./lib/nativescript-cli-lib.js",
4
- "version": "9.0.0-alpha.3",
4
+ "version": "9.0.0-alpha.5",
5
5
  "author": "NativeScript <oss@nativescript.org>",
6
6
  "description": "Command-line interface for building NativeScript projects",
7
7
  "bin": {
@@ -51,7 +51,7 @@
51
51
  "keywords": [
52
52
  "nativescript",
53
53
  "typescript",
54
- "mobile"
54
+ "javascript"
55
55
  ],
56
56
  "dependencies": {
57
57
  "@foxt/js-srp": "^0.0.3-patch2",
@@ -75,7 +75,7 @@
75
75
  "glob": "11.0.1",
76
76
  "ios-device-lib": "0.9.4",
77
77
  "ios-mobileprovision-finder": "1.2.1",
78
- "ios-sim-portable": "4.5.0",
78
+ "ios-sim-portable": "4.5.1",
79
79
  "jimp": "1.6.0",
80
80
  "lodash": "4.17.21",
81
81
  "log4js": "6.9.1",
@@ -157,7 +157,6 @@
157
157
  "grunt-ts": "6.0.0-beta.22",
158
158
  "husky": "9.1.7",
159
159
  "istanbul": "0.4.5",
160
- "latest-version": "9.0.0",
161
160
  "lint-staged": "~15.4.3",
162
161
  "mocha": "11.1.0",
163
162
  "sinon": "19.0.2",