-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore dependencies in falsy branches (#1166)
- Loading branch information
1 parent
d67b76c
commit a176ded
Showing
8 changed files
with
114 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const types = require('babel-types'); | ||
const matchesPattern = require('./matches-pattern'); | ||
|
||
module.exports = { | ||
MemberExpression(node, asset) { | ||
// Inline environment variables accessed on process.env | ||
if (matchesPattern(node.object, 'process.env')) { | ||
let key = types.toComputedKey(node); | ||
if (types.isStringLiteral(key)) { | ||
let val = types.valueToNode(process.env[key.value]); | ||
morph(node, val); | ||
asset.isAstDirty = true; | ||
asset.cacheData.env[key.value] = process.env[key.value]; | ||
} | ||
} | ||
} | ||
}; | ||
|
||
// replace object properties | ||
function morph(object, newProperties) { | ||
for (let key in object) { | ||
delete object[key]; | ||
} | ||
|
||
for (let key in newProperties) { | ||
object[key] = newProperties[key]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
if (false) { | ||
require('if-false-optional-dep'); | ||
} | ||
|
||
if (false) { | ||
globalStuff(() => | ||
require('if-false-optional-dep-deep') | ||
); | ||
} | ||
|
||
if ('') { | ||
require('if-falsy-optional-dep'); | ||
} | ||
|
||
if (process.env.NODE_ENV === 'test') { | ||
require('./true-consequent'); | ||
} else { | ||
require('./false-alternate'); | ||
} | ||
|
||
if (process.env.NODE_ENV !== 'test') { | ||
require('./false-consequent'); | ||
} else { | ||
require('./true-alternate'); | ||
} | ||
|
||
module.exports = 2; |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters