@react-native-windows/cli 0.73.2 → 0.74.0-preview.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/lib-commonjs/commands/autolinkWindows/autolinkWindows.d.ts +87 -87
  2. package/lib-commonjs/commands/autolinkWindows/autolinkWindows.js +654 -654
  3. package/lib-commonjs/commands/autolinkWindows/autolinkWindowsOptions.d.ts +14 -14
  4. package/lib-commonjs/commands/autolinkWindows/autolinkWindowsOptions.js +32 -32
  5. package/lib-commonjs/commands/codegenWindows/codegenWindows.d.ts +27 -27
  6. package/lib-commonjs/commands/codegenWindows/codegenWindows.js +205 -205
  7. package/lib-commonjs/commands/codegenWindows/codegenWindowsOptions.d.ts +12 -12
  8. package/lib-commonjs/commands/codegenWindows/codegenWindowsOptions.js +22 -22
  9. package/lib-commonjs/commands/config/configUtils.d.ts +123 -123
  10. package/lib-commonjs/commands/config/configUtils.js +380 -380
  11. package/lib-commonjs/commands/config/dependencyConfig.d.ts +37 -37
  12. package/lib-commonjs/commands/config/dependencyConfig.js +227 -227
  13. package/lib-commonjs/commands/config/projectConfig.d.ts +27 -27
  14. package/lib-commonjs/commands/config/projectConfig.js +180 -180
  15. package/lib-commonjs/commands/healthCheck/healthCheckList.d.ts +6 -6
  16. package/lib-commonjs/commands/healthCheck/healthCheckList.js +20 -20
  17. package/lib-commonjs/commands/healthCheck/healthCheckList.js.map +1 -1
  18. package/lib-commonjs/commands/healthCheck/healthChecks.d.ts +7 -7
  19. package/lib-commonjs/commands/healthCheck/healthChecks.js +123 -123
  20. package/lib-commonjs/commands/initWindows/initWindows.d.ts +46 -46
  21. package/lib-commonjs/commands/initWindows/initWindows.js +243 -243
  22. package/lib-commonjs/commands/initWindows/initWindowsOptions.d.ts +15 -15
  23. package/lib-commonjs/commands/initWindows/initWindowsOptions.js +37 -37
  24. package/lib-commonjs/commands/runWindows/runWindows.d.ts +10 -10
  25. package/lib-commonjs/commands/runWindows/runWindows.js +321 -321
  26. package/lib-commonjs/commands/runWindows/runWindowsOptions.d.ts +56 -56
  27. package/lib-commonjs/commands/runWindows/runWindowsOptions.js +132 -132
  28. package/lib-commonjs/e2etest/autolink.test.d.ts +6 -6
  29. package/lib-commonjs/e2etest/autolink.test.js +366 -366
  30. package/lib-commonjs/e2etest/dependencyConfig.test.d.ts +6 -6
  31. package/lib-commonjs/e2etest/dependencyConfig.test.js +129 -129
  32. package/lib-commonjs/e2etest/healthChecks.test.d.ts +6 -6
  33. package/lib-commonjs/e2etest/healthChecks.test.js +30 -30
  34. package/lib-commonjs/e2etest/initWindows.test.d.ts +6 -6
  35. package/lib-commonjs/e2etest/initWindows.test.js +42 -42
  36. package/lib-commonjs/e2etest/projectConfig.test.d.ts +6 -6
  37. package/lib-commonjs/e2etest/projectConfig.test.js +110 -110
  38. package/lib-commonjs/e2etest/projectConfig.utils.d.ts +8 -8
  39. package/lib-commonjs/e2etest/projectConfig.utils.js +76 -76
  40. package/lib-commonjs/e2etest/runWindows.test.d.ts +6 -6
  41. package/lib-commonjs/e2etest/runWindows.test.js +60 -60
  42. package/lib-commonjs/e2etest/typesUpToDate.test.d.ts +6 -0
  43. package/lib-commonjs/e2etest/typesUpToDate.test.js +21 -0
  44. package/lib-commonjs/e2etest/typesUpToDate.test.js.map +1 -0
  45. package/lib-commonjs/generator-common/index.d.ts +39 -39
  46. package/lib-commonjs/generator-common/index.js +242 -242
  47. package/lib-commonjs/generator-windows/index.d.ts +10 -10
  48. package/lib-commonjs/generator-windows/index.js +316 -316
  49. package/lib-commonjs/index.d.ts +50 -50
  50. package/lib-commonjs/index.js +77 -77
  51. package/lib-commonjs/utils/build.d.ts +12 -12
  52. package/lib-commonjs/utils/build.js +84 -84
  53. package/lib-commonjs/utils/checkRequirements.d.ts +6 -6
  54. package/lib-commonjs/utils/checkRequirements.js +69 -69
  55. package/lib-commonjs/utils/commandWithProgress.d.ts +21 -21
  56. package/lib-commonjs/utils/commandWithProgress.js +149 -149
  57. package/lib-commonjs/utils/deploy.d.ts +12 -12
  58. package/lib-commonjs/utils/deploy.js +353 -353
  59. package/lib-commonjs/utils/info.d.ts +6 -6
  60. package/lib-commonjs/utils/info.js +28 -28
  61. package/lib-commonjs/utils/msbuildtools.d.ts +28 -28
  62. package/lib-commonjs/utils/msbuildtools.js +273 -273
  63. package/lib-commonjs/utils/msbuildtools.js.map +1 -1
  64. package/lib-commonjs/utils/pathHelpers.d.ts +9 -9
  65. package/lib-commonjs/utils/pathHelpers.js +36 -36
  66. package/lib-commonjs/utils/telemetryHelpers.d.ts +29 -29
  67. package/lib-commonjs/utils/telemetryHelpers.js +120 -120
  68. package/lib-commonjs/utils/version.d.ts +19 -19
  69. package/lib-commonjs/utils/version.js +109 -109
  70. package/lib-commonjs/utils/vsInstalls.d.ts +34 -34
  71. package/lib-commonjs/utils/vsInstalls.js +99 -99
  72. package/lib-commonjs/utils/vstools.d.ts +16 -16
  73. package/lib-commonjs/utils/vstools.js +189 -189
  74. package/lib-commonjs/utils/winappdeploytool.d.ts +24 -24
  75. package/lib-commonjs/utils/winappdeploytool.js +108 -108
  76. package/package.json +16 -16
@@ -1,381 +1,381 @@
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.getExperimentalFeatures = exports.getProjectGuid = exports.getProjectNamespace = exports.getProjectName = exports.getProjectType = exports.getOutputType = exports.getConfigurationType = exports.importProjectExists = exports.findPropertyValue = exports.tryFindPropertyValueAsBoolean = exports.tryFindPropertyValue = exports.readProjectFile = exports.getProjectLanguage = exports.findAppProjectFiles = exports.findDependencyProjectFiles = exports.isRnwDependencyProject = exports.findSolutionFiles = exports.isRnwSolution = exports.findWindowsFolder = exports.findFiles = void 0;
12
- const fs_1 = __importDefault(require("@react-native-windows/fs"));
13
- const path_1 = __importDefault(require("path"));
14
- const glob_1 = __importDefault(require("glob"));
15
- const xmldom_1 = require("@xmldom/xmldom");
16
- const xpath_1 = __importDefault(require("xpath"));
17
- const telemetry_1 = require("@react-native-windows/telemetry");
18
- const msbuildSelect = xpath_1.default.useNamespaces({
19
- msbuild: 'http://schemas.microsoft.com/developer/msbuild/2003',
20
- });
21
- /**
22
- * Search for files matching the pattern under the target folder.
23
- * @param folder The absolute path to target folder.
24
- * @param filenamePattern The pattern to search for.
25
- * @return Return the array of relative file paths.
26
- */
27
- function findFiles(folder, filenamePattern) {
28
- const files = glob_1.default.sync(path_1.default.join('**', filenamePattern), {
29
- cwd: folder,
30
- ignore: [
31
- 'node_modules/**',
32
- '**/Debug/**',
33
- '**/Release/**',
34
- '**/Generated Files/**',
35
- '**/packages/**',
36
- ],
37
- });
38
- return files;
39
- }
40
- exports.findFiles = findFiles;
41
- /**
42
- * Search for the windows sub-folder under the target folder.
43
- * @param folder The absolute path to the target folder.
44
- * @return The absolute path to the windows folder, if it exists.
45
- */
46
- function findWindowsFolder(folder) {
47
- const winDir = 'windows';
48
- const joinedDir = path_1.default.join(folder, winDir);
49
- if (fs_1.default.existsSync(joinedDir)) {
50
- return joinedDir;
51
- }
52
- return null;
53
- }
54
- exports.findWindowsFolder = findWindowsFolder;
55
- /**
56
- * Checks if the target file path is a RNW solution file by checking if it contains the string "ReactNative".
57
- * @param filePath The absolute file path to check.
58
- * @return Whether the path is to a RNW solution file.
59
- */
60
- function isRnwSolution(filePath) {
61
- return (fs_1.default
62
- .readFileSync(filePath)
63
- .toString()
64
- .search(/ReactNative/) > 0);
65
- }
66
- exports.isRnwSolution = isRnwSolution;
67
- /**
68
- * Search for the RNW solution files under the target folder.
69
- * @param winFolder The absolute path to target folder.
70
- * @return Return the array of relative file paths.
71
- */
72
- function findSolutionFiles(winFolder) {
73
- // First search for all potential solution files
74
- const allSolutions = findFiles(winFolder, '*.sln');
75
- if (allSolutions.length === 0) {
76
- // If there're no solution files, return 0
77
- return [];
78
- }
79
- else if (allSolutions.length === 1) {
80
- // If there is exactly one solution file, assume it's it
81
- return [allSolutions[0]];
82
- }
83
- const solutionFiles = [];
84
- // Try to find any solution file that appears to be a React Native solution
85
- for (const solutionFile of allSolutions) {
86
- if (isRnwSolution(path_1.default.join(winFolder, solutionFile))) {
87
- solutionFiles.push(path_1.default.normalize(solutionFile));
88
- }
89
- }
90
- return solutionFiles;
91
- }
92
- exports.findSolutionFiles = findSolutionFiles;
93
- /**
94
- * Checks if the target file path is a RNW lib project file.
95
- * @param filePath The absolute file path to check.
96
- * @return Whether the path is to a RNW lib project file.
97
- */
98
- function isRnwDependencyProject(filePath) {
99
- const projectContents = readProjectFile(filePath);
100
- const projectLang = getProjectLanguage(filePath);
101
- if (projectLang === 'cs') {
102
- return importProjectExists(projectContents, 'Microsoft.ReactNative.Uwp.CSharpLib.targets');
103
- }
104
- else if (projectLang === 'cpp') {
105
- return (importProjectExists(projectContents, 'Microsoft.ReactNative.Uwp.CppLib.targets') ||
106
- importProjectExists(projectContents, 'Microsoft.ReactNative.Composition.CppLib.targets'));
107
- }
108
- return false;
109
- }
110
- exports.isRnwDependencyProject = isRnwDependencyProject;
111
- /**
112
- * Search for the RNW lib project files under the target folder.
113
- * @param winFolder The absolute path to target folder.
114
- * @return Return the array of relative file paths.
115
- */
116
- function findDependencyProjectFiles(winFolder) {
117
- // First, search for all potential project files
118
- const allCppProj = findFiles(winFolder, '*.vcxproj');
119
- const allCsProj = findFiles(winFolder, '*.csproj');
120
- const allProjects = allCppProj.concat(allCsProj);
121
- if (allProjects.length === 0) {
122
- // If there're no project files, return 0
123
- return [];
124
- }
125
- const dependencyProjectFiles = [];
126
- // Try to find any project file that appears to be a dependency project
127
- for (const projectFile of allProjects) {
128
- // A project is marked as a RNW dependency iff either:
129
- // - If the project has the standard native module imports, or
130
- // - If we only have a single project (and it doesn't have the standard native module imports),
131
- // pick it and hope for the best. This enables autolinking for modules that were written
132
- // before the standard native module template existed.
133
- if (allProjects.length === 1 ||
134
- isRnwDependencyProject(path_1.default.join(winFolder, projectFile))) {
135
- dependencyProjectFiles.push(path_1.default.normalize(projectFile));
136
- }
137
- }
138
- return dependencyProjectFiles;
139
- }
140
- exports.findDependencyProjectFiles = findDependencyProjectFiles;
141
- function getReactNativeProjectType(value) {
142
- switch (value) {
143
- case 'App-WinAppSDK':
144
- return value;
145
- default:
146
- return 'unknown';
147
- }
148
- }
149
- /**
150
- * Checks if the target file path is a RNW app project file.
151
- * @param filePath The absolute file path to check.
152
- * @return Whether the path is to a RNW app project file.
153
- */
154
- function isRnwAppProject(filePath) {
155
- const projectContents = readProjectFile(filePath);
156
- const rnProjectType = getReactNativeProjectType(tryFindPropertyValue(projectContents, 'ReactNativeProjectType'));
157
- if (rnProjectType !== 'unknown') {
158
- return true;
159
- }
160
- const projectLang = getProjectLanguage(filePath);
161
- if (projectLang === 'cs') {
162
- return importProjectExists(projectContents, 'Microsoft.ReactNative.Uwp.CSharpApp.targets');
163
- }
164
- else if (projectLang === 'cpp') {
165
- return (importProjectExists(projectContents, 'Microsoft.ReactNative.Uwp.CppApp.targets') ||
166
- importProjectExists(projectContents, 'Microsoft.ReactNative.Composition.CppApp.targets'));
167
- }
168
- return false;
169
- }
170
- /**
171
- * Search for the RNW app project files under the target folder.
172
- * @param winFolder The absolute path to target folder.
173
- * @return Return the array of relative file paths.
174
- */
175
- function findAppProjectFiles(winFolder) {
176
- // First, search for all potential project files
177
- const allCppProj = findFiles(winFolder, '*.vcxproj');
178
- const allCsProj = findFiles(winFolder, '*.csproj');
179
- const allProjects = allCppProj.concat(allCsProj);
180
- if (allProjects.length === 0) {
181
- // If there're no project files, return 0
182
- return [];
183
- }
184
- const appProjectFiles = [];
185
- // Try to find any project file that appears to be an app project
186
- for (const projectFile of allProjects) {
187
- if (isRnwAppProject(path_1.default.join(winFolder, projectFile))) {
188
- appProjectFiles.push(path_1.default.normalize(projectFile));
189
- }
190
- }
191
- return appProjectFiles;
192
- }
193
- exports.findAppProjectFiles = findAppProjectFiles;
194
- /**
195
- * Returns the programming language of the project file.
196
- * @param projectPath The project file path to check.
197
- * @return The language string: cpp, cs, or null if unknown.
198
- */
199
- function getProjectLanguage(projectPath) {
200
- if (projectPath.endsWith('.vcxproj')) {
201
- return 'cpp';
202
- }
203
- else if (projectPath.endsWith('.csproj')) {
204
- return 'cs';
205
- }
206
- return null;
207
- }
208
- exports.getProjectLanguage = getProjectLanguage;
209
- /**
210
- * Reads in the contents of the target project file.
211
- * @param projectPath The target project file path.
212
- * @return The project file contents.
213
- */
214
- function readProjectFile(projectPath) {
215
- const projectContents = fs_1.default.readFileSync(projectPath, 'utf8').toString();
216
- return new xmldom_1.DOMParser().parseFromString(projectContents, 'application/xml');
217
- }
218
- exports.readProjectFile = readProjectFile;
219
- /**
220
- * Search for the given property in the project contents and return its value.
221
- * @param projectContents The XML project contents.
222
- * @param propertyName The property to look for.
223
- * @return The value of the tag if it exists.
224
- */
225
- function tryFindPropertyValue(projectContents, propertyName) {
226
- const nodes = msbuildSelect(`//msbuild:PropertyGroup/msbuild:${propertyName}`, projectContents);
227
- if (nodes.length > 0) {
228
- // Take the last one
229
- return nodes[nodes.length - 1].textContent;
230
- }
231
- else {
232
- const noNamespaceNodes = xpath_1.default.select(`//PropertyGroup/${propertyName}`, projectContents);
233
- if (noNamespaceNodes.length > 0) {
234
- return noNamespaceNodes[noNamespaceNodes.length - 1]
235
- .textContent;
236
- }
237
- }
238
- return null;
239
- }
240
- exports.tryFindPropertyValue = tryFindPropertyValue;
241
- /**
242
- * Search for the given property in the project contents and return its value.
243
- * @param projectContents The XML project contents.
244
- * @param propertyName The property to look for.
245
- * @return The value of the tag if it exists.
246
- */
247
- function tryFindPropertyValueAsBoolean(projectContents, propertyName) {
248
- const rawValue = tryFindPropertyValue(projectContents, propertyName);
249
- switch (rawValue) {
250
- case 'true':
251
- return true;
252
- case 'false':
253
- return false;
254
- default:
255
- return null;
256
- }
257
- }
258
- exports.tryFindPropertyValueAsBoolean = tryFindPropertyValueAsBoolean;
259
- function findPropertyValue(projectContents, propertyName, filePath) {
260
- const res = tryFindPropertyValue(projectContents, propertyName);
261
- if (!res) {
262
- throw new telemetry_1.CodedError('NoPropertyInProject', `Couldn't find property ${propertyName} from ${filePath}`, { propertyName: propertyName });
263
- }
264
- return res;
265
- }
266
- exports.findPropertyValue = findPropertyValue;
267
- /**
268
- * Search for the given import project in the project contents and return if it exists.
269
- * @param projectContents The XML project contents.
270
- * @param projectName The project to look for.
271
- * @return If the target exists.
272
- */
273
- function importProjectExists(projectContents, projectName) {
274
- const nodes = msbuildSelect(`//msbuild:Import[contains(@Project,'${projectName}')]`, projectContents);
275
- return nodes.length > 0;
276
- }
277
- exports.importProjectExists = importProjectExists;
278
- /**
279
- * Gets the configuration type of the project from the project contents.
280
- * @param projectContents The XML project contents.
281
- * @return The project configuration type.
282
- */
283
- function getConfigurationType(projectContents) {
284
- var _a;
285
- const configurationType = (_a = tryFindPropertyValue(projectContents, 'ConfigurationType')) === null || _a === void 0 ? void 0 : _a.toLowerCase();
286
- switch (configurationType) {
287
- case 'application':
288
- case 'dynamiclibrary':
289
- case 'generic':
290
- case 'staticlibrary':
291
- return configurationType;
292
- default:
293
- return 'unknown';
294
- }
295
- }
296
- exports.getConfigurationType = getConfigurationType;
297
- /**
298
- * Gets the output type of the project from the project contents.
299
- * @param projectContents The XML project contents.
300
- * @return The project output type.
301
- */
302
- function getOutputType(projectContents) {
303
- var _a;
304
- const outputType = (_a = tryFindPropertyValue(projectContents, 'OutputType')) === null || _a === void 0 ? void 0 : _a.toLowerCase();
305
- switch (outputType) {
306
- case 'appcontainerexe':
307
- case 'exe':
308
- case 'library':
309
- case 'module':
310
- case 'winexe':
311
- case 'winmdobj':
312
- return outputType;
313
- default:
314
- return 'unknown';
315
- }
316
- }
317
- exports.getOutputType = getOutputType;
318
- /**
319
- * Gets the type of the project from the project contents.
320
- * @param projectPath The project file path to check.
321
- * @param projectContents The XML project contents.
322
- * @return The project type.
323
- */
324
- function getProjectType(projectPath, projectContents) {
325
- switch (getProjectLanguage(projectPath)) {
326
- case 'cpp':
327
- return getConfigurationType(projectContents);
328
- case 'cs':
329
- return getOutputType(projectContents);
330
- default:
331
- return 'unknown';
332
- }
333
- }
334
- exports.getProjectType = getProjectType;
335
- /**
336
- * Gets the name of the project from the project contents.
337
- * @param projectPath The project file path to check.
338
- * @param projectContents The XML project contents.
339
- * @return The project name.
340
- */
341
- function getProjectName(projectPath, projectContents) {
342
- const name = tryFindPropertyValue(projectContents, 'ProjectName') ||
343
- path_1.default.parse(projectPath).name ||
344
- '';
345
- return name;
346
- }
347
- exports.getProjectName = getProjectName;
348
- /**
349
- * Gets the namespace of the project from the project contents.
350
- * @param projectContents The XML project contents.
351
- * @return The project namespace.
352
- */
353
- function getProjectNamespace(projectContents) {
354
- return tryFindPropertyValue(projectContents, 'RootNamespace');
355
- }
356
- exports.getProjectNamespace = getProjectNamespace;
357
- /**
358
- * Gets the guid of the project from the project contents.
359
- * @param projectContents The XML project contents.
360
- * @return The project guid.
361
- */
362
- function getProjectGuid(projectContents) {
363
- return tryFindPropertyValue(projectContents, 'ProjectGuid');
364
- }
365
- exports.getProjectGuid = getProjectGuid;
366
- function getExperimentalFeatures(solutionDir) {
367
- const propsFile = path_1.default.join(solutionDir, 'ExperimentalFeatures.props');
368
- if (!fs_1.default.existsSync(propsFile)) {
369
- return undefined;
370
- }
371
- const result = {};
372
- const propsContents = readProjectFile(propsFile);
373
- const nodes = msbuildSelect(`//msbuild:PropertyGroup/msbuild:*`, propsContents);
374
- for (const node of nodes) {
375
- const propertyNode = node;
376
- result[propertyNode.nodeName] = propertyNode.textContent;
377
- }
378
- return result;
379
- }
380
- exports.getExperimentalFeatures = getExperimentalFeatures;
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.getExperimentalFeatures = exports.getProjectGuid = exports.getProjectNamespace = exports.getProjectName = exports.getProjectType = exports.getOutputType = exports.getConfigurationType = exports.importProjectExists = exports.findPropertyValue = exports.tryFindPropertyValueAsBoolean = exports.tryFindPropertyValue = exports.readProjectFile = exports.getProjectLanguage = exports.findAppProjectFiles = exports.findDependencyProjectFiles = exports.isRnwDependencyProject = exports.findSolutionFiles = exports.isRnwSolution = exports.findWindowsFolder = exports.findFiles = void 0;
12
+ const fs_1 = __importDefault(require("@react-native-windows/fs"));
13
+ const path_1 = __importDefault(require("path"));
14
+ const glob_1 = __importDefault(require("glob"));
15
+ const xmldom_1 = require("@xmldom/xmldom");
16
+ const xpath_1 = __importDefault(require("xpath"));
17
+ const telemetry_1 = require("@react-native-windows/telemetry");
18
+ const msbuildSelect = xpath_1.default.useNamespaces({
19
+ msbuild: 'http://schemas.microsoft.com/developer/msbuild/2003',
20
+ });
21
+ /**
22
+ * Search for files matching the pattern under the target folder.
23
+ * @param folder The absolute path to target folder.
24
+ * @param filenamePattern The pattern to search for.
25
+ * @return Return the array of relative file paths.
26
+ */
27
+ function findFiles(folder, filenamePattern) {
28
+ const files = glob_1.default.sync(path_1.default.join('**', filenamePattern), {
29
+ cwd: folder,
30
+ ignore: [
31
+ 'node_modules/**',
32
+ '**/Debug/**',
33
+ '**/Release/**',
34
+ '**/Generated Files/**',
35
+ '**/packages/**',
36
+ ],
37
+ });
38
+ return files;
39
+ }
40
+ exports.findFiles = findFiles;
41
+ /**
42
+ * Search for the windows sub-folder under the target folder.
43
+ * @param folder The absolute path to the target folder.
44
+ * @return The absolute path to the windows folder, if it exists.
45
+ */
46
+ function findWindowsFolder(folder) {
47
+ const winDir = 'windows';
48
+ const joinedDir = path_1.default.join(folder, winDir);
49
+ if (fs_1.default.existsSync(joinedDir)) {
50
+ return joinedDir;
51
+ }
52
+ return null;
53
+ }
54
+ exports.findWindowsFolder = findWindowsFolder;
55
+ /**
56
+ * Checks if the target file path is a RNW solution file by checking if it contains the string "ReactNative".
57
+ * @param filePath The absolute file path to check.
58
+ * @return Whether the path is to a RNW solution file.
59
+ */
60
+ function isRnwSolution(filePath) {
61
+ return (fs_1.default
62
+ .readFileSync(filePath)
63
+ .toString()
64
+ .search(/ReactNative/) > 0);
65
+ }
66
+ exports.isRnwSolution = isRnwSolution;
67
+ /**
68
+ * Search for the RNW solution files under the target folder.
69
+ * @param winFolder The absolute path to target folder.
70
+ * @return Return the array of relative file paths.
71
+ */
72
+ function findSolutionFiles(winFolder) {
73
+ // First search for all potential solution files
74
+ const allSolutions = findFiles(winFolder, '*.sln');
75
+ if (allSolutions.length === 0) {
76
+ // If there're no solution files, return 0
77
+ return [];
78
+ }
79
+ else if (allSolutions.length === 1) {
80
+ // If there is exactly one solution file, assume it's it
81
+ return [allSolutions[0]];
82
+ }
83
+ const solutionFiles = [];
84
+ // Try to find any solution file that appears to be a React Native solution
85
+ for (const solutionFile of allSolutions) {
86
+ if (isRnwSolution(path_1.default.join(winFolder, solutionFile))) {
87
+ solutionFiles.push(path_1.default.normalize(solutionFile));
88
+ }
89
+ }
90
+ return solutionFiles;
91
+ }
92
+ exports.findSolutionFiles = findSolutionFiles;
93
+ /**
94
+ * Checks if the target file path is a RNW lib project file.
95
+ * @param filePath The absolute file path to check.
96
+ * @return Whether the path is to a RNW lib project file.
97
+ */
98
+ function isRnwDependencyProject(filePath) {
99
+ const projectContents = readProjectFile(filePath);
100
+ const projectLang = getProjectLanguage(filePath);
101
+ if (projectLang === 'cs') {
102
+ return importProjectExists(projectContents, 'Microsoft.ReactNative.Uwp.CSharpLib.targets');
103
+ }
104
+ else if (projectLang === 'cpp') {
105
+ return (importProjectExists(projectContents, 'Microsoft.ReactNative.Uwp.CppLib.targets') ||
106
+ importProjectExists(projectContents, 'Microsoft.ReactNative.Composition.CppLib.targets'));
107
+ }
108
+ return false;
109
+ }
110
+ exports.isRnwDependencyProject = isRnwDependencyProject;
111
+ /**
112
+ * Search for the RNW lib project files under the target folder.
113
+ * @param winFolder The absolute path to target folder.
114
+ * @return Return the array of relative file paths.
115
+ */
116
+ function findDependencyProjectFiles(winFolder) {
117
+ // First, search for all potential project files
118
+ const allCppProj = findFiles(winFolder, '*.vcxproj');
119
+ const allCsProj = findFiles(winFolder, '*.csproj');
120
+ const allProjects = allCppProj.concat(allCsProj);
121
+ if (allProjects.length === 0) {
122
+ // If there're no project files, return 0
123
+ return [];
124
+ }
125
+ const dependencyProjectFiles = [];
126
+ // Try to find any project file that appears to be a dependency project
127
+ for (const projectFile of allProjects) {
128
+ // A project is marked as a RNW dependency iff either:
129
+ // - If the project has the standard native module imports, or
130
+ // - If we only have a single project (and it doesn't have the standard native module imports),
131
+ // pick it and hope for the best. This enables autolinking for modules that were written
132
+ // before the standard native module template existed.
133
+ if (allProjects.length === 1 ||
134
+ isRnwDependencyProject(path_1.default.join(winFolder, projectFile))) {
135
+ dependencyProjectFiles.push(path_1.default.normalize(projectFile));
136
+ }
137
+ }
138
+ return dependencyProjectFiles;
139
+ }
140
+ exports.findDependencyProjectFiles = findDependencyProjectFiles;
141
+ function getReactNativeProjectType(value) {
142
+ switch (value) {
143
+ case 'App-WinAppSDK':
144
+ return value;
145
+ default:
146
+ return 'unknown';
147
+ }
148
+ }
149
+ /**
150
+ * Checks if the target file path is a RNW app project file.
151
+ * @param filePath The absolute file path to check.
152
+ * @return Whether the path is to a RNW app project file.
153
+ */
154
+ function isRnwAppProject(filePath) {
155
+ const projectContents = readProjectFile(filePath);
156
+ const rnProjectType = getReactNativeProjectType(tryFindPropertyValue(projectContents, 'ReactNativeProjectType'));
157
+ if (rnProjectType !== 'unknown') {
158
+ return true;
159
+ }
160
+ const projectLang = getProjectLanguage(filePath);
161
+ if (projectLang === 'cs') {
162
+ return importProjectExists(projectContents, 'Microsoft.ReactNative.Uwp.CSharpApp.targets');
163
+ }
164
+ else if (projectLang === 'cpp') {
165
+ return (importProjectExists(projectContents, 'Microsoft.ReactNative.Uwp.CppApp.targets') ||
166
+ importProjectExists(projectContents, 'Microsoft.ReactNative.Composition.CppApp.targets'));
167
+ }
168
+ return false;
169
+ }
170
+ /**
171
+ * Search for the RNW app project files under the target folder.
172
+ * @param winFolder The absolute path to target folder.
173
+ * @return Return the array of relative file paths.
174
+ */
175
+ function findAppProjectFiles(winFolder) {
176
+ // First, search for all potential project files
177
+ const allCppProj = findFiles(winFolder, '*.vcxproj');
178
+ const allCsProj = findFiles(winFolder, '*.csproj');
179
+ const allProjects = allCppProj.concat(allCsProj);
180
+ if (allProjects.length === 0) {
181
+ // If there're no project files, return 0
182
+ return [];
183
+ }
184
+ const appProjectFiles = [];
185
+ // Try to find any project file that appears to be an app project
186
+ for (const projectFile of allProjects) {
187
+ if (isRnwAppProject(path_1.default.join(winFolder, projectFile))) {
188
+ appProjectFiles.push(path_1.default.normalize(projectFile));
189
+ }
190
+ }
191
+ return appProjectFiles;
192
+ }
193
+ exports.findAppProjectFiles = findAppProjectFiles;
194
+ /**
195
+ * Returns the programming language of the project file.
196
+ * @param projectPath The project file path to check.
197
+ * @return The language string: cpp, cs, or null if unknown.
198
+ */
199
+ function getProjectLanguage(projectPath) {
200
+ if (projectPath.endsWith('.vcxproj')) {
201
+ return 'cpp';
202
+ }
203
+ else if (projectPath.endsWith('.csproj')) {
204
+ return 'cs';
205
+ }
206
+ return null;
207
+ }
208
+ exports.getProjectLanguage = getProjectLanguage;
209
+ /**
210
+ * Reads in the contents of the target project file.
211
+ * @param projectPath The target project file path.
212
+ * @return The project file contents.
213
+ */
214
+ function readProjectFile(projectPath) {
215
+ const projectContents = fs_1.default.readFileSync(projectPath, 'utf8').toString();
216
+ return new xmldom_1.DOMParser().parseFromString(projectContents, 'application/xml');
217
+ }
218
+ exports.readProjectFile = readProjectFile;
219
+ /**
220
+ * Search for the given property in the project contents and return its value.
221
+ * @param projectContents The XML project contents.
222
+ * @param propertyName The property to look for.
223
+ * @return The value of the tag if it exists.
224
+ */
225
+ function tryFindPropertyValue(projectContents, propertyName) {
226
+ const nodes = msbuildSelect(`//msbuild:PropertyGroup/msbuild:${propertyName}`, projectContents);
227
+ if (nodes.length > 0) {
228
+ // Take the last one
229
+ return nodes[nodes.length - 1].textContent;
230
+ }
231
+ else {
232
+ const noNamespaceNodes = xpath_1.default.select(`//PropertyGroup/${propertyName}`, projectContents);
233
+ if (noNamespaceNodes.length > 0) {
234
+ return noNamespaceNodes[noNamespaceNodes.length - 1]
235
+ .textContent;
236
+ }
237
+ }
238
+ return null;
239
+ }
240
+ exports.tryFindPropertyValue = tryFindPropertyValue;
241
+ /**
242
+ * Search for the given property in the project contents and return its value.
243
+ * @param projectContents The XML project contents.
244
+ * @param propertyName The property to look for.
245
+ * @return The value of the tag if it exists.
246
+ */
247
+ function tryFindPropertyValueAsBoolean(projectContents, propertyName) {
248
+ const rawValue = tryFindPropertyValue(projectContents, propertyName);
249
+ switch (rawValue) {
250
+ case 'true':
251
+ return true;
252
+ case 'false':
253
+ return false;
254
+ default:
255
+ return null;
256
+ }
257
+ }
258
+ exports.tryFindPropertyValueAsBoolean = tryFindPropertyValueAsBoolean;
259
+ function findPropertyValue(projectContents, propertyName, filePath) {
260
+ const res = tryFindPropertyValue(projectContents, propertyName);
261
+ if (!res) {
262
+ throw new telemetry_1.CodedError('NoPropertyInProject', `Couldn't find property ${propertyName} from ${filePath}`, { propertyName: propertyName });
263
+ }
264
+ return res;
265
+ }
266
+ exports.findPropertyValue = findPropertyValue;
267
+ /**
268
+ * Search for the given import project in the project contents and return if it exists.
269
+ * @param projectContents The XML project contents.
270
+ * @param projectName The project to look for.
271
+ * @return If the target exists.
272
+ */
273
+ function importProjectExists(projectContents, projectName) {
274
+ const nodes = msbuildSelect(`//msbuild:Import[contains(@Project,'${projectName}')]`, projectContents);
275
+ return nodes.length > 0;
276
+ }
277
+ exports.importProjectExists = importProjectExists;
278
+ /**
279
+ * Gets the configuration type of the project from the project contents.
280
+ * @param projectContents The XML project contents.
281
+ * @return The project configuration type.
282
+ */
283
+ function getConfigurationType(projectContents) {
284
+ var _a;
285
+ const configurationType = (_a = tryFindPropertyValue(projectContents, 'ConfigurationType')) === null || _a === void 0 ? void 0 : _a.toLowerCase();
286
+ switch (configurationType) {
287
+ case 'application':
288
+ case 'dynamiclibrary':
289
+ case 'generic':
290
+ case 'staticlibrary':
291
+ return configurationType;
292
+ default:
293
+ return 'unknown';
294
+ }
295
+ }
296
+ exports.getConfigurationType = getConfigurationType;
297
+ /**
298
+ * Gets the output type of the project from the project contents.
299
+ * @param projectContents The XML project contents.
300
+ * @return The project output type.
301
+ */
302
+ function getOutputType(projectContents) {
303
+ var _a;
304
+ const outputType = (_a = tryFindPropertyValue(projectContents, 'OutputType')) === null || _a === void 0 ? void 0 : _a.toLowerCase();
305
+ switch (outputType) {
306
+ case 'appcontainerexe':
307
+ case 'exe':
308
+ case 'library':
309
+ case 'module':
310
+ case 'winexe':
311
+ case 'winmdobj':
312
+ return outputType;
313
+ default:
314
+ return 'unknown';
315
+ }
316
+ }
317
+ exports.getOutputType = getOutputType;
318
+ /**
319
+ * Gets the type of the project from the project contents.
320
+ * @param projectPath The project file path to check.
321
+ * @param projectContents The XML project contents.
322
+ * @return The project type.
323
+ */
324
+ function getProjectType(projectPath, projectContents) {
325
+ switch (getProjectLanguage(projectPath)) {
326
+ case 'cpp':
327
+ return getConfigurationType(projectContents);
328
+ case 'cs':
329
+ return getOutputType(projectContents);
330
+ default:
331
+ return 'unknown';
332
+ }
333
+ }
334
+ exports.getProjectType = getProjectType;
335
+ /**
336
+ * Gets the name of the project from the project contents.
337
+ * @param projectPath The project file path to check.
338
+ * @param projectContents The XML project contents.
339
+ * @return The project name.
340
+ */
341
+ function getProjectName(projectPath, projectContents) {
342
+ const name = tryFindPropertyValue(projectContents, 'ProjectName') ||
343
+ path_1.default.parse(projectPath).name ||
344
+ '';
345
+ return name;
346
+ }
347
+ exports.getProjectName = getProjectName;
348
+ /**
349
+ * Gets the namespace of the project from the project contents.
350
+ * @param projectContents The XML project contents.
351
+ * @return The project namespace.
352
+ */
353
+ function getProjectNamespace(projectContents) {
354
+ return tryFindPropertyValue(projectContents, 'RootNamespace');
355
+ }
356
+ exports.getProjectNamespace = getProjectNamespace;
357
+ /**
358
+ * Gets the guid of the project from the project contents.
359
+ * @param projectContents The XML project contents.
360
+ * @return The project guid.
361
+ */
362
+ function getProjectGuid(projectContents) {
363
+ return tryFindPropertyValue(projectContents, 'ProjectGuid');
364
+ }
365
+ exports.getProjectGuid = getProjectGuid;
366
+ function getExperimentalFeatures(solutionDir) {
367
+ const propsFile = path_1.default.join(solutionDir, 'ExperimentalFeatures.props');
368
+ if (!fs_1.default.existsSync(propsFile)) {
369
+ return undefined;
370
+ }
371
+ const result = {};
372
+ const propsContents = readProjectFile(propsFile);
373
+ const nodes = msbuildSelect(`//msbuild:PropertyGroup/msbuild:*`, propsContents);
374
+ for (const node of nodes) {
375
+ const propertyNode = node;
376
+ result[propertyNode.nodeName] = propertyNode.textContent;
377
+ }
378
+ return result;
379
+ }
380
+ exports.getExperimentalFeatures = getExperimentalFeatures;
381
381
  //# sourceMappingURL=configUtils.js.map