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

Resolve package.browser in subfolders (with backslashes) #2445

Merged
merged 8 commits into from
Dec 24, 2018
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 4 additions & 0 deletions packages/core/parcel-bundler/src/Resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ class Resolver {
}
}
}
// Or try a lookup replacing backslash characters with forward slash
if (alias == null && ~filename.indexOf('\\')) {
alias = aliases[filename.replace(/\\/g, '/')];
danmarshall marked this conversation as resolved.
Show resolved Hide resolved
}
}

if (typeof alias === 'string') {
Expand Down

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.

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

22 changes: 22 additions & 0 deletions packages/core/parcel-bundler/test/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,28 @@ describe('resolver', function() {
assert.equal(resolved.pkg.name, 'package-browser-alias');
});

it('should alias a deep nested relative file using the package.browser field', async function() {
let resolved = await resolver.resolve(
'./nested',
path.join(
rootDir,
'node_modules',
'package-browser-alias',
'browser.js'
)
);
assert.equal(
resolved.path,
path.join(
rootDir,
'node_modules',
'package-browser-alias',
'subfolder1/subfolder2/subfile.js'
)
);
assert.equal(resolved.pkg.name, 'package-browser-alias');
});

it('should alias a sub-file using the package.alias field', async function() {
let resolved = await resolver.resolve(
'package-alias/foo',
Expand Down