Replies: 1 comment 3 replies
-
|
I'm confused - why not just take the actual project folder, run |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have mono repo with a structure very similar to this:
The CI system creates the zip files that are deployed on the AWS Lambda system and does so by taking the content of lambda folder and placing next to it the content of the Common folder renamed as node_modules.
This has worked since the beginning and when unit tests were added later on, it was decided to have as little changes to the existing code as possible.
Each .js file inside the test folder uses module-alias to trick the loader into looking at the Common folder as a valid source for the files required by the lambda code. This allows debugging the unit tests while being able to edit the common files "in place", greatly speeding up the development process.
Here is the code added at the top of each .js file in the test subfolders:
The second path alias is here because only the
package.jsonfiles in the test folders are defining thedevDependenciesto@awsmodules because they already are available in the target environment, and because the entry point is via tests only. This avoids cluttering the developer's machines with lots of duplicate folders.This works fairly well in CommonJS format but as we must modernize the code base, we are trying to move to ES6 syntax and "module" resolution with as little changes as possible.
One thing that is clear is that adding path aliases like before is no longer possible because imports are resolved long before any of our code is run. This has to be done via the
--importflag on the command line so that I can register a module hook which is what I tried with the following code, inspired byesm-module-alias:This is not exactly the same as the situation before because the
loader.mjsfile is loaded once at the start of the process called by the test runner (mocha) which means__dirnameis the one from that file, not the one for each test file.But even then, the retry appears to work as I see the console log, but sadly it still throws an error, but this time with a hint message:
It's like it has "seen" the folder but did not find the expected files for
ESmodules, which I find weird as they appear to be in thedist-esfolder.Am I on the right track here? Would you have any suggestions for this situation?
I looked at subpath imports (with the # prefix) but this does not work because it cannot look into parent folders for resolution.
Thanks for your time.
Beta Was this translation helpful? Give feedback.
All reactions