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

feat: use netlify:import-map specifier #246

Merged
merged 2 commits into from
Dec 9, 2022

Conversation

eduardoboucas
Copy link
Member

Which problem is this pull request solving?

In #235 we started writing the import map URL to the manifest. We were writing an actual import map file to disk, to the dist directory, and then building a virtual path relative to the repository root.

For example, the following project would yield a path of file:///root/.netlify/edge-functions-dist/import_map.json for the import map.

.netlify/
  edge-functions-dist/
    import_map.json
other-file

While this works great for projects with this structure, it doesn't work that well when the dist directory is not a child directory of the repository root, because we won't be able to encode a relative path into the file URL (e.g. something like file:///root/../../import_map.json is not valid).

What happens now in these situations is that we end up using an absolute path rather than a relative one, which has the problem of being a path that is specific to the machine that builds it — we can end up with things like file:///Users/johndoe/import_map in the ESZIP, and while that technically works, it's not something we want to do.

This PR changes things a bit so that we don't compute a relative path from the import map file to the repository root, and in fact we stop writing an import map file at all. We give the ESZIP loader a static specifier for the import map (netlify:import-map) and then map it to the contents of the import map.

The imports themselves are rewritten so that any relative paths have the repository root as the base, using the file:///root/ prefix. These relative paths we know we can always generate, because any file referenced by the import map should always be a child of the repository root (otherwise it can't be deployed).

@eduardoboucas eduardoboucas added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Dec 8, 2022
@eduardoboucas eduardoboucas requested a review from a team December 8, 2022 00:20
@eduardoboucas eduardoboucas merged commit 9f2a947 into main Dec 9, 2022
@eduardoboucas eduardoboucas deleted the feat/import-map-specifier branch December 9, 2022 10:27
Skn0tt pushed a commit to netlify/build that referenced this pull request Apr 23, 2024
* feat: use `netlify:import-map` specifier

* refactor: conditionally set import map URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants