@nullvoxpopuli/ember-vite 2.0.0 → 2.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nullvoxpopuli/ember-vite",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Meta plugin for ember projects focusing on speed.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -21,7 +21,7 @@
21
21
  "@embroider/core": "^4.6.9",
22
22
  "@embroider/macros": "^1.21.3",
23
23
  "@embroider/vite": "^1.7.15",
24
- "@nullvoxpopuli/ember-build-tooling-utils": "2.0.0"
24
+ "@nullvoxpopuli/ember-build-tooling-utils": "2.0.1"
25
25
  },
26
26
  "engines": {
27
27
  "node": ">= 24"
package/src/ember.test.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { extensions } from "@embroider/vite";
2
2
  import { interpreter, type TopLevelFilterExpression } from "@rolldown/pluginutils";
3
- import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
4
- import { join } from "node:path";
3
+ import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
4
+ import { dirname, join } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import type { ConfigEnv, ConfigPluginContext, Plugin } from "vite";
7
7
  import { afterEach, describe, expect, it } from "vitest";
@@ -153,6 +153,7 @@ function inProject(files: Record<string, string>) {
153
153
  const directory = mkdtempSync(join(cache, "project-"));
154
154
 
155
155
  for (const [name, content] of Object.entries(files)) {
156
+ mkdirSync(dirname(join(directory, name)), { recursive: true });
156
157
  writeFileSync(join(directory, name), content);
157
158
  }
158
159
 
@@ -265,12 +266,21 @@ describe("babel.parallel", () => {
265
266
  `});`,
266
267
  ].join("\n");
267
268
 
268
- async function compileWithConfigFile(options: Parameters<typeof ember>[0] = {}) {
269
- const directory = inProject({
270
- "package.json": `{ "type": "module" }`,
271
- "thread-plugin.js": THREAD_PLUGIN,
272
- "babel.config.js": `export default { plugins: ["./thread-plugin.js"] };`,
273
- });
269
+ async function compileWithConfigFile(
270
+ options: Parameters<typeof ember>[0] = {},
271
+ config = `export default { plugins: ["./thread-plugin.js"] };`,
272
+ files: Record<string, string> = {},
273
+ ) {
274
+ const directory = inProject(
275
+ Object.assign(
276
+ {
277
+ "package.json": `{ "type": "module" }`,
278
+ "thread-plugin.js": THREAD_PLUGIN,
279
+ "babel.config.js": config,
280
+ },
281
+ files,
282
+ ),
283
+ );
274
284
 
275
285
  const plugins = ember(options) as Plugin[];
276
286
  const babel = await startedBabel(plugins);
@@ -294,6 +304,43 @@ describe("babel.parallel", () => {
294
304
  expect(await compileWithConfigFile()).toContain("worker thread");
295
305
  });
296
306
 
307
+ /**
308
+ * `@warp-drive/build-config` before 5.9 finds its own folder with `typeof __dirname`,
309
+ * which Node sets to "." in an eval worker thread.
310
+ * See https://github.com/warp-drive-data/warp-drive/pull/10926.
311
+ */
312
+ function buildConfig(version: string) {
313
+ return {
314
+ "node_modules/@warp-drive/build-config/package.json": JSON.stringify({
315
+ name: "@warp-drive/build-config",
316
+ version,
317
+ type: "module",
318
+ exports: { ".": "./index.js" },
319
+ }),
320
+ "node_modules/@warp-drive/build-config/index.js": [
321
+ `if (typeof __dirname !== "undefined") throw new Error("__dirname is " + __dirname);`,
322
+ `export const setConfig = () => {};`,
323
+ ].join("\n"),
324
+ };
325
+ }
326
+
327
+ const CONFIG_WITH_WARP_DRIVE = [
328
+ `import "@warp-drive/build-config";`,
329
+ `export default { plugins: ["./thread-plugin.js"] };`,
330
+ ].join("\n");
331
+
332
+ it("gives @warp-drive/build-config before 5.9 no __dirname in a worker thread", async () => {
333
+ expect(await compileWithConfigFile({}, CONFIG_WITH_WARP_DRIVE, buildConfig("5.8.2"))).toContain(
334
+ "worker thread",
335
+ );
336
+ expect(existsSync("node_modules/.cache/nullvoxpopuli-babel")).toBe(true);
337
+ });
338
+
339
+ it("loads the config file directly without @warp-drive/build-config before 5.9", async () => {
340
+ expect(await compileWithConfigFile()).toContain("worker thread");
341
+ expect(existsSync("node_modules/.cache/nullvoxpopuli-babel")).toBe(false);
342
+ });
343
+
297
344
  it("runs babel in the main thread when parallel is false", async () => {
298
345
  expect(await compileWithConfigFile({ babel: { parallel: false } })).toContain("main thread");
299
346
  });
package/src/ember.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { buildMacros } from "@embroider/macros/babel";
2
2
  import { ember as embroiderEmber, extensions, resolver, templateTag } from "@embroider/vite";
3
+ import type { PluginItem } from "@babel/core";
3
4
  import { existsSync, readFileSync } from "node:fs";
4
5
  import { join, resolve } from "node:path";
5
6
  import type { ConfigEnv, ConfigPluginContext, ResolvedConfig, UserConfig } from "vite";
@@ -64,7 +65,7 @@ function absolutePath(relativePath: string) {
64
65
  * `buildMacros` reads NODE_ENV, but vite sets NODE_ENV
65
66
  * only after the config hooks run.
66
67
  */
67
- function defaultBabelPlugins(mode: string) {
68
+ function defaultBabelPlugins(mode: string): PluginItem[] {
68
69
  const macros = buildMacros({
69
70
  configure(config) {
70
71
  if (isDev(mode)) {