mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
Use tinyexec (#11845)
This commit is contained in:
parent
6272e6cec0
commit
440a4be0a6
14 changed files with 87 additions and 59 deletions
5
.changeset/four-beans-remember.md
Normal file
5
.changeset/four-beans-remember.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Replaces `execa` with `tinyexec` internally
|
|
@ -1,5 +1,5 @@
|
|||
import { fileURLToPath } from 'node:url';
|
||||
import { execaCommand } from 'execa';
|
||||
import { exec } from 'tinyexec';
|
||||
import { markdownTable } from 'markdown-table';
|
||||
import { astroBin, calculateStat } from './_util.js';
|
||||
|
||||
|
@ -14,11 +14,11 @@ export async function run(projectDir, outputFile) {
|
|||
const root = fileURLToPath(projectDir);
|
||||
|
||||
console.log('Benchmarking `astro --help`...');
|
||||
const helpStat = await benchmarkCommand(`node ${astroBin} --help`, root);
|
||||
const helpStat = await benchmarkCommand('node', [astroBin, '--help'], root);
|
||||
console.log('Done');
|
||||
|
||||
console.log('Benchmarking `astro info`...');
|
||||
const infoStat = await benchmarkCommand(`node ${astroBin} info`, root);
|
||||
console.log('Benchmarking `astro preferences list`...');
|
||||
const infoStat = await benchmarkCommand('node', [astroBin, 'preferences', 'list'], root);
|
||||
console.log('Done');
|
||||
|
||||
console.log('Result preview:');
|
||||
|
@ -35,16 +35,17 @@ export async function run(projectDir, outputFile) {
|
|||
|
||||
/**
|
||||
* @param {string} command
|
||||
* @param {string[]} args
|
||||
* @param {string} root
|
||||
* @returns {Promise<import('./_util.js').Stat>}
|
||||
*/
|
||||
async function benchmarkCommand(command, root) {
|
||||
async function benchmarkCommand(command, args, root) {
|
||||
/** @type {number[]} */
|
||||
const durations = [];
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const start = performance.now();
|
||||
await execaCommand(command, { cwd: root });
|
||||
await exec(command, args, { nodeOptions: { cwd: root } });
|
||||
durations.push(performance.now() - start);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { execaCommand } from 'execa';
|
||||
import { exec } from 'tinyexec';
|
||||
import { markdownTable } from 'markdown-table';
|
||||
import fs from 'node:fs/promises';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
@ -18,11 +18,13 @@ export async function run(projectDir, outputFile) {
|
|||
const outputFilePath = fileURLToPath(outputFile);
|
||||
|
||||
console.log('Building and benchmarking...');
|
||||
await execaCommand(`node --expose-gc --max_old_space_size=10000 ${astroBin} build --silent`, {
|
||||
cwd: root,
|
||||
stdio: 'inherit',
|
||||
env: {
|
||||
ASTRO_TIMER_PATH: outputFilePath,
|
||||
await exec('node', ['--expose-gc', '--max_old_space_size=10000', astroBin, 'build'], {
|
||||
nodeOptions: {
|
||||
cwd: root,
|
||||
stdio: 'inherit',
|
||||
env: {
|
||||
ASTRO_TIMER_PATH: outputFilePath,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { execaCommand } from 'execa';
|
||||
import { exec } from 'tinyexec';
|
||||
import { markdownTable } from 'markdown-table';
|
||||
import fs from 'node:fs/promises';
|
||||
import http from 'node:http';
|
||||
|
@ -20,15 +20,19 @@ export async function run(projectDir, outputFile) {
|
|||
const root = fileURLToPath(projectDir);
|
||||
|
||||
console.log('Building...');
|
||||
await execaCommand(`${astroBin} build`, {
|
||||
cwd: root,
|
||||
stdio: 'inherit',
|
||||
await exec(astroBin, ['build'], {
|
||||
nodeOptions: {
|
||||
cwd: root,
|
||||
stdio: 'inherit',
|
||||
},
|
||||
});
|
||||
|
||||
console.log('Previewing...');
|
||||
const previewProcess = execaCommand(`${astroBin} preview --port ${port}`, {
|
||||
cwd: root,
|
||||
stdio: 'inherit',
|
||||
const previewProcess = exec(astroBin, ['preview', '--port', port], {
|
||||
nodeOptions: {
|
||||
cwd: root,
|
||||
stdio: 'inherit',
|
||||
},
|
||||
});
|
||||
|
||||
console.log('Waiting for server ready...');
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import autocannon from 'autocannon';
|
||||
import { execaCommand } from 'execa';
|
||||
import { exec } from 'tinyexec';
|
||||
import { markdownTable } from 'markdown-table';
|
||||
import fs from 'node:fs/promises';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
@ -19,9 +19,11 @@ export async function run(projectDir, outputFile) {
|
|||
const root = fileURLToPath(projectDir);
|
||||
|
||||
console.log('Building...');
|
||||
await execaCommand(`${astroBin} build`, {
|
||||
cwd: root,
|
||||
stdio: 'inherit',
|
||||
await exec(astroBin, ['build'], {
|
||||
nodeOptions: {
|
||||
cwd: root,
|
||||
stdio: 'inherit',
|
||||
},
|
||||
});
|
||||
|
||||
console.log('Previewing...');
|
||||
|
|
|
@ -12,11 +12,11 @@
|
|||
"@benchmark/timer": "workspace:*",
|
||||
"astro": "workspace:*",
|
||||
"autocannon": "^7.15.0",
|
||||
"execa": "^8.0.1",
|
||||
"markdown-table": "^3.0.3",
|
||||
"mri": "^1.2.0",
|
||||
"port-authority": "^2.0.1",
|
||||
"pretty-bytes": "^6.1.1",
|
||||
"sharp": "^0.33.3"
|
||||
"sharp": "^0.33.3",
|
||||
"tinyexec": "^0.3.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -151,7 +151,6 @@
|
|||
"es-module-lexer": "^1.5.4",
|
||||
"esbuild": "^0.21.5",
|
||||
"estree-walker": "^3.0.3",
|
||||
"execa": "^8.0.1",
|
||||
"fast-glob": "^3.3.2",
|
||||
"flattie": "^1.1.1",
|
||||
"github-slugger": "^2.0.0",
|
||||
|
@ -176,6 +175,7 @@
|
|||
"shiki": "^1.14.1",
|
||||
"string-width": "^7.2.0",
|
||||
"strip-ansi": "^7.1.0",
|
||||
"tinyexec": "^0.3.0",
|
||||
"tsconfck": "^3.1.1",
|
||||
"unist-util-visit": "^5.0.0",
|
||||
"vfile": "^6.0.3",
|
||||
|
@ -214,6 +214,7 @@
|
|||
"astro-scripts": "workspace:*",
|
||||
"cheerio": "1.0.0",
|
||||
"eol": "^0.9.1",
|
||||
"execa": "^8.0.1",
|
||||
"expect-type": "^0.20.0",
|
||||
"mdast-util-mdx": "^3.0.0",
|
||||
"mdast-util-mdx-jsx": "^3.1.3",
|
||||
|
|
|
@ -3,12 +3,12 @@ import path from 'node:path';
|
|||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
import boxen from 'boxen';
|
||||
import { diffWords } from 'diff';
|
||||
import { execa } from 'execa';
|
||||
import { bold, cyan, dim, green, magenta, red, yellow } from 'kleur/colors';
|
||||
import ora from 'ora';
|
||||
import preferredPM from 'preferred-pm';
|
||||
import prompts from 'prompts';
|
||||
import maxSatisfying from 'semver/ranges/max-satisfying.js';
|
||||
import { exec } from 'tinyexec';
|
||||
import {
|
||||
loadTSConfig,
|
||||
resolveConfig,
|
||||
|
@ -659,7 +659,7 @@ async function tryToInstallIntegrations({
|
|||
if (await askToContinue({ flags })) {
|
||||
const spinner = ora('Installing dependencies...').start();
|
||||
try {
|
||||
await execa(
|
||||
await exec(
|
||||
installCommand.pm,
|
||||
[
|
||||
installCommand.command,
|
||||
|
@ -668,10 +668,12 @@ async function tryToInstallIntegrations({
|
|||
...installCommand.dependencies,
|
||||
],
|
||||
{
|
||||
cwd,
|
||||
// reset NODE_ENV to ensure install command run in dev mode
|
||||
env: { NODE_ENV: undefined },
|
||||
},
|
||||
nodeOptions: {
|
||||
cwd,
|
||||
// reset NODE_ENV to ensure install command run in dev mode
|
||||
env: { NODE_ENV: undefined },
|
||||
},
|
||||
}
|
||||
);
|
||||
spinner.succeed();
|
||||
return UpdateResult.updated;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import type { ExecaChildProcess } from 'execa';
|
||||
import { execa } from 'execa';
|
||||
import { type Result, exec } from 'tinyexec';
|
||||
|
||||
/**
|
||||
* Credit: Azhar22
|
||||
|
@ -26,7 +25,7 @@ const getPlatformSpecificCommand = (): [string] | [string, string[]] => {
|
|||
}
|
||||
};
|
||||
|
||||
export async function openInBrowser(url: string): Promise<ExecaChildProcess> {
|
||||
export async function openInBrowser(url: string): Promise<Result> {
|
||||
const [command, args = []] = getPlatformSpecificCommand();
|
||||
return execa(command, [...args, encodeURI(url)]);
|
||||
return exec(command, [...args, encodeURI(url)]);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { createRequire } from 'node:module';
|
||||
import boxen from 'boxen';
|
||||
import ci from 'ci-info';
|
||||
import { execa } from 'execa';
|
||||
import { bold, cyan, dim, magenta } from 'kleur/colors';
|
||||
import ora from 'ora';
|
||||
import preferredPM from 'preferred-pm';
|
||||
import prompts from 'prompts';
|
||||
import { exec } from 'tinyexec';
|
||||
import whichPm from 'which-pm';
|
||||
import type { Logger } from '../core/logger/core.js';
|
||||
|
||||
|
@ -141,10 +141,10 @@ async function installPackage(
|
|||
if (Boolean(response)) {
|
||||
const spinner = ora('Installing dependencies...').start();
|
||||
try {
|
||||
await execa(
|
||||
await exec(
|
||||
installCommand.pm,
|
||||
[installCommand.command, ...installCommand.flags, ...installCommand.dependencies],
|
||||
{ cwd: cwd },
|
||||
{ nodeOptions: { cwd: cwd } }
|
||||
);
|
||||
spinner.succeed();
|
||||
|
||||
|
@ -203,8 +203,8 @@ async function getRegistry(): Promise<string> {
|
|||
const fallback = 'https://registry.npmjs.org';
|
||||
const packageManager = (await preferredPM(process.cwd()))?.name || 'npm';
|
||||
try {
|
||||
const { stdout } = await execa(packageManager, ['config', 'get', 'registry']);
|
||||
_registry = stdout?.trim()?.replace(/\/$/, '') || fallback;
|
||||
const { stdout } = await exec(packageManager, ['config', 'get', 'registry']);
|
||||
_registry = stdout.trim()?.replace(/\/$/, '') || fallback;
|
||||
// Detect cases where the shell command returned a non-URL (e.g. a warning)
|
||||
if (!new URL(_registry).host) _registry = fallback;
|
||||
} catch {
|
||||
|
|
|
@ -78,9 +78,6 @@ importers:
|
|||
autocannon:
|
||||
specifier: ^7.15.0
|
||||
version: 7.15.0
|
||||
execa:
|
||||
specifier: ^8.0.1
|
||||
version: 8.0.1
|
||||
markdown-table:
|
||||
specifier: ^3.0.3
|
||||
version: 3.0.3
|
||||
|
@ -96,6 +93,9 @@ importers:
|
|||
sharp:
|
||||
specifier: ^0.33.3
|
||||
version: 0.33.3
|
||||
tinyexec:
|
||||
specifier: ^0.3.0
|
||||
version: 0.3.0
|
||||
|
||||
benchmark/packages/timer:
|
||||
dependencies:
|
||||
|
@ -642,9 +642,6 @@ importers:
|
|||
estree-walker:
|
||||
specifier: ^3.0.3
|
||||
version: 3.0.3
|
||||
execa:
|
||||
specifier: ^8.0.1
|
||||
version: 8.0.1
|
||||
fast-glob:
|
||||
specifier: ^3.3.2
|
||||
version: 3.3.2
|
||||
|
@ -717,6 +714,9 @@ importers:
|
|||
strip-ansi:
|
||||
specifier: ^7.1.0
|
||||
version: 7.1.0
|
||||
tinyexec:
|
||||
specifier: ^0.3.0
|
||||
version: 0.3.0
|
||||
tsconfck:
|
||||
specifier: ^3.1.1
|
||||
version: 3.1.1(typescript@5.5.4)
|
||||
|
@ -821,6 +821,9 @@ importers:
|
|||
eol:
|
||||
specifier: ^0.9.1
|
||||
version: 0.9.1
|
||||
execa:
|
||||
specifier: ^8.0.1
|
||||
version: 8.0.1
|
||||
expect-type:
|
||||
specifier: ^0.20.0
|
||||
version: 0.20.0
|
||||
|
@ -6007,9 +6010,6 @@ importers:
|
|||
esbuild-plugin-copy:
|
||||
specifier: ^2.1.1
|
||||
version: 2.1.1(esbuild@0.21.5)
|
||||
execa:
|
||||
specifier: ^8.0.1
|
||||
version: 8.0.1
|
||||
fast-glob:
|
||||
specifier: ^3.3.2
|
||||
version: 3.3.2
|
||||
|
@ -6019,6 +6019,9 @@ importers:
|
|||
p-limit:
|
||||
specifier: ^6.1.0
|
||||
version: 6.1.0
|
||||
tinyexec:
|
||||
specifier: ^0.3.0
|
||||
version: 0.3.0
|
||||
tsconfck:
|
||||
specifier: ^3.1.1
|
||||
version: 3.1.1(typescript@5.5.4)
|
||||
|
@ -11020,6 +11023,9 @@ packages:
|
|||
tinybench@2.8.0:
|
||||
resolution: {integrity: sha512-1/eK7zUnIklz4JUUlL+658n58XO2hHLQfSk1Zf2LKieUjxidN16eKFEoDEfjHc3ohofSSqK3X5yO6VGb6iW8Lw==}
|
||||
|
||||
tinyexec@0.3.0:
|
||||
resolution: {integrity: sha512-tVGE0mVJPGb0chKhqmsoosjsS+qUnJVGJpZgsHYQcGoPlG3B51R3PouqTgEGH2Dc9jjFyOqOpix6ZHNMXp1FZg==}
|
||||
|
||||
tinypool@1.0.0:
|
||||
resolution: {integrity: sha512-KIKExllK7jp3uvrNtvRBYBWBOAXSX8ZvoaD8T+7KB/QHIuoJW3Pmr60zucywjAlMb5TeXUkcs/MWeWLu0qvuAQ==}
|
||||
engines: {node: ^18.0.0 || >=20.0.0}
|
||||
|
@ -17560,6 +17566,8 @@ snapshots:
|
|||
|
||||
tinybench@2.8.0: {}
|
||||
|
||||
tinyexec@0.3.0: {}
|
||||
|
||||
tinypool@1.0.0: {}
|
||||
|
||||
tinyrainbow@1.2.0: {}
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
"dependencies": {
|
||||
"esbuild": "^0.21.5",
|
||||
"esbuild-plugin-copy": "^2.1.1",
|
||||
"execa": "^8.0.1",
|
||||
"fast-glob": "^3.3.2",
|
||||
"kleur": "^4.1.5",
|
||||
"p-limit": "^6.1.0",
|
||||
"tinyexec": "^0.3.0",
|
||||
"tsconfck": "^3.1.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// @ts-check
|
||||
|
||||
import { execa } from 'execa';
|
||||
import { exec } from 'tinyexec';
|
||||
import { promises as fs } from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
|
@ -36,7 +36,9 @@ async function run() {
|
|||
|
||||
console.log('🤖', 'Resetting', 'pnpm');
|
||||
|
||||
await execa('pnpm', ['install'], { cwd: fileURLToPath(rootDir), stdout: 'inherit', stderr: 'inherit' });
|
||||
await exec('pnpm', ['install'], {
|
||||
nodeOptions: { cwd: fileURLToPath(rootDir), stdio: ['pipe', 'inherit', 'inherit'] },
|
||||
});
|
||||
}
|
||||
|
||||
/* Functionality
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// @ts-check
|
||||
|
||||
import { execa } from 'execa';
|
||||
import { exec } from 'tinyexec';
|
||||
import { promises as fs } from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
|
@ -32,10 +32,12 @@ async function run() {
|
|||
console.log('');
|
||||
|
||||
const directories = [...(await getChildDirectories(smokeDir)), ...(await getChildDirectories(exampleDir))];
|
||||
/** @type {Partial<import('tinyexec').Options>} */
|
||||
const execOptions = { nodeOptions: { cwd: fileURLToPath(rootDir), stdio: 'inherit' }};
|
||||
|
||||
console.log('🤖', 'Preparing', 'pnpm');
|
||||
|
||||
await execa('pnpm', ['install', '--frozen-lockfile=false'], { cwd: fileURLToPath(rootDir), stdio: 'inherit' });
|
||||
|
||||
await exec('pnpm', ['install', '--frozen-lockfile=false'], execOptions);
|
||||
|
||||
for (const directory of directories) {
|
||||
const name = directory.pathname.split('/').at(-1) ?? "";
|
||||
|
@ -43,9 +45,9 @@ async function run() {
|
|||
console.log('🤖', 'Testing', name);
|
||||
|
||||
try {
|
||||
await execa('pnpm', ['install', '--ignore-scripts', '--frozen-lockfile=false'].filter(x => x), { cwd: fileURLToPath(directory), stdio: 'inherit' });
|
||||
await execa('pnpm', ['astro', 'telemetry', 'disable']);
|
||||
await execa('pnpm', ['run', 'build'], { cwd: fileURLToPath(directory), stdio: 'inherit' });
|
||||
await exec('pnpm', ['install', '--ignore-scripts', '--frozen-lockfile=false'], execOptions);
|
||||
await exec('pnpm', ['astro', 'telemetry', 'disable']);
|
||||
await exec('pnpm', ['run', 'build'], execOptions);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
process.exit(1);
|
||||
|
|
Loading…
Reference in a new issue