Git Product home page Git Product logo

Comments (7)

3rd-Eden avatar 3rd-Eden commented on August 20, 2024

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 :)

from primus.

3rd-Eden avatar 3rd-Eden commented on August 20, 2024

At least, if that is what you want ;)

from primus.

pocesar avatar pocesar commented on August 20, 2024

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.

from primus.

3rd-Eden avatar 3rd-Eden commented on August 20, 2024

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

from primus.

pocesar avatar pocesar commented on August 20, 2024

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).

from primus.

3rd-Eden avatar 3rd-Eden commented on August 20, 2024

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

from primus.

pocesar avatar pocesar commented on August 20, 2024

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

from primus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.