Skip to content

feat: use c12 to replace cosmiconfig #1212

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

Merged
merged 14 commits into from
Apr 9, 2025
Merged

Conversation

aa900031
Copy link
Contributor

Follow that issue #934, we can use c12 to replace cosmiconfig.

Changes

  1. The options, and localConfig is not sync anymore in Config:

Because the loadConfig provided by c12 is processed asynchronously, we need to change the way obtains options and localConfig in class Config.
For the above reasons, an additional resolved variable is provided so that we can await it and ensure that options and localConfig have been obtained correctly.

  1. Adjust the way to get config in tests, to support asynchronous

# Conflicts:
#	package-lock.json
#	test/config.js
#	test/git.init.js
#	test/git.js
#	test/github.js
#	test/gitlab.js
#	test/npm.js
#	test/prompt.js
#	test/shell.js
#	test/spinner.js
#	test/tasks.interactive.js
#	test/tasks.js
#	test/util/index.js
#	test/version.js
@webpro
Copy link
Collaborator

webpro commented Mar 29, 2025

Thanks @aa900031!

#1181 was just merged to add support for extend configuration.

What's the difference? Can we end up with one or the other, but not both?

@aa900031
Copy link
Contributor Author

Hi @webpro,

I think the biggest difference is that c12 supports nested extends and multiple extends, for example:

In my-project, extends two configs

// my-project/.release-it.json
{
    "extends": [
        "github:owner/repo",
        "github:foo/bar",
    ]
}

These two configs also extended from other repos

# github/owner/repo/.release-it.toml
extends = [
  "github:other/repo"
]
[git]
commitMessage = "Release version ${version}"
# github/other/repo/.release-it.yaml
gitlab:
  release: true

Another key point in the example above is that extend doesn't have to be in a JSON file.

So switching to c12 will make the functionality more complete and increase flexibility.

@webpro
Copy link
Collaborator

webpro commented Mar 29, 2025

Thanks for the explanation, that makes sense.

The async config loading adds a lot of code overall, but I guess sooner or later this had to happen anyway.

@juancarlosjr97 What do you think?

Copy link

pkg-pr-new bot commented Mar 29, 2025

Open in StackBlitz

npm i https://pkg.pr.new/release-it@1212

commit: 3d6ecf6

package.json Outdated
@@ -94,11 +94,13 @@
"issue-parser": "7.0.1",
"lodash.get": "4.4.2",
"lodash.merge": "4.6.2",
"make-synchronized": "0.6.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry my bad, that is try to make load config to synchronized, but that have some problems

I'm already drop that at d3e7fbb

@aa900031
Copy link
Contributor Author

@webpro There tests have some problems about mock fetch response, here is the PR humanwhocodes/mentoss#92

- `github:owner/repo#tag`: Get the config from the specified tag in the repo at Github.
- `github:owner/repo:subdir#tag`: Get the config from the specified tag in the repo sub dir at Github.

And support other schema, either `gitlab:`, `bitbucket:`, or `https:`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is HTTPS, then the file should be public and not behind authorization. However, GitHub, GitLab, and BitBucket will work as it is getting pulled with the token, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you right, if want to get private repo or private content from https, it could use the environment GIGET_AUTH to set it. The value will be set in Authorization: Bearer ... header

Refs to giget docs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Then I am super happy! I did not know we were working with giget, but I can see it is a transitive dependency of c12, so awesome :)

@juancarlosjr97
Copy link
Contributor

Everything looks good, a very nice improvement, only one question.

@juancarlosjr97
Copy link
Contributor

Also, this will make this change https://github.com/release-it/release-it/pull/1211/files not longer needed @webpro I believe

@webpro
Copy link
Collaborator

webpro commented Mar 30, 2025

Also, this will make this change https://github.com/release-it/release-it/pull/1211/files not longer needed @webpro I believe

True! Thanks for chiming in, very glad to have your opinion on this one.

@webpro
Copy link
Collaborator

webpro commented Mar 30, 2025

About the Config constructor. Currently it automatically starts an async loader, while constructor itself is sync, which might be a bit unclear that we need config.resolve:

const config = new Config();
await config.resolved;

Is this a well-known pattern to add async logic to the constructor? If not, how about this:

const config = new Config();
await config.resolve(); // or await config.init();

So that the async part isn't automatically triggered from the constructor, but it would be made more explicit by having to call resolve() or init() on the instance.

For me personally this latter pattern feels more natural, but happy to hear your thoughts.

@aa900031
Copy link
Contributor Author

aa900031 commented Mar 30, 2025

@webpro I think that make more sense as you say. I like this pattern to use await config.init(), so I'll refactor that later to fit that.

aa900031 added 2 commits April 9, 2025 23:08
# Conflicts:
#	package-lock.json
#	package.json
@aa900031
Copy link
Contributor Author

aa900031 commented Apr 9, 2025

Hi @webpro , mentoss was released include fix, and I'm already upgraded it. Please check it again, thanks

@webpro
Copy link
Collaborator

webpro commented Apr 9, 2025

Thank you @aa900031! Also for the fix in Mentoss 🔥

@webpro webpro merged commit 23272f8 into release-it:main Apr 9, 2025
10 checks passed
@webpro
Copy link
Collaborator

webpro commented Apr 9, 2025

🚀 This pull request is included in v19.0.0-next.5. See Release 19.0.0-next.5 for release notes.

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

Successfully merging this pull request may close these issues.

3 participants