yortus / require-self

Lets you require('foobar') from within foobar itself
MIT License
19 stars 5 forks source link

adds support for private/scoped modules #3

Closed benmonro closed 7 years ago

yortus commented 8 years ago

Hi @benmonro thanks for the PR.

I think there may be still be a problem with the scoped package support:

var name = pkg.name;
...
var modulePath = path.join(cwd, 'node_modules', name + '.js');
...  
// Create the pseudo-module.
fs.writeFileSync(modulePath, moduleText);

If our module name was say "@myscope/mypackage", then fs.writeFileSync is being asked to create a file at the path "[...]/node_modules/@myscope/mypackage.js" which will fail because the "@myscope" directory doesn't exist in "node_modules".

Maybe add some logic to create this directory first (if not exists) before creating the file?

yortus commented 7 years ago

7 fixes this.