Skip to content

Commit

Permalink
fix: allow using deprecated versions (#36)
Browse files Browse the repository at this point in the history
Adds a `--deprecated`/`-d` flag to `iim use` which includes
deprecated versions in the list of versions eligble to install.

Fixes #33
  • Loading branch information
achingbrain authored Dec 18, 2023
1 parent c2c83f1 commit 107d930
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/commands/use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,23 @@ const options: Record<string, ParseArgsOptionConfig> = {
pre: {
short: 'p',
type: 'boolean'
},
deprecated: {
short: 'd',
type: 'boolean'
}
}

export default {
aliases: ['u'],
help,
options,
run: async (positionals: string[], options: { pre: boolean }) => {
run: async (positionals: string[], options: { pre: boolean, deprecated: boolean }) => {
const [implName, versionRange] = positionals

const spinner = ora()
const npm = new Npm()
await use({ npm, spinner }, implName, versionRange, options.pre, binPath, installPath, homePath, currentBinLinkPath)
await use({ npm, spinner }, implName, versionRange, options.pre, options.deprecated, binPath, installPath, homePath, currentBinLinkPath)

console.log('🚀 IPFS is ready to use')
}
Expand Down
8 changes: 5 additions & 3 deletions src/lib/npm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ export default class NpmLib {
return versions
}

async rangeToVersion (mod: string, range: string, includePre: boolean): Promise<string> {
const allVers = await this.getVersions(mod)
async rangeToVersion (mod: string, range: string, includePre: boolean, includeDeprecated: boolean): Promise<string> {
const allVers = await this.getVersions(mod, {
deprecated: includeDeprecated
})

if (allVers.length === 0) {
throw new Error(`${mod} has no versions to select from`)
throw new Error(`${mod} has no versions to select from. Some may be deprecated, pass --deprecated as a flag to enabled their use`)
}

let rangeVers = includePre
Expand Down
3 changes: 2 additions & 1 deletion src/lib/use/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default async function use (
implName: string,
versionRange: string,
includePre: boolean,
includeDeprecated: boolean,
binPath: string,
installPath: string,
homePath: string,
Expand All @@ -36,7 +37,7 @@ export default async function use (
{ npm, spinner },
implementations[implName].moduleName,
versionRange,
{ moduleTitle: `${implName}-ipfs`, includePre }
{ moduleTitle: `${implName}-ipfs`, includePre, includeDeprecated }
)

const implInstallPath = Path.join(installPath, `${implName}-ipfs@${version}`)
Expand Down
3 changes: 2 additions & 1 deletion src/lib/use/select-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Context } from '../../bin'

export interface SelectVersionOptions {
includePre: boolean
includeDeprecated: boolean
moduleTitle: string
}

Expand All @@ -12,7 +13,7 @@ export default async function selectVersion (ctx: Required<Context>, mod: string

spinner.start(`finding ${options.moduleTitle} versions`)
try {
version = await npm.rangeToVersion(mod, version, options.includePre)
version = await npm.rangeToVersion(mod, version, options.includePre, options.includeDeprecated)
} catch (err) {
spinner.fail(`failed to find ${options.moduleTitle} versions`)
throw err
Expand Down

0 comments on commit 107d930

Please sign in to comment.