all-contributors/cli

init created empty .all-contributorsrc

schweden1997 opened this issue ยท 4 comments

Describe the bug
When I use yarn all-contributors init a .all-contributorsrc is created but it contains just an undefined in line 1.
When trying to add a contributor the json-fixer fails, since json cannot contain just an undefined.
When manually creating a .all-contributorsrc and using all-contributors add the command deletes everything in the .all-contributorsrc and adds an undefined.

To Reproduce
Steps to reproduce the behavior:

  1. yarn init -y
  2. yarn add -D all-contributors-cli
  3. git init
  4. yarn all-contributors init (.all-contributorsrc is created, but undefined)
  5. yarn all-contributors add schweden1997 doc,code (this errors)
There's still an error!
There's still an error!
There's still an error!
Error: Expected "[", "false", "null", "true", "{", number, or string but "u" found.
    at doubleCheck (/Users/marcodegaetano/Developer/oss/test-ac/.yarn/cache/json-fixer-npm-1.6.15-ae75b6da33-ae805d5155.zip/node_modules/json-fixer/index.js:29:11)
    at fixJson (/Users/marcodegaetano/Developer/oss/test-ac/.yarn/cache/json-fixer-npm-1.6.15-ae75b6da33-ae805d5155.zip/node_modules/json-fixer/index.js:103:10)
    at doubleCheck (/Users/marcodegaetano/Developer/oss/test-ac/.yarn/cache/json-fixer-npm-1.6.15-ae75b6da33-ae805d5155.zip/node_modules/json-fixer/index.js:27:44)
    at fixJson (/Users/marcodegaetano/Developer/oss/test-ac/.yarn/cache/json-fixer-npm-1.6.15-ae75b6da33-ae805d5155.zip/node_modules/json-fixer/index.js:103:10)
    at doubleCheck (/Users/marcodegaetano/Developer/oss/test-ac/.yarn/cache/json-fixer-npm-1.6.15-ae75b6da33-ae805d5155.zip/node_modules/json-fixer/index.js:27:44)
    at fixJson (/Users/marcodegaetano/Developer/oss/test-ac/.yarn/cache/json-fixer-npm-1.6.15-ae75b6da33-ae805d5155.zip/node_modules/json-fixer/index.js:103:10)
    at doubleCheck (/Users/marcodegaetano/Developer/oss/test-ac/.yarn/cache/json-fixer-npm-1.6.15-ae75b6da33-ae805d5155.zip/node_modules/json-fixer/index.js:27:44)
    at fixJson (/Users/marcodegaetano/Developer/oss/test-ac/.yarn/cache/json-fixer-npm-1.6.15-ae75b6da33-ae805d5155.zip/node_modules/json-fixer/index.js:103:10)
    at doubleCheck (/Users/marcodegaetano/Developer/oss/test-ac/.yarn/cache/json-fixer-npm-1.6.15-ae75b6da33-ae805d5155.zip/node_modules/json-fixer/index.js:27:44)
    at fixJson (/Users/marcodegaetano/Developer/oss/test-ac/.yarn/cache/json-fixer-npm-1.6.15-ae75b6da33-ae805d5155.zip/node_modules/json-fixer/index.js:103:10)

Expected behavior
init command should create correct .all-contributorsrc

Additional context
node -v v20.3.1
node -v v16.20.1 (both tested)
yarn -v 3.6.1
yarn -v 1.22.19 (both tested)
all-contributors -v 6.26.0

Solution
Error seems to occur from:

return pify(fs.writeFile)(configPath, `${formatConfig(content)}\n`)

formatConfig() requires 2 arguments. The first is configPath, second is content. Here the content is passed as the configPath.
Changing this to:

return pify(fs.writeFile)(configPath, `${formatConfig(configPath, content)}\n`);

resolves the issue.

Same thing applied to this:

fs.writeFileSync(configPath, formatConfig(config))

mprins commented

BTW when running eg. npx all-contributors-cli add mprins code,infra,review,bug,data,doc,maintenance the markdown file is updated properly

Thanks; I was seeing this too.

Temporary fix:

    "all-contributors-cli": "6.25.1"

BTW when running eg. npx all-contributors-cli add mprins code,infra,review,bug,data,doc,maintenance the markdown file is updated properly

For me it works the first time you run the command. Afterwards if trying to add another contributor it stops working due to the empty rc file.

๐ŸŽ‰ This issue has been resolved in version 6.26.1 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€