Skip to content
Merged
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
26 changes: 23 additions & 3 deletions packages/node-resolve/src/resolveImportSpecifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,41 @@ async function resolveWithExportMap({
importer,
moduleDirs: moduleDirectories,
conditions: exportConditions,
// Resolve targets of "imports" mappings using the same algorithm
// we use for normal specifiers: try export maps first and then
// fall back to classic resolution. This is important for cases
// like "#foo/*": "@scope/pkg/*" where the target package relies
// on "exports" to expose subpaths. Using the classic resolver
// alone would fail to find those subpaths.
resolveId(id /* , parent*/) {
return resolveIdClassic({
importSpecifier: id,
return resolveImportSpecifiers({
importer,
importSpecifierList: [id],
exportConditions,
// pass-through of the rest of the context
packageInfoCache,
extensions,
mainFields,
preserveSymlinks,
useBrowserOverrides,
baseDir,
moduleDirectories,
modulePaths
modulePaths,
rootDir,
ignoreSideEffectsForRoot,
allowExportsFolderMapping
});
}
});

if (resolveResult == null) {
// When the target of an "imports" mapping cannot be resolved,
// surface a proper resolve error instead of throwing from
// fileURLToPath(null).
throw new ResolveError(
`Could not resolve import "${importSpecifier}" in ${importer} using imports.`
);
}
const location = fileURLToPath(resolveResult);
return {
location: preserveSymlinks ? location : await resolveSymlink(location),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { a, b, c } from 'imports-bare-pattern-exports';

export default { a, b, c };

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions packages/node-resolve/test/package-entry-points.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,23 @@ test('can resolve a package import with a pattern', async (t) => {
});
});

test('can resolve a package import pattern to a bare package that uses exports', async (t) => {
const bundle = await rollup({
input: 'imports-bare-pattern-exports.js',
onwarn: () => {
t.fail('No warnings were expected');
},
plugins: [nodeResolve()]
});
const { module } = await testBundle(t, bundle);

t.deepEqual(module.exports, {
a: 'exported-foo a',
b: 'exported-foo b',
c: 'exported-foo c'
});
});

test('can override a star pattern using null', async (t) => {
const errors = [];
const bundle = await rollup({
Expand Down
Loading