Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.markdown 10.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. # resolve
  2. implements the [node `require.resolve()`
  3. algorithm](https://nodejs.org/api/modules.html#modules_all_together)
  4. such that you can `require.resolve()` on behalf of a file asynchronously and
  5. synchronously
  6. [![build status](https://secure.travis-ci.org/browserify/resolve.png)](http://travis-ci.org/browserify/resolve)
  7. # example
  8. asynchronously resolve:
  9. ```js
  10. var resolve = require('resolve');
  11. resolve('tap', { basedir: __dirname }, function (err, res) {
  12. if (err) console.error(err);
  13. else console.log(res);
  14. });
  15. ```
  16. ```
  17. $ node example/async.js
  18. /home/substack/projects/node-resolve/node_modules/tap/lib/main.js
  19. ```
  20. synchronously resolve:
  21. ```js
  22. var resolve = require('resolve');
  23. var res = resolve.sync('tap', { basedir: __dirname });
  24. console.log(res);
  25. ```
  26. ```
  27. $ node example/sync.js
  28. /home/substack/projects/node-resolve/node_modules/tap/lib/main.js
  29. ```
  30. # methods
  31. ```js
  32. var resolve = require('resolve');
  33. ```
  34. For both the synchronous and asynchronous methods, errors may have any of the following `err.code` values:
  35. - `MODULE_NOT_FOUND`: the given path string (`id`) could not be resolved to a module
  36. - `INVALID_BASEDIR`: the specified `opts.basedir` doesn't exist, or is not a directory
  37. - `INVALID_PACKAGE_MAIN`: a `package.json` was encountered with an invalid `main` property (eg. not a string)
  38. ## resolve(id, opts={}, cb)
  39. Asynchronously resolve the module path string `id` into `cb(err, res [, pkg])`, where `pkg` (if defined) is the data from `package.json`.
  40. options are:
  41. * opts.basedir - directory to begin resolving from
  42. * opts.package - `package.json` data applicable to the module being loaded
  43. * opts.extensions - array of file extensions to search in order
  44. * opts.includeCoreModules - set to `false` to exclude node core modules (e.g. `fs`) from the search
  45. * opts.readFile - how to read files asynchronously
  46. * opts.isFile - function to asynchronously test whether a file exists
  47. * opts.isDirectory - function to asynchronously test whether a directory exists
  48. * opts.realpath - function to asynchronously resolve a potential symlink to its real path
  49. * `opts.readPackage(readFile, pkgfile, cb)` - function to asynchronously read and parse a package.json file
  50. * readFile - the passed `opts.readFile` or `fs.readFile` if not specified
  51. * pkgfile - path to package.json
  52. * cb - callback
  53. * `opts.packageFilter(pkg, pkgfile, dir)` - transform the parsed package.json contents before looking at the "main" field
  54. * pkg - package data
  55. * pkgfile - path to package.json
  56. * dir - directory for package.json
  57. * `opts.pathFilter(pkg, path, relativePath)` - transform a path within a package
  58. * pkg - package data
  59. * path - the path being resolved
  60. * relativePath - the path relative from the package.json location
  61. * returns - a relative path that will be joined from the package.json location
  62. * opts.paths - require.paths array to use if nothing is found on the normal `node_modules` recursive walk (probably don't use this)
  63. For advanced users, `paths` can also be a `opts.paths(request, start, opts)` function
  64. * request - the import specifier being resolved
  65. * start - lookup path
  66. * getNodeModulesDirs - a thunk (no-argument function) that returns the paths using standard `node_modules` resolution
  67. * opts - the resolution options
  68. * `opts.packageIterator(request, start, opts)` - return the list of candidate paths where the packages sources may be found (probably don't use this)
  69. * request - the import specifier being resolved
  70. * start - lookup path
  71. * getPackageCandidates - a thunk (no-argument function) that returns the paths using standard `node_modules` resolution
  72. * opts - the resolution options
  73. * opts.moduleDirectory - directory (or directories) in which to recursively look for modules. default: `"node_modules"`
  74. * opts.preserveSymlinks - if true, doesn't resolve `basedir` to real path before resolving.
  75. This is the way Node resolves dependencies when executed with the [--preserve-symlinks](https://nodejs.org/api/all.html#cli_preserve_symlinks) flag.
  76. **Note:** this property is currently `true` by default but it will be changed to
  77. `false` in the next major version because *Node's resolution algorithm does not preserve symlinks by default*.
  78. default `opts` values:
  79. ```js
  80. {
  81. paths: [],
  82. basedir: __dirname,
  83. extensions: ['.js'],
  84. includeCoreModules: true,
  85. readFile: fs.readFile,
  86. isFile: function isFile(file, cb) {
  87. fs.stat(file, function (err, stat) {
  88. if (!err) {
  89. return cb(null, stat.isFile() || stat.isFIFO());
  90. }
  91. if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
  92. return cb(err);
  93. });
  94. },
  95. isDirectory: function isDirectory(dir, cb) {
  96. fs.stat(dir, function (err, stat) {
  97. if (!err) {
  98. return cb(null, stat.isDirectory());
  99. }
  100. if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
  101. return cb(err);
  102. });
  103. },
  104. realpath: function realpath(file, cb) {
  105. var realpath = typeof fs.realpath.native === 'function' ? fs.realpath.native : fs.realpath;
  106. realpath(file, function (realPathErr, realPath) {
  107. if (realPathErr && realPathErr.code !== 'ENOENT') cb(realPathErr);
  108. else cb(null, realPathErr ? file : realPath);
  109. });
  110. },
  111. readPackage: function defaultReadPackage(readFile, pkgfile, cb) {
  112. readFile(pkgfile, function (readFileErr, body) {
  113. if (readFileErr) cb(readFileErr);
  114. else {
  115. try {
  116. var pkg = JSON.parse(body);
  117. cb(null, pkg);
  118. } catch (jsonErr) {
  119. cb(null);
  120. }
  121. }
  122. });
  123. },
  124. moduleDirectory: 'node_modules',
  125. preserveSymlinks: true
  126. }
  127. ```
  128. ## resolve.sync(id, opts)
  129. Synchronously resolve the module path string `id`, returning the result and
  130. throwing an error when `id` can't be resolved.
  131. options are:
  132. * opts.basedir - directory to begin resolving from
  133. * opts.extensions - array of file extensions to search in order
  134. * opts.includeCoreModules - set to `false` to exclude node core modules (e.g. `fs`) from the search
  135. * opts.readFileSync - how to read files synchronously
  136. * opts.isFile - function to synchronously test whether a file exists
  137. * opts.isDirectory - function to synchronously test whether a directory exists
  138. * opts.realpathSync - function to synchronously resolve a potential symlink to its real path
  139. * `opts.readPackageSync(readFileSync, pkgfile)` - function to synchronously read and parse a package.json file
  140. * readFileSync - the passed `opts.readFileSync` or `fs.readFileSync` if not specified
  141. * pkgfile - path to package.json
  142. * `opts.packageFilter(pkg, dir)` - transform the parsed package.json contents before looking at the "main" field
  143. * pkg - package data
  144. * dir - directory for package.json (Note: the second argument will change to "pkgfile" in v2)
  145. * `opts.pathFilter(pkg, path, relativePath)` - transform a path within a package
  146. * pkg - package data
  147. * path - the path being resolved
  148. * relativePath - the path relative from the package.json location
  149. * returns - a relative path that will be joined from the package.json location
  150. * opts.paths - require.paths array to use if nothing is found on the normal `node_modules` recursive walk (probably don't use this)
  151. For advanced users, `paths` can also be a `opts.paths(request, start, opts)` function
  152. * request - the import specifier being resolved
  153. * start - lookup path
  154. * getNodeModulesDirs - a thunk (no-argument function) that returns the paths using standard `node_modules` resolution
  155. * opts - the resolution options
  156. * `opts.packageIterator(request, start, opts)` - return the list of candidate paths where the packages sources may be found (probably don't use this)
  157. * request - the import specifier being resolved
  158. * start - lookup path
  159. * getPackageCandidates - a thunk (no-argument function) that returns the paths using standard `node_modules` resolution
  160. * opts - the resolution options
  161. * opts.moduleDirectory - directory (or directories) in which to recursively look for modules. default: `"node_modules"`
  162. * opts.preserveSymlinks - if true, doesn't resolve `basedir` to real path before resolving.
  163. This is the way Node resolves dependencies when executed with the [--preserve-symlinks](https://nodejs.org/api/all.html#cli_preserve_symlinks) flag.
  164. **Note:** this property is currently `true` by default but it will be changed to
  165. `false` in the next major version because *Node's resolution algorithm does not preserve symlinks by default*.
  166. default `opts` values:
  167. ```js
  168. {
  169. paths: [],
  170. basedir: __dirname,
  171. extensions: ['.js'],
  172. includeCoreModules: true,
  173. readFileSync: fs.readFileSync,
  174. isFile: function isFile(file) {
  175. try {
  176. var stat = fs.statSync(file);
  177. } catch (e) {
  178. if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;
  179. throw e;
  180. }
  181. return stat.isFile() || stat.isFIFO();
  182. },
  183. isDirectory: function isDirectory(dir) {
  184. try {
  185. var stat = fs.statSync(dir);
  186. } catch (e) {
  187. if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;
  188. throw e;
  189. }
  190. return stat.isDirectory();
  191. },
  192. realpathSync: function realpathSync(file) {
  193. try {
  194. var realpath = typeof fs.realpathSync.native === 'function' ? fs.realpathSync.native : fs.realpathSync;
  195. return realpath(file);
  196. } catch (realPathErr) {
  197. if (realPathErr.code !== 'ENOENT') {
  198. throw realPathErr;
  199. }
  200. }
  201. return file;
  202. },
  203. readPackageSync: function defaultReadPackageSync(readFileSync, pkgfile) {
  204. var body = readFileSync(pkgfile);
  205. try {
  206. var pkg = JSON.parse(body);
  207. return pkg;
  208. } catch (jsonErr) {}
  209. },
  210. moduleDirectory: 'node_modules',
  211. preserveSymlinks: true
  212. }
  213. ```
  214. # install
  215. With [npm](https://npmjs.org) do:
  216. ```sh
  217. npm install resolve
  218. ```
  219. # license
  220. MIT