Skip to content

Commit 29af27d

Browse files
rigor789NathanWalker
authored andcommitted
fix: don't pass the CLI's own options to package managers
ensureAllDependenciesAreInstalled passes path, frameworkPath, disableNpmInstall and ignoreScripts as install options, and getFlagsString turned them into flags. npm 12 fails on unknown flags, so ns commands that install with --path, like ns debug --path app --force, stopped with EUNKNOWNCONFIG.
1 parent c7e0c5b commit 29af27d

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

‎lib/base-package-manager.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ import {
1313
IHostInfo,
1414
} from "./common/declarations";
1515

16+
// Options for the CLI itself. npm 12 fails on flags it doesn't know.
17+
const CLI_ONLY_OPTIONS = [
18+
"path",
19+
"frameworkPath",
20+
"disableNpmInstall",
21+
"ignoreScripts",
22+
];
23+
1624
export abstract class BasePackageManager implements INodePackageManager {
1725
public abstract install(
1826
packageName: string,
@@ -136,6 +144,10 @@ export abstract class BasePackageManager implements INodePackageManager {
136144
protected getFlagsString(config: any, asArray: boolean): any {
137145
const array: Array<string> = [];
138146
for (const flag in config) {
147+
if (CLI_ONLY_OPTIONS.includes(flag)) {
148+
continue;
149+
}
150+
139151
if (
140152
flag === "global" &&
141153
this.packageManager !== "yarn" &&

‎test/base-package-manager.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { assert } from "chai";
2+
import { BasePackageManager } from "../lib/base-package-manager";
3+
4+
class TestPackageManager extends (<any>BasePackageManager) {
5+
constructor() {
6+
super({}, {}, {}, {}, {}, "npm");
7+
}
8+
}
9+
10+
describe("BasePackageManager", () => {
11+
const flags = (config: object): string[] =>
12+
(<any>new TestPackageManager()).getFlagsString(config, true);
13+
14+
it("doesn't pass the CLI's own options to the package manager", () => {
15+
assert.deepEqual(
16+
flags({
17+
path: "apps/app",
18+
frameworkPath: "runtime.tgz",
19+
disableNpmInstall: true,
20+
ignoreScripts: true,
21+
}),
22+
[],
23+
);
24+
});
25+
26+
it("passes the package manager's options on", () => {
27+
assert.deepEqual(flags({ "ignore-scripts": true, "save-dev": true }), [
28+
"--ignore-scripts",
29+
"--save-dev",
30+
]);
31+
});
32+
});

0 commit comments

Comments
 (0)