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

Local plugin and parameters #1031

Open
LastDragon-ru opened this issue Aug 14, 2023 · 8 comments
Open

Local plugin and parameters #1031

LastDragon-ru opened this issue Aug 14, 2023 · 8 comments

Comments

@LastDragon-ru
Copy link

LastDragon-ru commented Aug 14, 2023

I have a local plugin:

import {Plugin} from 'release-it';

class Dump extends Plugin {
    getInitialOptions(options, pluginName) {
        return Object.assign({param: null}, options[pluginName]);
    }

    beforeRelease() {
        throw new Error(this.options.param);
    }
}

export default Dump;

It is added to config and it is work

plugins: {
    './.release-it/plugins/Dump.mjs':       {
        'param': 123
    },
},

But I cannot find a way to pass parameters to it :( When I try to pass --plugins.<name>.param it just fail with Error: Cannot find module '<name>'. I have tried --plugins.dump.param=455, --plugins.Dump.param=455, --plugins../.release-it/plugins/Dump.mjs.param=455, --plugins./.release-it/plugins/Dump.mjs.param=455, but nothing work.

I'm doing something wrong or maybe it just not supported yet?

@webpro
Copy link
Collaborator

webpro commented Aug 30, 2023

You can try quoting:

--'plugins./.release-it/plugins/Dump.mjs.param=455'
'--plugins./.release-it/plugins/Dump.mjs.param=455'

@khylias
Copy link

khylias commented Feb 19, 2024

Which solution worked @LastDragon-ru ?

I've a similar case with local plugins but quotes annotations doesn't affect modules load.

./release/.release-it.json

{
  "plugins": {
    "./release/calver-plugin.js": {
	    "format": "yyyy.0M.0D",
	    "increment": "calendar",
	    "rcIncrement": "calendar.rc",
	    "fallbackIncrement": "calendar",
	    "candidate": false
    },
    "@release-it/bumper": {
	    "in": ["package.json"],
	    "out": ["package.json"]
    },
    "./release/generate-changelog-plugin.js": {}
  }
}

./package.json

"release-candidate": "release-it --ci --config ./release/.release-it.json --plugins./release/calver-plugin.js.candidate=true",

I can't find an effective annotation to configure my "candidate" argument.
Best I can have is this message : Error: Cannot find module '/release/calver-plugin'

@LastDragon-ru
Copy link
Author

Which solution worked @LastDragon-ru ?

@khylias, to be honest, it working without plugin..... 😅

@webpro
Copy link
Collaborator

webpro commented Feb 19, 2024

In the example package.json, the argument is not quoted

"release-candidate": "release-it '--plugins../release/calver-plugin.js.candidate'"

You'd need to fiddle a bit with the dots and the quotes to get it right. Here, dots are object key separators, but also path segments. Use --debug to see the results. I think providing the argument already means true (but probably any not-falsy value will do).

@khylias
Copy link

khylias commented Feb 20, 2024

Yes, I didn't quote the command in the package.json but I was able to test with your first answer and nothing helped.

More precisely, I see in the debug that it's the .js extension that's causing the problem, precisely because the dot is a separator and a segment of the path.
The result is the same whether between quotes or not :

$ release-it --debug --ci --config ./release/.release-it.json '--plugins./release/calver-plugin.js.candidate'
plugins: {
    '/release/calver-plugin': { js: [Object] },
    './release/calver-plugin.js': {
      format: 'yyyy.0M.0D',
      increment: 'calendar',
      rcIncrement: 'calendar.rc',
      fallbackIncrement: 'calendar',
      candidate: false
    },
    '@release-it/bumper': { in: [Array], out: [Array] },
    './release/generate-changelog-plugin.js': {}
  },

Add more dot before extension will add more sub-object in configuration.

@webpro
Copy link
Collaborator

webpro commented Feb 20, 2024

Maybe you can omit the .js extension? Or is it ESM and fails because of that?

Either way, it's something I might be able to handle/fix in release-it core.

@khylias
Copy link

khylias commented Feb 20, 2024

No, unfortunately I can't. ESM does not allow you to import the module without the extension

@LastDragon-ru LastDragon-ru reopened this Feb 20, 2024
@webpro
Copy link
Collaborator

webpro commented Feb 20, 2024

Feel free to take a stab at it btw, happy to review PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants