Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
resolve-dependency-path
Advanced tools
Convert a dependency path into a filepath
npm install resolve-dependency-path
const resolvePath = require('resolve-dependency-path');
const resolved = resolvePath({
dependency: './foobar',
filename: 'path/to/file/containing/dependency.js',
directory: 'path/to/all/files'
});
dependency
: the actual dependency path (probably extracted from a require()
)filename
: the file that required this dependency (likely the file whose dependencies are being extracted)directory
: the root of all modules being processed. Dependencies are often about this root unless they're relative.If you have a file like:
myapp/foo.js
var require('./bar');
Then if you want to open the file associated with the dependency, you need to resolve ./bar
onto the filesystem.
Since ./bar
is a relative path, it should be resolved relative to foo.js
,
more specifically the directory containing foo.js
, myapp/
. This resolution would yield
myapp/bar.js
.
This is why the filename
attribute is required to use this library.
If you have a non-relative dependency path like:
myapp/foo.js
define([
'bar'
], function(bar) {
});
Then bar
is relative to the root of all files, myapp
. The resolution would yield
myapp/bar.js
.
A more complex example with subdirectories:
myapp/feature1/foo.js
define([
'feature2/bar'
], function(bar) {
});
The dependency feature2/bar
is relative to the root of all files, myapp
, not the file foo.js
.
This is why the directory
attribute is required to use this library.
FAQs
Convert a dependency path into a filepath
The npm package resolve-dependency-path receives a total of 915,115 weekly downloads. As such, resolve-dependency-path popularity was classified as popular.
We found that resolve-dependency-path demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.