Repository: ProjectEvergreen/greenwood (js)

Issue:
binary asset formats (e.g. png) are getting corrupted when bundled with `new URL` + `import.meta.url`
### What happened?

Noticed as part of debugging https://github.com/ProjectEvergreen/greenwood/discussions/1408#discussioncomment-12104620 that certain bundled asset were not loading correctly after running the `build` command.
![Image](https://github.com/user-attachments/assets/599eae73-a282-4f98-994f-72957f92d4a0)

### Steps to reproduce

1. Have a binary asset type (e.g. _.png_, _.svg_)
1. Reference it in a component using `new URL` + `import.meta.url`

```js
const template = document.createElement('template');

export default class HeaderComponent extends HTMLElement {
  #logo = new URL("../../assets/greenwood-logo.png", import.meta.url);

  connectedCallback() {
    if (!this.shadowRoot) {
      template.innerHTML = `
        <header class="header">
          <a href="/">
            <img src="${this.#logo.pathname.replace(window.location.pathname, "/")}" alt="Greenwood Logo"/>
            <h4>My Blog</h4>
          </a>
        </header>
      `;
      
      this.attachShadow({ mode: 'open' });
      this.shadowRoot.appendChild(template.content.cloneNode(true));
    }
  }
}

customElements.define('app-header', HeaderComponent);
```

Repro here - https://github.com/ProjectEvergreen/greenwood-getting-started/compare/1408-debug-new-url-import-meta?expand=1

### Environment

- Greenwood v0.31.0
- Node v22

### Additional Context

Looking at the generated output, it looks like the file is getting corrupted somehow, with starting source size of 7KB, and ending up as 12KB?
![Image](https://github.com/user-attachments/assets/939a2a32-fe40-4ed5-a211-be0ff787b397)

Plus VSCode can't open it
![Image](https://github.com/user-attachments/assets/cbaa7e9a-bf05-4892-bc0c-0a955fb5958a)

Pull request:
bug/issue 1409 do not force encoding when bundling / emitting static asset contents
<!--
## Submitting a Pull Request
We love contributions and appreciate any help you can offer!
-->

## Related Issue

resolves #1409 

## Documentation 

N / A

## Summary of Changes

1. Don't force encoding when reading static assets off of disk during bundling

![Screenshot 2025-02-08 at 3 13 06 PM](https://github.com/user-attachments/assets/f57b4522-57dd-4914-97d2-39e993615d98)

Patch:
diff --git a/packages/cli/src/config/rollup.config.js b/packages/cli/src/config/rollup.config.js
index bc309dcb..d82b221c 100644
--- a/packages/cli/src/config/rollup.config.js
+++ b/packages/cli/src/config/rollup.config.js
@@ -334,7 +334,7 @@ function greenwoodImportMetaUrl(compilation) {
         const { relativeAssetPath } = assetUrl;
         const assetName = path.basename(pathname);
         const assetExtension = assetName.split(".").pop();
-        const assetContents = await fs.promises.readFile(url, "utf-8");
+        const assetContents = await fs.promises.readFile(url);
         const name = assetName.replace(`.${assetExtension}`, "");
         const request = new Request(url, { headers: { Accept: "text/javascript" } });
         let bundleExtensions = ["js"];


Test patch:
diff --git a/packages/cli/test/cases/build.default.static-asset-bundling/build.default.static-asset-bundling.spec.js b/packages/cli/test/cases/build.default.static-asset-bundling/build.default.static-asset-bundling.spec.js
index df195533..c1b47620 100644
--- a/packages/cli/test/cases/build.default.static-asset-bundling/build.default.static-asset-bundling.spec.js
+++ b/packages/cli/test/cases/build.default.static-asset-bundling/build.default.static-asset-bundling.spec.js
@@ -63,7 +63,7 @@ describe("Build Greenwood With: ", function () {
       });
 
       it("should have the expected bundle path for the first static asset", function () {
-        const bundleName = "greenwood-logo.BBDNkm3l.png";
+        const bundleName = "greenwood-logo.DiicYFep.png";
 
         expect(headerContents).to.contain(bundleName);
       });