Skip to content

Commit 9ac3e5a

Browse files
Merge pull request #13 from aligent/feature/debug-install
MI-206: Have CI_DEBUG affect package manager install command(s)
2 parents 120fb47 + 9f6277b commit 9ac3e5a

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

lib/packageManagers.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
import { existsSync } from 'fs';
2+
import { env } from './env';
23

3-
type PackageManager = 'npm' | 'pnpm' | 'yarn';
4+
const supportedPackageManagers = ['npm', 'pnpm', 'yarn'] as const;
5+
type PackageManager = (typeof supportedPackageManagers)[number];
6+
7+
const installCommands: Record<PackageManager, string> = {
8+
npm: 'npm ci',
9+
pnpm: 'pnpm install --frozen-lockfile',
10+
yarn: 'yarn install --frozen-lockfile',
11+
};
12+
const debugFlags: Record<PackageManager, string> = {
13+
npm: '--verbose',
14+
pnpm: '--verbose',
15+
yarn: '--verbose',
16+
};
417

518
export function detectPackageManager(directoryPath: string): PackageManager {
619
if (existsSync(`${directoryPath}/yarn.lock`)) {
@@ -14,13 +27,15 @@ export function detectPackageManager(directoryPath: string): PackageManager {
1427
return `npm`;
1528
}
1629

17-
export function getInstallCommand(packageManager: PackageManager) {
18-
switch (packageManager) {
19-
case 'npm':
20-
return 'npm ci';
21-
case 'pnpm':
22-
return 'pnpm install --frozen-lockfile';
23-
case 'yarn':
24-
return 'yarn install --frozen-lockfile';
30+
export function getInstallCommand(packageManager: PackageManager): string {
31+
const installCommand = installCommands[packageManager];
32+
if (!installCommand) {
33+
const packageManagers = supportedPackageManagers.join(', ');
34+
throw new Error(
35+
`Unsupported package manager: "${packageManager}". Options are: ${packageManagers}`,
36+
);
2537
}
38+
39+
const debugFlag = env.debug ? ` ${debugFlags[packageManager]}` : '';
40+
return `${installCommand}${debugFlag}`;
2641
}

0 commit comments

Comments
 (0)