Skip to content

Commit

Permalink
fix: use metro's mainFields, resolve platform-specific files first, i…
Browse files Browse the repository at this point in the history
…mprove yarn monorepo search (#5)
  • Loading branch information
flisboac committed Feb 18, 2019
1 parent 7967794 commit b512a13
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export namespace Metro {
}

export interface IConfig {
projectRoot?: string;
watchFolders: string[];
resolver: {
resolveRequest?: CustomResolver;
Expand Down Expand Up @@ -304,7 +305,7 @@ class MetroConfigHelper {
...this.watchFolders()
.map(this.mapByFolderFollowingSymlink)
.filter(this.filterByNonEmptyString),
],
],
resolver: {
...(this.defaultConfig().resolver || {}),
resolveRequest: this.customResolver(),
Expand Down Expand Up @@ -349,8 +350,11 @@ class MetroConfigHelper {
const moduleName = context.moduleName;

const packageFilter = (pkg: any) => {
if (typeof pkg["react-native"] === 'string') {
pkg.main = pkg["react-native"];
for (const mainField of context.metro.mainFields || []) {
if (typeof pkg[mainField] === 'string') {
pkg.main = pkg[mainField];
break;
}
}
return pkg;
};
Expand Down Expand Up @@ -453,8 +457,8 @@ class MetroConfigHelper {
let filePaths: string[] = [];
for (const baseExt of baseExtensions) {
filePaths = filePaths.concat([
`${baseExt}`,
`${context.platform}.${baseExt}`,
`${baseExt}`,
]);
}
return filePaths;
Expand Down Expand Up @@ -552,8 +556,10 @@ export function findYarnMonorepo(
while (true) {
helper.logger().debug(`Searching for yarn monorepo at '${monorepoRoot}'...`);
const packageJsonFilename = path.resolve(monorepoRoot, "package.json");
const yarnPackageJson = tryParseJsonFile(packageJsonFilename);
const yarnWorkspaces = yarnPackageJson ? yarnPackageJson.workspaces : {};

if (fs.existsSync(packageJsonFilename)) {
if (yarnWorkspaces && 'packages' in yarnWorkspaces) {
if (yarnInPath) {
let workspaceInfoJson: string | undefined;

Expand Down

0 comments on commit b512a13

Please sign in to comment.