66import fs from 'fs' ;
77import path from 'path' ;
88import { execFileSync } from 'child_process' ;
9- import { copilotSourceVersion , readCopilotBuildOverrides , RUNTIME_NPM_NAME , SDK_NPM_NAME , type CopilotBuildOverrides , type VscodeSourceMetadata } from './copilotSource.ts' ;
109
1110/**
1211 * Stage 3 of the Copilot SDK -> VS Code integration pipeline.
@@ -46,7 +45,6 @@ const ROOT = path.join(import.meta.dirname, '../../../');
4645 */
4746const IS_WINDOWS = process . platform === 'win32' ;
4847const NPM = IS_WINDOWS ? 'npm.cmd' : 'npm' ;
49- const COPILOT_SOURCE_PIPELINE_URL = 'https://dev.azure.com/monacotools/Monaco/_build?definitionId=704' ;
5048
5149/**
5250 * Allowlist for npm version / range specifiers before they are interpolated
@@ -67,7 +65,7 @@ function assertSafeSpec(label: string, value: string): void {
6765/** Manifests that declare the Copilot dependencies. */
6866const TARGET_DIRS = [ '' , 'remote' ] ;
6967
70- export interface Override {
68+ interface Override {
7169 readonly name : string ;
7270 readonly version : string ;
7371}
@@ -189,7 +187,7 @@ function resolveLatestCanary(): string {
189187 return latest ;
190188}
191189
192- function collectCanaryOverrides ( ) : Override [ ] {
190+ function collectOverrides ( ) : Override [ ] {
193191 let sdkVersion = ( process . env [ 'VSCODE_SDK_CANARY_VERSION' ] ?? '' ) . trim ( ) ;
194192 if ( ! sdkVersion ) {
195193 return [ ] ;
@@ -228,71 +226,6 @@ function collectCanaryOverrides(): Override[] {
228226 return overrides ;
229227}
230228
231- function readVscodeSourceMetadata ( packageName : string , version : string ) : VscodeSourceMetadata {
232- let raw : string ;
233- try {
234- raw = execFileSync ( NPM , [ 'view' , `${ packageName } @${ version } ` , 'vscodeSource' , '--json' ] , { encoding : 'utf8' , shell : IS_WINDOWS } ) ;
235- } catch ( error ) {
236- throw new Error (
237- `[build-override] ${ packageName } @${ version } is not available from the configured feed. ` +
238- `Run the Copilot source pipeline for this VS Code commit: ${ COPILOT_SOURCE_PIPELINE_URL } \n` +
239- `${ error instanceof Error ? error . message : String ( error ) } `
240- ) ;
241- }
242- const metadata = JSON . parse ( raw || 'null' ) as Partial < VscodeSourceMetadata > | null ;
243- if ( ! metadata || typeof metadata !== 'object' ) {
244- throw new Error ( `[build-override] ${ packageName } @${ version } has no vscodeSource provenance metadata. Run ${ COPILOT_SOURCE_PIPELINE_URL } ` ) ;
245- }
246- return metadata as VscodeSourceMetadata ;
247- }
248-
249- export function assertVscodeSourceMetadata ( packageName : string , packageVersion : string , actual : VscodeSourceMetadata , expected : VscodeSourceMetadata ) : void {
250- const mismatches = ( Object . keys ( expected ) as ( keyof VscodeSourceMetadata ) [ ] )
251- . filter ( key => key !== 'sourceBuildId' && actual [ key ] !== expected [ key ] )
252- . map ( key => `${ key } : expected ${ expected [ key ] } , got ${ actual [ key ] ?? '<missing>' } ` ) ;
253- if ( mismatches . length > 0 ) {
254- throw new Error (
255- `[build-override] ${ packageName } @${ packageVersion } does not match package.json buildOverrides (${ mismatches . join ( '; ' ) } ). ` +
256- `Run the Copilot source pipeline: ${ COPILOT_SOURCE_PIPELINE_URL } `
257- ) ;
258- }
259- }
260-
261- export function collectBuildOverrides (
262- buildOverrides : CopilotBuildOverrides ,
263- vscodeCommit : string ,
264- metadataReader : ( packageName : string , version : string ) => VscodeSourceMetadata = readVscodeSourceMetadata ,
265- queuedSdk = ( process . env [ 'VSCODE_SDK_CANARY_VERSION' ] ?? '' ) . trim ( ) ,
266- queuedCli = ( process . env [ 'VSCODE_CLI_CANARY_VERSION' ] ?? '' ) . trim ( ) ,
267- ) : Override [ ] {
268- if ( queuedSdk || queuedCli ) {
269- throw new Error ( '[build-override] package.json buildOverrides cannot be combined with VSCODE_SDK_CANARY_VERSION or VSCODE_CLI_CANARY_VERSION.' ) ;
270- }
271- const version = copilotSourceVersion ( buildOverrides . vscodeVersion , vscodeCommit ) ;
272- const expectedByPackage = new Map < string , VscodeSourceMetadata > ( [
273- [ SDK_NPM_NAME , {
274- vscodeCommit,
275- sourceCommit : buildOverrides . sdkRef ,
276- sourceVersion : buildOverrides . sdkVersion ,
277- sourceBuildId : '' ,
278- } ] ,
279- [ RUNTIME_NPM_NAME , {
280- vscodeCommit,
281- sourceCommit : buildOverrides . runtimeRef ,
282- sourceVersion : buildOverrides . runtimeVersion ,
283- sourceBuildId : '' ,
284- } ] ,
285- ] ) ;
286- for ( const [ packageName , expected ] of expectedByPackage ) {
287- assertVscodeSourceMetadata ( packageName , version , metadataReader ( packageName , version ) , expected ) ;
288- }
289- console . log ( `##vso[build.addbuildtag]copilot-build-override=${ version } ` ) ;
290- return [
291- { name : SDK_NPM_NAME , version } ,
292- { name : RUNTIME_NPM_NAME , version } ,
293- ] ;
294- }
295-
296229function applyOverrides ( dir : string , overrides : Override [ ] ) : Override [ ] {
297230 const packageJsonPath = path . join ( ROOT , dir , 'package.json' ) ;
298231 const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf8' ) ) ;
@@ -350,20 +283,7 @@ function verifyResolved(dir: string, overrides: Override[]): void {
350283}
351284
352285function main ( ) : void {
353- const buildOverrides = readCopilotBuildOverrides ( ROOT ) ;
354- const canaryRequested = Boolean ( ( process . env [ 'VSCODE_SDK_CANARY_VERSION' ] ?? '' ) . trim ( ) ) ;
355- if ( process . argv . includes ( '--detect' ) ) {
356- if ( buildOverrides && ( ( process . env [ 'VSCODE_SDK_CANARY_VERSION' ] ?? '' ) . trim ( ) || ( process . env [ 'VSCODE_CLI_CANARY_VERSION' ] ?? '' ) . trim ( ) ) ) {
357- throw new Error ( '[build-override] package.json buildOverrides cannot be combined with SDK/CLI canary version parameters.' ) ;
358- }
359- console . log ( `##vso[task.setvariable variable=VSCODE_APPLY_COPILOT_OVERRIDE]${ Boolean ( buildOverrides || canaryRequested ) } ` ) ;
360- console . log ( `[build-override] ${ buildOverrides ? 'Detected package.json Copilot build overrides.' : canaryRequested ? 'Detected an SDK canary request.' : 'No Copilot package override detected.' } ` ) ;
361- return ;
362- }
363-
364- const overrides = buildOverrides
365- ? collectBuildOverrides ( buildOverrides , ( process . env [ 'BUILD_SOURCEVERSION' ] ?? '' ) . trim ( ) )
366- : collectCanaryOverrides ( ) ;
286+ const overrides = collectOverrides ( ) ;
367287 if ( overrides . length === 0 ) {
368288 console . log ( '[canary-override] No canary versions set — nothing to do.' ) ;
369289 return ;
@@ -378,6 +298,4 @@ function main(): void {
378298 }
379299}
380300
381- if ( import . meta. main ) {
382- main ( ) ;
383- }
301+ main ( ) ;
0 commit comments