Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
resolve-from
Advanced tools
Resolve the path of a module like `require.resolve()` but from a given path
The resolve-from npm package is a module that allows you to resolve the path of a module like require.resolve() but from a given path. It is useful for situations where you need to resolve modules from a different directory than the current file's directory.
Resolve the path of a module from a given path
This feature allows you to resolve the path of a module from a specific directory. You provide the directory as the first argument and the module name as the second argument. It returns the resolved path to the module.
const resolveFrom = require('resolve-from');
const modulePath = resolveFrom('/some/path', 'some-module');
Silently resolve the path of a module or return null
This feature is similar to the first, but it will return null instead of throwing an error if the module cannot be found. This is useful for cases where you want to check for a module's existence without causing an exception.
const resolveFrom = require('resolve-from');
const modulePath = resolveFrom.silent('/some/path', 'non-existent-module');
The 'resolve' package is similar to 'resolve-from' in that it helps to resolve the path of a module. However, 'resolve' provides more options and flexibility, such as the ability to customize the resolution algorithm or to resolve based on the package.json's 'main' field.
The 'enhanced-resolve' package is used by webpack and offers a highly configurable resolution mechanism that can resolve files, directories, and modules. It is more complex and feature-rich compared to 'resolve-from', which is simpler and more straightforward.
The 'browser-resolve' package is designed to resolve modules for browser environments, taking into account the 'browser' field in package.json. It is similar to 'resolve-from' but is specifically tailored for browser-based module resolution.
Resolve the path of a module like
require.resolve()
but from a given path
$ npm install resolve-from
const resolveFrom = require('resolve-from');
// There is a file at `./foo/bar.js`
resolveFrom('foo', './bar');
//=> '/Users/sindresorhus/dev/test/foo/bar.js'
Like require()
, throws when the module can't be found.
Returns undefined
instead of throwing when the module can't be found.
Type: string
Directory to resolve from.
Type: string
What you would use in require()
.
Create a partial using a bound function if you want to resolve from the same fromDirectory
multiple times:
const resolveFromFoo = resolveFrom.bind(null, 'foo');
resolveFromFoo('./bar');
resolveFromFoo('./baz');
MIT © Sindre Sorhus
FAQs
Resolve the path of a module like `require.resolve()` but from a given path
The npm package resolve-from receives a total of 55,952,599 weekly downloads. As such, resolve-from popularity was classified as popular.
We found that resolve-from demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.