Skip to content

Commit b93a2fd

Browse files
committed
Detect whether a project file is a dynamic library
1 parent 04f9cad commit b93a2fd

File tree

3 files changed

+88
-30
lines changed

3 files changed

+88
-30
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Detect whether a project file is a dynamic library",
4+
"packageName": "@react-native-windows/cli",
5+
"email": "4123478+tido64@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}

packages/@react-native-windows/cli/src/config/configUtils.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,36 @@ export function importProjectExists(
291291
return nodes.length > 0;
292292
}
293293

294+
export type ConfigurationType =
295+
| 'Application'
296+
| 'DynamicLibrary'
297+
| 'Generic'
298+
| 'StaticLibrary'
299+
| 'Unknown';
300+
301+
/**
302+
* Gets the configuration type of the project from the project contents.
303+
* @param projectContents The XML project contents.
304+
* @return The project configuration type.
305+
*/
306+
export function getConfigurationType(projectContents: Node): ConfigurationType {
307+
const configurationType = tryFindPropertyValue(
308+
projectContents,
309+
'ConfigurationType',
310+
);
311+
312+
switch (configurationType) {
313+
case 'Application':
314+
case 'DynamicLibrary':
315+
case 'Generic':
316+
case 'StaticLibrary':
317+
return configurationType;
318+
319+
default:
320+
return 'Unknown';
321+
}
322+
}
323+
294324
/**
295325
* Gets the name of the project from the project contents.
296326
* @param projectPath The project file path to check.

packages/@react-native-windows/cli/src/config/dependencyConfig.ts

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -271,47 +271,68 @@ export function dependencyConfigWindows(
271271
for (const foundProject of foundProjects) {
272272
const projectFile = path.join(sourceDir, foundProject);
273273

274-
const projectLang = configUtils.getProjectLanguage(projectFile);
275-
276274
const projectContents = configUtils.readProjectFile(projectFile);
277275

278-
const projectName = configUtils.getProjectName(
279-
projectFile,
276+
const configurationType = configUtils.getConfigurationType(
280277
projectContents,
281278
);
282279

283-
const projectGuid = configUtils.getProjectGuid(projectContents);
280+
if (configurationType === 'DynamicLibrary') {
281+
const projectLang = configUtils.getProjectLanguage(projectFile);
282+
283+
const projectName = configUtils.getProjectName(
284+
projectFile,
285+
projectContents,
286+
);
287+
288+
const projectGuid = configUtils.getProjectGuid(projectContents);
289+
290+
const projectNamespace = configUtils.getProjectNamespace(
291+
projectContents,
292+
);
284293

285-
const projectNamespace = configUtils.getProjectNamespace(projectContents);
294+
const directDependency = true;
286295

287-
const directDependency = true;
296+
const cppHeaders: string[] = [];
297+
const cppPackageProviders: string[] = [];
298+
const csNamespaces: string[] = [];
299+
const csPackageProviders: string[] = [];
288300

289-
const cppHeaders: string[] = [];
290-
const cppPackageProviders: string[] = [];
291-
const csNamespaces: string[] = [];
292-
const csPackageProviders: string[] = [];
301+
if (projectNamespace !== null) {
302+
const cppNamespace = projectNamespace.replace(/\./g, '::');
303+
const csNamespace = projectNamespace.replace(/::/g, '.');
293304

294-
if (projectNamespace !== null) {
295-
const cppNamespace = projectNamespace.replace(/\./g, '::');
296-
const csNamespace = projectNamespace.replace(/::/g, '.');
305+
cppHeaders.push(`winrt/${csNamespace}.h`);
306+
cppPackageProviders.push(`${cppNamespace}::ReactPackageProvider`);
307+
csNamespaces.push(`${csNamespace}`);
308+
csPackageProviders.push(`${csNamespace}.ReactPackageProvider`);
309+
}
297310

298-
cppHeaders.push(`winrt/${csNamespace}.h`);
299-
cppPackageProviders.push(`${cppNamespace}::ReactPackageProvider`);
300-
csNamespaces.push(`${csNamespace}`);
301-
csPackageProviders.push(`${csNamespace}.ReactPackageProvider`);
311+
result.projects.push({
312+
projectFile: path.relative(sourceDir, projectFile),
313+
projectName,
314+
projectLang,
315+
projectGuid,
316+
directDependency,
317+
cppHeaders,
318+
cppPackageProviders,
319+
csNamespaces,
320+
csPackageProviders,
321+
});
322+
} else {
323+
const projectPath = path.relative(sourceDir, projectFile);
324+
result.projects.push({
325+
projectFile: `Error: ${projectPath} has configuration type '${configurationType}'`,
326+
directDependency: false,
327+
projectName: '',
328+
projectLang: null,
329+
projectGuid: null,
330+
cppHeaders: [],
331+
cppPackageProviders: [],
332+
csNamespaces: [],
333+
csPackageProviders: [],
334+
});
302335
}
303-
304-
result.projects.push({
305-
projectFile: path.relative(sourceDir, projectFile),
306-
projectName,
307-
projectLang,
308-
projectGuid,
309-
directDependency,
310-
cppHeaders,
311-
cppPackageProviders,
312-
csNamespaces,
313-
csPackageProviders,
314-
});
315336
}
316337
}
317338

0 commit comments

Comments
 (0)