getProjectPath fails on Travis CI
Comandeer opened this issue · 5 comments
I've run into this issue in my project, which uses commitplease with greenkeeper-lockfile. This package sometimes tries to do a new git commit during Travis CI build. However it fails because commitplease can't find package.json
file.
Error details
module.js:529
throw err;
^
Error: Cannot find module 'package.json'
at Function.Module._resolveFilename (module.js:527:15)
at Function.Module._load (module.js:476:23)
at Module.require (module.js:568:17)
at require (internal/module.js:11:18)
at Function.getOptions (/home/travis/build/Comandeer/rollup-plugin-babel-minify/node_modules/commitplease/index.js:64:31)
at Object.<anonymous> (/home/travis/build/Comandeer/rollup-plugin-babel-minify/.git/hooks/prepare-commit-msg:5:39)
at Module._compile (module.js:624:30)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at checkExecSyncError (child_process.js:592:13)
at execSync (child_process.js:632:13)
at updateLockfile (/home/travis/.nvm/versions/node/v8.7.0/lib/node_modules/greenkeeper-lockfile/lib/update-lockfile.js:63:3)
at Module.update [as exports] (/home/travis/.nvm/versions/node/v8.7.0/lib/node_modules/greenkeeper-lockfile/update.js:54:3)
at Object.<anonymous> (/home/travis/.nvm/versions/node/v8.7.0/lib/node_modules/greenkeeper-lockfile/update.js:62:37)
at Module._compile (module.js:624:30)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at Function.Module._load (module.js:500:3)
It seems that issue is caused by Travis CI behavior, which returns .
for process.cwd()
(but only for JS files run as Bash scripts) and that value passed to path.join
results in generating package.json
, treated by require
as package name, not local path.
I've hit the same on a regular macOS terminal when using jquery-release to try to release an alpha of jQuery Color.
commitplease 2.7.10
doesn't seem to have this issue.
@alisianoi could you look into this?
@Comandeer thanks for the initial MWE and sorry that I completely forgot about you! Your MWE works now, the issue appears to be that sometimes PATH
environment variable contains absolute paths, and sometimes relative ones.
I dunno if it fixes the issues for you @Comandeer or you @mgol but if you could try it out that would be great. You can do this:
- Take your repo that depends on commitplease
- In its
package.json
underdependencies
ordevDependencies
find commitplease and change the line to:
devDependencies: {
'commitplease': 'https://github.com/jzaefferer/commitplease#cwd-fix'
}
This will let you try it against that specific cwd-fix
branch.
TBH I resolved my issue in the other way (I've added check if git commit
is run on CI or not; if it's CI, I just skip commitplease). But I updated my test repo with new version of getProjectPath
(the one with path.resolve
) and it seems that results are correct
edit: oh, you've done it already :D
Published as 3.2.0
, feel free to reopen.