Skip to content

Commit

Permalink
[labs/cli] Fix npm install failing in Winows (#4616)
Browse files Browse the repository at this point in the history
Spawning npm/npx by adding .cmd for Windows is considered insecure (nodejs/node@9095c914ed).
The npm install command for the cli and the npx command in testing will now go through a shell instead.
  • Loading branch information
augustjk committed Apr 15, 2024
1 parent ab77cc9 commit e90dd62
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-icons-move.md
@@ -0,0 +1,5 @@
---
'@lit-labs/cli': patch
---

Use a shell when spawning a child process to install packages. This fixes an error that would happen when command is run in Windows with the latest Node.js security fix in v21.7.3.
4 changes: 2 additions & 2 deletions packages/labs/cli/src/lib/lit-cli.ts
Expand Up @@ -288,12 +288,12 @@ export class LitCli {
const installFrom = reference.installFrom ?? reference.importSpecifier;
this.console.log(`Installing ${installFrom}...`);
const child = childProcess.spawn(
// https://stackoverflow.com/questions/43230346/error-spawn-npm-enoent
/^win/.test(process.platform) ? 'npm.cmd' : 'npm',
'npm',
['install', '--save-dev', installFrom],
{
cwd: this.cwd,
stdio: [process.stdin, 'pipe', 'pipe'],
shell: true,
}
);
(async () => {
Expand Down
5 changes: 2 additions & 3 deletions packages/tests/src/utils/assert-goldens.ts
Expand Up @@ -10,7 +10,7 @@ import fsExtra from 'fs-extra';
import * as dirCompare from 'dir-compare';
import * as path from 'path';
import * as diff from 'diff';
import {execFileSync} from 'child_process';
import {execSync} from 'child_process';

const __dirname = path.dirname(new URL(import.meta.url).pathname);
const red = '\x1b[31m';
Expand Down Expand Up @@ -96,8 +96,7 @@ export const assertGoldensMatch = async (
'--write',
`${path.join(outputDir, formatGlob)}`,
];
// https://stackoverflow.com/questions/43230346/error-spawn-npm-enoent
execFileSync(/^win/.test(process.platform) ? 'npx.cmd' : 'npx', args); //
execSync(`npx ${args.join(' ')}`);
}

if (process.env.UPDATE_TEST_GOLDENS) {
Expand Down

0 comments on commit e90dd62

Please sign in to comment.