Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): properly translate user-agent #2964

Merged
merged 1 commit into from Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/utils/config/definitions.js
Expand Up @@ -1970,6 +1970,11 @@ define('user-agent', {
.replace(/\{arch\}/gi, process.arch)
.replace(/\{ci\}/gi, ciName ? `ci/${ciName}` : '')
.trim()
// user-agent is a unique kind of config item that gets set from a template
// and ends up translated. Because of this, the normal "should we set this
// to process.env also doesn't work
obj[key] = flatOptions.userAgent
process.env.npm_config_user_agent = flatOptions.userAgent
},
})

Expand Down
6 changes: 6 additions & 0 deletions test/lib/utils/config/definitions.js
Expand Up @@ -733,10 +733,16 @@ t.test('user-agent', t => {
`${process.platform} ${process.arch}`
definitions['user-agent'].flatten('user-agent', obj, flat)
t.equal(flat.userAgent, expectNoCI)
t.equal(process.env.npm_config_user_agent, flat.userAgent, 'npm_user_config environment is set')
t.equal(obj['user-agent'], flat.userAgent, 'config user-agent template is translated')

obj['ci-name'] = 'foo'
obj['user-agent'] = definitions['user-agent'].default
const expectCI = `${expectNoCI} ci/foo`
definitions['user-agent'].flatten('user-agent', obj, flat)
t.equal(flat.userAgent, expectCI)
t.equal(process.env.npm_config_user_agent, flat.userAgent, 'npm_user_config environment is set')
t.equal(obj['user-agent'], flat.userAgent, 'config user-agent template is translated')
t.end()
})

Expand Down