Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Determine used exports for CJS modules
Based on the entire graph, not just the subset of the graph that has already loaded.
- Loading branch information
Showing
10 changed files
with
118 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var isString = require("lodash/isString"); | ||
|
||
/** | ||
* @method graph.eachDependants | ||
*/ | ||
module.exports = function(graph, names, callback){ | ||
var deps = {}; | ||
var nodeNames = isString(names) ? [names] : names; | ||
|
||
function visit(name, node) { | ||
if(!deps[name]) { | ||
deps[name] = true; | ||
|
||
if(node && node.dependencies.length) { | ||
if(includes(node.dependencies, nodeNames)) { | ||
callback(name, node); | ||
} | ||
} | ||
} | ||
} | ||
|
||
for(var name in graph) { | ||
visit(name, graph[name]); | ||
} | ||
}; | ||
|
||
function includes(arr1, arr2) { | ||
for(var i = 0; i < arr2.length; i++) { | ||
if(arr1.indexOf(arr2[i]) !== -1) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} |
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,9 @@ | ||
var eachDependants = require("./each_dependants"); | ||
|
||
module.exports = function(graph, name) { | ||
var deps = []; | ||
eachDependants(graph, name, function(depName) { | ||
deps.push(depName); | ||
}); | ||
return deps; | ||
}; |
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,6 @@ | ||
|
||
exports.pick = function(){}; | ||
|
||
exports.assign = function(){}; | ||
|
||
exports.isUndefined = function(){}; |
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,4 @@ | ||
import { assign } from './dep'; | ||
import './other'; | ||
|
||
window.APP = { assign }; |
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,4 @@ | ||
import { pick } from './dep'; | ||
|
||
window.APP = window.APP || {}; | ||
window.APP.pick = pick; |
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,8 @@ | ||
{ | ||
"name": "app", | ||
"main": "index.js", | ||
"version": "1.0.0", | ||
"steal": { | ||
"bundle": ["~/page"] | ||
} | ||
} |
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,4 @@ | ||
import { isUndefined } from './dep'; | ||
|
||
window.APP = window.APP || {}; | ||
window.APP.isUndefined = isUndefined; |
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 @@ | ||
<script src="./dist/steal.production.js"></script> |