solid-register icon indicating copy to clipboard operation
solid-register copied to clipboard

Handle imports relative to project root

Open theSherwood opened this issue 3 years ago • 4 comments

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?

theSherwood avatar Jan 28 '22 05:01 theSherwood

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.

atk avatar Jan 28 '22 09:01 atk

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

theSherwood avatar Jan 28 '22 16:01 theSherwood

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 avatar Apr 01 '22 08:04 atk

Please check with version 0.2.0; aliases should now work.

atk avatar Apr 03 '22 21:04 atk