Reputation: 1630
I'm working in a team of 10 people and we've just started using Lerna. But we found some issues when we're all developing new features and also fixing existing packages.
Sometimes it happens that someone don't push changes to master branch and they do lerna publish just so they can install the newest version of that package and use it in their project.
And this causes troubles for all of us because we're not synced with package versions and lerna finds changes in packages that person did not update and forces them to publish not changed (by them) packages. Do you have some tip how to use Lerna package 'in progress' where it hasn't been published to npm yet? For now we install it from our local file using command:
npm install - save file:path_to_npm_package
Why I found this bad? Because this way it doesn't know about lerna's symlink and I should install in my project all dependencies that that lerna package depends on.
PS. Projects that use lerna packages are not other lerna packges.
Upvotes: 2
Views: 1077
Reputation: 3122
Sometimes it happens that someone don't push changes to master branch and they do lerna publish just so they can install the newest version of that package and use it in their project.
To prevent this from happening, you can utilize a release script to ensure you're:
master
This should prevent you from getting out of sync, and ensuring that published versions are clean.
$ node scripts/prerelease.js && lerna publish
scripts/prerelease.js
const {promisify} = require('util');
const execa = require('execa');
const parse = require('git-url-parse');
const rimraf = promisify(require('rimraf'));
const Listr = require('listr');
const pkg = require('../package');
const tasks = new Listr([
{
task: () =>
execa.stdout('git', ['remote', 'get-url', 'origin']).then((result) => {
const pkgUrlParsed = parse(pkg.repository.url);
const gitUrlParsed = parse(result);
const pkgUrl = pkgUrlParsed.resource + pkgUrlParsed.pathname;
const gitUrl = gitUrlParsed.resource + gitUrlParsed.pathname;
if (pkgUrl !== gitUrl) {
throw new Error(
'Cannot publish from a fork. Please clone source repository directly or ensure that the `package.json` file has a `repository.url` set.'
);
}
}),
title: 'Not publishing from fork'
},
{
task: () =>
execa.stdout('git', ['symbolic-ref', '--short', 'HEAD']).then((result) => {
if (result !== 'master') {
throw new Error('Not on `master` branch. Please switch to `master` branch before publishing.');
}
}),
title: 'On `master` branch'
},
{
task: () =>
execa.stdout('git', ['status', '--porcelain']).then((result) => {
if (result !== '') {
throw new Error('Unclean working tree. Please commit or stash changes first.');
}
}),
title: 'No uncommitted changes'
},
{
task: () =>
execa.stdout('git', ['rev-list', '--count', '--left-only', '@{u}...HEAD']).then((result) => {
if (result !== '0') {
throw new Error('Remote has changes you do not have locally. Please pull changes.');
}
}),
title: 'Have latest remote changes'
},
{
task: () => rimraf('**/node_modules'),
title: 'Removing `node_modules`'
},
{
task: () => execa('yarn'),
title: 'Installing dependencies using yarn'
},
{
task: () => execa('yarn', ['bootstrap']),
title: 'Bootstrap packages together with Lerna'
},
{
enabled: () => pkg.scripts.test !== undefined,
task: () => execa('yarn', ['test']),
title: 'Running tests'
},
{
enabled: () => pkg.scripts.build !== undefined,
task: () => execa('yarn', ['build']),
title: 'Building assets'
}
]);
tasks
.run()
.then(() => console.log('Finished! 🎉`'))
.catch((error) => {
console.error(error);
process.exit(1);
});
Upvotes: 2