Skip to content

Commit

Permalink
Remove withCwd
Browse files Browse the repository at this point in the history
  • Loading branch information
sheck committed Nov 9, 2019
1 parent db378c7 commit a2ac4a3
Showing 1 changed file with 15 additions and 30 deletions.
45 changes: 15 additions & 30 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,15 @@ const {
const event = require(process.env.GITHUB_EVENT_PATH)
const checkName = 'eslint'

async function withCwd (directory, innerAction) {
const oldCwd = process.cwd()

try {
process.chdir(directory)

return await innerAction()
} finally {
process.chdir(oldCwd)
}
}

let yarnOutput = null

async function getYarn () {
if (yarnOutput) return yarnOutput

return await withCwd(GITHUB_WORKSPACE, async () => {
const { output } = await easyExec('yarn list --depth=0 --json')
const { output } = await easyExec('yarn list --depth=0 --json')

yarnOutput = JSON.parse(output)
return yarnOutput
})
yarnOutput = JSON.parse(output)
return yarnOutput
}

async function getPeerDependencies (error) {
Expand Down Expand Up @@ -66,19 +52,17 @@ async function installEslintPackagesAsync () {
.filter(p => p.name.match(/eslint/))
.map(p => p.name)

await withCwd(__dirname, async () => {
await io.mv('package.json', 'package.json-bak')

try {
const { error } = await easyExec(
['npm i', ...versions, '--no-package-lock'].join(' ')
)
const peerVersions = await getPeerDependencies(error)
await easyExec(['npm i', ...peerVersions, '--no-package-lock'].join(' '))
} finally {
await io.mv('package.json-bak', 'package.json')
}
})
await io.mv('package.json', 'package.json-bak')

try {
const { error } = await easyExec(
['npm i', ...versions, '--no-package-lock'].join(' ')
)
const peerVersions = await getPeerDependencies(error)
await easyExec(['npm i', ...peerVersions, '--no-package-lock'].join(' '))
} finally {
await io.mv('package.json-bak', 'package.json')
}
}

async function runEslint () {
Expand Down Expand Up @@ -149,6 +133,7 @@ async function run () {
await checkRun.create()
let report = {}
try {
process.chdir(GITHUB_WORKSPACE)
await installEslintPackagesAsync()
report = await runEslint()
} catch (e) {
Expand Down

0 comments on commit a2ac4a3

Please sign in to comment.