@@ -6,6 +6,10 @@ const inquirer = require('inquirer');
6
6
const args = require ( 'minimist' ) ( process . argv . slice ( 2 ) ) ;
7
7
const convertToIntegerKey = require ( './utils/convertToIntegerKey' ) ;
8
8
9
+ // ----------------------------------------------------------------------------
10
+ // Set up configuration
11
+ // ----------------------------------------------------------------------------
12
+
9
13
const bundleLocation = args . _ [ 0 ] || args . input || args . i ;
10
14
const outputLocation = args . output || args . o ;
11
15
const configPath = args . config || args . c ;
@@ -42,7 +46,9 @@ if (!config.moduleAst) {
42
46
console . log ( `* Using default AST location for ${ config . type } ...` ) ;
43
47
}
44
48
45
-
49
+ // ----------------------------------------------------------------------------
50
+ // Read in bundle
51
+ // ----------------------------------------------------------------------------
46
52
47
53
console . log ( '* Reading bundle...' ) ;
48
54
const bundleContents = fs . readFileSync ( bundleLocation ) ;
@@ -60,17 +66,9 @@ if (config.entryPoint === undefined) {
60
66
}
61
67
62
68
63
-
64
-
65
- // TODO
66
- // KNOWN BUGS
67
- // - If a package has a nonstandard location for it's root file (ie, not in index.js), and that
68
- // location is in a folder, then we aren't smart enough to put that in the right location.
69
- // ie, blueprint has it's root in `src/index.js` and it requires `./common` from that file, which
70
- // when the root file is put in `index.js` it can't resolve.
71
-
72
- // Browserify bundles start with an IIFE. Fetch the IIFE and get it's arguments (what we care about,
73
- // and where all the module code is located)
69
+ // ----------------------------------------------------------------------------
70
+ // Find all the modules in the bundle via `moduleAst`
71
+ // ----------------------------------------------------------------------------
74
72
75
73
let iifeModules = ast ;
76
74
while ( true ) {
@@ -84,18 +82,10 @@ while (true) {
84
82
}
85
83
}
86
84
87
- // Known paths are inserted absolutely into requires. They need to be made relative.
88
- //
89
-
90
-
91
-
92
- // Webpack bundle
93
- // let iifeModules = ast.body[0].expression.arguments[0];
94
-
95
-
96
-
97
-
98
-
85
+ // ------------------------------------------------------------------------------
86
+ // Given the path to the modules in the AST and the AST, pull out the modules and normalize
87
+ // them to a predefined format.
88
+ // ------------------------------------------------------------------------------
99
89
100
90
console . log ( '* Decoding modules...' ) ;
101
91
@@ -110,14 +100,22 @@ if (config.type === 'browserify') {
110
100
modules = webpackDecoder ( iifeModules , config . knownPaths ) ;
111
101
}
112
102
103
+
104
+
105
+ // ------------------------------------------------------------------------------
113
106
// Transform the module id in each require call into a relative path to the module.
114
107
// var a = require(1) => var a = require('./path/to/a')
108
+ // ------------------------------------------------------------------------------
109
+
115
110
console . log ( '* Reassembling requires...' ) ;
116
111
const transformRequires = require ( './transformRequires' ) ;
117
112
modules = transformRequires ( modules , config . knownPaths , config . entryPoint , config . type ) ;
118
113
114
+ // ------------------------------------------------------------------------------
119
115
// Take the array of modules and figure out where to put each module on disk.
120
116
// module 1 => ./dist/path/to/a.js
117
+ // ------------------------------------------------------------------------------
118
+
121
119
console . log ( '* Resolving files...' ) ;
122
120
const lookupTableResolver = require ( './lookupTable' ) ;
123
121
const files = lookupTableResolver (
@@ -128,6 +126,9 @@ const files = lookupTableResolver(
128
126
outputLocation
129
127
) ;
130
128
129
+ // ------------------------------------------------------------------------------
130
+ // Finally, write the bundle to disk in the specified output location.
131
+ // ------------------------------------------------------------------------------
131
132
132
133
console . log ( '* Writing to disk...' ) ;
133
134
const writeToDisk = require ( './writeToDisk' ) ;
0 commit comments