Skip to content

Commit 89bc11d

Browse files
authored
refactor: remove _incorrectWorkingDirectory (#38)
* refactor: trust docker and ci and code spaces environment * refactor: remove _incorrectWorkingDirectory
1 parent 7d46172 commit 89bc11d

File tree

2 files changed

+0
-37
lines changed

2 files changed

+0
-37
lines changed

index.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
exports = module.exports = lifecycle
44
exports.makeEnv = makeEnv
5-
exports._incorrectWorkingDirectory = _incorrectWorkingDirectory
65

76
const spawn = require('./lib/spawn')
87
const { execute } = require('@yarnpkg/shell')
@@ -75,12 +74,6 @@ function lifecycle (pkg, stage, wd, opts) {
7574
validWd(wd || path.resolve(opts.dir, pkg.name), (er, wd) => {
7675
if (er) return reject(er)
7776

78-
if ((wd.indexOf(opts.dir) !== 0 || _incorrectWorkingDirectory(wd, pkg)) &&
79-
!opts.unsafePerm && pkg.scripts[stage]) {
80-
opts.log.warn(`"${stage}" script of "${pkg._id}" inside "${wd}" is skipped as the working directory seems suspicious. To run this lifecycle script anyway, use "--unsafe-perm".`)
81-
return resolve()
82-
}
83-
8477
// set the env variables, then run scripts as a child process.
8578
const env = makeEnv(pkg, opts)
8679
env.npm_lifecycle_event = stage
@@ -114,10 +107,6 @@ function lifecycle (pkg, stage, wd, opts) {
114107
})
115108
}
116109

117-
function _incorrectWorkingDirectory (wd, pkg) {
118-
return wd.lastIndexOf(pkg.name) !== wd.length - pkg.name.length
119-
}
120-
121110
function lifecycle_ (pkg, stage, wd, opts, env, cb) {
122111
env[PATH] = extendPath(wd, env[PATH], path.join(__dirname, 'node-gyp-bin'), opts)
123112

test/index.js

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,6 @@ const path = require('path')
77

88
function noop () {}
99

10-
test('_incorrectWorkingDirectory: accepts wd for package that matches project\'s name', function (t) {
11-
const wd = '/opt/my-time/node_modules/time'
12-
const pkg = { name: 'time' }
13-
14-
t.equal(lifecycle._incorrectWorkingDirectory(wd, pkg), false)
15-
t.end()
16-
})
17-
18-
test('_incorrectWorkingDirectory: accepts wd for package that doesn\'t match project\'s name', function (t) {
19-
const wd = '/opt/my-project/node_modules/time'
20-
const pkg = { name: 'time' }
21-
22-
t.equal(lifecycle._incorrectWorkingDirectory(wd, pkg), false)
23-
t.end()
24-
})
25-
26-
test('_incorrectWorkingDirectory: rejects wd from other packages', function (t) {
27-
const wd = '/opt/my-time/node_modules/time/invalid'
28-
const pkg = {
29-
name: 'time'
30-
}
31-
32-
t.equal(lifecycle._incorrectWorkingDirectory(wd, pkg), true)
33-
t.end()
34-
})
35-
3610
test('runs scripts from .hooks directory even if no script is present in package.json', function (t) {
3711
const fixture = path.join(__dirname, 'fixtures', 'has-hooks')
3812

0 commit comments

Comments
 (0)