Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add module resolver for aliasing react-native
- Loading branch information
Showing
5 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
'use strict'; | ||
|
||
const glob = require('glob'); | ||
const path = require('path'); | ||
|
||
/** | ||
* Glob pattern to look for xcodeproj | ||
*/ | ||
const GLOB_PATTERN = '**/*.xcodeproj'; | ||
|
||
/** | ||
* Regexp matching all test projects | ||
*/ | ||
const TEST_PROJECTS = /test|example|sample/i; | ||
|
||
/** | ||
* Base iOS folder | ||
*/ | ||
const IOS_BASE = 'macos'; | ||
|
||
/** | ||
* These folders will be excluded from search to speed it up | ||
*/ | ||
const GLOB_EXCLUDE_PATTERN = ['**/@(Pods|node_modules)/**']; | ||
|
||
/** | ||
* Finds iOS project by looking for all .xcodeproj files | ||
* in given folder. | ||
* | ||
* Returns first match if files are found or null | ||
* | ||
* Note: `./ios/*.xcodeproj` are returned regardless of the name | ||
*/ | ||
module.exports = function findProject(folder) { | ||
const projects = glob | ||
.sync(GLOB_PATTERN, { | ||
cwd: folder, | ||
ignore: GLOB_EXCLUDE_PATTERN, | ||
}) | ||
.filter(project => { | ||
return path.dirname(project) === IOS_BASE || !TEST_PROJECTS.test(project); | ||
}) | ||
.sort((projectA, projectB) => { | ||
return path.dirname(projectA) === IOS_BASE ? -1 : 1; | ||
}); | ||
|
||
if (projects.length === 0) { | ||
return null; | ||
} | ||
|
||
return projects[0]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
'use strict'; | ||
|
||
const findProject = require('./findProject'); | ||
const path = require('path'); | ||
|
||
/** | ||
* For libraries specified without an extension, add '.tbd' for those that | ||
* start with 'lib' and '.framework' to the rest. | ||
*/ | ||
const mapSharedLibaries = (libraries) => { | ||
return libraries.map(name => { | ||
if (path.extname(name)) { | ||
return name; | ||
} | ||
return name + (name.indexOf('lib') === 0 ? '.tbd' : '.framework'); | ||
}); | ||
}; | ||
|
||
/** | ||
* Returns project config by analyzing given folder and applying some user defaults | ||
* when constructing final object | ||
*/ | ||
exports.projectConfig = function projectConfigIOS(folder, userConfig) { | ||
const project = userConfig.project || findProject(folder); | ||
|
||
/** | ||
* No iOS config found here | ||
*/ | ||
if (!project) { | ||
return null; | ||
} | ||
|
||
const projectPath = path.join(folder, project); | ||
|
||
return { | ||
sourceDir: path.dirname(projectPath), | ||
folder: folder, | ||
pbxprojPath: path.join(projectPath, 'project.pbxproj'), | ||
projectPath: projectPath, | ||
projectName: path.basename(projectPath), | ||
libraryFolder: userConfig.libraryFolder || 'Libraries', | ||
sharedLibraries: mapSharedLibaries(userConfig.sharedLibraries || []), | ||
plist: userConfig.plist || [], | ||
}; | ||
}; | ||
|
||
exports.dependencyConfig = exports.projectConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters