@@ -11,6 +11,7 @@ import { spawnSync } from "child_process";
1111import { basename , resolve } from "path" ;
1212import { pathExists , readJSON } from "fs-extra" ;
1313import { SourceMapConsumer } from "source-map" ;
14+ import { Open } from "unzipper" ;
1415
1516if ( process . argv . length !== 4 ) {
1617 console . error (
@@ -24,6 +25,12 @@ const versionNumber = process.argv[2].startsWith("v")
2425const filenameAndLine = process . argv [ 3 ] ;
2526
2627async function extractSourceMap ( ) {
28+ const releaseAssetsDirectory = resolve (
29+ __dirname ,
30+ ".." ,
31+ "release-assets" ,
32+ versionNumber ,
33+ ) ;
2734 const sourceMapsDirectory = resolve (
2835 __dirname ,
2936 ".." ,
@@ -35,34 +42,64 @@ async function extractSourceMap() {
3542 if ( ! ( await pathExists ( sourceMapsDirectory ) ) ) {
3643 console . log ( "Downloading source maps..." ) ;
3744
38- const workflowRuns = runGhJSON < WorkflowRunListItem [ ] > ( [
39- "run" ,
40- "list" ,
41- "--workflow" ,
42- "release.yml" ,
43- "--branch" ,
45+ const release = runGhJSON < Release > ( [
46+ "release" ,
47+ "view" ,
4448 versionNumber ,
4549 "--json" ,
46- "databaseId,number " ,
50+ "id,name,assets " ,
4751 ] ) ;
4852
49- if ( workflowRuns . length !== 1 ) {
50- throw new Error (
51- `Expected exactly one workflow run for ${ versionNumber } , got ${ workflowRuns . length } ` ,
53+ const sourcemapAsset = release . assets . find (
54+ ( asset ) => asset . name === `vscode-codeql-sourcemaps-${ versionNumber } .zip` ,
55+ ) ;
56+
57+ if ( sourcemapAsset ) {
58+ // This downloads a ZIP file of the source maps
59+ runGh ( [
60+ "release" ,
61+ "download" ,
62+ versionNumber ,
63+ "--pattern" ,
64+ sourcemapAsset . name ,
65+ "--dir" ,
66+ releaseAssetsDirectory ,
67+ ] ) ;
68+
69+ const file = await Open . file (
70+ resolve ( releaseAssetsDirectory , sourcemapAsset . name ) ,
5271 ) ;
72+ await file . extract ( { path : sourceMapsDirectory } ) ;
73+ } else {
74+ const workflowRuns = runGhJSON < WorkflowRunListItem [ ] > ( [
75+ "run" ,
76+ "list" ,
77+ "--workflow" ,
78+ "release.yml" ,
79+ "--branch" ,
80+ versionNumber ,
81+ "--json" ,
82+ "databaseId,number" ,
83+ ] ) ;
84+
85+ if ( workflowRuns . length !== 1 ) {
86+ throw new Error (
87+ `Expected exactly one workflow run for ${ versionNumber } , got ${ workflowRuns . length } ` ,
88+ ) ;
89+ }
90+
91+ const workflowRun = workflowRuns [ 0 ] ;
92+
93+ runGh ( [
94+ "run" ,
95+ "download" ,
96+ workflowRun . databaseId . toString ( ) ,
97+ "--name" ,
98+ "vscode-codeql-sourcemaps" ,
99+ "--dir" ,
100+ sourceMapsDirectory ,
101+ ] ) ;
53102 }
54-
55- const workflowRun = workflowRuns [ 0 ] ;
56-
57- runGh ( [
58- "run" ,
59- "download" ,
60- workflowRun . databaseId . toString ( ) ,
61- "--name" ,
62- "vscode-codeql-sourcemaps" ,
63- "--dir" ,
64- sourceMapsDirectory ,
65- ] ) ;
66103 }
67104
68105 const [ filename , line , column ] = filenameAndLine . split ( ":" , 3 ) ;
@@ -119,6 +156,17 @@ function runGhJSON<T>(args: readonly string[]): T {
119156 return JSON . parse ( runGh ( args ) ) ;
120157}
121158
159+ type ReleaseAsset = {
160+ id : string ;
161+ name : string ;
162+ } ;
163+
164+ type Release = {
165+ id : string ;
166+ name : string ;
167+ assets : ReleaseAsset [ ] ;
168+ } ;
169+
122170type WorkflowRunListItem = {
123171 databaseId : number ;
124172 number : number ;
0 commit comments