Skip to content

Conversation

@petermetz
Copy link
Contributor

The credit should go to @ghiscoding - I'm just back-porting his fix to the same bug in lerna-lite to lerna here.

Description

The newer version of cosmicconfig does not suffer from the issue that
it defaults to looking for .config.json the way 8.x does.
This upgrade implicitly fixes the underlying issue that lerna has for the
same reason.

Motivation and Context

Fixes #4061

lerna-lite used to have the same bug, you can read the full context here:

  1. bug: empty .config.json file in project root gets picked up as lerna-lite config lerna-lite/lerna-lite#729
  2. [Bug]: Config search fails if there is a file named .config cosmiconfig/cosmiconfig#313
  3. feat: add support for TypeScript configuration files cosmiconfig/cosmiconfig#311

How Has This Been Tested?

npm test && npm run integration

The tests all passed, but for the integratin tests 2 of them failed with the logs pasted below. They were failing the same way on main prior to my changes so I'm assuming this to be a false positive but you tell me.

Summary of all failing tests
 FAIL  __tests__/lerna-publish-validation.spec.ts
  ● lerna publish exits with EBEHIND when behind upstream remote

    Command failed with exit code 128: git commit -m upstream change
    Author identity unknown

    *** Please tell me who you are.

    Run

      git config --global user.email "you@example.com"
      git config --global user.name "Your Name"

    to set your account's default identity.
    Omit --global to set the identity only in this repository.

    fatal: empty ident name (for <peter@C11-73JFIMZA8J6.dir.svc.accenture.com>) not allowed

      26 |   await fs.outputFile(path.join(cloneDir, "README.md"), "upstream change");
      27 |   await gitAdd(cloneDir, "-A");
    > 28 |   await gitCommit(cloneDir, "upstream change");
         |   ^
      29 |   await execa("git", ["push", "origin", "main"], { cwd: cloneDir });
      30 |
      31 |   // throws during interactive publish (local)

      at makeError (../node_modules/execa/lib/error.js:59:11)
      at handlePromise (../node_modules/execa/index.js:114:26)
      at Object.<anonymous> (__tests__/lerna-publish-validation.spec.ts:28:3)

 FAIL  __tests__/lerna-bootstrap-yarn.spec.ts
  ● lerna bootstrap --npm-client yarn

    Command failed with exit code 1: node /home/peter/a/lerna/packages/lerna/dist/cli.js bootstrap --npm-client yarn
    lerna notice cli v8.1.8
    lerna info ci enabled
    lerna info Bootstrapping 4 packages
    lerna info lifecycle package-4@1.0.0~preinstall: package-4@1.0.0
    lerna info Installing external dependencies
    lerna ERR! yarn install --mutex network:42424 --non-interactive exited 1 in '@integration/package-2'
    lerna ERR! yarn install --mutex network:42424 --non-interactive stdout:
    Unknown Syntax Error: Unsupported option name ("--mutex").

    $ yarn install [--json] [--immutable] [--immutable-cache] [--refresh-lockfile] [--check-cache] [--check-resolutions] [--inline-builds] [--mode #0]
    lerna ERR! yarn install --mutex network:42424 --non-interactive exited 1 in '@integration/package-2'
    lerna WARN complete Waiting for 2 child processes to exit. CTRL-C to exit immediately.

    > package-4@1.0.0 preinstall /tmp/dd16a3ecb8e9a0c03b35291c2f37dd47/package-4
    > exit 0

       9 |   const lerna = cliRunner(cwd);
      10 |
    > 11 |   const { stderr } = await lerna("bootstrap", "--npm-client", "yarn");
         |                      ^
      12 |   expect(stderr).toMatchInlineSnapshot(`
      13 | lerna notice cli __TEST_VERSION__
      14 | lerna info ci enabled

      at makeError (../node_modules/execa/lib/error.js:59:11)
      at handlePromise (../node_modules/execa/index.js:114:26)
      at Object.<anonymous> (__tests__/lerna-bootstrap-yarn.spec.ts:11:22)


Test Suites: 2 failed, 31 passed, 33 total
Tests:       2 failed, 83 passed, 85 total
Snapshots:   93 passed, 93 total
Time:        68.037 s, estimated 83 s
Ran all test suites.

——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 NX   Ran target integration for project integration and 6 task(s) they depend on (1m)

      With additional flags:
        --maxWorkers=2

   ✖  1/7 failed
   ✔  6/7 succeeded [4 read from cache]

View structured, searchable error logs at https://nx.app/runs/8xAbKEIHdj

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • [] Chore (change that has absolutely no effect on users)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

The newer version of cosmicconfig does not suffer from the issue that
it defaults to looking for .config.json the way 8.x does.
This upgrade implicitly fixes the underlying issue that lerna has for the
same reason.

Fixes #4061

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
@nx-cloud
Copy link

nx-cloud bot commented Aug 9, 2024

@JamesHenry
Copy link
Member

@petermetz Thanks for this! I can't reproduce an issue, it seems to be specific to your environment.

What does git config --global user.email and git config --global user.name return for you on your machine?

@JamesHenry
Copy link
Member

I made sure everything was all good on latest main here: #4071

So I am good to merge this in the meantime, thanks again!

@JamesHenry JamesHenry merged commit 960bdd9 into lerna:main Aug 26, 2024
@petermetz petermetz deleted the fix-core-avoid-reading-empty-dot-config-json branch August 27, 2024 16:58
@petermetz
Copy link
Contributor Author

@JamesHenry Thank you very much for the review!

What does git config --global user.email and git config --global user.name return for you on your machine?

Nothing - I set these parameters on a per-repo basis only.

Now, with that said, if I run them without the --global flag then it would show my corporate email address for user.email (the one that is associated with my GitHub account - I double checked) and "Peter Somogyvari" for user.name. Not sure if this helps or not but I didn't want to just sidestep the question. :-)

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.

fix(core): empty .config.json file in project root gets picked up as lerna config

2 participants