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.
Files changed (33) hide show
  1. package/config/test-deps-versions-generated.json +16 -1
  2. package/lib/.d.ts +3 -3
  3. package/lib/bootstrap.js +1 -1
  4. package/lib/color.js +38 -7
  5. package/lib/commands/clean.js +1 -2
  6. package/lib/commands/embedding/embed.js +1 -1
  7. package/lib/commands/post-install.js +2 -2
  8. package/lib/commands/typings.js +12 -12
  9. package/lib/common/header.js +3 -3
  10. package/lib/common/logger/layouts/cli-layout.js +1 -1
  11. package/lib/common/logger/logger.js +2 -2
  12. package/lib/common/mobile/android/android-emulator-services.js +9 -7
  13. package/lib/common/mobile/device-log-provider.js +3 -4
  14. package/lib/common/mobile/emulator-helper.js +1 -0
  15. package/lib/common/services/hooks-service.js +23 -6
  16. package/lib/common/verify-node-version.js +1 -1
  17. package/lib/constants.js +6 -4
  18. package/lib/controllers/migrate-controller.js +3 -4
  19. package/lib/controllers/prepare-controller.js +9 -9
  20. package/lib/definitions/project.d.ts +19 -1
  21. package/lib/definitions/temp-service.d.ts +6 -2
  22. package/lib/helpers/key-command-helper.js +2 -1
  23. package/lib/project-data.js +10 -4
  24. package/lib/services/analytics-settings-service.js +2 -1
  25. package/lib/services/bundler/bundler-compiler-service.js +641 -0
  26. package/lib/services/bundler/bundler.js +2 -0
  27. package/lib/services/ios/spm-service.js +1 -1
  28. package/lib/services/livesync/android-livesync-tool.js +3 -1
  29. package/lib/services/temp-service.js +16 -4
  30. package/package.json +28 -33
  31. package/vendor/gradle-plugin/build.gradle +3 -3
  32. package/lib/services/webpack/webpack-compiler-service.js +0 -396
  33. package/lib/services/webpack/webpack.d.ts +0 -226
@@ -1,20 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TempService = void 0;
4
- const temp = require("temp");
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ const os_1 = require("os");
5
7
  const yok_1 = require("../common/yok");
6
8
  class TempService {
7
9
  constructor($cleanupService) {
8
10
  this.$cleanupService = $cleanupService;
9
- temp.track();
10
11
  }
11
12
  async mkdirSync(affixes) {
12
- const pathToDir = temp.mkdirSync(affixes);
13
+ var _a;
14
+ const opts = typeof affixes === "string" ? { prefix: affixes } : affixes;
15
+ const baseDir = (opts === null || opts === void 0 ? void 0 : opts.dir) ? opts.dir : (0, os_1.tmpdir)();
16
+ const prefix = ((_a = opts === null || opts === void 0 ? void 0 : opts.prefix) !== null && _a !== void 0 ? _a : "ns-").replace(/\s+/g, "-");
17
+ const pathToDir = fs.mkdtempSync(path.join(baseDir, prefix));
13
18
  await this.$cleanupService.addCleanupDeleteAction(pathToDir);
14
19
  return pathToDir;
15
20
  }
16
21
  async path(options) {
17
- const pathToFile = temp.path(options);
22
+ var _a, _b;
23
+ const opts = typeof options === "string" ? { prefix: options } : options;
24
+ const baseDir = (opts === null || opts === void 0 ? void 0 : opts.dir) ? opts.dir : (0, os_1.tmpdir)();
25
+ const prefix = ((_a = opts === null || opts === void 0 ? void 0 : opts.prefix) !== null && _a !== void 0 ? _a : "ns-").replace(/\s+/g, "-");
26
+ const suffix = (_b = opts === null || opts === void 0 ? void 0 : opts.suffix) !== null && _b !== void 0 ? _b : "";
27
+ const unique = Math.random().toString(36).slice(2);
28
+ const filePath = path.join(baseDir, `${prefix}${unique}${suffix}`);
29
+ const pathToFile = filePath;
18
30
  await this.$cleanupService.addCleanupDeleteAction(pathToFile);
19
31
  return pathToFile;
20
32
  }
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.0",
4
+ "version": "9.0.0-alpha.10",
5
5
  "author": "NativeScript <oss@nativescript.org>",
6
6
  "description": "Command-line interface for building NativeScript projects",
7
7
  "bin": {
@@ -51,19 +51,17 @@
51
51
  "keywords": [
52
52
  "nativescript",
53
53
  "typescript",
54
- "mobile"
54
+ "javascript"
55
55
  ],
56
56
  "dependencies": {
57
- "@foxt/js-srp": "^0.0.3-patch2",
58
- "@nativescript/doctor": "2.0.16-rc.0",
59
- "@npmcli/arborist": "^9.0.0",
57
+ "@foxt/js-srp": "0.0.3-patch2",
58
+ "@nativescript/doctor": "2.0.17",
59
+ "@npmcli/arborist": "9.1.4",
60
60
  "@rigor789/resolve-package-path": "1.0.7",
61
- "@rigor789/trapezedev-project": "7.1.2",
62
- "ansi-colors": "^4.1.3",
63
- "archiver": "^7.0.1",
64
- "axios": "1.7.9",
61
+ "@nstudio/trapezedev-project": "7.2.3",
62
+ "archiver": "7.0.1",
63
+ "axios": "1.11.0",
65
64
  "byline": "5.0.0",
66
- "chalk": "4.1.2",
67
65
  "chokidar": "4.0.3",
68
66
  "cli-table3": "0.6.5",
69
67
  "color": "4.2.3",
@@ -72,16 +70,15 @@
72
70
  "email-validator": "2.0.4",
73
71
  "esprima": "4.0.1",
74
72
  "font-finder": "1.1.0",
75
- "glob": "11.0.1",
76
73
  "ios-device-lib": "0.9.4",
77
74
  "ios-mobileprovision-finder": "1.2.1",
78
- "ios-sim-portable": "4.5.0",
75
+ "ios-sim-portable": "4.5.1",
79
76
  "jimp": "1.6.0",
80
77
  "lodash": "4.17.21",
81
78
  "log4js": "6.9.1",
82
- "marked": "15.0.7",
79
+ "marked": "15.0.12",
83
80
  "marked-terminal": "7.3.0",
84
- "minimatch": "10.0.1",
81
+ "minimatch": "10.0.3",
85
82
  "mkdirp": "3.0.1",
86
83
  "mute-stream": "2.0.0",
87
84
  "nativescript-dev-xcode": "0.8.1",
@@ -91,37 +88,35 @@
91
88
  "pbxproj-dom": "1.2.0",
92
89
  "plist": "3.1.0",
93
90
  "plist-merge-patch": "0.2.0",
94
- "prettier": "3.5.2",
91
+ "prettier": "3.6.2",
95
92
  "prompts": "2.4.2",
96
93
  "proper-lockfile": "4.1.2",
97
- "proxy-lib": "0.4.0",
94
+ "proxy-lib": "0.4.1",
98
95
  "qr-image": "3.2.0",
99
96
  "qrcode-terminal": "0.12.0",
100
- "semver": "7.7.1",
101
- "shelljs": "0.8.5",
97
+ "semver": "7.7.2",
98
+ "shelljs": "0.10.0",
102
99
  "simple-git": "3.27.0",
103
100
  "simple-plist": "1.4.0",
104
- "source-map": "0.7.4",
101
+ "source-map": "0.7.6",
105
102
  "tar": "7.4.3",
106
- "temp": "0.9.4",
107
103
  "ts-morph": "25.0.1",
108
104
  "tunnel": "0.0.6",
109
105
  "typescript": "5.7.3",
110
106
  "universal-analytics": "0.5.3",
111
107
  "uuid": "11.1.0",
112
108
  "winreg": "1.2.5",
113
- "ws": "8.18.1",
109
+ "ws": "8.18.3",
114
110
  "xml2js": "0.6.2",
115
111
  "yargs": "17.7.2"
116
112
  },
117
113
  "devDependencies": {
118
114
  "@types/archiver": "^6.0.3",
119
115
  "@types/byline": "^4.2.36",
120
- "@types/chai": "5.0.1",
121
- "@types/chai-as-promised": "8.0.1",
116
+ "@types/chai": "5.2.2",
117
+ "@types/chai-as-promised": "8.0.2",
122
118
  "@types/color": "4.2.0",
123
119
  "@types/convert-source-map": "2.0.3",
124
- "@types/glob": "^8.1.0",
125
120
  "@types/lodash": "4.17.15",
126
121
  "@types/marked-terminal": "^6.1.1",
127
122
  "@types/node": "^22.0.0",
@@ -132,20 +127,20 @@
132
127
  "@types/proper-lockfile": "4.1.4",
133
128
  "@types/qr-image": "3.2.9",
134
129
  "@types/retry": "0.12.5",
135
- "@types/semver": "7.5.8",
130
+ "@types/semver": "7.7.1",
136
131
  "@types/shelljs": "^0.8.11",
137
132
  "@types/sinon": "^17.0.3",
138
133
  "@types/tabtab": "^3.0.2",
139
134
  "@types/tar": "6.1.13",
140
- "@types/temp": "0.9.4",
141
135
  "@types/tunnel": "0.0.7",
142
136
  "@types/universal-analytics": "0.4.8",
143
137
  "@types/uuid": "^10.0.0",
144
- "@types/ws": "8.5.14",
138
+ "@types/ws": "8.18.1",
145
139
  "@types/xml2js": "0.4.14",
146
140
  "@types/yargs": "17.0.33",
147
- "chai": "5.2.0",
148
- "chai-as-promised": "8.0.1",
141
+ "braces": ">=3.0.3",
142
+ "chai": "5.3.3",
143
+ "chai-as-promised": "8.0.2",
149
144
  "conventional-changelog-cli": "^5.0.0",
150
145
  "grunt": "1.6.1",
151
146
  "grunt-contrib-clean": "2.0.1",
@@ -156,11 +151,11 @@
156
151
  "grunt-ts": "6.0.0-beta.22",
157
152
  "husky": "9.1.7",
158
153
  "istanbul": "0.4.5",
159
- "latest-version": "9.0.0",
160
- "lint-staged": "~15.4.3",
154
+ "lint-staged": "~15.5.2",
161
155
  "mocha": "11.1.0",
162
- "sinon": "19.0.2",
163
- "source-map-support": "0.5.21"
156
+ "sinon": "19.0.5",
157
+ "source-map-support": "0.5.21",
158
+ "xml2js": ">=0.5.0"
164
159
  },
165
160
  "optionalDependencies": {
166
161
  "fsevents": "*"
@@ -159,10 +159,10 @@ allprojects {
159
159
  }
160
160
 
161
161
 
162
- def computeCompileSdkVersion = { -> project.hasProperty("compileSdk") ? compileSdk : 34 }
163
- def computeTargetSdkVersion = { -> project.hasProperty("targetSdk") ? targetSdk : 34 as int }
162
+ def computeCompileSdkVersion = { -> project.hasProperty("compileSdk") ? compileSdk : 35 }
163
+ def computeTargetSdkVersion = { -> project.hasProperty("targetSdk") ? targetSdk : 35 as int }
164
164
  def computeBuildToolsVersion = { ->
165
- project.hasProperty("buildToolsVersion") ? buildToolsVersion : "34.0.0"
165
+ project.hasProperty("buildToolsVersion") ? buildToolsVersion : "35.0.1"
166
166
  }
167
167
 
168
168
  android {
@@ -1,396 +0,0 @@
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.WebpackCompilerService = 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
- class WebpackCompilerService extends events_1.EventEmitter {
19
- constructor($options, $errors, $childProcess, $fs, $hooksService, $hostInfo, $logger, $mobileHelper, $cleanupService, $packageManager, $packageInstallationManager) {
20
- super();
21
- this.$options = $options;
22
- this.$errors = $errors;
23
- this.$childProcess = $childProcess;
24
- this.$fs = $fs;
25
- this.$hooksService = $hooksService;
26
- this.$hostInfo = $hostInfo;
27
- this.$logger = $logger;
28
- this.$mobileHelper = $mobileHelper;
29
- this.$cleanupService = $cleanupService;
30
- this.$packageManager = $packageManager;
31
- this.$packageInstallationManager = $packageInstallationManager;
32
- this.webpackProcesses = {};
33
- this.expectedHashes = {};
34
- }
35
- async compileWithWatch(platformData, projectData, prepareData) {
36
- return new Promise(async (resolve, reject) => {
37
- if (this.webpackProcesses[platformData.platformNameLowerCase]) {
38
- resolve(void 0);
39
- return;
40
- }
41
- let isFirstWebpackWatchCompilation = true;
42
- prepareData.watch = true;
43
- try {
44
- const childProcess = await this.startWebpackProcess(platformData, projectData, prepareData);
45
- childProcess.stdout.on("data", function (data) {
46
- process.stdout.write(data);
47
- });
48
- childProcess.stderr.on("data", function (data) {
49
- process.stderr.write(data);
50
- });
51
- childProcess.on("message", (message) => {
52
- this.$logger.trace("Message from webpack", message);
53
- if (typeof message === "object" &&
54
- "version" in message &&
55
- "type" in message) {
56
- if (isFirstWebpackWatchCompilation) {
57
- isFirstWebpackWatchCompilation = false;
58
- resolve(childProcess);
59
- return;
60
- }
61
- return this.handleHMRMessage(message, platformData, projectData, prepareData);
62
- }
63
- if (message === "Webpack compilation complete.") {
64
- this.$logger.info("Webpack build done!");
65
- resolve(childProcess);
66
- }
67
- message = message;
68
- if (message.emittedFiles) {
69
- if (isFirstWebpackWatchCompilation) {
70
- isFirstWebpackWatchCompilation = false;
71
- this.expectedHashes[platformData.platformNameLowerCase] =
72
- prepareData.hmr ? message.hash : "";
73
- return;
74
- }
75
- const previousHash = this.expectedHashes[platformData.platformNameLowerCase];
76
- let result;
77
- if (prepareData.hmr) {
78
- result = this.getUpdatedEmittedFiles(message.emittedFiles, message.chunkFiles, message.hash, platformData.platformNameLowerCase);
79
- }
80
- else {
81
- result = {
82
- emittedFiles: message.emittedFiles,
83
- fallbackFiles: [],
84
- hash: "",
85
- };
86
- }
87
- const files = result.emittedFiles.map((file) => path.join(platformData.appDestinationDirectoryPath, this.$options.hostProjectModuleName, file));
88
- const fallbackFiles = result.fallbackFiles.map((file) => path.join(platformData.appDestinationDirectoryPath, this.$options.hostProjectModuleName, file));
89
- const data = {
90
- files,
91
- hasOnlyHotUpdateFiles: files.every((f) => f.indexOf("hot-update") > -1),
92
- hmrData: {
93
- hash: result.hash,
94
- fallbackFiles,
95
- },
96
- platform: platformData.platformNameLowerCase,
97
- };
98
- this.$logger.trace("Generated data from webpack message:", data);
99
- if (data.hasOnlyHotUpdateFiles && previousHash === message.hash) {
100
- return;
101
- }
102
- if (data.files.length) {
103
- this.emit(constants_1.WEBPACK_COMPILATION_COMPLETE, data);
104
- }
105
- }
106
- });
107
- childProcess.on("error", (err) => {
108
- this.$logger.trace(`Unable to start webpack process in watch mode. Error is: ${err}`);
109
- delete this.webpackProcesses[platformData.platformNameLowerCase];
110
- reject(err);
111
- });
112
- childProcess.on("close", async (arg) => {
113
- await this.$cleanupService.removeKillProcess(childProcess.pid.toString());
114
- const exitCode = typeof arg === "number" ? arg : arg && arg.code;
115
- this.$logger.trace(`Webpack process exited with code ${exitCode} when we expected it to be long living with watch.`);
116
- const error = new Error(`Executing webpack failed with exit code ${exitCode}.`);
117
- error.code = exitCode;
118
- delete this.webpackProcesses[platformData.platformNameLowerCase];
119
- reject(error);
120
- });
121
- }
122
- catch (err) {
123
- reject(err);
124
- }
125
- });
126
- }
127
- async compileWithoutWatch(platformData, projectData, prepareData) {
128
- return new Promise(async (resolve, reject) => {
129
- if (this.webpackProcesses[platformData.platformNameLowerCase]) {
130
- resolve();
131
- return;
132
- }
133
- try {
134
- const childProcess = await this.startWebpackProcess(platformData, projectData, prepareData);
135
- childProcess.on("error", (err) => {
136
- this.$logger.trace(`Unable to start webpack process in non-watch mode. Error is: ${err}`);
137
- delete this.webpackProcesses[platformData.platformNameLowerCase];
138
- reject(err);
139
- });
140
- childProcess.on("close", async (arg) => {
141
- await this.$cleanupService.removeKillProcess(childProcess.pid.toString());
142
- delete this.webpackProcesses[platformData.platformNameLowerCase];
143
- const exitCode = typeof arg === "number" ? arg : arg && arg.code;
144
- if (exitCode === 0) {
145
- resolve();
146
- }
147
- else {
148
- const error = new Error(`Executing webpack failed with exit code ${exitCode}.`);
149
- error.code = exitCode;
150
- reject(error);
151
- }
152
- });
153
- }
154
- catch (err) {
155
- reject(err);
156
- }
157
- });
158
- }
159
- async stopWebpackCompiler(platform) {
160
- if (platform) {
161
- await this.stopWebpackForPlatform(platform);
162
- }
163
- else {
164
- const webpackedPlatforms = Object.keys(this.webpackProcesses);
165
- for (let i = 0; i < webpackedPlatforms.length; i++) {
166
- await this.stopWebpackForPlatform(webpackedPlatforms[i]);
167
- }
168
- }
169
- }
170
- async shouldUsePreserveSymlinksOption() {
171
- const currentPackageManager = await this.$packageManager.getPackageManagerName();
172
- const res = currentPackageManager !== constants_1.PackageManagers.pnpm;
173
- return res;
174
- }
175
- async startWebpackProcess(platformData, projectData, prepareData) {
176
- if (!this.$fs.exists(projectData.webpackConfigPath)) {
177
- this.$errors.fail(`The webpack configuration file ${projectData.webpackConfigPath} does not exist. Ensure the file exists, or update the path in ${constants_1.CONFIG_FILE_NAME_DISPLAY}.`);
178
- }
179
- const envData = this.buildEnvData(platformData.platformNameLowerCase, projectData, prepareData);
180
- const envParams = await this.buildEnvCommandLineParams(envData, platformData, projectData, prepareData);
181
- const additionalNodeArgs = semver.major(process.version) <= 8 ? ["--harmony"] : [];
182
- if (await this.shouldUsePreserveSymlinksOption()) {
183
- additionalNodeArgs.push("--preserve-symlinks");
184
- }
185
- if (process.arch === "x64") {
186
- additionalNodeArgs.unshift("--max_old_space_size=4096");
187
- }
188
- const args = [
189
- ...additionalNodeArgs,
190
- this.getWebpackExecutablePath(projectData),
191
- this.isWebpack5(projectData) ? `build` : null,
192
- `--config=${projectData.webpackConfigPath}`,
193
- ...envParams,
194
- ].filter(Boolean);
195
- if (prepareData.watch) {
196
- args.push("--watch");
197
- }
198
- const stdio = prepareData.watch ? ["ipc"] : "inherit";
199
- const options = {
200
- cwd: projectData.projectDir,
201
- stdio,
202
- };
203
- options.env = {
204
- NATIVESCRIPT_WEBPACK_ENV: JSON.stringify(envData),
205
- };
206
- if (this.$hostInfo.isWindows) {
207
- Object.assign(options.env, { APPDATA: process.env.appData });
208
- }
209
- if (this.$options.hostProjectPath) {
210
- Object.assign(options.env, {
211
- USER_PROJECT_PLATFORMS_ANDROID: this.$options.hostProjectPath,
212
- USER_PROJECT_PLATFORMS_ANDROID_MODULE: this.$options.hostProjectModuleName,
213
- USER_PROJECT_PLATFORMS_IOS: this.$options.hostProjectPath,
214
- });
215
- }
216
- const childProcess = this.$childProcess.spawn(process.execPath, args, options);
217
- this.webpackProcesses[platformData.platformNameLowerCase] = childProcess;
218
- await this.$cleanupService.addKillProcess(childProcess.pid.toString());
219
- return childProcess;
220
- }
221
- buildEnvData(platform, projectData, prepareData) {
222
- var _a, _b, _c;
223
- const { env } = prepareData;
224
- const envData = Object.assign({}, env, { [platform.toLowerCase()]: true });
225
- const appId = projectData.projectIdentifiers[platform];
226
- const appPath = projectData.getAppDirectoryRelativePath();
227
- const appResourcesPath = projectData.getAppResourcesRelativeDirectoryPath();
228
- Object.assign(envData, appId && { appId }, appPath && { appPath }, appResourcesPath && { appResourcesPath }, {
229
- nativescriptLibPath: path.resolve(__dirname, "..", "..", "nativescript-cli-lib.js"),
230
- });
231
- envData.verbose = envData.verbose || this.$logger.isVerbose();
232
- envData.production = envData.production || prepareData.release;
233
- envData.config =
234
- (_b = (_a = process.env.NATIVESCRIPT_CONFIG_NAME) !== null && _a !== void 0 ? _a : this.$options.config) !== null && _b !== void 0 ? _b : "false";
235
- process.env.NATIVESCRIPT_CONFIG_NAME = envData.config;
236
- envData.skipSnapshotTools =
237
- prepareData.nativePrepare && prepareData.nativePrepare.skipNativePrepare;
238
- if (typeof ((_c = prepareData === null || prepareData === void 0 ? void 0 : prepareData.env) === null || _c === void 0 ? void 0 : _c.sourceMap) === "undefined") {
239
- if (!prepareData.release) {
240
- envData.sourceMap = true;
241
- }
242
- }
243
- if (envData.sourceMap === "true" || envData.sourceMap === "false") {
244
- envData.sourceMap = envData.sourceMap === "true";
245
- }
246
- if (prepareData.uniqueBundle > 0) {
247
- envData.uniqueBundle = prepareData.uniqueBundle;
248
- }
249
- return envData;
250
- }
251
- async buildEnvCommandLineParams(envData, platformData, projectData, prepareData) {
252
- const envFlagNames = Object.keys(envData);
253
- const canSnapshot = prepareData.release &&
254
- this.$mobileHelper.isAndroidPlatform(platformData.normalizedPlatformName);
255
- if (envData && envData.snapshot) {
256
- if (!canSnapshot) {
257
- this.$logger.warn("Stripping the snapshot flag. " +
258
- "Bear in mind that snapshot is only available in Android release builds.");
259
- envFlagNames.splice(envFlagNames.indexOf("snapshot"), 1);
260
- }
261
- else if (this.$hostInfo.isWindows) {
262
- const minWebpackPluginWithWinSnapshotsVersion = "1.3.0";
263
- const installedWebpackPluginVersion = await this.$packageInstallationManager.getInstalledDependencyVersion(constants_1.WEBPACK_PLUGIN_NAME, projectData.projectDir);
264
- const hasWebpackPluginWithWinSnapshotsSupport = !!installedWebpackPluginVersion
265
- ? semver.gte(semver.coerce(installedWebpackPluginVersion), minWebpackPluginWithWinSnapshotsVersion)
266
- : true;
267
- if (!hasWebpackPluginWithWinSnapshotsSupport) {
268
- this.$errors.fail(`In order to generate Snapshots on Windows, please upgrade your Webpack plugin version (npm i ${constants_1.WEBPACK_PLUGIN_NAME}@latest).`);
269
- }
270
- }
271
- }
272
- const args = [];
273
- envFlagNames.map((item) => {
274
- let envValue = envData[item];
275
- if (typeof envValue === "undefined") {
276
- return;
277
- }
278
- if (typeof envValue === "boolean") {
279
- if (envValue) {
280
- args.push(`--env.${item}`);
281
- }
282
- }
283
- else {
284
- if (!Array.isArray(envValue)) {
285
- envValue = [envValue];
286
- }
287
- envValue.map((value) => args.push(`--env.${item}=${value}`));
288
- }
289
- });
290
- return args;
291
- }
292
- getUpdatedEmittedFiles(allEmittedFiles, chunkFiles, nextHash, platform) {
293
- const currentHash = this.getCurrentHotUpdateHash(allEmittedFiles);
294
- const isHashValid = nextHash
295
- ? this.expectedHashes[platform] === currentHash
296
- : true;
297
- this.expectedHashes[platform] = nextHash;
298
- const emittedHotUpdatesAndAssets = isHashValid
299
- ? _.difference(allEmittedFiles, chunkFiles)
300
- : allEmittedFiles;
301
- const fallbackFiles = chunkFiles.concat(emittedHotUpdatesAndAssets.filter((f) => f.indexOf("hot-update") === -1));
302
- return {
303
- emittedFiles: emittedHotUpdatesAndAssets,
304
- fallbackFiles,
305
- hash: currentHash,
306
- };
307
- }
308
- getCurrentHotUpdateHash(emittedFiles) {
309
- let hotHash;
310
- const hotUpdateScripts = emittedFiles.filter((x) => x.endsWith(".hot-update.js"));
311
- if (hotUpdateScripts && hotUpdateScripts.length) {
312
- const hotUpdateName = hotUpdateScripts[0];
313
- const matcher = /^(.+)\.(.+)\.hot-update/gm;
314
- const matches = matcher.exec(hotUpdateName);
315
- hotHash = matches[2];
316
- }
317
- return hotHash || "";
318
- }
319
- async stopWebpackForPlatform(platform) {
320
- this.$logger.trace(`Stopping webpack watch for platform ${platform}.`);
321
- const webpackProcess = this.webpackProcesses[platform];
322
- await this.$cleanupService.removeKillProcess(webpackProcess.pid.toString());
323
- if (webpackProcess) {
324
- webpackProcess.kill("SIGINT");
325
- delete this.webpackProcesses[platform];
326
- }
327
- }
328
- handleHMRMessage(message, platformData, projectData, prepareData) {
329
- this.$logger.trace("Received message from webpack process:", message);
330
- if (message.type !== "compilation") {
331
- return;
332
- }
333
- this.$logger.trace("Webpack build done!");
334
- const files = message.data.emittedAssets.map((asset) => path.join(platformData.appDestinationDirectoryPath, this.$options.hostProjectModuleName, asset));
335
- const staleFiles = message.data.staleAssets.map((asset) => path.join(platformData.appDestinationDirectoryPath, this.$options.hostProjectModuleName, asset));
336
- const lastHash = (() => {
337
- const absoluteFileNameWithLastHash = files.find((fileName) => fileName.endsWith("hot-update.js"));
338
- if (!absoluteFileNameWithLastHash) {
339
- return null;
340
- }
341
- const fileNameWithLastHash = path.basename(absoluteFileNameWithLastHash);
342
- const matches = fileNameWithLastHash.match(/\.(.+).hot-update\.js/);
343
- if (matches) {
344
- return matches[1];
345
- }
346
- })();
347
- if (!files.length) {
348
- return;
349
- }
350
- this.emit(constants_1.WEBPACK_COMPILATION_COMPLETE, {
351
- files,
352
- staleFiles,
353
- hasOnlyHotUpdateFiles: prepareData.hmr,
354
- hmrData: {
355
- hash: lastHash || message.hash,
356
- fallbackFiles: [],
357
- },
358
- platform: platformData.platformNameLowerCase,
359
- });
360
- }
361
- getWebpackExecutablePath(projectData) {
362
- if (this.isWebpack5(projectData)) {
363
- const packagePath = (0, package_path_helper_1.resolvePackagePath)("@nativescript/webpack", {
364
- paths: [projectData.projectDir],
365
- });
366
- if (packagePath) {
367
- return path.resolve(packagePath, "dist", "bin", "index.js");
368
- }
369
- }
370
- const packagePath = (0, package_path_helper_1.resolvePackagePath)("webpack", {
371
- paths: [projectData.projectDir],
372
- });
373
- if (!packagePath) {
374
- return "";
375
- }
376
- return path.resolve(packagePath, "bin", "webpack.js");
377
- }
378
- isWebpack5(projectData) {
379
- const packageJSONPath = (0, package_path_helper_1.resolvePackageJSONPath)("@nativescript/webpack", {
380
- paths: [projectData.projectDir],
381
- });
382
- if (packageJSONPath) {
383
- const packageData = this.$fs.readJson(packageJSONPath);
384
- const ver = semver.coerce(packageData.version);
385
- if (semver.satisfies(ver, ">= 5.0.0")) {
386
- return true;
387
- }
388
- }
389
- return false;
390
- }
391
- }
392
- exports.WebpackCompilerService = WebpackCompilerService;
393
- __decorate([
394
- (0, decorators_1.performanceLog)()
395
- ], WebpackCompilerService.prototype, "startWebpackProcess", null);
396
- yok_1.injector.register("webpackCompilerService", WebpackCompilerService);