|
1 | 1 | import { spawn } from 'child_process' |
2 | 2 | import { execPath } from 'process' |
3 | | -import { downloadSelfInstaller } from '../self-installer' |
| 3 | +import { join } from 'path' |
| 4 | +import { remove, ensureFile, writeFile } from 'fs-extra' |
| 5 | +import fetch from 'node-fetch' |
4 | 6 | import { Inputs } from '../inputs' |
5 | 7 |
|
6 | 8 | export async function runSelfInstaller(inputs: Inputs): Promise<number> { |
7 | | - const cp = spawn(execPath, { |
8 | | - env: { |
9 | | - PNPM_VERSION: inputs.version, |
10 | | - PNPM_DEST: inputs.dest, |
11 | | - PNPM_BIN_DEST: inputs.binDest, |
12 | | - PNPM_REGISTRY: inputs.registry, |
13 | | - }, |
| 9 | + const { version, dest } = inputs |
| 10 | + const target = version ? `pnpm@${version}` : 'pnpm' |
| 11 | + const pkgJson = join(dest, 'package.json') |
| 12 | + |
| 13 | + await remove(dest) |
| 14 | + await ensureFile(pkgJson) |
| 15 | + await writeFile(pkgJson, JSON.stringify({ private: true })) |
| 16 | + |
| 17 | + const cp = spawn(execPath, ['-', 'install', target, '--no-lockfile'], { |
| 18 | + cwd: dest, |
14 | 19 | stdio: ['pipe', 'inherit', 'inherit'], |
15 | 20 | }) |
16 | 21 |
|
17 | | - const response = await downloadSelfInstaller() |
| 22 | + const response = await fetch('https://pnpm.js.org/pnpm.js') |
18 | 23 | response.body.pipe(cp.stdin) |
19 | 24 |
|
20 | 25 | return new Promise((resolve, reject) => { |
|
0 commit comments