[Pkg-javascript-commits] [node-require-relative] 01/02: New upstream version 0.8.7

Julien Puydt julien.puydt at laposte.net
Tue Nov 1 12:32:39 UTC 2016


This is an automated email from the git hooks/post-receive script.

jpuydt-guest pushed a commit to branch master
in repository node-require-relative.

commit 1a333b59cfc1fce6e00292d3ab6f60cd3e6b1af7
Author: Julien Puydt <julien.puydt at laposte.net>
Date:   Tue Nov 1 12:45:08 2016 +0100

    New upstream version 0.8.7
---
 README.md    | 26 ++++++++++++++++++++++++++
 index.js     | 33 +++++++++++++++++++++++++++++++++
 package.json | 22 ++++++++++++++++++++++
 3 files changed, 81 insertions(+)

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..0ef1415
--- /dev/null
+++ b/README.md
@@ -0,0 +1,26 @@
+# require-relative
+
+require-relative is a node.js program to require and resolve modules relative to a path of your choice.
+It exploits node.js's own `module` module, and has no additional dependencies.
+
+## Example
+
+requiring modules relatively
+
+```js
+var relative = require('require-relative');
+
+var someModule = relative('./some-module', '/home/kamicane');
+var somePackage = relative('some-package', '/home/kamicane');
+var isTrue = relative('./some-module.js', process.cwd()) === relative('./some-module.js');
+```
+
+resolving filenames relatively
+
+```js
+var relative = require('require-relative');
+
+relative.resolve('./some-module', '/home/kamicane'); // /home/kamicane/some-module.js
+relative.resolve('some-package', '/home/kamicane'); // /home/kamicane/node_modules/some-package/index.js
+var isTrue = relative.resolve('./some-module.js', process.cwd()) === relative.resolve('./some-module.js');
+```
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..376a6de
--- /dev/null
+++ b/index.js
@@ -0,0 +1,33 @@
+/*
+relative require
+*/'use strict';
+
+var path = require('path');
+var Module = require('module');
+
+var modules = {};
+
+var getModule = function(dir) {
+  var rootPath = dir ? path.resolve(dir) : process.cwd();
+  var rootName = path.join(rootPath, '@root');
+  var root = modules[rootName];
+  if (!root) {
+    root = new Module(rootName);
+    root.filename = rootName;
+    root.paths = Module._nodeModulePaths(rootPath);
+    modules[rootName] = root;
+  }
+  return root;
+};
+
+var requireRelative = function(requested, relativeTo) {
+  var root = getModule(relativeTo);
+  return root.require(requested);
+};
+
+requireRelative.resolve = function(requested, relativeTo) {
+  var root = getModule(relativeTo);
+  return Module._resolveFilename(requested, root);
+};
+
+module.exports = requireRelative;
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..cdd4d90
--- /dev/null
+++ b/package.json
@@ -0,0 +1,22 @@
+{
+  "name": "require-relative",
+  "version": "0.8.7",
+  "description": "require and resolve modules relative to a path of your choice",
+  "main": "index.js",
+  "homepage": "https://github.com/kamicane/require-relative",
+  "author": "Valerio Proietti <@kamicane> (http://mad4milk.net)",
+  "keywords": [
+    "require",
+    "resolve",
+    "modules",
+    "relative"
+  ],
+  "license": "MIT",
+  "bugs": {
+    "url": "https://github.com/kamicane/require-relative/issues"
+  },
+  "repository": {
+    "type": "git",
+    "url": "git://github.com/kamicane/require-relative.git"
+  }
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-require-relative.git



More information about the Pkg-javascript-commits mailing list