live-plugin-manager icon indicating copy to clipboard operation
live-plugin-manager copied to clipboard

Handling modules with index.json entrypoints

Open danieldelcore opened this issue 2 years ago • 2 comments

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 avatar Jun 29 '23 06:06 danieldelcore

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.

danieldelcore avatar Jun 29 '23 08:06 danieldelcore

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

davideicardi avatar Jun 30 '23 08:06 davideicardi