-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
This is the same issue that lerna-lite had here: lerna-lite/lerna-lite#729
Describe the bug
If I have an empty .config.json file in my project root then lerna will crash because it assumes that the config file was for itself and not for something else (and it tries to parse it and then crash because the config property is undefined)
IMO, since lerna is a tool that is commonly used as part of tooling of projects that have their own config files, the tool shouldn't assume that a generic name such as .config.json is a config file that is intended for itself (now that I think about it my app also shouldn't assume that TBH, but maybe it has a slightly stronger claim to "squat" on a generic name like this).
Expectation
TLDR: The default search path for config files should consist of files that have lerna in their names, not the generic ones. This is just my opinion though, not a strongly held one either.
Or if you think that it's okay to assume .config.json belonging to lerna, that's fine by me, but then it should at least validate the config and error out with something more obvious explaining that the config was missing certain (mandatory) properties from it.
Reproduction
cd some-lerna-project-root-dir
touch .config.json
yarn lerna run 'echo hello'Which will then crash with:
lerna notice cli v8.1.7
lerna ERR! TypeError: Cannot use 'in' operator to search for 'extends' in undefined
lerna ERR! at applyExtends (/home/peter/a/cacti/node_modules/lerna/dist/index.js:2429:17)
lerna ERR! at Object.transform (/home/peter/a/cacti/node_modules/lerna/dist/index.js:2694:28)
lerna ERR! at load (/home/peter/a/cacti/node_modules/lerna/node_modules/cosmiconfig/dist/ExplorerSync.js:20:32)
lerna ERR! at emplace (/home/peter/a/cacti/node_modules/lerna/node_modules/cosmiconfig/dist/util.js:12:20)
lerna ERR! at ExplorerSync.load (/home/peter/a/cacti/node_modules/lerna/node_modules/cosmiconfig/dist/ExplorerSync.js:23:42)
lerna ERR! at ExplorerSync.search (/home/peter/a/cacti/node_modules/lerna/node_modules/cosmiconfig/dist/ExplorerSync.js:30:33)
lerna ERR! at #resolveLernaConfig (/home/peter/a/cacti/node_modules/lerna/dist/index.js:2698:27)
lerna ERR! at new _Project (/home/peter/a/cacti/node_modules/lerna/dist/index.js:2560:78)
lerna ERR! ENOPROJECT Lerna Project not initialized!
/home/peter/a/cacti/node_modules/lerna/dist/index.js:3181
throw new ValidationError("ENOPROJECT", "Lerna Project not initialized!");
^
ValidationError: Lerna Project not initialized!
at get project [as project] (/home/peter/a/cacti/node_modules/lerna/dist/index.js:3181:17)
at /home/peter/a/cacti/node_modules/lerna/dist/index.js:3158:35 {
prefix: 'ENOPROJECT'
}
Node.js v20.11.0Used Package Manager
yarn@4.3.1
Failure Logs / Configuration
lerna.json
{
"version": "2.0.0-rc.3",
"npmClient": "yarn",
"command": {
"version": {
"message": "chore(release): publish"
}
},
"changelogPreset": "angular"
}lerna-debug.log
N/A
Environment
$ npx lerna info
lerna notice cli v8.1.7
Environment info:
System:
OS: Linux 5.10 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish)
CPU: (24) x64 12th Gen Intel(R) Core(TM) i7-12850HX
Binaries:
Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node
Yarn: 4.3.1 - ~/.nvm/versions/node/v20.11.0/bin/yarn
npm: 10.2.4 - ~/.nvm/versions/node/v20.11.0/bin/npm
Utilities:
Git: 2.34.1 - /usr/bin/git