nativescript 9.0.0-alpha.0 → 9.0.0-alpha.10
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/config/test-deps-versions-generated.json +16 -1
- package/lib/.d.ts +3 -3
- package/lib/bootstrap.js +1 -1
- package/lib/color.js +38 -7
- package/lib/commands/clean.js +1 -2
- package/lib/commands/embedding/embed.js +1 -1
- package/lib/commands/post-install.js +2 -2
- package/lib/commands/typings.js +12 -12
- package/lib/common/header.js +3 -3
- package/lib/common/logger/layouts/cli-layout.js +1 -1
- package/lib/common/logger/logger.js +2 -2
- package/lib/common/mobile/android/android-emulator-services.js +9 -7
- package/lib/common/mobile/device-log-provider.js +3 -4
- package/lib/common/mobile/emulator-helper.js +1 -0
- package/lib/common/services/hooks-service.js +23 -6
- package/lib/common/verify-node-version.js +1 -1
- package/lib/constants.js +6 -4
- package/lib/controllers/migrate-controller.js +3 -4
- package/lib/controllers/prepare-controller.js +9 -9
- package/lib/definitions/project.d.ts +19 -1
- package/lib/definitions/temp-service.d.ts +6 -2
- package/lib/helpers/key-command-helper.js +2 -1
- package/lib/project-data.js +10 -4
- package/lib/services/analytics-settings-service.js +2 -1
- package/lib/services/bundler/bundler-compiler-service.js +641 -0
- package/lib/services/bundler/bundler.js +2 -0
- package/lib/services/ios/spm-service.js +1 -1
- package/lib/services/livesync/android-livesync-tool.js +3 -1
- package/lib/services/temp-service.js +16 -4
- package/package.json +28 -33
- package/vendor/gradle-plugin/build.gradle +3 -3
- package/lib/services/webpack/webpack-compiler-service.js +0 -396
- package/lib/services/webpack/webpack.d.ts +0 -226
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.BundlerCompilerService = void 0;
|
|
10
|
+
const path = require("path");
|
|
11
|
+
const semver = require("semver");
|
|
12
|
+
const _ = require("lodash");
|
|
13
|
+
const events_1 = require("events");
|
|
14
|
+
const decorators_1 = require("../../common/decorators");
|
|
15
|
+
const constants_1 = require("../../constants");
|
|
16
|
+
const yok_1 = require("../../common/yok");
|
|
17
|
+
const package_path_helper_1 = require("../../helpers/package-path-helper");
|
|
18
|
+
const debugLog = false;
|
|
19
|
+
class BundlerCompilerService extends events_1.EventEmitter {
|
|
20
|
+
constructor($options, $errors, $childProcess, $fs, $hooksService, $hostInfo, $logger, $mobileHelper, $cleanupService, $packageManager, $packageInstallationManager, $projectConfigService) {
|
|
21
|
+
super();
|
|
22
|
+
this.$options = $options;
|
|
23
|
+
this.$errors = $errors;
|
|
24
|
+
this.$childProcess = $childProcess;
|
|
25
|
+
this.$fs = $fs;
|
|
26
|
+
this.$hooksService = $hooksService;
|
|
27
|
+
this.$hostInfo = $hostInfo;
|
|
28
|
+
this.$logger = $logger;
|
|
29
|
+
this.$mobileHelper = $mobileHelper;
|
|
30
|
+
this.$cleanupService = $cleanupService;
|
|
31
|
+
this.$packageManager = $packageManager;
|
|
32
|
+
this.$packageInstallationManager = $packageInstallationManager;
|
|
33
|
+
this.$projectConfigService = $projectConfigService;
|
|
34
|
+
this.bundlerProcesses = {};
|
|
35
|
+
this.expectedHashes = {};
|
|
36
|
+
}
|
|
37
|
+
async compileWithWatch(platformData, projectData, prepareData) {
|
|
38
|
+
return new Promise(async (resolve, reject) => {
|
|
39
|
+
if (this.bundlerProcesses[platformData.platformNameLowerCase]) {
|
|
40
|
+
resolve(void 0);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
let isFirstBundlerWatchCompilation = true;
|
|
44
|
+
prepareData.watch = true;
|
|
45
|
+
try {
|
|
46
|
+
const childProcess = await this.startBundleProcess(platformData, projectData, prepareData);
|
|
47
|
+
const isVite = this.getBundler() === "vite";
|
|
48
|
+
childProcess.stdout.on("data", function (data) {
|
|
49
|
+
process.stdout.write(data);
|
|
50
|
+
});
|
|
51
|
+
childProcess.stderr.on("data", function (data) {
|
|
52
|
+
process.stderr.write(data);
|
|
53
|
+
});
|
|
54
|
+
childProcess.on("message", (message) => {
|
|
55
|
+
this.$logger.trace(`Message from ${projectData.bundler}`, message);
|
|
56
|
+
if (isVite &&
|
|
57
|
+
message &&
|
|
58
|
+
message.emittedFiles) {
|
|
59
|
+
message = message;
|
|
60
|
+
if (debugLog) {
|
|
61
|
+
console.log("Received Vite IPC message:", message);
|
|
62
|
+
}
|
|
63
|
+
const distOutput = path.join(projectData.projectDir, "dist");
|
|
64
|
+
const destDir = path.join(platformData.appDestinationDirectoryPath, this.$options.hostProjectModuleName);
|
|
65
|
+
if (debugLog) {
|
|
66
|
+
console.log(`🔥 Copying from ${distOutput} to ${destDir}`);
|
|
67
|
+
}
|
|
68
|
+
if (message.isHMR) {
|
|
69
|
+
if (debugLog) {
|
|
70
|
+
console.log("🔥 HMR update - copying only changed files for:", message.changedFiles);
|
|
71
|
+
}
|
|
72
|
+
let filesToCopy = message.emittedFiles;
|
|
73
|
+
const hasHTMLChanges = message.changedFiles.some((f) => f.endsWith(".html"));
|
|
74
|
+
if (hasHTMLChanges) {
|
|
75
|
+
filesToCopy = message.emittedFiles.filter((f) => f.includes(".component") ||
|
|
76
|
+
f === "bundle.mjs" ||
|
|
77
|
+
f === "bundle.mjs.map");
|
|
78
|
+
if (debugLog) {
|
|
79
|
+
console.log("🔥 HTML change detected - copying component files:", filesToCopy);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
this.copyViteBundleToNative(distOutput, destDir, filesToCopy);
|
|
83
|
+
}
|
|
84
|
+
else if (message.buildType === "incremental" &&
|
|
85
|
+
message.changedFiles &&
|
|
86
|
+
message.changedFiles.length > 0) {
|
|
87
|
+
if (debugLog) {
|
|
88
|
+
console.log("🔥 Incremental build - copying only relevant files for:", message.changedFiles);
|
|
89
|
+
}
|
|
90
|
+
const filesToCopy = this.getIncrementalFilesToCopy(message.emittedFiles, message.changedFiles);
|
|
91
|
+
if (debugLog) {
|
|
92
|
+
console.log("🔥 Incremental build - files to copy:", filesToCopy);
|
|
93
|
+
}
|
|
94
|
+
this.copyViteBundleToNative(distOutput, destDir, filesToCopy);
|
|
95
|
+
}
|
|
96
|
+
else if (message.buildType === "incremental" &&
|
|
97
|
+
message.changedFiles &&
|
|
98
|
+
message.changedFiles.length > 0) {
|
|
99
|
+
console.log("🔥 Incremental build - copying only relevant files for:", message.changedFiles);
|
|
100
|
+
const filesToCopy = this.getIncrementalFilesToCopy(message.emittedFiles, message.changedFiles);
|
|
101
|
+
console.log("🔥 Incremental build - files to copy:", filesToCopy);
|
|
102
|
+
this.copyViteBundleToNative(distOutput, destDir, filesToCopy);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
if (debugLog) {
|
|
106
|
+
console.log("🔥 Full build - copying all files");
|
|
107
|
+
}
|
|
108
|
+
this.copyViteBundleToNative(distOutput, destDir);
|
|
109
|
+
}
|
|
110
|
+
if (isFirstBundlerWatchCompilation) {
|
|
111
|
+
isFirstBundlerWatchCompilation = false;
|
|
112
|
+
if (debugLog) {
|
|
113
|
+
console.log("Vite first build completed, resolving compileWithWatch");
|
|
114
|
+
}
|
|
115
|
+
resolve(childProcess);
|
|
116
|
+
}
|
|
117
|
+
const files = message.emittedFiles.map((file) => path.join(platformData.appDestinationDirectoryPath, this.$options.hostProjectModuleName, file));
|
|
118
|
+
const data = {
|
|
119
|
+
files,
|
|
120
|
+
hasOnlyHotUpdateFiles: message.isHMR || false,
|
|
121
|
+
hmrData: {
|
|
122
|
+
hash: message.hash || "",
|
|
123
|
+
fallbackFiles: [],
|
|
124
|
+
},
|
|
125
|
+
platform: platformData.platformNameLowerCase,
|
|
126
|
+
};
|
|
127
|
+
this.$logger.info(`Vite build completed! Files copied to native platform.`);
|
|
128
|
+
this.notifyHMRClients({
|
|
129
|
+
type: message.isHMR ? "js-update" : "build-complete",
|
|
130
|
+
timestamp: Date.now(),
|
|
131
|
+
changedFiles: message.changedFiles || [],
|
|
132
|
+
buildType: message.buildType || "incremental",
|
|
133
|
+
isHMR: message.isHMR || false,
|
|
134
|
+
});
|
|
135
|
+
if (message.isHMR) {
|
|
136
|
+
if (debugLog) {
|
|
137
|
+
console.log("🔥 Skipping BUNDLER_COMPILATION_COMPLETE for HMR update - app will not restart");
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
if (debugLog) {
|
|
142
|
+
console.log("🔥 Emitting BUNDLER_COMPILATION_COMPLETE for full build");
|
|
143
|
+
}
|
|
144
|
+
this.emit(constants_1.BUNDLER_COMPILATION_COMPLETE, data);
|
|
145
|
+
}
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (typeof message === "object" &&
|
|
149
|
+
"version" in message &&
|
|
150
|
+
"type" in message) {
|
|
151
|
+
if (isFirstBundlerWatchCompilation) {
|
|
152
|
+
isFirstBundlerWatchCompilation = false;
|
|
153
|
+
resolve(childProcess);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
return this.handleHMRMessage(message, platformData, projectData, prepareData);
|
|
157
|
+
}
|
|
158
|
+
if (message ===
|
|
159
|
+
`${capitalizeFirstLetter(projectData.bundler)} compilation complete.`) {
|
|
160
|
+
this.$logger.info(`${capitalizeFirstLetter(projectData.bundler)} build done!`);
|
|
161
|
+
resolve(childProcess);
|
|
162
|
+
}
|
|
163
|
+
message = message;
|
|
164
|
+
if (message.emittedFiles) {
|
|
165
|
+
if (isFirstBundlerWatchCompilation) {
|
|
166
|
+
isFirstBundlerWatchCompilation = false;
|
|
167
|
+
this.expectedHashes[platformData.platformNameLowerCase] =
|
|
168
|
+
prepareData.hmr ? message.hash : "";
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const previousHash = this.expectedHashes[platformData.platformNameLowerCase];
|
|
172
|
+
let result;
|
|
173
|
+
if (prepareData.hmr) {
|
|
174
|
+
result = this.getUpdatedEmittedFiles(message.emittedFiles, message.chunkFiles, message.hash, platformData.platformNameLowerCase);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
result = {
|
|
178
|
+
emittedFiles: message.emittedFiles,
|
|
179
|
+
fallbackFiles: [],
|
|
180
|
+
hash: "",
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
const files = result.emittedFiles.map((file) => path.join(platformData.appDestinationDirectoryPath, this.$options.hostProjectModuleName, file));
|
|
184
|
+
const fallbackFiles = result.fallbackFiles.map((file) => path.join(platformData.appDestinationDirectoryPath, this.$options.hostProjectModuleName, file));
|
|
185
|
+
const data = {
|
|
186
|
+
files,
|
|
187
|
+
hasOnlyHotUpdateFiles: files.every((f) => f.indexOf("hot-update") > -1),
|
|
188
|
+
hmrData: {
|
|
189
|
+
hash: result.hash,
|
|
190
|
+
fallbackFiles,
|
|
191
|
+
},
|
|
192
|
+
platform: platformData.platformNameLowerCase,
|
|
193
|
+
};
|
|
194
|
+
this.$logger.trace(`Generated data from ${projectData.bundler} message:`, data);
|
|
195
|
+
if (data.hasOnlyHotUpdateFiles && previousHash === message.hash) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (data.files.length) {
|
|
199
|
+
this.emit(constants_1.BUNDLER_COMPILATION_COMPLETE, data);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
childProcess.on("error", (err) => {
|
|
204
|
+
this.$logger.trace(`Unable to start ${projectData.bundler} process in watch mode. Error is: ${err}`);
|
|
205
|
+
delete this.bundlerProcesses[platformData.platformNameLowerCase];
|
|
206
|
+
reject(err);
|
|
207
|
+
});
|
|
208
|
+
childProcess.on("close", async (arg) => {
|
|
209
|
+
const exitCode = typeof arg === "number" ? arg : arg && arg.code;
|
|
210
|
+
this.$logger.trace(`${capitalizeFirstLetter(projectData.bundler)} process exited with code ${exitCode} when we expected it to be long living with watch.`);
|
|
211
|
+
await this.$cleanupService.removeKillProcess(childProcess.pid.toString());
|
|
212
|
+
const error = new Error(`Executing ${projectData.bundler} failed with exit code ${exitCode}.`);
|
|
213
|
+
error.code = exitCode;
|
|
214
|
+
delete this.bundlerProcesses[platformData.platformNameLowerCase];
|
|
215
|
+
reject(error);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
catch (err) {
|
|
219
|
+
reject(err);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
async compileWithoutWatch(platformData, projectData, prepareData) {
|
|
224
|
+
return new Promise(async (resolve, reject) => {
|
|
225
|
+
if (this.bundlerProcesses[platformData.platformNameLowerCase]) {
|
|
226
|
+
resolve();
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
const childProcess = await this.startBundleProcess(platformData, projectData, prepareData);
|
|
231
|
+
childProcess.on("error", (err) => {
|
|
232
|
+
this.$logger.trace(`Unable to start ${projectData.bundler} process in non-watch mode. Error is: ${err}`);
|
|
233
|
+
delete this.bundlerProcesses[platformData.platformNameLowerCase];
|
|
234
|
+
reject(err);
|
|
235
|
+
});
|
|
236
|
+
childProcess.on("close", async (arg) => {
|
|
237
|
+
await this.$cleanupService.removeKillProcess(childProcess.pid.toString());
|
|
238
|
+
delete this.bundlerProcesses[platformData.platformNameLowerCase];
|
|
239
|
+
const exitCode = typeof arg === "number" ? arg : arg && arg.code;
|
|
240
|
+
if (exitCode === 0) {
|
|
241
|
+
resolve();
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
const error = new Error(`Executing ${projectData.bundler} failed with exit code ${exitCode}.`);
|
|
245
|
+
error.code = exitCode;
|
|
246
|
+
reject(error);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
catch (err) {
|
|
251
|
+
reject(err);
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
async stopBundlerCompiler(platform) {
|
|
256
|
+
if (platform) {
|
|
257
|
+
await this.stopBundlerForPlatform(platform);
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
const bundlerPlatforms = Object.keys(this.bundlerProcesses);
|
|
261
|
+
for (let i = 0; i < bundlerPlatforms.length; i++) {
|
|
262
|
+
await this.stopBundlerForPlatform(bundlerPlatforms[i]);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
async shouldUsePreserveSymlinksOption() {
|
|
267
|
+
const currentPackageManager = await this.$packageManager.getPackageManagerName();
|
|
268
|
+
const res = currentPackageManager !== constants_1.PackageManagers.pnpm;
|
|
269
|
+
return res;
|
|
270
|
+
}
|
|
271
|
+
async startBundleProcess(platformData, projectData, prepareData) {
|
|
272
|
+
if (projectData.bundlerConfigPath) {
|
|
273
|
+
if (!this.$fs.exists(projectData.bundlerConfigPath)) {
|
|
274
|
+
this.$errors.fail(`The bundler configuration file ${projectData.bundlerConfigPath} does not exist. Ensure the file exists, or update the path in ${constants_1.CONFIG_FILE_NAME_DISPLAY}.`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
if (!this.$fs.exists(projectData.bundlerConfigPath)) {
|
|
279
|
+
this.$errors.fail(`The ${projectData.bundler} configuration file ${projectData.bundlerConfigPath} does not exist. Ensure the file exists, or update the path in ${constants_1.CONFIG_FILE_NAME_DISPLAY}.`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
const envData = this.buildEnvData(platformData.platformNameLowerCase, projectData, prepareData);
|
|
283
|
+
const isVite = this.getBundler() === "vite";
|
|
284
|
+
const cliArgs = await this.buildEnvCommandLineParams(envData, platformData, projectData, prepareData);
|
|
285
|
+
const envParams = isVite
|
|
286
|
+
? [
|
|
287
|
+
`--mode=${platformData.platformNameLowerCase}`,
|
|
288
|
+
`--watch`,
|
|
289
|
+
"--",
|
|
290
|
+
...cliArgs,
|
|
291
|
+
]
|
|
292
|
+
: cliArgs;
|
|
293
|
+
const additionalNodeArgs = semver.major(process.version) <= 8 ? ["--harmony"] : [];
|
|
294
|
+
if (await this.shouldUsePreserveSymlinksOption()) {
|
|
295
|
+
additionalNodeArgs.push("--preserve-symlinks");
|
|
296
|
+
}
|
|
297
|
+
if (process.arch === "x64") {
|
|
298
|
+
additionalNodeArgs.unshift("--max_old_space_size=4096");
|
|
299
|
+
}
|
|
300
|
+
const args = [
|
|
301
|
+
...additionalNodeArgs,
|
|
302
|
+
this.getBundlerExecutablePath(projectData),
|
|
303
|
+
isVite ? "build" : this.isModernBundler(projectData) ? `build` : null,
|
|
304
|
+
`--config=${projectData.bundlerConfigPath}`,
|
|
305
|
+
...envParams,
|
|
306
|
+
].filter(Boolean);
|
|
307
|
+
if (!isVite) {
|
|
308
|
+
if (prepareData.watch) {
|
|
309
|
+
args.push("--watch");
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
const stdio = prepareData.watch || isVite ? ["ipc"] : "inherit";
|
|
313
|
+
const options = {
|
|
314
|
+
cwd: projectData.projectDir,
|
|
315
|
+
stdio,
|
|
316
|
+
};
|
|
317
|
+
options.env = {
|
|
318
|
+
...process.env,
|
|
319
|
+
NATIVESCRIPT_WEBPACK_ENV: JSON.stringify(envData),
|
|
320
|
+
NATIVESCRIPT_BUNDLER_ENV: JSON.stringify(envData),
|
|
321
|
+
};
|
|
322
|
+
if (this.$hostInfo.isWindows) {
|
|
323
|
+
Object.assign(options.env, { APPDATA: process.env.appData });
|
|
324
|
+
}
|
|
325
|
+
if (this.$options.hostProjectPath) {
|
|
326
|
+
Object.assign(options.env, {
|
|
327
|
+
USER_PROJECT_PLATFORMS_ANDROID: this.$options.hostProjectPath,
|
|
328
|
+
USER_PROJECT_PLATFORMS_ANDROID_MODULE: this.$options.hostProjectModuleName,
|
|
329
|
+
USER_PROJECT_PLATFORMS_IOS: this.$options.hostProjectPath,
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
if (debugLog) {
|
|
333
|
+
console.log("args:", args);
|
|
334
|
+
}
|
|
335
|
+
const childProcess = this.$childProcess.spawn(process.execPath, args, options);
|
|
336
|
+
this.bundlerProcesses[platformData.platformNameLowerCase] = childProcess;
|
|
337
|
+
await this.$cleanupService.addKillProcess(childProcess.pid.toString());
|
|
338
|
+
return childProcess;
|
|
339
|
+
}
|
|
340
|
+
buildEnvData(platform, projectData, prepareData) {
|
|
341
|
+
var _a, _b, _c;
|
|
342
|
+
const { env } = prepareData;
|
|
343
|
+
const envData = Object.assign({}, env, { [platform.toLowerCase()]: true });
|
|
344
|
+
const appId = projectData.projectIdentifiers[platform];
|
|
345
|
+
const appPath = projectData.getAppDirectoryRelativePath();
|
|
346
|
+
const appResourcesPath = projectData.getAppResourcesRelativeDirectoryPath();
|
|
347
|
+
Object.assign(envData, appId && { appId }, appPath && { appPath }, appResourcesPath && { appResourcesPath }, {
|
|
348
|
+
nativescriptLibPath: path.resolve(__dirname, "..", "..", "nativescript-cli-lib.js"),
|
|
349
|
+
});
|
|
350
|
+
envData.verbose = envData.verbose || this.$logger.isVerbose();
|
|
351
|
+
envData.production = envData.production || prepareData.release;
|
|
352
|
+
envData.config =
|
|
353
|
+
(_b = (_a = process.env.NATIVESCRIPT_CONFIG_NAME) !== null && _a !== void 0 ? _a : this.$options.config) !== null && _b !== void 0 ? _b : "false";
|
|
354
|
+
process.env.NATIVESCRIPT_CONFIG_NAME = envData.config;
|
|
355
|
+
envData.skipSnapshotTools =
|
|
356
|
+
prepareData.nativePrepare && prepareData.nativePrepare.skipNativePrepare;
|
|
357
|
+
if (typeof ((_c = prepareData === null || prepareData === void 0 ? void 0 : prepareData.env) === null || _c === void 0 ? void 0 : _c.sourceMap) === "undefined") {
|
|
358
|
+
if (!prepareData.release) {
|
|
359
|
+
envData.sourceMap = true;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (envData.sourceMap === "true" || envData.sourceMap === "false") {
|
|
363
|
+
envData.sourceMap = envData.sourceMap === "true";
|
|
364
|
+
}
|
|
365
|
+
if (prepareData.uniqueBundle > 0) {
|
|
366
|
+
envData.uniqueBundle = prepareData.uniqueBundle;
|
|
367
|
+
}
|
|
368
|
+
return envData;
|
|
369
|
+
}
|
|
370
|
+
async buildEnvCommandLineParams(envData, platformData, projectData, prepareData) {
|
|
371
|
+
const envFlagNames = Object.keys(envData);
|
|
372
|
+
const canSnapshot = prepareData.release &&
|
|
373
|
+
this.$mobileHelper.isAndroidPlatform(platformData.normalizedPlatformName);
|
|
374
|
+
if (envData && envData.snapshot) {
|
|
375
|
+
if (!canSnapshot) {
|
|
376
|
+
this.$logger.warn("Stripping the snapshot flag. " +
|
|
377
|
+
"Bear in mind that snapshot is only available in Android release builds.");
|
|
378
|
+
envFlagNames.splice(envFlagNames.indexOf("snapshot"), 1);
|
|
379
|
+
}
|
|
380
|
+
else if (this.$hostInfo.isWindows) {
|
|
381
|
+
if (projectData.bundler === "webpack") {
|
|
382
|
+
const minWebpackPluginWithWinSnapshotsVersion = "1.3.0";
|
|
383
|
+
const installedWebpackPluginVersion = await this.$packageInstallationManager.getInstalledDependencyVersion(constants_1.WEBPACK_PLUGIN_NAME, projectData.projectDir);
|
|
384
|
+
const hasWebpackPluginWithWinSnapshotsSupport = !!installedWebpackPluginVersion
|
|
385
|
+
? semver.gte(semver.coerce(installedWebpackPluginVersion), minWebpackPluginWithWinSnapshotsVersion)
|
|
386
|
+
: true;
|
|
387
|
+
if (!hasWebpackPluginWithWinSnapshotsSupport) {
|
|
388
|
+
this.$errors.fail(`In order to generate Snapshots on Windows, please upgrade your Webpack plugin version (npm i ${constants_1.WEBPACK_PLUGIN_NAME}@latest).`);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
const args = [];
|
|
394
|
+
envFlagNames.map((item) => {
|
|
395
|
+
let envValue = envData[item];
|
|
396
|
+
if (typeof envValue === "undefined") {
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
if (typeof envValue === "boolean") {
|
|
400
|
+
if (envValue) {
|
|
401
|
+
args.push(`--env.${item}`);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
if (!Array.isArray(envValue)) {
|
|
406
|
+
envValue = [envValue];
|
|
407
|
+
}
|
|
408
|
+
envValue.map((value) => args.push(`--env.${item}=${value}`));
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
return args;
|
|
412
|
+
}
|
|
413
|
+
getUpdatedEmittedFiles(allEmittedFiles, chunkFiles, nextHash, platform) {
|
|
414
|
+
const currentHash = this.getCurrentHotUpdateHash(allEmittedFiles);
|
|
415
|
+
const isHashValid = nextHash
|
|
416
|
+
? this.expectedHashes[platform] === currentHash
|
|
417
|
+
: true;
|
|
418
|
+
this.expectedHashes[platform] = nextHash;
|
|
419
|
+
const emittedHotUpdatesAndAssets = isHashValid
|
|
420
|
+
? _.difference(allEmittedFiles, chunkFiles)
|
|
421
|
+
: allEmittedFiles;
|
|
422
|
+
const fallbackFiles = chunkFiles.concat(emittedHotUpdatesAndAssets.filter((f) => f.indexOf("hot-update") === -1));
|
|
423
|
+
return {
|
|
424
|
+
emittedFiles: emittedHotUpdatesAndAssets,
|
|
425
|
+
fallbackFiles,
|
|
426
|
+
hash: currentHash,
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
getCurrentHotUpdateHash(emittedFiles) {
|
|
430
|
+
let hotHash;
|
|
431
|
+
const hotUpdateScripts = emittedFiles.filter((x) => x.endsWith(".hot-update.js"));
|
|
432
|
+
if (hotUpdateScripts && hotUpdateScripts.length) {
|
|
433
|
+
const hotUpdateName = hotUpdateScripts[0];
|
|
434
|
+
const matcher = /^(.+)\.(.+)\.hot-update/gm;
|
|
435
|
+
const matches = matcher.exec(hotUpdateName);
|
|
436
|
+
hotHash = matches[2];
|
|
437
|
+
}
|
|
438
|
+
return hotHash || "";
|
|
439
|
+
}
|
|
440
|
+
async stopBundlerForPlatform(platform) {
|
|
441
|
+
this.$logger.trace(`Stopping ${this.getBundler()} watch for platform ${platform}.`);
|
|
442
|
+
const bundlerProcess = this.bundlerProcesses[platform];
|
|
443
|
+
await this.$cleanupService.removeKillProcess(bundlerProcess.pid.toString());
|
|
444
|
+
if (bundlerProcess) {
|
|
445
|
+
bundlerProcess.kill("SIGINT");
|
|
446
|
+
delete this.bundlerProcesses[platform];
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
handleHMRMessage(message, platformData, projectData, prepareData) {
|
|
450
|
+
this.$logger.trace(`Received message from ${projectData.bundler} process:`, message);
|
|
451
|
+
if (message.type !== "compilation") {
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
this.$logger.trace(`${capitalizeFirstLetter(projectData.bundler)} build done!`);
|
|
455
|
+
const files = message.data.emittedAssets.map((asset) => path.join(platformData.appDestinationDirectoryPath, this.$options.hostProjectModuleName, asset));
|
|
456
|
+
const staleFiles = message.data.staleAssets.map((asset) => path.join(platformData.appDestinationDirectoryPath, this.$options.hostProjectModuleName, asset));
|
|
457
|
+
const lastHash = (() => {
|
|
458
|
+
const absoluteFileNameWithLastHash = files.find((fileName) => fileName.endsWith("hot-update.js"));
|
|
459
|
+
if (!absoluteFileNameWithLastHash) {
|
|
460
|
+
return null;
|
|
461
|
+
}
|
|
462
|
+
const fileNameWithLastHash = path.basename(absoluteFileNameWithLastHash);
|
|
463
|
+
const matches = fileNameWithLastHash.match(/\.(.+).hot-update\.js/);
|
|
464
|
+
if (matches) {
|
|
465
|
+
return matches[1];
|
|
466
|
+
}
|
|
467
|
+
})();
|
|
468
|
+
if (!files.length) {
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
this.emit(constants_1.BUNDLER_COMPILATION_COMPLETE, {
|
|
472
|
+
files,
|
|
473
|
+
staleFiles,
|
|
474
|
+
hasOnlyHotUpdateFiles: prepareData.hmr,
|
|
475
|
+
hmrData: {
|
|
476
|
+
hash: lastHash || message.hash,
|
|
477
|
+
fallbackFiles: [],
|
|
478
|
+
},
|
|
479
|
+
platform: platformData.platformNameLowerCase,
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
getBundlerExecutablePath(projectData) {
|
|
483
|
+
const bundler = this.getBundler();
|
|
484
|
+
if (bundler === "vite") {
|
|
485
|
+
const packagePath = (0, package_path_helper_1.resolvePackagePath)(`vite`, {
|
|
486
|
+
paths: [projectData.projectDir],
|
|
487
|
+
});
|
|
488
|
+
if (packagePath) {
|
|
489
|
+
return path.resolve(packagePath, "bin", "vite.js");
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
else if (this.isModernBundler(projectData)) {
|
|
493
|
+
const packagePath = (0, package_path_helper_1.resolvePackagePath)(`@nativescript/${bundler}`, {
|
|
494
|
+
paths: [projectData.projectDir],
|
|
495
|
+
});
|
|
496
|
+
if (packagePath) {
|
|
497
|
+
return path.resolve(packagePath, "dist", "bin", "index.js");
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
const packagePath = (0, package_path_helper_1.resolvePackagePath)("webpack", {
|
|
501
|
+
paths: [projectData.projectDir],
|
|
502
|
+
});
|
|
503
|
+
if (!packagePath) {
|
|
504
|
+
return "";
|
|
505
|
+
}
|
|
506
|
+
return path.resolve(packagePath, "bin", "webpack.js");
|
|
507
|
+
}
|
|
508
|
+
isModernBundler(projectData) {
|
|
509
|
+
const bundler = this.getBundler();
|
|
510
|
+
switch (bundler) {
|
|
511
|
+
case "rspack":
|
|
512
|
+
return true;
|
|
513
|
+
default:
|
|
514
|
+
const packageJSONPath = (0, package_path_helper_1.resolvePackageJSONPath)(constants_1.WEBPACK_PLUGIN_NAME, {
|
|
515
|
+
paths: [projectData.projectDir],
|
|
516
|
+
});
|
|
517
|
+
if (packageJSONPath) {
|
|
518
|
+
const packageData = this.$fs.readJson(packageJSONPath);
|
|
519
|
+
const ver = semver.coerce(packageData.version);
|
|
520
|
+
if (semver.satisfies(ver, ">= 5.0.0")) {
|
|
521
|
+
return true;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
break;
|
|
525
|
+
}
|
|
526
|
+
return false;
|
|
527
|
+
}
|
|
528
|
+
getBundler() {
|
|
529
|
+
return this.$projectConfigService.getValue(`bundler`, "webpack");
|
|
530
|
+
}
|
|
531
|
+
copyViteBundleToNative(distOutput, destDir, specificFiles = null) {
|
|
532
|
+
if (debugLog) {
|
|
533
|
+
console.log(`Copying Vite bundle from "${distOutput}" to "${destDir}"`);
|
|
534
|
+
}
|
|
535
|
+
const fs = require("fs");
|
|
536
|
+
try {
|
|
537
|
+
if (specificFiles) {
|
|
538
|
+
if (debugLog) {
|
|
539
|
+
console.log("🔥 Selective copy - copying specific files:", specificFiles);
|
|
540
|
+
}
|
|
541
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
542
|
+
for (const file of specificFiles) {
|
|
543
|
+
const srcPath = path.join(distOutput, file);
|
|
544
|
+
const destPath = path.join(destDir, file);
|
|
545
|
+
if (!fs.existsSync(srcPath))
|
|
546
|
+
continue;
|
|
547
|
+
fs.mkdirSync(path.dirname(destPath), { recursive: true });
|
|
548
|
+
fs.copyFileSync(srcPath, destPath);
|
|
549
|
+
if (debugLog) {
|
|
550
|
+
console.log(`🔥 Copied ${file}`);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
if (debugLog) {
|
|
556
|
+
console.log("🔥 Full build: Copying all files");
|
|
557
|
+
}
|
|
558
|
+
if (fs.existsSync(destDir)) {
|
|
559
|
+
fs.rmSync(destDir, { recursive: true, force: true });
|
|
560
|
+
}
|
|
561
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
562
|
+
if (fs.existsSync(distOutput)) {
|
|
563
|
+
this.copyRecursiveSync(distOutput, destDir, fs);
|
|
564
|
+
}
|
|
565
|
+
else {
|
|
566
|
+
this.$logger.warn(`Vite output directory does not exist: ${distOutput}`);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
catch (error) {
|
|
571
|
+
this.$logger.warn(`Failed to copy Vite bundle: ${error.message}`);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
getIncrementalFilesToCopy(emittedFiles, changedFiles) {
|
|
575
|
+
const filesToCopy = [];
|
|
576
|
+
const bundleFiles = emittedFiles.filter((file) => !file.includes("vendor") &&
|
|
577
|
+
(file.includes("bundle") ||
|
|
578
|
+
file.includes("main") ||
|
|
579
|
+
file.includes("app") ||
|
|
580
|
+
file.endsWith(".mjs") ||
|
|
581
|
+
file.endsWith(".js")));
|
|
582
|
+
filesToCopy.push(...bundleFiles);
|
|
583
|
+
const sourceMapFiles = emittedFiles.filter((file) => !file.includes("vendor") && file.endsWith(".map"));
|
|
584
|
+
filesToCopy.push(...sourceMapFiles);
|
|
585
|
+
const hasAssetChanges = changedFiles.some((file) => file.includes("/assets/") ||
|
|
586
|
+
file.includes("/static/") ||
|
|
587
|
+
file.includes("/public/"));
|
|
588
|
+
if (hasAssetChanges) {
|
|
589
|
+
const assetFiles = emittedFiles.filter((file) => file.includes("assets/") ||
|
|
590
|
+
file.includes("static/") ||
|
|
591
|
+
file.includes("fonts/") ||
|
|
592
|
+
file.includes("images/"));
|
|
593
|
+
filesToCopy.push(...assetFiles);
|
|
594
|
+
}
|
|
595
|
+
return [...new Set(filesToCopy)];
|
|
596
|
+
}
|
|
597
|
+
notifyHMRClients(message) {
|
|
598
|
+
try {
|
|
599
|
+
const WebSocket = require("ws");
|
|
600
|
+
const ws = new WebSocket("ws://localhost:24678");
|
|
601
|
+
ws.on("open", () => {
|
|
602
|
+
if (debugLog) {
|
|
603
|
+
console.log("🔥 Sending HMR notification to bridge:", message.type);
|
|
604
|
+
}
|
|
605
|
+
ws.send(JSON.stringify(message));
|
|
606
|
+
ws.close();
|
|
607
|
+
});
|
|
608
|
+
ws.on("error", () => {
|
|
609
|
+
if (debugLog) {
|
|
610
|
+
console.log("🔥 HMR bridge not available (this is normal without HMR)");
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
catch (error) {
|
|
615
|
+
if (debugLog) {
|
|
616
|
+
console.log("🔥 WebSocket not available for HMR notifications");
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
copyRecursiveSync(src, dest, fs) {
|
|
621
|
+
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
622
|
+
const srcPath = path.join(src, entry.name);
|
|
623
|
+
const destPath = path.join(dest, entry.name);
|
|
624
|
+
if (entry.isDirectory()) {
|
|
625
|
+
fs.mkdirSync(destPath, { recursive: true });
|
|
626
|
+
this.copyRecursiveSync(srcPath, destPath, fs);
|
|
627
|
+
}
|
|
628
|
+
else if (entry.isFile() || entry.isSymbolicLink()) {
|
|
629
|
+
fs.copyFileSync(srcPath, destPath);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
exports.BundlerCompilerService = BundlerCompilerService;
|
|
635
|
+
__decorate([
|
|
636
|
+
(0, decorators_1.performanceLog)()
|
|
637
|
+
], BundlerCompilerService.prototype, "startBundleProcess", null);
|
|
638
|
+
function capitalizeFirstLetter(val) {
|
|
639
|
+
return String(val).charAt(0).toUpperCase() + String(val).slice(1);
|
|
640
|
+
}
|
|
641
|
+
yok_1.injector.register("bundlerCompilerService", BundlerCompilerService);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SPMService = void 0;
|
|
4
4
|
const yok_1 = require("../../common/yok");
|
|
5
|
-
const trapezedev_project_1 = require("@
|
|
5
|
+
const trapezedev_project_1 = require("@nstudio/trapezedev-project");
|
|
6
6
|
const path = require("path");
|
|
7
7
|
class SPMService {
|
|
8
8
|
constructor($logger, $projectConfigService, $xcodebuildCommandService, $xcodebuildArgsService) {
|
|
@@ -292,7 +292,9 @@ class AndroidLivesyncTool {
|
|
|
292
292
|
socket.removeAllListeners();
|
|
293
293
|
this.pendingConnectionData.socketTimer = setTimeout(tryConnect, 1000);
|
|
294
294
|
};
|
|
295
|
-
this.pendingConnectionData
|
|
295
|
+
if (this.pendingConnectionData) {
|
|
296
|
+
this.pendingConnectionData.socket = socket;
|
|
297
|
+
}
|
|
296
298
|
socket.once("data", (data) => {
|
|
297
299
|
socket.removeListener("close", tryConnectAfterTimeout);
|
|
298
300
|
socket.removeListener("error", tryConnectAfterTimeout);
|