Giter Club home page Giter Club logo

node-resolve-dependency-path's Introduction

resolve-dependency-path

Convert a dependency path into a filepath

I literally wrote this simple function in a handful of projects and decided it should be its own module.

Usage

var resolvePath = require('resolve-dependency-path');

var resolved = resolvePath(depPath, filename, directory);
  • depPath: 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.

Example

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.

node-resolve-dependency-path's People

Contributors

jimthedev avatar mrjoelkemp avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.