-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
[MAJOR] Expand relative imports in external maps #81
[MAJOR] Expand relative imports in external maps #81
Conversation
acf8be5
to
9ed3f66
Compare
package.json
Outdated
@@ -61,5 +61,6 @@ | |||
}, | |||
"dependencies": { | |||
"cookie": "^0.4.1" | |||
} | |||
}, | |||
"packageManager": "[email protected]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the pnpm-lock.yaml
file to a more recent version of pnpm. I suggest adding this line to make explicit which version of pnpm goes well with the existing lock file.
@@ -63,3 +63,6 @@ dist | |||
|
|||
# jetbrain IDE files | |||
/.idea | |||
|
|||
# VSCode IDE files | |||
.vscode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To prevent accidentally adding VSCode settings
return Promise.all([promise, nextPromise]).then( | ||
([originalMap, newMap]) => | ||
imo.mergeImportMap(originalMap, newMap) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prettier seems to be reformatting some lines...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot explain this change from prettier. I verified I am using the version of prettier pinned in the dependencies.
console.warn( | ||
Error(`Unable to download external import map at url '${url}'`) | ||
); | ||
imo.invalidExternalMaps.push(new URL(url, document.baseURI).href); | ||
return createEmptyImportMap(); | ||
} | ||
); | ||
) | ||
.then((importMap) => expandRelativeUrlsInImportMap(importMap, url)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the actual change
9ed3f66
to
609fd2c
Compare
package.json
Outdated
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "import-map-overrides", | |||
"version": "3.0.0", | |||
"version": "4.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is potentially a breaking change. What do you think @joeldenning?
609fd2c
to
23b1ed8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. Were you able to test it very much? I'm thinking this might not need to be a major/breaking change to import-map-overrides, since it only impacts how the URLs are displayed in the UI. Do you agree?
const outUrl = new URL(url, baseUrl); | ||
return outUrl.href; | ||
} catch (err) { | ||
return url; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is returning the relative url the correct thing to do when there is an error? The error would only happen if baseUrl
is wrong, right? I'm not sure what the best UX is for when the baseUrl is invalid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, me neither. I wasn't sure so I thought that returning the relative url would still be a reasonable thing to do. I am open to change it as you see fit, if there is a better way of handling this. I don't think this should ever happen, actually.
); | ||
imo.invalidExternalMaps.push(r.url); | ||
imo.invalidExternalMaps.push(new URL(url, document.baseURI).href); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 this is a good change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this line was already there (line 487 in the older version). It looks like a change because of the modifications from prettier. See this comment about it.
b07d322
to
e93d8ff
Compare
externalOverrideModules.push({ | ||
...mod, | ||
overrideUrl: this.state.currentPageMap.imports[moduleName], | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When including an external override the domain is displayed from the defaultMap, not from the overridden entry.
I tested it in the following scenarios:
In this second scenario, I realised there was still a problem with the visualisation of the domain, which I tried to fix here). As for the version change. This PR will change the way modified dev dependencies will be loaded. The import-map-overrides changes automatically the production version of some dependencies to the development counterpart. When it does that, the overridden dependencies are injected in an import map after all the ones already existing in the document. If those dependencies were specified with a relative path and they were set in an external import map, they were resolved based to the URL of the import map file and when the override happened, they would instead be resolved to the base URL of the index.html file. With this PR, they continue to be resolved w.r.t. the URL of the import map, which might change the behaviour for some existing instances. As you prefer, Joel, both major or patch are OK for me. |
@@ -10,6 +10,7 @@ | |||
"build": "pnpm run clean && cross-env NODE_ENV=production rollup -c", | |||
"build:dev": "pnpm run clean && cross-env NODE_ENV=development rollup -c", | |||
"clean": "rimraf dist", | |||
"check-format": "prettier --check src", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes issues #80.
In order to fix the issue, I propose expanding relative URLs in external maps when they are loaded. In this way those mappings:
This is potentially a breaking change so it would need a major release update.