1
mirror of https://github.com/jakejarvis/hugo-extended.git synced 2025-07-03 19:16:37 -04:00

lib/install.js: minor cosmetic changes.

This commit is contained in:
XhmikosR
2019-02-01 12:24:23 +02:00
committed by Shun Sato
parent a320551fef
commit 5f542e07d0

View File

@ -5,20 +5,22 @@ const signale = require('signale');
const bin = require('.'); const bin = require('.');
function getProjectRoot() { function getProjectRoot() {
// projectRoot on postinstall could be INIT_CWD introduced in npm>=5.4 // `projectRoot` on postinstall could be INIT_CWD introduced in npm >= 5.4
// see: https://github.com/npm/npm/issues/16990 // see: https://github.com/npm/npm/issues/16990
const initCwd = process.env.INIT_CWD; const initCwd = process.env.INIT_CWD;
if (initCwd) { if (initCwd) {
return initCwd; return initCwd;
} }
// Fallback of getting INIT_CWD // Fallback of getting INIT_CWD
const cwd = process.cwd(); const cwd = process.cwd();
const paths = cwd.split(path.sep); const paths = cwd.split(path.sep);
// If process.cwd end with 'node_modules/*' then get the dependent root directory, // If `process.cwd` ends with 'node_modules/*' then get the dependent root directory,
// otherwise returns cwd (ordinary it will be the postinstall process of hugo-bin itself). // 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') { if (paths.length > 1 && paths[paths.length - 2] === 'node_modules') {
return path.resolve('../../', cwd); return path.resolve('../../', cwd);
} }
return cwd; return cwd;
} }