@@ -2,6 +2,7 @@ import { Binary } from "@coder/nbin";
22import { field } from "@coder/logger" ;
33import { register , run } from "@coder/runner" ;
44
5+ import * as cp from "child_process" ;
56import * as fs from "fs" ;
67import * as fse from "fs-extra" ;
78import * as https from "https" ;
@@ -11,8 +12,9 @@ import * as tar from "tar";
1112
1213import { platform } from "./platform" ;
1314
14- const libPath = path . join ( __dirname , "../lib" ) ;
15- const releasePath = path . resolve ( __dirname , "../release" ) ;
15+ const rootPath = path . resolve ( __dirname , ".." ) ;
16+ const libPath = path . join ( rootPath , "lib" ) ;
17+ const releasePath = path . join ( rootPath , "release" ) ;
1618const target = `${ platform ( ) } -${ os . arch ( ) } ` ;
1719const vscodeVersion = process . env . VSCODE_VERSION || "1.35.0" ;
1820
@@ -30,25 +32,34 @@ register("build", async (runner, logger, shouldWatch: string) => {
3032 const outPath = path . join ( __dirname , "../out" ) ;
3133 const compile = async ( ) : Promise < void > => {
3234 fse . removeSync ( path . resolve ( outPath ) ) ;
33-
34- runner . cwd = path . resolve ( __dirname , ".." ) ;
35- const resp = await runner . execute (
36- "tsc" ,
37- [ "--project" , "tsconfig.build.json" ] . concat ( watch ? [ "--watch" ] : [ ] ) ,
38- ) ;
39- if ( resp . exitCode !== 0 ) {
40- throw new Error ( `Failed to build: ${ resp . stderr } ` ) ;
35+ if ( watch ) {
36+ const proc = cp . spawn ( "tsc" , [ "--project" , "tsconfig.build.json" , "--watch" , "--preserveWatchOutput" ] , {
37+ cwd : rootPath ,
38+ } ) ;
39+ await new Promise ( ( resolve , reject ) : void => {
40+ proc . stdout . setEncoding ( "utf8" ) ;
41+ proc . stdout . on ( "data" , ( data : string ) => {
42+ logger . info ( data . split ( "\n" ) . filter ( ( l ) => ! ! l ) . join ( "\n" ) ) ;
43+ } ) ;
44+ proc . on ( "exit" , resolve ) ;
45+ proc . on ( "error" , reject ) ;
46+ } ) ;
47+ } else {
48+ runner . cwd = rootPath ;
49+ const resp = await runner . execute ( "tsc" , [ "--project" , "tsconfig.build.json" ] ) ;
50+ if ( resp . exitCode !== 0 ) {
51+ throw new Error ( `Failed to build: ${ resp . stderr } ` ) ;
52+ }
4153 }
4254 } ;
4355
4456 const copy = async ( ) : Promise < void > => {
4557 // TODO: If watching, copy every time they change.
4658 await Promise . all ( [
4759 "packages/protocol/src/proto" ,
48- [ "tsconfig.runtime.json" , "tsconfig.json" ] ,
4960 ] . map ( ( p ) => fse . copy (
50- path . resolve ( __dirname , ".." , Array . isArray ( p ) ? p [ 0 ] : p ) ,
51- path . resolve ( outPath , Array . isArray ( p ) ? p [ 1 ] : p ) ,
61+ path . resolve ( rootPath , p ) ,
62+ path . resolve ( outPath , p ) ,
5263 ) ) ) ;
5364 fse . unlinkSync ( path . resolve ( outPath , "packages/protocol/src/proto/index.ts" ) ) ;
5465 } ;
@@ -64,15 +75,14 @@ register("build", async (runner, logger, shouldWatch: string) => {
6475 * Bundle built code into a binary with nbin.
6576 */
6677register ( "bundle" , async ( ) => {
67- const root = path . join ( __dirname , ".." ) ;
6878 const bin = new Binary ( {
69- mainFile : path . join ( root , "out/packages/server/src/cli .js" ) ,
79+ mainFile : path . join ( rootPath , "out/packages/server/src/bootstrap .js" ) ,
7080 target : platform ( ) === "darwin" ? "darwin" : platform ( ) === "musl" ? "alpine" : "linux" ,
7181 } ) ;
7282
73- bin . writeFiles ( path . join ( root , "lib/**" ) ) ;
74- bin . writeFiles ( path . join ( root , "out/**" ) ) ;
75- bin . writeFiles ( path . join ( root , "**/node_modules" ) ) ;
83+ bin . writeFiles ( path . join ( rootPath , "lib/**" ) ) ;
84+ bin . writeFiles ( path . join ( rootPath , "out/**" ) ) ;
85+ bin . writeFiles ( path . join ( rootPath , "**/node_modules/** " ) ) ;
7686
7787 fse . mkdirpSync ( releasePath ) ;
7888
0 commit comments