Skip to content

Commit

Permalink
chore: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Jan 28, 2025
1 parent 0d65743 commit 09913cd
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 44 deletions.
6 changes: 6 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ export default [
'@typescript-eslint/no-unused-expressions': 'off',
},
},
{
files: ['test/**/*.test.ts'],
rules: {
'import/no-named-as-default-member': 'off',
},
},
]
3 changes: 0 additions & 3 deletions src/commands/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ interface RecursiveTree {
export default class PluginsIndex extends Command {
static description = 'List installed plugins.'
static enableJsonFlag = true

static examples = ['<%= config.bin %> <%= command.id %>']

static flags = {
core: Flags.boolean({description: 'Show core plugins.'}),
}

plugins!: Plugins

public async run(): Promise<PluginsJson> {
Expand Down
11 changes: 2 additions & 9 deletions src/commands/plugins/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function trimUntil(fsPath: string, part: string): string {
}

type Dependencies = Record<string, {from: string | undefined; version: string}>
type PluginWithDeps = {deps: Dependencies} & Omit<
type PluginWithDeps = Omit<
Plugin,
| '_commandsDir'
| '_debug'
Expand All @@ -36,7 +36,7 @@ type PluginWithDeps = {deps: Dependencies} & Omit<
| 'topics'
| 'warn'
| 'warned'
>
> & {deps: Dependencies}

export default class PluginsInspect extends Command {
static args = {
Expand All @@ -46,22 +46,15 @@ export default class PluginsInspect extends Command {
required: true,
}),
}

static description = 'Displays installation properties of a plugin.'

static enableJsonFlag = true

static examples = ['<%= config.bin %> <%= command.id %> <%- config.pjson.oclif.examplePlugin || "myplugin" %> ']

static flags = {
help: Flags.help({char: 'h'}),
verbose: Flags.boolean({char: 'v'}),
}

static strict = false

static usage = 'plugins:inspect PLUGIN...'

plugins!: Plugins

async findDep(plugin: Plugin, dependency: string): Promise<{pkgPath: null | string; version: null | string}> {
Expand Down
8 changes: 0 additions & 8 deletions src/commands/plugins/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,16 @@ import Plugins from '../../plugins.js'

export default class PluginsInstall extends Command {
static aliases = ['plugins:add']

static args = {
plugin: Args.string({description: 'Plugin to install.', required: true}),
}

static description = `Uses npm to install plugins.
Installation of a user-installed plugin will override a core plugin.
Use the <%= config.scopedEnvVarKey('NPM_LOG_LEVEL') %> environment variable to set the npm loglevel.
Use the <%= config.scopedEnvVarKey('NPM_REGISTRY') %> environment variable to set the npm registry.`

public static enableJsonFlag = true

static examples = [
{
command: '<%= config.bin %> <%= command.id %> <%- config.pjson.oclif.examplePlugin || "myplugin" %> ',
Expand All @@ -36,7 +32,6 @@ Use the <%= config.scopedEnvVarKey('NPM_REGISTRY') %> environment variable to se
description: 'Install a plugin from a github slug.',
},
]

static flags = {
force: Flags.boolean({
char: 'f',
Expand Down Expand Up @@ -82,11 +77,8 @@ Use the <%= config.scopedEnvVarKey('NPM_REGISTRY') %> environment variable to se
exclusive: ['silent'],
}),
}

static strict = false

static summary = 'Installs a plugin into <%= config.bin %>.'

flags!: Interfaces.InferredFlags<typeof PluginsInstall.flags>

// In this case we want these operations to happen
Expand Down
3 changes: 0 additions & 3 deletions src/commands/plugins/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ export default class PluginsLink extends Command {
static args = {
path: Args.string({default: '.', description: 'path to plugin', name: 'path', required: true}),
}

static description = `Installation of a linked plugin will override a user-installed or core plugin.
e.g. If you have a user-installed or core plugin that has a 'hello' command, installing a linked plugin with a 'hello' command will override the user-installed or core plugin implementation. This is useful for development work.
`
static examples = ['<%= config.bin %> <%= command.id %> <%- config.pjson.oclif.examplePlugin || "myplugin" %> ']

static flags = {
help: Flags.help({char: 'h'}),
install: Flags.boolean({
Expand All @@ -24,7 +22,6 @@ e.g. If you have a user-installed or core plugin that has a 'hello' command, ins
}),
verbose: Flags.boolean({char: 'v'}),
}

static summary = 'Links a plugin into the CLI for development.'

async run(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/plugins/reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export default class Reset extends Command {
summary: 'Reinstall all plugins after uninstalling.',
}),
}

static summary = 'Remove all user-installed and linked plugins.'

// eslint-disable-next-line complexity
async run(): Promise<void> {
const {flags} = await this.parse(Reset)
const plugins = new Plugins({
Expand Down
5 changes: 0 additions & 5 deletions src/commands/plugins/uninstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,15 @@ function removeTags(plugin: string): string {

export default class PluginsUninstall extends Command {
static aliases = ['plugins:unlink', 'plugins:remove']

static args = {
plugin: Args.string({description: 'plugin to uninstall'}),
}

static description = 'Removes a plugin from the CLI.'

static examples = ['<%= config.bin %> <%= command.id %> <%- config.pjson.oclif.examplePlugin || "myplugin" %>']

static flags = {
help: Flags.help({char: 'h'}),
verbose: Flags.boolean({char: 'v'}),
}

static strict = false

// In this case we want these operations to happen
Expand Down
1 change: 0 additions & 1 deletion src/commands/plugins/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Plugins from '../../plugins.js'

export default class PluginsUpdate extends Command {
static description = 'Update installed plugins.'

static flags = {
help: Flags.help({char: 'h'}),
verbose: Flags.boolean({char: 'v'}),
Expand Down
4 changes: 2 additions & 2 deletions src/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {ExecOptions, Output, spawn} from './spawn.js'

const debug = makeDebug('@oclif/plugin-plugins:npm')

type InstallOptions = {
type InstallOptions = ExecOptions & {
prod?: boolean
} & ExecOptions
}

export class NPM {
private bin: string | undefined
Expand Down
21 changes: 10 additions & 11 deletions src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ function dedupePlugins(plugins: Plugin[]): Plugin[] {
}

function extractIssuesLocation(
bugs: {url: string} | string | undefined,
repository: {type: string; url: string} | string | undefined,
bugs: string | undefined | {url: string},
repository: string | undefined | {type: string; url: string},
): string | undefined {
if (bugs) {
return typeof bugs === 'string' ? bugs : bugs.url
Expand Down Expand Up @@ -84,7 +84,6 @@ function notifyUser(plugin: Config, output: Output): void {
export default class Plugins {
public config: Interfaces.Config
public readonly npm: NPM

private readonly debug: ReturnType<typeof makeDebug>
private readonly logLevel: LogLevel

Expand All @@ -98,6 +97,10 @@ export default class Plugins {
})
}

private get pjsonPath() {
return join(this.config.dataDir, 'package.json')
}

public async add(...plugins: Plugin[]): Promise<void> {
const pjson = await this.pjson()
const mergedPlugins = [...(pjson.oclif.plugins || []), ...plugins] as typeof pjson.oclif.plugins
Expand All @@ -117,7 +120,7 @@ export default class Plugins {
return match?.[1] ?? name
}

public async hasPlugin(name: string): Promise<Plugin | false> {
public async hasPlugin(name: string): Promise<false | Plugin> {
const list = await this.list()
const friendlyName = this.friendlyName(name)
const unfriendlyName = this.unfriendlyName(name) ?? name
Expand Down Expand Up @@ -171,7 +174,7 @@ export default class Plugins {
// Check that the prepare script produced all the expected files
// If it didn't, it might be because the plugin doesn't have a prepare
// script that compiles the plugin from source.
const safeToNotExist = new Set(['oclif.manifest.json', 'oclif.lock', 'npm-shrinkwrap.json'])
const safeToNotExist = new Set(['npm-shrinkwrap.json', 'oclif.lock', 'oclif.manifest.json'])
const files = ((plugin.pjson.files ?? []) as string[])
.map((f) => join(root, f))
.filter((f) => !safeToNotExist.has(basename(f)))
Expand Down Expand Up @@ -454,16 +457,12 @@ export default class Plugins {
}
}

private get pjsonPath() {
return join(this.config.dataDir, 'package.json')
}

private async readPJSON(): Promise<UserPJSON | undefined> {
private async readPJSON(): Promise<undefined | UserPJSON> {
try {
return JSON.parse(await readFile(this.pjsonPath, 'utf8')) as UserPJSON
} catch (error: unknown) {
this.debug(error)
const err = error as {code?: string} & Error
const err = error as Error & {code?: string}
if (err.code !== 'ENOENT') process.emitWarning(err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/plugins.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Config, Interfaces} from '@oclif/core'
import {expect} from 'chai'
import {join} from 'node:path'
import {SinonSandbox, SinonSpy, createSandbox} from 'sinon'
import {createSandbox, SinonSandbox, SinonSpy} from 'sinon'

import Plugins from '../src/plugins.js'

Expand Down

0 comments on commit 09913cd

Please sign in to comment.