Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove --skip-plugin from arguments #6972

Merged
merged 3 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/guide/cli-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ npx vue-cli-service build --skip-plugins pwa
This option is available for _every_ `vue-cli-service` command, including custom ones added by other plugins.
:::

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

```bash
npx vue-cli-service build --skip-plugins pwa,apollo
npx vue-cli-service build --skip-plugins pwa,apollo --skip-plugins eslint
```

Plugin names are resolved the same way they are during install, as described [here](./plugins-and-presets.md#installing-plugins-in-an-existing-project)
Expand Down
56 changes: 56 additions & 0 deletions packages/@vue/cli-service/__tests__/Service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,62 @@ test('api: --skip-plugins', async () => {
expect(untouched).toEqual(true)
})

describe('internal: gather pluginsToSkip and cleanup args', () => {
let resultingArgs, resultingRawArgv

const testCommand = {
id: 'test-command',
apply: api => {
api.registerCommand('foo', (_args, _rawArgv) => {
resultingArgs = _args
resultingRawArgv = _rawArgv
})
}
}
const plugin1 = {
id: 'vue-cli-plugin-test-plugin1',
apply: api => {
}
}

test('Single --skip-plugins', async () => {
const service = await createMockService([
testCommand,
plugin1
], false)
const args = { 'skip-plugins': 'test-plugin1' }
const rawArgv = ['foo', '--skip-plugins', 'test-plugin1']
await service.run('foo', args, rawArgv)
expect(resultingArgs).toEqual({ '_': [] })
expect(resultingRawArgv).toEqual([])
expect(...service.pluginsToSkip).toEqual('vue-cli-plugin-test-plugin1')
})

resultingArgs = resultingRawArgv = undefined
test('Multiple --skip-plugins', async () => {
const service = await createMockService([
testCommand,
plugin1,
{
id: 'vue-cli-plugin-test-plugin2',
apply: api => {
}
},
{
id: 'vue-cli-plugin-test-plugin3',
apply: api => {
}
}
], false)
const args = { 'skip-plugins': ['test-plugin1,test-plugin2', 'test-plugin3'] }
const rawArgv = ['foo', '--skip-plugins', 'test-plugin1,test-plugin2', '--skip-plugins', 'test-plugin3']
await service.run('foo', args, rawArgv)
expect(resultingArgs).toEqual({ '_': [] })
expect(resultingRawArgv).toEqual([])
expect([...service.pluginsToSkip].sort()).toEqual(['vue-cli-plugin-test-plugin1', 'vue-cli-plugin-test-plugin2', 'vue-cli-plugin-test-plugin3'])
})
})

test('api: defaultModes', async () => {
fs.writeFileSync('/.env.foo', `FOO=5\nBAR=6`)
fs.writeFileSync('/.env.foo.local', `FOO=7\nBAZ=8`)
Expand Down
30 changes: 23 additions & 7 deletions packages/@vue/cli-service/lib/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,29 @@ module.exports = class Service {
}
}

setPluginsToSkip (args) {
const skipPlugins = args['skip-plugins']
const pluginsToSkip = skipPlugins
? new Set(skipPlugins.split(',').map(id => resolvePluginId(id)))
: new Set()

setPluginsToSkip (args, rawArgv) {
let skipPlugins = args['skip-plugins']
const pluginsToSkip = new Set()
if (skipPlugins) {
// When only one appearence, convert to array to prevent duplicate code
if (!Array.isArray(skipPlugins)) {
skipPlugins = Array.from([skipPlugins])
}
// Iter over all --skip-plugins appearences
for (const value of skipPlugins.values()) {
for (const plugin of value.split(',').map(id => resolvePluginId(id))) {
pluginsToSkip.add(plugin)
}
}
}
this.pluginsToSkip = pluginsToSkip

delete args['skip-plugins']
// Delete all --skip-plugin appearences
let index
while ((index = rawArgv.indexOf('--skip-plugins')) > -1) {
rawArgv.splice(index, 2) // Remove the argument and its value
}
}

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

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

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