diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
commit | bbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch) | |
tree | c58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/resolve/readme.markdown | |
parent | 003fb34971cf63466184351b4db5f7c67df4f444 (diff) |
update packages
Diffstat (limited to 'node_modules/resolve/readme.markdown')
-rw-r--r-- | node_modules/resolve/readme.markdown | 71 |
1 files changed, 42 insertions, 29 deletions
diff --git a/node_modules/resolve/readme.markdown b/node_modules/resolve/readme.markdown index 1bb67d434..47f799c50 100644 --- a/node_modules/resolve/readme.markdown +++ b/node_modules/resolve/readme.markdown @@ -5,17 +5,17 @@ algorithm](https://nodejs.org/api/modules.html#modules_all_together) such that you can `require.resolve()` on behalf of a file asynchronously and synchronously -[](http://travis-ci.org/substack/node-resolve) +[](http://travis-ci.org/browserify/node-resolve) # example asynchronously resolve: -``` js +```js var resolve = require('resolve'); resolve('tap', { basedir: __dirname }, function (err, res) { - if (err) console.error(err) - else console.log(res) + if (err) console.error(err); + else console.log(res); }); ``` @@ -26,7 +26,7 @@ $ node example/async.js synchronously resolve: -``` js +```js var resolve = require('resolve'); var res = resolve.sync('tap', { basedir: __dirname }); console.log(res); @@ -39,8 +39,8 @@ $ node example/sync.js # methods -``` js -var resolve = require('resolve') +```js +var resolve = require('resolve'); ``` ## resolve(id, opts={}, cb) @@ -59,17 +59,17 @@ options are: * opts.isFile - function to asynchronously test whether a file exists -* opts.packageFilter - transform the parsed package.json contents before looking -at the "main" field +* `opts.packageFilter(pkg, pkgfile)` - transform the parsed package.json contents before looking at the "main" field + * pkg - package data + * pkgfile - path to package.json -* opts.pathFilter(pkg, path, relativePath) - transform a path within a package +* `opts.pathFilter(pkg, path, relativePath)` - transform a path within a package * pkg - package data * path - the path being resolved * relativePath - the path relative from the package.json location * returns - a relative path that will be joined from the package.json location -* opts.paths - require.paths array to use if nothing is found on the normal -node_modules recursive walk (probably don't use this) +* opts.paths - require.paths array to use if nothing is found on the normal `node_modules` recursive walk (probably don't use this) * opts.moduleDirectory - directory (or directories) in which to recursively look for modules. default: `"node_modules"` @@ -80,17 +80,19 @@ This is the way Node resolves dependencies when executed with the [--preserve-sy default `opts` values: -``` javascript +```js { paths: [], basedir: __dirname, - extensions: [ '.js' ], + extensions: ['.js'], readFile: fs.readFile, - isFile: function (file, cb) { + isFile: function isFile(file, cb) { fs.stat(file, function (err, stat) { - if (err && err.code === 'ENOENT') cb(null, false) - else if (err) cb(err) - else cb(null, stat.isFile()) + if (!err) { + return cb(null, stat.isFile() || stat.isFIFO()); + } + if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false); + return cb(err); }); }, moduleDirectory: 'node_modules', @@ -113,11 +115,17 @@ options are: * opts.isFile - function to synchronously test whether a file exists -* `opts.packageFilter(pkg, pkgfile)` - transform the parsed package.json -* contents before looking at the "main" field +* `opts.packageFilter(pkg, dir)` - transform the parsed package.json contents before looking at the "main" field + * pkg - package data + * dir - directory for package.json (Note: the second argument will change to "pkgfile" in v2) + +* `opts.pathFilter(pkg, path, relativePath)` - transform a path within a package + * pkg - package data + * path - the path being resolved + * relativePath - the path relative from the package.json location + * returns - a relative path that will be joined from the package.json location -* opts.paths - require.paths array to use if nothing is found on the normal -node_modules recursive walk (probably don't use this) +* opts.paths - require.paths array to use if nothing is found on the normal `node_modules` recursive walk (probably don't use this) * opts.moduleDirectory - directory (or directories) in which to recursively look for modules. default: `"node_modules"` @@ -128,20 +136,25 @@ This is the way Node resolves dependencies when executed with the [--preserve-sy default `opts` values: -``` javascript +```js { paths: [], basedir: __dirname, - extensions: [ '.js' ], + extensions: ['.js'], readFileSync: fs.readFileSync, - isFile: function (file) { - try { return fs.statSync(file).isFile() } - catch (e) { return false } + isFile: function isFile(file) { + try { + var stat = fs.statSync(file); + } catch (e) { + if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false; + throw e; + } + return stat.isFile() || stat.isFIFO(); }, moduleDirectory: 'node_modules', preserveSymlinks: true } -```` +``` ## resolve.isCore(pkg) @@ -151,7 +164,7 @@ Return whether a package is in core. With [npm](https://npmjs.org) do: -``` +```sh npm install resolve ``` |