Skip to content
This repository was archived by the owner on Jul 28, 2021. It is now read-only.

Commit a733499

Browse files
committed
test: fs pkglock lstatSync
1 parent eb268ce commit a733499

File tree

5 files changed

+65
-3
lines changed

5 files changed

+65
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ node_modules
44
/test/cache
55
yarn.lock
66
/lib/commands/utils/.htaccess
7+
test/.cache
8+
.vscode

lib/pkglock.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@ const isPkgLockDisabled = () => !process.tink || process.tink.noPkgLock || envNo
1818
module.exports.resolve = resolve
1919
module.exports._clearCache = () => pkgLockCache.clear()
2020

21+
const tinkDir = path.dirname(__dirname)
22+
2123
function resolve (...p) {
2224
if (isPkgLockDisabled()) { return null }
2325
const resolved = path.resolve(...p)
24-
if (resolved.match(path.dirname(__dirname)) || resolved.match(process.tink.cache)) {
25-
// Don't be a smartass about our own sources and cache...
26-
return null
26+
27+
if (!process.tink._isSelf_) {
28+
if ((tinkDir && resolved.match(tinkDir)) || (process.tink.cache && resolved.match(process.tink.cache))) {
29+
// Don't be a smartass about our own sources and cache...
30+
return null
31+
}
2732
}
33+
2834
const result = readPkgLock(resolved)
2935
if (!result) { return result }
3036
let { pkgLock, subPath } = result

test/fixtures/p1/package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/p1/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "p1",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": ""
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"require-from-path": "^1.0.0"
14+
}
15+
}

test/node/fs-pkglock.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict'
2+
3+
const fs = require('fs')
4+
const path = require('path')
5+
const { test } = require('tap')
6+
const { overrideNode } = require('../../lib/node/fs')
7+
8+
overrideNode()
9+
10+
test('lstatSync', t => {
11+
process.tink = {
12+
_isSelf_: true,
13+
cache: path.join(__dirname, '../.cache'),
14+
config: {
15+
concat: () => null
16+
}
17+
}
18+
19+
try {
20+
const stat = fs.lstatSync(path.join(__dirname, '../fixtures/p1/node_modules/require-from-path/package.json'))
21+
t.equal(stat.integrity, 'sha256-zH8eaxFgnwlLNL9Ze8zmBqDB0WbqdOBrSs8r2PO5Jxo=', `fs-pkglock.lstatSync integrity should match`)
22+
t.end()
23+
} catch (err) {
24+
t.fail(`fs-pkglock.lstatSync caught ${err}`)
25+
}
26+
})

0 commit comments

Comments
 (0)