@react-native-windows/cli 0.0.0-canary.99 → 0.0.1-0

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 (131) hide show
  1. package/README.md +0 -2
  2. package/lib-commonjs/{runWindows/utils/autolink.d.ts → commands/autolinkWindows/autolinkWindows.d.ts} +87 -86
  3. package/lib-commonjs/{runWindows/utils/autolink.js → commands/autolinkWindows/autolinkWindows.js} +655 -625
  4. package/lib-commonjs/commands/autolinkWindows/autolinkWindows.js.map +1 -0
  5. package/lib-commonjs/commands/autolinkWindows/autolinkWindowsOptions.d.ts +14 -0
  6. package/lib-commonjs/commands/autolinkWindows/autolinkWindowsOptions.js +33 -0
  7. package/lib-commonjs/commands/autolinkWindows/autolinkWindowsOptions.js.map +1 -0
  8. package/lib-commonjs/commands/codegenWindows/codegenWindows.d.ts +27 -0
  9. package/lib-commonjs/commands/codegenWindows/codegenWindows.js +206 -0
  10. package/lib-commonjs/commands/codegenWindows/codegenWindows.js.map +1 -0
  11. package/lib-commonjs/commands/codegenWindows/codegenWindowsOptions.d.ts +12 -0
  12. package/lib-commonjs/commands/codegenWindows/codegenWindowsOptions.js +23 -0
  13. package/lib-commonjs/commands/codegenWindows/codegenWindowsOptions.js.map +1 -0
  14. package/lib-commonjs/{config → commands/config}/configUtils.d.ts +123 -116
  15. package/lib-commonjs/{config → commands/config}/configUtils.js +380 -341
  16. package/lib-commonjs/commands/config/configUtils.js.map +1 -0
  17. package/lib-commonjs/{config → commands/config}/dependencyConfig.d.ts +37 -37
  18. package/lib-commonjs/{config → commands/config}/dependencyConfig.js +227 -221
  19. package/lib-commonjs/commands/config/dependencyConfig.js.map +1 -0
  20. package/lib-commonjs/{config → commands/config}/projectConfig.d.ts +27 -27
  21. package/lib-commonjs/{config → commands/config}/projectConfig.js +180 -176
  22. package/lib-commonjs/commands/config/projectConfig.js.map +1 -0
  23. package/lib-commonjs/commands/healthCheck/healthCheckList.d.ts +6 -0
  24. package/lib-commonjs/commands/healthCheck/healthCheckList.js +21 -0
  25. package/lib-commonjs/commands/healthCheck/healthCheckList.js.map +1 -0
  26. package/lib-commonjs/{healthChecks.d.ts → commands/healthCheck/healthChecks.d.ts} +7 -2
  27. package/lib-commonjs/commands/healthCheck/healthChecks.js +124 -0
  28. package/lib-commonjs/commands/healthCheck/healthChecks.js.map +1 -0
  29. package/lib-commonjs/commands/initWindows/initWindows.d.ts +46 -0
  30. package/lib-commonjs/commands/initWindows/initWindows.js +244 -0
  31. package/lib-commonjs/commands/initWindows/initWindows.js.map +1 -0
  32. package/lib-commonjs/commands/initWindows/initWindowsOptions.d.ts +15 -0
  33. package/lib-commonjs/commands/initWindows/initWindowsOptions.js +38 -0
  34. package/lib-commonjs/commands/initWindows/initWindowsOptions.js.map +1 -0
  35. package/lib-commonjs/{runWindows → commands/runWindows}/runWindows.d.ts +10 -11
  36. package/lib-commonjs/{runWindows → commands/runWindows}/runWindows.js +321 -318
  37. package/lib-commonjs/commands/runWindows/runWindows.js.map +1 -0
  38. package/lib-commonjs/{runWindows → commands/runWindows}/runWindowsOptions.d.ts +56 -56
  39. package/lib-commonjs/{runWindows → commands/runWindows}/runWindowsOptions.js +132 -135
  40. package/lib-commonjs/commands/runWindows/runWindowsOptions.js.map +1 -0
  41. package/lib-commonjs/e2etest/autolink.test.d.ts +6 -6
  42. package/lib-commonjs/e2etest/autolink.test.js +366 -418
  43. package/lib-commonjs/e2etest/autolink.test.js.map +1 -1
  44. package/lib-commonjs/e2etest/dependencyConfig.test.d.ts +6 -6
  45. package/lib-commonjs/e2etest/dependencyConfig.test.js +129 -161
  46. package/lib-commonjs/e2etest/dependencyConfig.test.js.map +1 -1
  47. package/lib-commonjs/e2etest/healthChecks.test.d.ts +6 -0
  48. package/lib-commonjs/e2etest/healthChecks.test.js +31 -0
  49. package/lib-commonjs/e2etest/healthChecks.test.js.map +1 -0
  50. package/lib-commonjs/e2etest/initWindows.test.d.ts +6 -0
  51. package/lib-commonjs/e2etest/initWindows.test.js +43 -0
  52. package/lib-commonjs/e2etest/initWindows.test.js.map +1 -0
  53. package/lib-commonjs/e2etest/projectConfig.test.d.ts +6 -6
  54. package/lib-commonjs/e2etest/projectConfig.test.js +110 -124
  55. package/lib-commonjs/e2etest/projectConfig.test.js.map +1 -1
  56. package/lib-commonjs/e2etest/projectConfig.utils.d.ts +8 -4
  57. package/lib-commonjs/e2etest/projectConfig.utils.js +76 -62
  58. package/lib-commonjs/e2etest/projectConfig.utils.js.map +1 -1
  59. package/lib-commonjs/e2etest/runWindows.test.d.ts +6 -6
  60. package/lib-commonjs/e2etest/runWindows.test.js +60 -39
  61. package/lib-commonjs/e2etest/runWindows.test.js.map +1 -1
  62. package/lib-commonjs/e2etest/typesUpToDate.test.d.ts +6 -0
  63. package/lib-commonjs/e2etest/typesUpToDate.test.js +21 -0
  64. package/lib-commonjs/e2etest/typesUpToDate.test.js.map +1 -0
  65. package/lib-commonjs/generator-common/index.d.ts +39 -39
  66. package/lib-commonjs/generator-common/index.js +242 -242
  67. package/lib-commonjs/generator-common/index.js.map +1 -1
  68. package/lib-commonjs/generator-windows/index.d.ts +10 -10
  69. package/lib-commonjs/generator-windows/index.js +316 -369
  70. package/lib-commonjs/generator-windows/index.js.map +1 -1
  71. package/lib-commonjs/index.d.ts +50 -50
  72. package/lib-commonjs/index.js +77 -106
  73. package/lib-commonjs/index.js.map +1 -1
  74. package/lib-commonjs/{runWindows/utils → utils}/build.d.ts +12 -12
  75. package/lib-commonjs/{runWindows/utils → utils}/build.js +84 -84
  76. package/lib-commonjs/utils/build.js.map +1 -0
  77. package/lib-commonjs/{runWindows/utils → utils}/checkRequirements.d.ts +6 -6
  78. package/lib-commonjs/{runWindows/utils → utils}/checkRequirements.js +69 -69
  79. package/lib-commonjs/utils/checkRequirements.js.map +1 -0
  80. package/lib-commonjs/{runWindows/utils → utils}/commandWithProgress.d.ts +21 -15
  81. package/lib-commonjs/{runWindows/utils → utils}/commandWithProgress.js +149 -127
  82. package/lib-commonjs/utils/commandWithProgress.js.map +1 -0
  83. package/lib-commonjs/{runWindows/utils → utils}/deploy.d.ts +12 -12
  84. package/lib-commonjs/{runWindows/utils → utils}/deploy.js +353 -328
  85. package/lib-commonjs/utils/deploy.js.map +1 -0
  86. package/lib-commonjs/{runWindows/utils → utils}/info.d.ts +6 -6
  87. package/lib-commonjs/{runWindows/utils → utils}/info.js +28 -28
  88. package/lib-commonjs/utils/info.js.map +1 -0
  89. package/lib-commonjs/{runWindows/utils → utils}/msbuildtools.d.ts +28 -26
  90. package/lib-commonjs/{runWindows/utils → utils}/msbuildtools.js +273 -219
  91. package/lib-commonjs/utils/msbuildtools.js.map +1 -0
  92. package/lib-commonjs/utils/pathHelpers.d.ts +9 -0
  93. package/lib-commonjs/utils/pathHelpers.js +37 -0
  94. package/lib-commonjs/utils/pathHelpers.js.map +1 -0
  95. package/lib-commonjs/utils/telemetryHelpers.d.ts +29 -0
  96. package/lib-commonjs/utils/telemetryHelpers.js +121 -0
  97. package/lib-commonjs/utils/telemetryHelpers.js.map +1 -0
  98. package/lib-commonjs/{runWindows/utils → utils}/version.d.ts +19 -19
  99. package/lib-commonjs/{runWindows/utils → utils}/version.js +109 -109
  100. package/lib-commonjs/utils/version.js.map +1 -0
  101. package/lib-commonjs/{runWindows/utils → utils}/vsInstalls.d.ts +34 -34
  102. package/lib-commonjs/{runWindows/utils → utils}/vsInstalls.js +99 -73
  103. package/lib-commonjs/utils/vsInstalls.js.map +1 -0
  104. package/lib-commonjs/{runWindows/utils → utils}/vstools.d.ts +16 -16
  105. package/lib-commonjs/{runWindows/utils → utils}/vstools.js +189 -162
  106. package/lib-commonjs/utils/vstools.js.map +1 -0
  107. package/lib-commonjs/{runWindows/utils → utils}/winappdeploytool.d.ts +24 -24
  108. package/lib-commonjs/{runWindows/utils → utils}/winappdeploytool.js +108 -108
  109. package/lib-commonjs/utils/winappdeploytool.js.map +1 -0
  110. package/package.json +27 -20
  111. package/src/powershell/Eval-MsBuildProperties.ps1 +156 -0
  112. package/lib-commonjs/config/configUtils.js.map +0 -1
  113. package/lib-commonjs/config/dependencyConfig.js.map +0 -1
  114. package/lib-commonjs/config/projectConfig.js.map +0 -1
  115. package/lib-commonjs/healthChecks.js +0 -88
  116. package/lib-commonjs/healthChecks.js.map +0 -1
  117. package/lib-commonjs/runWindows/runWindows.js.map +0 -1
  118. package/lib-commonjs/runWindows/runWindowsOptions.js.map +0 -1
  119. package/lib-commonjs/runWindows/utils/autolink.js.map +0 -1
  120. package/lib-commonjs/runWindows/utils/build.js.map +0 -1
  121. package/lib-commonjs/runWindows/utils/checkRequirements.js.map +0 -1
  122. package/lib-commonjs/runWindows/utils/commandWithProgress.js.map +0 -1
  123. package/lib-commonjs/runWindows/utils/deploy.js.map +0 -1
  124. package/lib-commonjs/runWindows/utils/info.js.map +0 -1
  125. package/lib-commonjs/runWindows/utils/msbuildtools.js.map +0 -1
  126. package/lib-commonjs/runWindows/utils/version.js.map +0 -1
  127. package/lib-commonjs/runWindows/utils/vsInstalls.js.map +0 -1
  128. package/lib-commonjs/runWindows/utils/vstools.js.map +0 -1
  129. package/lib-commonjs/runWindows/utils/winappdeploytool.js.map +0 -1
  130. /package/{powershell → src/powershell}/Add-AppDevPackage.ps1 +0 -0
  131. /package/{powershell → src/powershell}/WindowsStoreAppUtils.ps1 +0 -0
@@ -1,319 +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
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || function (mod) {
20
- if (mod && mod.__esModule) return mod;
21
- var result = {};
22
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
- __setModuleDefault(result, mod);
24
- return result;
25
- };
26
- var __importDefault = (this && this.__importDefault) || function (mod) {
27
- return (mod && mod.__esModule) ? mod : { "default": mod };
28
- };
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.runWindowsCommand = exports.getAnonymizedProjectName = void 0;
31
- const crypto_1 = __importDefault(require("crypto"));
32
- const fs_1 = __importDefault(require("fs"));
33
- const path_1 = __importDefault(require("path"));
34
- const telemetry_1 = require("@react-native-windows/telemetry");
35
- const build = __importStar(require("./utils/build"));
36
- const chalk_1 = __importDefault(require("chalk"));
37
- const deploy = __importStar(require("./utils/deploy"));
38
- const commandWithProgress_1 = require("./utils/commandWithProgress");
39
- const info = __importStar(require("./utils/info"));
40
- const msbuildtools_1 = __importDefault(require("./utils/msbuildtools"));
41
- const runWindowsOptions_1 = require("./runWindowsOptions");
42
- const autolink_1 = require("./utils/autolink");
43
- const os_1 = require("os");
44
- function setExitProcessWithError(error, loggingWasEnabled) {
45
- if (loggingWasEnabled !== true) {
46
- console.log(`Re-run the command with ${chalk_1.default.bold('--logging')} for more information`);
47
- if (telemetry_1.Telemetry.client) {
48
- console.log(`Your session id was ${telemetry_1.Telemetry.client.commonProperties.sessionId}`);
49
- }
50
- }
51
- if (error instanceof telemetry_1.CodedError) {
52
- process.exitCode = telemetry_1.CodedErrors[error.name];
53
- }
54
- else {
55
- process.exitCode = 1;
56
- }
57
- }
58
- function getPkgVersion(pkgName) {
59
- try {
60
- const pkgJsonPath = require.resolve(`${pkgName}/package.json`, {
61
- paths: [process.cwd(), __dirname],
62
- });
63
- const pkgJson = JSON.parse(fs_1.default.readFileSync(pkgJsonPath).toString());
64
- if (pkgJson.name === pkgName && pkgJson.version !== undefined) {
65
- return pkgJson.version;
66
- }
67
- }
68
- catch (_a) { }
69
- (0, commandWithProgress_1.newWarn)(`Could not determine ${pkgName} version`);
70
- return '';
71
- }
72
- let runWindowsPhase = 'None';
73
- /**
74
- * Performs build deploy and launch of RNW apps.
75
- * @param args Unprocessed args passed from react-native CLI.
76
- * @param config Config passed from react-native CLI.
77
- * @param options Options passed from react-native CLI.
78
- */
79
- async function runWindows(args, config, options) {
80
- var _a, _b;
81
- if (!options.telemetry) {
82
- if (options.logging) {
83
- console.log('Disabling telemetry');
84
- }
85
- telemetry_1.Telemetry.disable();
86
- }
87
- else {
88
- telemetry_1.Telemetry.setup();
89
- }
90
- // https://github.com/yarnpkg/yarn/issues/8334 - Yarn on Windows breaks apps that read from the environment variables
91
- // Yarn will run node via CreateProcess and pass npm_config_* variables in lowercase without unifying their value
92
- // with their possibly existing uppercase counterparts. This breaks programs that read from the environment block
93
- // and write to a case-insensitive dictionary since they expect to encounter each variable only once.
94
- // The values of the lowercase variables are the one npm actually wants to use, plus they are seeded from the
95
- // uppercase variable values one if there are no overrides.
96
- delete process.env.NPM_CONFIG_CACHE;
97
- delete process.env.NPM_CONFIG_PREFIX;
98
- const hasRunRnwDependencies = process.env.LocalAppData &&
99
- fs_1.default.existsSync(path_1.default.join(process.env.LocalAppData, 'rnw-dependencies.txt')); // CODESYNC \vnext\scripts\rnw-dependencies.ps1
100
- if (options.info) {
101
- try {
102
- const output = await info.getEnvironmentInfo();
103
- console.log(output.trimEnd());
104
- console.log(' Installed UWP SDKs:');
105
- const sdks = msbuildtools_1.default.getAllAvailableUAPVersions();
106
- sdks.forEach(version => console.log(' ' + version));
107
- return;
108
- }
109
- catch (err) {
110
- const e = err;
111
- telemetry_1.Telemetry.trackException(e);
112
- (0, commandWithProgress_1.newError)('Unable to print environment info.\n' + e.toString());
113
- return setExitProcessWithError(e, options.logging);
114
- }
115
- }
116
- let runWindowsError;
117
- try {
118
- await runWindowsInternal(args, config, options);
119
- }
120
- catch (e) {
121
- telemetry_1.Telemetry.trackException(e);
122
- runWindowsError = e;
123
- if (!hasRunRnwDependencies) {
124
- const rnwPkgJsonPath = require.resolve('react-native-windows/package.json', {
125
- paths: [process.cwd(), __dirname],
126
- });
127
- const rnwDependenciesPath = path_1.default.join(path_1.default.dirname(rnwPkgJsonPath), 'scripts/rnw-dependencies.ps1');
128
- (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`);
129
- }
130
- return setExitProcessWithError(e, options.logging);
131
- }
132
- finally {
133
- (_a = telemetry_1.Telemetry.client) === null || _a === void 0 ? void 0 : _a.trackEvent({
134
- name: 'run-windows',
135
- properties: {
136
- release: options.release,
137
- arch: options.arch,
138
- singleproc: options.singleproc,
139
- emulator: options.emulator,
140
- device: options.device,
141
- target: options.target,
142
- remoteDebugging: options.remoteDebugging,
143
- logging: options.logging,
144
- packager: options.packager,
145
- bundle: options.bundle,
146
- launch: options.launch,
147
- autolink: options.autolink,
148
- build: options.bundle,
149
- deploy: options.deploy,
150
- sln: options.sln !== undefined,
151
- proj: options.proj !== undefined,
152
- msBuildProps: options.msbuildprops !== undefined
153
- ? options.msbuildprops.split(',').length
154
- : 0,
155
- info: options.info,
156
- directDebugging: options.directDebugging,
157
- 'react-native-windows': getPkgVersion('react-native-windows'),
158
- 'react-native': getPkgVersion('react-native'),
159
- 'cli-version': getPkgVersion('@react-native-windows/cli'),
160
- msftInternal: (0, telemetry_1.isMSFTInternal)(),
161
- durationInSecs: process.uptime(),
162
- success: runWindowsError === undefined,
163
- phase: runWindowsPhase,
164
- totalMem: (0, os_1.totalmem)(),
165
- diskFree: (0, telemetry_1.getDiskFreeSpace)(__dirname),
166
- cpus: (0, os_1.cpus)().length,
167
- project: await getAnonymizedProjectName(config.root),
168
- hasRunRnwDependencies: hasRunRnwDependencies,
169
- },
170
- });
171
- (_b = telemetry_1.Telemetry.client) === null || _b === void 0 ? void 0 : _b.flush();
172
- }
173
- }
174
- async function getAnonymizedProjectName(projectRoot) {
175
- const projectJsonPath = path_1.default.join(projectRoot, 'package.json');
176
- if (!fs_1.default.existsSync(projectJsonPath)) {
177
- return null;
178
- }
179
- const projectJson = JSON.parse((await fs_1.default.promises.readFile(projectJsonPath)).toString());
180
- const projectName = projectJson.name;
181
- if (typeof projectName !== 'string') {
182
- return null;
183
- }
184
- // Ensure the project name cannot be reverse engineered to avoid leaking PII
185
- return crypto_1.default
186
- .createHash('sha256')
187
- .update(projectName)
188
- .digest('hex')
189
- .toString();
190
- }
191
- exports.getAnonymizedProjectName = getAnonymizedProjectName;
192
- async function runWindowsInternal(args, config, options) {
193
- const verbose = options.logging === true;
194
- if (verbose) {
195
- (0, commandWithProgress_1.newInfo)('Verbose: ON');
196
- }
197
- // Get the solution file
198
- let slnFile;
199
- try {
200
- slnFile = build.getAppSolutionFile(options, config);
201
- }
202
- catch (e) {
203
- (0, commandWithProgress_1.newError)(`Couldn't get app solution information. ${e.message}`);
204
- throw e;
205
- }
206
- try {
207
- if (options.autolink) {
208
- const autolinkArgs = [];
209
- const autolinkConfig = config;
210
- const autoLinkOptions = {
211
- logging: options.logging,
212
- proj: options.proj,
213
- sln: options.sln,
214
- };
215
- runWindowsPhase = 'AutoLink';
216
- await autolink_1.autoLinkCommand.func(autolinkArgs, autolinkConfig, autoLinkOptions);
217
- }
218
- else {
219
- (0, commandWithProgress_1.newInfo)('Autolink step is skipped');
220
- }
221
- }
222
- catch (e) {
223
- (0, commandWithProgress_1.newError)(`Autolinking failed. ${e.message}`);
224
- throw e;
225
- }
226
- let buildTools;
227
- runWindowsPhase = 'FindBuildTools';
228
- try {
229
- buildTools = msbuildtools_1.default.findAvailableVersion(options.arch, verbose);
230
- }
231
- catch (error) {
232
- (0, commandWithProgress_1.newWarn)('No public VS release found');
233
- // Try prerelease
234
- try {
235
- (0, commandWithProgress_1.newInfo)('Trying pre-release VS');
236
- buildTools = msbuildtools_1.default.findAvailableVersion(options.arch, verbose, true);
237
- }
238
- catch (e) {
239
- (0, commandWithProgress_1.newError)(e.message);
240
- throw error;
241
- }
242
- }
243
- if (options.build) {
244
- runWindowsPhase = 'FindSolution';
245
- if (!slnFile) {
246
- (0, commandWithProgress_1.newError)('Visual Studio Solution file not found. Maybe run "npx react-native-windows-init" first?');
247
- throw new telemetry_1.CodedError('NoSolution', 'Cannot find solution file');
248
- }
249
- // Get build/deploy options
250
- const buildType = deploy.getBuildConfiguration(options);
251
- const msBuildProps = build.parseMsBuildProps(options);
252
- // Disable the autolink check since we just ran it
253
- msBuildProps.RunAutolinkCheck = 'false';
254
- try {
255
- runWindowsPhase = 'FindSolution';
256
- await build.buildSolution(buildTools, slnFile, buildType, options.arch, msBuildProps, verbose, 'build', options.buildLogDirectory, options.singleproc);
257
- }
258
- catch (e) {
259
- (0, commandWithProgress_1.newError)(`Build failed with message ${e.message}. Check your build configuration.`);
260
- if (e.logfile) {
261
- console.log('See', chalk_1.default.bold(e.logfile));
262
- }
263
- throw e;
264
- }
265
- }
266
- else {
267
- (0, commandWithProgress_1.newInfo)('Build step is skipped');
268
- }
269
- if (shouldLaunchPackager(options)) {
270
- await deploy.startServerInNewWindow(options, verbose);
271
- }
272
- if (options.deploy) {
273
- runWindowsPhase = 'FindSolution';
274
- if (!slnFile) {
275
- (0, commandWithProgress_1.newError)('Visual Studio Solution file not found. Maybe run "npx react-native-windows-init" first?');
276
- throw new telemetry_1.CodedError('NoSolution', 'Cannot find solution file');
277
- }
278
- try {
279
- runWindowsPhase = 'Deploy';
280
- if (options.device || options.emulator || options.target) {
281
- await deploy.deployToDevice(options, verbose, config);
282
- }
283
- else {
284
- await deploy.deployToDesktop(options, verbose, config, buildTools);
285
- }
286
- }
287
- catch (e) {
288
- (0, commandWithProgress_1.newError)(`Failed to deploy${e ? `: ${e.message}` : ''}`);
289
- throw e;
290
- }
291
- }
292
- else {
293
- (0, commandWithProgress_1.newInfo)('Deploy step is skipped');
294
- }
295
- }
296
- function shouldLaunchPackager(options) {
297
- return (options.packager === true &&
298
- options.launch === true &&
299
- options.release !== true);
300
- }
301
- /*
302
- // Example of running the Windows Command
303
- runWindows({
304
- root: 'C:\\github\\hack\\myapp',
305
- debug: true,
306
- arch: 'x86',
307
- nugetPath: 'C:\\github\\react\\react-native-windows\\local-cli\\runWindows\\.nuget\\nuget.exe'
308
- });
309
- */
310
- /**
311
- * Starts the app on a connected Windows emulator or mobile device.
312
- */
313
- exports.runWindowsCommand = {
314
- name: 'run-windows',
315
- description: 'builds your app and starts it on a connected Windows desktop, emulator or device',
316
- func: runWindows,
317
- options: runWindowsOptions_1.runWindowsOptions,
318
- };
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
+ };
319
322
  //# sourceMappingURL=runWindows.js.map