davideicardi / live-plugin-manager

Plugin manager and installer for Node.JS
MIT License
225 stars 43 forks source link

Handling modules with index.json entrypoints #80

Open danieldelcore opened 1 year ago

danieldelcore commented 1 year ago
image image

I've run into an issue with this module spdx-license-ids which is transitively brought in by one of my dependencies.

And imported like so:

'use strict'

var licenses = []
  .concat(require('spdx-license-ids'))
  .concat(require('spdx-license-ids/deprecated'))
var exceptions = require('spdx-exceptions')

module.exports = function (source) {
  var index = 0

Keen to hear your thoughts on how live-plugin-manager should handle or workaround this module 🤔

danieldelcore commented 1 year ago

I found that adding the following check before this line fixes the problem:

https://github.com/davideicardi/live-plugin-manager/blob/c2966f1c63c845149b1f07f5b9360ede52e8b8aa/src/PluginVm.ts#L247

Because fullPath wrongfully adds index.js by default.

      if (checkPath(fullPath) === "none") {
        const isDirectory = this.tryResolveAsDirectory(
          fullPath.replace("/index.js", "")
        );
        if (isDirectory) {
          return isDirectory;
        }
      }

I'm sure there is a more elegant way to fix this.

davideicardi commented 1 year ago

Not sure about that. That additional check seems to be good, but maybe the original problem is that .json files are not loaded by default? Maybe we should try to load index.js or index.json (or any other compatible extensions)?