diff --git a/package.json b/package.json index 685c6c9..4401833 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "dependencies": { "@ionic/cli-framework-output": "^2.2.6", "@ionic/utils-fs": "^3.1.7", + "detect-package-manager": "^2.0.1", "kleur": "^4.1.5", "rimraf": "^5.0.0", "semver": "^7.5.0" diff --git a/src/index.ts b/src/index.ts index 563aaaf..f8d7aad 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ import { existsSync, readFileSync, pathExists, readJSON, writeFileSync, writeJSON } from '@ionic/utils-fs'; +import { detect } from 'detect-package-manager'; import { join, resolve } from 'path'; import { rimraf } from 'rimraf'; @@ -67,9 +68,18 @@ export const run = async (): Promise => { await writeJSON(packageJson, pluginJSON, { spaces: 2 }); rimraf.sync(join(dir, 'node_modules/@capacitor')); - rimraf.sync(join(dir, 'package-lock.json')); - await runSubprocess('npm', ['install'], { + const pm = await detect(); + if (pm === 'yarn') { + rimraf.sync(join(dir, 'yarn.lock')); + } else if (pm === 'pnpm') { + rimraf.sync(join(dir, 'pnpm-lock.yaml')); + } else { + rimraf.sync(join(dir, 'package-lock.json')); + } + const commandInstall = pm === 'yarn' ? 'add' : 'install'; + + await runSubprocess(pm, [commandInstall], { ...opts, cwd: dir, }); @@ -121,7 +131,7 @@ async function updateBuildGradle( if (!gradleFile) { return; } - gradleFile = gradleFile.replaceAll(" = ", " = "); + gradleFile = gradleFile.replaceAll(' = ', ' = '); logger.info('Updating build.gradle'); gradleFile = setAllStringIn(gradleFile, `sourceCompatibility JavaVersion.`, `\n`, `VERSION_17`); gradleFile = setAllStringIn(gradleFile, `targetCompatibility JavaVersion.`, `\n`, `VERSION_17`);