diff --git a/src/controllers/doMeESLint.ts b/src/controllers/doMeESLint.ts index 1101fa6..4f59f58 100644 --- a/src/controllers/doMeESLint.ts +++ b/src/controllers/doMeESLint.ts @@ -21,6 +21,7 @@ export const doMeESLint = async (context: Context): Promise => { log.info('Checking required NPM dependencies for ESLint') installDependencies({ dependencyManager: context.dependencyManager, + hasPnpmWorkspaces: context.hasPnpmWorkspaces, dependencies, installedPackages: context.installedPackages, cwd: context.projectDirectory, diff --git a/src/controllers/getMeContext.ts b/src/controllers/getMeContext.ts index 4cadd49..9b2c09b 100644 --- a/src/controllers/getMeContext.ts +++ b/src/controllers/getMeContext.ts @@ -29,6 +29,7 @@ const getGitignore = (projectDirectory: string): string[] => { export interface Context { installedPackages: InstalledPackage[] + hasPnpmWorkspaces: boolean projectDirectory: string monorepoRoot?: string patterns: Patterns @@ -65,6 +66,9 @@ export const getMeContext = (): Context => { const dependencyManager = packageJson && getDependencyManager(projectDirectory) log.debug(`project type:\t\t${dependencyManager ?? 'start from scratch'}`) + const hasPnpmWorkspaces = + dependencyManager === 'pnpm' && fileExists(path.join(projectDirectory, 'pnpm-workspace.yaml')) + const installedPackages: InstalledPackage[] = packageJson && dependencyManager ? getInstalledPackages({ packageJson, dependencyManager, projectDirectory }) @@ -74,6 +78,7 @@ export const getMeContext = (): Context => { return { dependencyManager, + hasPnpmWorkspaces, installedPackages, projectDirectory, monorepoRoot, diff --git a/src/lib/eslint/installDependencies.ts b/src/lib/eslint/installDependencies.ts index 45d2976..8aec46b 100644 --- a/src/lib/eslint/installDependencies.ts +++ b/src/lib/eslint/installDependencies.ts @@ -32,6 +32,7 @@ function getDependenciesToUpdate( interface InstallDependenciesParameters { dependenciesToUpdate: ExactDependency[] devDependenciesToUpdate: ExactDependency[] + hasWorkspaces: boolean cwd: string debug: boolean } @@ -76,7 +77,7 @@ const installYarnDependencies = (parameters: InstallDependenciesParameters): voi } const installPnpmDependencies = (parameters: InstallDependenciesParameters): void => { - const { dependenciesToUpdate, devDependenciesToUpdate, cwd, debug } = parameters + const { dependenciesToUpdate, hasWorkspaces, devDependenciesToUpdate, cwd, debug } = parameters const dependencyList = dependenciesToUpdate .map(([dependency, version]) => `${dependency}@${version}`) .join(' ') @@ -85,11 +86,14 @@ const installPnpmDependencies = (parameters: InstallDependenciesParameters): voi .join(' ') if (dependencyList) { - execSync(`pnpm add ${dependencyList}`, { cwd, stdio: debug ? 'inherit' : 'ignore' }) + execSync(`pnpm add ${dependencyList}${hasWorkspaces ? ' -w' : ''}`, { + cwd, + stdio: debug ? 'inherit' : 'ignore', + }) } if (developmentDependencyList) { - execSync(`pnpm add -D ${developmentDependencyList}`, { + execSync(`pnpm add -D ${developmentDependencyList}${hasWorkspaces ? ' -w' : ''}`, { cwd, stdio: debug ? 'inherit' : 'ignore', }) @@ -98,13 +102,16 @@ const installPnpmDependencies = (parameters: InstallDependenciesParameters): voi interface Parameters { dependencyManager?: DependencyManager + hasPnpmWorkspaces: boolean dependencies: ExactDependency[] installedPackages: InstalledPackage[] cwd: string debug: boolean } export const installDependencies = (parameters: Parameters) => { - const { dependencyManager, dependencies, installedPackages, cwd, debug } = parameters + const { dependencyManager, hasPnpmWorkspaces, dependencies, installedPackages, cwd, debug } = + parameters + const { dependenciesToUpdate, devDependenciesToUpdate } = getDependenciesToUpdate( dependencies, installedPackages @@ -130,6 +137,7 @@ export const installDependencies = (parameters: Parameters) => { devDependenciesToUpdate, cwd, debug, + hasWorkspaces: false, // currently not needed }) break @@ -140,6 +148,7 @@ export const installDependencies = (parameters: Parameters) => { devDependenciesToUpdate, cwd, debug, + hasWorkspaces: false, // currently not needed }) break @@ -150,6 +159,7 @@ export const installDependencies = (parameters: Parameters) => { devDependenciesToUpdate, cwd, debug, + hasWorkspaces: hasPnpmWorkspaces, }) break @@ -161,6 +171,7 @@ export const installDependencies = (parameters: Parameters) => { devDependenciesToUpdate, cwd, debug, + hasWorkspaces: false, // currently not needed }) } }