Skip to content

Commit 4e2c510

Browse files
Fix plugins prompts on postinstall (#2949)
* Fix plugins prompts on postinstall In case some plugins (like `nativescript-plugin-firebase`) try to prompt the user on postinstall, users are unable to answer the question when `tns plugin add <name>` is used. The reason is that the stdin of current process is not passed to the stdin of the `npm install` process and the user has no way to input the result. Fix this by using "inherit" of current stdio when the console is interactive. * Update CHANGELOG for 3.1.2
1 parent fd4fcef commit 4e2c510

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
NativeScript CLI Changelog
22
================
3+
4+
3.1.2 (2017, July 06)
5+
==
6+
7+
### Fixed
8+
* [Fixed #2950](https://github.com/NativeScript/nativescript-cli/issues/2950): Unable to provide user input on postinstall of plugin
9+
310
3.1.1 (2017, June 28)
411
==
512

lib/node-package-manager.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as path from "path";
22
import { exported } from "./common/decorators";
3+
import { isInteractive } from "./common/helpers";
34

45
export class NodePackageManager implements INodePackageManager {
56
private static SCOPED_DEPENDENCY_REGEXP = /^(@.+?)(?:@(.+?))?$/;
@@ -194,16 +195,20 @@ export class NodePackageManager implements INodePackageManager {
194195
private async getNpmInstallResult(params: string[], cwd: string): Promise<ISpawnResult> {
195196
return new Promise<ISpawnResult>((resolve, reject) => {
196197
const npmExecutable = this.getNpmExecutableName();
197-
let childProcess = this.$childProcess.spawn(npmExecutable, params, { cwd, stdio: "pipe" });
198+
const stdioValue = isInteractive() ? "inherit" : "pipe";
199+
200+
const childProcess = this.$childProcess.spawn(npmExecutable, params, { cwd, stdio: stdioValue });
198201

199202
let isFulfilled = false;
200203
let capturedOut = "";
201204
let capturedErr = "";
202205

203-
childProcess.stdout.on("data", (data: string) => {
204-
this.$logger.write(data.toString());
205-
capturedOut += data;
206-
});
206+
if (childProcess.stdout) {
207+
childProcess.stdout.on("data", (data: string) => {
208+
this.$logger.write(data.toString());
209+
capturedOut += data;
210+
});
211+
}
207212

208213
if (childProcess.stderr) {
209214
childProcess.stderr.on("data", (data: string) => {

0 commit comments

Comments
 (0)