Skip to content
This repository was archived by the owner on Jul 28, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ node_modules
/test/cache
yarn.lock
/lib/commands/utils/.htaccess
test/.cache
.vscode
12 changes: 9 additions & 3 deletions lib/pkglock.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ const isPkgLockDisabled = () => !process.tink || process.tink.noPkgLock || envNo
module.exports.resolve = resolve
module.exports._clearCache = () => pkgLockCache.clear()

const tinkDir = path.dirname(__dirname)

function resolve (...p) {
if (isPkgLockDisabled()) { return null }
const resolved = path.resolve(...p)
if (resolved.match(path.dirname(__dirname)) || resolved.match(process.tink.cache)) {
// Don't be a smartass about our own sources and cache...
return null

if (!process.tink._isSelf_) {
if ((tinkDir && resolved.match(tinkDir)) || (process.tink.cache && resolved.match(process.tink.cache))) {
// Don't be a smartass about our own sources and cache...
return null
}
}

const result = readPkgLock(resolved)
if (!result) { return result }
let { pkgLock, subPath } = result
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/p1/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions test/fixtures/p1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "p1",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": ""
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"require-from-path": "^1.0.0"
}
}
26 changes: 26 additions & 0 deletions test/node/fs-pkglock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict'

const fs = require('fs')
const path = require('path')
const { test } = require('tap')
const { overrideNode } = require('../../lib/node/fs')

overrideNode()

test('lstatSync', t => {
process.tink = {
_isSelf_: true,
cache: path.join(__dirname, '../.cache'),
config: {
concat: () => null
}
}

try {
const stat = fs.lstatSync(path.join(__dirname, '../fixtures/p1/node_modules/require-from-path/package.json'))
t.equal(stat.integrity, 'sha256-zH8eaxFgnwlLNL9Ze8zmBqDB0WbqdOBrSs8r2PO5Jxo=', `fs-pkglock.lstatSync integrity should match`)
t.end()
} catch (err) {
t.fail(`fs-pkglock.lstatSync caught ${err}`)
}
})