Skip to content

Commit cd17ec3

Browse files
committed
fully uninstall installed plugins, reduce noise
1 parent 3a4f8ae commit cd17ec3

File tree

4 files changed

+88
-14
lines changed

4 files changed

+88
-14
lines changed

src/run/src/npm.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ const npmFg = (
6969
}
7070

7171
// suppress all non-essential npm output
72-
const quiet = ['--no-audit', '--loglevel=error', '--no-progress']
72+
const quiet = ['--silent', '--log-level=silent', '--no-audit', '--loglevel=error', '--no-progress', '--no-fund']
7373

7474
export const install = async (
7575
pkgs: string[],
7676
config: LoadedConfig,
7777
) => {
7878
const npmCwd = await npmFindCwd(config.projectRoot)
79-
const args = ['install', ...quiet, '--save-dev', ...pkgs]
79+
const args = ['install', ...quiet, '--save', ...pkgs]
8080
await new Promise<void>((res, rej) => {
8181
npmFg(args, npmCwd, (code, signal) => {
8282
// allow error exit to proceed

src/run/src/plugin.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,20 @@ const rm = async (args: string[], config: LoadedConfig) => {
173173
if (pc.includes(plugin)) {
174174
pc.splice(pc.indexOf(plugin), 1)
175175
}
176-
// if it's not a file on disk, then we probably need to uninstall a pkg
177-
if (!(await exists(plugin))) needRemove.add(plugin)
176+
177+
// if it's an installed plugin, remove it
178+
if (
179+
!(await exists(plugin)) &&
180+
await exists(
181+
resolve(
182+
config.projectRoot,
183+
'.tap/plugins/node_modules',
184+
plugin,
185+
),
186+
)
187+
) {
188+
needRemove.add(plugin)
189+
}
178190
}
179191

180192
if (!removed.size) {
@@ -198,12 +210,7 @@ const rm = async (args: string[], config: LoadedConfig) => {
198210
console.log('successfully removed plugin(s):')
199211
console.log([...removed].join('\n'))
200212
if (needRemove.size) {
201-
console.log('The following packages can likely be removed:')
202-
console.log(
203-
`npm rm ${[...needRemove]
204-
.map(p => JSON.stringify(p))
205-
.join(' ')}`,
206-
)
213+
await uninstall([...needRemove], config)
207214
}
208215
}
209216

src/run/tap-snapshots/test/npm.ts.test.cjs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ Array [
1111
"npm",
1212
Array [
1313
"install",
14+
"--silent",
15+
"--log-level=silent",
1416
"--no-audit",
1517
"--loglevel=error",
1618
"--no-progress",
17-
"--save-dev",
19+
"--no-fund",
20+
"--save",
1821
"a",
1922
"b",
2023
],
@@ -57,9 +60,12 @@ Array [
5760
"npm",
5861
Array [
5962
"rm",
63+
"--silent",
64+
"--log-level=silent",
6065
"--no-audit",
6166
"--loglevel=error",
6267
"--no-progress",
68+
"--no-fund",
6369
"a",
6470
"b",
6571
],
@@ -81,10 +87,13 @@ Array [
8187
"npm",
8288
Array [
8389
"install",
90+
"--silent",
91+
"--log-level=silent",
8492
"--no-audit",
8593
"--loglevel=error",
8694
"--no-progress",
87-
"--save-dev",
95+
"--no-fund",
96+
"--save",
8897
"a",
8998
"b",
9099
],
@@ -127,9 +136,12 @@ Array [
127136
"npm",
128137
Array [
129138
"rm",
139+
"--silent",
140+
"--log-level=silent",
130141
"--no-audit",
131142
"--loglevel=error",
132143
"--no-progress",
144+
"--no-fund",
133145
"a",
134146
"b",
135147
],

src/run/test/plugin.ts

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { LoadedConfig } from '@tapjs/config'
44
import { resolve } from 'node:path'
55
import { pathToFileURL } from 'node:url'
66
import { resolveImport } from 'resolve-import'
7+
import * as npm from '../dist/esm/npm.js'
78

89
const CWD = process.cwd().toUpperCase()
910
const deCwd = <T extends any>(obj: T): T => {
@@ -113,8 +114,6 @@ t.test('remove plugin', async t => {
113114
t.strictSame(logs.args(), [
114115
['successfully removed plugin(s):'],
115116
['a'],
116-
['The following packages can likely be removed:'],
117-
['npm rm "a"'],
118117
])
119118
})
120119

@@ -194,6 +193,62 @@ t.test('remove plugin', async t => {
194193
])
195194
})
196195

196+
t.test('remove installed plugin', async t => {
197+
t.testdir({
198+
'.tap': {
199+
plugins: {
200+
node_modules: {
201+
'my-plugin': {
202+
'package.json': JSON.stringify({
203+
name: 'my-plugin',
204+
exports: {
205+
import: './index.mjs',
206+
require: './index.cjs',
207+
},
208+
}),
209+
'index.mjs': 'export const plugin = () => ({})',
210+
'index.cjs': 'exports.plugin = () => ({})',
211+
},
212+
},
213+
},
214+
},
215+
})
216+
const p = 'my-plugin'
217+
let buildRan = false
218+
const config = new MockConfig(t)
219+
config.pluginList.push(p)
220+
config.values.plugin.push(p)
221+
222+
let uninstalled: string[] = []
223+
const { plugin } = await t.mockImport<
224+
typeof import('../dist/esm/plugin.js')
225+
>('../dist/esm/plugin.js', {
226+
'../dist/esm/npm.js': t.createMock(npm, {
227+
uninstall: (pkgs: string[]) => {
228+
uninstalled = pkgs
229+
},
230+
}),
231+
'../dist/esm/build.js': {
232+
build: () => (buildRan = true),
233+
'foreground-child': {
234+
foregroundChild: nope,
235+
},
236+
},
237+
})
238+
239+
await plugin(['rm', p], config.l)
240+
t.strictSame(config.edited, {
241+
plugin: ['a', 'b', 'c'],
242+
})
243+
t.strictSame(config.values.plugin, ['a', 'b', 'c'])
244+
t.equal(buildRan, true)
245+
t.strictSame(logs.args(), [
246+
['successfully removed plugin(s):'],
247+
[p],
248+
])
249+
t.strictSame(uninstalled, ['my-plugin'])
250+
})
251+
197252
t.test('remove already missing plugin', async t => {
198253
const config = new MockConfig(t)
199254
let buildRan = false

0 commit comments

Comments
 (0)