nativescript 9.1.0-alpha.13 → 9.1.0-alpha.15

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.
@@ -44,6 +44,12 @@ class BundlerCompilerService extends events_1.EventEmitter {
44
44
  getViteDistOutputPath(projectDir) {
45
45
  return path.join(projectDir, process.env.NS_VITE_DIST_DIR || constants_1.VITE_DIST_FOLDER_NAME);
46
46
  }
47
+ getViteBuildPaths(platformData, projectData) {
48
+ return {
49
+ distOutput: this.getViteDistOutputPath(projectData.projectDir),
50
+ destDir: path.join(platformData.appDestinationDirectoryPath, this.$options.hostProjectModuleName),
51
+ };
52
+ }
47
53
  async compileWithWatch(platformData, projectData, prepareData) {
48
54
  return new Promise(async (resolve, reject) => {
49
55
  if (this.bundlerProcesses[platformData.platformNameLowerCase]) {
@@ -88,8 +94,7 @@ class BundlerCompilerService extends events_1.EventEmitter {
88
94
  console.log("Received Vite IPC message:", message);
89
95
  }
90
96
  // Copy Vite output files directly to platform destination
91
- const distOutput = this.getViteDistOutputPath(projectData.projectDir);
92
- const destDir = path.join(platformData.appDestinationDirectoryPath, this.$options.hostProjectModuleName);
97
+ const { distOutput, destDir } = this.getViteBuildPaths(platformData, projectData);
93
98
  if (debugLog) {
94
99
  console.log(`Copying from ${distOutput} to ${destDir}.`);
95
100
  }
@@ -256,17 +261,19 @@ class BundlerCompilerService extends events_1.EventEmitter {
256
261
  // is left empty (or worse, runs stale dev/HMR artifacts from
257
262
  // a previous `ns debug` run) and the runtime crashes on
258
263
  // launch with `Check failed: has_pending_exception()`.
259
- if (isVite) {
260
- try {
261
- const distOutput = this.getViteDistOutputPath(projectData.projectDir);
262
- const destDir = path.join(platformData.appDestinationDirectoryPath, this.$options.hostProjectModuleName);
263
- this.copyViteBundleToNative(distOutput, destDir);
264
- }
265
- catch (copyErr) {
266
- this.$logger.warn(`Failed to copy Vite output to platform destination: ${copyErr.message}`);
264
+ // The copy must succeed for the build to succeed — a build
265
+ // whose bundle never reached the native app is not a
266
+ // successful build, so copy failures reject here.
267
+ try {
268
+ if (isVite) {
269
+ const { distOutput, destDir } = this.getViteBuildPaths(platformData, projectData);
270
+ this.copyViteBundleToNative(distOutput, destDir, null, true);
267
271
  }
272
+ resolve();
273
+ }
274
+ catch (error) {
275
+ reject(error);
268
276
  }
269
- resolve();
270
277
  }
271
278
  else {
272
279
  const error = new Error(`Executing ${projectData.bundler} failed with exit code ${exitCode}.`);
@@ -732,7 +739,7 @@ class BundlerCompilerService extends events_1.EventEmitter {
732
739
  getBundler() {
733
740
  return this.$projectConfigService.getValue(`bundler`, "webpack");
734
741
  }
735
- copyViteBundleToNative(distOutput, destDir, specificFiles = null) {
742
+ copyViteBundleToNative(distOutput, destDir, specificFiles = null, failOnError = false) {
736
743
  // Clean and copy Vite output to native platform folder
737
744
  if (debugLog) {
738
745
  console.log(`Copying Vite bundle from "${distOutput}" to "${destDir}".`);
@@ -764,22 +771,27 @@ class BundlerCompilerService extends events_1.EventEmitter {
764
771
  if (debugLog) {
765
772
  console.log("Full build: Copying all files.");
766
773
  }
774
+ // Validate the source before touching the destination — cleaning
775
+ // destDir first would wipe a previously good bundle and leave an
776
+ // empty app folder behind a missing Vite output.
777
+ if (!this.$fs.exists(distOutput)) {
778
+ throw new Error(`Vite output directory does not exist: ${distOutput}`);
779
+ }
767
780
  // Clean destination directory
768
781
  if (this.$fs.exists(destDir)) {
769
782
  this.$fs.deleteDirectory(destDir);
770
783
  }
771
784
  this.$fs.createDirectory(destDir);
772
785
  // Copy all files from dist to platform destination
773
- if (this.$fs.exists(distOutput)) {
774
- this.copyRecursiveSync(distOutput, destDir);
775
- }
776
- else {
777
- this.$logger.warn(`Vite output directory does not exist: ${distOutput}`);
778
- }
786
+ this.copyRecursiveSync(distOutput, destDir);
779
787
  }
780
788
  }
781
789
  catch (error) {
782
- this.$logger.warn(`Failed to copy Vite bundle: ${error.message}`);
790
+ const copyError = error instanceof Error ? error : new Error(String(error));
791
+ if (failOnError) {
792
+ throw copyError;
793
+ }
794
+ this.$logger.warn(`Failed to copy Vite bundle: ${copyError.message}`);
783
795
  }
784
796
  }
785
797
  getIncrementalFilesToCopy(emittedFiles) {
@@ -5,6 +5,8 @@ const yok_1 = require("../../common/yok");
5
5
  const trapezedev_project_1 = require("@nstudio/trapezedev-project");
6
6
  const color_1 = require("../../color");
7
7
  const path = require("path");
8
+ const os = require("os");
9
+ const fs = require("fs");
8
10
  class SPMService {
9
11
  constructor($logger, $fs, $projectConfigService, $terminalSpinnerService, $xcodebuildCommandService, $xcodebuildArgsService) {
10
12
  this.$logger = $logger;
@@ -28,11 +30,19 @@ class SPMService {
28
30
  // include swift packages from plugin configs
29
31
  // but allow app packages to override plugin packages with the same name
30
32
  const appPackageNames = new Set(appPackages.map((pkg) => pkg.name));
33
+ // multiple plugins may declare the same package (e.g. a shared shim) —
34
+ // only the first declaration is added; a second same-name package would
35
+ // produce duplicate (and possibly conflicting) references in the pbxproj.
36
+ const addedPluginPackageNames = new Set();
31
37
  for (const pluginPkg of pluginPackages) {
32
38
  if (appPackageNames.has(pluginPkg.name)) {
33
39
  this.$logger.trace(`SPM: app package overrides plugin package: ${pluginPkg.name}`);
34
40
  }
41
+ else if (addedPluginPackageNames.has(pluginPkg.name)) {
42
+ this.$logger.trace(`SPM: skipping duplicate plugin package: ${pluginPkg.name}`);
43
+ }
35
44
  else {
45
+ addedPluginPackageNames.add(pluginPkg.name);
36
46
  appPackages.push(pluginPkg);
37
47
  }
38
48
  }
@@ -52,6 +62,10 @@ class SPMService {
52
62
  this.$logger.trace("SPM: no SPM packages to apply.");
53
63
  return;
54
64
  }
65
+ // name every package and where it comes from — when resolution is
66
+ // slow or fails, this is the first thing needed to tell WHICH
67
+ // dependency is responsible.
68
+ this.$logger.info(this.formatPackageListing(spmPackages));
55
69
  const project = new trapezedev_project_1.MobileProject(platformData.projectRoot, {
56
70
  ios: {
57
71
  path: ".",
@@ -70,6 +84,11 @@ class SPMService {
70
84
  // resolve the path relative to the project root
71
85
  this.$logger.trace("SPM: resolving path for package: ", pkg.path);
72
86
  pkg.path = path.resolve(projectData.projectDir, pkg.path);
87
+ if (!this.$fs.exists(pkg.path)) {
88
+ // surface this now — otherwise the only symptom is a cryptic
89
+ // xcodebuild resolution failure much later.
90
+ this.$logger.warn(`SPM: local package path for "${pkg.name}" does not exist: ${pkg.path} — Xcode will fail to resolve it.`);
91
+ }
73
92
  }
74
93
  this.$logger.trace(`SPM: adding package ${pkg.name} to project.`, pkg);
75
94
  await project.ios.addSPMPackage(projectData.projectName, pkg);
@@ -126,22 +145,74 @@ class SPMService {
126
145
  const startedAt = Date.now();
127
146
  let activity = "Resolving Swift Package dependencies";
128
147
  let lineBuffer = "";
148
+ // package currently being git-fetched (short name), if any — used to
149
+ // measure its growing clone in the SwiftPM cache so a long silent fetch
150
+ // shows visible progress ("2.31 GB of git history fetched") instead of
151
+ // looking hung.
152
+ let fetchingPackageRef = null;
153
+ let fetchedBytes = 0;
154
+ let largeCloneNoted = false;
155
+ // rolling tail of raw xcodebuild output for the failure report.
156
+ const outputTail = [];
129
157
  const render = () => {
130
158
  const elapsed = Math.round((Date.now() - startedAt) / 1000);
131
- spinner.text = `${activity}… ${color_1.color.dim(`(${this.formatElapsed(elapsed)})`)}`;
159
+ const fetched = fetchedBytes > 0
160
+ ? ` — ${this.formatBytes(fetchedBytes)} of git history fetched`
161
+ : "";
162
+ spinner.text = `${activity}…${fetched} ${color_1.color.dim(`(${this.formatElapsed(elapsed)})`)}`;
132
163
  };
133
164
  // keep the elapsed timer ticking even when xcodebuild is silent (e.g.
134
- // while a binary artifact downloads) so the user can see it's alive.
135
- const ticker = setInterval(render, 1000);
165
+ // while a repository clones or a binary artifact downloads) so the user
166
+ // can see it's alive. Every 5th tick, measure the in-progress clone.
167
+ let tickCount = 0;
168
+ const ticker = setInterval(() => {
169
+ tickCount++;
170
+ if (fetchingPackageRef && tickCount % 5 === 0) {
171
+ fetchedBytes = this.getPackageCloneSizeBytes(fetchingPackageRef);
172
+ if (!largeCloneNoted &&
173
+ fetchedBytes >= SPMService.LARGE_CLONE_NOTE_BYTES) {
174
+ largeCloneNoted = true;
175
+ // persist a one-time explanation above the spinner: this is the
176
+ // point where users otherwise assume the CLI is stuck.
177
+ spinner.stopAndPersist({
178
+ symbol: color_1.color.yellow("ℹ"),
179
+ text: color_1.color.yellow(`the "${fetchingPackageRef}" package is hosted in a repository with a large git history — ` +
180
+ `SwiftPM clones the entire repository on first fetch, which can take a long time.${os.EOL}` +
181
+ ` cache: ${SPMService.SWIFTPM_REPO_CACHE}`),
182
+ });
183
+ spinner.start();
184
+ }
185
+ }
186
+ render();
187
+ }, 1000);
136
188
  const onProgress = (chunk) => {
137
189
  lineBuffer += chunk.data;
138
- const lines = lineBuffer.split("\n");
190
+ // tolerate CRLF as well as LF so parsed lines never carry a stray \r
191
+ const lines = lineBuffer.split(/\r?\n/);
139
192
  // keep the last (possibly partial) line in the buffer
140
193
  lineBuffer = lines.pop();
141
194
  for (const line of lines) {
195
+ const trimmed = line.trim();
196
+ if (trimmed) {
197
+ this.$logger.trace(`SPM: ${trimmed}`);
198
+ outputTail.push(trimmed);
199
+ if (outputTail.length > SPMService.OUTPUT_TAIL_LINES) {
200
+ outputTail.shift();
201
+ }
202
+ }
142
203
  const described = this.describeSPMActivity(line);
143
204
  if (described) {
144
205
  activity = described;
206
+ // track which package a "Fetching <url>" line refers to so the
207
+ // ticker can measure its clone; any other activity means the
208
+ // fetch finished.
209
+ if (/^Fetching\b/i.test(trimmed)) {
210
+ fetchingPackageRef = this.shortenPackageRef(trimmed);
211
+ }
212
+ else {
213
+ fetchingPackageRef = null;
214
+ fetchedBytes = 0;
215
+ }
145
216
  render();
146
217
  }
147
218
  }
@@ -153,10 +224,20 @@ class SPMService {
153
224
  cwd: projectData.projectDir,
154
225
  onProgress,
155
226
  });
156
- spinner.succeed(color_1.color.green("Swift Package dependencies resolved"));
227
+ const elapsed = Math.round((Date.now() - startedAt) / 1000);
228
+ spinner.succeed(color_1.color.green("Swift Package dependencies resolved") +
229
+ color_1.color.dim(` (${this.formatElapsed(elapsed)})`));
157
230
  }
158
231
  catch (err) {
159
232
  spinner.fail(color_1.color.red("Failed to resolve Swift Package dependencies"));
233
+ // the spinner swallowed the raw log — replay the tail so the actual
234
+ // xcodebuild error is visible without rerunning in verbose mode.
235
+ if (outputTail.length) {
236
+ this.$logger.info(color_1.color.dim("xcodebuild output (last lines):"));
237
+ for (const line of outputTail) {
238
+ this.$logger.info(color_1.color.dim(` ${line}`));
239
+ }
240
+ }
160
241
  throw err;
161
242
  }
162
243
  finally {
@@ -253,6 +334,98 @@ class SPMService {
253
334
  const seconds = totalSeconds % 60;
254
335
  return `${minutes}m ${seconds}s`;
255
336
  }
337
+ /**
338
+ * Multi-line listing of every package and its source — one package per
339
+ * line, separated by the platform EOL so entries never clump together in
340
+ * terminal output on macOS, Windows, or Linux.
341
+ */
342
+ formatPackageListing(spmPackages) {
343
+ return [
344
+ "Swift Packages:",
345
+ ...spmPackages.map((pkg) => ` ${this.describePackageSource(pkg)}`),
346
+ ].join(os.EOL);
347
+ }
348
+ /**
349
+ * One-line description of a package and where it resolves from, e.g.
350
+ * "FontManager (1.0.12 · https://github.com/NativeScript/font-manager.git)"
351
+ * or "CanvasNative (local: node_modules/@nativescript/canvas/platforms/ios/NativeScriptV8)".
352
+ */
353
+ describePackageSource(pkg) {
354
+ if ("path" in pkg) {
355
+ return `${pkg.name} (local: ${pkg.path})`;
356
+ }
357
+ return `${pkg.name} (${pkg.version} · ${pkg.repositoryURL})`;
358
+ }
359
+ /**
360
+ * Size on disk of the SwiftPM cache clone(s) for a package ref (the short
361
+ * name produced by shortenPackageRef). Cache entries are named
362
+ * "<repo-name>-<hash>". Returns 0 when nothing is there (yet).
363
+ */
364
+ getPackageCloneSizeBytes(packageRef) {
365
+ let entries;
366
+ try {
367
+ entries = fs.readdirSync(SPMService.SWIFTPM_REPO_CACHE, {
368
+ withFileTypes: true,
369
+ });
370
+ }
371
+ catch (err) {
372
+ return 0;
373
+ }
374
+ let total = 0;
375
+ for (const entry of entries) {
376
+ if (entry.isDirectory() &&
377
+ (entry.name === packageRef || entry.name.startsWith(`${packageRef}-`))) {
378
+ total += this.getDirectorySizeBytes(path.join(SPMService.SWIFTPM_REPO_CACHE, entry.name));
379
+ }
380
+ }
381
+ return total;
382
+ }
383
+ /**
384
+ * Recursive directory size via the raw fs API. Tolerates files vanishing
385
+ * mid-walk (git renames its temp packfiles while cloning) and does not
386
+ * follow symlinks.
387
+ */
388
+ getDirectorySizeBytes(dirPath) {
389
+ let total = 0;
390
+ const pending = [dirPath];
391
+ while (pending.length) {
392
+ const current = pending.pop();
393
+ let entries;
394
+ try {
395
+ entries = fs.readdirSync(current, { withFileTypes: true });
396
+ }
397
+ catch (err) {
398
+ continue;
399
+ }
400
+ for (const entry of entries) {
401
+ const fullPath = path.join(current, entry.name);
402
+ try {
403
+ if (entry.isDirectory()) {
404
+ pending.push(fullPath);
405
+ }
406
+ else if (entry.isFile()) {
407
+ total += fs.statSync(fullPath).size;
408
+ }
409
+ }
410
+ catch (err) {
411
+ // entry disappeared between readdir and stat — ignore
412
+ }
413
+ }
414
+ }
415
+ return total;
416
+ }
417
+ /** Formats a byte count as a short human-readable size ("2.31 GB"). */
418
+ formatBytes(bytes) {
419
+ const GB = 1024 ** 3;
420
+ const MB = 1024 ** 2;
421
+ if (bytes >= GB) {
422
+ return `${(bytes / GB).toFixed(2)} GB`;
423
+ }
424
+ if (bytes >= MB) {
425
+ return `${Math.round(bytes / MB)} MB`;
426
+ }
427
+ return `${Math.round(bytes / 1024)} KB`;
428
+ }
256
429
  /** True when the Xcode project references any Swift packages. */
257
430
  hasSPMReferences(platformData, projectData) {
258
431
  const pbxprojPath = path.join(platformData.projectRoot, `${projectData.projectName}.xcodeproj`, "project.pbxproj");
@@ -278,5 +451,17 @@ class SPMService {
278
451
  }
279
452
  }
280
453
  exports.SPMService = SPMService;
454
+ // SwiftPM keeps one bare clone per source package here (shared by Xcode and
455
+ // xcodebuild). Watching a package's clone grow is the only visibility into
456
+ // an otherwise silent long fetch — SwiftPM clones a repository's ENTIRE git
457
+ // history to read Package.swift, so a package hosted in a multi-GB repo can
458
+ // legitimately "fetch" for tens of minutes with no output.
459
+ SPMService.SWIFTPM_REPO_CACHE = path.join(os.homedir(), "Library", "Caches", "org.swift.swiftpm", "repositories");
460
+ // Once a single package's clone passes this size, surface a one-time note
461
+ // explaining why the fetch is slow (250 MB is already far beyond any
462
+ // reasonably-hosted Swift package).
463
+ SPMService.LARGE_CLONE_NOTE_BYTES = 250 * 1024 * 1024;
464
+ // Lines of raw xcodebuild output kept for the failure report.
465
+ SPMService.OUTPUT_TAIL_LINES = 25;
281
466
  yok_1.injector.register("spmService", SPMService);
282
467
  //# sourceMappingURL=spm-service.js.map
@@ -697,6 +697,23 @@ class IOSProjectService extends projectServiceBaseLib.PlatformProjectServiceBase
697
697
  const config = this.$projectConfigService.readConfig(plugin.fullPath);
698
698
  const packages = _.get(config, `${platformData.platformNameLowerCase}.SPMPackages`, []);
699
699
  if (packages.length) {
700
+ for (const pkg of packages) {
701
+ // a plugin's local package path is naturally authored relative
702
+ // to the plugin itself, but the SPM service resolves relative
703
+ // paths against the app project dir. When the app-relative
704
+ // path doesn't exist (e.g. non-hoisted node_modules layouts),
705
+ // fall back to resolving against the plugin's own directory.
706
+ if ("path" in pkg &&
707
+ pkg.path &&
708
+ !path.isAbsolute(pkg.path) &&
709
+ !this.$fs.exists(path.resolve(projectData.projectDir, pkg.path))) {
710
+ const pluginRelativePath = path.resolve(plugin.fullPath, pkg.path);
711
+ if (this.$fs.exists(pluginRelativePath)) {
712
+ this.$logger.trace(`SPM: resolved plugin-relative package path for ${pkg.name}: ${pluginRelativePath}`);
713
+ pkg.path = pluginRelativePath;
714
+ }
715
+ }
716
+ }
700
717
  pluginSpmPackages.push(...packages);
701
718
  }
702
719
  }
@@ -798,11 +815,18 @@ class IOSProjectService extends projectServiceBaseLib.PlatformProjectServiceBase
798
815
  this.$fs.rename(path.join(fileRootLocation, oldFileName), path.join(fileRootLocation, newFileName));
799
816
  }
800
817
  async prepareNativeSourceCode(groupName, sourceFolderPath, projectData) {
818
+ var _a;
801
819
  const project = this.createPbxProj(projectData);
802
820
  const group = await this.getRootGroup(groupName, sourceFolderPath);
821
+ // pin the sources to the main app target: without an explicit target the
822
+ // underlying xcode lib picks whichever "Sources" build phase it finds
823
+ // first, which can be an extension target (e.g. a widget) once one
824
+ // exists — compiling plugin native code into extensions breaks their
825
+ // builds (and bloats them) since they lack the app's search paths.
803
826
  project.addPbxGroup(group.files, group.name, group.path, null, {
804
827
  isMain: true,
805
828
  filesRelativeToProject: true,
829
+ target: (_a = project.getFirstTarget()) === null || _a === void 0 ? void 0 : _a.uuid,
806
830
  });
807
831
  project.addToHeaderSearchPaths(group.path);
808
832
  const headerFiles = this.$fs.exists(sourceFolderPath)
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.1.0-alpha.13",
4
+ "version": "9.1.0-alpha.15",
5
5
  "author": "NativeScript <oss@nativescript.org>",
6
6
  "description": "Command-line interface for building NativeScript projects",
7
7
  "bin": {
@@ -60,7 +60,7 @@
60
60
  "@npmcli/arborist": "9.1.8",
61
61
  "@nstudio/trapezedev-project": "7.2.4",
62
62
  "@rigor789/resolve-package-path": "1.0.7",
63
- "axios": "1.13.5",
63
+ "axios": "1.18.1",
64
64
  "byline": "5.0.0",
65
65
  "chokidar": "^3.6.0",
66
66
  "cli-table3": "0.6.5",
@@ -96,7 +96,7 @@
96
96
  "qrcode-terminal": "0.12.0",
97
97
  "semver": "7.7.3",
98
98
  "shelljs": "0.10.0",
99
- "simple-git": "3.30.0",
99
+ "simple-git": "3.36.0",
100
100
  "simple-plist": "1.4.0",
101
101
  "source-map": "0.7.6",
102
102
  "tar": "7.5.9",