@@ -39,52 +39,63 @@ const { createVSIX } = require('vsce');
3939 } else if ( context . repo && context . ref ) {
4040 console . log ( `${ id } : preparing from ${ context . repo } ...` ) ;
4141 await exec ( `git checkout ${ context . ref } ` , { cwd : context . repo } ) ;
42- let yarn = await new Promise ( resolve => {
43- fs . access ( path . join ( context . repo , 'yarn.lock' ) , error => resolve ( ! error ) ) ;
44- } ) ;
45- try {
46- await exec ( `${ yarn ? 'yarn' : 'npm' } install` , { cwd : packagePath } ) ;
47- } catch ( e ) {
48- const pck = JSON . parse ( await fs . promises . readFile ( path . join ( packagePath , 'package.json' ) , 'utf-8' ) ) ;
49- // try to auto migrate from vscode: https://code.visualstudio.com/api/working-with-extensions/testing-extension#migrating-from-vscode
50- if ( pck . scripts ?. postinstall === 'node ./node_modules/vscode/bin/install' ) {
51- delete pck . scripts [ 'postinstall' ] ;
52- pck . devDependencies = pck . devDependencies || { } ;
53- delete pck . devDependencies [ 'vscode' ] ;
54- pck . devDependencies [ '@types/vscode' ] = pck . engines [ 'vscode' ] ;
55- const content = JSON . stringify ( pck , undefined , 2 ) . replace ( / n o d e \. \/ n o d e _ m o d u l e s \/ v s c o d e \/ b i n \/ c o m p i l e / g, 'tsc' ) ;
56- await fs . promises . writeFile ( path . join ( packagePath , 'package.json' ) , content , 'utf-8' ) ;
57- await exec ( `${ yarn ? 'yarn' : 'npm' } install` , { cwd : packagePath } ) ;
58- } else {
42+ if ( extension . custom ) {
43+ try {
44+ for ( const command of extension . custom ) {
45+ await exec ( command , { cwd : context . repo } ) ;
46+ }
47+ options = { extensionFile : path . join ( context . repo , extension . location , 'extension.vsix' ) } ;
48+ } catch ( e ) {
5949 throw e ;
6050 }
61- }
62- if ( extension . prepublish ) {
63- await exec ( extension . prepublish , { cwd : context . repo } )
64- }
65- if ( extension . extensionFile ) {
66- options = { extensionFile : path . join ( context . repo , extension . extensionFile ) } ;
6751 } else {
68- options = { extensionFile : path . join ( context . repo , 'extension.vsix' ) } ;
69- if ( yarn ) {
70- options . yarn = true ;
71- }
72- // answer y to all quetions https://github.com/microsoft/vscode-vsce/blob/7182692b0f257dc10e7fc643269511549ca0c1db/src/util.ts#L12
73- const vsceTests = process . env [ 'VSCE_TESTS' ] ;
74- process . env [ 'VSCE_TESTS' ] = '1' ;
52+ let yarn = await new Promise ( resolve => {
53+ fs . access ( path . join ( context . repo , 'yarn.lock' ) , error => resolve ( ! error ) ) ;
54+ } ) ;
7555 try {
76- await createVSIX ( {
77- cwd : packagePath ,
78- packagePath : options . extensionFile ,
79- baseContentUrl : options . baseContentUrl ,
80- baseImagesUrl : options . baseImagesUrl ,
81- useYarn : options . yarn
82- } ) ;
83- } finally {
84- process . env [ 'VSCE_TESTS' ] = vsceTests ;
56+ await exec ( `${ yarn ? 'yarn' : 'npm' } install` , { cwd : packagePath } ) ;
57+ } catch ( e ) {
58+ const pck = JSON . parse ( await fs . promises . readFile ( path . join ( packagePath , 'package.json' ) , 'utf-8' ) ) ;
59+ // try to auto migrate from vscode: https://code.visualstudio.com/api/working-with-extensions/testing-extension#migrating-from-vscode
60+ if ( pck . scripts ?. postinstall === 'node ./node_modules/vscode/bin/install' ) {
61+ delete pck . scripts [ 'postinstall' ] ;
62+ pck . devDependencies = pck . devDependencies || { } ;
63+ delete pck . devDependencies [ 'vscode' ] ;
64+ pck . devDependencies [ '@types/vscode' ] = pck . engines [ 'vscode' ] ;
65+ const content = JSON . stringify ( pck , undefined , 2 ) . replace ( / n o d e \. \/ n o d e _ m o d u l e s \/ v s c o d e \/ b i n \/ c o m p i l e / g, 'tsc' ) ;
66+ await fs . promises . writeFile ( path . join ( packagePath , 'package.json' ) , content , 'utf-8' ) ;
67+ await exec ( `${ yarn ? 'yarn' : 'npm' } install` , { cwd : packagePath } ) ;
68+ } else {
69+ throw e ;
70+ }
71+ }
72+ if ( extension . prepublish ) {
73+ await exec ( extension . prepublish , { cwd : context . repo } )
74+ }
75+ if ( extension . extensionFile ) {
76+ options = { extensionFile : path . join ( context . repo , extension . extensionFile ) } ;
77+ } else {
78+ options = { extensionFile : path . join ( context . repo , 'extension.vsix' ) } ;
79+ if ( yarn ) {
80+ options . yarn = true ;
81+ }
82+ // answer y to all quetions https://github.com/microsoft/vscode-vsce/blob/7182692b0f257dc10e7fc643269511549ca0c1db/src/util.ts#L12
83+ const vsceTests = process . env [ 'VSCE_TESTS' ] ;
84+ process . env [ 'VSCE_TESTS' ] = '1' ;
85+ try {
86+ await createVSIX ( {
87+ cwd : packagePath ,
88+ packagePath : options . extensionFile ,
89+ baseContentUrl : options . baseContentUrl ,
90+ baseImagesUrl : options . baseImagesUrl ,
91+ useYarn : options . yarn
92+ } ) ;
93+ } finally {
94+ process . env [ 'VSCE_TESTS' ] = vsceTests ;
95+ }
8596 }
97+ console . log ( `${ id } : prepared from ${ context . repo } ` ) ;
8698 }
87- console . log ( `${ id } : prepared from ${ context . repo } ` ) ;
8899 }
89100
90101 // Check if the requested version is greater than the one on Open VSX.
@@ -93,6 +104,7 @@ const { createVSIX } = require('vsce');
93104 if ( ! context . version ) {
94105 throw new Error ( `${ extension . id } : version is not resolved` ) ;
95106 }
107+
96108 if ( context . ovsxVersion ) {
97109 if ( semver . gt ( context . ovsxVersion , context . version ) ) {
98110 throw new Error ( `extensions.json is out-of-date: Open VSX version ${ context . ovsxVersion } is already greater than specified version ${ context . version } ` ) ;
@@ -102,6 +114,7 @@ const { createVSIX } = require('vsce');
102114 return ;
103115 }
104116 }
117+
105118 // TODO(ak) check license is open-source
106119 if ( ! xmlManifest ?. PackageManifest ?. Metadata [ 0 ] ?. License ?. [ 0 ] && ! manifest . license && ! ( packagePath && await ovsx . isLicenseOk ( packagePath , manifest ) ) ) {
107120 throw new Error ( `${ extension . id } : license is missing` ) ;
0 commit comments