Skip to content

Commit cbb6502

Browse files
committed
fix(packages): login command for node@24+ spawn change
1 parent 276bb94 commit cbb6502

File tree

3 files changed

+18
-39
lines changed

3 files changed

+18
-39
lines changed

packages/core/packages/PackageManager.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -248,20 +248,16 @@ export class PackageManager {
248248
if (process.stdin.isTTY) {
249249
process.stdin.setRawMode(true);
250250
}
251-
const cmd = /^win/.test(process.platform) ? "npm.cmd" : "npm"; //https://github.com/nodejs/node/issues/3675
252-
const login = Util.spawnSync(cmd,
253-
["adduser", `--registry=${fullPackageRegistry}`, `--scope=@infragistics`, `--auth-type=legacy`],
254-
{ stdio: "inherit" }
255-
);
256-
if (login?.status === 0) {
251+
252+
try {
253+
Util.execSync(
254+
`npm login --registry=${fullPackageRegistry} --scope=@infragistics --auth-type=legacy`,
255+
{ stdio: "inherit" }
256+
);
257257
//make sure scope is configured:
258-
try {
259-
Util.execSync(`npm config set @infragistics:registry ${fullPackageRegistry}`);
260-
return true;
261-
} catch (error) {
262-
return false;
263-
}
264-
} else {
258+
Util.execSync(`npm config set @infragistics:registry ${fullPackageRegistry}`);
259+
return true;
260+
} catch (error) {
265261
Util.log(message, "red");
266262
return false;
267263
}

packages/core/util/Util.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,14 +365,15 @@ export class Util {
365365
/**
366366
* Execute synchronous command with options using spawnSync
367367
* @param command Command to be executed
368-
* NOTE: `spawn` without `shell` (unsafe) is **not** equivalent to `exec` & requires `npm.cmd` to run the correct process on win
369-
* do not call with/add commands that are not known binaries without validating first
368+
* NOTE: `spawn` without `shell` (unsafe) is **not** equivalent to `exec` & requires direct path to run the correct process on win,
369+
* e.g. `npm.cmd` but that is also blocked in node@24+ for security reasons
370+
* Do not call with/add commands that are not known binaries without validating first
370371
* @param args Command arguments
371372
* @param options Command options
372373
* @returns {SpawnSyncReturns} object with status and stdout
373374
* @remarks Consuming code MUST handle the result and check for failure status!
374375
*/
375-
public static spawnSync(command: string, args: string[], options?: Omit<SpawnSyncOptions, 'shell'>) {
376+
public static spawnSync(command: 'node' | 'git', args: string[], options?: Omit<SpawnSyncOptions, 'shell'>) {
376377
return spawnSync(command, args, options);
377378
}
378379

spec/unit/packageManager-spec.ts

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ describe("Unit - Package Manager", () => {
4545
}
4646
return "";
4747
});
48-
spyOn(Util, "spawnSync").and.returnValues({
49-
status: 0,
50-
pid: 0,
51-
output: [],
52-
stdout: "",
53-
stderr: "",
54-
signal: "SIGABRT"
55-
});
5648
spyOn(Util, "log");
5749
spyOn(PackageManager, "removePackage");
5850
await PackageManager.ensureIgniteUISource(true, mockTemplateMgr, true);
@@ -75,9 +67,8 @@ describe("Unit - Package Manager", () => {
7567
"yellow"
7668
);
7769
expect(path.join).toHaveBeenCalled();
78-
expect(Util.spawnSync).toHaveBeenCalledWith(
79-
/^win/.test(process.platform) ? "npm.cmd" : "npm",
80-
["adduser", `--registry=trial`, `--scope=@infragistics`, `--auth-type=legacy`],
70+
expect(Util.execSync).toHaveBeenCalledWith(
71+
"npm login --registry=trial --scope=@infragistics --auth-type=legacy",
8172
{
8273
stdio: "inherit"
8374
}
@@ -119,14 +110,6 @@ describe("Unit - Package Manager", () => {
119110
spyOn(Util, "log");
120111
spyOn(TestPackageManager, "removePackage");
121112
spyOn(TestPackageManager, "getPackageJSON").and.callFake(() => mockRequire);
122-
spyOn(Util, "spawnSync").and.returnValues({
123-
status: 1,
124-
pid: 0,
125-
output: [],
126-
stdout: "",
127-
stderr: "",
128-
signal: "SIGABRT"
129-
});
130113
await TestPackageManager.ensureIgniteUISource(true, mockTemplateMgr, true);
131114
expect(ProjectConfig.localConfig).toHaveBeenCalled();
132115
expect(Util.log).toHaveBeenCalledTimes(12);
@@ -162,14 +145,13 @@ describe("Unit - Package Manager", () => {
162145
`for instructions on how to install the full package.`,
163146
"yellow"
164147
); // x1
165-
expect(Util.spawnSync).toHaveBeenCalledWith(
166-
/^win/.test(process.platform) ? "npm.cmd" : "npm",
167-
["adduser", `--registry=trial`, `--scope=@infragistics`, `--auth-type=legacy`],
148+
expect(Util.execSync).toHaveBeenCalledWith(
149+
"npm login --registry=trial --scope=@infragistics --auth-type=legacy",
168150
{
169151
stdio: "inherit"
170152
}
171153
);
172-
expect(Util.execSync).toHaveBeenCalledTimes(2);
154+
expect(Util.execSync).toHaveBeenCalledTimes(4 /* ¯\(°_o)/¯*/);
173155
expect(Util.execSync).toHaveBeenCalledWith(`npm whoami --registry=trial`, { stdio: "pipe", encoding: "utf8" });
174156
});
175157
it("ensureIgniteUISource - Should run through properly when install now is set to false", async () => {

0 commit comments

Comments
 (0)