Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package exports: resolve to real paths, fix module duplication in output #1198

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/metro-resolver/src/PackageExportsResolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,19 @@ export function resolvePackageTargetFromExports(
}
}

if (context.doesFileExist(filePath)) {
return {type: 'sourceFile', filePath};
if (context.unstable_getRealPath != null) {
const maybeRealPath = context.unstable_getRealPath(filePath);
if (maybeRealPath != null) {
return {
type: 'sourceFile',
filePath: maybeRealPath,
};
}
} else if (context.doesFileExist(filePath)) {
return {
type: 'sourceFile',
filePath,
};
}

throw createConfigError(
Expand Down
39 changes: 31 additions & 8 deletions packages/metro-resolver/src/__tests__/package-exports-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,20 @@ describe('with package exports resolution disabled', () => {
describe('with package exports resolution enabled', () => {
describe('main entry point', () => {
const baseContext = {
...createResolutionContext({
'/root/src/main.js': '',
'/root/node_modules/test-pkg/package.json': '',
'/root/node_modules/test-pkg/index.js': '',
'/root/node_modules/test-pkg/index-main.js': '',
'/root/node_modules/test-pkg/index-exports.js.js': '',
'/root/node_modules/test-pkg/index-exports.ios.js': '',
}),
...createResolutionContext(
{
'/root/src/main.js': '',
'/root/node_modules/test-pkg/package.json': '',
'/root/node_modules/test-pkg/index.js': '',
'/root/node_modules/test-pkg/index-main.js': '',
'/root/node_modules/test-pkg/index-exports.js.js': '',
'/root/node_modules/test-pkg/index-exports.ios.js': '',
'/root/node_modules/test-pkg/symlink.js': {
realPath: '/root/node_modules/test-pkg/symlink-target.js',
},
},
{enableSymlinks: true},
),
originModulePath: '/root/src/main.js',
unstable_enablePackageExports: true,
};
Expand Down Expand Up @@ -229,6 +235,23 @@ describe('with package exports resolution enabled', () => {
filePath: '/root/node_modules/test-pkg/index-main.js',
});
});

test('following symlinks and resolving real paths', () => {
const context = {
...baseContext,
...createPackageAccessors({
'/root/node_modules/test-pkg/package.json': {
main: 'index-main.js',
exports: './symlink.js',
},
}),
};

expect(Resolver.resolve(context, 'test-pkg', null)).toEqual({
type: 'sourceFile',
filePath: '/root/node_modules/test-pkg/symlink-target.js',
});
});
});
});

Expand Down