Git Product home page Git Product logo

nps-utils's Issues

Feature: better documentation

Accidentally created the issue before writing the description.
So:

  1. This doesn't work for me. https://doclets.io/kentcdodds/nps-utils/master
    • Once it loads (which takes a few) I can't navigate around it without getting a 502.
  2. This generated documentation is sub par: https://doc.esdoc.org/github.com/kentcdodds/nps-utils/function/index.html#static-function-crossEnv
    • It's probably convenient to run (in CI/CD process). It's maybe convenient for you to maintain? But more important than all that is it's just not as intelligible as we (the greater community) has come to expect from senior engineers such as yourself. I mean that with respect of course.

If you would like me to volunteer, I would help you redo it. Gitbooks, a nextjs app, whatever you want.

Add function for rimraf

Similar to #1 and #2. Maybe we could just return a script that uses the native commands based on the platform.

concurrent: options

Although in most cases you would want to use --kill-others-on-fail, I fell in a situation where I would prefer if it was off.
Also concurrently has some other options like --no-color, --raw, and --allow-restart which I believe should be toggleable in an options object sent as a second argument to .concurrent.

export getBin, but without prepending node

It would be nice to be able to get the path to a binfile of a package. getBin is not exported, but it also prepends node.

So I propose adding const runBin = (...args) => `node ${getBin(...args)}` internally and exporting getBin

My very specific use case would be to be able to run Jest under ndb like

const {getBin} = require('nps-utils')

module.exports = {
 test: {
   inspect: `ndb ${getBin('jest')} --runInBand`
 }
}

Methods should use config path defined in package.json

While refactoring my package.json to use nps I haven noticed that methods like:

  • concurrent.nps or
  • series.nps

ignore custom config path provided via "nps --config". It would be extremely easy to check if env contains config path e.g.
process.argv.slice(3,4)
& reuse it while creating new nps call in following locations (nps-utils/src/index.js):

That would simplify reference of scripts with config in custom location, don't you think?

I'm happy to make pull request but due to #12 I'm not confident that this repo is ready to be forked ;-/

concurrent + yarn : ENOTEMPTY dir not empty npm-lodash...

When I run my setup script in circle ci using npm-utils' concurrent to yarn 3 directories at once it fails. Changing concurrent to series and it passes.

I think this maybe the same issue: yarnpkg/yarn#2531 (comment)
and according to that link it's resolved by:

concurrently -r -k \"yarn run db\" \"yarn run dev\"

Here's the log:

$ npm start setup

> [email protected] start /home/ubuntu/web-admin
> nps "setup"

nps is executing `setup` : nps scrub.yarn && nps setup.all
nps is executing `scrub.yarn` : yarn cache clean
yarn cache v0.27.5
⠁ ⠂ ⠄ ⡀ ⢀ ⠠ ⠐ ⠈ ⠁ ⠂ ⠄ ⡀ ⢀ success Cleared cache.
Done in 1.47s.
nps is executing `setup.all` : node node_modules/concurrently/src/main.js --kill-others-on-fail --prefix-colors "bgBlue.bold,bgMagenta.bold,bgGreen.bold" --prefix "[{name}]" --names "setup.meta,setup.client,setup.server" 'nps setup.meta' 'nps setup.client' 'nps setup.server'
[setup.meta] nps is executing `setup.meta` : yarn
[setup.client] nps is executing `setup.client` : cd www && cd client && yarn add -E [email protected]
[setup.server] nps is executing `setup.server` : cd www && cd server && yarn
[setup.client] yarn add v0.27.5
[setup.meta] yarn install v0.27.5
[setup.client] [1/4] Resolving packages...
[setup.server] yarn install v0.27.5
[setup.meta] [1/4] Resolving packages...
[setup.server] [1/4] Resolving packages...
[setup.meta] success Already up-to-date.
[setup.meta] Done in 1.44s.
[setup.meta] nps setup.meta exited with code 0
[setup.server] [2/4] Fetching packages...
[setup.client] [2/4] Fetching packages...

[setup.client] error An unexpected error occurred: "ENOTEMPTY: directory not empty, rmdir '/home/ubuntu/.cache/yarn/v1/npm-lodash-4.17.4-78203a4d1c328ae1d86dca6460e369b57f4055ae'".
[setup.client] info If you think this is a bug, please open a bug report with the information provided in "/home/ubuntu/web-admin/www/client/yarn-error.log".
[setup.client] info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
[setup.client] The script called "setup.client" which runs "cd www && cd client && yarn add -E [email protected]" failed with exit code 1 https://github.com/kentcdodds/nps/blob/v5.7.0/other/ERRORS_AND_WARNINGS.md#failed-with-exit-code
[setup.client] nps setup.client exited with code 1
--> Sending SIGTERM to other processes..

[setup.server] nps setup.server exited with code null
The script called "setup.all" which runs "node node_modules/concurrently/src/main.js --kill-others-on-fail --prefix-colors "bgBlue.bold,bgMagenta.bold,bgGreen.bold" --prefix "[{name}]" --names "setup.meta,setup.client,setup.server" 'nps setup.meta' 'nps setup.client' 'nps setup.server'" failed with exit code 1 https://github.com/kentcdodds/nps/blob/v5.7.0/other/ERRORS_AND_WARNINGS.md#failed-with-exit-code
The script called "setup" which runs "nps scrub.yarn && nps setup.all" failed with exit code 1 https://github.com/kentcdodds/nps/blob/v5.7.0/other/ERRORS_AND_WARNINGS.md#failed-with-exit-code
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `nps "setup"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ubuntu/.npm/_logs/2017-08-18T22_51_38_094Z-debug.log

npm start setup returned exit code 1

Action failed: npm start setup

Security vulnerability in `concurrently` -> `tree-kill`

A security vulnerability has recently been reported for a nested dependency:
nps-utils> concurrently > tree-kill
https://npmjs.com/advisories/1432

Concurrently has updated it's dependencies to address the vulnerability:
https://github.com/kimmobrunfeldt/concurrently/releases/tag/v5.0.2

Updating to [email protected] ought to remediate the vulnerability.
I attempted to do so in a fork, but tests fail for me so I can't confidently make the updates.

Thank you for this great project along with nps, it's really brought clarity to npm scripts in my projects.

Add function for cross-env

Or perhaps, just add a function that does the same thing cross-env does, just before the script is even run! That'd improve perf for sure!

Helpers for multi-packages

Hey guys.

Firstly thanks for all the hard work, this is a great tool.

I thought you or others might find this helpful when dealing with multi-package situations (think lerna or yarn workspaces) which are becoming more and more popular these days.

In your root package-scripts.js:

const utils = require('nps-utils');
const series = utils.series;

const importPackage = (package) => {
  var scripts = require("./packages/"+package+"/package-scripts.js");
  var replace = (obj, prefix) => {
    var retObj = {};
    for(var key in obj) {

      if (typeof obj[key] === "string")
        retObj[key] = series("cd packages/"+package, "yarn start "+prefix+key);
      else
        retObj[key] = Object.assign({}, replace(obj[key], key+"."));
    }
    return retObj;
  }
  return replace(scripts.scripts, "");
}

module.exports = {
  scripts: {
    client: importPackage("client"),
    server: importPackage("server"),
    shared: importPackage("shared"),
  }
}

This then makes all your sub-package scripts available at the top level.

So now you can just type yarn start client.build or yarn start server.test without having to cd in there first.

Obviously this assumes that you are running nps on all your sub-packages too.

Probably this could be vastly improved to:

  • Detect if you are running nps, if not just use normal calls.
  • Detect if you actually have yarn or not.
  • Handle help from sub-packages etc etc.
  • Allow for additional commands to be added rather than "all or nothing" import.

Feature request: cross-var

(There's a closed issue about this but it doesn't seem to have been closed responsively?)

cross-env is great but doesn't solve all the potential issues between BASH and PowerShell, among other things. Adding cross-var would solve all the rest of those issues (mostly involving quotes requirements for CLI args). Please consider adding a second method for it, alongside cross-env?

"npm start validate" fails on untouched (fresh) fork

Hi,
just wanted to add a neat feature for this repo but... validation fails on an untouched code.

  • Operating system: macOS Sierra 10.12.3
  • Node: v7.7.4
  • Issue - failed tests:
    • crossEnv as darwin:
      • expect(value).toMatchSnapshot() - Received value does not match stored snapshot 1.
    • crossEnv as win32:
      • expect(value).toMatchSnapshot() - Received value does not match stored snapshot 1.
  • Dumpfrom: npm-debug.log:
0 info it worked if it ends with ok
1 verbose cli [ '/Users/dabrowskif/.nvm/v7.7.4/bin/node',
1 verbose cli   '/Users/dabrowskif/.nvm/v7.7.4/bin/npm',
1 verbose cli   'start',
1 verbose cli   'validate' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle [email protected]~prestart: [email protected]
6 silly lifecycle [email protected]~prestart: no script for prestart, continuing
7 info lifecycle [email protected]~start: [email protected]
8 verbose lifecycle [email protected]~start: unsafe-perm in lifecycle true
9 verbose lifecycle [email protected]~start: PATH: /Users/dabrowskif/.nvm/v7.7.4/lib/node_modules/npm/bin/node-gyp-bin:/Users/dabrowskif/Documents/nps-utils/node_modules/.bin:/Users/dabrowskif/.nvm/v7.7.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/share/dotnet:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/usr/local/share/npm/bin
10 verbose lifecycle [email protected]~start: CWD: /Users/dabrowskif/Documents/nps-utils
11 silly lifecycle [email protected]~start: Args: [ '-c', 'nps "validate"' ]
12 silly lifecycle [email protected]~start: Returned: code: 1  signal: null
13 info lifecycle [email protected]~start: Failed to exec start script
14 verbose stack Error: [email protected] start: `nps "validate"`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (/Users/dabrowskif/.nvm/v7.7.4/lib/node_modules/npm/lib/utils/lifecycle.js:279:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:194:7)
14 verbose stack     at ChildProcess.<anonymous> (/Users/dabrowskif/.nvm/v7.7.4/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:194:7)
14 verbose stack     at maybeClose (internal/child_process.js:899:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid [email protected]
16 verbose cwd /Users/dabrowskif/Documents/nps-utils
17 error Darwin 16.4.0
18 error argv "/Users/dabrowskif/.nvm/v7.7.4/bin/node" "/Users/dabrowskif/.nvm/v7.7.4/bin/npm" "start" "validate"
19 error node v7.7.4
20 error npm  v4.1.2
21 error code ELIFECYCLE
22 error [email protected] start: `nps "validate"`
22 error Exit status 1
23 error Failed at the [email protected] start script 'nps "validate"'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the nps-utils package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error     nps "validate"
23 error You can get information on how to open an issue for this project with:
23 error     npm bugs nps-utils
23 error Or if that isn't available, you can get their info via:
23 error     npm owner ls nps-utils
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]

Apologies, but don't have time to dig what's happening there ;-/

Support glob-like patterns?

Basically so people transitioning from npm-run-all can have something for their scripts that are like: npm-run-all test:*

Could be something like:

runAll('test.*') // runs test.client and test.server (but not test.server.watch)
runAll('build.**') // runs build.main, build.umd, and build.umd.min
runAll('lint.* --cache') // runs "lint.client --cache" and "lint.server --cache"
runAllConcurrent('validate.*') // runs validate.lint, validate.test, and validate.build concurrently

By runs ___ I don't mean it actually runs those scripts, it simply returns a script that would run those things :)

Anyone wanna take this one? The biggest challenge will be figuring out what the scripts are. Thinking that it may be better to support this in nps itself actually... Thoughts welcome!

concurrent + series not working together

npsUtils.concurrent.nps('task1', 'task2', 'task3') works fine, as does the equivalent npsUtils.concurrent('nps task1', 'nps task2', 'nps task3')

however when you put a series inside of concurrent, such as the following:

npsUtils.concurrent(npsUtils.series('task a', 'task b'), 'nps task 1', 'nps task 2'));

it fails with a weird key/range output, and the only way to fix is to take the series part out and put it into its own task and replace it with the name of the task:

λ ~/Projects/lad/template/ master* yarn start pretest
yarn run v1.3.2
$ nps pretest
nps is executing `pretest` : node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=test WEB_TIMEOUT_MS=10000 API_TIMEOUT_MS=10000 MONGO_NAME=lad_test REDIS_URL=redis://localhost:6379/lad_test I18N_SYNC_FILES=false I18N_AUTH_RELOAD=false I18N_UPDATE_FILES=false node node_modules/concurrently/src/main.js --kill-others-on-fail --prefix-colors "bgBlue.bold,bgMagenta.bold,bgGreen.bold,bgBlack.bold,bgCyan.bold,bgRed.bold,bgWhite.bold,bgYellow.bold,bgBlue.bold,bgMagenta.bold,bgGreen.bold,bgBlack.bold,bgCyan.bold,bgRed.bold,bgWhite.bold,bgYellow.bold,bgBlue.bold,bgMagenta.bold,bgGreen.bold,bgBlack.bold,bgCyan.bold" --prefix "[{name}]" --names "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20" n p s ' ' b u i l d ' ' '&' '&' ' ' n p s ' ' l i n t
[0] /bin/sh: n: command not found
[1] /bin/sh: p: command not found
[2] /bin/sh: s: command not found
[4] /bin/sh: b: command not found
[5] /bin/sh: u: command not found
[6] /bin/sh: i: command not found
[7] /bin/sh: l: command not found
[8] /bin/sh: d: command not found
[10] /bin/sh: -c: line 0: syntax error near unexpected token `&'
[10] /bin/sh: -c: line 0: `&'
[11] /bin/sh: -c: line 0: syntax error near unexpected token `&'
[11] /bin/sh: -c: line 0: `&'
[13] /bin/sh: n: command not found
[14] /bin/sh: p: command not found
[15] /bin/sh: s: command not found
[17] /bin/sh: l: command not found
[18] /bin/sh: i: command not found
[19] /bin/sh: n: command not found
[20] /bin/sh: t: command not found
[16]   exited with code 0
[12]   exited with code 0
[9]   exited with code 0
[3]   exited with code 0
[20] t exited with code 127
--> Sending SIGTERM to other processes..
[19] n exited with code 127
[18] i exited with code 127
[17] l exited with code 127
[15] s exited with code 127
[14] p exited with code 127
[13] n exited with code 127
[11] & exited with code 2
[10] & exited with code 2
[8] d exited with code 127
[7] l exited with code 127
[6] i exited with code 127
[5] u exited with code 127
[4] b exited with code 127
[2] s exited with code 127
[1] p exited with code 127
[0] n exited with code 127

feature: nps.retry(n, cmd)

I'm currently in a heated battle with some flaky tests. One of the dozen approaches I'm taking is stringing a bunch of the test command together with short-circuit or, e.g:

(jest --ci --coverage && codecov) || (jest --ci --coverage && codecov) || (jest --ci --coverage && codecov)

and I was wondering if you'd accept a PR adding a feature that does that?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.