Skip to content

Commit

Permalink
Remove the npm projectRoot workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Dec 9, 2021
1 parent 7ca1304 commit 44fffa0
Showing 1 changed file with 1 addition and 23 deletions.
24 changes: 1 addition & 23 deletions lib/install.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,6 @@
import path from 'node:path';
import process from 'node:process';
import bin from './index.js';

function getProjectRoot() {
// `projectRoot` on postinstall could be INIT_CWD introduced in npm >= 5.4
// see: /~https://github.com/npm/npm/issues/16990
const initCwd = process.env.INIT_CWD;
if (initCwd) {
return initCwd;
}

// Fallback of getting INIT_CWD
const cwd = process.cwd();
const paths = cwd.split(path.sep);
// If `process.cwd` ends with 'node_modules/*' then get the dependent root directory,
// otherwise return the `cwd` (ordinary it will be the postinstall process of hugo-bin itself).
if (paths.length > 1 && paths[paths.length - 2] === 'node_modules') {
return path.resolve('../../', cwd);
}

return cwd;
}

bin(getProjectRoot()).run(['version'])
bin().run(['version'])
.then(() => {
console.log('Hugo binary installed successfully!');
})
Expand Down

0 comments on commit 44fffa0

Please sign in to comment.