Skip to content

Commit

Permalink
add support for node bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
Spikef committed Apr 24, 2020
1 parent 06e6b39 commit 7ff994b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ _Note: Gaps between patch versions are faulty, broken or test releases._

## UNRELEASED

* **Improvement**
* Added support for exports.modules when webpack target = node

<!-- Add changelog entries for new changes under this section -->

## 3.7.0
Expand Down
15 changes: 15 additions & 0 deletions src/parseUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ function parseBundle(bundlePath) {
ast,
walkState,
{
AssignmentExpression(node, state,) {
if (state.locations) return;

// Modules are stored in exports.modules:
// exports.modules = {};
const {left, right} = node;

if (
left &&
left.object && left.object.name === 'exports' &&
left.property && left.property.name === 'modules'
) {
state.locations = getModulesLocations(right);
}
},
CallExpression(node, state, c) {
if (state.locations) return;

Expand Down
6 changes: 6 additions & 0 deletions test/bundles/validNodeBundleWithModulesAsArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
exports.ids = ["common"];
exports.modules = {
0: function(e,t,n){n(1),n(21),n(96),n(306),n(23),n(150),n(57),n(56),n(34),n(138),e.exports=n(348)},
3: function(e,t,n){"use strict";e.exports=n(680)},
5: function(e,t){}
};
7 changes: 7 additions & 0 deletions test/bundles/validNodeBundleWithModulesAsArray.modules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"modules": {
"0": "function(e,t,n){n(1),n(21),n(96),n(306),n(23),n(150),n(57),n(56),n(34),n(138),e.exports=n(348)}",
"3": "function(e,t,n){\"use strict\";e.exports=n(680)}",
"5": "function(e,t){}"
}
}

0 comments on commit 7ff994b

Please sign in to comment.