Skip to content

Commit b39599e

Browse files
authored
Merge pull request #4 from dependents/object_form
Breaking: Support an object form
2 parents 6bad609 + 1a781a6 commit b39599e

File tree

6 files changed

+1111
-33
lines changed

6 files changed

+1111
-33
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
language: node_js
22

33
node_js:
4-
- "0.10"
4+
- "6"
5+
- "7"
6+
- "8"
57

68
notifications:
79
email: false
810

9-
sudo: false
11+
sudo: false

Readme.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22

33
> Convert a dependency path into a filepath
44
5-
`npm install resolve-dependency-path`
5+
`npm install --save resolve-dependency-path`
66

77
### Usage
88

99
```js
1010
var resolvePath = require('resolve-dependency-path');
1111

12-
var resolved = resolvePath(depPath, filename, directory);
12+
var resolved = resolvePath({
13+
dependency: './foobar',
14+
filename: 'path/to/file/containing/dependency.js',
15+
directory: 'path/to/all/files'
16+
});
1317
```
1418

15-
* `depPath`: the actual dependency path (probably extracted from a `require()`)
16-
* filename: the file that required this dependency (likely the file whose dependencies are being extracted)
17-
* directory: the root of all modules being processed. Dependencies are often about this root unless they're relative.
19+
* `dependency`: the actual dependency path (probably extracted from a `require()`)
20+
* `filename`: the file that required this dependency (likely the file whose dependencies are being extracted)
21+
* `directory`: the root of all modules being processed. Dependencies are often about this root unless they're relative.
1822

1923
### Example
2024

@@ -63,4 +67,4 @@ define([
6367

6468
The dependency `feature2/bar` is relative to the root of all files, `myapp`, *not* the file `foo.js`.
6569

66-
This is why the `directory` attribute is required to use this library.
70+
This is why the `directory` attribute is required to use this library.

index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
var path = require('path');
22

33
/**
4-
* Resolve a dependency's path
5-
* @param {String} dep - The dependency name to resolve
6-
* @param {String} filename - Filename that contains the dependency
7-
* @param {String} directory - Root of all files
4+
* @param {Object} options
5+
* @param {String} options.dependency - The dependency name to resolve
6+
* @param {String} options.filename - Filename that contains the dependency
7+
* @param {String} options.directory - Root of all files
88
* @return {String} Absolute/resolved path of the dependency
99
*/
10-
module.exports = function(dep, filename, directory) {
10+
module.exports = function({dependency: dep, filename, directory} = {}) {
1111
if (!dep) { throw new Error('dependency path not given'); }
1212
if (!filename) { throw new Error('filename not given'); }
1313
if (!directory) { throw new Error('directory not given'); }
@@ -16,7 +16,7 @@ module.exports = function(dep, filename, directory) {
1616
var ext = getDependencyExtension(dep, filename);
1717

1818
return filepath + ext;
19-
}
19+
};
2020

2121
/**
2222
* @param {String} dep

0 commit comments

Comments
 (0)