summaryrefslogtreecommitdiff
path: root/packages/create-astro
diff options
context:
space:
mode:
authorGravatar Nate Moore <natemoo-re@users.noreply.github.com> 2023-08-14 14:23:14 -0500
committerGravatar GitHub <noreply@github.com> 2023-08-14 14:23:14 -0500
commit44cf30a25209b331e6e8a95a4b40a768ede3604a (patch)
tree66c4abd963c863da7793327e44b86f287278ec81 /packages/create-astro
parenta34a48826cbbcf749f05ba19ce0edaa701437e62 (diff)
downloadastro-44cf30a25209b331e6e8a95a4b40a768ede3604a.tar.gz
astro-44cf30a25209b331e6e8a95a4b40a768ede3604a.tar.zst
astro-44cf30a25209b331e6e8a95a4b40a768ede3604a.zip
chore: slim create-astro deps (#8077)
Diffstat (limited to '')
-rw-r--r--packages/create-astro/package.json7
-rw-r--r--packages/create-astro/src/actions/dependencies.ts9
-rw-r--r--packages/create-astro/src/actions/git.ts8
-rw-r--r--packages/create-astro/src/messages.ts4
-rw-r--r--packages/create-astro/src/shell.ts44
-rw-r--r--packages/create-astro/test/fixtures/not-empty/git.json1
-rw-r--r--packages/create-astro/test/git.test.js47
7 files changed, 84 insertions, 36 deletions
diff --git a/packages/create-astro/package.json b/packages/create-astro/package.json
index 761a230cf..3b484abb1 100644
--- a/packages/create-astro/package.json
+++ b/packages/create-astro/package.json
@@ -32,15 +32,14 @@
"//b": "DEPENDENCIES IS FOR UNBUNDLED PACKAGES",
"dependencies": {
"@astrojs/cli-kit": "^0.2.3",
- "chai": "^4.3.7",
- "execa": "^6.1.0",
- "giget": "1.0.0",
- "mocha": "^9.2.2",
+ "giget": "^1.1.2",
"node-fetch-native": "^1.2.0",
"which-pm-runs": "^1.1.0"
},
"devDependencies": {
"@types/which-pm-runs": "^1.0.0",
+ "chai": "^4.3.7",
+ "mocha": "^9.2.2",
"arg": "^5.0.2",
"astro-scripts": "workspace:*",
"strip-ansi": "^7.1.0",
diff --git a/packages/create-astro/src/actions/dependencies.ts b/packages/create-astro/src/actions/dependencies.ts
index 2949e784d..bf46d5d5f 100644
--- a/packages/create-astro/src/actions/dependencies.ts
+++ b/packages/create-astro/src/actions/dependencies.ts
@@ -1,5 +1,5 @@
import { color } from '@astrojs/cli-kit';
-import { execa } from 'execa';
+import { shell } from '../shell.js';
import fs from 'node:fs';
import path from 'node:path';
import { error, info, spinner, title } from '../messages.js';
@@ -49,12 +49,7 @@ export async function dependencies(
async function install({ pkgManager, cwd }: { pkgManager: string; cwd: string }) {
if (pkgManager === 'yarn') await ensureYarnLock({ cwd });
- const installExec = execa(pkgManager, ['install'], { cwd });
- return new Promise<void>((resolve, reject) => {
- setTimeout(() => reject(`Request timed out after 1m 30s`), 90_000);
- installExec.on('error', (e) => reject(e));
- installExec.on('close', () => resolve());
- });
+ return shell(pkgManager, ['install'], { cwd, timeout: 90_000, stdio: 'ignore' });
}
async function ensureYarnLock({ cwd }: { cwd: string }) {
diff --git a/packages/create-astro/src/actions/git.ts b/packages/create-astro/src/actions/git.ts
index 00c42dae5..9711387b4 100644
--- a/packages/create-astro/src/actions/git.ts
+++ b/packages/create-astro/src/actions/git.ts
@@ -3,7 +3,7 @@ import path from 'node:path';
import type { Context } from './context';
import { color } from '@astrojs/cli-kit';
-import { execa } from 'execa';
+import { shell } from '../shell.js';
import { error, info, spinner, title } from '../messages.js';
export async function git(ctx: Pick<Context, 'cwd' | 'git' | 'yes' | 'prompt' | 'dryRun'>) {
@@ -45,9 +45,9 @@ export async function git(ctx: Pick<Context, 'cwd' | 'git' | 'yes' | 'prompt' |
async function init({ cwd }: { cwd: string }) {
try {
- await execa('git', ['init'], { cwd, stdio: 'ignore' });
- await execa('git', ['add', '-A'], { cwd, stdio: 'ignore' });
- await execa(
+ await shell('git', ['init'], { cwd, stdio: 'ignore' });
+ await shell('git', ['add', '-A'], { cwd, stdio: 'ignore' });
+ await shell(
'git',
[
'commit',
diff --git a/packages/create-astro/src/messages.ts b/packages/create-astro/src/messages.ts
index ee67f3b19..da2c08f1d 100644
--- a/packages/create-astro/src/messages.ts
+++ b/packages/create-astro/src/messages.ts
@@ -1,7 +1,7 @@
/* eslint no-console: 'off' */
import { color, say as houston, label, spinner as load } from '@astrojs/cli-kit';
import { align, sleep } from '@astrojs/cli-kit/utils';
-import { execa } from 'execa';
+import { shell } from './shell.js';
import fetch from 'node-fetch-native';
import { exec } from 'node:child_process';
import stripAnsi from 'strip-ansi';
@@ -14,7 +14,7 @@ import detectPackageManager from 'which-pm-runs';
async function getRegistry(): Promise<string> {
const packageManager = detectPackageManager()?.name || 'npm';
try {
- const { stdout } = await execa(packageManager, ['config', 'get', 'registry']);
+ const { stdout } = await shell(packageManager, ['config', 'get', 'registry']);
return stdout?.trim()?.replace(/\/$/, '') || 'https://registry.npmjs.org';
} catch (e) {
return 'https://registry.npmjs.org';
diff --git a/packages/create-astro/src/shell.ts b/packages/create-astro/src/shell.ts
new file mode 100644
index 000000000..4941d788c
--- /dev/null
+++ b/packages/create-astro/src/shell.ts
@@ -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 }
+}
diff --git a/packages/create-astro/test/fixtures/not-empty/git.json b/packages/create-astro/test/fixtures/not-empty/git.json
new file mode 100644
index 000000000..9e26dfeeb
--- /dev/null
+++ b/packages/create-astro/test/fixtures/not-empty/git.json
@@ -0,0 +1 @@
+{} \ No newline at end of file
diff --git a/packages/create-astro/test/git.test.js b/packages/create-astro/test/git.test.js
index c8fa86e86..0ba14c56b 100644
--- a/packages/create-astro/test/git.test.js
+++ b/packages/create-astro/test/git.test.js
@@ -1,7 +1,6 @@
import { expect } from 'chai';
-
-import { execa } from 'execa';
-import fs from 'node:fs';
+import { mkdir, writeFile } from 'node:fs/promises';
+import { rmSync } from 'node:fs';
import { git } from '../dist/index.js';
import { setup } from './utils.js';
@@ -16,22 +15,6 @@ describe('git', () => {
expect(fixture.hasMessage('Skipping Git initialization')).to.be.true;
});
- it('already initialized', async () => {
- const context = {
- git: true,
- cwd: './test/fixtures/not-empty',
- dryRun: true,
- prompt: () => ({ git: false }),
- };
- await execa('git', ['init'], { cwd: './test/fixtures/not-empty' });
- await git(context);
-
- expect(fixture.hasMessage('Git has already been initialized')).to.be.true;
-
- // Cleanup
- fs.rmSync('./test/fixtures/not-empty/.git', { recursive: true, force: true });
- });
-
it('yes (--dry-run)', async () => {
const context = { cwd: '', dryRun: true, prompt: () => ({ git: true }) };
await git(context);
@@ -46,3 +29,29 @@ describe('git', () => {
expect(fixture.hasMessage('Skipping Git initialization')).to.be.true;
});
});
+
+describe('git initialized', () => {
+ const fixture = setup();
+ const dir = new URL(new URL('./fixtures/not-empty/.git', import.meta.url));
+
+ before(async () => {
+ await mkdir(dir, { recursive: true });
+ await writeFile(new URL('./git.json', dir), '{}', { encoding: 'utf8' });
+ })
+
+ it('already initialized', async () => {
+ const context = {
+ git: true,
+ cwd: './test/fixtures/not-empty',
+ dryRun: false,
+ prompt: () => ({ git: false }),
+ };
+ await git(context);
+
+ expect(fixture.hasMessage('Git has already been initialized')).to.be.true;
+ });
+
+ after(() => {
+ rmSync(dir, { recursive: true, force: true });
+ })
+})