feat: use netlify:import-map
specifier
#246
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.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).