Skip to content

Commit 69860ba

Browse files
committed
fix: recognize .npmrc array-valued hoist keys; make stdio test TTY-independent
Review follow-ups: hoist-pattern[]= / public-hoist-pattern[]= (the .npmrc array syntax) now count as user-managed layout config, and the stdin test forces non-interactive mode via setIsInteractive so it passes from a TTY.
1 parent 2428b3a commit 69860ba

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

lib/pnpm-package-manager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,9 @@ export class PnpmPackageManager extends BasePackageManager {
171171
private projectManagesOwnHoisting(installDir: string): boolean {
172172
// A pnpm-workspace.yaml (pnpm's config home since v10) or an .npmrc with
173173
// a layout key marks the node_modules layout as the project's own choice.
174+
// The optional [] suffix covers .npmrc's array syntax (hoist-pattern[]=).
174175
const layoutKeyPattern =
175-
/^\s*(shamefully-hoist|node-linker|hoist|hoist-pattern|public-hoist-pattern)\s*[=:]/m;
176+
/^\s*(shamefully-hoist|node-linker|hoist|hoist-pattern|public-hoist-pattern)(\[\])?\s*[=:]/m;
176177
let dir = path.resolve(installDir);
177178
while (true) {
178179
if (this.$fs.exists(path.join(dir, "pnpm-workspace.yaml"))) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "nativescript",
33
"main": "./dist/lib/nativescript-cli-lib.js",
4-
"version": "9.1.1-dev.0",
4+
"version": "9.1.0",
55
"author": "NativeScript <oss@nativescript.org>",
66
"description": "Command-line interface for building NativeScript projects",
77
"bin": {

test/pnpm-package-manager.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as path from "path";
22
import { Yok } from "../lib/common/yok";
33
import * as stubs from "./stubs";
44
import { assert } from "chai";
5+
import { setIsInteractive } from "../lib/common/helpers";
56
import { PnpmPackageManager } from "../lib/pnpm-package-manager";
67
import { IInjector } from "../lib/common/definitions/yok";
78

@@ -133,6 +134,24 @@ describe("pnpm-package-manager", () => {
133134
assert.deepEqual(childProcess.spawnedArgs[0], ["i"]);
134135
});
135136

137+
["hoist-pattern[]", "public-hoist-pattern[]"].forEach((layoutKey) => {
138+
it(`omits --shamefully-hoist when an .npmrc sets array-valued ${layoutKey}`, async () => {
139+
const testInjector = createTestInjector();
140+
const pnpm = testInjector.resolve<PnpmPackageManager>("pnpm");
141+
const childProcess =
142+
testInjector.resolve<RecordingChildProcessStub>("childProcess");
143+
const fs = testInjector.resolve<SelectiveFileSystemStub>("fs");
144+
const npmrcPath = path.join(projectDir, ".npmrc");
145+
fs.existingPaths = [npmrcPath];
146+
fs.textFiles[npmrcPath] =
147+
`registry=https://example.com\n${layoutKey}=*types*\n`;
148+
149+
await pnpm.install(projectDir, projectDir, {} as any);
150+
151+
assert.deepEqual(childProcess.spawnedArgs[0], ["i"]);
152+
});
153+
});
154+
136155
it("keeps --shamefully-hoist when an .npmrc has no layout key", async () => {
137156
const testInjector = createTestInjector();
138157
const pnpm = testInjector.resolve<PnpmPackageManager>("pnpm");
@@ -176,7 +195,12 @@ describe("pnpm-package-manager", () => {
176195
const childProcess =
177196
testInjector.resolve<RecordingChildProcessStub>("childProcess");
178197

179-
await pnpm.install(projectDir, projectDir, {} as any);
198+
setIsInteractive(() => false);
199+
try {
200+
await pnpm.install(projectDir, projectDir, {} as any);
201+
} finally {
202+
setIsInteractive(undefined);
203+
}
180204

181205
// pnpm never exits while its stdin is an open pipe, so anything but
182206
// "ignore" here hangs the CLI's wait for the child's "close" event.

0 commit comments

Comments
 (0)