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