Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sindresorhus/execa
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.0.3
Choose a base ref
...
head repository: sindresorhus/execa
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.1.0
Choose a head ref
  • 6 commits
  • 7 files changed
  • 5 contributors

Commits on Sep 24, 2020

  1. Avoid using Array#reduce (#436)

    fregante authored Sep 24, 2020
    Copy the full SHA
    cfcc2dc View commit details

Commits on Oct 12, 2020

  1. Fix import syntax in example in index.d.ts (#437)

    Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
    papb and sindresorhus authored Oct 12, 2020
    Copy the full SHA
    3694816 View commit details

Commits on Oct 19, 2020

  1. Add link to Netlify job description (#439)

    Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
    ehmicky and sindresorhus authored Oct 19, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    db1e9ac View commit details

Commits on Oct 24, 2020

  1. Run CI on Node.js 15 (#440)

    ehmicky authored Oct 24, 2020
    Copy the full SHA
    1e5cb36 View commit details

Commits on Oct 28, 2020

  1. Copy the full SHA
    8fd3f64 View commit details
  2. 4.1.0

    sindresorhus committed Oct 28, 2020
    Copy the full SHA
    cae090f View commit details
Showing with 82 additions and 23 deletions.
  1. +1 −0 .travis.yml
  2. +2 −2 index.d.ts
  3. +5 −1 index.js
  4. +13 −19 lib/command.js
  5. +1 −1 package.json
  6. +6 −0 readme.md
  7. +54 −0 test/node.js
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ os:
- osx
language: node_js
node_js:
- '15'
- '14'
- '12'
- '10'
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -425,7 +425,7 @@ declare const execa: {
@example
```
import execa from 'execa';
import execa = require('execa');
(async () => {
const {stdout} = await execa('echo', ['unicorns']);
@@ -499,7 +499,7 @@ declare const execa: {
@example
```
import execa from 'execa';
import execa = require('execa');
(async () => {
const {stdout} = await execa.command('echo unicorns');
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -234,8 +234,12 @@ module.exports.node = (scriptPath, args, options = {}) => {
}

const stdio = normalizeStdio.node(options);
const defaultExecArgv = process.execArgv.filter(arg => !arg.startsWith('--inspect'));

const {nodePath = process.execPath, nodeOptions = process.execArgv} = options;
const {
nodePath = process.execPath,
nodeOptions = defaultExecArgv
} = options;

return execa(
nodePath,
32 changes: 13 additions & 19 deletions lib/command.js
Original file line number Diff line number Diff line change
@@ -9,27 +9,21 @@ const joinCommand = (file, args = []) => {
return [file, ...args].join(' ');
};

// Allow spaces to be escaped by a backslash if not meant as a delimiter
const handleEscaping = (tokens, token, index) => {
if (index === 0) {
return [token];
}

const previousToken = tokens[tokens.length - 1];

if (previousToken.endsWith('\\')) {
return [...tokens.slice(0, -1), `${previousToken.slice(0, -1)} ${token}`];
}

return [...tokens, token];
};

// Handle `execa.command()`
const parseCommand = command => {
return command
.trim()
.split(SPACES_REGEXP)
.reduce(handleEscaping, []);
const tokens = [];
for (const token of command.trim().split(SPACES_REGEXP)) {
// Allow spaces to be escaped by a backslash if not meant as a delimiter
const previousToken = tokens[tokens.length - 1];
if (previousToken && previousToken.endsWith('\\')) {
// Merge previous token with current one
tokens[tokens.length - 1] = `${previousToken.slice(0, -1)} ${token}`;
} else {
tokens.push(token);
}
}

return tokens;
};

module.exports = {
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "execa",
"version": "4.0.3",
"version": "4.1.0",
"description": "Process execution for humans",
"license": "MIT",
"repository": "sindresorhus/execa",
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -5,6 +5,12 @@

> Process execution for humans
---

Netlify is looking for a senior/expert Node.js backend engineer to join a fully remote, international, diverse (44% women and non-binary) and friendly team. This is for the team where one of the co-maintainers [@ehmicky](https://github.com/ehmicky) is working. The job description is [here](https://boards.greenhouse.io/netlify/jobs/4832483002).

---

## Why

This package improves [`child_process`](https://nodejs.org/api/child_process.html) methods with:
54 changes: 54 additions & 0 deletions test/node.js
Original file line number Diff line number Diff line change
@@ -5,6 +5,23 @@ import execa from '..';

process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;

async function inspectMacro(t, input) {
const originalArgv = process.execArgv;
process.execArgv = [input, '-e'];
try {
const subprocess = execa.node('console.log("foo")', {
reject: false
});

const {stdout, stderr} = await subprocess;

t.is(stdout, 'foo');
t.is(stderr, '');
} finally {
process.execArgv = originalArgv;
}
}

test('node()', async t => {
const {exitCode} = await execa.node('test/fixtures/noop');
t.is(exitCode, 0);
@@ -37,6 +54,43 @@ test('node pass on nodeOptions', async t => {
t.is(stdout, 'foo');
});

test.serial(
'node removes --inspect from nodeOptions when defined by parent process',
inspectMacro,
'--inspect'
);

test.serial(
'node removes --inspect=9222 from nodeOptions when defined by parent process',
inspectMacro,
'--inspect=9222'
);

test.serial(
'node removes --inspect-brk from nodeOptions when defined by parent process',
inspectMacro,
'--inspect-brk'
);

test.serial(
'node removes --inspect-brk=9222 from nodeOptions when defined by parent process',
inspectMacro,
'--inspect-brk=9222'
);

test.serial(
'node should not remove --inspect when passed through nodeOptions',
async t => {
const {stdout, stderr} = await execa.node('console.log("foo")', {
reject: false,
nodeOptions: ['--inspect', '-e']
});

t.is(stdout, 'foo');
t.true(stderr.includes('Debugger listening'));
}
);

test('node\'s forked script has a communication channel', async t => {
const subprocess = execa.node('test/fixtures/send');
subprocess.send('ping');