Skip to content

Commit

Permalink
Resolve package.browser in subfolders (with backslashes) (#2445)
Browse files Browse the repository at this point in the history
* add alias lookup when filename contains backslashes

* Create subfile.js in a deep subfolder

* Create nested.js

* add unit test for files in subfolders

* prettier

* Remove white space

* zero length file
  • Loading branch information
danmarshall authored and DeMoorJasper committed Dec 24, 2018
1 parent 449a48e commit 0fac29e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/core/parcel-bundler/src/Resolver.js
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, '/')];
}
}

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

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
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

0 comments on commit 0fac29e

Please sign in to comment.