Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent __moduleRoot__ prefix in importMap #64

Open
HolgerJeromin opened this issue Jan 23, 2025 · 4 comments · May be fixed by #65
Open

Inconsistent __moduleRoot__ prefix in importMap #64

HolgerJeromin opened this issue Jan 23, 2025 · 4 comments · May be fixed by #65

Comments

@HolgerJeromin
Copy link
Contributor

While working with module I found that often the module path get a prefix __moduleRoot__ but not always (yeah some/all are resulting from my #60 ).
This issue is, that the files are executed twice when loaded via both srcDir and import because of the different paths.

@sgravrock
May I ask why __moduleRoot__ was added?
I would have expected that module files from srcDir will get __src__ and modules from specFiles/helpers will get __spec__.

I could create a PR with such a change, but wanted to have your OK or your opinion on this.
As this is an internal implementation detail (the prefix is added into sourcemap, too) I do not see a compatibility issue.

@sgravrock
Copy link
Member

sgravrock commented Jan 24, 2025

As far as I know, __moduleRoot__ only comes into play when a module specifier appears in the configured import map. The original use case for import map support in jasmine-browser-runner was to load library code that lives outside the normal source directory, for example in node_modules.

My best guess from what you've told me is that you have modules in the src directory that are also listed in the import map. If that's the case, try removing them from the import map.

@HolgerJeromin
Copy link
Contributor Author

You are right. __moduleRoot__ is only used when "having an importmap".

I am importing with a id prefix (import { Control } from 'myPackageID/Controls.esm.js') because the path is not constant in all my scenarios. So I need to manipulate the path via an importMap in different runtime scenarios (and jasmine).

@sgravrock
Copy link
Member

Thanks for the clarification.

I would have expected that module files from srcDir will get src and modules from specFiles/helpers will get spec.

I could create a PR with such a change, but wanted to have your OK or your opinion on this.
As this is an internal implementation detail (the prefix is added into sourcemap, too) I do not see a compatibility issue.

I think that makes sense.

@HolgerJeromin HolgerJeromin changed the title Inconsistent __moduleRoot__ prefix Inconsistent __moduleRoot__ prefix in importMap Jan 29, 2025
@HolgerJeromin HolgerJeromin linked a pull request Jan 29, 2025 that will close this issue
@HolgerJeromin
Copy link
Contributor Author

The importMap property is provided by the user.
j-b-r does not know if it is meant to target files in srcDir or specDir.
We can not decide to 100% what folder is meant.

So my solution is to detect if a resulting path will be available in one of the path.
If it is not found it falls back to the existing __moduleRoot__. This can be projectBaseDir+moduleRootDir or projectBaseDir or current working directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants