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

Support *.cjs configs #1814

Comments

@opiation
Copy link
Contributor

New feature motivation

When attempting to use semantic-release with a ESM-written package ("type": "module") and node with ES modules enabled, a plain release.config.js config fails understandably given the tool is written with require()s. Renaming the config to release.config.cjs does not work as the version of cosmicconfig used by semantic-release does not search for .cjs files. Thus, only the json config options are available.

Updating the cosmicconfig dependency to v7.0.0 would allow one to use semantic-release developing a package implicitly in ES modules (--experimental-modules).

New feature description

Supports *.cjs file extensions like release.config.cjs for configuring semantic-release.

New feature implementation

Update cosmicconfig dependency to v7.0.0 which adds support for *.cjs file extensions.

@travi
Copy link
Member

travi commented Feb 22, 2021

please double check the version of semantic-release that you are using. the current version of cosmiconfic that is depended on by semantic-release is already v7.0.0:

"cosmiconfig": "^7.0.0",

@opiation
Copy link
Contributor Author

opiation commented Feb 22, 2021

My apologies, @travi. I could have sworn that I looked at master but must have still been looking at the v17.3.0 tag. You're correct that cosmicconfig was indeed updated recently (v17.3.6). I've updated my local version to use v17.3.9 however, .cjs still is not read.

My config:

// release.config.cjs

const releaseRules = [
  { type: 'docs', release: 'patch' }
]

const gitOptions = {
  assets: ['CHANGELOG.md', 'dist/**/*', 'package.json']
}

module.exports = {
  plugins: [
    ['@semantic-release/commit-analyzer', { releaseRules }],
    '@semantic-release/release-notes-generator',
    '@semantic-release/changelog',
    '@semantic-release/npm',
    ['@semantic-release/git', gitOptions]
  ]
}
$ yarn run semantic-release --debug --dry-run

[11:22:25 AM] [semantic-release] › ℹ  Running semantic-release version 17.3.9                                                                                                                  
  semantic-release:config load config from: undefined +0ms 

^^^ I've omitted the remainder of the output as the undefined config seems sufficient to indicate this might be a bug. Given that possibility, I'll include some more details to save time.

$ node --version
v14.15.4

$ echo ${NODE_OPTIONS}
--experimental-modules --experimental-vm-modules --max-old-space-size=4096

$ yarn --version
1.22.10

Using Ubuntu 18.04.5 LTS

Let me know if any additional information is needed or if I've misread any documentation about using cjs configs.

EDIT: Also tried clearing node_modules and reinstalling to no avail.

$ rm -rf node_modules && yarn install

@travi
Copy link
Member

travi commented Feb 22, 2021

this seems like a valid request and we want to make sure that semantic-release isn't blocking this capability. however, we may not get a chance to investigate deeply right away.

if you could help us investigate, it would really help this be resolved more quickly. our usage of cosmiconfig is here:

const {config, filepath} = (await cosmiconfig(CONFIG_NAME, {searchPlaces: CONFIG_FILES}).search(cwd)) || {};
. if you identify a problem with our usage, please start a PR suggesting the change that would fix our usage and we'll be happy to work through additional details there.

@opiation
Copy link
Contributor Author

Sure thing! Here's what I've found briefly so far...

In lib/get-config.js, cosmicconfig() is invoked with CONFIG_NAME as the moduleName (from the cosmicconfig API) and CONFIG_FILES is provided as explicit searchPlaces.

const CONFIG_NAME = 'release';

const CONFIG_FILES = [
'package.json',
`.${CONFIG_NAME}rc`,
`.${CONFIG_NAME}rc.json`,
`.${CONFIG_NAME}rc.yaml`,
`.${CONFIG_NAME}rc.yml`,
`.${CONFIG_NAME}rc.js`,
`${CONFIG_NAME}.config.js`,
];

According to the cosmicconfig docs however, the module name, in this case "release" is used to create the default set of search places.

This is used to create the default searchPlaces and packageProp.

By providing the searchPlaces explicitly with CONFIG_FILES, these defaults are overwritten, thus excluding the .cjs variants that are now supported by cosmicconfig.

For reference, the default searchPlaces can be found here (inlined below).

[
  'package.json',
  `.${moduleName}rc`,
  `.${moduleName}rc.json`,
  `.${moduleName}rc.yaml`,
  `.${moduleName}rc.yml`,
  `.${moduleName}rc.js`,
  `.${moduleName}rc.cjs`,
  `${moduleName}.config.js`,
  `${moduleName}.config.cjs`,
]

Based on the current implementation and the defaults generated by cosmicconfig, it seems likely the best course of action is to remove the explicit searchPlaces option and rely on cosmicconfig's defaults which would include .cjs variants.

I might have time to test this locally and/or submit a PR but thought I'd at least share these findings here in case anyone has time to do so.

@opiation
Copy link
Contributor Author

I was able to test this locally in the end and removing the searchPlaces works as I expected and described above. I'll submit a PR shortly.

opiation added a commit to opiation/semantic-release that referenced this issue Feb 22, 2021
This change adds support for `*.cjs` config files by removing the
explicit use of `searchPlaces` options and relying and the default
search places generated by `cosmicconfig`.  As per the docs for
[`cosmicconfig`][cc], the defaults include all the extensions/formats
previously supported by semantic-release in addition to the new .cjs
variants.

Resolves [semantic-release#1814][issue].

[issue]: https://gitlab.qualiproto.fr/pyx4/qualipso/-/issues/2172
[cc]: https://github.com/davidtheclark/cosmiconfig#searchplaces
opiation added a commit to opiation/semantic-release that referenced this issue Feb 22, 2021
This change adds support for `*.cjs` config files by removing the
explicit use of `searchPlaces` options and relying and the default
search places generated by `cosmicconfig`.  As per the docs for
[`cosmicconfig`][cc], the defaults include all the extensions/formats
previously supported by semantic-release in addition to the new .cjs
variants.

Resolves [semantic-release#1814][issue].

[issue]: semantic-release#1814
[cc]: https://github.com/davidtheclark/cosmiconfig#searchplaces
@opiation
Copy link
Contributor Author

To anyone interested, submitted PR #1815 and it is pending review.

opiation added a commit to opiation/semantic-release that referenced this issue Feb 26, 2021
This change adds support for `*.cjs` config files by removing the
explicit use of `searchPlaces` options and relying and the default
search places generated by `cosmicconfig`.  As per the docs for
[`cosmicconfig`][cc], the defaults include all the extensions/formats
previously supported by semantic-release in addition to the new .cjs
variants.

Resolves [semantic-release#1814][issue].

[issue]: semantic-release#1814
[cc]: https://github.com/davidtheclark/cosmiconfig#searchplaces
travi pushed a commit that referenced this issue Feb 26, 2021
…1815)

This change adds support for `*.cjs` config files by removing the
explicit use of `searchPlaces` options and relying and the default
search places generated by `cosmicconfig`.  As per the docs for
[`cosmicconfig`][cc], the defaults include all the extensions/formats
previously supported by semantic-release in addition to the new .cjs
variants.

Resolves [#1814][issue].

[issue]: #1814
[cc]: https://github.com/davidtheclark/cosmiconfig#searchplaces
This was referenced Mar 7, 2021
This was referenced Mar 12, 2021
evan-gerard added a commit to evan-gerard/Semantic-Release that referenced this issue May 22, 2022
…#1815)

This change adds support for `*.cjs` config files by removing the
explicit use of `searchPlaces` options and relying and the default
search places generated by `cosmicconfig`.  As per the docs for
[`cosmicconfig`][cc], the defaults include all the extensions/formats
previously supported by semantic-release in addition to the new .cjs
variants.

Resolves [#1814][issue].

[issue]: semantic-release/semantic-release#1814
[cc]: https://github.com/davidtheclark/cosmiconfig#searchplaces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment