Skip to content

Commit

Permalink
Merge branch 'main' into mdonnalley/revamp
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Jan 31, 2024
2 parents b4ef3d3 + 27504a2 commit d044775
Show file tree
Hide file tree
Showing 6 changed files with 268 additions and 172 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## [4.1.23](https://github.com/oclif/plugin-plugins/compare/4.1.22...4.1.23) (2024-01-30)

### Bug Fixes

- update npm version ([2bf7ff4](https://github.com/oclif/plugin-plugins/commit/2bf7ff40d2a9019f42dec235071bd56aef8cf31b))

## [4.1.22](https://github.com/oclif/plugin-plugins/compare/4.1.21...4.1.22) (2024-01-27)

### Bug Fixes

- **deps:** bump npm from 10.2.3 to 10.4.0 ([#781](https://github.com/oclif/plugin-plugins/issues/781)) ([2618266](https://github.com/oclif/plugin-plugins/commit/26182664219f9aec86af2e71373ca884bdbd02e5))

## [4.1.21](https://github.com/oclif/plugin-plugins/compare/4.1.20...4.1.21) (2024-01-23)

### Bug Fixes
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ EXAMPLES
$ mycli plugins
```

_See code: [src/commands/plugins/index.ts](https://github.com/oclif/plugin-plugins/blob/4.1.21/src/commands/plugins/index.ts)_
_See code: [src/commands/plugins/index.ts](https://github.com/oclif/plugin-plugins/blob/4.1.23/src/commands/plugins/index.ts)_

## `mycli plugins:inspect PLUGIN...`

Expand All @@ -144,7 +144,7 @@ EXAMPLES
$ mycli plugins inspect myplugin
```

_See code: [src/commands/plugins/inspect.ts](https://github.com/oclif/plugin-plugins/blob/4.1.21/src/commands/plugins/inspect.ts)_
_See code: [src/commands/plugins/inspect.ts](https://github.com/oclif/plugin-plugins/blob/4.1.23/src/commands/plugins/inspect.ts)_

## `mycli plugins:install PLUGIN...`

Expand Down Expand Up @@ -188,7 +188,7 @@ EXAMPLES
$ mycli plugins install someuser/someplugin
```

_See code: [src/commands/plugins/install.ts](https://github.com/oclif/plugin-plugins/blob/4.1.21/src/commands/plugins/install.ts)_
_See code: [src/commands/plugins/install.ts](https://github.com/oclif/plugin-plugins/blob/4.1.23/src/commands/plugins/install.ts)_

## `mycli plugins:link PLUGIN`

Expand Down Expand Up @@ -218,7 +218,7 @@ EXAMPLES
$ mycli plugins link myplugin
```

_See code: [src/commands/plugins/link.ts](https://github.com/oclif/plugin-plugins/blob/4.1.21/src/commands/plugins/link.ts)_
_See code: [src/commands/plugins/link.ts](https://github.com/oclif/plugin-plugins/blob/4.1.23/src/commands/plugins/link.ts)_

## `mycli plugins reset`

Expand All @@ -229,7 +229,7 @@ USAGE
$ mycli plugins reset
```

_See code: [src/commands/plugins/reset.ts](https://github.com/oclif/plugin-plugins/blob/4.1.21/src/commands/plugins/reset.ts)_
_See code: [src/commands/plugins/reset.ts](https://github.com/oclif/plugin-plugins/blob/4.1.23/src/commands/plugins/reset.ts)_

## `mycli plugins:uninstall PLUGIN...`

Expand Down Expand Up @@ -257,7 +257,7 @@ EXAMPLES
$ mycli plugins uninstall myplugin
```

_See code: [src/commands/plugins/uninstall.ts](https://github.com/oclif/plugin-plugins/blob/4.1.21/src/commands/plugins/uninstall.ts)_
_See code: [src/commands/plugins/uninstall.ts](https://github.com/oclif/plugin-plugins/blob/4.1.23/src/commands/plugins/uninstall.ts)_

## `mycli plugins update`

Expand All @@ -275,6 +275,6 @@ DESCRIPTION
Update installed plugins.
```

_See code: [src/commands/plugins/update.ts](https://github.com/oclif/plugin-plugins/blob/4.1.21/src/commands/plugins/update.ts)_
_See code: [src/commands/plugins/update.ts](https://github.com/oclif/plugin-plugins/blob/4.1.23/src/commands/plugins/update.ts)_

<!-- commandsstop -->
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@oclif/core": "^3.10.2",
"chalk": "^5.3.0",
"debug": "^4.3.4",
"npm": "10.2.3",
"npm": "10.2.4",
"npm-package-arg": "^11.0.1",
"npm-run-path": "^5.2.0",
"semver": "^7.5.4",
Expand All @@ -31,13 +31,13 @@
"commitlint": "^17.8.1",
"eslint": "^8.56.0",
"eslint-config-oclif": "^5.0.0",
"eslint-config-oclif-typescript": "^3.0.37",
"eslint-config-oclif-typescript": "^3.0.39",
"eslint-config-prettier": "^9.1.0",
"husky": "^8.0.3",
"lint-staged": "^15.2.0",
"mocha": "^10.2.0",
"oclif": "^4.3.6",
"prettier": "^3.1.1",
"oclif": "^4.4.0",
"prettier": "^3.2.4",
"shx": "^0.3.4",
"sinon": "^16.1.3",
"ts-node": "^10.9.2",
Expand Down
77 changes: 73 additions & 4 deletions src/commands/plugins/reset.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,91 @@
import {Command} from '@oclif/core'
/* eslint-disable no-await-in-loop */
import {Command, Flags} from '@oclif/core'
import chalk from 'chalk'
import {rm} from 'node:fs/promises'
import {join} from 'node:path'

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

export default class Reset extends Command {
static flags = {
hard: Flags.boolean({
summary: 'Delete node_modules and package manager related files in addition to uninstalling plugins.',
}),
reinstall: Flags.boolean({
summary: 'Reinstall all plugins after uninstalling.',
}),
}

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

async run(): Promise<void> {
const {flags} = await this.parse(Reset)
const plugins = new Plugins({
config: this.config,
})
const userPlugins = await plugins.list()

this.log(`Uninstalling ${userPlugins.length} plugin${userPlugins.length === 0 ? '' : 's'}`)
this.log(`Found ${userPlugins.length} plugin${userPlugins.length === 0 ? '' : 's'}:`)
for (const plugin of userPlugins) {
this.log(`• ${plugin.name} ${chalk.dim(`(${plugin.type})`)}`)
this.log(
`- ${plugin.name} ${chalk.dim(this.config.plugins.get(plugin.name)?.version)} ${chalk.dim(`(${plugin.type})`)}`,
)
}

await Promise.all(userPlugins.map(async (plugin) => plugins.uninstall(plugin.name)))
if (flags.hard) {
const filesToDelete = [
join(this.config.dataDir, 'node_modules'),
join(this.config.dataDir, 'package.json'),
join(this.config.dataDir, 'yarn.lock'),
join(this.config.dataDir, 'package-lock.json'),
]

this.log('✅ Removed the following files:')
for (const file of filesToDelete) {
this.log(`- ${file}`)
}

await Promise.all(filesToDelete.map((file) => rm(file, {force: true, recursive: true})))

for (const plugin of userPlugins) {
this.log(`✅ ${plugin.type === 'link' ? 'Unlinked' : 'Uninstalled'} ${plugin.name}`)
}
} else {
// These need to run sequentially so as to avoid write conflicts to the package.json
for (const plugin of userPlugins) {
try {
await plugins.uninstall(plugin.name)
this.log(`✅ ${plugin.type === 'link' ? 'Unlinked' : 'Uninstalled'} ${plugin.name}`)
} catch {
this.warn(`Failed to uninstall ${plugin.name}`)
}
}
}

if (flags.reinstall) {
this.log('Reinstall flag passed:')
// These need to run sequentially so as to avoid write conflicts to the package.json
for (const plugin of userPlugins) {
if (plugin.type === 'link') {
try {
const newPlugin = await plugins.link(plugin.root, {install: false})
const newVersion = chalk.dim(`-> ${newPlugin.version}`)
this.log(`✅ Relinked ${plugin.name} ${newVersion}`)
} catch {
this.warn(`Failed to relink ${plugin.name}`)
}
}

if (plugin.type === 'user') {
try {
const newPlugin = await plugins.install(plugin.name, {tag: plugin.tag})
const newVersion = chalk.dim(`-> ${newPlugin.version}`)
this.log(`✅ Reinstalled ${plugin.name}@${plugin.tag} ${newVersion}`)
} catch {
this.warn(`Failed to reinstall ${plugin.name}`)
}
}
}
}
}
}
5 changes: 4 additions & 1 deletion src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ export default class Plugins {
}
}

public async link(p: string, {install}: {install: boolean}): Promise<void> {
public async link(p: string, {install}: {install: boolean}): Promise<Interfaces.Config> {
const c = await Config.load(resolve(p))

this.isValidPlugin(c)

if (install) {
Expand All @@ -178,6 +179,8 @@ export default class Plugins {
}

await this.add({name: c.name, root: c.root, type: 'link'})

return c
}

public async list(): Promise<(Interfaces.PJSON.PluginTypes.Link | Interfaces.PJSON.PluginTypes.User)[]> {
Expand Down
Loading

0 comments on commit d044775

Please sign in to comment.