atk / solid-register

MIT License
18 stars 1 forks source link

Handle imports relative to project root #4

Open theSherwood opened 2 years ago

theSherwood commented 2 years ago

I'm curious about moving to use solid-register for testing, but I have a lot of code that uses imports relative to the project root, like: src/components/Thing.ts. In jest, which I'm using currently and allows the imports relative to root., the config takes a moduleDirectories property, like: moduleDirectories: ["node_modules", "."]. Is there any chance of this being added to the solid-register config?

atk commented 2 years ago

At the moment, you can handcraft an alias from src to /src, but there's no custom resolver that would support multiple module directories as of now. I'm currently not sure if that's within the scope of this project, so I'll leave the issue open for now while I ponder it for a bit.

theSherwood commented 2 years ago

Maybe I don't understand the way the aliases are supposed to work. I tried:

// solid-register-config.js
module.exports = {
  aliases: {
    filenames: {
      src: __dirname + "/src",
    },
  },
};

...but without success. I'm still getting

Error: Cannot find module 'src/lib/dispatch'

...when I run

uvu . \\.*test.ts$ -r solid-register

...or

uvu src \\.*test.ts$ -r solid-register

Is there a way to get this to work at present? Or not so much

atk commented 2 years ago

Sorry, you don't need __dirname; this is already being taken care of. Only relative paths did not work yet, but I have a fix in the pipeline.

atk commented 2 years ago

Please check with version 0.2.0; aliases should now work.