Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixes issue #227 and Fixes issue #228 #231

Closed
wants to merge 1 commit into from

2 participants

Paul Kinlan James Halliday
Paul Kinlan

There is some oddness in the parsing of submodules tied to the way it loads sub-modules that are relative to the module.

This fix understands if the module is a global module or one that is a sub-module.

James Halliday
Owner

Thanks for your patch, but v2 moved to a static module resolution approach so this issue should no longer apply.

James Halliday substack closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
2  .gitignore
View
@@ -0,0 +1,2 @@
+*.swp
+node_modules/*
20 lib/wrap.js
View
@@ -525,14 +525,20 @@ Wrap.prototype.require = function (mfile, opts) {
// not a real directory on the filesystem; just using the path
// module to get rid of the filename.
var targetDir = path.dirname(opts.target);
- // not a real filename; just using the path module to deal with
- // relative paths.
- var reqFilename = path.resolve(targetDir, req);
- // get rid of drive letter on Windows; replace it with '/'
- var reqFilenameWithoutDriveLetter = /^[A-Z]:\\/.test(reqFilename) ?
- '/' + reqFilename.substring(3) : reqFilename;
+ if(targetDir == ".") {
+ // a single level import
+ params.target = path.join("/", opts.target, req);
+ }
+ else {
+ // not a real filename; just using the path module to deal with
+ // relative paths.
+ var reqFilename = path.resolve(targetDir, req);
+ // get rid of drive letter on Windows; replace it with '/'
+ var reqFilenameWithoutDriveLetter = /^[A-Z]:\\/.test(reqFilename) ?
+ '/' + reqFilename.substring(3) : reqFilename;
- params.target = idFromPath(reqFilenameWithoutDriveLetter);
+ params.target = idFromPath(reqFilenameWithoutDriveLetter);
+ }
}
self.require(req, params);
});
1  test/node_modules/bop/bop.js
View
@@ -0,0 +1 @@
+module.exports = 'boo';
1  test/node_modules/bop/index.js
View
@@ -0,0 +1 @@
+module.exports = require('./bop.js');
27 test/requiresubmodule.js
View
@@ -0,0 +1,27 @@
+var test = require('tap').test;
+var spawn = require('child_process').spawn;
+var path = require('path');
+var vm = require('vm');
+
+test('require submodule with -r', function (t) {
+ t.plan(2);
+
+ var cwd = process.cwd();
+ process.chdir(__dirname);
+
+ var ps = spawn(process.execPath, [
+ path.resolve(__dirname, '../bin/cmd.js'),
+ '-r', 'bop',
+ '--exports=require'
+ ]);
+ var src = '';
+ ps.stdout.on('data', function (buf) { src += buf });
+
+ ps.on('exit', function (code) {
+ t.equal(code, 0);
+
+ var c = {};
+ vm.runInNewContext(src, c);
+ t.equal(c.require('bop'), 'boo');
+ });
+});
1  wrappers/prelude.js
View
@@ -154,6 +154,7 @@ require.alias = function (from, to) {
;
var require_ = function (file) {
+ dirname = (dirname == ".") ? filename : dirname ;
var requiredModule = require(file, dirname);
var cached = require.cache[require.resolve(file, dirname)];
Something went wrong with that request. Please try again.