Skip to content

Commit 8b5ab22

Browse files
fix: remove --skip-plugin from arguments passed to the plugins (vuejs#6972)
Fixes vuejs#6971
1 parent ff035c6 commit 8b5ab22

File tree

3 files changed

+81
-9
lines changed

3 files changed

+81
-9
lines changed

docs/guide/cli-service.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ npx vue-cli-service build --skip-plugins pwa
135135
This option is available for _every_ `vue-cli-service` command, including custom ones added by other plugins.
136136
:::
137137

138-
You can skip multiple plugins by passing their names as a comma-separated list:
138+
You can skip multiple plugins by passing their names as a comma-separated list or by repeating the argument:
139139

140140
```bash
141-
npx vue-cli-service build --skip-plugins pwa,apollo
141+
npx vue-cli-service build --skip-plugins pwa,apollo --skip-plugins eslint
142142
```
143143

144144
Plugin names are resolved the same way they are during install, as described [here](./plugins-and-presets.md#installing-plugins-in-an-existing-project)

packages/@vue/cli-service/__tests__/Service.spec.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,62 @@ test('api: --skip-plugins', async () => {
208208
expect(untouched).toEqual(true)
209209
})
210210

211+
describe('internal: gather pluginsToSkip and cleanup args', () => {
212+
let resultingArgs, resultingRawArgv
213+
214+
const testCommand = {
215+
id: 'test-command',
216+
apply: api => {
217+
api.registerCommand('foo', (_args, _rawArgv) => {
218+
resultingArgs = _args
219+
resultingRawArgv = _rawArgv
220+
})
221+
}
222+
}
223+
const plugin1 = {
224+
id: 'vue-cli-plugin-test-plugin1',
225+
apply: api => {
226+
}
227+
}
228+
229+
test('Single --skip-plugins', async () => {
230+
const service = await createMockService([
231+
testCommand,
232+
plugin1
233+
], false)
234+
const args = { 'skip-plugins': 'test-plugin1' }
235+
const rawArgv = ['foo', '--skip-plugins', 'test-plugin1']
236+
await service.run('foo', args, rawArgv)
237+
expect(resultingArgs).toEqual({ '_': [] })
238+
expect(resultingRawArgv).toEqual([])
239+
expect(...service.pluginsToSkip).toEqual('vue-cli-plugin-test-plugin1')
240+
})
241+
242+
resultingArgs = resultingRawArgv = undefined
243+
test('Multiple --skip-plugins', async () => {
244+
const service = await createMockService([
245+
testCommand,
246+
plugin1,
247+
{
248+
id: 'vue-cli-plugin-test-plugin2',
249+
apply: api => {
250+
}
251+
},
252+
{
253+
id: 'vue-cli-plugin-test-plugin3',
254+
apply: api => {
255+
}
256+
}
257+
], false)
258+
const args = { 'skip-plugins': ['test-plugin1,test-plugin2', 'test-plugin3'] }
259+
const rawArgv = ['foo', '--skip-plugins', 'test-plugin1,test-plugin2', '--skip-plugins', 'test-plugin3']
260+
await service.run('foo', args, rawArgv)
261+
expect(resultingArgs).toEqual({ '_': [] })
262+
expect(resultingRawArgv).toEqual([])
263+
expect([...service.pluginsToSkip].sort()).toEqual(['vue-cli-plugin-test-plugin1', 'vue-cli-plugin-test-plugin2', 'vue-cli-plugin-test-plugin3'])
264+
})
265+
})
266+
211267
test('api: defaultModes', async () => {
212268
fs.writeFileSync('/.env.foo', `FOO=5\nBAR=6`)
213269
fs.writeFileSync('/.env.foo.local', `FOO=7\nBAZ=8`)

packages/@vue/cli-service/lib/Service.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,29 @@ module.exports = class Service {
141141
}
142142
}
143143

144-
setPluginsToSkip (args) {
145-
const skipPlugins = args['skip-plugins']
146-
const pluginsToSkip = skipPlugins
147-
? new Set(skipPlugins.split(',').map(id => resolvePluginId(id)))
148-
: new Set()
149-
144+
setPluginsToSkip (args, rawArgv) {
145+
let skipPlugins = args['skip-plugins']
146+
const pluginsToSkip = new Set()
147+
if (skipPlugins) {
148+
// When only one appearence, convert to array to prevent duplicate code
149+
if (!Array.isArray(skipPlugins)) {
150+
skipPlugins = Array.from([skipPlugins])
151+
}
152+
// Iter over all --skip-plugins appearences
153+
for (const value of skipPlugins.values()) {
154+
for (const plugin of value.split(',').map(id => resolvePluginId(id))) {
155+
pluginsToSkip.add(plugin)
156+
}
157+
}
158+
}
150159
this.pluginsToSkip = pluginsToSkip
160+
161+
delete args['skip-plugins']
162+
// Delete all --skip-plugin appearences
163+
let index
164+
while ((index = rawArgv.indexOf('--skip-plugins')) > -1) {
165+
rawArgv.splice(index, 2) // Remove the argument and its value
166+
}
151167
}
152168

153169
resolvePlugins (inlinePlugins, useBuiltIn) {
@@ -225,7 +241,7 @@ module.exports = class Service {
225241
const mode = args.mode || (name === 'build' && args.watch ? 'development' : this.modes[name])
226242

227243
// --skip-plugins arg may have plugins that should be skipped during init()
228-
this.setPluginsToSkip(args)
244+
this.setPluginsToSkip(args, rawArgv)
229245

230246
// load env variables, load user config, apply plugins
231247
await this.init(mode)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy