@@ -4,21 +4,22 @@ import * as fse from "fs-extra";
4
4
import * as os from "os" ;
5
5
import * as path from "path" ;
6
6
import * as zlib from "zlib" ;
7
+ import * as https from "https" ;
8
+ import * as tar from "tar" ;
7
9
8
10
const isWin = os . platform ( ) === "win32" ;
9
11
const libPath = path . join ( __dirname , "../lib" ) ;
10
12
const vscodePath = path . join ( libPath , "vscode" ) ;
13
+ const defaultExtensionsPath = path . join ( libPath , "extensions" ) ;
11
14
const pkgsPath = path . join ( __dirname , "../packages" ) ;
12
- const defaultExtensionsPath = path . join ( libPath , "VSCode-linux-x64/resources/app/extensions" ) ;
13
15
const vscodeVersion = process . env . VSCODE_VERSION || "1.32.0" ;
16
+ const vsSourceUrl = `https://codesrv-ci.cdr.sh/vstar-${ vscodeVersion } .tar.gz` ;
14
17
15
18
const buildServerBinary = register ( "build:server:binary" , async ( runner ) => {
16
19
await ensureInstalled ( ) ;
17
- await copyForDefaultExtensions ( ) ;
18
20
await Promise . all ( [
19
21
buildBootstrapFork ( ) ,
20
22
buildWeb ( ) ,
21
- buildDefaultExtensions ( ) ,
22
23
buildServerBundle ( ) ,
23
24
buildAppBrowser ( ) ,
24
25
] ) ;
@@ -129,97 +130,50 @@ const buildWeb = register("build:web", async (runner) => {
129
130
await runner . execute ( isWin ? "npm.cmd" : "npm" , [ "run" , "build" ] ) ;
130
131
} ) ;
131
132
132
- const extDirPath = path . join ( "lib" , "vscode-default-extensions" ) ;
133
- const copyForDefaultExtensions = register ( "build:copy-vscode" , async ( runner ) => {
134
- if ( ! fs . existsSync ( defaultExtensionsPath ) ) {
135
- await ensureClean ( ) ;
136
- await ensureInstalled ( ) ;
137
- await new Promise ( ( resolve , reject ) : void => {
138
- fse . remove ( extDirPath , ( err ) => {
139
- if ( err ) {
140
- return reject ( err ) ;
141
- }
142
-
143
- resolve ( ) ;
144
- } ) ;
145
- } ) ;
146
- await new Promise ( ( resolve , reject ) : void => {
147
- fse . copy ( vscodePath , extDirPath , ( err ) => {
148
- if ( err ) {
149
- return reject ( err ) ;
150
- }
151
-
152
- resolve ( ) ;
153
- } ) ;
154
- } ) ;
155
- }
156
- } ) ;
157
-
158
- const buildDefaultExtensions = register ( "build:default-extensions" , async ( runner ) => {
159
- if ( ! fs . existsSync ( defaultExtensionsPath ) ) {
160
- await copyForDefaultExtensions ( ) ;
161
- runner . cwd = extDirPath ;
162
- const resp = await runner . execute ( isWin ? "npx.cmd" : "npx" , [ isWin ? "gulp.cmd" : "gulp" , "vscode-linux-x64" , "--max-old-space-size=32384" ] ) ;
163
- if ( resp . exitCode !== 0 ) {
164
- throw new Error ( `Failed to build default extensions: ${ resp . stderr } ` ) ;
165
- }
166
- }
167
- } ) ;
168
-
169
133
const ensureInstalled = register ( "vscode:install" , async ( runner ) => {
170
- await ensureCloned ( ) ;
134
+ runner . cwd = libPath ;
171
135
172
- runner . cwd = vscodePath ;
173
- const install = await runner . execute ( isWin ? "yarn.cmd" : "yarn" , [ ] ) ;
174
- if ( install . exitCode !== 0 ) {
175
- throw new Error ( `Failed to install vscode dependencies: ${ install . stderr } ` ) ;
176
- }
177
- } ) ;
136
+ if ( fs . existsSync ( vscodePath ) && fs . existsSync ( defaultExtensionsPath ) ) {
137
+ const pkgVersion = JSON . parse ( fs . readFileSync ( path . join ( vscodePath , "package.json" ) ) . toString ( "utf8" ) ) . version ;
138
+ if ( pkgVersion === vscodeVersion ) {
139
+ runner . cwd = vscodePath ;
178
140
179
- const ensureCloned = register ( "vscode:clone" , async ( runner ) => {
180
- if ( fs . existsSync ( vscodePath ) ) {
181
- await ensureClean ( ) ;
182
- } else {
183
- fse . mkdirpSync ( libPath ) ;
184
- runner . cwd = libPath ;
185
- const clone = await runner . execute ( "git" , [ "clone" , "https://github.com/microsoft/vscode" , "--branch" , vscodeVersion , "--single-branch" , "--depth=1" ] ) ;
186
- if ( clone . exitCode !== 0 ) {
187
- throw new Error ( `Failed to clone: ${ clone . exitCode } ` ) ;
141
+ const reset = await runner . execute ( "git" , [ "reset" , "--hard" ] ) ;
142
+ if ( reset . exitCode !== 0 ) {
143
+ throw new Error ( `Failed to clean git repository: ${ reset . stderr } ` ) ;
144
+ }
145
+
146
+ return ;
188
147
}
189
148
}
190
149
191
- runner . cwd = vscodePath ;
192
- const checkout = await runner . execute ( "git" , [ "checkout" , vscodeVersion ] ) ;
193
- if ( checkout . exitCode !== 0 ) {
194
- throw new Error ( `Failed to checkout: ${ checkout . stderr } ` ) ;
195
- }
196
- } ) ;
150
+ fse . removeSync ( libPath ) ;
151
+ fse . mkdirpSync ( libPath ) ;
197
152
198
- const ensureClean = register ( "vscode:clean" , async ( runner ) => {
199
- runner . cwd = vscodePath ;
153
+ await new Promise < void > ( ( resolve , reject ) : void => {
154
+ https . get ( vsSourceUrl , ( res ) => {
155
+ if ( res . statusCode !== 200 ) {
156
+ return reject ( res . statusMessage ) ;
157
+ }
200
158
201
- const status = await runner . execute ( "git" , [ "status" , "--porcelain" ] ) ;
202
- if ( status . stdout . trim ( ) !== "" ) {
203
- const clean = await runner . execute ( "git" , [ "clean" , "-f" , "-d" , "-X" ] ) ;
204
- if ( clean . exitCode !== 0 ) {
205
- throw new Error ( `Failed to clean git repository: ${ clean . stderr } ` ) ;
206
- }
207
- const removeUnstaged = await runner . execute ( "git" , [ "checkout" , "--" , "." ] ) ;
208
- if ( removeUnstaged . exitCode !== 0 ) {
209
- throw new Error ( `Failed to remove unstaged files: ${ removeUnstaged . stderr } ` ) ;
210
- }
211
- }
212
- const fetch = await runner . execute ( "git" , [ "fetch" , "--prune" ] ) ;
213
- if ( fetch . exitCode !== 0 ) {
214
- throw new Error ( `Failed to fetch latest changes: ${ fetch . stderr } ` ) ;
215
- }
159
+ res . pipe ( tar . x ( {
160
+ C : libPath ,
161
+ } ) . on ( "finish" , ( ) => {
162
+ resolve ( ) ;
163
+ } ) . on ( "error" , ( err : Error ) => {
164
+ reject ( err ) ;
165
+ } ) ) ;
166
+ } ) . on ( "error" , ( err ) => {
167
+ reject ( err ) ;
168
+ } ) ;
169
+ } ) ;
216
170
} ) ;
217
171
218
172
const ensurePatched = register ( "vscode:patch" , async ( runner ) => {
219
173
if ( ! fs . existsSync ( vscodePath ) ) {
220
174
throw new Error ( "vscode must be cloned to patch" ) ;
221
175
}
222
- await ensureClean ( ) ;
176
+ await ensureInstalled ( ) ;
223
177
224
178
runner . cwd = vscodePath ;
225
179
const patchPath = path . join ( __dirname , "../scripts/vscode.patch" ) ;
0 commit comments