embroider-build / ember-auto-import

Zero config import from npm packages
Other
360 stars 109 forks source link

When `rootURL` is the relative path, chunks are being output as absolute path. #639

Open christophersansone opened 1 month ago

christophersansone commented 1 month ago

Hi there! We are upgrading ember-auto-import from 1.x to the latest, and hit a snag that appears to be a bug.

In config/environments.js, we have rootURL set to an empty string so that all assets are loaded relative to where index.html is. Our app runs in many different environments, so for the sake of portability, all paths are relative, and {{rootURL}} returns an empty string as expected.

The script tags for the vendor and application Javascript files are correct:

<script src="assets/vendor.js"></script>
<script src="assets/application.js"></script>

For the chunk script tags, the expected behavior is for the path to be similarly relative:

<script src="assets/chunk.123.js"></script>

However, the actual behavior is that the path is outputting as absolute:

<script src="/assets/chunk.123.js"></script>

Here where publicAssetURL is determined, an empty rootURL returns /. This is due to ensureTrailingSlash always appending a / to the end of the string, even an empty string. By doing so, what should be relative paths are being output as absolute paths, thus causing 404's.

To me, the optimal fix would be for ensureTrailingSlash to only append a slash to the URL if the URL is actually present.