Skip to content

Commit

Permalink
feat: add support for pnpm (install and cache deps)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kocal committed Jul 25, 2022
1 parent 4996a77 commit 0ec9869
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
23 changes: 21 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74706,15 +74706,21 @@ 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'
)

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
Expand All @@ -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}`
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 21 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,21 @@ 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'
)

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
Expand All @@ -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}`
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0ec9869

Please sign in to comment.