Skip to content

Commit

Permalink
feat(package): add lerna 3.0.0 support
Browse files Browse the repository at this point in the history
affects: lerna-semantic-release-io, lerna-semantic-release-utils

ISSUES CLOSED: atlassian#93
  • Loading branch information
silouanwright committed Mar 2, 2019
1 parent c984ed0 commit 7ad032a
Show file tree
Hide file tree
Showing 7 changed files with 3,716 additions and 139 deletions.
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
sudo: false
language: node_js
node_js:
- 9
cache:
directories:
- node_modules
notifications:
email: false
node_js:
- "5"
before_install: .travis/before_install.sh
after_success: .travis/after_success.sh
script: npm run lint && npm test
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
"license": "MIT",
"devDependencies": {
"commitizen": "^2.9.5",
"cz-lerna-changelog": "1.2.1",
"cz-lerna-changelog": "2.0.2",
"eslint": "^3.14.1",
"husky": "^0.13.1",
"lerna": "2.0.0-beta.34",
"lerna": "3.13.1",
"lerna-semantic-release": "^9.0.1",
"validate-commit-msg": "^2.11.1"
},
Expand Down
6 changes: 2 additions & 4 deletions packages/lerna-semantic-release-io/io/lerna.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
var Repository = require('lerna/lib/Repository');
var PackageUtilities = require('lerna/lib/PackageUtilities');
const { getPackages } = require("@lerna/project");

module.exports = {
getAllPackages: function () {
var repository = new Repository();
return PackageUtilities.getPackages(repository);
return getPackages()
}
};
2 changes: 1 addition & 1 deletion packages/lerna-semantic-release-io/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"shelljs": "~0.7.0",
"simple-git": "~1.48.0",
"mockery": "~1.7.0",
"mock-fs": "~3.11.0",
"mock-fs": "4.8.0",
"sinon": "~1.17.0"
},
"peerDependencies": {
Expand Down
45 changes: 26 additions & 19 deletions packages/lerna-semantic-release-utils/for-each-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,30 @@ module.exports = function forEachPackage (tasks, options, done) {
var asyncType = (options && options.asyncType) || async.series;
var packages = options.allPackages;

var packageLocations = packages.map(function (pkg) {
return pkg.location;
});

var tasksToRunInEachPackage = packageLocations.map(function (packagePath) {
return function (next) {
var contextBoundTasks = bindTasks(tasks, Object.assign({}, extraContext, {packagePath: packagePath}), packagePath);

asyncType(contextBoundTasks, function (err) {
err && log.error(err);
next();
});
}
});

async.series(tasksToRunInEachPackage, function (err) {
err && log.error(err);
done && done();
});
packages.then(pkgs => {

var packageLocations = pkgs.map(function (pkg) {
return pkg.location;
});

var tasksToRunInEachPackage = packageLocations.map(function (packagePath) {
return function (next) {
var contextBoundTasks = bindTasks(tasks, Object.assign({}, extraContext, {packagePath: packagePath}), packagePath);

asyncType(contextBoundTasks, function (err) {
err && log.error(err);
next();
});
}
});

async.series(tasksToRunInEachPackage, function (err) {
err && log.error(err);
done && done();
});

})



};

3 comments on commit 7ad032a

@CowDotDev
Copy link

@CowDotDev CowDotDev commented on 7ad032a Sep 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well all of that was wrong, the package.then is just causing the tests to fail... but is absolutely needed for the package to work. Leaving the comment as is to show history of thought... but the packages.then is absolutely necessary, next step is to get the tests to not get upset about it.

Yo man! I was taking a look at this, and I believe your issue is that packages.then wont work because the getPackages from @lerna/project returns an array, not a promise w/ an array. The getPackages method does the promise handling for you, and the final return is an Array.reduce() that just produces a regular old array.

I have pre and perform tests working after that switch, and just need to figure out why the post test is failing an assert.

@CowDotDev
Copy link

@CowDotDev CowDotDev commented on 7ad032a Sep 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found my issue, I overlooked the io mock in the unit tests, and the lerna object is just a basic array. Since utils expects it to be a promise, that causes the test to fail with a code break. The fix would be to mock the packageVersion to be a promise with an array (in -pre for example).

The work to add a resolved Promise to the mock getAllPackages in done in -io. I'll link to a forked repo with my changes once it looks fully happy and tested.

@CowDotDev
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a fork with the changes I had to make to get Lerna 3.x support, I also fixed the broken tests. atlassian#97

Please sign in to comment.