1
+ import browserify from "browserify"
1
2
import * as cp from "child_process"
2
- import Bundler from "parcel-bundler "
3
+ import * as fs from "fs "
3
4
import * as path from "path"
4
5
5
6
async function main ( ) : Promise < void > {
@@ -40,7 +41,6 @@ class Watcher {
40
41
const plugin = process . env . PLUGIN_DIR
41
42
? cp . spawn ( "yarn" , [ "build" , "--watch" ] , { cwd : process . env . PLUGIN_DIR } )
42
43
: undefined
43
- const bundler = this . createBundler ( )
44
44
45
45
const cleanup = ( code ?: number | null ) : void => {
46
46
Watcher . log ( "killing vs code watcher" )
@@ -63,7 +63,7 @@ class Watcher {
63
63
server . kill ( )
64
64
}
65
65
66
- Watcher . log ( "killing bundler " )
66
+ Watcher . log ( "killing watch " )
67
67
process . exit ( code || 0 )
68
68
}
69
69
@@ -84,23 +84,19 @@ class Watcher {
84
84
cleanup ( code )
85
85
} )
86
86
}
87
- const bundle = bundler . bundle ( ) . catch ( ( ) => {
88
- Watcher . log ( "parcel watcher terminated unexpectedly" )
89
- cleanup ( 1 )
90
- } )
91
- bundler . on ( "buildEnd" , ( ) => {
92
- console . log ( "[parcel] bundled" )
93
- } )
94
- bundler . on ( "buildError" , ( error ) => {
95
- console . error ( "[parcel]" , error )
96
- } )
97
87
98
88
vscode . stderr . on ( "data" , ( d ) => process . stderr . write ( d ) )
99
89
tsc . stderr . on ( "data" , ( d ) => process . stderr . write ( d ) )
100
90
if ( plugin ) {
101
91
plugin . stderr . on ( "data" , ( d ) => process . stderr . write ( d ) )
102
92
}
103
93
94
+ const browserFiles = [
95
+ path . join ( this . rootPath , "out/browser/register.js" ) ,
96
+ path . join ( this . rootPath , "out/browser/pages/login.js" ) ,
97
+ path . join ( this . rootPath , "out/browser/pages/vscode.js" ) ,
98
+ ]
99
+
104
100
// From https://github.com/chalk/ansi-regex
105
101
const pattern = [
106
102
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)" ,
@@ -143,7 +139,7 @@ class Watcher {
143
139
startingVscode = true
144
140
} else if ( startingVscode && line . includes ( "Finished compilation" ) ) {
145
141
if ( startedVscode ) {
146
- bundle . then ( restartServer )
142
+ restartServer ( )
147
143
}
148
144
startedVscode = true
149
145
}
@@ -155,7 +151,8 @@ class Watcher {
155
151
console . log ( "[tsc]" , original )
156
152
}
157
153
if ( line . includes ( "Watching for file changes" ) ) {
158
- bundle . then ( restartServer )
154
+ bundleBrowserCode ( browserFiles )
155
+ restartServer ( )
159
156
}
160
157
} )
161
158
@@ -166,29 +163,26 @@ class Watcher {
166
163
console . log ( "[plugin]" , original )
167
164
}
168
165
if ( line . includes ( "Watching for file changes" ) ) {
169
- bundle . then ( restartServer )
166
+ restartServer ( )
170
167
}
171
168
} )
172
169
}
173
170
}
171
+ }
174
172
175
- private createBundler ( out = "dist" ) : Bundler {
176
- return new Bundler (
177
- [
178
- path . join ( this . rootPath , "src/browser/register.ts" ) ,
179
- path . join ( this . rootPath , "src/browser/serviceWorker.ts" ) ,
180
- path . join ( this . rootPath , "src/browser/pages/login.ts" ) ,
181
- path . join ( this . rootPath , "src/browser/pages/vscode.ts" ) ,
182
- ] ,
183
- {
184
- outDir : path . join ( this . rootPath , out ) ,
185
- cacheDir : path . join ( this . rootPath , ".cache" ) ,
186
- minify : ! ! process . env . MINIFY ,
187
- logLevel : 1 ,
188
- publicUrl : "." ,
189
- } ,
190
- )
191
- }
173
+ function bundleBrowserCode ( inputFiles : string [ ] ) {
174
+ console . log ( `[browser] bundling...` )
175
+ inputFiles . forEach ( async ( path : string ) => {
176
+ const outputPath = path . replace ( ".js" , ".browserified.js" )
177
+ browserify ( )
178
+ . add ( path )
179
+ . bundle ( )
180
+ . on ( "error" , function ( error : Error ) {
181
+ console . error ( error . toString ( ) )
182
+ } )
183
+ . pipe ( fs . createWriteStream ( outputPath ) )
184
+ } )
185
+ console . log ( `[browser] done bundling` )
192
186
}
193
187
194
188
main ( )
0 commit comments