ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / build / next / build-fast.ts 529 строк · изменён 14 нояб., 04:52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
import { spawn } from 'child_process' ;
import { createHash } from 'crypto' ;
import * as esbuild from 'esbuild' ;
import * as fs from 'fs' ;
import * as path from 'path' ;
import { getGitCommitDate } from '../lib/date.ts' ;
import { applyIncrementalClientChanges, mapWithConcurrency, MAX_CONCURRENT_FILE_OPERATIONS } from './transpile.ts' ;
const STATE_SCHEMA =
schema
recipe
head
environment
dirty Readonly Record Fingerprint
head
dirty Readonly Record Fingerprint
reason
changedPaths
client LaneMode
extensions LaneMode
copilot LaneMode
tasks
clientChangedPaths
state BuildFastState
reason
client
extensions
copilot
repoRoot force
stateDir path repoRoot
fs promises stateDir recursive
lock path stateDir
environment repoRoot
statePath path stateDir
saved statePath
before BuildFastSnapshot
committedPaths
before repoRoot
committedPaths saved state repoRoot saved state head before head
error
fs promises statePath force
repoRoot
changedPaths saved state before committedPaths
outputs repoRoot
plan saved environment changedPaths outputs force
plan
hasBuildWork plan client plan extensions plan copilot
hasBuildWork saved state head before head
hasBuildWork
fs promises statePath force
fullBuild plan client plan extensions
prerequisites fullBuild plan changedPaths
prerequisites tasks length
repoRoot prerequisites tasks
before repoRoot
tasks
plan client
tasks repoRoot process execPath path repoRoot
plan client
tasks repoRoot prerequisites clientChangedPaths
plan extensions
tasks repoRoot
tasks
after repoRoot
snapshot builtSnapshot inputsChanged before after
inputsChanged
outputStatus repoRoot
plan outputStatus
saved state head builtSnapshot head inputsChanged
fs promises path repoRoot
statePath
schema
recipe
head builtSnapshot head
environment
dirty builtSnapshot dirty
lock
fullBuild changedPaths BuildFastPrerequisites
apiProposalsChanged changedPaths filePath filePath filePath
extensionPointsOutputChanged changedPaths
tasks fullBuild
apiProposalsChanged
extensionPointsOutputChanged
clientChangedPaths
changedPaths
apiProposalsChanged
extensionPointsOutputChanged
tasks clientChangedPaths
saved BuildFastState current BuildFastSnapshot committedPaths
saved
changed committedPaths
filePath fingerprint Object current dirty
Object saved dirty filePath saved dirty filePath fingerprint
changed filePath
filePath Object saved dirty
Object current dirty filePath
changed filePath
changed
before BuildFastSnapshot after BuildFastSnapshot snapshot BuildFastSnapshot inputsChanged
inputsChanged before after
snapshot inputsChanged before after inputsChanged
saved StateReadResult environment changedPaths outputs OutputStatus force BuildFastPlan
force
changedPaths
saved state
saved reason changedPaths
saved state schema saved state recipe
changedPaths
saved state environment environment
changedPaths
changedPaths isGlobalBuildInput
changedPaths
client LaneMode outputs client
extensions LaneMode outputs extensions
copilot LaneMode
filePath changedPaths
filePath
client
client
filePath
filePath filePath
extensions
reasons
outputs client
reasons
outputs extensions
reasons
changedPaths length
reasons
reason reasons
changedPaths
client
extensions
copilot
output Buffer
output Boolean normalizePath
repoRoot BuildFastSnapshot
headOutput trackedOutput untrackedOutput
repoRoot
repoRoot
repoRoot
head headOutput
dirtyPaths trackedOutput untrackedOutput
dirtyEntries dirtyPaths filePath
filePath path repoRoot filePath
head dirty Object dirtyEntries
repoRoot savedHead currentHead
savedHead currentHead
output repoRoot savedHead currentHead
output
repoRoot args Buffer
resolve reject
child args cwd repoRoot stdio
stdout Buffer
stderr Buffer
child stdout data stdout data
child stderr data stderr data
child reject
child code
code
Buffer stdout
filePath Fingerprint
content fs promises filePath
content
error
error error
error
statePath StateReadResult
value
value fs promises statePath
error
state reason error
value
state reason
state value reason
statePath state BuildFastState
temporaryPath
fs promises temporaryPath
fs promises temporaryPath statePath
value value BuildFastState
value
value schema
value recipe
value head
value environment
value dirty
Object value dirty fingerprint fingerprint fingerprint
value value Record
value value value
filePath
filePath
filePath
filePath
filePath
filePath
reason changedPaths BuildFastPlan
reason changedPaths client extensions copilot
repoRoot OutputStatus
client extensions
path repoRoot
path repoRoot
client extensions copilot
plan BuildFastPlan outputs OutputStatus
plan client outputs client
plan extensions outputs extensions
plan copilot outputs copilot
repoRoot
repoRoot
repoRoot process execPath path repoRoot
repoRoot
cwd command args label
label resolve reject
useShell process platform path command
child command args cwd stdio shell useShell
child reject
child code
code
tasks
results tasks
failure results result result PromiseRejectedResult result status
failure
failure reason
label
start Date
plan BuildFastPlan
repoRoot
copilotPackage fs path repoRoot
devDependencies Readonly Record
lockPath Lock
handle fs promises lockPath
handle process pid
handle
fs promises lockPath force
error
error
error
owner lockPath
owner owner
owner lockPath
lockPath
stat fs promises lockPath
Date stat mtimeMs
error
error
error
lockPath
owner Number fs promises lockPath
Number owner owner owner
error
error
error
pid
process pid
error
error
first BuildFastSnapshot second BuildFastSnapshot
first head second head first dirty second dirty
filePath
fs promises filePath
error
error
error
filePath
filePath
process platform
error
error error message error
error error NodeJS ErrnoException
error error error code error code
error error NodeJS ErrnoException
error error error code
error error NodeJS ErrnoException
error error error code
error error NodeJS ErrnoException
error error error code
1
;
const
BUILD_RECIPE
=
1
;
const
LOCK_STALE_AFTER_MS
=
30_000
;
const
BUILD_SCOPES
=
[
'src'
,
'extensions'
,
'.vscode/extensions'
,
'build'
,
'gulpfile.mjs'
,
'package.json'
,
'package-lock.json'
,
'.nvmrc'
]
;
const
API_PROPOSALS_OUTPUT
=
'src/vs/platform/extensions/common/extensionsApiProposals.ts'
;
const
EXTENSION_POINTS_OUTPUT
=
'src/vs/workbench/services/extensions/common/extensionPoints.json'
;
const
EXTENSION_BUILD_ARGS
=
[
'run'
,
'gulp'
,
'compile-extensions'
,
'compile-extension-media'
]
;
type
Fingerprint
=
string
|
null
;
type
LaneMode
=
'skip'
|
'incremental'
|
'full'
;
export
interface
BuildFastState
{
readonly
:
number
;
readonly
:
number
;
readonly
:
string
;
readonly
:
string
;
readonly
:
<
<
string
,
>>
;
}
export
interface
BuildFastSnapshot
{
readonly
:
string
;
readonly
:
<
<
string
,
>>
;
}
export
interface
BuildFastPlan
{
readonly
:
string
;
readonly
:
readonly
string
[
]
;
readonly
:
;
readonly
:
;
readonly
:
;
}
export
interface
BuildFastPrerequisites
{
readonly
:
readonly
string
[
]
;
readonly
:
readonly
string
[
]
;
}
export
interface
StateReadResult
{
readonly
:
|
undefined
;
readonly
:
string
|
undefined
;
}
export
interface
OutputStatus
{
readonly
:
boolean
;
readonly
:
boolean
;
readonly
:
boolean
;
}
interface
Lock
{
dispose
(
)
:
Promise
<
void
>
;
}
export
async
function
runBuildFast
(
:
string
,
:
boolean
)
:
Promise
<
void
>
{
const
=
.
join
(
,
'.build'
,
'build-fast'
)
;
await
.
.
mkdir
(
,
{
:
true
}
)
;
const
=
await
acquireLock
(
.
join
(
,
'lock'
)
)
;
try
{
const
=
readEnvironment
(
)
;
const
=
.
join
(
,
'state.json'
)
;
const
=
await
readState
(
)
;
let
:
;
let
:
readonly
string
[
]
;
try
{
=
await
collectSnapshot
(
)
;
=
.
?
await
getCommittedPaths
(
,
.
.
,
.
)
:
[
]
;
}
catch
(
)
{
console
.
warn
(
` [build-fast] Git discovery failed; running a full build without updating incremental state: ${ getErrorMessage ( error) } `
)
;
await
.
.
rm
(
,
{
:
true
}
)
;
await
runAllFull
(
)
;
return
;
}
const
=
computeChangedPaths
(
.
,
,
)
;
const
=
await
getOutputStatus
(
)
;
const
=
createBuildPlan
(
,
,
,
,
)
;
logPlan
(
)
;
const
=
.
!==
'skip'
||
.
!==
'skip'
||
.
!==
'skip'
;
if
(
!
&&
.
?.
===
.
)
{
return
;
}
if
(
)
{
await
.
.
rm
(
,
{
:
true
}
)
;
}
const
=
.
===
'full'
&&
.
===
'full'
;
const
=
createBuildFastPrerequisites
(
,
.
)
;
if
(
.
.
>
0
)
{
await
runCommand
(
,
npmCommand
(
)
,
[
'run'
,
'gulp'
,
...
.
]
,
'prerequisites'
)
;
=
await
collectSnapshot
(
)
;
}
const
:
Promise
<
void
>
[
]
=
[
]
;
if
(
.
===
'full'
)
{
.
push
(
runCommand
(
,
.
,
[
.
join
(
,
'build'
,
'next'
,
'index.ts'
)
,
'transpile'
]
,
'client'
)
)
;
}
else
if
(
.
===
'incremental'
)
{
.
push
(
runTimed
(
'client'
,
(
)
=>
applyIncrementalClientChanges
(
,
'out'
,
.
)
)
)
;
}
if
(
.
===
'full'
)
{
.
push
(
runCommand
(
,
npmCommand
(
)
,
EXTENSION_BUILD_ARGS
,
'extensions'
)
)
;
}
await
waitForTasks
(
)
;
const
=
await
collectSnapshot
(
)
;
const
{
:
,
}
=
selectBuiltSnapshot
(
,
)
;
if
(
)
{
console
.
warn
(
'[build-fast] Inputs changed during the build; late changes will be rebuilt on the next run.'
)
;
}
const
=
await
getOutputStatus
(
)
;
validateSelectedOutputs
(
,
)
;
if
(
.
?.
!==
.
&&
!
)
{
await
.
.
writeFile
(
.
join
(
,
'out'
,
'date'
)
,
getGitCommitDate
(
)
,
'utf8'
)
;
}
await
writeState
(
,
{
:
STATE_SCHEMA
,
:
BUILD_RECIPE
,
:
.
,
,
:
.
,
}
)
;
}
finally
{
await
.
dispose
(
)
;
}
}
export
function
createBuildFastPrerequisites
(
:
boolean
,
:
readonly
string
[
]
)
:
{
const
=
.
some
(
=>
.
startsWith
(
'src/vscode-dts/'
)
||
===
API_PROPOSALS_OUTPUT
)
;
const
=
.
includes
(
EXTENSION_POINTS_OUTPUT
)
;
const
=
?
[
'copy-codicons'
,
'compile-api-proposal-names'
,
'compile-extension-point-names'
]
:
[
...
(
?
[
'compile-api-proposal-names'
]
:
[
]
)
,
...
(
?
[
'compile-extension-point-names'
]
:
[
]
)
,
]
;
const
=
[
...
new
Set
(
[
...
,
...
(
?
[
API_PROPOSALS_OUTPUT
]
:
[
]
)
,
...
(
?
[
EXTENSION_POINTS_OUTPUT
]
:
[
]
)
,
]
)
]
;
return
{
,
}
;
}
export
function
computeChangedPaths
(
:
|
undefined
,
:
,
:
readonly
string
[
]
)
:
string
[
]
{
if
(
!
)
{
return
[
]
;
}
const
=
new
Set
(
)
;
for
(
const
[
,
]
of
.
entries
(
.
)
)
{
if
(
!
.
hasOwn
(
.
,
)
||
.
[
]
!==
)
{
.
add
(
)
;
}
}
for
(
const
of
.
keys
(
.
)
)
{
if
(
!
.
hasOwn
(
.
,
)
)
{
.
add
(
)
;
}
}
return
[
...
]
.
sort
(
)
;
}
export
function
selectBuiltSnapshot
(
:
,
:
)
:
{
:
;
:
boolean
}
{
const
=
!
snapshotsEqual
(
,
)
;
return
{
:
?
:
,
}
;
}
export
function
createBuildPlan
(
:
,
:
string
,
:
readonly
string
[
]
,
:
,
:
boolean
)
:
{
if
(
)
{
return
fullPlan
(
'forced by --force'
,
)
;
}
if
(
!
.
)
{
return
fullPlan
(
.
??
'incremental state is unavailable'
,
)
;
}
if
(
.
.
!==
STATE_SCHEMA
||
.
.
!==
BUILD_RECIPE
)
{
return
fullPlan
(
'incremental state schema or recipe changed'
,
)
;
}
if
(
.
.
!==
)
{
return
fullPlan
(
'build environment changed'
,
)
;
}
if
(
.
some
(
)
)
{
return
fullPlan
(
'build configuration or dependencies changed'
,
)
;
}
let
:
=
.
?
'skip'
:
'full'
;
let
:
=
.
?
'skip'
:
'full'
;
let
:
=
'skip'
;
for
(
const
of
)
{
if
(
.
startsWith
(
'src/'
)
)
{
if
(
===
'skip'
)
{
=
'incremental'
;
}
}
else
if
(
.
startsWith
(
'extensions/copilot/'
)
)
{
continue
;
}
else
if
(
.
startsWith
(
'extensions/'
)
||
.
startsWith
(
'.vscode/extensions/'
)
)
{
=
'full'
;
}
}
const
:
string
[
]
=
[
]
;
if
(
!
.
)
{
.
push
(
'client output is missing'
)
;
}
if
(
!
.
)
{
.
push
(
'extension output is missing'
)
;
}
if
(
.
>
0
)
{
.
push
(
` ${ changedPaths. length} input path(s) changed `
)
;
}
return
{
:
.
join
(
'; '
)
||
'inputs and outputs are up to date'
,
,
,
,
,
}
;
}
export
function
parseNullSeparatedPaths
(
:
)
:
string
[
]
{
return
.
toString
(
'utf8'
)
.
split
(
'\0'
)
.
filter
(
)
.
map
(
)
;
}
export
async
function
collectSnapshot
(
:
string
)
:
Promise
<
>
{
const
[
,
,
]
=
await
Promise
.
all
(
[
runGit
(
,
[
'rev-parse'
,
'HEAD'
]
)
,
runGit
(
,
[
'diff'
,
'--name-only'
,
'-z'
,
'--no-renames'
,
'HEAD'
,
'--'
,
...
BUILD_SCOPES
]
)
,
runGit
(
,
[
'ls-files'
,
'--others'
,
'--exclude-standard'
,
'-z'
,
'--'
,
...
BUILD_SCOPES
]
)
,
]
)
;
const
=
.
toString
(
'utf8'
)
.
trim
(
)
;
const
=
new
Set
(
[
...
parseNullSeparatedPaths
(
)
,
...
parseNullSeparatedPaths
(
)
]
)
;
const
=
await
mapWithConcurrency
(
[
...
]
.
sort
(
)
,
MAX_CONCURRENT_FILE_OPERATIONS
,
async
=>
{
return
[
,
await
fingerprintFile
(
.
join
(
,
)
)
]
as
const
;
}
)
;
return
{
,
:
.
fromEntries
(
)
}
;
}
async
function
getCommittedPaths
(
:
string
,
:
string
,
:
string
)
:
Promise
<
string
[
]
>
{
if
(
===
)
{
return
[
]
;
}
const
=
await
runGit
(
,
[
'diff'
,
'--name-only'
,
'-z'
,
'--no-renames'
,
,
,
'--'
,
...
BUILD_SCOPES
]
)
;
return
parseNullSeparatedPaths
(
)
;
}
async
function
runGit
(
:
string
,
:
readonly
string
[
]
)
:
Promise
<
>
{
return
new
Promise
(
(
,
)
=>
{
const
=
spawn
(
'git'
,
,
{
:
,
:
[
'ignore'
,
'pipe'
,
'pipe'
]
}
)
;
const
:
[
]
=
[
]
;
const
:
[
]
=
[
]
;
.
.
on
(
'data'
,
=>
.
push
(
)
)
;
.
.
on
(
'data'
,
=>
.
push
(
)
)
;
.
on
(
'error'
,
)
;
.
on
(
'close'
,
=>
{
if
(
===
0
)
{
resolve
(
.
concat
(
)
)
;
}
else
{
reject
(
new
Error
(
` git ${ args[ 0 ] } failed with exit code ${ code} : ${ Buffer. concat ( stderr) . toString ( 'utf8' ) . trim ( ) } `
)
)
;
}
}
)
;
}
)
;
}
async
function
fingerprintFile
(
:
string
)
:
Promise
<
>
{
try
{
const
=
await
.
.
readFile
(
)
;
return
createHash
(
'sha256'
)
.
update
(
)
.
digest
(
'hex'
)
;
}
catch
(
)
{
if
(
isPathMissing
(
)
||
isDirectoryRead
(
)
)
{
return
null
;
}
throw
;
}
}
async
function
readState
(
:
string
)
:
Promise
<
>
{
let
:
unknown
;
try
{
=
JSON
.
parse
(
await
.
.
readFile
(
,
'utf8'
)
)
;
}
catch
(
)
{
return
{
:
undefined
,
:
isPathMissing
(
)
?
'incremental state is missing'
:
'incremental state is unreadable'
}
;
}
if
(
!
isBuildFastState
(
)
)
{
return
{
:
undefined
,
:
'incremental state is malformed'
}
;
}
return
{
:
,
:
undefined
}
;
}
async
function
writeState
(
:
string
,
:
)
:
Promise
<
void
>
{
const
=
` ${ statePath} . ${ process. pid} .tmp `
;
await
.
.
writeFile
(
,
` ${ JSON . stringify ( state, null , '\t' ) } \n `
,
'utf8'
)
;
await
.
.
rename
(
,
)
;
}
function
isBuildFastState
(
:
unknown
)
:
is
{
if
(
!
isRecord
(
)
||
typeof
.
!==
'number'
||
typeof
.
!==
'number'
||
typeof
.
!==
'string'
||
typeof
.
!==
'string'
||
!
isRecord
(
.
)
)
{
return
false
;
}
return
.
values
(
.
)
.
every
(
=>
===
null
||
typeof
===
'string'
)
;
}
function
isRecord
(
:
unknown
)
:
is
<
string
,
unknown
>
{
return
typeof
===
'object'
&&
!==
null
&&
!
Array
.
isArray
(
)
;
}
function
isGlobalBuildInput
(
:
string
)
:
boolean
{
return
.
startsWith
(
'build/'
)
||
===
'gulpfile.mjs'
||
===
'package.json'
||
===
'package-lock.json'
||
===
'.nvmrc'
;
}
function
fullPlan
(
:
string
,
:
readonly
string
[
]
)
:
{
return
{
,
,
:
'full'
,
:
'full'
,
:
'skip'
}
;
}
async
function
getOutputStatus
(
:
string
)
:
Promise
<
>
{
const
[
,
]
=
await
Promise
.
all
(
[
pathExists
(
.
join
(
,
'out'
,
'main.js'
)
)
,
pathExists
(
.
join
(
,
'extensions'
,
'configuration-editing'
,
'out'
,
'configurationEditingMain.js'
)
)
,
]
)
;
return
{
,
,
:
true
}
;
}
function
validateSelectedOutputs
(
:
,
:
)
:
void
{
if
(
.
!==
'skip'
&&
!
.
)
{
throw
new
Error
(
'Client build completed without producing out/main.js.'
)
;
}
if
(
.
!==
'skip'
&&
!
.
)
{
throw
new
Error
(
'Extension build completed without producing the expected configuration-editing output.'
)
;
}
if
(
.
!==
'skip'
&&
!
.
)
{
throw
new
Error
(
'Copilot build completed without producing dist/extension.js.'
)
;
}
}
async
function
runAllFull
(
:
string
)
:
Promise
<
void
>
{
await
runCommand
(
,
npmCommand
(
)
,
[
'run'
,
'gulp'
,
'copy-codicons'
,
'compile-api-proposal-names'
,
'compile-extension-point-names'
,
]
,
'prerequisites'
)
;
await
waitForTasks
(
[
runCommand
(
,
.
,
[
.
join
(
,
'build'
,
'next'
,
'index.ts'
)
,
'transpile'
]
,
'client'
)
,
runCommand
(
,
npmCommand
(
)
,
EXTENSION_BUILD_ARGS
,
'extensions'
)
,
]
)
;
}
async
function
runCommand
(
:
string
,
:
string
,
:
readonly
string
[
]
,
:
string
)
:
Promise
<
void
>
{
return
runTimed
(
,
(
)
=>
new
Promise < void >
(
(
,
)
=>
{
const
=
.
===
'win32'
&&
.
basename
(
)
.
toLowerCase
(
)
===
'npm.cmd'
;
const
=
spawn
(
,
,
{
,
:
'inherit'
,
:
}
)
;
.
on
(
'error'
,
)
;
.
on
(
'close'
,
=>
{
if
(
===
0
)
{
resolve
(
)
;
}
else
{
reject
(
new
Error
(
` ${ label} build failed with exit code ${ code} `
)
)
;
}
}
)
;
}
)
)
;
}
async
function
waitForTasks
(
:
readonly
Promise
<
void
>
[
]
)
:
Promise
<
void
>
{
const
=
await
Promise
.
allSettled
(
)
;
const
=
.
find
(
(
)
:
is
=>
.
===
'rejected'
)
;
if
(
)
{
throw
.
;
}
}
async
function
runTimed
(
:
string
,
task
:
(
)
=>
Promise
<
void
>
)
:
Promise
<
void
>
{
const
=
.
now
(
)
;
await
task
(
)
;
console
.
log
(
` [build-fast] ${ label} finished in ${ Date. now ( ) - start} ms `
)
;
}
function
logPlan
(
:
)
:
void
{
console
.
log
(
` [build-fast] ${ plan. reason} `
)
;
console
.
log
(
` [build-fast] client= ${ plan. client} , extensions= ${ plan. extensions} , copilot= ${ plan. copilot} `
)
;
}
function
readEnvironment
(
:
string
)
:
string
{
const
=
JSON
.
parse
(
.
readFileSync
(
.
join
(
,
'extensions'
,
'copilot'
,
'package.json'
)
,
'utf8'
)
)
as
{
readonly
?
:
<
<
string
,
string
>>
;
}
;
return
[
` recipe= ${ BUILD_RECIPE } `
,
` platform= ${ process. platform} `
,
` arch= ${ process. arch} `
,
` node= ${ process. version} `
,
` esbuild= ${ esbuild. version} `
,
` copilot-esbuild= ${ copilotPackage. devDependencies?. esbuild ?? '' } `
,
]
.
join
(
';'
)
;
}
async
function
acquireLock
(
:
string
)
:
Promise
<
>
{
try
{
const
=
await
.
.
open
(
,
'wx'
)
;
await
.
writeFile
(
String
(
.
)
,
'utf8'
)
;
await
.
close
(
)
;
return
{
dispose
:
async
(
)
=>
{
await
.
.
rm
(
,
{
:
true
}
)
;
}
}
;
}
catch
(
)
{
if
(
!
isAlreadyExists
(
)
)
{
throw
;
}
}
const
=
await
readLockOwner
(
)
;
if
(
!==
undefined
&&
isProcessRunning
(
)
)
{
throw
new
Error
(
` Another build-fast process is already running (PID ${ owner} ). `
)
;
}
if
(
===
undefined
&&
await
isFreshLock
(
)
)
{
throw
new
Error
(
'Another build-fast process is acquiring the build lock.'
)
;
}
throw
new
Error
(
` A stale build-fast lock exists at ${ lockPath} . Remove it after confirming that no build-fast process is running. `
)
;
}
async
function
isFreshLock
(
:
string
)
:
Promise
<
boolean
>
{
try
{
const
=
await
.
.
stat
(
)
;
return
.
now
(
)
-
.
<
LOCK_STALE_AFTER_MS
;
}
catch
(
)
{
if
(
isPathMissing
(
)
)
{
return
false
;
}
throw
;
}
}
async
function
readLockOwner
(
:
string
)
:
Promise
<
number
|
undefined
>
{
try
{
const
=
.
parseInt
(
await
.
.
readFile
(
,
'utf8'
)
,
10
)
;
return
.
isSafeInteger
(
)
&&
>
0
?
:
undefined
;
}
catch
(
)
{
if
(
isPathMissing
(
)
)
{
return
undefined
;
}
throw
;
}
}
function
isProcessRunning
(
:
number
)
:
boolean
{
try
{
.
kill
(
,
0
)
;
return
true
;
}
catch
(
)
{
return
!
isNoSuchProcess
(
)
;
}
}
function
snapshotsEqual
(
:
,
:
)
:
boolean
{
return
.
===
.
&&
JSON
.
stringify
(
.
)
===
JSON
.
stringify
(
.
)
;
}
async
function
pathExists
(
:
string
)
:
Promise
<
boolean
>
{
try
{
await
.
.
access
(
)
;
return
true
;
}
catch
(
)
{
if
(
isPathMissing
(
)
)
{
return
false
;
}
throw
;
}
}
function
normalizePath
(
:
string
)
:
string
{
return
.
replaceAll
(
'\\'
,
'/'
)
;
}
function
npmCommand
(
)
:
string
{
return
.
===
'win32'
?
'npm.cmd'
:
'npm'
;
}
function
getErrorMessage
(
:
unknown
)
:
string
{
return
instanceof
Error
?
.
:
String
(
)
;
}
function
isPathMissing
(
:
unknown
)
:
is
.
{
return
instanceof
Error
&&
'code'
in
&&
(
.
===
'ENOENT'
||
.
===
'ENOTDIR'
)
;
}
function
isDirectoryRead
(
:
unknown
)
:
is
.
{
return
instanceof
Error
&&
'code'
in
&&
.
===
'EISDIR'
;
}
function
isAlreadyExists
(
:
unknown
)
:
is
.
{
return
instanceof
Error
&&
'code'
in
&&
.
===
'EEXIST'
;
}
function
isNoSuchProcess
(
:
unknown
)
:
is
.
{
return
instanceof
Error
&&
'code'
in
&&
.
===
'ESRCH'
;
}