-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: slim create-astro deps (#8077)
- Loading branch information
1 parent
a34a488
commit 44cf30a
Showing
9 changed files
with
128 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'create-astro': minor | ||
--- | ||
|
||
Reduce dependency installation size, swap `execa` for light `node:child_process` wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// This is an extremely simplified version of [`execa`](https://github.com/sindresorhus/execa) | ||
// intended to keep our dependency size down | ||
import type { StdioOptions } from 'node:child_process'; | ||
import type { Readable } from 'node:stream'; | ||
|
||
import { text as textFromStream } from 'node:stream/consumers'; | ||
import { spawn } from 'node:child_process'; | ||
import { setTimeout as sleep } from 'node:timers/promises'; | ||
|
||
export interface ExecaOptions { | ||
cwd?: string | URL; | ||
stdio?: StdioOptions; | ||
timeout?: number; | ||
} | ||
export interface Output { | ||
stdout: string; | ||
stderr: string; | ||
exitCode: number; | ||
} | ||
const text = (stream: NodeJS.ReadableStream | Readable | null) => stream ? textFromStream(stream).then(t => t.trimEnd()) : ''; | ||
|
||
export async function shell(command: string, flags: string[], opts: ExecaOptions = {}): Promise<Output> { | ||
const controller = opts.timeout ? new AbortController() : undefined; | ||
const child = spawn(command, flags, { | ||
cwd: opts.cwd, | ||
shell: true, | ||
stdio: opts.stdio, | ||
signal: controller?.signal | ||
}) | ||
const stdout = await text(child.stdout); | ||
const stderr = await text(child.stderr); | ||
if (opts.timeout) { | ||
sleep(opts.timeout).then(() => { | ||
controller!.abort(); | ||
throw { stdout, stderr, exitCode: 1 } | ||
}) | ||
} | ||
await new Promise((resolve) => child.on('exit', resolve)) | ||
const { exitCode } = child; | ||
if (exitCode !== 0) { | ||
throw { stdout, stderr, exitCode }; | ||
} | ||
return { stdout, stderr, exitCode } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.