nodeify #24

Merged
merged 7 commits into from May 30, 2016

Projects

None yet

4 participants

@SamVerschueren
Collaborator
SamVerschueren commented May 25, 2016 edited

Rewrote the module with Node. Any feedback is welcome. It's untested at the moment as I don't have a module at this time that should be released.

Should we drop 0.12 and 0.10?

Can you enable travis for this module?

@SamVerschueren SamVerschueren and 1 other commented on an outdated diff May 25, 2016
+
+var exec = function (cmd, args) {
+ const result = execa.sync(cmd, args);
+
+ if (result.stderr !== '') {
+ throw new Error(result.stderr);
+ }
+
+ return result.stdout;
+};
+
+module.exports = function (input) {
+ input = input || 'patch';
+
+ if (['patch', 'minor', 'major'].indexOf(input) === -1 && !semver.valid(input)) {
+ throw new Error('Invalid version.');
@SamVerschueren
SamVerschueren May 25, 2016 Collaborator

Error message can be better. Might be something like

  • Version should be one of patch, minor, major or a valid semver version
@sindresorhus
sindresorhus May 25, 2016 Owner

Version should be either path, minor, major, or a valid semver version

@sindresorhus
Owner

Nice! I added you to https://www.npmjs.com/package/sindre-playground. Just use the package for manual testing.

@sindresorhus
Owner

Should we drop 0.12 and 0.10?

👍

Can you enable travis for this module?

Done.

@SamVerschueren SamVerschueren and 1 other commented on an outdated diff May 25, 2016
@@ -0,0 +1,19 @@
+#!/usr/bin/env node
+'use strict';
+var meow = require('meow');
+var logSymbols = require('log-symbols');
+var np = require('./');
+
+var cli = meow(`
+ Usage
+ $ np [patch | minor | major | <version>]
@SamVerschueren
SamVerschueren May 25, 2016 Collaborator

Somehow we should inform the user that patch is the default.

@sindresorhus
sindresorhus May 25, 2016 Owner

Yup. Don't know if there's any syntax convention for default values though. Might just write it in text below.

@SamVerschueren
SamVerschueren May 25, 2016 Collaborator
$ np [patch | minor | major | <version>] (Default: patch)

or

$ np [patch | minor | major | <version>]
patch is default
@sindresorhus sindresorhus and 2 others commented on an outdated diff May 25, 2016
@@ -0,0 +1,42 @@
+'use strict';
+var semver = require('semver');
+var execa = require('execa');
+var del = require('del');
+
+var exec = function (cmd, args) {
+ const result = execa.sync(cmd, args);
+
+ if (result.stderr !== '') {
@SamVerschueren
SamVerschueren May 25, 2016 Collaborator

I thought that if stderr contains data (for example when running npm install) we should throw to inform the user.

@sindresorhus
sindresorhus May 25, 2016 Owner

Nah, stderr doesn't mean error. It's just an alternative stream commonly used for errors. The exit code decides whether something is an error.

@sindresorhus
sindresorhus May 25, 2016 Owner

Instead just log both stdout and stderr in this method. The return is also moot as it's not used anywhere.

@SamVerschueren
SamVerschueren May 25, 2016 Collaborator

It's used in the if statements.

if (exec('git', ['status', '--porcelain']) !== '') {

So just do something like this and print all the output?

const exec = (cmd, args) => {
    const {stdout, stderr} = execa.sync(cmd, args);
    console.log(stdout);
    console.log(stderr);        

    return stdout;
};
@SamVerschueren
SamVerschueren May 25, 2016 Collaborator

Going to drop using it in the if statements. It doesn't need logging for git status --porcelain.

@sindresorhus
sindresorhus May 25, 2016 Owner

stderr should be logged with console.error though.

@SamVerschueren
SamVerschueren May 25, 2016 Collaborator

Should I only log if stdout or stderr is not empty? To prevent from printing empty lines.

@sindresorhus
sindresorhus May 25, 2016 edited Owner

Actually, might be better to just pass stdio: 'inherit' in the options, instead of console.

@SamVerschueren
SamVerschueren May 25, 2016 Collaborator

It doesn't look like stdio is an option in execa

@SamVerschueren
SamVerschueren May 25, 2016 Collaborator

It's probably passed somewhere down the chain. If I pass in stdio: 'inherit' I get the error Cannot read property 'length' of null when running execa.sync('npm', ['install'], {stdio: 'inherit'});

@sindresorhus
sindresorhus May 25, 2016 Owner

Alright. Just use console.log/err then.

Do you get the error even with the latest master of execa? If so, would you mind opening an issue? stdio should definitely be supported.

@SamVerschueren
SamVerschueren May 25, 2016 Collaborator

It seems master works.

@kevva
kevva May 25, 2016 Collaborator

I think it is supported in master since we use childProcess.spawn there. In 0.4.0 we're still using execFile which doesn't have a stdio option.

@SamVerschueren
SamVerschueren May 25, 2016 edited Collaborator

Is it possible to do a new execa release or should I use console.log/err for now and create a new issue here to keep track of this improvement.

@sindresorhus
sindresorhus May 25, 2016 Owner

Just use console.log/err for now, but add a TODO comment about switching when next execa version is out. I don't think we're ready to do a release there just yet.

@SamVerschueren SamVerschueren process feedback
5fcaa84
@sindresorhus sindresorhus commented on an outdated diff May 25, 2016
@@ -1,4 +1,4 @@
-# np
+# np [![Build Status](https://travis-ci.org/sindresorhus/np.svg?branch=master)](https://travis-ci.org/sindresorhus/np) [![Coverage Status]
@sindresorhus
sindresorhus May 25, 2016 Owner

Left-over coverage.

@SamVerschueren SamVerschueren process feedback
414e7c6
@SamVerschueren SamVerschueren commented on an outdated diff May 25, 2016
+module.exports = input => {
+ input = input || 'patch';
+
+ if (['patch', 'minor', 'major'].indexOf(input) === -1 && !semver.valid(input)) {
+ throw new Error('Version should be either path, minor, major, or a valid semver version.');
+ }
+
+ if (semver.gte(process.version, '6.0.0')) {
+ throw new Error('You should not publish when running Node.js 6. Please downgrade and publish again. https://github.com/npm/npm/issues/5082');
+ }
+
+ if (execa.sync('git', ['status', '--porcelain']).stdout !== '') {
+ throw new Error('Unclean working tree. Commit or stash changes first.');
+ }
+
+ if (execa.sync('git', ['rev-list', '--count', '--left-only', '@{u}...HEAD']).stdout !== '0') {
@SamVerschueren
SamVerschueren May 25, 2016 Collaborator

Does this actually work? I updated sindre-playground via a separate clone and ran the command

$ git rev-list --count --left-only @'{u}'...HEAD
0
@SamVerschueren
SamVerschueren May 25, 2016 Collaborator

Is it possible that we should run git fetch first?

@SamVerschueren
SamVerschueren May 25, 2016 Collaborator

Tested it with running git fetch first and then the rev-list check works.

SamVerschueren added some commits May 25, 2016
@SamVerschueren SamVerschueren process feedback
45a35c8
@SamVerschueren SamVerschueren fix readme
93750c4
@SamVerschueren
Collaborator

I processed the feedback. The only thing is that at the moment if npm test is executed and it fails, it will stil release a new version, no?

@sindresorhus
Owner

It should not release a new version if tests fail.

@SamVerschueren SamVerschueren test status
9f24db2
@SamVerschueren
Collaborator
SamVerschueren commented May 25, 2016 edited

It now tests for the status returned by execa. If that is not 0, it will throw an Error with the message being the output to stderr. Not sure if this is enough?

It might be better to put that check between the console.log and console.error check, because currently it prints the stderr twice.
screen shot 2016-05-25 at 12 15 51

If we switch the order (and thus only print the stdout and not the stderr)

screen shot 2016-05-25 at 12 16 16

But not sure if stderr is ok as error message. Or do you rather prefer something like Exitted with status ${status}.

@SamVerschueren
Collaborator

Tested it for quite some scenarios. Released a package today with the new version and all seems to work quite fine.

@MoOx
Contributor
MoOx commented May 26, 2016

Maybe you can take a look to this https://github.com/MoOx/npmpub/blob/master/npmpub.js
The only difference with this module is that my forked (and rewritten) version release the current version number and do not bump.

@SamVerschueren SamVerschueren and 1 other commented on an outdated diff May 26, 2016
+const meow = require('meow');
+const logSymbols = require('log-symbols');
+const np = require('./');
+
+const cli = meow(`
+ Usage
+ $ np [patch | minor | major | <version>] (Default: patch)
+
+ Example
+ $ np patch
+`);
+
+try {
+ np(cli.input[0]);
+} catch (err) {
+ console.log(` ${logSymbols.error} ${err.message}`);
@SamVerschueren
SamVerschueren May 26, 2016 Collaborator

Should we call process.exit(1) here? If np is used in another CLI tool it should stop executing if something went wrong, no?

@sindresorhus
sindresorhus May 30, 2016 Owner

Yes, and should also use console.error.

@sindresorhus
Owner

Or do you rather prefer something like Exitted with status ${status}.

Yeah, let's go with that.

@SamVerschueren SamVerschueren process feedback
0ba0300
@SamVerschueren
Collaborator

done

@sindresorhus sindresorhus merged commit c46e63c into master May 30, 2016

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@sindresorhus sindresorhus deleted the nodeify branch May 30, 2016
@sindresorhus
Owner

Yay!

celebration

@SamVerschueren
Collaborator

Cheers :)

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