GithubHelp home page GithubHelp logo

load-plugin's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

load-plugin's Issues

Wrong detection of npm prefix on windows

Hi. You rely on npm-prefix package for detecting npm prefix.
But this package is very outdated I suppose.
At least it may give wrong results on windows.

By default nodejs with npm are installing into 'system' folder:

  • C:\Program Files\nodejs\node.exe
  • C:\Program Files\nodejs\npm.cmd
  • C:\Program Files\nodejs\node_modules\npm\...

In this situation the npm-prefix package correctly returns C:\Program Files\nodejs.

But... all consequent global installs go to user's folder (without requirements of privileged access to system folders):
C:\Users\{username}\AppData\Roaming\npm\node_modules\...
npm i -g npm becomes C:\Users\{username}\AppData\Roaming\npm\node_modules\npm\...
npm i -g remark-cli becomes C:\Users\{username}\AppData\Roaming\npm\node_modules\remark-cli\...
npm i -g remark-html becomes C:\Users\{username}\AppData\Roaming\npm\node_modules\remark-html\...

And here arises the problem with npm-prefix.
It still returns C:\Program Files\nodejs but not the actual C:\Users\{username}\AppData\Roaming\npm.
Eventually your load-plugin searches for modules in a wrong directory.

So I suggest you to find another solution.
Some other package or maybe just npm config get prefix?

Thank you.

Yarn PnP compatibility?

I believe the issue described here (remarkjs/remark-language-server#6 (comment)) is a result of an assumption that packages are stored in a node_modules directory.

I tried running resolvePlugin and loadPlugin against my project and got the following error

% yarn node test.mjs

Error: Cannot find package 'lint' imported from /<mycwd>/
    at new NodeError (file:///<mycwd>/.yarn/cache/import-meta-resolve-npm-2.1.0-fcf1208127-4554ea5e2d.zip/node_modules/import-meta-resolve/lib/errors.js:276:5)
    at packageResolve (file:///<mycwd>/.yarn/cache/import-meta-resolve-npm-2.1.0-fcf1208127-4554ea5e2d.zip/node_modules/import-meta-resolve/lib/resolve.js:1060:9)
    at moduleResolve (file:///<mycwd>/.yarn/cache/import-meta-resolve-npm-2.1.0-fcf1208127-4554ea5e2d.zip/node_modules/import-meta-resolve/lib/resolve.js:1117:20)
    at defaultResolve (file:///<mycwd>/.yarn/cache/import-meta-resolve-npm-2.1.0-fcf1208127-4554ea5e2d.zip/node_modules/import-meta-resolve/lib/resolve.js:1266:15)
    at resolve (file:///<mycwd>/.yarn/cache/import-meta-resolve-npm-2.1.0-fcf1208127-4554ea5e2d.zip/node_modules/import-meta-resolve/index.js:29:12)
    at attempt (file:///<mycwd>/.yarn/cache/load-plugin-npm-5.1.0-5695bc6a89-d450c9a083.zip/node_modules/load-plugin/index.js:167:15)
    at resolvePlugin (file:///<mycwd>/.yarn/cache/load-plugin-npm-5.1.0-5695bc6a89-d450c9a083.zip/node_modules/load-plugin/index.js:148:16)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async file:///<mycwd>/test.mjs:5:17 {
  code: 'ERR_MODULE_NOT_FOUND'
}

where test.mjs is

import { loadPlugin, resolvePlugin } from 'load-plugin';

(async () => {
  try {
    console.log(await resolvePlugin('lint', { prefix: 'remark' }));
  } catch (error) {
    console.error(error);
  }
})();

Wrap errors in an `AggregateError`

resolvePlugin tries to resolve a plugin from several locations. Each try may fail, but only the last error is preserved. I think it’s better to collect all errors, and throw an AggregateError instead. This communicates all attempted locations to the user.

If only one error is thrown, perhaps no AggregateError is needed.

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.