a special purpose fast memoizing way to resolve a node modules package.json
Installations
npm install resolve-package-path
Releases
Unable to fetch releases
Developer
stefanpenner
Developer Guide
Module System
CommonJS
Min. Node Version
>= 12
Typescript Support
Yes
Node Version
12.19.0
NPM Version
6.14.8
Statistics
30 Stars
159 Commits
10 Forks
5 Watching
7 Branches
9 Contributors
Updated on 27 Oct 2024
Languages
TypeScript (97.71%)
JavaScript (2.29%)
Total Downloads
Cumulative downloads
Total Downloads
171,305,371
Last day
-19.1%
213,146
Compared to previous day
Last week
-8.6%
1,116,701
Compared to previous week
Last month
17.7%
5,050,081
Compared to previous month
Last year
68.4%
63,626,223
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
resolve-package-path
This project is special-purpose, made to resolve package.json
files for:
- a given module name and basedir or
- a given basedir
It cannot and does not resolve anything else.
To achieve its file-resolution performance, it does two specific things:
-
It memoizes results identically to node's
require
. Specifically, for a given moduleName and baseDir it will, for the duration of the process, always return the exact same response. -
It re-implements the parts of
require.resolve
needed to resolve package.json files ONLY. This removes unneeded I/O. (based on @davecombs approach)
Usage
1yarn add resolve-package-path
1const resolvePackagePath = require('resolve-package-path');
2
3resolvePackagePath('rsvp', 'base-dir/to/start/the/node_resolution-algorithm-from') // => /path/to/rsvp.json or null
4
5const { findUpPackagePath } = resolvePackagePath;
6findUpPackagePath('base-dir/to/start') // => path/to/package.json or null
Advanced usage
Preserve Symlinks
Node supports --preserve-symlinks
and NODE_PRESERVE_SYMLINKS=1
for compatibility this library respects these.
Disable default caching
Although by default resolve-package-path
caches or memoizes results, this feature can be disabled:
1const resolvePackagePath = require('resolve-package-path');
2
3resolvePackagePath('rsvp', 'base-dir/to/start/the/node_resolution-algorithm-from', false) // => uncached result /path/to/rsvp.json or null
4
5const { findUpPackagePath } = resolvePackagePath;
6findUpPackagePath('base-dir/to/start', false) // => path/to/package.json or null
Purge the cache
1const resolvePackagePath = require('resolve-package-path'); 2resolvePackagePath._resetCache();
Provide an alternative cache
In some advanced circumtances, you may want to gain access to the cache to share between more systems. In that case, a cache instance of the following form can be provided as a third argument:
1cache = {
2 RESOLVED_PACKAGE_PATH: new Map(),
3 REAL_FILE_PATH: new Map(),
4 REAL_DIRECTORY_PATH: new Map(),
5};
6findUpCache = new Map();
7
8const resolvePackagePath = require('resolve-package-path');
9resolvePackagePath('rsvp', 'path/to/start/from', cache);
10
11const { findUpPackagePath } = resolvePackagePath;
12findUpPackagePath('base-dir/to/start', findUpCache) // => path/to/package.json or null
Use internal helper functions
For consumers who also do getRealFilePath
or
getRealDirectoryPath
calls on relevant paths, we expose them as utilities.
These utilties ensure identical functionality to resolve-package-path, and a
shared cache, which may help reduce IO.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 2/15 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/stefanpenner/resolve-package-path/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/stefanpenner/resolve-package-path/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/stefanpenner/resolve-package-path/ci.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 22 are checked with a SAST tool
Reason
11 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-qrpm-p2h7-hrv2
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
Score
2.6
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to resolve-package-path
@rigor789/resolve-package-path
[![CI](https://github.com/rigor789/resolve-package-path/actions/workflows/ci.yml/badge.svg)](https://github.com/rigor789/resolve-package-path/actions/workflows/ci.yml)
resolve-from
Resolve the path of a module like `require.resolve()` but from a given path
enhanced-resolve
Offers a async require.resolve function. It's highly configurable.
resolve-dir
Resolve a directory that is either local, global or in the user's home directory.