1- import browserify from "browserify"
21import * as cp from "child_process"
3- import * as fs from "fs"
42import * as path from "path"
53import { onLine } from "../../src/node/util"
64
75async function main ( ) : Promise < void > {
86 try {
97 const watcher = new Watcher ( )
108 await watcher . watch ( )
11- } catch ( error ) {
9+ } catch ( error : any ) {
1210 console . error ( error . message )
1311 process . exit ( 1 )
1412 }
@@ -38,6 +36,9 @@ class Watcher {
3836 }
3937
4038 const vscode = cp . spawn ( "yarn" , [ "watch" ] , { cwd : this . vscodeSourcePath } )
39+
40+ const vscodeWebExtensions = cp . spawn ( "yarn" , [ "watch-web" ] , { cwd : this . vscodeSourcePath } )
41+
4142 const tsc = cp . spawn ( "tsc" , [ "--watch" , "--pretty" , "--preserveWatchOutput" ] , { cwd : this . rootPath } )
4243 const plugin = process . env . PLUGIN_DIR
4344 ? cp . spawn ( "yarn" , [ "build" , "--watch" ] , { cwd : process . env . PLUGIN_DIR } )
@@ -48,6 +49,10 @@ class Watcher {
4849 vscode . removeAllListeners ( )
4950 vscode . kill ( )
5051
52+ Watcher . log ( "killing vs code web extension watcher" )
53+ vscodeWebExtensions . removeAllListeners ( )
54+ vscodeWebExtensions . kill ( )
55+
5156 Watcher . log ( "killing tsc" )
5257 tsc . removeAllListeners ( )
5358 tsc . kill ( )
@@ -75,29 +80,32 @@ class Watcher {
7580 Watcher . log ( "vs code watcher terminated unexpectedly" )
7681 cleanup ( code )
7782 } )
83+
84+ vscodeWebExtensions . on ( "exit" , ( code ) => {
85+ Watcher . log ( "vs code extension watcher terminated unexpectedly" )
86+ cleanup ( code )
87+ } )
88+
7889 tsc . on ( "exit" , ( code ) => {
7990 Watcher . log ( "tsc terminated unexpectedly" )
8091 cleanup ( code )
8192 } )
93+
8294 if ( plugin ) {
8395 plugin . on ( "exit" , ( code ) => {
8496 Watcher . log ( "plugin terminated unexpectedly" )
8597 cleanup ( code )
8698 } )
8799 }
88100
101+ vscodeWebExtensions . stderr . on ( "data" , ( d ) => process . stderr . write ( d ) )
89102 vscode . stderr . on ( "data" , ( d ) => process . stderr . write ( d ) )
90103 tsc . stderr . on ( "data" , ( d ) => process . stderr . write ( d ) )
104+
91105 if ( plugin ) {
92106 plugin . stderr . on ( "data" , ( d ) => process . stderr . write ( d ) )
93107 }
94108
95- const browserFiles = [
96- path . join ( this . rootPath , "out/browser/register.js" ) ,
97- path . join ( this . rootPath , "out/browser/pages/login.js" ) ,
98- path . join ( this . rootPath , "out/browser/pages/vscode.js" ) ,
99- ]
100-
101109 let startingVscode = false
102110 let startedVscode = false
103111 onLine ( vscode , ( line , original ) => {
@@ -120,7 +128,6 @@ class Watcher {
120128 console . log ( "[tsc]" , original )
121129 }
122130 if ( line . includes ( "Watching for file changes" ) ) {
123- bundleBrowserCode ( browserFiles )
124131 restartServer ( )
125132 }
126133 } )
@@ -139,19 +146,4 @@ class Watcher {
139146 }
140147}
141148
142- function bundleBrowserCode ( inputFiles : string [ ] ) {
143- console . log ( `[browser] bundling...` )
144- inputFiles . forEach ( async ( path : string ) => {
145- const outputPath = path . replace ( ".js" , ".browserified.js" )
146- browserify ( )
147- . add ( path )
148- . bundle ( )
149- . on ( "error" , function ( error : Error ) {
150- console . error ( error . toString ( ) )
151- } )
152- . pipe ( fs . createWriteStream ( outputPath ) )
153- } )
154- console . log ( `[browser] done bundling` )
155- }
156-
157149main ( )
0 commit comments