fix(create-vinext-app): pnpm output loses ansi colors when installing dependencies - #2867
Open
NriotHrreion wants to merge 1 commit into
Open
Conversation
…ls dependencies (cloudflare#2863) No longer detect ignored builds from `pnpm install` output. Instead, parse ignored builds by running `pnpm ignore-builds`.
commit: |
Contributor
Performance benchmarksCompared 0 improved · 0 regressed · 6 within ±1.5%
View detailed results and traces 🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2863
Overview
Dependency installation during vinext init should behave like running the package manager directly in the terminal, including preserving pnpm’s interactive output and ANSI colors.
This PR restores that terminal-native experience while retaining reliable detection of pnpm dependencies awaiting build-script approval. It also ensures unrelated installation failures remain visible instead of being misclassified as approval-related errors.
What changed
The root cause of this issue is the hard-coded
pipeatpackages/vinext/src/init.ts:472, which is to get the raw output ofpnpm installand resolve the ignored builds. However, it just broke the terminal-native experience and made pnpm lost its color.Fortunately, pnpm has a builtin command to list all ignore builds:
pnpm ignored-builds. This PR runspnpm ignored-builds, gets its output and resolve the list.In this way, the default
exec()function doesn't need to passpipeto stdio and doesn't need to collect exec output:const child = spawn(cmd, { cwd: opts.cwd, shell: true, - stdio: ["inherit", "pipe", "pipe"], + stdio: opts.stdio, }); - let output = ""; - child.stdout.on("data", (chunk: Buffer) => { - const text = chunk.toString(); - output += text; - process.stdout.write(text); - }); - child.stderr.on("data", (chunk: Buffer) => { - const text = chunk.toString(); - output += text; - process.stderr.write(text); - }); - child.on("error", (error) => reject(Object.assign(error, { output }))); + child.on("error", reject); child.on("close", (status) => { - if (status === 0) resolve(output); + if (status === 0) resolve(); else { reject( Object.assign(new Error(`Command failed with exit code ${status}: ${cmd}`), { status, - output, }), ); } });Testing
pnpm test tests/init-command-exec.test.ts tests/init.test.ts