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

feat: support plugins with wildcards #978

Merged
merged 2 commits into from
Mar 5, 2024
Merged

Conversation

mdonnalley
Copy link
Contributor

@mdonnalley mdonnalley commented Feb 28, 2024

Allow plugins to be defined with minimatch patterns. For instance:

{
  "dependencies": {
    "@oclif/core": "^3",
    "@oclif/plugin-help": "^6",
    "@oclif/plugin-plugins": "^4",
    "@org/cool-plugin": "^1",
    "@org/awesome-plugin": "^1",
   },
  "oclif": {
    "plugins": [
        "@oclif/plugin-*",
        "@org/*",
     ]
  }
}

This PR also exposes a new option on Config called pluginAdditions that informs Config of additional plugins that should be loaded. This is solves the use case described in #976

pluginAdditions is defined as:

  pluginAdditions?: {
    core?: string[] // core plugins that should be loaded
    dev?: string[] // dev plugins that should be loaded
    path?: string // path to load these plugins from (defaults to root plugin's path)
  }

Example:

  const config = new Config({
    pluginAdditions: {
      core: ['@oclif/plugin-*'],
    },
    root: __dirname,
  })
  await config.load()

QA

  • checkout branch and yarn && yarn build
  • oclif generate my-cli
  • cd my-cli && yarn link @oclif/core
  • Change plugins entry in package.json to "plugins": ["@oclif/plugin-*"]
  • bin/dev.js should should help and plugins topics
  • bin/dev.js plugins --core should show plugin-help and plugin-plugins
  • remove plugins from package.json
  • change bin/run.js to:
#!/usr/bin/env node

// eslint-disable-next-line unicorn/prefer-top-level-await
;(async () => {
  const {execute} = await import('@oclif/core')
  await execute({
    loadOptions: {
      pluginAdditions: {
        core: ['@oclif/plugin-*'],
      },
      root: __dirname,
    },
  })
})()
  • bin/dev.js should should help and plugins topics
  • bin/dev.js plugins --core should show plugin-help and plugin-plugins
  • oclif generate another-cli
  • cd another-cli && yarn add @oclif/plugin-version
  • change bin/dev.js of my-cli to:
#!/usr/bin/env node

// eslint-disable-next-line unicorn/prefer-top-level-await
;(async () => {
  const {execute} = await import('@oclif/core')
  await execute({
    loadOptions: {
      pluginAdditions: {
        core: ['@oclif/plugin-*'],
        path: 'path/to/another-cli'
      },
      root: __dirname,
    },
  })
})()
  • bin/dev.js should should help, plugins, and version topics/commands
  • bin/dev.js plugins --core should show plugin-help, plugin-plugins, and plugin-version

Closes #976
Closes oclif/oclif#1235

@mdonnalley mdonnalley added the enhancement New feature or request label Feb 28, 2024
Copy link

git2gus bot commented Feb 28, 2024

This issue has been linked to a new work item: W-15141781

@isaacroldan
Copy link

Tested this for our use case and works great 👌

@shetzel
Copy link
Contributor

shetzel commented Mar 5, 2024

All QA steps passed.

@shetzel shetzel merged commit a43c000 into main Mar 5, 2024
79 checks passed
@shetzel shetzel deleted the mdonnalley/wildcard-plugins branch March 5, 2024 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants