1
1
import { Binary } from "@coder/nbin" ;
2
- import { logger , field } from "@coder/logger" ;
2
+ import { field } from "@coder/logger" ;
3
3
import { register , run } from "@coder/runner" ;
4
4
5
5
import * as fs from "fs" ;
@@ -11,25 +11,25 @@ import * as tar from "tar";
11
11
12
12
import { platform } from "./platform" ;
13
13
14
- const libDir = path . join ( __dirname , "../lib" ) ;
14
+ const libPath = path . join ( __dirname , "../lib" ) ;
15
15
const releasePath = path . resolve ( __dirname , "../release" ) ;
16
16
const target = `${ platform ( ) } -${ os . arch ( ) } ` ;
17
- const vscodeVersion = process . env . VSCODE_VERSION || "1.34 .0" ;
17
+ const vscodeVersion = process . env . VSCODE_VERSION || "1.35 .0" ;
18
18
19
19
/**
20
20
* Build source.
21
21
*/
22
- register ( "build" , async ( runner , shouldWatch : string ) => {
22
+ register ( "build" , async ( runner , logger , shouldWatch : string ) => {
23
23
const watch = shouldWatch === "true" ;
24
24
25
25
logger . info ( "Building" , field ( "env" , {
26
26
NODE_ENV : process . env . NODE_ENV ,
27
27
VERSION : process . env . VERSION ,
28
28
} ) , field ( "vscode" , vscodeVersion ) , field ( "watch" , watch ) ) ;
29
29
30
- const outDir = path . join ( __dirname , "../out" ) ;
30
+ const outPath = path . join ( __dirname , "../out" ) ;
31
31
const compile = async ( ) : Promise < void > => {
32
- fse . removeSync ( path . resolve ( outDir ) ) ;
32
+ fse . removeSync ( path . resolve ( outPath ) ) ;
33
33
34
34
runner . cwd = path . resolve ( __dirname , ".." ) ;
35
35
const resp = await runner . execute (
@@ -48,15 +48,15 @@ register("build", async (runner, shouldWatch: string) => {
48
48
[ "tsconfig.runtime.json" , "tsconfig.json" ] ,
49
49
] . map ( ( p ) => fse . copy (
50
50
path . resolve ( __dirname , ".." , Array . isArray ( p ) ? p [ 0 ] : p ) ,
51
- path . resolve ( outDir , Array . isArray ( p ) ? p [ 1 ] : p ) ,
51
+ path . resolve ( outPath , Array . isArray ( p ) ? p [ 1 ] : p ) ,
52
52
) ) ) ;
53
- fse . unlinkSync ( path . resolve ( outDir , "packages/protocol/src/proto/index.ts" ) ) ;
53
+ fse . unlinkSync ( path . resolve ( outPath , "packages/protocol/src/proto/index.ts" ) ) ;
54
54
} ;
55
55
56
+ await ensureInstalled ( ) ,
56
57
await Promise . all ( [
57
58
await compile ( ) ,
58
59
await copy ( ) ,
59
- await ensureInstalled ( ) ,
60
60
] ) ;
61
61
} ) ;
62
62
@@ -70,8 +70,9 @@ register("bundle", async () => {
70
70
target : platform ( ) === "darwin" ? "darwin" : platform ( ) === "musl" ? "alpine" : "linux" ,
71
71
} ) ;
72
72
73
+ bin . writeFiles ( path . join ( root , "lib/**" ) ) ;
73
74
bin . writeFiles ( path . join ( root , "out/**" ) ) ;
74
- // TODO: dependencies ( node_modules).
75
+ bin . writeFiles ( path . join ( root , "**/ node_modules" ) ) ;
75
76
76
77
fse . mkdirpSync ( releasePath ) ;
77
78
@@ -89,41 +90,65 @@ register("bundle", async () => {
89
90
/**
90
91
* Make sure the expected VS code version has been downloaded.
91
92
*/
92
- const ensureInstalled = register ( "vscode:install" , async ( runner ) => {
93
- runner . cwd = libDir ;
93
+ const ensureInstalled = register ( "vscode:install" , async ( runner , logger ) => {
94
+ const vscodePath = path . join ( libPath , "vscode" ) ;
95
+
96
+ const build = async ( ) : Promise < void > => {
97
+ runner . cwd = vscodePath ;
98
+ if ( ! fs . existsSync ( path . join ( vscodePath , "node_modules" ) ) ) {
99
+ await runner . execute ( "yarn" ) ;
100
+ }
101
+ if ( ! fs . existsSync ( path . join ( vscodePath , "out" ) ) ) {
102
+ await runner . execute ( "yarn" , [ "compile" ] ) ;
103
+ }
104
+ } ;
105
+
106
+ const clone = async ( ) : Promise < void > => {
107
+ runner . cwd = libPath ;
108
+ await runner . execute ( "git" , [
109
+ "clone" , "https://github.com/microsoft/vscode" ,
110
+ "--branch" , `${ vscodeVersion } ` , "--single-branch" , "--depth=1" ,
111
+ ] ) ;
112
+ } ;
94
113
95
114
// See if we already have the correct version downloaded.
96
- const vscodePath = path . join ( libDir , "vscode" ) ;
97
115
if ( fs . existsSync ( vscodePath ) ) {
98
116
const pkgVersion = JSON . parse (
99
117
fs . readFileSync ( path . join ( vscodePath , "package.json" ) ) . toString ( "utf8" ) ,
100
118
) . version ;
101
119
if ( pkgVersion === vscodeVersion ) {
102
- // TODO: check that it has been properly built along with dependencies.
103
- return ;
120
+ logger . info ( `Found existing VS Code ${ vscodeVersion } installation` ) ;
121
+
122
+ return build ( ) ;
104
123
}
105
124
}
106
125
107
- fse . removeSync ( libDir ) ;
108
- fse . mkdirpSync ( libDir ) ;
126
+ fse . removeSync ( libPath ) ;
127
+ fse . mkdirpSync ( libPath ) ;
109
128
129
+ // If we can, fetch the pre-built version to save time. Otherwise we'll need
130
+ // to clone and build.
110
131
await new Promise < void > ( ( resolve , reject ) : void => {
111
- const vsSourceUrl = `https://codesrv-ci.cdr.sh/vstar -${ vscodeVersion } .tar.gz` ;
132
+ const vsSourceUrl = `https://codesrv-ci.cdr.sh/vscode -${ vscodeVersion } -prebuilt .tar.gz` ;
112
133
https . get ( vsSourceUrl , ( res ) => {
113
134
switch ( res . statusCode ) {
114
- case 200 : break ;
115
- // TODO: if it hasn't been packaged, clone and build it instead.
116
- case 404 : return reject ( new Error ( `${ vscodeVersion } has not been packaged yet` ) ) ;
117
- default : return reject ( new Error ( res . statusMessage ) ) ;
135
+ case 200 :
136
+ logger . info ( `Downloading pre-built VS Code ${ vscodeVersion } ` ) ;
137
+ res . pipe ( tar . x ( {
138
+ C : libPath ,
139
+ } ) . on ( "finish" , ( ) => {
140
+ resolve ( ) ;
141
+ } ) . on ( "error" , ( err : Error ) => {
142
+ reject ( err ) ;
143
+ } ) ) ;
144
+ break ;
145
+ case 404 :
146
+ logger . info ( `VS Code ${ vscodeVersion } hasn't been packaged yet` ) ;
147
+ clone ( ) . then ( ( ) => build ( ) ) . catch ( reject ) ;
148
+ break ;
149
+ default :
150
+ return reject ( new Error ( res . statusMessage ) ) ;
118
151
}
119
-
120
- res . pipe ( tar . x ( {
121
- C : libDir ,
122
- } ) . on ( "finish" , ( ) => {
123
- resolve ( ) ;
124
- } ) . on ( "error" , ( err : Error ) => {
125
- reject ( err ) ;
126
- } ) ) ;
127
152
} ) . on ( "error" , ( err ) => {
128
153
reject ( err ) ;
129
154
} ) ;
@@ -133,7 +158,7 @@ const ensureInstalled = register("vscode:install", async (runner) => {
133
158
/**
134
159
* Package the binary, readme, and license into an archive.
135
160
*/
136
- register ( "package" , async ( runner , releaseTag ) => {
161
+ register ( "package" , async ( runner , _logger , releaseTag ) => {
137
162
if ( ! releaseTag ) {
138
163
throw new Error ( "Please specify the release tag." ) ;
139
164
}
0 commit comments