From 489852039a848f8e59cbbfa415d81cd3a7fbafa1 Mon Sep 17 00:00:00 2001
From: Chris Manson <chris@manson.ie>
Date: Sat, 7 Sep 2024 10:03:17 +0100
Subject: [PATCH] update to work without app rewriting

---
 files-override/.gitignore         |  3 ---
 files-override/ember-cli-build.js |  8 +-------
 files-override/testem.js          | 25 +++++++++++++++++++++++++
 files-override/tests/index.html   |  1 -
 files/vite.config.mjs             | 14 +++-----------
 index.js                          | 10 ++++++++++
 6 files changed, 39 insertions(+), 22 deletions(-)
 create mode 100644 files-override/testem.js

diff --git a/files-override/.gitignore b/files-override/.gitignore
index 49922f1..b034d62 100644
--- a/files-override/.gitignore
+++ b/files-override/.gitignore
@@ -24,6 +24,3 @@
 
 # broccoli-debug
 /DEBUG/
-
-# temporary until https://github.com/embroider-build/embroider/issues/2020 is merged
-/tmp/
diff --git a/files-override/ember-cli-build.js b/files-override/ember-cli-build.js
index ab01aed..ebb76e5 100644
--- a/files-override/ember-cli-build.js
+++ b/files-override/ember-cli-build.js
@@ -6,11 +6,5 @@ const { maybeEmbroider } = require('@embroider/test-setup');
 module.exports = function (defaults) {
   let app = new EmberApp(defaults, {});
 
-  return maybeEmbroider(app, {
-    skipBabel: [
-      {
-        package: 'qunit',
-      },
-    ],
-  });
+  return maybeEmbroider(app);
 };
diff --git a/files-override/testem.js b/files-override/testem.js
new file mode 100644
index 0000000..b4b6691
--- /dev/null
+++ b/files-override/testem.js
@@ -0,0 +1,25 @@
+'use strict';
+
+if (typeof module !== 'undefined') {
+  module.exports = {
+    test_page: 'tests/index.html?hidepassed',
+    disable_watching: true,
+    launch_in_ci: ['Chrome'],
+    launch_in_dev: ['Chrome'],
+    browser_start_timeout: 120,
+    browser_args: {
+      Chrome: {
+        ci: [
+          // --no-sandbox is needed when running Chrome inside a container
+          process.env.CI ? '--no-sandbox' : null,
+          '--headless',
+          '--disable-dev-shm-usage',
+          '--disable-software-rasterizer',
+          '--mute-audio',
+          '--remote-debugging-port=0',
+          '--window-size=1440,900',
+        ].filter(Boolean),
+      },
+    },
+  };
+}
diff --git a/files-override/tests/index.html b/files-override/tests/index.html
index 860a56c..f28b7c5 100644
--- a/files-override/tests/index.html
+++ b/files-override/tests/index.html
@@ -27,7 +27,6 @@
     <script src="/testem.js" integrity="" data-embroider-ignore></script>
     <script src="/@embroider/core/vendor.js"></script>
     <script src="/@embroider/core/test-support.js"></script>
-    <script src="/@embroider/core/entrypoint" type="module"></script>
     <script type="module">import "ember-testing";</script>
 
     <script type="module">
diff --git a/files/vite.config.mjs b/files/vite.config.mjs
index c2eff23..3d37d0d 100644
--- a/files/vite.config.mjs
+++ b/files/vite.config.mjs
@@ -9,10 +9,8 @@ import {
   assets,
   contentFor,
 } from '@embroider/vite';
-import { resolve } from 'path';
 import { babel } from '@rollup/plugin-babel';
 
-const root = 'tmp/rewritten-app';
 const extensions = [
   '.mjs',
   '.gjs',
@@ -26,8 +24,6 @@ const extensions = [
 
 export default defineConfig(({ mode }) => {
   return {
-    root,
-    cacheDir: resolve('node_modules', '.vite'),
     resolve: {
       extensions,
     },
@@ -46,20 +42,16 @@ export default defineConfig(({ mode }) => {
       }),
     ],
     optimizeDeps: optimizeDeps(),
-    publicDir: resolve(process.cwd(), 'public'),
     server: {
       port: 4200,
-      watch: {
-        ignored: ['!**/tmp/rewritten-app/**'],
-      },
     },
     build: {
-      outDir: resolve(process.cwd(), 'dist'),
+      outDir: 'dist',
       rollupOptions: {
         input: {
-          main: resolve(root, 'index.html'),
+          main: 'index.html',
           ...(shouldBuildTests(mode)
-            ? { tests: resolve(root, 'tests/index.html') }
+            ? { tests: 'tests/index.html' }
             : undefined),
         },
       },
diff --git a/index.js b/index.js
index 3efb720..e1d2f14 100644
--- a/index.js
+++ b/index.js
@@ -82,6 +82,16 @@ module.exports = {
       'test:ember': 'vite build --mode test && ember test --path dist',
     };
 
+    json['ember-addon'] = {
+      type: 'app',
+      version: 2,
+    };
+
+    json.exports = {
+      './tests/*': './tests/*',
+      './*': './app/*',
+    };
+
     fs.writeFileSync(packageJson, JSON.stringify(json, null, 2));
 
     await emberCliUpdate({