Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Commit

Permalink
Fix pkg.browser mappings issue by specifying a value of false issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
allex committed Oct 18, 2018
1 parent b2ecf57 commit d0138c1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/empty.js
@@ -1 +1 @@
export default {};
module.exports = {};
24 changes: 17 additions & 7 deletions src/index.js
Expand Up @@ -40,6 +40,8 @@ function cachedIsFile (file, cb) {

const resolveIdAsync = (file, opts) => new Promise((fulfil, reject) => resolveId(file, opts, (err, contents) => err ? reject(err) : fulfil(contents)));

const FALSE = {};

export default function nodeResolve ( options = {} ) {
const useModule = options.module !== false;
const useMain = options.main !== false;
Expand Down Expand Up @@ -86,6 +88,7 @@ export default function nodeResolve ( options = {} ) {
// disregard entry module
if ( !importer ) return null;

// https://github.com/defunctzombie/package-browser-field-spec
if (options.browser && browserMapCache[importer]) {
const resolvedImportee = resolve( dirname( importer ), importee );
const browser = browserMapCache[importer];
Expand Down Expand Up @@ -161,16 +164,23 @@ export default function nodeResolve ( options = {} ) {
importee,
Object.assign( resolveOptions, customResolveOptions )
)
.catch(() => false)
.catch(() => FALSE)
.then(resolved => {
if (options.browser && packageBrowserField) {
if (packageBrowserField[ resolved ]) {
resolved = packageBrowserField[ resolved ];
if (resolved !== FALSE && options.browser && packageBrowserField) {
let l, hasLink = packageBrowserField.hasOwnProperty(resolved);
if (hasLink) {
l = packageBrowserField[ resolved ];
}
browserMapCache[l || resolved] = packageBrowserField;
if (hasLink) {
resolved = l;
}
if (resolved === false) {
return ES6_BROWSER_EMPTY;
}
browserMapCache[resolved] = packageBrowserField;
}

if ( !disregardResult && resolved !== false ) {
if ( !disregardResult && resolved !== FALSE ) {
if ( !preserveSymlinks && resolved && fs.existsSync( resolved ) ) {
resolved = fs.realpathSync( resolved );
}
Expand All @@ -194,7 +204,7 @@ export default function nodeResolve ( options = {} ) {
if ( resolved && options.modulesOnly ) {
return readFileAsync( resolved, 'utf-8').then(code => isModule( code ) ? resolved : null);
} else {
return resolved === false ? null : resolved;
return resolved === FALSE ? null : resolved;
}
});
}
Expand Down

0 comments on commit d0138c1

Please sign in to comment.