1- import { CreatePlan , DestroyPlan , getPty , Resource , ResourceSettings , untildify , } from 'codify-plugin-lib' ;
2- import { ResourceConfig } from 'codify-schemas' ;
1+ import {
2+ CreatePlan ,
3+ DestroyPlan ,
4+ Resource ,
5+ ResourceSettings ,
6+ SpawnStatus ,
7+ getPty ,
8+ } from 'codify-plugin-lib' ;
9+ import { OS , ResourceConfig } from 'codify-schemas' ;
310import * as fs from 'node:fs/promises' ;
411import path from 'node:path' ;
512
6- import { SpawnStatus , codifySpawn } from '../../utils/codify-spawn.js' ;
713import { FileUtils } from '../../utils/file-utils.js' ;
814import AsdfInstallSchema from './asdf-install-schema.json' ;
9- import { AsdfPluginVersionsParameter } from './version-parameter.js' ;
1015
1116export interface AsdfInstallConfig extends ResourceConfig {
1217 plugin ?: string ;
1318 versions ?: string [ ] ;
1419 directory ?: string ;
1520}
1621
17- const CURRENT_VERSION_REGEX = / [ ^ ] + + ( [ ^ ] + ) .* / ;
22+ const CURRENT_VERSION_REGEX = / ^ ( [ ^ ] + ? ) \s + ( [ ^ ] + ? ) \s + .* / ;
1823const TOOL_VERSIONS_REGEX = / ^ ( [ ^ ] + ) + ( [ ^ ] + ) $ / ;
1924
2025
2126export class AsdfInstallResource extends Resource < AsdfInstallConfig > {
2227 getSettings ( ) : ResourceSettings < AsdfInstallConfig > {
2328 return {
2429 id : 'asdf-install' ,
30+ operatingSystems : [ OS . Darwin , OS . Linux ] ,
2531 dependencies : [ 'asdf' ] ,
2632 schema : AsdfInstallSchema ,
2733 parameterSettings : {
@@ -60,13 +66,13 @@ export class AsdfInstallResource extends Resource<AsdfInstallConfig> {
6066 const desiredTools = await this . getToolVersions ( parameters . directory ) ;
6167
6268 for ( const { plugin, version } of desiredTools ) {
63- const { status, data } = await $ . spawnSafe ( `asdf current ${ plugin } ` , { cwd : parameters . directory } ) ;
69+ const { status, data } = await $ . spawnSafe ( `asdf current ${ plugin } --no-header ` , { cwd : parameters . directory } ) ;
6470 if ( status === SpawnStatus . ERROR || data . trim ( ) === '' ) {
6571 return null ;
6672 }
6773
68- const [ _ , currentVersion ] = data . match ( CURRENT_VERSION_REGEX ) ! ;
69- if ( currentVersion !== version ) {
74+ const [ _ , currentPlugin , currentVersion ] = data . match ( CURRENT_VERSION_REGEX ) ! ;
75+ if ( currentPlugin !== plugin || currentVersion !== version ) {
7076 return null ;
7177 }
7278 }
@@ -78,12 +84,12 @@ export class AsdfInstallResource extends Resource<AsdfInstallConfig> {
7884
7985 // Directly check plugin version
8086 const versionsQuery = await $ . spawnSafe ( `asdf list ${ parameters . plugin } ` ) ;
81- if ( versionsQuery . status === SpawnStatus . ERROR || versionsQuery . data . trim ( ) === 'No versions installed' ) {
87+ if ( versionsQuery . status === SpawnStatus . ERROR || versionsQuery . data . trim ( ) . includes ( 'No compatible versions installed' ) ) {
8288 return null ;
8389 }
8490
8591 const latest = parameters . versions ?. includes ( 'latest' )
86- ? ( await codifySpawn ( `asdf latest ${ parameters . plugin } ` ) ) . data . trim ( )
92+ ? ( await $ . spawnSafe ( `asdf latest ${ parameters . plugin } ` ) ) . data . trim ( )
8793 : null ;
8894
8995 const versions = versionsQuery . data . split ( / \n / )
@@ -99,37 +105,40 @@ export class AsdfInstallResource extends Resource<AsdfInstallConfig> {
99105 }
100106
101107 async create ( plan : CreatePlan < AsdfInstallConfig > ) : Promise < void > {
108+ const $ = getPty ( ) ;
109+
102110 if ( plan . desiredConfig . directory ) {
103111 const desiredTools = await this . getToolVersions ( plan . desiredConfig . directory ) ;
104112
105113 // Make sure all of the plugins are installed. If not installed, then install them
106114 for ( const { plugin } of desiredTools ) {
107- if ( ( await codifySpawn ( `asdf list ${ plugin } ` , { throws : false } ) ) . status === SpawnStatus . ERROR ) {
108- await codifySpawn ( `asdf plugin add ${ plugin } ` ) ;
115+ if ( ( await $ . spawnSafe ( `asdf list ${ plugin } ` ) ) . status === SpawnStatus . ERROR ) {
116+ await $ . spawn ( `asdf plugin add ${ plugin } ` , { interactive : true } ) ;
109117 }
110118 }
111119
112- await codifySpawn ( 'asdf install' , { cwd : plan . desiredConfig . directory } ) ;
120+ await $ . spawn ( 'asdf install' , { cwd : plan . desiredConfig . directory , interactive : true } ) ;
113121 return ;
114122 }
115123
116- await codifySpawn ( `asdf install ${ plan . desiredConfig ?. plugin } ${ plan . desiredConfig . versions ?. join ( ' ' ) } ` ) ;
124+ await $ . spawn ( `asdf install ${ plan . desiredConfig ?. plugin } ${ plan . desiredConfig . versions ?. join ( ' ' ) } ` , { interactive : true } ) ;
117125 }
118126
119127 async destroy ( plan : DestroyPlan < AsdfInstallConfig > ) : Promise < void > {
128+ const $ = getPty ( ) ;
120129 if ( plan . currentConfig . directory ) {
121130 const desiredTools = await this . getToolVersions ( plan . currentConfig . directory ) ;
122131
123132 // Uninstall plugin versions listed in .tool-versions
124133 for ( const { plugin, version } of desiredTools ) {
125- await codifySpawn ( `asdf uninstall ${ plugin } ${ version } ` ) ;
134+ await $ . spawn ( `asdf uninstall ${ plugin } ${ version } ` , { interactive : true } ) ;
126135 }
127136
128137 return ;
129138 }
130139
131140 // Other path is uninstalled through the stateful parameter
132- await codifySpawn ( `asdf uninstall ${ plan . currentConfig ?. plugin } ${ plan . currentConfig . versions ?. join ( ' ' ) } ` ) ;
141+ await $ . spawn ( `asdf uninstall ${ plan . currentConfig ?. plugin } ${ plan . currentConfig . versions ?. join ( ' ' ) } ` , { interactive : true } ) ;
133142 }
134143
135144 private async getToolVersions ( directory : string ) : Promise < Array < { plugin : string ; version : string } > > {
0 commit comments