~stephen-stewart/+junk/add-grunt

« back to all changes in this revision

Viewing changes to node_modules/grunt-cli/node_modules/resolve/readme.markdown

  • Committer: Stephen Stewart
  • Date: 2014-05-13 01:26:55 UTC
  • Revision ID: stephen.stewart@canonical.com-20140513012655-wx8xbwcdohofxoyj
add --production node_modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# resolve
 
2
 
 
3
implements the [node `require.resolve()`
 
4
algorithm](http://nodejs.org/docs/v0.4.8/api/all.html#all_Together...)
 
5
such that you can `require.resolve()` on behalf of a file asynchronously and
 
6
synchronously
 
7
 
 
8
[![build status](https://secure.travis-ci.org/substack/node-resolve.png)](http://travis-ci.org/substack/node-resolve)
 
9
 
 
10
# example
 
11
 
 
12
asynchronously resolve:
 
13
 
 
14
``` js
 
15
var resolve = require('resolve');
 
16
resolve('tap', { basedir: __dirname }, function (err, res) {
 
17
    if (err) console.error(err)
 
18
    else console.log(res)
 
19
});
 
20
```
 
21
 
 
22
```
 
23
$ node example/async.js
 
24
/home/substack/projects/node-resolve/node_modules/tap/lib/main.js
 
25
```
 
26
 
 
27
synchronously resolve:
 
28
 
 
29
``` js
 
30
var resolve = require('resolve');
 
31
var res = resolve.sync('tap', { basedir: __dirname });
 
32
console.log(res);
 
33
```
 
34
 
 
35
```
 
36
$ node example/sync.js
 
37
/home/substack/projects/node-resolve/node_modules/tap/lib/main.js
 
38
```
 
39
 
 
40
# methods
 
41
 
 
42
``` js
 
43
var resolve = require('resolve')
 
44
```
 
45
 
 
46
## resolve(pkg, opts={}, cb)
 
47
 
 
48
Asynchronously resolve the module path string `pkg` into `cb(err, res)`.
 
49
 
 
50
options are:
 
51
 
 
52
* opts.basedir - directory to begin resolving from
 
53
 
 
54
* opts.extensions - array of file extensions to search in order
 
55
 
 
56
* opts.readFile - how to read files asynchronously
 
57
 
 
58
* opts.isFile - function to asynchronously test whether a file exists
 
59
 
 
60
* opts.packageFilter - transform the parsed package.json contents before looking
 
61
at the "main" field
 
62
 
 
63
* opts.paths - require.paths array to use if nothing is found on the normal
 
64
node_modules recursive walk (probably don't use this)
 
65
 
 
66
default `opts` values:
 
67
 
 
68
``` javascript
 
69
{
 
70
    paths: [],
 
71
    basedir: __dirname,
 
72
    extensions: [ '.js' ],
 
73
    readFile: fs.readFile,
 
74
    isFile: function (file, cb) {
 
75
        fs.stat(file, function (err, stat) {
 
76
            if (err && err.code === 'ENOENT') cb(null, false)
 
77
            else if (err) cb(err)
 
78
            else cb(null, stat.isFile())
 
79
        });
 
80
    }
 
81
}
 
82
```
 
83
 
 
84
## resolve.sync(pkg, opts)
 
85
 
 
86
Synchronously resolve the module path string `pkg`, returning the result and
 
87
throwing an error when `pkg` can't be resolved.
 
88
 
 
89
options are:
 
90
 
 
91
* opts.basedir - directory to begin resolving from
 
92
 
 
93
* opts.extensions - array of file extensions to search in order
 
94
 
 
95
* opts.readFile - how to read files synchronously
 
96
 
 
97
* opts.isFile - function to synchronously test whether a file exists
 
98
 
 
99
* opts.packageFilter - transform the parsed package.json contents before looking
 
100
at the "main" field
 
101
 
 
102
* opts.paths - require.paths array to use if nothing is found on the normal
 
103
node_modules recursive walk (probably don't use this)
 
104
 
 
105
default `opts` values:
 
106
 
 
107
``` javascript
 
108
{
 
109
    paths: [],
 
110
    basedir: __dirname,
 
111
    extensions: [ '.js' ],
 
112
    readFileSync: fs.readFileSync,
 
113
    isFile: function (file) {
 
114
        try { return fs.statSync(file).isFile() }
 
115
        catch (e) { return false }
 
116
    }
 
117
}
 
118
````
 
119
 
 
120
## resolve.isCore(pkg)
 
121
 
 
122
Return whether a package is in core.
 
123
 
 
124
# install
 
125
 
 
126
With [npm](https://npmjs.org) do:
 
127
 
 
128
```
 
129
npm install resolve
 
130
```
 
131
 
 
132
# license
 
133
 
 
134
MIT