node/deps/npm/node_modules/@npmcli/git/lib/env.js
Myles Borins 2e54524955
deps: update npm to 7.0.0-rc.3
PR-URL: https://github.com/nodejs/node/pull/35474
Reviewed-By: Ruy Adorno <ruyadorno@github.com>
Reviewed-By: Ujjwal Sharma <ryzokuken@disroot.org>
Reviewed-By: Ben Coe <bencoe@gmail.com>
Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2020-10-07 09:59:49 -04:00

34 lines
789 B
JavaScript

const uniqueFilename = require('unique-filename')
const { join } = require('path')
const {tmpdir} = require('os')
const goodEnvVars = new Set([
'GIT_ASKPASS',
'GIT_EXEC_PATH',
'GIT_PROXY_COMMAND',
'GIT_SSH',
'GIT_SSH_COMMAND',
'GIT_SSL_CAINFO',
'GIT_SSL_NO_VERIFY'
])
// memoize
let gitEnv
module.exports = () => {
if (gitEnv)
return gitEnv
// we set the template dir to an empty folder to give git less to do
const tmpDir = join(tmpdir(), 'npmcli-git-template-tmp')
const tmpName = uniqueFilename(tmpDir, 'git-clone')
return gitEnv = Object.keys(process.env).reduce((gitEnv, k) => {
if (goodEnvVars.has(k) || !k.startsWith('GIT_'))
gitEnv[k] = process.env[k]
return gitEnv
}, {
GIT_ASKPASS: 'echo',
GIT_TEMPLATE_DIR: tmpName
})
}