Replace execa with nano-spawn (#17128)
This commit is contained in:
1 parent
451bacb545
commit
a94d2e7873
6 files changed
+43
-100
No files matched your search
@@ -1,14 +1,17 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import crypto from "node:crypto";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import chalk from "chalk";
|
||||
import { execaSync } from "execa";
|
||||
import { outdent } from "outdent";
|
||||
|
||||
const createTemporaryDirectory = () => {
|
||||
const directory = path.join(
|
||||
os.tmpdir(),
|
||||
// The following quoted from https://github.com/es-tooling/module-replacements/blob/27d1acd38f19741e31d2eae561a5c8a914373fc5/docs/modules/tempy.md?plain=1#L20-L21, not sure if it's true
|
||||
// MacOS and possibly some other platforms return a symlink from `os.tmpdir`.
|
||||
// For some applications, this can cause problems; thus, we use `realpath`.
|
||||
fs.realpathSync(os.tmpdir()),
|
||||
crypto.randomBytes(16).toString("hex"),
|
||||
);
|
||||
fs.mkdirSync(directory);
|
||||
@@ -51,8 +54,10 @@ function cleanUp() {
|
||||
function installPrettier(packageDirectory) {
|
||||
const temporaryDirectory = createTemporaryDirectory();
|
||||
directoriesToClean.add(temporaryDirectory);
|
||||
const fileName = execaSync("npm", ["pack"], {
|
||||
const fileName = spawnSync("npm", ["pack"], {
|
||||
cwd: packageDirectory,
|
||||
shell: true,
|
||||
encoding: "utf8",
|
||||
}).stdout.trim();
|
||||
const file = path.join(packageDirectory, fileName);
|
||||
const packed = path.join(temporaryDirectory, fileName);
|
||||
@@ -60,7 +65,7 @@ function installPrettier(packageDirectory) {
|
||||
fs.unlinkSync(file);
|
||||
|
||||
const runNpmClient = (args) =>
|
||||
execaSync(client, args, { cwd: temporaryDirectory });
|
||||
spawnSync(client, args, { cwd: temporaryDirectory, shell: true });
|
||||
|
||||
runNpmClient(client === "pnpm" ? ["init"] : ["init", "-y"]);
|
||||
|
||||
|
||||
Reference in new issue
Block a user