Open
Conversation
shsteimer
reviewed
Feb 17, 2026
| expect(window.hlx.codeBasePath).to.be.equal('/some/path'); | ||
| // When setup.js is in /src/, codeBasePath will be empty or src path | ||
| // In production, aem.js is at /scripts/aem.js so split works correctly | ||
| expect(window.hlx.codeBasePath).to.exist; |
Contributor
There was a problem hiding this comment.
Sorry to be annoying, but I don't think there is much value in just asserting the value exists. The code could change in a way that breaks how the value is set, and the test wouldn't catch it.
If we want to test this logic, I'd probably change the signature of setup() to be setup(importUrl = import.meta.url) Then in the tests, we can pass different values to ensure window.hlx.codeBasePath is always set properly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Replaces the DOM query approach for detecting
codeBasePathwithimport.meta.url, simplifying the code and making it more reliable.Before:
<script src$="/scripts/scripts.js">srcattributeAfter:
import.meta.urldirectly from the ES moduleExample:
When
aem.jsis loaded from/scripts/aem.js:import.meta.url=http://example.com/scripts/aem.js/scripts/givescodeBasePath=''(root) or base pathRelated Issue
Closes #134
Motivation and Context
The original DOM query approach was a legacy from when aem.js and scripts.js were combined. With ES modules,
import.meta.urlprovides a more direct and reliable way to determine the module's location without needing to search the DOM.Benefits:
import.meta.urlis supported everywhere ES modules areHow Has This Been Tested?
Updated existing test in
test/setup/setup.test.html:codeBasePathexists rather than checking for specific path valueBrowser Support
import.meta.urlis supported in all browsers that support ES modules (95%+ coverage):Since this library already requires ES module support (
"type": "module"), there is no additional browser support loss.Types of changes
Checklist: