Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin .library should include the file automatically #36

Closed
pocesar opened this issue Aug 23, 2013 · 7 comments
Closed

plugin .library should include the file automatically #36

pocesar opened this issue Aug 23, 2013 · 7 comments

Comments

@pocesar
Copy link

pocesar commented Aug 23, 2013

the plugin code:

module.exports = {
  server: function(){},
  client: function(){},
  library: require('fs').readFileSync(require.resolve('./angular/primus.js'), 'utf-8')  // could be simplified
};

the library member should automatically require the files, for example, if you pass an array, like this:

module.exports = {
  server: function(){},
  client: function(){},
  library: ['./angular/primus.js','another/lib.js']
};

the path should resolved using require.resolve each file and concat them. This way the, Primus can distinguish between paths and a 'raw' library string. Could it be done?

@3rd-Eden
Copy link
Member

If I would require.resolve that in the primus library your files would end up missing as it would search the directory of the primus module not the directory of your primus plugin.

I can just check if the library is an array and do a simple:

if (Array.isArray(plugin.library)) library += plugin.library.map(function (path) { 
  return fs.readFileSync(path, 'utf-8');
}).join('\n');

I don't have a problem with that at all :)

@3rd-Eden
Copy link
Member

At least, if that is what you want ;)

@pocesar
Copy link
Author

pocesar commented Aug 23, 2013

I see. glob, like in grunt, would be useful, since it translates to real paths to the files, since you can specify the src, so it would know where to start searching. indeed, require.resolve isn't the way to go, and the problem is more dificult to solve than it sounds. unless the directory (before readFileSync) is forcefully appended with the required plugin file path, but that would need a change in the use function to accept options I guess.

@3rd-Eden
Copy link
Member

I honestly don't the big problem here, what's the problem with doing a require.resolve in the plugin?

@pocesar
Copy link
Author

pocesar commented Aug 27, 2013

well, relative paths won't work, unless it's __dirname + 'library.js', the require will know where to look for them. mostly because of that. relative paths like ./file.js or ../../file.js won't work unless you use the current plugin file path (that is unknown to primus, since you use primus.use with an already require'd module).

@3rd-Eden
Copy link
Member

Why would need relative paths? What's wrong with the __dirname & resolve approach?

@pocesar
Copy link
Author

pocesar commented Aug 27, 2013

nothing, it just need to be stated explicity in the readme that the library paths (that will be concat'ed) need to be absolute instead of relative. that would be the only catch, else, everything is fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants