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

Error when using Lerna 3.0 #405

Closed
1 of 4 tasks
backflip opened this issue Aug 6, 2018 · 2 comments
Closed
1 of 4 tasks

Error when using Lerna 3.0 #405

backflip opened this issue Aug 6, 2018 · 2 comments

Comments

@backflip
Copy link
Contributor

backflip commented Aug 6, 2018

When using Commitlint in a monorepo with Lerna 3.0.0-rc.0, the following error occurs:

Error: Cannot find module 'lerna/lib/Repository'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at resolveFileName (node_modules/resolve-from/index.js:17:39)
    at resolveFrom (node_modules/resolve-from/index.js:31:9)
    at module.exports (node_modules/resolve-from/index.js:34:41)
    at module.exports (node_modules/import-from/index.js:4:49)
    at getPackages (node_modules/@commitlint/config-lerna-scopes/index.js:14:21)
    at scope-enum (commitlint.config.js:10:41)
    at Object.<anonymous> (node_modules/@commitlint/execute-rule/lib/index.js:23:27)
    at new Promise (<anonymous>)
    at Object.<anonymous> (node_modules/@commitlint/execute-rule/lib/index.js:21:25)

Expected Behavior

As soon as Lerna 3 is stable, https://github.com/marionebl/commitlint/tree/master/%40commitlint/config-lerna-scopes should be updated to work with it.

Current Behavior

The current code in https://github.com/marionebl/commitlint/tree/master/%40commitlint/config-lerna-scopes is not compatible with Lerna 3.

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

Figure out how Lerna 3 exposes package names.

Steps to Reproduce (for bugs)

  1. Have a working monorepo using Lerna 2.
  2. Bump Lerna to 3
  3. See above error

Context

I want to be able to update a Lerna monorepo to v3.

Your Environment

Executable Version
commitlint --version 7.0.0
git --version 2.15.2
node --version 10.8.0
@backflip
Copy link
Contributor Author

backflip commented Aug 6, 2018

Judging from https://github.com/lerna/lerna/blob/master/core/project/index.js, the updated code should probably look something like this:

async function getPackages(context) {
	const ctx = context || {};
	const cwd = ctx.cwd || process.cwd();

	const Project = importFrom(cwd, '@lerna/project');

	const project = new Project(cwd);
	const packages = await project.getPackages();

	return packages
		.map(pkg => pkg.name)
		.map(name => (name.charAt(0) === '@' ? name.split('/')[1] : name));
}

Should I open a PR for this? Or are you working on an update to 3.0 anyway?

UPDATE: I have opened a PR to demonstrate possible changes: https://github.com/marionebl/commitlint/pull/406

@marionebl
Copy link
Contributor

@backflip Thanks for your proposed solution and the PR.

I went with an approach that keeps lerna v2 support around for the time being. The improvements / fixes are released via 7.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants