@nullvoxpopuli/ember-vite 1.1.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -75,7 +75,23 @@ function testHtml() {
75
75
  }
76
76
  //#endregion
77
77
  //#region src/ember.ts
78
- const emberConfig = ember$1()[3];
78
+ const EMBER_CONFIG = "vite-plugin-ember-config";
79
+ /**
80
+ * `@embroider/vite` does not export its config hook on its own.
81
+ *
82
+ * The position of the plugin in the list changes between releases,
83
+ * so the name is the only stable way to find it.
84
+ */
85
+ function findEmberConfig() {
86
+ for (const plugin of ember$1()) {
87
+ if (plugin.name !== EMBER_CONFIG) continue;
88
+ const hook = plugin.config;
89
+ const handler = typeof hook === "function" ? hook : hook?.handler;
90
+ if (handler) return handler;
91
+ }
92
+ throw new Error(`@embroider/vite has no "${EMBER_CONFIG}" plugin with a config hook. This version of @embroider/vite is not supported by @nullvoxpopuli/ember-vite.`);
93
+ }
94
+ const emberConfig = findEmberConfig();
79
95
  const cwd = process.cwd();
80
96
  function absolutePath(relativePath) {
81
97
  return join(cwd, relativePath);
@@ -156,7 +172,11 @@ function ember(nvpConfig = {}) {
156
172
  {
157
173
  name: "ember:nullvoxpopuli",
158
174
  async config(viteConfig, env) {
159
- await emberConfig.config(viteConfig, env);
175
+ /**
176
+ * The hook reads the rolldown version from the plugin context,
177
+ * and takes its esbuild path without it.
178
+ */
179
+ await emberConfig.call(this, viteConfig, env);
160
180
  viteConfig.experimental ||= {};
161
181
  viteConfig.build ||= {};
162
182
  viteConfig.optimizeDeps ||= {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nullvoxpopuli/ember-vite",
3
- "version": "1.1.1",
3
+ "version": "1.3.0",
4
4
  "description": "Meta plugin for ember projects focusing on speed.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -17,11 +17,11 @@
17
17
  "directory": "packages/vite"
18
18
  },
19
19
  "dependencies": {
20
- "@babel/core": "^7.28.10",
21
- "@embroider/core": "^4.4.2",
22
- "@embroider/macros": "^1.20.3",
23
- "@embroider/vite": "^1.5.0",
24
- "@nullvoxpopuli/ember-build-tooling-utils": "1.1.1"
20
+ "@babel/core": "^7.28.10 || ^8.0.0",
21
+ "@embroider/core": "^4.6.9",
22
+ "@embroider/macros": "^1.21.3",
23
+ "@embroider/vite": "^1.7.15",
24
+ "@nullvoxpopuli/ember-build-tooling-utils": "1.2.0"
25
25
  },
26
26
  "engines": {
27
27
  "node": ">= 24"
@@ -0,0 +1,38 @@
1
+ import { extensions } from "@embroider/vite";
2
+ import type { ConfigEnv, ConfigPluginContext } from "vite";
3
+ import { describe, expect, it } from "vitest";
4
+
5
+ import { ember } from "./ember.ts";
6
+
7
+ const ROLLDOWN = { meta: { rolldownVersion: "1.0.0" } } as ConfigPluginContext;
8
+
9
+ async function configure(env: ConfigEnv) {
10
+ const config: any = {};
11
+ const [plugin] = ember();
12
+
13
+ // @ts-expect-error the first entry is the config plugin
14
+ await plugin.config.call(ROLLDOWN, config, env);
15
+
16
+ return config;
17
+ }
18
+
19
+ describe("ember", () => {
20
+ /**
21
+ * These values come from the config hook of `@embroider/vite`.
22
+ * They are missing when that hook does not run.
23
+ */
24
+ it("applies the config from @embroider/vite", async () => {
25
+ const config = await configure({ command: "build", mode: "production" });
26
+
27
+ expect(config.resolve.extensions).toEqual(extensions);
28
+ expect(config.server.port).toBe(4200);
29
+ expect(config.optimizeDeps.exclude).toContain("@embroider/macros");
30
+ });
31
+
32
+ it("gives @embroider/vite the plugin context, so that it configures rolldown", async () => {
33
+ const config = await configure({ command: "build", mode: "production" });
34
+
35
+ expect(config.build.rolldownOptions.moduleTypes).toEqual({ ".ts": "js" });
36
+ expect(config.optimizeDeps.rolldownOptions.resolve.extensions).toEqual(extensions);
37
+ });
38
+ });
package/src/ember.ts CHANGED
@@ -2,13 +2,43 @@ import { buildMacros } from "@embroider/macros/babel";
2
2
  import { ember as embroiderEmber, extensions, resolver, templateTag } from "@embroider/vite";
3
3
  import { existsSync } from "node:fs";
4
4
  import { join, resolve } from "node:path";
5
- import type { ConfigEnv, ResolvedConfig } from "vite";
5
+ import type { ConfigEnv, ConfigPluginContext, ResolvedConfig, UserConfig } from "vite";
6
6
 
7
7
  import { maybeBabel } from "@nullvoxpopuli/ember-build-tooling-utils";
8
8
 
9
9
  import { testHtml } from "./test-html.ts";
10
10
 
11
- const emberConfig = embroiderEmber()[3]!;
11
+ const EMBER_CONFIG = "vite-plugin-ember-config";
12
+
13
+ type ConfigHook = (
14
+ this: ConfigPluginContext,
15
+ config: UserConfig,
16
+ env: ConfigEnv,
17
+ ) => Promise<unknown> | unknown;
18
+
19
+ /**
20
+ * `@embroider/vite` does not export its config hook on its own.
21
+ *
22
+ * The position of the plugin in the list changes between releases,
23
+ * so the name is the only stable way to find it.
24
+ */
25
+ function findEmberConfig(): ConfigHook {
26
+ for (const plugin of embroiderEmber()) {
27
+ if (plugin.name !== EMBER_CONFIG) continue;
28
+
29
+ const hook = plugin.config;
30
+ const handler = typeof hook === "function" ? hook : hook?.handler;
31
+
32
+ if (handler) return handler as ConfigHook;
33
+ }
34
+
35
+ throw new Error(
36
+ `@embroider/vite has no "${EMBER_CONFIG}" plugin with a config hook. ` +
37
+ `This version of @embroider/vite is not supported by @nullvoxpopuli/ember-vite.`,
38
+ );
39
+ }
40
+
41
+ const emberConfig = findEmberConfig();
12
42
 
13
43
  const cwd = process.cwd();
14
44
  function absolutePath(relativePath: string) {
@@ -173,9 +203,12 @@ export function ember(nvpConfig: Config = {}) {
173
203
  {
174
204
  // no compat
175
205
  name: "ember:nullvoxpopuli",
176
- async config(viteConfig: any, env: ConfigEnv) {
177
- // @ts-expect-error it exists
178
- await emberConfig.config(viteConfig, env);
206
+ async config(this: ConfigPluginContext, viteConfig: any, env: ConfigEnv) {
207
+ /**
208
+ * The hook reads the rolldown version from the plugin context,
209
+ * and takes its esbuild path without it.
210
+ */
211
+ await emberConfig.call(this, viteConfig, env);
179
212
 
180
213
  viteConfig.experimental ||= {};
181
214
  viteConfig.build ||= {};