Skip to content

Commit 5ec655d

Browse files
isaacsclaudiahdz
authored andcommitted
ci: pass appropriate configs for file/dir modes
Re: https://npm.community/t/6-11-2-npm-ci-installs-package-with-wrong-permissions/9720 Still passing a plain old (non-Figgy Pudding) object into libcipm, duplicating the extra keys added in figgy-config.js. This is not a clean or nice or elegant solution, but it works, without regressing the config env var issue. Pairing with @claudiahdz PR-URL: #243 Credit: @isaacs Close: #243 Reviewed-by: @claudiahdz
1 parent 23ce656 commit 5ec655d

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

lib/ci.js

+23-3
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,42 @@
22

33
const npm = require('./npm.js')
44
const Installer = require('libcipm')
5-
const npmlog = require('npmlog')
5+
const log = require('npmlog')
6+
const path = require('path')
67

78
ci.usage = 'npm ci'
89

910
ci.completion = (cb) => cb(null, [])
1011

1112
module.exports = ci
1213
function ci (args, cb) {
13-
const opts = Object.create({ log: npmlog })
14+
const opts = {
15+
// Add some non-npm-config opts by hand.
16+
cache: path.join(npm.config.get('cache'), '_cacache'),
17+
// NOTE: npm has some magic logic around color distinct from the config
18+
// value, so we have to override it here
19+
color: !!npm.color,
20+
hashAlgorithm: 'sha1',
21+
includeDeprecated: false,
22+
log,
23+
'npm-session': npm.session,
24+
'project-scope': npm.projectScope,
25+
refer: npm.referer,
26+
dmode: npm.modes.exec,
27+
fmode: npm.modes.file,
28+
umask: npm.modes.umask,
29+
npmVersion: npm.version,
30+
tmp: npm.tmp
31+
}
32+
1433
for (const key in npm.config.list[0]) {
1534
if (key !== 'log') {
1635
opts[key] = npm.config.list[0][key]
1736
}
1837
}
38+
1939
return new Installer(opts).run().then(details => {
20-
npmlog.disableProgress()
40+
log.disableProgress()
2141
console.log(`added ${details.pkgCount} packages in ${
2242
details.runTime / 1000
2343
}s`)

lib/config/figgy-config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const npm = require('../npm.js')
99
const pack = require('../pack.js')
1010
const path = require('path')
1111

12-
const npmSession = crypto.randomBytes(8).toString('hex')
12+
const npmSession = npm.session = crypto.randomBytes(8).toString('hex')
1313
log.verbose('npm-session', npmSession)
1414

1515
const SCOPE_REGISTRY_REGEX = /@.*:registry$/gi

test/tap/ci-permissions.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const t = require('tap')
2+
const tar = require('tar')
3+
const common = require('../common-tap.js')
4+
const pkg = common.pkg
5+
const rimraf = require('rimraf')
6+
const { writeFileSync, statSync, chmodSync } = require('fs')
7+
const { resolve } = require('path')
8+
const mkdirp = require('mkdirp')
9+
10+
t.test('setup', t => {
11+
mkdirp.sync(resolve(pkg, 'package'))
12+
const pj = resolve(pkg, 'package', 'package.json')
13+
writeFileSync(pj, JSON.stringify({
14+
name: 'foo',
15+
version: '1.2.3'
16+
}))
17+
chmodSync(pj, 0o640)
18+
tar.c({
19+
sync: true,
20+
file: resolve(pkg, 'foo.tgz'),
21+
gzip: true,
22+
cwd: pkg
23+
}, ['package'])
24+
writeFileSync(resolve(pkg, 'package.json'), JSON.stringify({
25+
name: 'root',
26+
version: '1.2.3',
27+
dependencies: {
28+
foo: 'file:foo.tgz'
29+
}
30+
}))
31+
t.end()
32+
})
33+
34+
t.test('run install to generate package-lock', t =>
35+
common.npm(['install'], { cwd: pkg }).then(([code]) => t.equal(code, 0)))
36+
37+
t.test('remove node_modules', t => rimraf(resolve(pkg, 'node_modules'), t.end))
38+
39+
t.test('run ci and check modes', t =>
40+
common.npm(['ci'], { cwd: pkg, stdio: 'inherit' }).then(([code]) => {
41+
t.equal(code, 0)
42+
const file = resolve(pkg, 'node_modules', 'foo', 'package.json')
43+
const mode = statSync(file).mode & 0o707
44+
t.equal(mode, 0o604)
45+
}))

0 commit comments

Comments
 (0)