Skip to content

Commit

Permalink
Support false mappings in "browser" fields
Browse files Browse the repository at this point in the history
Summary:
This adds support for `false` values in `package.json` `"browser"` and `"react-native"` mappings.
All `false` values are not longer silently ignored, but redirected to an empty file.

Fixes #9854 #9518

Reviewed By: bestander

Differential Revision: D3876521

fbshipit-source-id: 96d1ba03518812bc88c51672c374956eabd40c9b
  • Loading branch information
davidaurelio authored and Facebook Github Bot 7 committed Sep 16, 2016
1 parent 0c157be commit 5710b23
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const realPath = require('path');
const isAbsolutePath = require('absolute-path');
const getAssetDataFromName = require('../lib/getAssetDataFromName');

const emptyModule = require.resolve('./assets/empty-module.js');

class ResolutionRequest {
constructor({
platform,
Expand Down Expand Up @@ -193,7 +195,7 @@ class ResolutionRequest {

if (recursive) {
// doesn't block the return of this function invocation, but defers
// the resulution of collectionsInProgress.done.then()
// the resulution of collectionsInProgress.done.then(...)
dependencyModules
.forEach(dependency => collectedDependencies.get(dependency));
}
Expand Down Expand Up @@ -322,7 +324,7 @@ class ResolutionRequest {
return this._redirectRequire(fromModule, potentialModulePath).then(
realModuleName => {
if (realModuleName === false) {
return null;
return this._loadAsFile(emptyModule, fromModule, toModuleName);
}

return this._tryResolve(
Expand All @@ -341,7 +343,7 @@ class ResolutionRequest {
realModuleName => {
// exclude
if (realModuleName === false) {
return null;
return this._loadAsFile(emptyModule, fromModule, toModuleName);
}

if (isRelativeImport(realModuleName) || isAbsolutePath(realModuleName)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

1 comment on commit 5710b23

@aleclarson
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.