From 0ec98691d08114f336a7a40281a575a0a66f9de2 Mon Sep 17 00:00:00 2001 From: Hugo Alliaume Date: Mon, 25 Jul 2022 09:30:25 +0200 Subject: [PATCH] feat: add support for pnpm (install and cache deps) --- dist/index.js | 23 +++++++++++++++++++++-- index.js | 23 +++++++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 1a6f04aa2..45ea7abbb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -74706,6 +74706,10 @@ const yarnFilename = path.join( findYarnWorkspaceRoot(workingDirectory) || workingDirectory, 'yarn.lock' ) +const pnpmLockFilename = path.join( + workingDirectory, + 'pnpm-lock.yaml' +) const packageLockFilename = path.join( workingDirectory, 'package-lock.json' @@ -74713,8 +74717,10 @@ const packageLockFilename = path.join( const useYarn = () => fs.existsSync(yarnFilename) +const usePnpm = () => fs.existsSync(pnpmLockFilename); + const lockHash = () => { - const lockFilename = useYarn() ? yarnFilename : packageLockFilename + const lockFilename = useYarn() ? yarnFilename : (usePnpm() ? pnpmLockFilename : packageLockFilename) const fileHash = hasha.fromFileSync(lockFilename) debug(`Hash from file ${lockFilename} is ${fileHash}`) return fileHash @@ -74729,6 +74735,8 @@ const getNpmCache = () => { if (!key) { if (useYarn()) { key = `yarn-${platformAndArch}-${hash}` + } if (usePnpm()) { + key = `pnpm-${platformAndArch}-${hash}` } else { key = `npm-${platformAndArch}-${hash}` } @@ -74738,6 +74746,8 @@ const getNpmCache = () => { if (useYarn()) { o.inputPath = path.join(homeDirectory, '.cache', 'yarn') + } else if (usePnpm()) { + o.inputPath = NPM_CACHE_FOLDER } else { o.inputPath = NPM_CACHE_FOLDER } @@ -74842,9 +74852,18 @@ const install = () => { cypressCommandOptions ) }) + } else if (usePnpm()) { + debug('installing NPM dependencies using pnpm') + return io.which('pnpm', true).then((pnpmPath) => { + debug(`pnpm at "${pnpmPath}"`) + return exec.exec( + quote(pnpmPath), + ['install', '--frozen-lockfile'], + cypressCommandOptions + ) + }) } else { debug('installing NPM dependencies') - return io.which('npm', true).then((npmPath) => { debug(`npm at "${npmPath}"`) return exec.exec(quote(npmPath), ['ci'], cypressCommandOptions) diff --git a/index.js b/index.js index 422c8f342..d9f560afa 100644 --- a/index.js +++ b/index.js @@ -96,6 +96,10 @@ const yarnFilename = path.join( findYarnWorkspaceRoot(workingDirectory) || workingDirectory, 'yarn.lock' ) +const pnpmLockFilename = path.join( + workingDirectory, + 'pnpm-lock.yaml' +) const packageLockFilename = path.join( workingDirectory, 'package-lock.json' @@ -103,8 +107,10 @@ const packageLockFilename = path.join( const useYarn = () => fs.existsSync(yarnFilename) +const usePnpm = () => fs.existsSync(pnpmLockFilename); + const lockHash = () => { - const lockFilename = useYarn() ? yarnFilename : packageLockFilename + const lockFilename = useYarn() ? yarnFilename : (usePnpm() ? pnpmLockFilename : packageLockFilename) const fileHash = hasha.fromFileSync(lockFilename) debug(`Hash from file ${lockFilename} is ${fileHash}`) return fileHash @@ -119,6 +125,8 @@ const getNpmCache = () => { if (!key) { if (useYarn()) { key = `yarn-${platformAndArch}-${hash}` + } if (usePnpm()) { + key = `pnpm-${platformAndArch}-${hash}` } else { key = `npm-${platformAndArch}-${hash}` } @@ -128,6 +136,8 @@ const getNpmCache = () => { if (useYarn()) { o.inputPath = path.join(homeDirectory, '.cache', 'yarn') + } else if (usePnpm()) { + o.inputPath = NPM_CACHE_FOLDER } else { o.inputPath = NPM_CACHE_FOLDER } @@ -232,9 +242,18 @@ const install = () => { cypressCommandOptions ) }) + } else if (usePnpm()) { + debug('installing NPM dependencies using pnpm') + return io.which('pnpm', true).then((pnpmPath) => { + debug(`pnpm at "${pnpmPath}"`) + return exec.exec( + quote(pnpmPath), + ['install', '--frozen-lockfile'], + cypressCommandOptions + ) + }) } else { debug('installing NPM dependencies') - return io.which('npm', true).then((npmPath) => { debug(`npm at "${npmPath}"`) return exec.exec(quote(npmPath), ['ci'], cypressCommandOptions)