@react-native-windows/cli 0.73.1 → 0.74.0-preview.1

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 (76) hide show
  1. package/lib-commonjs/commands/autolinkWindows/autolinkWindows.d.ts +87 -87
  2. package/lib-commonjs/commands/autolinkWindows/autolinkWindows.js +654 -654
  3. package/lib-commonjs/commands/autolinkWindows/autolinkWindowsOptions.d.ts +14 -14
  4. package/lib-commonjs/commands/autolinkWindows/autolinkWindowsOptions.js +32 -32
  5. package/lib-commonjs/commands/codegenWindows/codegenWindows.d.ts +27 -27
  6. package/lib-commonjs/commands/codegenWindows/codegenWindows.js +205 -205
  7. package/lib-commonjs/commands/codegenWindows/codegenWindowsOptions.d.ts +12 -12
  8. package/lib-commonjs/commands/codegenWindows/codegenWindowsOptions.js +22 -22
  9. package/lib-commonjs/commands/config/configUtils.d.ts +123 -123
  10. package/lib-commonjs/commands/config/configUtils.js +380 -380
  11. package/lib-commonjs/commands/config/dependencyConfig.d.ts +37 -37
  12. package/lib-commonjs/commands/config/dependencyConfig.js +227 -227
  13. package/lib-commonjs/commands/config/projectConfig.d.ts +27 -27
  14. package/lib-commonjs/commands/config/projectConfig.js +180 -180
  15. package/lib-commonjs/commands/healthCheck/healthCheckList.d.ts +6 -6
  16. package/lib-commonjs/commands/healthCheck/healthCheckList.js +20 -20
  17. package/lib-commonjs/commands/healthCheck/healthCheckList.js.map +1 -1
  18. package/lib-commonjs/commands/healthCheck/healthChecks.d.ts +7 -7
  19. package/lib-commonjs/commands/healthCheck/healthChecks.js +123 -123
  20. package/lib-commonjs/commands/initWindows/initWindows.d.ts +46 -46
  21. package/lib-commonjs/commands/initWindows/initWindows.js +243 -243
  22. package/lib-commonjs/commands/initWindows/initWindowsOptions.d.ts +15 -15
  23. package/lib-commonjs/commands/initWindows/initWindowsOptions.js +37 -37
  24. package/lib-commonjs/commands/runWindows/runWindows.d.ts +10 -10
  25. package/lib-commonjs/commands/runWindows/runWindows.js +321 -321
  26. package/lib-commonjs/commands/runWindows/runWindowsOptions.d.ts +56 -56
  27. package/lib-commonjs/commands/runWindows/runWindowsOptions.js +132 -132
  28. package/lib-commonjs/e2etest/autolink.test.d.ts +6 -6
  29. package/lib-commonjs/e2etest/autolink.test.js +366 -366
  30. package/lib-commonjs/e2etest/dependencyConfig.test.d.ts +6 -6
  31. package/lib-commonjs/e2etest/dependencyConfig.test.js +129 -129
  32. package/lib-commonjs/e2etest/healthChecks.test.d.ts +6 -6
  33. package/lib-commonjs/e2etest/healthChecks.test.js +30 -30
  34. package/lib-commonjs/e2etest/initWindows.test.d.ts +6 -6
  35. package/lib-commonjs/e2etest/initWindows.test.js +42 -42
  36. package/lib-commonjs/e2etest/projectConfig.test.d.ts +6 -6
  37. package/lib-commonjs/e2etest/projectConfig.test.js +110 -110
  38. package/lib-commonjs/e2etest/projectConfig.utils.d.ts +8 -8
  39. package/lib-commonjs/e2etest/projectConfig.utils.js +76 -76
  40. package/lib-commonjs/e2etest/runWindows.test.d.ts +6 -6
  41. package/lib-commonjs/e2etest/runWindows.test.js +60 -60
  42. package/lib-commonjs/e2etest/typesUpToDate.test.d.ts +6 -0
  43. package/lib-commonjs/e2etest/typesUpToDate.test.js +21 -0
  44. package/lib-commonjs/e2etest/typesUpToDate.test.js.map +1 -0
  45. package/lib-commonjs/generator-common/index.d.ts +39 -39
  46. package/lib-commonjs/generator-common/index.js +242 -242
  47. package/lib-commonjs/generator-windows/index.d.ts +10 -10
  48. package/lib-commonjs/generator-windows/index.js +316 -316
  49. package/lib-commonjs/index.d.ts +50 -50
  50. package/lib-commonjs/index.js +77 -77
  51. package/lib-commonjs/utils/build.d.ts +12 -12
  52. package/lib-commonjs/utils/build.js +84 -84
  53. package/lib-commonjs/utils/checkRequirements.d.ts +6 -6
  54. package/lib-commonjs/utils/checkRequirements.js +69 -69
  55. package/lib-commonjs/utils/commandWithProgress.d.ts +21 -21
  56. package/lib-commonjs/utils/commandWithProgress.js +149 -149
  57. package/lib-commonjs/utils/deploy.d.ts +12 -12
  58. package/lib-commonjs/utils/deploy.js +353 -353
  59. package/lib-commonjs/utils/info.d.ts +6 -6
  60. package/lib-commonjs/utils/info.js +28 -28
  61. package/lib-commonjs/utils/msbuildtools.d.ts +28 -28
  62. package/lib-commonjs/utils/msbuildtools.js +273 -273
  63. package/lib-commonjs/utils/msbuildtools.js.map +1 -1
  64. package/lib-commonjs/utils/pathHelpers.d.ts +9 -9
  65. package/lib-commonjs/utils/pathHelpers.js +36 -36
  66. package/lib-commonjs/utils/telemetryHelpers.d.ts +29 -29
  67. package/lib-commonjs/utils/telemetryHelpers.js +120 -120
  68. package/lib-commonjs/utils/version.d.ts +19 -19
  69. package/lib-commonjs/utils/version.js +109 -109
  70. package/lib-commonjs/utils/vsInstalls.d.ts +34 -34
  71. package/lib-commonjs/utils/vsInstalls.js +99 -99
  72. package/lib-commonjs/utils/vstools.d.ts +16 -16
  73. package/lib-commonjs/utils/vstools.js +189 -189
  74. package/lib-commonjs/utils/winappdeploytool.d.ts +24 -24
  75. package/lib-commonjs/utils/winappdeploytool.js +108 -108
  76. package/package.json +16 -16
@@ -1,274 +1,274 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Microsoft Corporation.
4
- * Licensed under the MIT License.
5
- * @format
6
- */
7
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
- if (k2 === undefined) k2 = k;
9
- var desc = Object.getOwnPropertyDescriptor(m, k);
10
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
- desc = { enumerable: true, get: function() { return m[k]; } };
12
- }
13
- Object.defineProperty(o, k2, desc);
14
- }) : (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- o[k2] = m[k];
17
- }));
18
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
- Object.defineProperty(o, "default", { enumerable: true, value: v });
20
- }) : function(o, v) {
21
- o["default"] = v;
22
- });
23
- var __importStar = (this && this.__importStar) || function (mod) {
24
- if (mod && mod.__esModule) return mod;
25
- var result = {};
26
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
27
- __setModuleDefault(result, mod);
28
- return result;
29
- };
30
- var __importDefault = (this && this.__importDefault) || function (mod) {
31
- return (mod && mod.__esModule) ? mod : { "default": mod };
32
- };
33
- Object.defineProperty(exports, "__esModule", { value: true });
34
- const os_1 = require("os");
35
- const fs_1 = __importDefault(require("@react-native-windows/fs"));
36
- const path_1 = __importDefault(require("path"));
37
- const child_process_1 = __importDefault(require("child_process"));
38
- const chalk_1 = __importDefault(require("chalk"));
39
- const os_2 = __importDefault(require("os"));
40
- const shelljs_1 = __importDefault(require("shelljs"));
41
- const version_1 = __importDefault(require("./version"));
42
- const checkRequirements = __importStar(require("./checkRequirements"));
43
- const commandWithProgress_1 = require("./commandWithProgress");
44
- const child_process_2 = require("child_process");
45
- const vsInstalls_1 = require("./vsInstalls");
46
- const telemetry_1 = require("@react-native-windows/telemetry");
47
- class MSBuildTools {
48
- /**
49
- * @param version is something like 17.0 for 2022
50
- * @param installationPath Path to installation root
51
- * @param installationVersion is the full version e.g. 17.3.32929.385
52
- */
53
- constructor(version, installationPath, installationVersion) {
54
- this.version = version;
55
- this.installationPath = installationPath;
56
- this.installationVersion = installationVersion;
57
- }
58
- /**
59
- * @returns directory where x86 msbuild can be found
60
- */
61
- msbuildPath() {
62
- return path_1.default.join(this.installationPath, 'MSBuild/Current/Bin');
63
- }
64
- cleanProject(slnFile) {
65
- const cmd = `"${path_1.default.join(this.msbuildPath(), 'msbuild.exe')}" "${slnFile}" /t:Clean`;
66
- const results = child_process_1.default.execSync(cmd).toString().split(os_1.EOL);
67
- results.forEach(result => console.log(chalk_1.default.white(result)));
68
- }
69
- async restorePackageConfigs(slnFile, buildArch, buildType) {
70
- const text = 'Restoring NuGet packages ';
71
- const spinner = (0, commandWithProgress_1.newSpinner)(text);
72
- await (0, commandWithProgress_1.commandWithProgress)(spinner, text, path_1.default.join(this.msbuildPath(), 'msbuild.exe'), [
73
- slnFile,
74
- '/t:Restore',
75
- '/p:RestoreProjectStyle=PackagesConfig',
76
- '/p:RestorePackagesConfig=true',
77
- `/p:Platform=${buildArch}`,
78
- `/p:Configuration=${buildType}`,
79
- ], true, 'MSBuildError');
80
- }
81
- async buildProject(slnFile, buildType, buildArch, msBuildProps, verbose, target, buildLogDirectory, singleproc) {
82
- (0, commandWithProgress_1.newSuccess)(`Found Solution: ${slnFile}`);
83
- (0, commandWithProgress_1.newInfo)(`Build configuration: ${buildType}`);
84
- (0, commandWithProgress_1.newInfo)(`Build platform: ${buildArch}`);
85
- const verbosityOption = verbose ? 'normal' : 'minimal';
86
- const logPrefix = path_1.default.join(buildLogDirectory || os_2.default.tmpdir(), `msbuild_${process.pid}_${target}`);
87
- const errorLog = logPrefix + '.err';
88
- const warnLog = logPrefix + '.wrn';
89
- const localBinLog = target === 'build' ? '' : ':deploy.binlog';
90
- const binlog = buildLogDirectory ? `:${logPrefix}.binlog` : localBinLog;
91
- const args = [
92
- `/clp:NoSummary;NoItemAndPropertyList;Verbosity=${verbosityOption}`,
93
- '/nologo',
94
- `/p:Configuration=${buildType}`,
95
- `/p:Platform=${buildArch}`,
96
- '/p:AppxBundle=Never',
97
- `/bl${binlog}`,
98
- `/flp1:errorsonly;logfile=${errorLog}`,
99
- `/flp2:warningsonly;logfile=${warnLog}`,
100
- ];
101
- // Building projects in parallel increases compiler memory usage and
102
- // doesn't lead to dramatic performance gains (See #4739). Only enable
103
- // parallel builds on machines with >16GB of memory to avoid OOM errors
104
- const highMemory = (0, os_1.totalmem)() > 16 * 1024 * 1024 * 1024;
105
- const enableParallelBuilds = singleproc === false || highMemory;
106
- if (enableParallelBuilds) {
107
- args.push('/maxCpuCount');
108
- }
109
- if (target === 'build') {
110
- args.push('/restore', '/p:RestorePackagesConfig=true');
111
- }
112
- else {
113
- args.push(`/t:Deploy`);
114
- }
115
- Object.keys(msBuildProps).forEach(key => {
116
- args.push(`/p:${key}=${msBuildProps[key]}`);
117
- });
118
- try {
119
- checkRequirements.isWinSdkPresent('10.0');
120
- }
121
- catch (e) {
122
- (0, commandWithProgress_1.newError)(e.message);
123
- throw e;
124
- }
125
- if (verbose) {
126
- console.log(`Running MSBuild with args ${args.join(' ')}`);
127
- }
128
- const progressName = target === 'deploy' ? 'Deploying Solution' : 'Building Solution';
129
- const spinner = (0, commandWithProgress_1.newSpinner)(progressName);
130
- try {
131
- await (0, commandWithProgress_1.commandWithProgress)(spinner, progressName, path_1.default.join(this.msbuildPath(), 'msbuild.exe'), [slnFile].concat(args), verbose, 'MSBuildError');
132
- }
133
- catch (e) {
134
- let error = e;
135
- if (e instanceof telemetry_1.CodedError) {
136
- const origCodedError = e;
137
- if (origCodedError.type === 'MSBuildError') {
138
- // Try to parse msbuild errors from errorLog
139
- const errorLogContents = (await fs_1.default.readFile(errorLog))
140
- .toString()
141
- .split(os_1.EOL)
142
- .filter(s => s)
143
- .map(s => s.trim());
144
- if (errorLogContents.length > 0) {
145
- const firstMessage = errorLogContents[0];
146
- error = new telemetry_1.CodedError('MSBuildError', firstMessage, origCodedError.data);
147
- // Hide error messages in a field that won't automatically get reported
148
- // with telemetry but is still available to be parsed and sanitized
149
- error.msBuildErrorMessages = errorLogContents;
150
- }
151
- }
152
- }
153
- throw error;
154
- }
155
- // If we have no errors, delete the error log when we're done
156
- if ((await fs_1.default.stat(errorLog)).size === 0) {
157
- await fs_1.default.unlink(errorLog);
158
- }
159
- }
160
- static findAvailableVersion(buildArch, verbose, prerelease) {
161
- // https://aka.ms/vs/workloads
162
- const requires = [
163
- 'Microsoft.Component.MSBuild',
164
- getVCToolsByArch(buildArch),
165
- ];
166
- const minVersion = process.env.VisualStudioVersion || '17.0';
167
- const vsInstallation = (0, vsInstalls_1.findLatestVsInstall)({
168
- requires,
169
- minVersion,
170
- verbose,
171
- prerelease,
172
- });
173
- if (!vsInstallation) {
174
- if (process.env.VisualStudioVersion != null) {
175
- throw new telemetry_1.CodedError('NoMSBuild', `MSBuild tools not found for version ${process.env.VisualStudioVersion} (from environment). Make sure all required components have been installed`, { VisualStudioVersionFromEnv: process.env.VisualStudioVersion });
176
- }
177
- else {
178
- throw new telemetry_1.CodedError('NoMSBuild', `Could not find MSBuild with VCTools for Visual Studio ${minVersion} or later. Make sure all required components have been installed`, { minVersion: minVersion });
179
- }
180
- }
181
- const toolsPath = path_1.default.join(vsInstallation.installationPath, 'MSBuild/Current/Bin');
182
- if (fs_1.default.existsSync(toolsPath)) {
183
- if (verbose) {
184
- (0, commandWithProgress_1.newSuccess)(`Found compatible MSBuild at ${toolsPath} (${vsInstallation.installationVersion})`);
185
- }
186
- return new MSBuildTools(minVersion, vsInstallation.installationPath, vsInstallation.installationVersion);
187
- }
188
- else {
189
- throw new telemetry_1.CodedError('NoMSBuild', `MSBuild path '${toolsPath} does not exist'`);
190
- }
191
- }
192
- static getAllAvailableUAPVersions() {
193
- const results = [];
194
- const programFilesFolder = process.env['ProgramFiles(x86)'] || process.env.ProgramFiles;
195
- // No Program Files folder found, so we won't be able to find UAP SDK
196
- if (!programFilesFolder) {
197
- return results;
198
- }
199
- let uapFolderPath = path_1.default.join(programFilesFolder, 'Windows Kits', '10', 'Platforms', 'UAP');
200
- if (!shelljs_1.default.test('-e', uapFolderPath)) {
201
- // Check other installation folder from reg
202
- const sdkFolder = getSDK10InstallationFolder();
203
- if (sdkFolder) {
204
- uapFolderPath = path_1.default.join(sdkFolder, 'Platforms', 'UAP');
205
- }
206
- }
207
- // No UAP SDK exists on this machine
208
- if (!shelljs_1.default.test('-e', uapFolderPath)) {
209
- return results;
210
- }
211
- shelljs_1.default
212
- .ls(uapFolderPath)
213
- .filter(uapDir => shelljs_1.default.test('-d', path_1.default.join(uapFolderPath, uapDir)))
214
- .map(version_1.default.tryParse)
215
- .forEach(version => version && results.push(version));
216
- return results;
217
- }
218
- evaluateMSBuildProperties(solutionFile, projectFile, propertyNames, extraMsBuildProps) {
219
- const spinner = (0, commandWithProgress_1.newSpinner)('Running Eval-MsBuildProperties.ps1');
220
- try {
221
- const msbuildEvalScriptPath = path_1.default.resolve(__dirname, '..', '..', 'src', 'powershell', 'Eval-MsBuildProperties.ps1');
222
- let command = `${commandWithProgress_1.powershell} -ExecutionPolicy Unrestricted -NoProfile "${msbuildEvalScriptPath}" -SolutionFile '${solutionFile}' -ProjectFile '${projectFile}' -MSBuildPath '${this.msbuildPath()}'`;
223
- if (propertyNames && propertyNames.length > 0) {
224
- command += ` -PropertyNames '${propertyNames.join(',')}'`;
225
- }
226
- if (extraMsBuildProps) {
227
- command += " -ExtraMSBuildProps '";
228
- for (const extraProp in extraMsBuildProps) {
229
- if (!(extraProp in Object.prototype)) {
230
- command += `,${extraProp}=${extraMsBuildProps[extraProp]}`;
231
- }
232
- }
233
- command += "'";
234
- }
235
- const commandOutput = (0, child_process_2.execSync)(command).toString();
236
- spinner.succeed();
237
- const properties = JSON.parse(commandOutput);
238
- spinner.succeed();
239
- return properties;
240
- }
241
- catch (e) {
242
- spinner.fail('Running Eval-MsBuildProperties.ps1 failed: ' + e.message);
243
- throw e;
244
- }
245
- }
246
- }
247
- exports.default = MSBuildTools;
248
- function getVCToolsByArch(buildArch) {
249
- switch (buildArch) {
250
- case 'x86':
251
- case 'x64':
252
- return 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64';
253
- case 'ARM64':
254
- return 'Microsoft.VisualStudio.Component.VC.Tools.ARM64';
255
- }
256
- }
257
- function getSDK10InstallationFolder() {
258
- const folder = '';
259
- const execString = 'reg query "HKLM\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v10.0" /s /v InstallationFolder /reg:32';
260
- let output;
261
- try {
262
- output = (0, child_process_2.execSync)(execString).toString();
263
- }
264
- catch (e) {
265
- return folder;
266
- }
267
- const re = /\\Microsoft SDKs\\Windows\\v10.0\s*InstallationFolder\s+REG_SZ\s+(.*)/gim;
268
- const match = re.exec(output);
269
- if (match) {
270
- return match[1];
271
- }
272
- return folder;
273
- }
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation.
4
+ * Licensed under the MIT License.
5
+ * @format
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || function (mod) {
24
+ if (mod && mod.__esModule) return mod;
25
+ var result = {};
26
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
27
+ __setModuleDefault(result, mod);
28
+ return result;
29
+ };
30
+ var __importDefault = (this && this.__importDefault) || function (mod) {
31
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32
+ };
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ const os_1 = require("os");
35
+ const fs_1 = __importDefault(require("@react-native-windows/fs"));
36
+ const path_1 = __importDefault(require("path"));
37
+ const child_process_1 = __importDefault(require("child_process"));
38
+ const chalk_1 = __importDefault(require("chalk"));
39
+ const os_2 = __importDefault(require("os"));
40
+ const shelljs_1 = __importDefault(require("shelljs"));
41
+ const version_1 = __importDefault(require("./version"));
42
+ const checkRequirements = __importStar(require("./checkRequirements"));
43
+ const commandWithProgress_1 = require("./commandWithProgress");
44
+ const child_process_2 = require("child_process");
45
+ const vsInstalls_1 = require("./vsInstalls");
46
+ const telemetry_1 = require("@react-native-windows/telemetry");
47
+ class MSBuildTools {
48
+ /**
49
+ * @param version is something like 17.0 for 2022
50
+ * @param installationPath Path to installation root
51
+ * @param installationVersion is the full version e.g. 17.3.32929.385
52
+ */
53
+ constructor(version, installationPath, installationVersion) {
54
+ this.version = version;
55
+ this.installationPath = installationPath;
56
+ this.installationVersion = installationVersion;
57
+ }
58
+ /**
59
+ * @returns directory where x64 msbuild can be found
60
+ */
61
+ msbuildPath() {
62
+ return path_1.default.join(this.installationPath, 'MSBuild/Current/Bin/amd64');
63
+ }
64
+ cleanProject(slnFile) {
65
+ const cmd = `"${path_1.default.join(this.msbuildPath(), 'msbuild.exe')}" "${slnFile}" /t:Clean`;
66
+ const results = child_process_1.default.execSync(cmd).toString().split(os_1.EOL);
67
+ results.forEach(result => console.log(chalk_1.default.white(result)));
68
+ }
69
+ async restorePackageConfigs(slnFile, buildArch, buildType) {
70
+ const text = 'Restoring NuGet packages ';
71
+ const spinner = (0, commandWithProgress_1.newSpinner)(text);
72
+ await (0, commandWithProgress_1.commandWithProgress)(spinner, text, path_1.default.join(this.msbuildPath(), 'msbuild.exe'), [
73
+ slnFile,
74
+ '/t:Restore',
75
+ '/p:RestoreProjectStyle=PackagesConfig',
76
+ '/p:RestorePackagesConfig=true',
77
+ `/p:Platform=${buildArch}`,
78
+ `/p:Configuration=${buildType}`,
79
+ ], true, 'MSBuildError');
80
+ }
81
+ async buildProject(slnFile, buildType, buildArch, msBuildProps, verbose, target, buildLogDirectory, singleproc) {
82
+ (0, commandWithProgress_1.newSuccess)(`Found Solution: ${slnFile}`);
83
+ (0, commandWithProgress_1.newInfo)(`Build configuration: ${buildType}`);
84
+ (0, commandWithProgress_1.newInfo)(`Build platform: ${buildArch}`);
85
+ const verbosityOption = verbose ? 'normal' : 'minimal';
86
+ const logPrefix = path_1.default.join(buildLogDirectory || os_2.default.tmpdir(), `msbuild_${process.pid}_${target}`);
87
+ const errorLog = logPrefix + '.err';
88
+ const warnLog = logPrefix + '.wrn';
89
+ const localBinLog = target === 'build' ? '' : ':deploy.binlog';
90
+ const binlog = buildLogDirectory ? `:${logPrefix}.binlog` : localBinLog;
91
+ const args = [
92
+ `/clp:NoSummary;NoItemAndPropertyList;Verbosity=${verbosityOption}`,
93
+ '/nologo',
94
+ `/p:Configuration=${buildType}`,
95
+ `/p:Platform=${buildArch}`,
96
+ '/p:AppxBundle=Never',
97
+ `/bl${binlog}`,
98
+ `/flp1:errorsonly;logfile=${errorLog}`,
99
+ `/flp2:warningsonly;logfile=${warnLog}`,
100
+ ];
101
+ // Building projects in parallel increases compiler memory usage and
102
+ // doesn't lead to dramatic performance gains (See #4739). Only enable
103
+ // parallel builds on machines with >16GB of memory to avoid OOM errors
104
+ const highMemory = (0, os_1.totalmem)() > 16 * 1024 * 1024 * 1024;
105
+ const enableParallelBuilds = singleproc === false || highMemory;
106
+ if (enableParallelBuilds) {
107
+ args.push('/maxCpuCount');
108
+ }
109
+ if (target === 'build') {
110
+ args.push('/restore', '/p:RestorePackagesConfig=true');
111
+ }
112
+ else {
113
+ args.push(`/t:Deploy`);
114
+ }
115
+ Object.keys(msBuildProps).forEach(key => {
116
+ args.push(`/p:${key}=${msBuildProps[key]}`);
117
+ });
118
+ try {
119
+ checkRequirements.isWinSdkPresent('10.0');
120
+ }
121
+ catch (e) {
122
+ (0, commandWithProgress_1.newError)(e.message);
123
+ throw e;
124
+ }
125
+ if (verbose) {
126
+ console.log(`Running MSBuild with args ${args.join(' ')}`);
127
+ }
128
+ const progressName = target === 'deploy' ? 'Deploying Solution' : 'Building Solution';
129
+ const spinner = (0, commandWithProgress_1.newSpinner)(progressName);
130
+ try {
131
+ await (0, commandWithProgress_1.commandWithProgress)(spinner, progressName, path_1.default.join(this.msbuildPath(), 'msbuild.exe'), [slnFile].concat(args), verbose, 'MSBuildError');
132
+ }
133
+ catch (e) {
134
+ let error = e;
135
+ if (e instanceof telemetry_1.CodedError) {
136
+ const origCodedError = e;
137
+ if (origCodedError.type === 'MSBuildError') {
138
+ // Try to parse msbuild errors from errorLog
139
+ const errorLogContents = (await fs_1.default.readFile(errorLog))
140
+ .toString()
141
+ .split(os_1.EOL)
142
+ .filter(s => s)
143
+ .map(s => s.trim());
144
+ if (errorLogContents.length > 0) {
145
+ const firstMessage = errorLogContents[0];
146
+ error = new telemetry_1.CodedError('MSBuildError', firstMessage, origCodedError.data);
147
+ // Hide error messages in a field that won't automatically get reported
148
+ // with telemetry but is still available to be parsed and sanitized
149
+ error.msBuildErrorMessages = errorLogContents;
150
+ }
151
+ }
152
+ }
153
+ throw error;
154
+ }
155
+ // If we have no errors, delete the error log when we're done
156
+ if ((await fs_1.default.stat(errorLog)).size === 0) {
157
+ await fs_1.default.unlink(errorLog);
158
+ }
159
+ }
160
+ static findAvailableVersion(buildArch, verbose, prerelease) {
161
+ // https://aka.ms/vs/workloads
162
+ const requires = [
163
+ 'Microsoft.Component.MSBuild',
164
+ getVCToolsByArch(buildArch),
165
+ ];
166
+ const minVersion = process.env.VisualStudioVersion || '17.0';
167
+ const vsInstallation = (0, vsInstalls_1.findLatestVsInstall)({
168
+ requires,
169
+ minVersion,
170
+ verbose,
171
+ prerelease,
172
+ });
173
+ if (!vsInstallation) {
174
+ if (process.env.VisualStudioVersion != null) {
175
+ throw new telemetry_1.CodedError('NoMSBuild', `MSBuild tools not found for version ${process.env.VisualStudioVersion} (from environment). Make sure all required components have been installed`, { VisualStudioVersionFromEnv: process.env.VisualStudioVersion });
176
+ }
177
+ else {
178
+ throw new telemetry_1.CodedError('NoMSBuild', `Could not find MSBuild with VCTools for Visual Studio ${minVersion} or later. Make sure all required components have been installed`, { minVersion: minVersion });
179
+ }
180
+ }
181
+ const toolsPath = path_1.default.join(vsInstallation.installationPath, 'MSBuild/Current/Bin/amd64');
182
+ if (fs_1.default.existsSync(toolsPath)) {
183
+ if (verbose) {
184
+ (0, commandWithProgress_1.newSuccess)(`Found compatible MSBuild at ${toolsPath} (${vsInstallation.installationVersion})`);
185
+ }
186
+ return new MSBuildTools(minVersion, vsInstallation.installationPath, vsInstallation.installationVersion);
187
+ }
188
+ else {
189
+ throw new telemetry_1.CodedError('NoMSBuild', `MSBuild path '${toolsPath} does not exist'`);
190
+ }
191
+ }
192
+ static getAllAvailableUAPVersions() {
193
+ const results = [];
194
+ const programFilesFolder = process.env['ProgramFiles(x86)'] || process.env.ProgramFiles;
195
+ // No Program Files folder found, so we won't be able to find UAP SDK
196
+ if (!programFilesFolder) {
197
+ return results;
198
+ }
199
+ let uapFolderPath = path_1.default.join(programFilesFolder, 'Windows Kits', '10', 'Platforms', 'UAP');
200
+ if (!shelljs_1.default.test('-e', uapFolderPath)) {
201
+ // Check other installation folder from reg
202
+ const sdkFolder = getSDK10InstallationFolder();
203
+ if (sdkFolder) {
204
+ uapFolderPath = path_1.default.join(sdkFolder, 'Platforms', 'UAP');
205
+ }
206
+ }
207
+ // No UAP SDK exists on this machine
208
+ if (!shelljs_1.default.test('-e', uapFolderPath)) {
209
+ return results;
210
+ }
211
+ shelljs_1.default
212
+ .ls(uapFolderPath)
213
+ .filter(uapDir => shelljs_1.default.test('-d', path_1.default.join(uapFolderPath, uapDir)))
214
+ .map(version_1.default.tryParse)
215
+ .forEach(version => version && results.push(version));
216
+ return results;
217
+ }
218
+ evaluateMSBuildProperties(solutionFile, projectFile, propertyNames, extraMsBuildProps) {
219
+ const spinner = (0, commandWithProgress_1.newSpinner)('Running Eval-MsBuildProperties.ps1');
220
+ try {
221
+ const msbuildEvalScriptPath = path_1.default.resolve(__dirname, '..', '..', 'src', 'powershell', 'Eval-MsBuildProperties.ps1');
222
+ let command = `${commandWithProgress_1.powershell} -ExecutionPolicy Unrestricted -NoProfile "${msbuildEvalScriptPath}" -SolutionFile '${solutionFile}' -ProjectFile '${projectFile}' -MSBuildPath '${this.msbuildPath()}'`;
223
+ if (propertyNames && propertyNames.length > 0) {
224
+ command += ` -PropertyNames '${propertyNames.join(',')}'`;
225
+ }
226
+ if (extraMsBuildProps) {
227
+ command += " -ExtraMSBuildProps '";
228
+ for (const extraProp in extraMsBuildProps) {
229
+ if (!(extraProp in Object.prototype)) {
230
+ command += `,${extraProp}=${extraMsBuildProps[extraProp]}`;
231
+ }
232
+ }
233
+ command += "'";
234
+ }
235
+ const commandOutput = (0, child_process_2.execSync)(command).toString();
236
+ spinner.succeed();
237
+ const properties = JSON.parse(commandOutput);
238
+ spinner.succeed();
239
+ return properties;
240
+ }
241
+ catch (e) {
242
+ spinner.fail('Running Eval-MsBuildProperties.ps1 failed: ' + e.message);
243
+ throw e;
244
+ }
245
+ }
246
+ }
247
+ exports.default = MSBuildTools;
248
+ function getVCToolsByArch(buildArch) {
249
+ switch (buildArch) {
250
+ case 'x86':
251
+ case 'x64':
252
+ return 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64';
253
+ case 'ARM64':
254
+ return 'Microsoft.VisualStudio.Component.VC.Tools.ARM64';
255
+ }
256
+ }
257
+ function getSDK10InstallationFolder() {
258
+ const folder = '';
259
+ const execString = 'reg query "HKLM\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v10.0" /s /v InstallationFolder /reg:32';
260
+ let output;
261
+ try {
262
+ output = (0, child_process_2.execSync)(execString).toString();
263
+ }
264
+ catch (e) {
265
+ return folder;
266
+ }
267
+ const re = /\\Microsoft SDKs\\Windows\\v10.0\s*InstallationFolder\s+REG_SZ\s+(.*)/gim;
268
+ const match = re.exec(output);
269
+ if (match) {
270
+ return match[1];
271
+ }
272
+ return folder;
273
+ }
274
274
  //# sourceMappingURL=msbuildtools.js.map