Skip to content

Commit a0ea429

Browse files
committed
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
1 parent bd6e5d2 commit a0ea429

File tree

3 files changed

+71
-4
lines changed

3 files changed

+71
-4
lines changed

lib/ci.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,44 @@
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')
7+
const pack = require('./pack.js')
68

79
ci.usage = 'npm ci'
810

911
ci.completion = (cb) => cb(null, [])
1012

1113
module.exports = ci
1214
function ci (args, cb) {
13-
const opts = Object.create({ log: npmlog })
15+
const opts = {
16+
// Add some non-npm-config opts by hand.
17+
cache: path.join(npm.config.get('cache'), '_cacache'),
18+
// NOTE: npm has some magic logic around color distinct from the config
19+
// value, so we have to override it here
20+
color: !!npm.color,
21+
dirPacker: pack.packGitDep,
22+
hashAlgorithm: 'sha1',
23+
includeDeprecated: false,
24+
log,
25+
'npm-session': npm.session,
26+
'project-scope': npm.projectScope,
27+
refer: npm.referer,
28+
dmode: npm.modes.exec,
29+
fmode: npm.modes.file,
30+
umask: npm.modes.umask,
31+
npmVersion: npm.version,
32+
tmp: npm.tmp
33+
}
34+
1435
for (const key in npm.config.list[0]) {
1536
if (key !== 'log') {
1637
opts[key] = npm.config.list[0][key]
1738
}
1839
}
40+
1941
return new Installer(opts).run().then(details => {
20-
npmlog.disableProgress()
42+
log.disableProgress()
2143
console.log(`added ${details.pkgCount} packages in ${
2244
details.runTime / 1000
2345
}s`)

lib/config/figgy-config.js

Lines changed: 1 addition & 1 deletion
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

Lines changed: 45 additions & 0 deletions
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 & 0o777
44+
t.equal(mode, 0o644)
45+
}))

0 commit comments

Comments
 (0)