Improve `cwd` option (#803)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 72836f3 · Browse files · 10 files·+199 added−75 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
10 files+199 added−75 removed
- tests:+132 added−51 removed
- other:+67 added−24 removed
Provenance
- Commit
2fd9351- Tree
5a7dfac- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
72836f3
10 files changed+199 added−75 removed
added:lib/cwd.js+49 added
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import {statSync} from 'node:fs';import {resolve} from 'node:path';import {fileURLToPath} from 'node:url';import process from 'node:process';
export const getDefaultCwd = () => { try { return process.cwd(); } catch (error) { error.message = `The current directory does not exist.\n${error.message}`; throw error; }};
export const normalizeCwd = cwd => { const cwdString = safeNormalizeFileUrl(cwd, 'The "cwd" option'); return resolve(cwdString);};
export const safeNormalizeFileUrl = (file, name) => { const fileString = normalizeFileUrl(file);
if (typeof fileString !== 'string') { throw new TypeError(`${name} must be a string or a file URL: ${fileString}.`); }
return fileString;};
export const normalizeFileUrl = file => file instanceof URL ? fileURLToPath(file) : file;
export const fixCwdError = (originalMessage, cwd) => { if (cwd === getDefaultCwd()) { return originalMessage; }
let cwdStat; try { cwdStat = statSync(cwd); } catch (error) { return `The "cwd" option is invalid: ${cwd}.\n${error.message}\n${originalMessage}`; }
if (!cwdStat.isDirectory()) { return `The "cwd" option is not a directory: ${cwd}.\n${originalMessage}`; }
return originalMessage;};modified:lib/error.js+4 added-3 removed
11234567843 unmodified lines525354555656575859602 unmodified lines636465666767686970717242 unmodified linesimport process from 'node:process';import {signalsByName} from 'human-signals';import stripFinalNewline from 'strip-final-newline';import {isBinary, binaryToString} from './stdio/utils.js';import {fixCwdError} from './cwd.js';
const getErrorPrefix = ({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled}) => { if (timedOut) { return `timed out after ${timeout} milliseconds`;43 unmodified lines command, escapedCommand, timedOut, isCanceled, options: {timeoutDuration: timeout, cwd = process.cwd()}, options: {timeoutDuration: timeout, cwd},}) => { // `signal` and `exitCode` emitted on `spawned.on('exit')` event can be `null`. // We normalize them to `undefined` exitCode = exitCode === null ? undefined : exitCode;2 unmodified lines
const errorCode = error?.code; const prefix = getErrorPrefix({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled}); const execaMessage = `Command ${prefix}: ${command}`; const originalMessage = previousErrors.has(error) ? error.originalMessage : String(error?.message ?? error); const originalErrorMessage = previousErrors.has(error) ? error.originalMessage : String(error?.message ?? error); const originalMessage = fixCwdError(originalErrorMessage, cwd); const shortMessage = error === undefined ? execaMessage : `${execaMessage}\n${originalMessage}`; const messageStdio = all === undefined ? [stdio[2], stdio[1]] : [all]; const message = [shortMessage, ...messageStdio, ...stdio.slice(3)] .map(messagePart => stripFinalNewline(serializeMessagePart(messagePart)))42 unmodified linesmodified:test/helpers/fixtures-dir.js+3 added-3 removed
1123456788910111213131415import path from 'node:path';import {delimiter, resolve} from 'node:path';import process from 'node:process';import {fileURLToPath} from 'node:url';import pathKey from 'path-key';
export const PATH_KEY = pathKey();export const FIXTURES_DIR_URL = new URL('../fixtures/', import.meta.url);export const FIXTURES_DIR = fileURLToPath(FIXTURES_DIR_URL);export const FIXTURES_DIR = resolve(fileURLToPath(FIXTURES_DIR_URL));
// Add the fixtures directory to PATH so fixtures can be executed without adding// `node`. This is only meant to make writing tests simpler.export const setFixtureDir = () => { process.env[PATH_KEY] = FIXTURES_DIR + path.delimiter + process.env[PATH_KEY]; process.env[PATH_KEY] = FIXTURES_DIR + delimiter + process.env[PATH_KEY];};
added:test/cwd.js+103 added
1+import {mkdir, rmdir} from 'node:fs/promises';2+import {relative, toNamespacedPath} from 'node:path';3+import process from 'node:process';4+import {pathToFileURL, fileURLToPath} from 'node:url';5+import tempfile from 'tempfile';6+import test from 'ava';7+import {execa, execaSync} from '../index.js';8+import {FIXTURES_DIR, setFixtureDir} from './helpers/fixtures-dir.js';9+10+setFixtureDir();11+12+const isWindows = process.platform === 'win32';13+14+const testOptionCwdString = async (t, execaMethod) => {15+ const cwd = '/';16+ const {stdout} = await execaMethod('node', ['-p', 'process.cwd()'], {cwd});17+ t.is(toNamespacedPath(stdout), toNamespacedPath(cwd));18+};19+20+test('The "cwd" option can be a string', testOptionCwdString, execa);21+test('The "cwd" option can be a string - sync', testOptionCwdString, execaSync);22+23+const testOptionCwdUrl = async (t, execaMethod) => {24+ const cwd = '/';25+ const cwdUrl = pathToFileURL(cwd);26+ const {stdout} = await execaMethod('node', ['-p', 'process.cwd()'], {cwd: cwdUrl});27+ t.is(toNamespacedPath(stdout), toNamespacedPath(cwd));28+};29+30+test('The "cwd" option can be a URL', testOptionCwdUrl, execa);31+test('The "cwd" option can be a URL - sync', testOptionCwdUrl, execaSync);32+33+const testOptionCwdInvalid = (t, execaMethod) => {34+ t.throws(() => {35+ execaMethod('empty.js', {cwd: true});36+ }, {message: /The "cwd" option must be a string or a file URL: true/});37+};38+39+test('The "cwd" option cannot be an invalid type', testOptionCwdInvalid, execa);40+test('The "cwd" option cannot be an invalid type - sync', testOptionCwdInvalid, execaSync);41+42+const testErrorCwdDefault = async (t, execaMethod) => {43+ const {cwd} = await execaMethod('empty.js');44+ t.is(cwd, process.cwd());45+};46+47+test('The "cwd" option defaults to process.cwd()', testErrorCwdDefault, execa);48+test('The "cwd" option defaults to process.cwd() - sync', testErrorCwdDefault, execaSync);49+50+// Windows does not allow removing a directory used as `cwd` of a running process51+if (!isWindows) {52+ const testCwdPreSpawn = async (t, execaMethod) => {53+ const currentCwd = process.cwd();54+ const filePath = tempfile();55+ await mkdir(filePath);56+ process.chdir(filePath);57+ await rmdir(filePath);58+59+ try {60+ t.throws(() => {61+ execaMethod('empty.js');62+ }, {message: /The current directory does not exist/});63+ } finally {64+ process.chdir(currentCwd);65+ }66+ };67+68+ test.serial('The "cwd" option default fails if current cwd is missing', testCwdPreSpawn, execa);69+ test.serial('The "cwd" option default fails if current cwd is missing - sync', testCwdPreSpawn, execaSync);70+}71+72+const cwdNotExisting = {cwd: 'does_not_exist', expectedCode: 'ENOENT', expectedMessage: 'The "cwd" option is invalid'};73+const cwdTooLong = {cwd: '.'.repeat(1e5), expectedCode: 'ENAMETOOLONG', expectedMessage: 'The "cwd" option is invalid'};74+const cwdNotDir = {cwd: fileURLToPath(import.meta.url), expectedCode: isWindows ? 'ENOENT' : 'ENOTDIR', expectedMessage: 'The "cwd" option is not a directory'};75+76+const testCwdPostSpawn = async (t, {cwd, expectedCode, expectedMessage}, execaMethod) => {77+ const {failed, code, message} = await execaMethod('empty.js', {cwd, reject: false});78+ t.true(failed);79+ t.is(code, expectedCode);80+ t.true(message.includes(expectedMessage));81+ t.true(message.includes(cwd));82+};83+84+test('The "cwd" option must be an existing file', testCwdPostSpawn, cwdNotExisting, execa);85+test('The "cwd" option must be an existing file - sync', testCwdPostSpawn, cwdNotExisting, execaSync);86+test('The "cwd" option must not be too long', testCwdPostSpawn, cwdTooLong, execa);87+test('The "cwd" option must not be too long - sync', testCwdPostSpawn, cwdTooLong, execaSync);88+test('The "cwd" option must be a directory', testCwdPostSpawn, cwdNotDir, execa);89+test('The "cwd" option must be a directory - sync', testCwdPostSpawn, cwdNotDir, execaSync);90+91+const successProperties = {fixtureName: 'empty.js', expectedFailed: false};92+const errorProperties = {fixtureName: 'fail.js', expectedFailed: true};93+94+const testErrorCwd = async (t, execaMethod, {fixtureName, expectedFailed}) => {95+ const {failed, cwd} = await execaMethod(fixtureName, {cwd: relative('.', FIXTURES_DIR), reject: false});96+ t.is(failed, expectedFailed);97+ t.is(cwd, FIXTURES_DIR);98+};99+100+test('result.cwd is defined', testErrorCwd, execa, successProperties);101+test('result.cwd is defined - sync', testErrorCwd, execaSync, successProperties);102+test('error.cwd is defined', testErrorCwd, execa, errorProperties);103+test('error.cwd is defined - sync', testErrorCwd, execaSync, errorProperties);modified:test/error.js+6 added-16 removed
1 import process from 'node:process';2 import test from 'ava';3 import {execa, execaSync} from '../index.js';4-import {FIXTURES_DIR, setFixtureDir} from './helpers/fixtures-dir.js';4+import {setFixtureDir} from './helpers/fixtures-dir.js';5 import {fullStdio, getStdio} from './helpers/stdio.js';6 import {noopGenerator, outputObjectGenerator} from './helpers/generator.js';7 import {foobarString} from './helpers/input.js';8 7 unmodified lines16 const result = await execa('empty.js', {...fullStdio, all: true});17 t.deepEqual(Reflect.ownKeys(result), [18 'command',19 'escapedCommand',20+ 'cwd',21 'failed',22 'timedOut',23 'isCanceled',24 'isTerminated',160 unmodified lines185 test('error.message newlines are consistent - no newline', testErrorMessageConsistent, 'stdout');186 test('error.message newlines are consistent - newline', testErrorMessageConsistent, 'stdout\n');187 188 test('Original error.message is kept', async t => {188- const {originalMessage} = await t.throwsAsync(execa('noop.js', {cwd: 1}));189- t.true(originalMessage.startsWith('The "options.cwd" property must be of type string or an instance of Buffer or URL. Received type number'));189+ const {originalMessage} = await t.throwsAsync(execa('noop.js', {uid: true}));190+ t.is(originalMessage, 'The "options.uid" property must be int32. Received type boolean (true)');191 });192 193 test('failed is false on success', async t => {194 const {failed} = await execa('noop.js', ['foo']);125 unmodified lines320 t.is(code, undefined);321 });322 323 test('error.code is defined on failure if applicable', async t => {323- const {code} = await t.throwsAsync(execa('noop.js', {cwd: 1}));324+ const {code} = await t.throwsAsync(execa('noop.js', {uid: true}));325 t.is(code, 'ERR_INVALID_ARG_TYPE');326 });327 327-test('error.cwd is defined on failure if applicable', async t => {328- const {cwd} = await t.throwsAsync(execa('fail.js', [], {cwd: FIXTURES_DIR}));329- t.is(cwd, FIXTURES_DIR);330-});331-332-test('error.cwd is undefined on failure if not passed as options', async t => {333- const expectedCwd = process.cwd();334- const {cwd} = await t.throwsAsync(execa('fail.js'));335- t.is(cwd, expectedCwd);336-});337-328 const testUnusualError = async (t, error) => {329 const childProcess = execa('empty.js');330 childProcess.emit('error', error);331 const {message, originalMessage} = await t.throwsAsync(childProcess);24 unmodified lines356 357 test('error instance can be shared', async t => {358 const originalMessage = foobarString;359 const error = new Error(originalMessage);370- const fixtureName = 'noop.js';360+ const fixtureName = 'empty.js';361 362 const firstArgument = 'one';363 const childProcess = execa(fixtureName, [firstArgument]);364 childProcess.emit('error', error);25 unmodified linesmodified:test/kill.js+5 added-5 removed
8 unmodified lines9 import {setFixtureDir} from './helpers/fixtures-dir.js';10 11 setFixtureDir();12 13+const isWindows = process.platform === 'win32';14 const TIMEOUT_REGEXP = /timed out after/;15 16 const spawnNoKillable = async (forceKillAfterDelay, options) => {17 const subprocess = execa('no-killable.js', {29 unmodified lines47 test('`forceKillAfterDelay` should not be negative', testInvalidForceKill, -1);48 49 // `SIGTERM` cannot be caught on Windows, and it always aborts the process (like `SIGKILL` on Unix).50 // Therefore, this feature and those tests must be different on Windows.50-if (process.platform === 'win32') {51+if (isWindows) {52 test('Can call `.kill()` with `forceKillAfterDelay` on Windows', async t => {53 const {subprocess} = await spawnNoKillable(1);54 subprocess.kill();55 233 unmodified lines289 // if `options.detached: true`290 // - on Linux subprocesses are never killed regardless of `options.detached`291 // With `options.cleanup`, subprocesses are always killed292 // - `options.cleanup` with SIGKILL is a noop, since it cannot be handled292-const exitIfWindows = process.platform === 'win32';293-test('spawnAndKill SIGTERM', spawnAndKill, ['SIGTERM', false, false, exitIfWindows]);294-test('spawnAndKill SIGKILL', spawnAndKill, ['SIGKILL', false, false, exitIfWindows]);293+test('spawnAndKill SIGTERM', spawnAndKill, ['SIGTERM', false, false, isWindows]);294+test('spawnAndKill SIGKILL', spawnAndKill, ['SIGKILL', false, false, isWindows]);295 test('spawnAndKill cleanup SIGTERM', spawnAndKill, ['SIGTERM', true, false, true]);296-test('spawnAndKill cleanup SIGKILL', spawnAndKill, ['SIGKILL', true, false, exitIfWindows]);296+test('spawnAndKill cleanup SIGKILL', spawnAndKill, ['SIGKILL', true, false, isWindows]);297 test('spawnAndKill detached SIGTERM', spawnAndKill, ['SIGTERM', false, true, false]);298 test('spawnAndKill detached SIGKILL', spawnAndKill, ['SIGKILL', false, true, false]);299 test('spawnAndKill cleanup detached SIGTERM', spawnAndKill, ['SIGTERM', true, true, false]);300 test('spawnAndKill cleanup detached SIGKILL', spawnAndKill, ['SIGKILL', true, true, false]);133 unmodified linesmodified:test/test.js+15 added-27 removed
1-import path from 'node:path';1+import {delimiter, join, basename} from 'node:path';2 import process from 'node:process';3 import {fileURLToPath, pathToFileURL} from 'node:url';4 import test from 'ava';5 import isRunning from 'is-running';6 unmodified lines12 13 setFixtureDir();14 process.env.FOO = 'foo';15 16+const isWindows = process.platform === 'win32';16-const ENOENT_REGEXP = process.platform === 'win32' ? /failed with exit code 1/ : /spawn.* ENOENT/;17+const ENOENT_REGEXP = isWindows ? /failed with exit code 1/ : /spawn.* ENOENT/;18 19 const testOutput = async (t, index, execaMethod) => {20 const {stdout, stderr, stdio} = await execaMethod('noop-fd.js', [`${index}`, 'foobar'], fullStdio);21 t.is(stdio[index], 'foobar');24 unmodified lines46 const {stdio} = await execa('stdin-fd.js', ['3'], getStdio(3, [['foobar']]));47 t.is(stdio[3], undefined);48 });49 49-if (process.platform === 'win32') {50+if (isWindows) {51 test('execa() - cmd file', async t => {52 const {stdout} = await execa('hello.cmd');53 t.is(stdout, 'Hello World');54 });57 unmodified lines112 t.deepEqual(stdout, ['foobar\n']);113 });114 115 const getPathWithoutLocalDir = () => {115- const newPath = process.env[PATH_KEY].split(path.delimiter).filter(pathDir => !BIN_DIR_REGEXP.test(pathDir)).join(path.delimiter);116+ const newPath = process.env[PATH_KEY].split(delimiter).filter(pathDir => !BIN_DIR_REGEXP.test(pathDir)).join(delimiter);117 return {[PATH_KEY]: newPath};118 };119 120 const BIN_DIR_REGEXP = /node_modules[\\/]\.bin/;18 unmodified lines139 t.notThrows(() => $({env: getPathWithoutLocalDir()}).sync`ava --version`);140 });141 142 test('localDir option', async t => {142- const command = process.platform === 'win32' ? 'echo %PATH%' : 'echo $PATH';143+ const command = isWindows ? 'echo %PATH%' : 'echo $PATH';144 const {stdout} = await execa(command, {shell: true, preferLocal: true, localDir: '/test'});144- const envPaths = stdout.split(path.delimiter);145+ const envPaths = stdout.split(delimiter);146 t.true(envPaths.some(envPath => envPath.endsWith('.bin')));147 });148 149 test('execa() returns a promise with pid', async t => {44 unmodified lines194 t.is(stdout2, 'foo');195 });196 197 test('use relative path with \'..\' chars', async t => {197- const pathViaParentDir = path.join('..', path.basename(fileURLToPath(new URL('..', import.meta.url))), 'test', 'fixtures', 'noop.js');198+ const pathViaParentDir = join('..', basename(fileURLToPath(new URL('..', import.meta.url))), 'test', 'fixtures', 'noop.js');199 const {stdout} = await execa(pathViaParentDir, ['foo']);200 t.is(stdout, 'foo');201 });202 202-if (process.platform !== 'win32') {203+if (!isWindows) {204 test('execa() rejects if running non-executable', async t => {205 await t.throwsAsync(execa('non-executable.js'));206 });207 1 unmodified line209 await t.throwsAsync(execa('non-executable.js', {input: 'Hey!'}), {message: /EACCES/});210 });211 }212 212-if (process.platform !== 'win32') {213+if (!isWindows) {214 test('write to fast-exit process', async t => {215 // Try-catch here is necessary, because this test is not 100% accurate216 // Sometimes process can manage to accept input before exiting217 try {19 unmodified lines237 const {stdout} = await execa('environment.js', [], {env: {BAR: 'bar', [PATH_KEY]: process.env[PATH_KEY]}, extendEnv: false});238 t.deepEqual(stdout.split('\n'), ['undefined', 'bar']);239 });240 240-test('can use `options.cwd` as a string', async t => {241- const cwd = '/';242- const {stdout} = await execa('node', ['-p', 'process.cwd()'], {cwd});243- t.is(path.toNamespacedPath(stdout), path.toNamespacedPath(cwd));244-});245-241 test('localDir option can be a URL', async t => {247- const command = process.platform === 'win32' ? 'echo %PATH%' : 'echo $PATH';242+ const command = isWindows ? 'echo %PATH%' : 'echo $PATH';243 const {stdout} = await execa(command, {shell: true, preferLocal: true, localDir: pathToFileURL('/test')});249- const envPaths = stdout.split(path.delimiter);244+ const envPaths = stdout.split(delimiter);245 t.true(envPaths.some(envPath => envPath.endsWith('.bin')));246 });247 253-test('can use `options.cwd` as a URL', async t => {254- const cwd = '/';255- const cwdUrl = pathToFileURL(cwd);256- const {stdout} = await execa('node', ['-p', 'process.cwd()'], {cwd: cwdUrl});257- t.is(path.toNamespacedPath(stdout), path.toNamespacedPath(cwd));258-});259-248 test('can use `options.shell: true`', async t => {249 const {stdout} = await execa('node test/fixtures/noop.js foo', {shell: true});250 t.is(stdout, 'foo');251 });252 253 const testShellPath = async (t, mapPath) => {266- const shellPath = process.platform === 'win32' ? 'cmd.exe' : 'bash';254+ const shellPath = isWindows ? 'cmd.exe' : 'bash';255 const shell = mapPath(await which(shellPath));256 const {stdout} = await execa('node test/fixtures/noop.js foo', {shell});257 t.is(stdout, 'foo');258 };2 unmodified lines261 test('can use `options.shell: file URL`', testShellPath, pathToFileURL);262 263 test('use extend environment with `extendEnv: true` and `shell: true`', async t => {264 process.env.TEST = 'test';277- const command = process.platform === 'win32' ? 'echo %TEST%' : 'echo $TEST';265+ const command = isWindows ? 'echo %TEST%' : 'echo $TEST';266 const {stdout} = await execa(command, {shell: true, env: {}, extendEnv: true});267 t.is(stdout, 'test');268 delete process.env.TEST;269 });30 unmodified lines300 301 const testInvalidCommand = async (t, execaMethod) => {302 t.throws(() => {303 execaMethod(['command', 'arg']);316- }, {message: /must be a string or a file URL/});304+ }, {message: /First argument must be a string or a file URL/});305 };306 307 test('execa()\'s command argument must be a string or file URL', testInvalidCommand, execa);308 test('execaSync()\'s command argument must be a string or file URL', testInvalidCommand, execaSync);1 unmodified linemodified:index.d.ts+3 added-3 removed
278 unmodified lines279 280 /**281 Path to the Node.js executable to use in child processes.282 283- This can be either an absolute path or a path relative to the `cwd` option.284-283 Requires `preferLocal` to be `true`.284 285 For example, this can be used together with [`get-node`](https://github.com/ehmicky/get-node) to run a specific Node.js version in a child process.286 122 unmodified lines409 410 /**411 Current working directory of the child process.412 413+ This is also used to resolve the `execPath` option when it is a relative path.414+415 @default process.cwd()416 */417 readonly cwd?: string | URL;418 291 unmodified lines710 */711 signalDescription?: string;712 713 /**714- The `cwd` of the command if provided in the command options. Otherwise it is `process.cwd()`.714+ The current directory in which the command was run.715 */716 cwd: string;717 718 /**580 unmodified linesmodified:index.js+8 added-15 removed
1 import {Buffer} from 'node:buffer';2 import {setMaxListeners} from 'node:events';3-import path from 'node:path';3+import {basename} from 'node:path';4 import childProcess from 'node:child_process';5 import process from 'node:process';6-import {fileURLToPath} from 'node:url';6 import crossSpawn from 'cross-spawn';7 import stripFinalNewline from 'strip-final-newline';8 import {npmRunPathEnv} from 'npm-run-path';9 import {makeError} from './lib/error.js';4 unmodified lines14 import {getSpawnedResult, makeAllStream} from './lib/stream.js';15 import {mergePromise} from './lib/promise.js';16 import {joinCommand, getEscapedCommand} from './lib/escape.js';17 import {parseCommand} from './lib/command.js';18+import {getDefaultCwd, normalizeCwd, safeNormalizeFileUrl, normalizeFileUrl} from './lib/cwd.js';19 import {parseTemplates} from './lib/script.js';20 import {logCommand, verboseDefault} from './lib/verbose.js';21 import {bufferToUint8Array} from './lib/stdio/utils.js';22 8 unmodified lines31 32 return env;33 };34 35-const normalizeFileUrl = file => file instanceof URL ? fileURLToPath(file) : file;35+const getFilePath = rawFile => safeNormalizeFileUrl(rawFile, 'First argument');36 37-const getFilePath = rawFile => {38- const fileString = normalizeFileUrl(rawFile);39-40- if (typeof fileString !== 'string') {41- throw new TypeError('First argument must be a string or a file URL.');42- }43-44- return fileString;45-};46-37 const handleArguments = (rawFile, rawArgs, rawOptions = {}) => {38 const filePath = getFilePath(rawFile);39 const command = joinCommand(filePath, rawArgs);40 const escapedCommand = getEscapedCommand(filePath, rawArgs);4 unmodified lines45 validateTimeout(options);46 options.shell = normalizeFileUrl(options.shell);47 options.env = getEnv(options);48 options.forceKillAfterDelay = normalizeForceKillAfterDelay(options.forceKillAfterDelay);49+ options.cwd = normalizeCwd(options.cwd);50 60- if (process.platform === 'win32' && path.basename(file, '.exe') === 'cmd') {51+ if (process.platform === 'win32' && basename(file, '.exe') === 'cmd') {52 // #11653 args.unshift('/q');54 }55 7 unmodified lines63 buffer = true,64 stripFinalNewline = true,65 extendEnv = true,66 preferLocal = false,76- cwd = process.cwd(),67+ cwd = getDefaultCwd(),68 localDir = cwd,69 execPath = process.execPath,70 encoding = 'utf8',71 reject = true,128 unmodified lines200 201 return {202 command,203 escapedCommand,204+ cwd: options.cwd,205 failed: false,206 timedOut: false,207 isCanceled: false,208 isTerminated: false,59 unmodified lines268 269 return {270 command,271 escapedCommand,272+ cwd: options.cwd,273 failed: false,274 timedOut: false,275 isCanceled: false,276 isTerminated: false,77 unmodified linesmodified:readme.md+3 added-3 removed
364 unmodified lines365 #### cwd366 367 Type: `string`368 369-The `cwd` of the command if provided in the [command options](#cwd-1). Otherwise it is `process.cwd()`.369+The [current directory](#cwd-1) in which the command was run.370 371 #### stdout372 373 Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`135 unmodified lines509 Default: `process.cwd()`510 511 Current working directory of the child process.512 513+This is also used to resolve the [`execPath`](#execpath) option when it is a relative path.514+515 #### env516 517 Type: `object`\518 Default: `process.env`31 unmodified lines550 Default: `process.execPath` (Current Node.js executable)551 552 Path to the Node.js executable to use in child processes.553 552-This can be either an absolute path or a path relative to the [`cwd` option](#cwd).553-554 Requires [`preferLocal`](#preferlocal) to be `true`.555 556 For example, this can be used together with [`get-node`](https://github.com/ehmicky/get-node) to run a specific Node.js version in a child process.557 392 unmodified lines