@react-native-windows/cli 0.0.0-canary.28 → 0.0.0-canary.280

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 (150) hide show
  1. package/README.md +117 -0
  2. package/lib-commonjs/commands/autolinkWindows/autolinkWindows.d.ts +88 -0
  3. package/lib-commonjs/commands/autolinkWindows/autolinkWindows.js +705 -0
  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 +211 -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 +141 -93
  15. package/lib-commonjs/commands/config/configUtils.js +433 -0
  16. package/lib-commonjs/commands/config/configUtils.js.map +1 -0
  17. package/lib-commonjs/{config → commands/config}/dependencyConfig.d.ts +38 -37
  18. package/lib-commonjs/{config → commands/config}/dependencyConfig.js +229 -171
  19. package/lib-commonjs/commands/config/dependencyConfig.js.map +1 -0
  20. package/lib-commonjs/{config → commands/config}/projectConfig.d.ts +28 -25
  21. package/lib-commonjs/commands/config/projectConfig.js +191 -0
  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/commands/healthCheck/healthChecks.d.ts +7 -0
  27. package/lib-commonjs/commands/healthCheck/healthChecks.js +121 -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 +290 -0
  31. package/lib-commonjs/commands/initWindows/initWindows.js.map +1 -0
  32. package/lib-commonjs/commands/initWindows/initWindowsOptions.d.ts +16 -0
  33. package/lib-commonjs/commands/initWindows/initWindowsOptions.js +42 -0
  34. package/lib-commonjs/commands/initWindows/initWindowsOptions.js.map +1 -0
  35. package/lib-commonjs/{runWindows → commands/runWindows}/runWindows.d.ts +10 -10
  36. package/lib-commonjs/commands/runWindows/runWindows.js +327 -0
  37. package/lib-commonjs/commands/runWindows/runWindows.js.map +1 -0
  38. package/lib-commonjs/{runWindows → commands/runWindows}/runWindowsOptions.d.ts +54 -52
  39. package/lib-commonjs/{runWindows → commands/runWindows}/runWindowsOptions.js +128 -131
  40. package/lib-commonjs/commands/runWindows/runWindowsOptions.js.map +1 -0
  41. package/lib-commonjs/e2etest/autolink.test.d.ts +6 -0
  42. package/lib-commonjs/e2etest/autolink.test.js +367 -0
  43. package/lib-commonjs/e2etest/autolink.test.js.map +1 -0
  44. package/lib-commonjs/e2etest/createRnwApp.test.d.ts +6 -0
  45. package/lib-commonjs/e2etest/createRnwApp.test.js +296 -0
  46. package/lib-commonjs/e2etest/createRnwApp.test.js.map +1 -0
  47. package/lib-commonjs/e2etest/dependencyConfig.test.d.ts +6 -6
  48. package/lib-commonjs/e2etest/dependencyConfig.test.js +109 -101
  49. package/lib-commonjs/e2etest/dependencyConfig.test.js.map +1 -1
  50. package/lib-commonjs/e2etest/healthChecks.test.d.ts +6 -0
  51. package/lib-commonjs/e2etest/healthChecks.test.js +31 -0
  52. package/lib-commonjs/e2etest/healthChecks.test.js.map +1 -0
  53. package/lib-commonjs/e2etest/initWindows.test.d.ts +6 -0
  54. package/lib-commonjs/e2etest/initWindows.test.js +110 -0
  55. package/lib-commonjs/e2etest/initWindows.test.js.map +1 -0
  56. package/lib-commonjs/e2etest/projectConfig.test.d.ts +6 -6
  57. package/lib-commonjs/e2etest/projectConfig.test.js +107 -101
  58. package/lib-commonjs/e2etest/projectConfig.test.js.map +1 -1
  59. package/lib-commonjs/e2etest/projectConfig.utils.d.ts +8 -0
  60. package/lib-commonjs/e2etest/projectConfig.utils.js +54 -0
  61. package/lib-commonjs/e2etest/projectConfig.utils.js.map +1 -0
  62. package/lib-commonjs/e2etest/runWindows.test.d.ts +6 -0
  63. package/lib-commonjs/e2etest/runWindows.test.js +60 -0
  64. package/lib-commonjs/e2etest/runWindows.test.js.map +1 -0
  65. package/lib-commonjs/e2etest/typesUpToDate.test.d.ts +6 -0
  66. package/lib-commonjs/e2etest/typesUpToDate.test.js +21 -0
  67. package/lib-commonjs/e2etest/typesUpToDate.test.js.map +1 -0
  68. package/lib-commonjs/generator-common/index.d.ts +39 -39
  69. package/lib-commonjs/generator-common/index.js +242 -222
  70. package/lib-commonjs/generator-common/index.js.map +1 -1
  71. package/lib-commonjs/generator-windows/index.d.ts +10 -10
  72. package/lib-commonjs/generator-windows/index.js +331 -366
  73. package/lib-commonjs/generator-windows/index.js.map +1 -1
  74. package/lib-commonjs/index.d.ts +49 -47
  75. package/lib-commonjs/index.js +77 -39
  76. package/lib-commonjs/index.js.map +1 -1
  77. package/lib-commonjs/{runWindows/utils → utils}/build.d.ts +12 -13
  78. package/lib-commonjs/{runWindows/utils → utils}/build.js +89 -91
  79. package/lib-commonjs/utils/build.js.map +1 -0
  80. package/lib-commonjs/{runWindows/utils → utils}/checkRequirements.d.ts +6 -6
  81. package/lib-commonjs/{runWindows/utils → utils}/checkRequirements.js +69 -65
  82. package/lib-commonjs/utils/checkRequirements.js.map +1 -0
  83. package/lib-commonjs/{runWindows/utils → utils}/commandWithProgress.d.ts +21 -13
  84. package/lib-commonjs/{runWindows/utils → utils}/commandWithProgress.js +149 -113
  85. package/lib-commonjs/utils/commandWithProgress.js.map +1 -0
  86. package/lib-commonjs/{runWindows/utils → utils}/deploy.d.ts +12 -12
  87. package/lib-commonjs/utils/deploy.js +351 -0
  88. package/lib-commonjs/utils/deploy.js.map +1 -0
  89. package/lib-commonjs/{runWindows/utils → utils}/info.d.ts +6 -6
  90. package/lib-commonjs/{runWindows/utils → utils}/info.js +28 -25
  91. package/lib-commonjs/utils/info.js.map +1 -0
  92. package/lib-commonjs/utils/msbuildtools.d.ts +28 -0
  93. package/lib-commonjs/utils/msbuildtools.js +280 -0
  94. package/lib-commonjs/utils/msbuildtools.js.map +1 -0
  95. package/lib-commonjs/utils/nameHelpers.d.ts +9 -0
  96. package/lib-commonjs/utils/nameHelpers.js +46 -0
  97. package/lib-commonjs/utils/nameHelpers.js.map +1 -0
  98. package/lib-commonjs/utils/oldArchWarning.d.ts +9 -0
  99. package/lib-commonjs/utils/oldArchWarning.js +29 -0
  100. package/lib-commonjs/utils/oldArchWarning.js.map +1 -0
  101. package/lib-commonjs/utils/pathHelpers.d.ts +6 -0
  102. package/lib-commonjs/utils/pathHelpers.js +19 -0
  103. package/lib-commonjs/utils/pathHelpers.js.map +1 -0
  104. package/lib-commonjs/utils/telemetryHelpers.d.ts +29 -0
  105. package/lib-commonjs/utils/telemetryHelpers.js +127 -0
  106. package/lib-commonjs/utils/telemetryHelpers.js.map +1 -0
  107. package/lib-commonjs/{runWindows/utils → utils}/version.d.ts +19 -19
  108. package/lib-commonjs/{runWindows/utils → utils}/version.js +109 -109
  109. package/lib-commonjs/utils/version.js.map +1 -0
  110. package/lib-commonjs/{runWindows/utils → utils}/vsInstalls.d.ts +34 -34
  111. package/lib-commonjs/utils/vsInstalls.js +102 -0
  112. package/lib-commonjs/utils/vsInstalls.js.map +1 -0
  113. package/lib-commonjs/{runWindows/utils → utils}/vstools.d.ts +16 -16
  114. package/lib-commonjs/{runWindows/utils → utils}/vstools.js +189 -157
  115. package/lib-commonjs/utils/vstools.js.map +1 -0
  116. package/lib-commonjs/{runWindows/utils → utils}/winappdeploytool.d.ts +24 -24
  117. package/lib-commonjs/{runWindows/utils → utils}/winappdeploytool.js +108 -105
  118. package/lib-commonjs/utils/winappdeploytool.js.map +1 -0
  119. package/package.json +50 -31
  120. package/{powershell → src/powershell}/Add-AppDevPackage.ps1 +2 -2
  121. package/src/powershell/Eval-MsBuildProperties.ps1 +156 -0
  122. package/src/powershell/WindowsStoreAppUtils.psm1 +465 -0
  123. package/CHANGELOG.json +0 -443
  124. package/CHANGELOG.md +0 -216
  125. package/lib-commonjs/config/configUtils.js +0 -253
  126. package/lib-commonjs/config/configUtils.js.map +0 -1
  127. package/lib-commonjs/config/dependencyConfig.js.map +0 -1
  128. package/lib-commonjs/config/projectConfig.js +0 -121
  129. package/lib-commonjs/config/projectConfig.js.map +0 -1
  130. package/lib-commonjs/runWindows/runWindows.js +0 -159
  131. package/lib-commonjs/runWindows/runWindows.js.map +0 -1
  132. package/lib-commonjs/runWindows/runWindowsOptions.js.map +0 -1
  133. package/lib-commonjs/runWindows/utils/autolink.d.ts +0 -7
  134. package/lib-commonjs/runWindows/utils/autolink.js +0 -404
  135. package/lib-commonjs/runWindows/utils/autolink.js.map +0 -1
  136. package/lib-commonjs/runWindows/utils/build.js.map +0 -1
  137. package/lib-commonjs/runWindows/utils/checkRequirements.js.map +0 -1
  138. package/lib-commonjs/runWindows/utils/commandWithProgress.js.map +0 -1
  139. package/lib-commonjs/runWindows/utils/deploy.js +0 -247
  140. package/lib-commonjs/runWindows/utils/deploy.js.map +0 -1
  141. package/lib-commonjs/runWindows/utils/info.js.map +0 -1
  142. package/lib-commonjs/runWindows/utils/msbuildtools.d.ts +0 -22
  143. package/lib-commonjs/runWindows/utils/msbuildtools.js +0 -195
  144. package/lib-commonjs/runWindows/utils/msbuildtools.js.map +0 -1
  145. package/lib-commonjs/runWindows/utils/version.js.map +0 -1
  146. package/lib-commonjs/runWindows/utils/vsInstalls.js +0 -70
  147. package/lib-commonjs/runWindows/utils/vsInstalls.js.map +0 -1
  148. package/lib-commonjs/runWindows/utils/vstools.js.map +0 -1
  149. package/lib-commonjs/runWindows/utils/winappdeploytool.js.map +0 -1
  150. package/powershell/WindowsStoreAppUtils.ps1 +0 -264
@@ -0,0 +1,280 @@
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 shelljs_1 = __importDefault(require("shelljs"));
40
+ const version_1 = __importDefault(require("./version"));
41
+ const checkRequirements = __importStar(require("./checkRequirements"));
42
+ const commandWithProgress_1 = require("./commandWithProgress");
43
+ const child_process_2 = require("child_process");
44
+ const vsInstalls_1 = require("./vsInstalls");
45
+ const telemetry_1 = require("@react-native-windows/telemetry");
46
+ class MSBuildTools {
47
+ /**
48
+ * @param version is something like 17.0 for 2022
49
+ * @param installationPath Path to installation root
50
+ * @param installationVersion is the full version e.g. 17.3.32929.385
51
+ */
52
+ constructor(version, installationPath, installationVersion) {
53
+ this.version = version;
54
+ this.installationPath = installationPath;
55
+ this.installationVersion = installationVersion;
56
+ }
57
+ /**
58
+ * @returns directory where x64 msbuild can be found
59
+ */
60
+ msbuildPath() {
61
+ return path_1.default.join(this.installationPath, 'MSBuild/Current/Bin/amd64');
62
+ }
63
+ cleanProject(slnFile) {
64
+ const cmd = `"${path_1.default.join(this.msbuildPath(), 'msbuild.exe')}" "${slnFile}" /t:Clean`;
65
+ const results = child_process_1.default.execSync(cmd).toString().split(os_1.EOL);
66
+ results.forEach(result => console.log(chalk_1.default.white(result)));
67
+ }
68
+ async restorePackageConfigs(slnFile, buildArch, buildType) {
69
+ const text = 'Restoring NuGet packages ';
70
+ const spinner = (0, commandWithProgress_1.newSpinner)(text);
71
+ await (0, commandWithProgress_1.commandWithProgress)(spinner, text, path_1.default.join(this.msbuildPath(), 'msbuild.exe'), [
72
+ slnFile,
73
+ '/t:Restore',
74
+ '/p:RestoreProjectStyle=PackagesConfig',
75
+ '/p:RestorePackagesConfig=true',
76
+ `/p:Platform=${buildArch}`,
77
+ `/p:Configuration=${buildType}`,
78
+ ], true, 'MSBuildError');
79
+ }
80
+ async buildProject(slnFile, buildType, buildArch, msBuildProps, verbose, target, buildLogDirectory, singleproc) {
81
+ (0, commandWithProgress_1.newSuccess)(`Found Solution: ${slnFile}`);
82
+ (0, commandWithProgress_1.newInfo)(`Build configuration: ${buildType}`);
83
+ (0, commandWithProgress_1.newInfo)(`Build platform: ${buildArch}`);
84
+ const verbosityOption = verbose ? 'normal' : 'minimal';
85
+ const defaultLogDirectory = path_1.default.dirname(slnFile);
86
+ const logPrefix = path_1.default.join(buildLogDirectory || defaultLogDirectory, `msbuild_${process.pid}_${target}`);
87
+ const errorLog = logPrefix + '.err';
88
+ const warnLog = logPrefix + '.wrn';
89
+ const binlog = `:${logPrefix}.binlog`;
90
+ const args = [
91
+ `/clp:NoSummary;NoItemAndPropertyList;Verbosity=${verbosityOption}`,
92
+ '/nologo',
93
+ `/p:Configuration=${buildType}`,
94
+ `/p:Platform=${buildArch}`,
95
+ '/p:AppxBundle=Never',
96
+ `/bl${binlog}`,
97
+ `/flp1:errorsonly;logfile=${errorLog}`,
98
+ `/flp2:warningsonly;logfile=${warnLog}`,
99
+ ];
100
+ // Building projects in parallel increases compiler memory usage and
101
+ // doesn't lead to dramatic performance gains (See #4739). Only enable
102
+ // parallel builds on machines with >16GB of memory to avoid OOM errors
103
+ const highMemory = (0, os_1.totalmem)() > 16 * 1024 * 1024 * 1024;
104
+ const enableParallelBuilds = singleproc !== true && highMemory;
105
+ if (enableParallelBuilds) {
106
+ args.push('/maxCpuCount');
107
+ }
108
+ if (target === 'build') {
109
+ args.push('/restore', '/p:RestorePackagesConfig=true');
110
+ }
111
+ else {
112
+ args.push(`/t:Deploy`);
113
+ }
114
+ Object.keys(msBuildProps).forEach(key => {
115
+ args.push(`/p:${key}=${msBuildProps[key]}`);
116
+ });
117
+ try {
118
+ checkRequirements.isWinSdkPresent('10.0');
119
+ }
120
+ catch (e) {
121
+ (0, commandWithProgress_1.newError)(e.message);
122
+ throw e;
123
+ }
124
+ if (verbose) {
125
+ console.log(`Running MSBuild with args ${args.join(' ')}`);
126
+ }
127
+ const progressName = target === 'deploy' ? 'Deploying Solution' : 'Building Solution';
128
+ const spinner = (0, commandWithProgress_1.newSpinner)(progressName);
129
+ try {
130
+ await (0, commandWithProgress_1.commandWithProgress)(spinner, progressName, path_1.default.join(this.msbuildPath(), 'msbuild.exe'), [slnFile].concat(args), verbose, 'MSBuildError');
131
+ }
132
+ catch (e) {
133
+ let error = e;
134
+ if (e instanceof telemetry_1.CodedError) {
135
+ const origCodedError = e;
136
+ if (origCodedError.type === 'MSBuildError') {
137
+ // Try to parse msbuild errors from errorLog
138
+ const errorLogContents = (await fs_1.default.readFile(errorLog))
139
+ .toString()
140
+ .split(os_1.EOL)
141
+ .filter(s => s)
142
+ .map(s => s.trim());
143
+ if (errorLogContents.length > 0) {
144
+ const firstMessage = errorLogContents[0];
145
+ error = new telemetry_1.CodedError('MSBuildError', firstMessage, origCodedError.data);
146
+ // Hide error messages in a field that won't automatically get reported
147
+ // with telemetry but is still available to be parsed and sanitized
148
+ error.msBuildErrorMessages = errorLogContents;
149
+ }
150
+ }
151
+ }
152
+ throw error;
153
+ }
154
+ // If we have no errors, delete the error log when we're done
155
+ if ((await fs_1.default.stat(errorLog)).size === 0) {
156
+ await fs_1.default.unlink(errorLog);
157
+ }
158
+ }
159
+ static findAvailableVersion(buildArch, verbose, prerelease) {
160
+ // https://aka.ms/vs/workloads
161
+ const requires = [
162
+ 'Microsoft.Component.MSBuild',
163
+ getVCToolsByArch(buildArch),
164
+ ];
165
+ const minVersion = process.env.MinimumVisualStudioVersion ||
166
+ process.env.VisualStudioVersion ||
167
+ '17.11.0';
168
+ const vsInstallation = (0, vsInstalls_1.findLatestVsInstall)({
169
+ requires,
170
+ minVersion,
171
+ verbose,
172
+ prerelease,
173
+ });
174
+ if (!vsInstallation) {
175
+ if (process.env.MinimumVisualStudioVersion != null) {
176
+ throw new telemetry_1.CodedError('NoMSBuild', `MSBuild tools not found for version ${process.env.MinimumVisualStudioVersion} (from environment). Make sure all required components have been installed`, {
177
+ MinimumVisualStudioVersionFromEnv: process.env.MinimumVisualStudioVersion,
178
+ });
179
+ }
180
+ else if (process.env.VisualStudioVersion != null) {
181
+ 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 });
182
+ }
183
+ else {
184
+ 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 });
185
+ }
186
+ }
187
+ const toolsPath = path_1.default.join(vsInstallation.installationPath, 'MSBuild/Current/Bin/amd64');
188
+ if (fs_1.default.existsSync(toolsPath)) {
189
+ if (verbose) {
190
+ (0, commandWithProgress_1.newSuccess)(`Found compatible MSBuild at ${toolsPath} (${vsInstallation.installationVersion})`);
191
+ }
192
+ return new MSBuildTools(minVersion, vsInstallation.installationPath, vsInstallation.installationVersion);
193
+ }
194
+ else {
195
+ throw new telemetry_1.CodedError('NoMSBuild', `MSBuild path '${toolsPath} does not exist'`);
196
+ }
197
+ }
198
+ static getAllAvailableUAPVersions() {
199
+ const results = [];
200
+ const programFilesFolder = process.env['ProgramFiles(x86)'] || process.env.ProgramFiles;
201
+ // No Program Files folder found, so we won't be able to find UAP SDK
202
+ if (!programFilesFolder) {
203
+ return results;
204
+ }
205
+ let uapFolderPath = path_1.default.join(programFilesFolder, 'Windows Kits', '10', 'Platforms', 'UAP');
206
+ if (!shelljs_1.default.test('-e', uapFolderPath)) {
207
+ // Check other installation folder from reg
208
+ const sdkFolder = getSDK10InstallationFolder();
209
+ if (sdkFolder) {
210
+ uapFolderPath = path_1.default.join(sdkFolder, 'Platforms', 'UAP');
211
+ }
212
+ }
213
+ // No UAP SDK exists on this machine
214
+ if (!shelljs_1.default.test('-e', uapFolderPath)) {
215
+ return results;
216
+ }
217
+ shelljs_1.default
218
+ .ls(uapFolderPath)
219
+ .filter(uapDir => shelljs_1.default.test('-d', path_1.default.join(uapFolderPath, uapDir)))
220
+ .map(version_1.default.tryParse)
221
+ .forEach(version => version && results.push(version));
222
+ return results;
223
+ }
224
+ evaluateMSBuildProperties(solutionFile, projectFile, propertyNames, extraMsBuildProps) {
225
+ const spinner = (0, commandWithProgress_1.newSpinner)('Running Eval-MsBuildProperties.ps1');
226
+ try {
227
+ const msbuildEvalScriptPath = path_1.default.resolve(__dirname, '..', '..', 'src', 'powershell', 'Eval-MsBuildProperties.ps1');
228
+ let command = `${commandWithProgress_1.powershell} -ExecutionPolicy Unrestricted -NoProfile "${msbuildEvalScriptPath}" -SolutionFile '${solutionFile}' -ProjectFile '${projectFile}' -MSBuildPath '${this.msbuildPath()}'`;
229
+ if (propertyNames && propertyNames.length > 0) {
230
+ command += ` -PropertyNames '${propertyNames.join(',')}'`;
231
+ }
232
+ if (extraMsBuildProps) {
233
+ command += " -ExtraMSBuildProps '";
234
+ for (const extraProp in extraMsBuildProps) {
235
+ if (!(extraProp in Object.prototype)) {
236
+ command += `,${extraProp}=${extraMsBuildProps[extraProp]}`;
237
+ }
238
+ }
239
+ command += "'";
240
+ }
241
+ const commandOutput = (0, child_process_2.execSync)(command).toString();
242
+ spinner.succeed();
243
+ const properties = JSON.parse(commandOutput);
244
+ spinner.succeed();
245
+ return properties;
246
+ }
247
+ catch (e) {
248
+ spinner.fail('Running Eval-MsBuildProperties.ps1 failed: ' + e.message);
249
+ throw e;
250
+ }
251
+ }
252
+ }
253
+ exports.default = MSBuildTools;
254
+ function getVCToolsByArch(buildArch) {
255
+ switch (buildArch) {
256
+ case 'x86':
257
+ case 'x64':
258
+ return 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64';
259
+ case 'ARM64':
260
+ return 'Microsoft.VisualStudio.Component.VC.Tools.ARM64';
261
+ }
262
+ }
263
+ function getSDK10InstallationFolder() {
264
+ const folder = '';
265
+ const execString = 'reg query "HKLM\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v10.0" /s /v InstallationFolder /reg:32';
266
+ let output;
267
+ try {
268
+ output = (0, child_process_2.execSync)(execString).toString();
269
+ }
270
+ catch (e) {
271
+ return folder;
272
+ }
273
+ const re = /\\Microsoft SDKs\\Windows\\v10.0\s*InstallationFolder\s+REG_SZ\s+(.*)/gim;
274
+ const match = re.exec(output);
275
+ if (match) {
276
+ return match[1];
277
+ }
278
+ return folder;
279
+ }
280
+ //# sourceMappingURL=msbuildtools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"msbuildtools.js","sourceRoot":"","sources":["../../src/utils/msbuildtools.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,2BAAiC;AACjC,kEAA0C;AAC1C,gDAAwB;AACxB,kEAA0C;AAC1C,kDAA0B;AAC1B,sDAA4B;AAC5B,wDAAgC;AAChC,uEAAyD;AACzD,+DAO+B;AAC/B,iDAAuC;AAEvC,6CAAiD;AACjD,+DAA2D;AAE3D,MAAqB,YAAY;IAC/B;;;;OAIG;IACH,YACkB,OAAe,EACf,gBAAwB,EACxB,mBAA2B;QAF3B,YAAO,GAAP,OAAO,CAAQ;QACf,qBAAgB,GAAhB,gBAAgB,CAAQ;QACxB,wBAAmB,GAAnB,mBAAmB,CAAQ;IAC1C,CAAC;IAEJ;;OAEG;IACH,WAAW;QACT,OAAO,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,2BAA2B,CAAC,CAAC;IACvE,CAAC;IAED,YAAY,CAAC,OAAe;QAC1B,MAAM,GAAG,GAAG,IAAI,cAAI,CAAC,IAAI,CACvB,IAAI,CAAC,WAAW,EAAE,EAClB,aAAa,CACd,MAAM,OAAO,YAAY,CAAC;QAC3B,MAAM,OAAO,GAAG,uBAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,QAAG,CAAC,CAAC;QAClE,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC9D,CAAC;IAED,KAAK,CAAC,qBAAqB,CACzB,OAAY,EACZ,SAAoB,EACpB,SAAsB;QAEtB,MAAM,IAAI,GAAG,2BAA2B,C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C;YACF,MAAM,CAAC,CAAC;SACT;IACH,CAAC;CACF;AAjUD,+BAiUC;AAED,SAAS,gBAAgB,CAAC,SAAoB;IAC5C,QAAQ,SAAS,EAAE;QACjB,KAAK,KAAK,CAAC;QACX,KAAK,KAAK;YACR,OAAO,mDAAmD,CAAC;QAC7D,KAAK,OAAO;YACV,OAAO,iDAAiD,CAAC;KAC5D;AACH,CAAC;AAED,SAAS,0BAA0B;IACjC,MAAM,MAAM,GAAG,EAAE,CAAC;IAElB,MAAM,UAAU,GACd,wGAAwG,CAAC;IAC3G,IAAI,MAAM,CAAC;IACX,IAAI;QACF,MAAM,GAAG,IAAA,wBAAQ,EAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC;KAC1C;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,MAAM,CAAC;KACf;IAED,MAAM,EAAE,GACN,0EAA0E,CAAC;IAC7E,MAAM,KAAK,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9B,IAAI,KAAK,EAAE;QACT,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;KACjB;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\nimport {totalmem, EOL} from 'os';\nimport fs from '@react-native-windows/fs';\nimport path from 'path';\nimport child_process from 'child_process';\nimport chalk from 'chalk';\nimport shell from 'shelljs';\nimport Version from './version';\nimport * as checkRequirements from './checkRequirements';\nimport {\n commandWithProgress,\n newInfo,\n newSpinner,\n newSuccess,\n newError,\n powershell,\n} from './commandWithProgress';\nimport {execSync} from 'child_process';\nimport {BuildArch, BuildConfig} from '../commands/runWindows/runWindowsOptions';\nimport {findLatestVsInstall} from './vsInstalls';\nimport {CodedError} from '@react-native-windows/telemetry';\n\nexport default class MSBuildTools {\n /**\n * @param version is something like 17.0 for 2022\n * @param installationPath Path to installation root\n * @param installationVersion is the full version e.g. 17.3.32929.385\n */\n constructor(\n public readonly version: string,\n public readonly installationPath: string,\n public readonly installationVersion: string,\n ) {}\n\n /**\n * @returns directory where x64 msbuild can be found\n */\n msbuildPath() {\n return path.join(this.installationPath, 'MSBuild/Current/Bin/amd64');\n }\n\n cleanProject(slnFile: string) {\n const cmd = `\"${path.join(\n this.msbuildPath(),\n 'msbuild.exe',\n )}\" \"${slnFile}\" /t:Clean`;\n const results = child_process.execSync(cmd).toString().split(EOL);\n results.forEach(result => console.log(chalk.white(result)));\n }\n\n async restorePackageConfigs(\n slnFile: any,\n buildArch: BuildArch,\n buildType: BuildConfig,\n ) {\n const text = 'Restoring NuGet packages ';\n const spinner = newSpinner(text);\n await commandWithProgress(\n spinner,\n text,\n path.join(this.msbuildPath(), 'msbuild.exe'),\n [\n slnFile,\n '/t:Restore',\n '/p:RestoreProjectStyle=PackagesConfig',\n '/p:RestorePackagesConfig=true',\n `/p:Platform=${buildArch}`,\n `/p:Configuration=${buildType}`,\n ],\n true,\n 'MSBuildError',\n );\n }\n\n async buildProject(\n slnFile: string,\n buildType: BuildConfig,\n buildArch: BuildArch,\n msBuildProps: Record<string, string>,\n verbose: boolean,\n target: 'build' | 'deploy',\n buildLogDirectory: string | undefined,\n singleproc?: boolean,\n ) {\n newSuccess(`Found Solution: ${slnFile}`);\n newInfo(`Build configuration: ${buildType}`);\n newInfo(`Build platform: ${buildArch}`);\n\n const verbosityOption = verbose ? 'normal' : 'minimal';\n const defaultLogDirectory = path.dirname(slnFile);\n const logPrefix = path.join(\n buildLogDirectory || defaultLogDirectory,\n `msbuild_${process.pid}_${target}`,\n );\n\n const errorLog = logPrefix + '.err';\n const warnLog = logPrefix + '.wrn';\n\n const binlog = `:${logPrefix}.binlog`;\n\n const args = [\n `/clp:NoSummary;NoItemAndPropertyList;Verbosity=${verbosityOption}`,\n '/nologo',\n `/p:Configuration=${buildType}`,\n `/p:Platform=${buildArch}`,\n '/p:AppxBundle=Never',\n `/bl${binlog}`,\n `/flp1:errorsonly;logfile=${errorLog}`,\n `/flp2:warningsonly;logfile=${warnLog}`,\n ];\n\n // Building projects in parallel increases compiler memory usage and\n // doesn't lead to dramatic performance gains (See #4739). Only enable\n // parallel builds on machines with >16GB of memory to avoid OOM errors\n const highMemory = totalmem() > 16 * 1024 * 1024 * 1024;\n const enableParallelBuilds = singleproc !== true && highMemory;\n\n if (enableParallelBuilds) {\n args.push('/maxCpuCount');\n }\n\n if (target === 'build') {\n args.push('/restore', '/p:RestorePackagesConfig=true');\n } else {\n args.push(`/t:Deploy`);\n }\n\n Object.keys(msBuildProps).forEach(key => {\n args.push(`/p:${key}=${msBuildProps[key]}`);\n });\n\n try {\n checkRequirements.isWinSdkPresent('10.0');\n } catch (e) {\n newError((e as Error).message);\n throw e;\n }\n\n if (verbose) {\n console.log(`Running MSBuild with args ${args.join(' ')}`);\n }\n\n const progressName =\n target === 'deploy' ? 'Deploying Solution' : 'Building Solution';\n const spinner = newSpinner(progressName);\n try {\n await commandWithProgress(\n spinner,\n progressName,\n path.join(this.msbuildPath(), 'msbuild.exe'),\n [slnFile].concat(args),\n verbose,\n 'MSBuildError',\n );\n } catch (e) {\n let error = e;\n if (e instanceof CodedError) {\n const origCodedError = e as CodedError;\n if (origCodedError.type === 'MSBuildError') {\n // Try to parse msbuild errors from errorLog\n const errorLogContents = (await fs.readFile(errorLog))\n .toString()\n .split(EOL)\n .filter(s => s)\n .map(s => s.trim());\n if (errorLogContents.length > 0) {\n const firstMessage = errorLogContents[0];\n error = new CodedError(\n 'MSBuildError',\n firstMessage,\n origCodedError.data,\n );\n // Hide error messages in a field that won't automatically get reported\n // with telemetry but is still available to be parsed and sanitized\n (error as any).msBuildErrorMessages = errorLogContents;\n }\n }\n }\n throw error;\n }\n // If we have no errors, delete the error log when we're done\n if ((await fs.stat(errorLog)).size === 0) {\n await fs.unlink(errorLog);\n }\n }\n\n static findAvailableVersion(\n buildArch: BuildArch,\n verbose: boolean,\n prerelease?: boolean,\n ): MSBuildTools {\n // https://aka.ms/vs/workloads\n const requires = [\n 'Microsoft.Component.MSBuild',\n getVCToolsByArch(buildArch),\n ];\n const minVersion =\n process.env.MinimumVisualStudioVersion ||\n process.env.VisualStudioVersion ||\n '17.11.0';\n const vsInstallation = findLatestVsInstall({\n requires,\n minVersion,\n verbose,\n prerelease,\n });\n\n if (!vsInstallation) {\n if (process.env.MinimumVisualStudioVersion != null) {\n throw new CodedError(\n 'NoMSBuild',\n `MSBuild tools not found for version ${process.env.MinimumVisualStudioVersion} (from environment). Make sure all required components have been installed`,\n {\n MinimumVisualStudioVersionFromEnv:\n process.env.MinimumVisualStudioVersion,\n },\n );\n } else if (process.env.VisualStudioVersion != null) {\n throw new CodedError(\n 'NoMSBuild',\n `MSBuild tools not found for version ${process.env.VisualStudioVersion} (from environment). Make sure all required components have been installed`,\n {VisualStudioVersionFromEnv: process.env.VisualStudioVersion},\n );\n } else {\n throw new CodedError(\n 'NoMSBuild',\n `Could not find MSBuild with VCTools for Visual Studio ${minVersion} or later. Make sure all required components have been installed`,\n {minVersion: minVersion},\n );\n }\n }\n\n const toolsPath = path.join(\n vsInstallation.installationPath,\n 'MSBuild/Current/Bin/amd64',\n );\n\n if (fs.existsSync(toolsPath)) {\n if (verbose) {\n newSuccess(\n `Found compatible MSBuild at ${toolsPath} (${vsInstallation.installationVersion})`,\n );\n }\n return new MSBuildTools(\n minVersion,\n vsInstallation.installationPath,\n vsInstallation.installationVersion,\n );\n } else {\n throw new CodedError(\n 'NoMSBuild',\n `MSBuild path '${toolsPath} does not exist'`,\n );\n }\n }\n\n static getAllAvailableUAPVersions(): Version[] {\n const results: Version[] = [];\n\n const programFilesFolder =\n process.env['ProgramFiles(x86)'] || process.env.ProgramFiles;\n // No Program Files folder found, so we won't be able to find UAP SDK\n if (!programFilesFolder) {\n return results;\n }\n\n let uapFolderPath = path.join(\n programFilesFolder,\n 'Windows Kits',\n '10',\n 'Platforms',\n 'UAP',\n );\n\n if (!shell.test('-e', uapFolderPath)) {\n // Check other installation folder from reg\n const sdkFolder = getSDK10InstallationFolder();\n if (sdkFolder) {\n uapFolderPath = path.join(sdkFolder, 'Platforms', 'UAP');\n }\n }\n\n // No UAP SDK exists on this machine\n if (!shell.test('-e', uapFolderPath)) {\n return results;\n }\n\n shell\n .ls(uapFolderPath)\n .filter(uapDir => shell.test('-d', path.join(uapFolderPath, uapDir)))\n .map(Version.tryParse)\n .forEach(version => version && results.push(version));\n\n return results;\n }\n\n evaluateMSBuildProperties(\n solutionFile: string,\n projectFile: string,\n propertyNames?: string[],\n extraMsBuildProps?: Record<string, string>,\n ): Record<string, string> {\n const spinner = newSpinner('Running Eval-MsBuildProperties.ps1');\n\n try {\n const msbuildEvalScriptPath = path.resolve(\n __dirname,\n '..',\n '..',\n 'src',\n 'powershell',\n 'Eval-MsBuildProperties.ps1',\n );\n\n let command = `${powershell} -ExecutionPolicy Unrestricted -NoProfile \"${msbuildEvalScriptPath}\" -SolutionFile '${solutionFile}' -ProjectFile '${projectFile}' -MSBuildPath '${this.msbuildPath()}'`;\n\n if (propertyNames && propertyNames.length > 0) {\n command += ` -PropertyNames '${propertyNames.join(',')}'`;\n }\n\n if (extraMsBuildProps) {\n command += \" -ExtraMSBuildProps '\";\n for (const extraProp in extraMsBuildProps) {\n if (!(extraProp in Object.prototype)) {\n command += `,${extraProp}=${extraMsBuildProps[extraProp]}`;\n }\n }\n command += \"'\";\n }\n\n const commandOutput = execSync(command).toString();\n spinner.succeed();\n\n const properties = JSON.parse(commandOutput) as Record<string, string>;\n spinner.succeed();\n return properties;\n } catch (e) {\n spinner.fail(\n 'Running Eval-MsBuildProperties.ps1 failed: ' + (e as Error).message,\n );\n throw e;\n }\n }\n}\n\nfunction getVCToolsByArch(buildArch: BuildArch): string {\n switch (buildArch) {\n case 'x86':\n case 'x64':\n return 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64';\n case 'ARM64':\n return 'Microsoft.VisualStudio.Component.VC.Tools.ARM64';\n }\n}\n\nfunction getSDK10InstallationFolder(): string {\n const folder = '';\n\n const execString =\n 'reg query \"HKLM\\\\SOFTWARE\\\\Microsoft\\\\Microsoft SDKs\\\\Windows\\\\v10.0\" /s /v InstallationFolder /reg:32';\n let output;\n try {\n output = execSync(execString).toString();\n } catch (e) {\n return folder;\n }\n\n const re =\n /\\\\Microsoft SDKs\\\\Windows\\\\v10.0\\s*InstallationFolder\\s+REG_SZ\\s+(.*)/gim;\n const match = re.exec(output);\n if (match) {\n return match[1];\n }\n\n return folder;\n}\n"]}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ export declare function isValidProjectName(name: string): boolean;
7
+ export declare function cleanName(str: string): string;
8
+ export declare function isValidProjectNamespace(namespace: string): boolean;
9
+ export declare function cleanNamespace(str: string): string;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation.
4
+ * Licensed under the MIT License.
5
+ * @format
6
+ */
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.cleanNamespace = exports.isValidProjectNamespace = exports.cleanName = exports.isValidProjectName = void 0;
12
+ const lodash_1 = __importDefault(require("lodash"));
13
+ function pascalCase(str) {
14
+ const camelCase = lodash_1.default.camelCase(str);
15
+ return camelCase[0].toUpperCase() + camelCase.substr(1);
16
+ }
17
+ function isValidProjectName(name) {
18
+ if (name.match(/^[a-z][a-z0-9]*$/gi)) {
19
+ return true;
20
+ }
21
+ return false;
22
+ }
23
+ exports.isValidProjectName = isValidProjectName;
24
+ function cleanName(str) {
25
+ str = str.replace('@', ''); // Remove '@' from package scope names
26
+ str = str.slice(str.lastIndexOf('/') + 1); // Remove package scope
27
+ str = pascalCase(str); // Convert to PascalCase
28
+ return str;
29
+ }
30
+ exports.cleanName = cleanName;
31
+ function isValidProjectNamespace(namespace) {
32
+ if (namespace
33
+ .split(/[.]+/)
34
+ .map(isValidProjectName)
35
+ .every(x => x)) {
36
+ // Validate that every part of the namespace is a valid project name
37
+ return true;
38
+ }
39
+ return false;
40
+ }
41
+ exports.isValidProjectNamespace = isValidProjectNamespace;
42
+ function cleanNamespace(str) {
43
+ return str.split(/[.:]+/).map(cleanName).join('.');
44
+ }
45
+ exports.cleanNamespace = cleanNamespace;
46
+ //# sourceMappingURL=nameHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nameHelpers.js","sourceRoot":"","sources":["../../src/utils/nameHelpers.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;AAEH,oDAAuB;AAEvB,SAAS,UAAU,CAAC,GAAW;IAC7B,MAAM,SAAS,GAAG,gBAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACnC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,IAAI,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,EAAE;QACpC,OAAO,IAAI,CAAC;KACb;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AALD,gDAKC;AAED,SAAgB,SAAS,CAAC,GAAW;IACnC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,sCAAsC;IAClE,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,uBAAuB;IAClE,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,wBAAwB;IAC/C,OAAO,GAAG,CAAC;AACb,CAAC;AALD,8BAKC;AAED,SAAgB,uBAAuB,CAAC,SAAiB;IACvD,IACE,SAAS;SACN,KAAK,CAAC,MAAM,CAAC;SACb,GAAG,CAAC,kBAAkB,CAAC;SACvB,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAChB;QACA,oEAAoE;QACpE,OAAO,IAAI,CAAC;KACb;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAXD,0DAWC;AAED,SAAgB,cAAc,CAAC,GAAW;IACxC,OAAO,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACrD,CAAC;AAFD,wCAEC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\nimport _ from 'lodash';\n\nfunction pascalCase(str: string): string {\n const camelCase = _.camelCase(str);\n return camelCase[0].toUpperCase() + camelCase.substr(1);\n}\n\nexport function isValidProjectName(name: string): boolean {\n if (name.match(/^[a-z][a-z0-9]*$/gi)) {\n return true;\n }\n return false;\n}\n\nexport function cleanName(str: string): string {\n str = str.replace('@', ''); // Remove '@' from package scope names\n str = str.slice(str.lastIndexOf('/') + 1); // Remove package scope\n str = pascalCase(str); // Convert to PascalCase\n return str;\n}\n\nexport function isValidProjectNamespace(namespace: string): boolean {\n if (\n namespace\n .split(/[.]+/)\n .map(isValidProjectName)\n .every(x => x)\n ) {\n // Validate that every part of the namespace is a valid project name\n return true;\n }\n return false;\n}\n\nexport function cleanNamespace(str: string): string {\n return str.split(/[.:]+/).map(cleanName).join('.');\n}\n"]}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ /**
7
+ * Displays a warning message about the Old Architecture template.
8
+ */
9
+ export declare function showOldArchitectureWarning(): void;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation.
4
+ * Licensed under the MIT License.
5
+ * @format
6
+ */
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.showOldArchitectureWarning = void 0;
12
+ const chalk_1 = __importDefault(require("chalk"));
13
+ /**
14
+ * Displays a warning message about the Old Architecture template.
15
+ */
16
+ function showOldArchitectureWarning() {
17
+ console.log(chalk_1.default.yellow(`⚠️ This project is using the React Native (for Windows) Old Architecture. The old architecture will begin to be removed starting with react-native-windows@0.82.0.`));
18
+ console.log();
19
+ console.log(chalk_1.default.cyan('💡 It is strongly recommended to move to the new architecture as soon as possible to take advantage of improved performance, long-term support, and modern capabilities.'));
20
+ console.log();
21
+ console.log(chalk_1.default.blue('🔗 Learn more: https://microsoft.github.io/react-native-windows/docs/new-architecture'));
22
+ console.log();
23
+ console.log(chalk_1.default.blue('🔗 View the list of properties not yet supported in Fabric: https://microsoft.github.io/react-native-windows/docs/new-arch-missingProps'));
24
+ console.log();
25
+ console.log(chalk_1.default.blue('💬 If you encounter missing properties, please open an issue: https://github.com/microsoft/react-native-windows/issues'));
26
+ console.log();
27
+ }
28
+ exports.showOldArchitectureWarning = showOldArchitectureWarning;
29
+ //# sourceMappingURL=oldArchWarning.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oldArchWarning.js","sourceRoot":"","sources":["../../src/utils/oldArchWarning.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;AAEH,kDAA0B;AAE1B;;GAEG;AACH,SAAgB,0BAA0B;IACxC,OAAO,CAAC,GAAG,CACT,eAAK,CAAC,MAAM,CACV,oKAAoK,CACrK,CACF,CAAC;IACF,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,OAAO,CAAC,GAAG,CACT,eAAK,CAAC,IAAI,CACR,0KAA0K,CAC3K,CACF,CAAC;IACF,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,OAAO,CAAC,GAAG,CACT,eAAK,CAAC,IAAI,CACR,uFAAuF,CACxF,CACF,CAAC;IACF,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,OAAO,CAAC,GAAG,CACT,eAAK,CAAC,IAAI,CACR,yIAAyI,CAC1I,CACF,CAAC;IACF,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,OAAO,CAAC,GAAG,CACT,eAAK,CAAC,IAAI,CACR,wHAAwH,CACzH,CACF,CAAC;IACF,OAAO,CAAC,GAAG,EAAE,CAAC;AAChB,CAAC;AA/BD,gEA+BC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\nimport chalk from 'chalk';\n\n/**\n * Displays a warning message about the Old Architecture template.\n */\nexport function showOldArchitectureWarning(): void {\n console.log(\n chalk.yellow(\n `⚠️ This project is using the React Native (for Windows) Old Architecture. The old architecture will begin to be removed starting with react-native-windows@0.82.0.`,\n ),\n );\n console.log();\n console.log(\n chalk.cyan(\n '💡 It is strongly recommended to move to the new architecture as soon as possible to take advantage of improved performance, long-term support, and modern capabilities.',\n ),\n );\n console.log();\n console.log(\n chalk.blue(\n '🔗 Learn more: https://microsoft.github.io/react-native-windows/docs/new-architecture',\n ),\n );\n console.log();\n console.log(\n chalk.blue(\n '🔗 View the list of properties not yet supported in Fabric: https://microsoft.github.io/react-native-windows/docs/new-arch-missingProps',\n ),\n );\n console.log();\n console.log(\n chalk.blue(\n '💬 If you encounter missing properties, please open an issue: https://github.com/microsoft/react-native-windows/issues',\n ),\n );\n console.log();\n}\n"]}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ export declare function resolveRnwRoot(paths: string | string[] | undefined): string;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation.
4
+ * Licensed under the MIT License.
5
+ * @format
6
+ */
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.resolveRnwRoot = void 0;
12
+ const path_1 = __importDefault(require("path"));
13
+ function resolveRnwRoot(paths) {
14
+ return path_1.default.dirname(require.resolve('react-native-windows/package.json', {
15
+ paths: typeof paths === 'string' ? [paths] : paths,
16
+ }));
17
+ }
18
+ exports.resolveRnwRoot = resolveRnwRoot;
19
+ //# sourceMappingURL=pathHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pathHelpers.js","sourceRoot":"","sources":["../../src/utils/pathHelpers.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;AAEH,gDAAwB;AAExB,SAAgB,cAAc,CAAC,KAAoC;IACjE,OAAO,cAAI,CAAC,OAAO,CACjB,OAAO,CAAC,OAAO,CAAC,mCAAmC,EAAE;QACnD,KAAK,EAAE,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK;KACnD,CAAC,CACH,CAAC;AACJ,CAAC;AAND,wCAMC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\nimport path from 'path';\n\nexport function resolveRnwRoot(paths: string | string[] | undefined): string {\n return path.dirname(\n require.resolve('react-native-windows/package.json', {\n paths: typeof paths === 'string' ? [paths] : paths,\n }),\n );\n}\n"]}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ import type { Config, CommandOption } from '@react-native-community/cli-types';
7
+ import { CommanderOptionsType, OptionSanitizer } from '@react-native-windows/telemetry';
8
+ /**
9
+ * Calculates a the default values of a given react-native CLI command's options.
10
+ * @param config Config passed from react-native CLI.
11
+ * @param commandOptions The options definition for the command.
12
+ * @returns The default options for the command.
13
+ */
14
+ export declare function getDefaultOptions(config: Config, commandOptions: CommandOption[]): CommanderOptionsType;
15
+ /**
16
+ * Sets up and starts the telemetry gathering for the CLI command.
17
+ * @param commandName The name of the CLI command.
18
+ * @param config Config passed from react-native CLI.
19
+ * @param options Options passed from react-native CLI.
20
+ * @param defaultOptions Default options for the command.
21
+ * @param optionSanitizer Function to sanitize the option values for telemetry.
22
+ */
23
+ export declare function startTelemetrySession(commandName: string, config: Config, options: CommanderOptionsType, defaultOptions: CommanderOptionsType, optionSanitizer: OptionSanitizer): Promise<void>;
24
+ /**
25
+ * Ends the gathering of telemetry for the CLI command.
26
+ * @param error The error (if any) thrown during the command.
27
+ * @param getExtraProps Function to get any extra command-specific telemetry properties.
28
+ */
29
+ export declare function endTelemetrySession(error?: Error, getExtraProps?: () => Promise<Record<string, any>>, finalOptions?: Record<string, any>, optionSanitizer?: (opts: Record<string, any>) => Record<string, any>): Promise<void>;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation.
4
+ * Licensed under the MIT License.
5
+ * @format
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.endTelemetrySession = exports.startTelemetrySession = exports.getDefaultOptions = void 0;
9
+ const lodash_1 = require("lodash");
10
+ const telemetry_1 = require("@react-native-windows/telemetry");
11
+ const commandWithProgress_1 = require("./commandWithProgress");
12
+ /**
13
+ * Calculates a the default values of a given react-native CLI command's options.
14
+ * @param config Config passed from react-native CLI.
15
+ * @param commandOptions The options definition for the command.
16
+ * @returns The default options for the command.
17
+ */
18
+ function getDefaultOptions(config, commandOptions) {
19
+ const result = {
20
+ logging: false,
21
+ };
22
+ for (const option of commandOptions) {
23
+ let key = option.name.startsWith('--')
24
+ ? option.name.slice('--'.length)
25
+ : option.name;
26
+ key = key.trim();
27
+ let value = option.default;
28
+ if (value !== undefined && value.name) {
29
+ value = value(config);
30
+ }
31
+ if (key.endsWith(' [string]')) {
32
+ // Option is a string
33
+ key = key.slice(0, -' [string]'.length);
34
+ // Option is a number
35
+ }
36
+ else if (key.endsWith(' [number]')) {
37
+ key = key.slice(0, -' [number]'.length);
38
+ }
39
+ else {
40
+ // Option is a boolean
41
+ // Note: Commander ignores the default property for booleans
42
+ if (key.startsWith('no-')) {
43
+ key = key.slice('no-'.length);
44
+ // Commander always defaults to true for flags that start with --no
45
+ value = true;
46
+ }
47
+ else {
48
+ // Commander always defaults to undefined for flags
49
+ value = undefined;
50
+ }
51
+ }
52
+ key = (0, lodash_1.camelCase)(key);
53
+ result[key] = value;
54
+ }
55
+ return result;
56
+ }
57
+ exports.getDefaultOptions = getDefaultOptions;
58
+ /**
59
+ * Sets up and starts the telemetry gathering for the CLI command.
60
+ * @param commandName The name of the CLI command.
61
+ * @param config Config passed from react-native CLI.
62
+ * @param options Options passed from react-native CLI.
63
+ * @param defaultOptions Default options for the command.
64
+ * @param optionSanitizer Function to sanitize the option values for telemetry.
65
+ */
66
+ async function startTelemetrySession(commandName, config, options, defaultOptions, optionSanitizer) {
67
+ const verbose = options.logging === true;
68
+ if (!options.telemetry) {
69
+ if (verbose) {
70
+ (0, commandWithProgress_1.newInfo)('Telemetry is disabled');
71
+ }
72
+ return;
73
+ }
74
+ if (verbose) {
75
+ (0, commandWithProgress_1.newInfo)(`Running ${(0, telemetry_1.nodeArchitecture)()} node on a ${(0, telemetry_1.deviceArchitecture)()} machine`);
76
+ }
77
+ if ((0, telemetry_1.deviceArchitecture)() !== (0, telemetry_1.nodeArchitecture)()) {
78
+ (0, commandWithProgress_1.newWarn)('This version of node was built for a different architecture than this machine and may cause unintended behavior');
79
+ }
80
+ await telemetry_1.Telemetry.setup();
81
+ const sanitizedOptions = (0, telemetry_1.commanderOptionsToOptions)(options, optionSanitizer);
82
+ const sanitizedDefaultOptions = (0, telemetry_1.commanderOptionsToOptions)(defaultOptions, optionSanitizer);
83
+ const sanitizedArgs = (0, telemetry_1.optionsToArgs)(sanitizedOptions, process.argv);
84
+ const startInfo = {
85
+ commandName,
86
+ args: sanitizedArgs,
87
+ options: sanitizedOptions,
88
+ defaultOptions: sanitizedDefaultOptions,
89
+ };
90
+ telemetry_1.Telemetry.startCommand(startInfo);
91
+ const projectInfo = await (0, telemetry_1.configToProjectInfo)(config);
92
+ if (projectInfo) {
93
+ telemetry_1.Telemetry.setProjectInfo(projectInfo);
94
+ }
95
+ const projectFile = (0, telemetry_1.getProjectFileFromConfig)(config);
96
+ if (projectFile) {
97
+ await telemetry_1.Telemetry.populateNuGetPackageVersions(projectFile);
98
+ }
99
+ }
100
+ exports.startTelemetrySession = startTelemetrySession;
101
+ /**
102
+ * Ends the gathering of telemetry for the CLI command.
103
+ * @param error The error (if any) thrown during the command.
104
+ * @param getExtraProps Function to get any extra command-specific telemetry properties.
105
+ */
106
+ async function endTelemetrySession(error, getExtraProps, finalOptions, optionSanitizer) {
107
+ if (!telemetry_1.Telemetry.isEnabled()) {
108
+ // Bail early so don't waste time here
109
+ return;
110
+ }
111
+ const endInfo = {
112
+ resultCode: 'Success',
113
+ };
114
+ if (error) {
115
+ endInfo.resultCode =
116
+ error instanceof telemetry_1.CodedError ? error.type : 'Unknown';
117
+ }
118
+ // Get extra properties
119
+ const extraProps = getExtraProps ? await getExtraProps() : undefined;
120
+ // Sanitize and attach finalOptions if provided
121
+ if (finalOptions && optionSanitizer) {
122
+ endInfo.finalOptions = optionSanitizer(finalOptions);
123
+ }
124
+ telemetry_1.Telemetry.endCommand(endInfo, extraProps);
125
+ }
126
+ exports.endTelemetrySession = endTelemetrySession;
127
+ //# sourceMappingURL=telemetryHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetryHelpers.js","sourceRoot":"","sources":["../../src/utils/telemetryHelpers.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,mCAAiC;AAQjC,+DAayC;AAEzC,+DAAuD;AAEvD;;;;;GAKG;AACH,SAAgB,iBAAiB,CAC/B,MAAc,EACd,cAA+B;IAE/B,MAAM,MAAM,GAAyB;QACnC,OAAO,EAAE,KAAK;KACf,CAAC;IACF,KAAK,MAAM,MAAM,IAAI,cAAc,EAAE;QACnC,IAAI,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC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,UAAU,mBAAmB,CACvC,KAAa,EACb,aAAkD,EAClD,YAAkC,EAClC,eAAoE;IAEpE,IAAI,CAAC,qBAAS,CAAC,SAAS,EAAE,EAAE;QAC1B,sCAAsC;QACtC,OAAO;KACR;IAED,MAAM,OAAO,GAAmB;QAC9B,UAAU,EAAE,SAAS;KACtB,CAAC;IAEF,IAAI,KAAK,EAAE;QACT,OAAO,CAAC,UAAU;YAChB,KAAK,YAAY,sBAAU,CAAC,CAAC,CAAE,KAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;KACxE;IAED,uBAAuB;IACvB,MAAM,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC,MAAM,aAAa,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAErE,+CAA+C;IAC/C,IAAI,YAAY,IAAI,eAAe,EAAE;QACnC,OAAO,CAAC,YAAY,GAAG,eAAe,CAAC,YAAY,CAAC,CAAC;KACtD;IAED,qBAAS,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AAC5C,CAAC;AA7BD,kDA6BC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\nimport {camelCase} from 'lodash';\n\nimport type {\n Config,\n CommandOption,\n OptionValue,\n} from '@react-native-community/cli-types';\n\nimport {\n Telemetry,\n CodedError,\n CommandStartInfo,\n CommandEndInfo,\n CommanderOptionsType,\n commanderOptionsToOptions,\n optionsToArgs,\n OptionSanitizer,\n configToProjectInfo,\n getProjectFileFromConfig,\n deviceArchitecture,\n nodeArchitecture,\n} from '@react-native-windows/telemetry';\n\nimport {newInfo, newWarn} from './commandWithProgress';\n\n/**\n * Calculates a the default values of a given react-native CLI command's options.\n * @param config Config passed from react-native CLI.\n * @param commandOptions The options definition for the command.\n * @returns The default options for the command.\n */\nexport function getDefaultOptions(\n config: Config,\n commandOptions: CommandOption[],\n): CommanderOptionsType {\n const result: CommanderOptionsType = {\n logging: false,\n };\n for (const option of commandOptions) {\n let key = option.name.startsWith('--')\n ? option.name.slice('--'.length)\n : option.name;\n key = key.trim();\n\n let value = option.default;\n if (value !== undefined && (value as (ctx: Config) => OptionValue).name) {\n value = (value as (ctx: Config) => OptionValue)(config);\n }\n\n if (key.endsWith(' [string]')) {\n // Option is a string\n key = key.slice(0, -' [string]'.length);\n // Option is a number\n } else if (key.endsWith(' [number]')) {\n key = key.slice(0, -' [number]'.length);\n } else {\n // Option is a boolean\n // Note: Commander ignores the default property for booleans\n if (key.startsWith('no-')) {\n key = key.slice('no-'.length);\n // Commander always defaults to true for flags that start with --no\n value = true;\n } else {\n // Commander always defaults to undefined for flags\n value = undefined;\n }\n }\n\n key = camelCase(key);\n result[key] = value;\n }\n return result;\n}\n\n/**\n * Sets up and starts the telemetry gathering for the CLI command.\n * @param commandName The name of the CLI command.\n * @param config Config passed from react-native CLI.\n * @param options Options passed from react-native CLI.\n * @param defaultOptions Default options for the command.\n * @param optionSanitizer Function to sanitize the option values for telemetry.\n */\nexport async function startTelemetrySession(\n commandName: string,\n config: Config,\n options: CommanderOptionsType,\n defaultOptions: CommanderOptionsType,\n optionSanitizer: OptionSanitizer,\n) {\n const verbose = options.logging === true;\n\n if (!options.telemetry) {\n if (verbose) {\n newInfo('Telemetry is disabled');\n }\n return;\n }\n\n if (verbose) {\n newInfo(\n `Running ${nodeArchitecture()} node on a ${deviceArchitecture()} machine`,\n );\n }\n\n if (deviceArchitecture() !== nodeArchitecture()) {\n newWarn(\n 'This version of node was built for a different architecture than this machine and may cause unintended behavior',\n );\n }\n\n await Telemetry.setup();\n\n const sanitizedOptions = commanderOptionsToOptions(options, optionSanitizer);\n const sanitizedDefaultOptions = commanderOptionsToOptions(\n defaultOptions,\n optionSanitizer,\n );\n const sanitizedArgs = optionsToArgs(sanitizedOptions, process.argv);\n\n const startInfo: CommandStartInfo = {\n commandName,\n args: sanitizedArgs,\n options: sanitizedOptions,\n defaultOptions: sanitizedDefaultOptions,\n };\n\n Telemetry.startCommand(startInfo);\n\n const projectInfo = await configToProjectInfo(config);\n if (projectInfo) {\n Telemetry.setProjectInfo(projectInfo);\n }\n\n const projectFile = getProjectFileFromConfig(config);\n if (projectFile) {\n await Telemetry.populateNuGetPackageVersions(projectFile);\n }\n}\n\n/**\n * Ends the gathering of telemetry for the CLI command.\n * @param error The error (if any) thrown during the command.\n * @param getExtraProps Function to get any extra command-specific telemetry properties.\n */\nexport async function endTelemetrySession(\n error?: Error,\n getExtraProps?: () => Promise<Record<string, any>>,\n finalOptions?: Record<string, any>,\n optionSanitizer?: (opts: Record<string, any>) => Record<string, any>,\n) {\n if (!Telemetry.isEnabled()) {\n // Bail early so don't waste time here\n return;\n }\n\n const endInfo: CommandEndInfo = {\n resultCode: 'Success',\n };\n\n if (error) {\n endInfo.resultCode =\n error instanceof CodedError ? (error as CodedError).type : 'Unknown';\n }\n\n // Get extra properties\n const extraProps = getExtraProps ? await getExtraProps() : undefined;\n\n // Sanitize and attach finalOptions if provided\n if (finalOptions && optionSanitizer) {\n endInfo.finalOptions = optionSanitizer(finalOptions);\n }\n\n Telemetry.endCommand(endInfo, extraProps);\n}\n"]}