diff --git a/lib/installPackages.js b/lib/installPackages.js index 224ec30..d7ab390 100644 --- a/lib/installPackages.js +++ b/lib/installPackages.js @@ -30,7 +30,8 @@ module.exports = async ({ installArgs, packages, saveDev, - registry + registry, + clientParams }) => { npmClient = npmClient || getNpmClient() const packageName = packages ? packages.join(', ') : 'packages' @@ -38,7 +39,7 @@ module.exports = async ({ return new Promise((resolve, reject) => { // `npm/pnpm/yarn add ` // `npm/pnpm/yarn install` - const args = [packages ? 'add' : 'install'].concat(packages ? packages : []) + let args = [packages ? 'add' : 'install'].concat(packages ? packages : []) if (saveDev) { args.push(npmClient === 'npm' ? '-D' : '--dev') } @@ -50,6 +51,11 @@ module.exports = async ({ args.push(...installArgs) } + // add params between npmClient param and install + if (clientParams) { + args = clientParams.concat(args) + } + logger.debug(npmClient, args.join(' ')) logger.debug('install directory', cwd) spinner.start(`Installing ${packageName} with ${npmClient}`) @@ -65,7 +71,8 @@ module.exports = async ({ /* eslint-enable camelcase */ }, process.env - ) + ), + shell: true // fix sometimes can't read environment variables }) let stdoutLogs = '' diff --git a/lib/parseGenerator.js b/lib/parseGenerator.js index 5398495..f21b660 100644 --- a/lib/parseGenerator.js +++ b/lib/parseGenerator.js @@ -27,7 +27,7 @@ module.exports = generator => { } } - const SPECIAL_PREFIX_RE = /^(npm|github|bitbucket|gitlab|alias):/ + const SPECIAL_PREFIX_RE = /^(npm|github|bitbucket|gitlab|alias|direct):/ if (!SPECIAL_PREFIX_RE.test(generator) && !generator.includes('/')) { generator = `npm:sao-${generator}` @@ -90,6 +90,32 @@ module.exports = generator => { path: path.join(paths.repoPath, hash) } } + // add direct git url + if (type === 'direct') { + const slug = 'direct:' + generator + let copyGenerator = generator + const protocolReg = /(http|https|ssh):(\/\/)/ + const portReg = /:[1-9]\d*/ + if (protocolReg.test(copyGenerator)) { + const fullProt = copyGenerator.match(protocolReg)[0] + copyGenerator = copyGenerator.split(fullProt)[1] + } + if (portReg.test(copyGenerator)) { + const fullPort = copyGenerator.match(portReg)[0] + copyGenerator = copyGenerator.split(fullPort)[1] + } + + const hash = sum(`repo:${slug}`) + const hasSubGenerator = copyGenerator.indexOf(':') !== -1 + return { + type: 'repo', + slug, + subGenerator: + hasSubGenerator && copyGenerator.slice(generator.indexOf(':') + 1), + hash, + path: path.join(paths.repoPath, hash) + } + } const [ ,