-
Notifications
You must be signed in to change notification settings - Fork 215
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
(fix) O3-3370: Properly handle relative imports in development #1258
Conversation
const importmap = JSON.parse(importMapDecl.value); | ||
const spaPathRegEx = new RegExp('^' + spaPath.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d')); |
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 hacky implementation of escaping regex metachars since RegExp.escape()
is only available in Node 22.
Size Change: -742 kB (-10.71%) 👏 Total Size: 6.18 MB
ℹ️ View Unchanged
|
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.
Thank you @ibacher! LGTM! I have a small question about one of the arguments that was removed
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.
LGTM. Thanks, @ibacher!
Indeed... It looks like somewhere things are getting transformed into http://dev3.openmrs.org//openmrs/spa/openmrs-esm-devtools-app-6.0.3-pre.2625/openmrs-esm-devtools-app.js. |
…rs#1258) * (fix) O3-3370: Properly handle relative imports in development * Fix doc strings
Requirements
feat
,fix
, orchore
, among others). See existing PR titles for inspiration.For changes to apps
If applicable
Summary
Follow-on for #1032. #1032 tried to add support for services like GitPod by converting URL references for JS files from fully-qualified names to relative names. However, it did this via string manipulation of the URL, which actually breaks things in the case when running against a local server (since the prefix replace of
http://localhost
with""
leads to broken URLs like:8081/openmrs-esm-login-app.js
, which fail to load).This PR reworks things so that we're actually doing something similar to a browser's origin check (i.e., confirming that we're using the same host, port, and protocol). If the URL for a JS file is on the same origin as the backend, we convert it to a relative URL and if it is not, we leave it as an absolute URL.
Basically what this means is that when running
yarn start
, most of the import map will be converted into local links like:But the app that's under development will remain as an absolute URL like this:
This should ensure that things work both in the case when connecting to a remote server via a reverse proxy and that it doesn't break things for local development.
Screenshots
Related Issue
Other