Skip to content

Commit

Permalink
Upgrade dependencies (#1138)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored Aug 3, 2024
1 parent f9f7140 commit abd9fd0
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 45 deletions.
4 changes: 2 additions & 2 deletions lib/arguments/cwd.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {statSync} from 'node:fs';
import {resolve} from 'node:path';
import path from 'node:path';
import process from 'node:process';
import {safeNormalizeFileUrl} from './file-url.js';

// Normalize `cwd` option
export const normalizeCwd = (cwd = getDefaultCwd()) => {
const cwdString = safeNormalizeFileUrl(cwd, 'The "cwd" option');
return resolve(cwdString);
return path.resolve(cwdString);
};

const getDefaultCwd = () => {
Expand Down
4 changes: 2 additions & 2 deletions lib/arguments/options.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {basename} from 'node:path';
import path from 'node:path';
import process from 'node:process';
import crossSpawn from 'cross-spawn';
import {npmRunPathEnv} from 'npm-run-path';
Expand Down Expand Up @@ -35,7 +35,7 @@ export const normalizeOptions = (filePath, rawArguments, rawOptions) => {
options.forceKillAfterDelay = normalizeForceKillAfterDelay(options.forceKillAfterDelay);
options.lines = options.lines.map((lines, fdNumber) => lines && !BINARY_ENCODINGS.has(options.encoding) && options.buffer[fdNumber]);

if (process.platform === 'win32' && basename(file, '.exe') === 'cmd') {
if (process.platform === 'win32' && path.basename(file, '.exe') === 'cmd') {
// #116
commandArguments.unshift('/q');
}
Expand Down
6 changes: 3 additions & 3 deletions lib/methods/node.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {execPath, execArgv} from 'node:process';
import {basename, resolve} from 'node:path';
import path from 'node:path';
import {safeNormalizeFileUrl} from '../arguments/file-url.js';

// `execaNode()` is a shortcut for `execa(..., {node: true})`
Expand Down Expand Up @@ -27,7 +27,7 @@ export const handleNodeOption = (file, commandArguments, {
}

const normalizedNodePath = safeNormalizeFileUrl(nodePath, 'The "nodePath" option');
const resolvedNodePath = resolve(cwd, normalizedNodePath);
const resolvedNodePath = path.resolve(cwd, normalizedNodePath);
const newOptions = {
...options,
nodePath: resolvedNodePath,
Expand All @@ -39,7 +39,7 @@ export const handleNodeOption = (file, commandArguments, {
return [file, commandArguments, newOptions];
}

if (basename(file, '.exe') === 'node') {
if (path.basename(file, '.exe') === 'node') {
throw new TypeError('When the "node" option is true, the first argument does not need to be "node".');
}

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"cross-spawn": "^7.0.3",
"figures": "^6.1.0",
"get-stream": "^9.0.0",
"human-signals": "^7.0.0",
"human-signals": "^8.0.0",
"is-plain-obj": "^4.1.0",
"is-stream": "^4.0.1",
"npm-run-path": "^5.2.0",
Expand All @@ -65,19 +65,19 @@
"yoctocolors": "^2.0.0"
},
"devDependencies": {
"@types/node": "^20.8.9",
"@types/node": "^22.1.0",
"ava": "^6.0.1",
"c8": "^10.1.2",
"get-node": "^15.0.0",
"is-in-ci": "^0.1.0",
"is-in-ci": "^1.0.0",
"is-running": "^2.1.0",
"path-exists": "^5.0.0",
"path-key": "^4.0.0",
"tempfile": "^5.0.0",
"tsd": "^0.31.0",
"typescript": "^5.4.5",
"which": "^4.0.0",
"xo": "^0.58.0"
"xo": "^0.59.3"
},
"c8": {
"reporter": [
Expand Down
8 changes: 4 additions & 4 deletions test/arguments/cwd.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {mkdir, rmdir} from 'node:fs/promises';
import {relative, toNamespacedPath} from 'node:path';
import path from 'node:path';
import process from 'node:process';
import {pathToFileURL, fileURLToPath} from 'node:url';
import tempfile from 'tempfile';
Expand All @@ -14,7 +14,7 @@ const isWindows = process.platform === 'win32';
const testOptionCwdString = async (t, execaMethod) => {
const cwd = '/';
const {stdout} = await execaMethod('node', ['-p', 'process.cwd()'], {cwd});
t.is(toNamespacedPath(stdout), toNamespacedPath(cwd));
t.is(path.toNamespacedPath(stdout), path.toNamespacedPath(cwd));
};

test('The "cwd" option can be a string', testOptionCwdString, execa);
Expand All @@ -24,7 +24,7 @@ const testOptionCwdUrl = async (t, execaMethod) => {
const cwd = '/';
const cwdUrl = pathToFileURL(cwd);
const {stdout} = await execaMethod('node', ['-p', 'process.cwd()'], {cwd: cwdUrl});
t.is(toNamespacedPath(stdout), toNamespacedPath(cwd));
t.is(path.toNamespacedPath(stdout), path.toNamespacedPath(cwd));
};

test('The "cwd" option can be a URL', testOptionCwdUrl, execa);
Expand Down Expand Up @@ -93,7 +93,7 @@ const successProperties = {fixtureName: 'empty.js', expectedFailed: false};
const errorProperties = {fixtureName: 'fail.js', expectedFailed: true};

const testErrorCwd = async (t, execaMethod, {fixtureName, expectedFailed}) => {
const {failed, cwd} = await execaMethod(fixtureName, {cwd: relative('.', FIXTURES_DIRECTORY), reject: false});
const {failed, cwd} = await execaMethod(fixtureName, {cwd: path.relative('.', FIXTURES_DIRECTORY), reject: false});
t.is(failed, expectedFailed);
t.is(cwd, FIXTURES_DIRECTORY);
};
Expand Down
10 changes: 6 additions & 4 deletions test/arguments/local.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {delimiter} from 'node:path';
import path from 'node:path';
import process from 'node:process';
import {pathToFileURL} from 'node:url';
import test from 'ava';
Expand All @@ -12,7 +12,9 @@ const isWindows = process.platform === 'win32';
const ENOENT_REGEXP = isWindows ? /failed with exit code 1/ : /spawn.* ENOENT/;

const getPathWithoutLocalDirectory = () => {
const newPath = process.env[PATH_KEY].split(delimiter).filter(pathDirectory => !BIN_DIR_REGEXP.test(pathDirectory)).join(delimiter);
const newPath = process.env[PATH_KEY]
.split(path.delimiter)
.filter(pathDirectory => !BIN_DIR_REGEXP.test(pathDirectory)).join(path.delimiter);
return {[PATH_KEY]: newPath};
};

Expand Down Expand Up @@ -59,13 +61,13 @@ test('preferLocal: undefined with $.pipe()', async t => {
test('localDir option', async t => {
const command = isWindows ? 'echo %PATH%' : 'echo $PATH';
const {stdout} = await execa(command, {shell: true, preferLocal: true, localDir: '/test'});
const envPaths = stdout.split(delimiter);
const envPaths = stdout.split(path.delimiter);
t.true(envPaths.some(envPath => envPath.endsWith('.bin')));
});

test('localDir option can be a URL', async t => {
const command = isWindows ? 'echo %PATH%' : 'echo $PATH';
const {stdout} = await execa(command, {shell: true, preferLocal: true, localDir: pathToFileURL('/test')});
const envPaths = stdout.split(delimiter);
const envPaths = stdout.split(path.delimiter);
t.true(envPaths.some(envPath => envPath.endsWith('.bin')));
});
4 changes: 2 additions & 2 deletions test/helpers/file-path.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {relative} from 'node:path';
import path from 'node:path';

export const getAbsolutePath = file => ({file});
export const getRelativePath = filePath => ({file: relative('.', filePath)});
export const getRelativePath = filePath => ({file: path.relative('.', filePath)});
6 changes: 3 additions & 3 deletions test/helpers/fixtures-directory.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {delimiter, resolve} from 'node:path';
import path 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_DIRECTORY_URL = new URL('../fixtures/', import.meta.url);
// @todo: use import.meta.dirname after dropping support for Node <20.11.0
export const FIXTURES_DIRECTORY = resolve(fileURLToPath(FIXTURES_DIRECTORY_URL));
export const FIXTURES_DIRECTORY = path.resolve(fileURLToPath(FIXTURES_DIRECTORY_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 setFixtureDirectory = () => {
process.env[PATH_KEY] = FIXTURES_DIRECTORY + delimiter + process.env[PATH_KEY];
process.env[PATH_KEY] = FIXTURES_DIRECTORY + path.delimiter + process.env[PATH_KEY];
};

6 changes: 3 additions & 3 deletions test/methods/bind.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {join} from 'node:path';
import path from 'node:path';
import test from 'ava';
import {
execa,
Expand All @@ -12,8 +12,8 @@ import {setFixtureDirectory, FIXTURES_DIRECTORY} from '../helpers/fixtures-direc

setFixtureDirectory();

const NOOP_PATH = join(FIXTURES_DIRECTORY, 'noop.js');
const PRINT_ENV_PATH = join(FIXTURES_DIRECTORY, 'environment.js');
const NOOP_PATH = path.join(FIXTURES_DIRECTORY, 'noop.js');
const PRINT_ENV_PATH = path.join(FIXTURES_DIRECTORY, 'environment.js');

const testBindOptions = async (t, execaMethod) => {
const {stdout} = await execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString]);
Expand Down
4 changes: 2 additions & 2 deletions test/methods/command.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {join} from 'node:path';
import path from 'node:path';
import test from 'ava';
import {
execa,
Expand All @@ -17,7 +17,7 @@ import {
import {QUOTE} from '../helpers/verbose.js';

setFixtureDirectory();
const STDIN_FIXTURE = join(FIXTURES_DIRECTORY, 'stdin.js');
const STDIN_FIXTURE = path.join(FIXTURES_DIRECTORY, 'stdin.js');
const ECHO_FIXTURE_URL = new URL('echo.js', FIXTURES_DIRECTORY_URL);

const parseAndRunCommand = command => execa`${parseCommandString(command)}`;
Expand Down
4 changes: 2 additions & 2 deletions test/methods/create.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {join} from 'node:path';
import path from 'node:path';
import test from 'ava';
import {
execa,
Expand All @@ -11,7 +11,7 @@ import {setFixtureDirectory, FIXTURES_DIRECTORY} from '../helpers/fixtures-direc

setFixtureDirectory();

const NOOP_PATH = join(FIXTURES_DIRECTORY, 'noop.js');
const NOOP_PATH = path.join(FIXTURES_DIRECTORY, 'noop.js');

const testTemplate = async (t, execaMethod) => {
const {stdout} = await execaMethod`${NOOP_PATH} ${foobarString}`;
Expand Down
12 changes: 6 additions & 6 deletions test/methods/node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {dirname, relative} from 'node:path';
import path from 'node:path';
import process, {version} from 'node:process';
import {pathToFileURL} from 'node:url';
import test from 'ava';
Expand Down Expand Up @@ -137,7 +137,7 @@ test.serial('The "nodePath" option impacts the subprocess - "node" option sync',

const testSubprocessNodePathDefault = async (t, execaMethod) => {
const {stdout} = await execaMethod(...nodePathArguments);
t.true(stdout.includes(dirname(process.execPath)));
t.true(stdout.includes(path.dirname(process.execPath)));
};

test('The "nodePath" option defaults to the current Node.js binary in the subprocess - execaNode()', testSubprocessNodePathDefault, execaNode);
Expand All @@ -152,8 +152,8 @@ test.serial('The "nodePath" option requires "node: true" to impact the subproces

const testSubprocessNodePathCwd = async (t, execaMethod) => {
const nodePath = await getNodePath();
const cwd = dirname(dirname(nodePath));
const relativeExecPath = relative(cwd, nodePath);
const cwd = path.dirname(path.dirname(nodePath));
const relativeExecPath = path.relative(cwd, nodePath);
const {stdout} = await execaMethod(...nodePathArguments, {nodePath: relativeExecPath, cwd});
t.true(stdout.includes(TEST_NODE_VERSION));
};
Expand All @@ -164,8 +164,8 @@ test.serial('The "nodePath" option is relative to "cwd" when used in the subproc

const testCwdNodePath = async (t, execaMethod) => {
const nodePath = await getNodePath();
const cwd = dirname(dirname(nodePath));
const relativeExecPath = relative(cwd, nodePath);
const cwd = path.dirname(path.dirname(nodePath));
const relativeExecPath = path.relative(cwd, nodePath);
const {stdout} = await execaMethod('--version', [], {nodePath: relativeExecPath, cwd});
t.is(stdout, `v${TEST_NODE_VERSION}`);
};
Expand Down
6 changes: 3 additions & 3 deletions test/methods/parameters-command.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {join, basename} from 'node:path';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import test from 'ava';
import {
Expand Down Expand Up @@ -73,8 +73,8 @@ test('$.sync\'s command argument must be a string or file URL', testInvalidComma

const testRelativePath = async (t, execaMethod) => {
// @todo: use import.meta.dirname after dropping support for Node <20.11.0
const rootDirectory = basename(fileURLToPath(new URL('../..', import.meta.url)));
const pathViaParentDirectory = join('..', rootDirectory, 'test', 'fixtures', 'noop.js');
const rootDirectory = path.basename(fileURLToPath(new URL('../..', import.meta.url)));
const pathViaParentDirectory = path.join('..', rootDirectory, 'test', 'fixtures', 'noop.js');
const {stdout} = await execaMethod(pathViaParentDirectory);
t.is(stdout, foobarString);
};
Expand Down
4 changes: 2 additions & 2 deletions test/methods/parameters-options.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {join} from 'node:path';
import path from 'node:path';
import test from 'ava';
import {
execa,
Expand All @@ -12,7 +12,7 @@ import {setFixtureDirectory, FIXTURES_DIRECTORY} from '../helpers/fixtures-direc

setFixtureDirectory();

const NOOP_PATH = join(FIXTURES_DIRECTORY, 'noop.js');
const NOOP_PATH = path.join(FIXTURES_DIRECTORY, 'noop.js');

const testSerializeArgument = async (t, commandArgument, execaMethod) => {
const {stdout} = await execaMethod(NOOP_PATH, [commandArgument]);
Expand Down
1 change: 1 addition & 0 deletions test/return/early-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ test('execaSync() throws error if ENOENT', t => {
const testEarlyErrorShape = async (t, reject) => {
const subprocess = getEarlyErrorSubprocess({reject});
t.notThrows(() => {
// eslint-disable-next-line promise/prefer-await-to-then
subprocess.catch(() => {});
subprocess.unref();
subprocess.on('error', () => {});
Expand Down
6 changes: 3 additions & 3 deletions test/stdio/file-path-main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {readFile, writeFile, rm} from 'node:fs/promises';
import {dirname, basename} from 'node:path';
import path from 'node:path';
import process from 'node:process';
import {pathToFileURL} from 'node:url';
import test from 'ava';
Expand Down Expand Up @@ -83,10 +83,10 @@ const testInputFileValidUrl = async (t, fdNumber, execaMethod) => {
const filePath = tempfile();
await writeFile(filePath, foobarString);
const currentCwd = process.cwd();
process.chdir(dirname(filePath));
process.chdir(path.dirname(filePath));

try {
const {stdout} = await execaMethod('stdin.js', getStdioInputFile(fdNumber, basename(filePath)));
const {stdout} = await execaMethod('stdin.js', getStdioInputFile(fdNumber, path.basename(filePath)));
t.is(stdout, foobarString);
} finally {
process.chdir(currentCwd);
Expand Down

0 comments on commit abd9fd0

Please sign in to comment.