@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,322 +1,322 @@
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
- exports.runWindowsCommand = void 0;
35
- const fs_1 = __importDefault(require("@react-native-windows/fs"));
36
- const path_1 = __importDefault(require("path"));
37
- const telemetry_1 = require("@react-native-windows/telemetry");
38
- const build = __importStar(require("../../utils/build"));
39
- const chalk_1 = __importDefault(require("chalk"));
40
- const deploy = __importStar(require("../../utils/deploy"));
41
- const commandWithProgress_1 = require("../../utils/commandWithProgress");
42
- const telemetryHelpers_1 = require("../../utils/telemetryHelpers");
43
- const pathHelpers = __importStar(require("../../utils/pathHelpers"));
44
- const info = __importStar(require("../../utils/info"));
45
- const msbuildtools_1 = __importDefault(require("../../utils/msbuildtools"));
46
- const runWindowsOptions_1 = require("./runWindowsOptions");
47
- const autolinkWindows_1 = require("../autolinkWindows/autolinkWindows");
48
- /**
49
- * Sanitizes the given option for telemetry.
50
- * @param key The key of the option.
51
- * @param value The unsanitized value of the option.
52
- * @returns The sanitized value of the option.
53
- */
54
- // eslint-disable-next-line complexity
55
- function optionSanitizer(key, value) {
56
- // Do not add a default case here.
57
- // Strings risking PII should just return true if present, false otherwise.
58
- // All others should return the value (or false if undefined).
59
- switch (key) {
60
- case 'root':
61
- case 'target':
62
- case 'sln':
63
- case 'proj':
64
- case 'buildLogDirectory':
65
- return value === undefined ? false : true; // Strip PII
66
- case 'msbuildprops':
67
- return value === undefined ? 0 : value.split(',').length; // Convert to count
68
- case 'release':
69
- case 'arch':
70
- case 'singleproc':
71
- case 'emulator':
72
- case 'device':
73
- case 'remoteDebugging':
74
- case 'logging':
75
- case 'packager':
76
- case 'bundle':
77
- case 'launch':
78
- case 'autolink':
79
- case 'build':
80
- case 'deploy':
81
- case 'deployFromLayout':
82
- case 'info':
83
- case 'directDebugging':
84
- case 'telemetry':
85
- return value === undefined ? false : value; // Return value
86
- }
87
- }
88
- /**
89
- * Get the extra props to add to the `run-windows` telemetry event.
90
- * @returns The extra props.
91
- */
92
- async function getExtraProps() {
93
- const extraProps = {
94
- phase: runWindowsPhase,
95
- hasRunRnwDependencies,
96
- msBuildProps: evaluateMSBuildPropsCallback
97
- ? evaluateMSBuildPropsCallback()
98
- : {},
99
- };
100
- return extraProps;
101
- }
102
- let runWindowsPhase = 'None';
103
- let hasRunRnwDependencies = false;
104
- let evaluateMSBuildPropsCallback;
105
- /**
106
- * The function run when calling `react-native run-windows`.
107
- * @param args Unprocessed args passed from react-native CLI.
108
- * @param config Config passed from react-native CLI.
109
- * @param options Options passed from react-native CLI.
110
- */
111
- async function runWindows(args, config, options) {
112
- await (0, telemetryHelpers_1.startTelemetrySession)('run-windows', config, options, (0, telemetryHelpers_1.getDefaultOptions)(config, runWindowsOptions_1.runWindowsOptions), optionSanitizer);
113
- // https://github.com/yarnpkg/yarn/issues/8334 - Yarn on Windows breaks apps that read from the environment variables
114
- // Yarn will run node via CreateProcess and pass npm_config_* variables in lowercase without unifying their value
115
- // with their possibly existing uppercase counterparts. This breaks programs that read from the environment block
116
- // and write to a case-insensitive dictionary since they expect to encounter each variable only once.
117
- // The values of the lowercase variables are the one npm actually wants to use, plus they are seeded from the
118
- // uppercase variable values one if there are no overrides.
119
- delete process.env.NPM_CONFIG_CACHE;
120
- delete process.env.NPM_CONFIG_PREFIX;
121
- if (process.env.LocalAppData) {
122
- hasRunRnwDependencies = fs_1.default.existsSync(path_1.default.join(process.env.LocalAppData, 'rnw-dependencies.txt')); // CODESYNC \vnext\scripts\rnw-dependencies.ps1
123
- }
124
- let runWindowsError;
125
- if (options.info) {
126
- runWindowsPhase = 'Info';
127
- try {
128
- const output = await info.getEnvironmentInfo();
129
- console.log(output.trimEnd());
130
- console.log(' Installed UWP SDKs:');
131
- const sdks = msbuildtools_1.default.getAllAvailableUAPVersions();
132
- sdks.forEach(version => console.log(' ' + version));
133
- }
134
- catch (ex) {
135
- runWindowsError =
136
- ex instanceof Error ? ex : new Error(String(ex));
137
- telemetry_1.Telemetry.trackException(runWindowsError);
138
- (0, commandWithProgress_1.newError)('Unable to print environment info.\n' + runWindowsError.toString());
139
- }
140
- await (0, telemetryHelpers_1.endTelemetrySession)(runWindowsError, getExtraProps);
141
- (0, commandWithProgress_1.setExitProcessWithError)(options.logging, runWindowsError);
142
- return;
143
- }
144
- try {
145
- await runWindowsInternal(args, config, options);
146
- }
147
- catch (ex) {
148
- runWindowsError =
149
- ex instanceof Error ? ex : new Error(String(ex));
150
- telemetry_1.Telemetry.trackException(runWindowsError);
151
- if (!hasRunRnwDependencies) {
152
- const rnwDependenciesPath = path_1.default.join(pathHelpers.resolveRnwRoot([process.cwd(), __dirname]), 'scripts/rnw-dependencies.ps1');
153
- (0, commandWithProgress_1.newError)(`It is possible your installation is missing required software dependencies. Dependencies can be automatically installed by running ${rnwDependenciesPath} from an elevated PowerShell prompt.\nFor more information, go to http://aka.ms/rnw-deps`);
154
- }
155
- }
156
- await (0, telemetryHelpers_1.endTelemetrySession)(runWindowsError, getExtraProps);
157
- (0, commandWithProgress_1.setExitProcessWithError)(options.logging, runWindowsError);
158
- }
159
- /**
160
- * Performs build deploy and launch of RNW apps.
161
- * @param args Unprocessed args passed from react-native CLI.
162
- * @param config Config passed from react-native CLI.
163
- * @param options Options passed from react-native CLI.
164
- */
165
- async function runWindowsInternal(args, config, options) {
166
- const verbose = options.logging === true;
167
- if (verbose) {
168
- (0, commandWithProgress_1.newInfo)('Verbose: ON');
169
- }
170
- // Get the solution file
171
- let slnFile;
172
- runWindowsPhase = 'FindSolution';
173
- try {
174
- slnFile = build.getAppSolutionFile(options, config);
175
- }
176
- catch (e) {
177
- (0, commandWithProgress_1.newError)(`Couldn't get app solution information. ${e.message}`);
178
- throw e;
179
- }
180
- let buildTools;
181
- runWindowsPhase = 'FindBuildTools';
182
- try {
183
- buildTools = msbuildtools_1.default.findAvailableVersion(options.arch, verbose);
184
- }
185
- catch (error) {
186
- (0, commandWithProgress_1.newWarn)('No public VS release found');
187
- // Try prerelease
188
- try {
189
- (0, commandWithProgress_1.newInfo)('Trying pre-release VS');
190
- buildTools = msbuildtools_1.default.findAvailableVersion(options.arch, verbose, true);
191
- }
192
- catch (e) {
193
- (0, commandWithProgress_1.newError)(e.message);
194
- throw error;
195
- }
196
- }
197
- // Set up the callback to capture MSBuild properties after the command completes
198
- evaluateMSBuildPropsCallback = () => {
199
- const projectFile = build.getAppProjectFile(options, config);
200
- if (projectFile) {
201
- if (verbose) {
202
- (0, commandWithProgress_1.newInfo)('Gathering MSBuild data for telemetry.');
203
- }
204
- const msBuildPropertiesJsonPath = path_1.default.resolve(path_1.default.dirname(projectFile), 'Generated Files', 'msbuildproperties.g.json');
205
- if (fs_1.default.existsSync(msBuildPropertiesJsonPath)) {
206
- if (verbose) {
207
- (0, commandWithProgress_1.newInfo)('Loading properties from msbuildproperties.g.json');
208
- }
209
- return fs_1.default.readJsonFileSync(msBuildPropertiesJsonPath);
210
- }
211
- if (verbose) {
212
- (0, commandWithProgress_1.newInfo)('Unable to find msbuildproperties.g.json');
213
- }
214
- }
215
- return {};
216
- };
217
- // Restore packages.config files for dependencies that don't support PackageReference.
218
- runWindowsPhase = 'RestorePackagesConfig';
219
- const buildType = deploy.getBuildConfiguration(options);
220
- try {
221
- await buildTools.restorePackageConfigs(slnFile, options.arch, buildType);
222
- }
223
- catch (e) {
224
- (0, commandWithProgress_1.newError)(`Couldn't restore found packages.config instances. ${e.message}`);
225
- throw e;
226
- }
227
- if (options.autolink) {
228
- runWindowsPhase = 'Autolink';
229
- try {
230
- const autolinkArgs = [];
231
- const autolinkConfig = config;
232
- const autolinkOptions = {
233
- logging: options.logging,
234
- check: false,
235
- proj: options.proj,
236
- sln: options.sln,
237
- telemetry: options.telemetry,
238
- };
239
- await (0, autolinkWindows_1.autolinkWindowsInternal)(autolinkArgs, autolinkConfig, autolinkOptions);
240
- }
241
- catch (e) {
242
- (0, commandWithProgress_1.newError)(`Autolinking failed. ${e.message}`);
243
- throw e;
244
- }
245
- }
246
- else {
247
- (0, commandWithProgress_1.newInfo)('Autolink step is skipped');
248
- }
249
- if (options.build) {
250
- runWindowsPhase = 'Build';
251
- if (!slnFile) {
252
- (0, commandWithProgress_1.newError)('Visual Studio Solution file not found. Maybe run "npx react-native-windows-init" first?');
253
- throw new telemetry_1.CodedError('NoSolution', 'Cannot find solution file');
254
- }
255
- // Get build/deploy options
256
- const msBuildProps = build.parseMsBuildProps(options);
257
- // Disable the autolink check since we just ran it
258
- msBuildProps.RunAutolinkCheck = 'false';
259
- try {
260
- await build.buildSolution(buildTools, slnFile, buildType, options.arch, msBuildProps, verbose, 'build', options.buildLogDirectory, options.singleproc);
261
- }
262
- catch (e) {
263
- (0, commandWithProgress_1.newError)(`Build failed with message ${e.message}. Check your build configuration.`);
264
- if (e.logfile) {
265
- console.log('See', chalk_1.default.bold(e.logfile));
266
- }
267
- throw e;
268
- }
269
- }
270
- else {
271
- (0, commandWithProgress_1.newInfo)('Build step is skipped');
272
- }
273
- if (shouldLaunchPackager(options)) {
274
- await deploy.startServerInNewWindow(options, verbose);
275
- }
276
- if (options.deploy) {
277
- runWindowsPhase = 'Deploy';
278
- if (!slnFile) {
279
- (0, commandWithProgress_1.newError)('Visual Studio Solution file not found. Maybe run "npx react-native-windows-init" first?');
280
- throw new telemetry_1.CodedError('NoSolution', 'Cannot find solution file');
281
- }
282
- try {
283
- if (options.device || options.emulator || options.target) {
284
- await deploy.deployToDevice(options, verbose, config);
285
- }
286
- else {
287
- await deploy.deployToDesktop(options, verbose, config, buildTools);
288
- }
289
- }
290
- catch (e) {
291
- (0, commandWithProgress_1.newError)(`Failed to deploy${e ? `: ${e.message}` : ''}`);
292
- throw e;
293
- }
294
- }
295
- else {
296
- (0, commandWithProgress_1.newInfo)('Deploy step is skipped');
297
- }
298
- }
299
- function shouldLaunchPackager(options) {
300
- return (options.packager === true &&
301
- options.launch === true &&
302
- options.release !== true);
303
- }
304
- /*
305
- // Example of running the Windows Command
306
- runWindows({
307
- root: 'C:\\github\\hack\\myapp',
308
- debug: true,
309
- arch: 'x86',
310
- nugetPath: 'C:\\github\\react\\react-native-windows\\local-cli\\runWindows\\.nuget\\nuget.exe'
311
- });
312
- */
313
- /**
314
- * Starts the app on a connected Windows emulator or mobile device.
315
- */
316
- exports.runWindowsCommand = {
317
- name: 'run-windows',
318
- description: 'Builds your app and starts it on a connected Windows desktop, emulator or device',
319
- func: runWindows,
320
- options: runWindowsOptions_1.runWindowsOptions,
321
- };
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
+ exports.runWindowsCommand = void 0;
35
+ const fs_1 = __importDefault(require("@react-native-windows/fs"));
36
+ const path_1 = __importDefault(require("path"));
37
+ const telemetry_1 = require("@react-native-windows/telemetry");
38
+ const build = __importStar(require("../../utils/build"));
39
+ const chalk_1 = __importDefault(require("chalk"));
40
+ const deploy = __importStar(require("../../utils/deploy"));
41
+ const commandWithProgress_1 = require("../../utils/commandWithProgress");
42
+ const telemetryHelpers_1 = require("../../utils/telemetryHelpers");
43
+ const pathHelpers = __importStar(require("../../utils/pathHelpers"));
44
+ const info = __importStar(require("../../utils/info"));
45
+ const msbuildtools_1 = __importDefault(require("../../utils/msbuildtools"));
46
+ const runWindowsOptions_1 = require("./runWindowsOptions");
47
+ const autolinkWindows_1 = require("../autolinkWindows/autolinkWindows");
48
+ /**
49
+ * Sanitizes the given option for telemetry.
50
+ * @param key The key of the option.
51
+ * @param value The unsanitized value of the option.
52
+ * @returns The sanitized value of the option.
53
+ */
54
+ // eslint-disable-next-line complexity
55
+ function optionSanitizer(key, value) {
56
+ // Do not add a default case here.
57
+ // Strings risking PII should just return true if present, false otherwise.
58
+ // All others should return the value (or false if undefined).
59
+ switch (key) {
60
+ case 'root':
61
+ case 'target':
62
+ case 'sln':
63
+ case 'proj':
64
+ case 'buildLogDirectory':
65
+ return value === undefined ? false : true; // Strip PII
66
+ case 'msbuildprops':
67
+ return value === undefined ? 0 : value.split(',').length; // Convert to count
68
+ case 'release':
69
+ case 'arch':
70
+ case 'singleproc':
71
+ case 'emulator':
72
+ case 'device':
73
+ case 'remoteDebugging':
74
+ case 'logging':
75
+ case 'packager':
76
+ case 'bundle':
77
+ case 'launch':
78
+ case 'autolink':
79
+ case 'build':
80
+ case 'deploy':
81
+ case 'deployFromLayout':
82
+ case 'info':
83
+ case 'directDebugging':
84
+ case 'telemetry':
85
+ return value === undefined ? false : value; // Return value
86
+ }
87
+ }
88
+ /**
89
+ * Get the extra props to add to the `run-windows` telemetry event.
90
+ * @returns The extra props.
91
+ */
92
+ async function getExtraProps() {
93
+ const extraProps = {
94
+ phase: runWindowsPhase,
95
+ hasRunRnwDependencies,
96
+ msBuildProps: evaluateMSBuildPropsCallback
97
+ ? evaluateMSBuildPropsCallback()
98
+ : {},
99
+ };
100
+ return extraProps;
101
+ }
102
+ let runWindowsPhase = 'None';
103
+ let hasRunRnwDependencies = false;
104
+ let evaluateMSBuildPropsCallback;
105
+ /**
106
+ * The function run when calling `react-native run-windows`.
107
+ * @param args Unprocessed args passed from react-native CLI.
108
+ * @param config Config passed from react-native CLI.
109
+ * @param options Options passed from react-native CLI.
110
+ */
111
+ async function runWindows(args, config, options) {
112
+ await (0, telemetryHelpers_1.startTelemetrySession)('run-windows', config, options, (0, telemetryHelpers_1.getDefaultOptions)(config, runWindowsOptions_1.runWindowsOptions), optionSanitizer);
113
+ // https://github.com/yarnpkg/yarn/issues/8334 - Yarn on Windows breaks apps that read from the environment variables
114
+ // Yarn will run node via CreateProcess and pass npm_config_* variables in lowercase without unifying their value
115
+ // with their possibly existing uppercase counterparts. This breaks programs that read from the environment block
116
+ // and write to a case-insensitive dictionary since they expect to encounter each variable only once.
117
+ // The values of the lowercase variables are the one npm actually wants to use, plus they are seeded from the
118
+ // uppercase variable values one if there are no overrides.
119
+ delete process.env.NPM_CONFIG_CACHE;
120
+ delete process.env.NPM_CONFIG_PREFIX;
121
+ if (process.env.LocalAppData) {
122
+ hasRunRnwDependencies = fs_1.default.existsSync(path_1.default.join(process.env.LocalAppData, 'rnw-dependencies.txt')); // CODESYNC \vnext\scripts\rnw-dependencies.ps1
123
+ }
124
+ let runWindowsError;
125
+ if (options.info) {
126
+ runWindowsPhase = 'Info';
127
+ try {
128
+ const output = await info.getEnvironmentInfo();
129
+ console.log(output.trimEnd());
130
+ console.log(' Installed UWP SDKs:');
131
+ const sdks = msbuildtools_1.default.getAllAvailableUAPVersions();
132
+ sdks.forEach(version => console.log(' ' + version));
133
+ }
134
+ catch (ex) {
135
+ runWindowsError =
136
+ ex instanceof Error ? ex : new Error(String(ex));
137
+ telemetry_1.Telemetry.trackException(runWindowsError);
138
+ (0, commandWithProgress_1.newError)('Unable to print environment info.\n' + runWindowsError.toString());
139
+ }
140
+ await (0, telemetryHelpers_1.endTelemetrySession)(runWindowsError, getExtraProps);
141
+ (0, commandWithProgress_1.setExitProcessWithError)(options.logging, runWindowsError);
142
+ return;
143
+ }
144
+ try {
145
+ await runWindowsInternal(args, config, options);
146
+ }
147
+ catch (ex) {
148
+ runWindowsError =
149
+ ex instanceof Error ? ex : new Error(String(ex));
150
+ telemetry_1.Telemetry.trackException(runWindowsError);
151
+ if (!hasRunRnwDependencies) {
152
+ const rnwDependenciesPath = path_1.default.join(pathHelpers.resolveRnwRoot([process.cwd(), __dirname]), 'scripts/rnw-dependencies.ps1');
153
+ (0, commandWithProgress_1.newError)(`It is possible your installation is missing required software dependencies. Dependencies can be automatically installed by running ${rnwDependenciesPath} from an elevated PowerShell prompt.\nFor more information, go to http://aka.ms/rnw-deps`);
154
+ }
155
+ }
156
+ await (0, telemetryHelpers_1.endTelemetrySession)(runWindowsError, getExtraProps);
157
+ (0, commandWithProgress_1.setExitProcessWithError)(options.logging, runWindowsError);
158
+ }
159
+ /**
160
+ * Performs build deploy and launch of RNW apps.
161
+ * @param args Unprocessed args passed from react-native CLI.
162
+ * @param config Config passed from react-native CLI.
163
+ * @param options Options passed from react-native CLI.
164
+ */
165
+ async function runWindowsInternal(args, config, options) {
166
+ const verbose = options.logging === true;
167
+ if (verbose) {
168
+ (0, commandWithProgress_1.newInfo)('Verbose: ON');
169
+ }
170
+ // Get the solution file
171
+ let slnFile;
172
+ runWindowsPhase = 'FindSolution';
173
+ try {
174
+ slnFile = build.getAppSolutionFile(options, config);
175
+ }
176
+ catch (e) {
177
+ (0, commandWithProgress_1.newError)(`Couldn't get app solution information. ${e.message}`);
178
+ throw e;
179
+ }
180
+ let buildTools;
181
+ runWindowsPhase = 'FindBuildTools';
182
+ try {
183
+ buildTools = msbuildtools_1.default.findAvailableVersion(options.arch, verbose);
184
+ }
185
+ catch (error) {
186
+ (0, commandWithProgress_1.newWarn)('No public VS release found');
187
+ // Try prerelease
188
+ try {
189
+ (0, commandWithProgress_1.newInfo)('Trying pre-release VS');
190
+ buildTools = msbuildtools_1.default.findAvailableVersion(options.arch, verbose, true);
191
+ }
192
+ catch (e) {
193
+ (0, commandWithProgress_1.newError)(e.message);
194
+ throw error;
195
+ }
196
+ }
197
+ // Set up the callback to capture MSBuild properties after the command completes
198
+ evaluateMSBuildPropsCallback = () => {
199
+ const projectFile = build.getAppProjectFile(options, config);
200
+ if (projectFile) {
201
+ if (verbose) {
202
+ (0, commandWithProgress_1.newInfo)('Gathering MSBuild data for telemetry.');
203
+ }
204
+ const msBuildPropertiesJsonPath = path_1.default.resolve(path_1.default.dirname(projectFile), 'Generated Files', 'msbuildproperties.g.json');
205
+ if (fs_1.default.existsSync(msBuildPropertiesJsonPath)) {
206
+ if (verbose) {
207
+ (0, commandWithProgress_1.newInfo)('Loading properties from msbuildproperties.g.json');
208
+ }
209
+ return fs_1.default.readJsonFileSync(msBuildPropertiesJsonPath);
210
+ }
211
+ if (verbose) {
212
+ (0, commandWithProgress_1.newInfo)('Unable to find msbuildproperties.g.json');
213
+ }
214
+ }
215
+ return {};
216
+ };
217
+ // Restore packages.config files for dependencies that don't support PackageReference.
218
+ runWindowsPhase = 'RestorePackagesConfig';
219
+ const buildType = deploy.getBuildConfiguration(options);
220
+ try {
221
+ await buildTools.restorePackageConfigs(slnFile, options.arch, buildType);
222
+ }
223
+ catch (e) {
224
+ (0, commandWithProgress_1.newError)(`Couldn't restore found packages.config instances. ${e.message}`);
225
+ throw e;
226
+ }
227
+ if (options.autolink) {
228
+ runWindowsPhase = 'Autolink';
229
+ try {
230
+ const autolinkArgs = [];
231
+ const autolinkConfig = config;
232
+ const autolinkOptions = {
233
+ logging: options.logging,
234
+ check: false,
235
+ proj: options.proj,
236
+ sln: options.sln,
237
+ telemetry: options.telemetry,
238
+ };
239
+ await (0, autolinkWindows_1.autolinkWindowsInternal)(autolinkArgs, autolinkConfig, autolinkOptions);
240
+ }
241
+ catch (e) {
242
+ (0, commandWithProgress_1.newError)(`Autolinking failed. ${e.message}`);
243
+ throw e;
244
+ }
245
+ }
246
+ else {
247
+ (0, commandWithProgress_1.newInfo)('Autolink step is skipped');
248
+ }
249
+ if (options.build) {
250
+ runWindowsPhase = 'Build';
251
+ if (!slnFile) {
252
+ (0, commandWithProgress_1.newError)('Visual Studio Solution file not found. Maybe run "npx react-native-windows-init" first?');
253
+ throw new telemetry_1.CodedError('NoSolution', 'Cannot find solution file');
254
+ }
255
+ // Get build/deploy options
256
+ const msBuildProps = build.parseMsBuildProps(options);
257
+ // Disable the autolink check since we just ran it
258
+ msBuildProps.RunAutolinkCheck = 'false';
259
+ try {
260
+ await build.buildSolution(buildTools, slnFile, buildType, options.arch, msBuildProps, verbose, 'build', options.buildLogDirectory, options.singleproc);
261
+ }
262
+ catch (e) {
263
+ (0, commandWithProgress_1.newError)(`Build failed with message ${e.message}. Check your build configuration.`);
264
+ if (e.logfile) {
265
+ console.log('See', chalk_1.default.bold(e.logfile));
266
+ }
267
+ throw e;
268
+ }
269
+ }
270
+ else {
271
+ (0, commandWithProgress_1.newInfo)('Build step is skipped');
272
+ }
273
+ if (shouldLaunchPackager(options)) {
274
+ await deploy.startServerInNewWindow(options, verbose);
275
+ }
276
+ if (options.deploy) {
277
+ runWindowsPhase = 'Deploy';
278
+ if (!slnFile) {
279
+ (0, commandWithProgress_1.newError)('Visual Studio Solution file not found. Maybe run "npx react-native-windows-init" first?');
280
+ throw new telemetry_1.CodedError('NoSolution', 'Cannot find solution file');
281
+ }
282
+ try {
283
+ if (options.device || options.emulator || options.target) {
284
+ await deploy.deployToDevice(options, verbose, config);
285
+ }
286
+ else {
287
+ await deploy.deployToDesktop(options, verbose, config, buildTools);
288
+ }
289
+ }
290
+ catch (e) {
291
+ (0, commandWithProgress_1.newError)(`Failed to deploy${e ? `: ${e.message}` : ''}`);
292
+ throw e;
293
+ }
294
+ }
295
+ else {
296
+ (0, commandWithProgress_1.newInfo)('Deploy step is skipped');
297
+ }
298
+ }
299
+ function shouldLaunchPackager(options) {
300
+ return (options.packager === true &&
301
+ options.launch === true &&
302
+ options.release !== true);
303
+ }
304
+ /*
305
+ // Example of running the Windows Command
306
+ runWindows({
307
+ root: 'C:\\github\\hack\\myapp',
308
+ debug: true,
309
+ arch: 'x86',
310
+ nugetPath: 'C:\\github\\react\\react-native-windows\\local-cli\\runWindows\\.nuget\\nuget.exe'
311
+ });
312
+ */
313
+ /**
314
+ * Starts the app on a connected Windows emulator or mobile device.
315
+ */
316
+ exports.runWindowsCommand = {
317
+ name: 'run-windows',
318
+ description: 'Builds your app and starts it on a connected Windows desktop, emulator or device',
319
+ func: runWindows,
320
+ options: runWindowsOptions_1.runWindowsOptions,
321
+ };
322
322
  //# sourceMappingURL=runWindows.js.map