ember.nvp 1.3.0 → 1.5.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.
Files changed (34) hide show
  1. package/.release-plan.json +8 -14
  2. package/CHANGELOG.md +57 -0
  3. package/package.json +1 -1
  4. package/packages/rolldown/README.md +62 -3
  5. package/packages/rolldown/index.ts +2 -3
  6. package/packages/rolldown/package.json +12 -5
  7. package/packages/rolldown/src/app-reexports.ts +2 -2
  8. package/packages/rolldown/src/babel.test.ts +125 -2
  9. package/packages/rolldown/src/babel.ts +52 -7
  10. package/packages/rolldown/src/isolated-declarations.ts +28 -3
  11. package/packages/rolldown/src/plugin-like.ts +23 -0
  12. package/packages/rolldown/src/published-types.test.ts +102 -0
  13. package/packages/rolldown/src/transform.test.ts +50 -2
  14. package/packages/rolldown/src/transform.ts +8 -1
  15. package/packages/rolldown/tsdown.config.ts +11 -0
  16. package/src/bases/minimal-app/app.test.ts +102 -1
  17. package/src/bases/minimal-app/files/app/app.ts +1 -1
  18. package/src/bases/minimal-app/files/babel.config.js +17 -1
  19. package/src/bases/minimal-app/files/package.json +2 -2
  20. package/src/bases/minimal-extension/files/app/app.ts +1 -1
  21. package/src/bases/minimal-extension/files/babel.config.js +17 -1
  22. package/src/bases/minimal-extension/files/package.json +2 -2
  23. package/src/bases/minimal-library/files/package.json +1 -1
  24. package/src/layers/qunit/index.js +0 -1
  25. package/src/layers/qunit/library-files/tests/test-helper.ts +1 -1
  26. package/src/layers/readme/index.js +16 -16
  27. package/src/utils/babel.js +20 -2
  28. package/test/ember.nvp/inspector-support.test.ts +13 -13
  29. package/test/ember.nvp/layer-inspector-support.test.ts +1 -1
  30. package/test/ember.nvp/layer-readme.test.ts +16 -16
  31. package/test/ember.nvp/layer-vitest.test.ts +1 -1
  32. package/test/ember.nvp/publish-configs.test.ts +352 -0
  33. package/packages/rolldown/rolldown.config.js +0 -23
  34. package/packages/rolldown/src/isolated-declarations.test.ts +0 -122
@@ -2,13 +2,17 @@
2
2
  "solution": {
3
3
  "ember.nvp": {
4
4
  "impact": "minor",
5
- "oldVersion": "1.2.0",
6
- "newVersion": "1.3.0",
5
+ "oldVersion": "1.4.0",
6
+ "newVersion": "1.5.0",
7
7
  "tagName": "latest",
8
8
  "constraints": [
9
9
  {
10
10
  "impact": "minor",
11
11
  "reason": "Appears in changelog section :rocket: Enhancement"
12
+ },
13
+ {
14
+ "impact": "patch",
15
+ "reason": "Appears in changelog section :bug: Bug Fix"
12
16
  }
13
17
  ],
14
18
  "pkgJSONPath": "./package.json"
@@ -17,21 +21,11 @@
17
21
  "oldVersion": "1.1.0"
18
22
  },
19
23
  "@nullvoxpopuli/ember-rolldown": {
20
- "impact": "minor",
21
- "oldVersion": "2.4.0",
22
- "newVersion": "2.5.0",
23
- "tagName": "latest",
24
- "constraints": [
25
- {
26
- "impact": "minor",
27
- "reason": "Appears in changelog section :rocket: Enhancement"
28
- }
29
- ],
30
- "pkgJSONPath": "./packages/rolldown/package.json"
24
+ "oldVersion": "2.7.0"
31
25
  },
32
26
  "@nullvoxpopuli/ember-vite": {
33
27
  "oldVersion": "1.1.0"
34
28
  }
35
29
  },
36
- "description": "## Release (2026-08-03)\n\n* ember.nvp 1.3.0 (minor)\n* @nullvoxpopuli/ember-rolldown 2.5.0 (minor)\n\n#### :rocket: Enhancement\n* `ember.nvp`\n * [#106](https://github.com/NullVoxPopuli/ember.nvp/pull/106) README layer ([@tcjr](https://github.com/tcjr))\n* `@nullvoxpopuli/ember-rolldown`\n * [#107](https://github.com/NullVoxPopuli/ember.nvp/pull/107) rolldown: check the tsconfig the build uses, not always tsconfig.json ([@NullVoxPopuli](https://github.com/NullVoxPopuli))\n\n#### Committers: 2\n- Tom Carter ([@tcjr](https://github.com/tcjr))\n- [@NullVoxPopuli](https://github.com/NullVoxPopuli)\n"
30
+ "description": "## Release (2026-08-18)\n\n* ember.nvp 1.5.0 (minor)\n\n#### :rocket: Enhancement\n* `ember.nvp`\n * [#125](https://github.com/NullVoxPopuli/ember.nvp/pull/125) Update to 7.2, drop ember-strict-application-resolver polyfill ([@NullVoxPopuli](https://github.com/NullVoxPopuli))\n\n#### :bug: Bug Fix\n* `ember.nvp`\n * [#121](https://github.com/NullVoxPopuli/ember.nvp/pull/121) Fix initial README formatting ([@tcjr](https://github.com/tcjr))\n * [#122](https://github.com/NullVoxPopuli/ember.nvp/pull/122) Strip debug code from production app builds ([@NullVoxPopuli](https://github.com/NullVoxPopuli))\n\n#### Committers: 2\n- Tom Carter ([@tcjr](https://github.com/tcjr))\n- [@NullVoxPopuli](https://github.com/NullVoxPopuli)\n"
37
31
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,62 @@
1
1
  # Changelog
2
2
 
3
+ ## Release (2026-08-18)
4
+
5
+ * ember.nvp 1.5.0 (minor)
6
+
7
+ #### :rocket: Enhancement
8
+ * `ember.nvp`
9
+ * [#125](https://github.com/NullVoxPopuli/ember.nvp/pull/125) Update to 7.2, drop ember-strict-application-resolver polyfill ([@NullVoxPopuli](https://github.com/NullVoxPopuli))
10
+
11
+ #### :bug: Bug Fix
12
+ * `ember.nvp`
13
+ * [#121](https://github.com/NullVoxPopuli/ember.nvp/pull/121) Fix initial README formatting ([@tcjr](https://github.com/tcjr))
14
+ * [#122](https://github.com/NullVoxPopuli/ember.nvp/pull/122) Strip debug code from production app builds ([@NullVoxPopuli](https://github.com/NullVoxPopuli))
15
+
16
+ #### Committers: 2
17
+ - Tom Carter ([@tcjr](https://github.com/tcjr))
18
+ - [@NullVoxPopuli](https://github.com/NullVoxPopuli)
19
+
20
+ ## Release (2026-08-07)
21
+
22
+ * @nullvoxpopuli/ember-rolldown 2.7.0 (minor)
23
+
24
+ #### :rocket: Enhancement
25
+ * `@nullvoxpopuli/ember-rolldown`
26
+ * [#118](https://github.com/NullVoxPopuli/ember.nvp/pull/118) rolldown: ship type declarations ([@NullVoxPopuli](https://github.com/NullVoxPopuli))
27
+
28
+ #### Committers: 1
29
+ - [@NullVoxPopuli](https://github.com/NullVoxPopuli)
30
+
31
+ ## Release (2026-08-05)
32
+
33
+ * @nullvoxpopuli/ember-rolldown 2.6.1 (patch)
34
+
35
+ #### :bug: Bug Fix
36
+ * `@nullvoxpopuli/ember-rolldown`
37
+ * [#115](https://github.com/NullVoxPopuli/ember.nvp/pull/115) rolldown: don't resolve absolute specifiers against the importer's directory ([@NullVoxPopuli](https://github.com/NullVoxPopuli))
38
+
39
+ #### Committers: 1
40
+ - [@NullVoxPopuli](https://github.com/NullVoxPopuli)
41
+
42
+ ## Release (2026-08-03)
43
+
44
+ * ember.nvp 1.4.0 (minor)
45
+ * @nullvoxpopuli/ember-rolldown 2.6.0 (minor)
46
+
47
+ #### :rocket: Enhancement
48
+ * `@nullvoxpopuli/ember-rolldown`, `ember.nvp`
49
+ * [#111](https://github.com/NullVoxPopuli/ember.nvp/pull/111) rolldown: find publish configs in config/ too ([@NullVoxPopuli](https://github.com/NullVoxPopuli))
50
+ * `@nullvoxpopuli/ember-rolldown`
51
+ * [#109](https://github.com/NullVoxPopuli/ember.nvp/pull/109) rolldown: prefer babel.publish.config over babel.config ([@NullVoxPopuli](https://github.com/NullVoxPopuli))
52
+
53
+ #### :house: Internal
54
+ * `@nullvoxpopuli/ember-rolldown`, `ember.nvp`
55
+ * [#112](https://github.com/NullVoxPopuli/ember.nvp/pull/112) rolldown: test the isolated-declarations guard through generated libraries ([@NullVoxPopuli](https://github.com/NullVoxPopuli))
56
+
57
+ #### Committers: 1
58
+ - [@NullVoxPopuli](https://github.com/NullVoxPopuli)
59
+
3
60
  ## Release (2026-08-03)
4
61
 
5
62
  * ember.nvp 1.3.0 (minor)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember.nvp",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "ember project generator, alternative to the official blueprints, but more modern -- hopefully one day to upstream back in to ember-cli / official blueprints",
5
5
  "repository": {
6
6
  "type": "git",
@@ -53,10 +53,12 @@ export default defineConfig({
53
53
  });
54
54
  ```
55
55
 
56
- A `babel.config.js` is optional. Without one, `ember()` compiles templates
56
+ A babel config is optional. Without one, `ember()` compiles templates
57
57
  (to `precompileTemplate`), decorators (via
58
58
  [decorator-transforms](https://github.com/ef4/decorator-transforms)), and
59
- TypeScript; with one, your config runs instead.
59
+ TypeScript; with one, your config runs instead. A `babel.publish.config.*` is
60
+ preferred over a `babel.config.*` — see
61
+ [Publish vs. development babel config](#publish-vs-development-babel-config).
60
62
 
61
63
  ### Entrypoints
62
64
 
@@ -124,6 +126,21 @@ export default defineConfig({
124
126
  });
125
127
  ```
126
128
 
129
+ Any path works, so the publish config can live wherever you keep build
130
+ configuration — `tsconfig: "./config/tsconfig.publish.json"`. (A directory works
131
+ too: `tsconfig: "./config"` picks up `config/tsconfig.json`.)
132
+
133
+ `tsconfig: false` is rejected while declarations are on: with no tsconfig there
134
+ is no `isolatedDeclarations`, and the fallback pipeline can't see compiled
135
+ `.gts`, so it would fail later with "Source file not found". Set `dts: false`
136
+ alongside it if the library ships no types.
137
+
138
+ A tsconfig's relative paths resolve against the file itself, so a config kept in
139
+ `config/` wants `"include": ["../src/**/*"]` and `"rootDir": "../src"`. The build
140
+ won't tell you if you get that wrong — tsdown drives declaration emit from
141
+ `entry`, not from the tsconfig's `include` — but `tsc`/`ember-tsc` and your
142
+ editor will, if you ever point them at that config.
143
+
127
144
  The tradeoff: isolated-declaration errors in `src` then surface when you build
128
145
  rather than in your editor, since the editor uses `tsconfig.json`. Run the build
129
146
  (or `tsc --noEmit -p tsconfig.publish.json`) in CI so nothing lands unchecked.
@@ -198,7 +215,9 @@ it.
198
215
  `.gts` specifiers in emitted `.d.ts` files.
199
216
  - **`emberBabel()`** — runs babel with `babelHelpers: "bundled"`, but only on
200
217
  the files that actually need it (template-tag, decorators, template imports);
201
- everything else stays on rolldown's fast native (oxc) transform.
218
+ everything else stays on rolldown's fast native (oxc) transform. Uses your
219
+ `babel.publish.config.*` (root or `config/`) in preference to your
220
+ `babel.config.*`.
202
221
 
203
222
  ## Configuration
204
223
 
@@ -220,6 +239,46 @@ combined with a babel config file — a config lists
220
239
  `babel-plugin-ember-template-compilation` itself, so its transforms belong
221
240
  there.
222
241
 
242
+ ### Publish vs. development babel config
243
+
244
+ A library's plain `babel.config.*` is usually its _development_ config: it
245
+ compiles `@embroider/macros` away, targets the wire format, and wires up
246
+ whatever the in-package demo app or test suite needs. None of that belongs in a
247
+ published artifact — macros must survive for the consuming app to evaluate, and
248
+ the wire format is private between one template compiler and one glimmer
249
+ runtime of the same version.
250
+
251
+ Babel's own resolution can't tell those apart, so `ember()` looks for a config
252
+ named for publishing first. With no explicit `configFile`, detection is:
253
+
254
+ 1. `babel.publish.config.{mjs,cjs,js,mts,cts,ts,json}` in the package root
255
+ 2. the same names in `config/`
256
+ 3. otherwise babel's own resolution (`babel.config.*`, honoring `rootMode`)
257
+ 4. otherwise no config file — templates, decorators and TypeScript are still
258
+ handled by the built-in defaults
259
+
260
+ So a library that keeps both configs needs no `babel` option at all:
261
+
262
+ ```
263
+ my-addon/
264
+ babel.config.mjs # dev: macros compiled, wire format, test-app wiring
265
+ babel.publish.config.mjs # what ember() uses
266
+ ```
267
+
268
+ ...and so does one that keeps build configuration out of its root:
269
+
270
+ ```
271
+ my-addon/
272
+ babel.config.mjs
273
+ config/
274
+ babel.publish.config.mjs # what ember() uses
275
+ tsconfig.publish.json # see below
276
+ ```
277
+
278
+ Set `configFile` explicitly to override that (`configFile: false` ignores config
279
+ files entirely, which is what you want when your publish config would just
280
+ restate the built-in defaults).
281
+
223
282
  ## App re-exports
224
283
 
225
284
  For libraries whose modules must appear in the consuming app's namespace
@@ -1,10 +1,9 @@
1
- import type { Plugin } from "rolldown";
2
-
3
1
  import { emberBabel, type BabelOptions } from "./src/babel.ts";
4
2
  import { emberConfig } from "./src/config.ts";
5
3
  import { emberExternals } from "./src/externals.ts";
6
4
  import { emberIsolatedDeclarations } from "./src/isolated-declarations.ts";
7
5
  import { emberTransform } from "./src/transform.ts";
6
+ import type { RolldownPluginLike } from "./src/plugin-like.ts";
8
7
 
9
8
  interface Config {
10
9
  /**
@@ -49,7 +48,7 @@ interface Config {
49
48
  * });
50
49
  * ```
51
50
  */
52
- export function ember(config: Config = {}): Plugin[] {
51
+ export function ember(config: Config = {}): RolldownPluginLike[] {
53
52
  return [
54
53
  emberConfig(),
55
54
  emberIsolatedDeclarations(),
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nullvoxpopuli/ember-rolldown",
3
- "version": "2.5.0",
3
+ "version": "2.7.0",
4
4
  "description": "Meta plugin for building ember v2 libraries/addons with rolldown & tsdown.",
5
5
  "type": "module",
6
6
  "main": "index.ts",
@@ -11,9 +11,16 @@
11
11
  "publishConfig": {
12
12
  "main": "dist/index.js",
13
13
  "exports": {
14
- ".": "./dist/index.js",
15
- "./app-reexports": "./dist/app-reexports.js"
16
- }
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ },
18
+ "./app-reexports": {
19
+ "types": "./dist/app-reexports.d.ts",
20
+ "default": "./dist/app-reexports.js"
21
+ }
22
+ },
23
+ "types": "dist/index.d.ts"
17
24
  },
18
25
  "keywords": [
19
26
  "rolldown",
@@ -31,7 +38,7 @@
31
38
  "directory": "packages/rolldown"
32
39
  },
33
40
  "scripts": {
34
- "build": "rolldown --config",
41
+ "build": "tsdown",
35
42
  "prepack": "pnpm build"
36
43
  },
37
44
  "packageManager": "pnpm@10.28.0",
@@ -1,7 +1,7 @@
1
1
  import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
2
  import { dirname, extname, join, matchesGlob, relative, resolve, sep } from "node:path";
3
3
 
4
- import type { Plugin } from "rolldown";
4
+ import type { RolldownPluginLike } from "./plugin-like.ts";
5
5
 
6
6
  export interface AppReexportsOptions {
7
7
  /**
@@ -79,7 +79,7 @@ export interface AppReexportsOptions {
79
79
  export function appReexports(
80
80
  includeOrOptions: string | string[] | AppReexportsOptions = {},
81
81
  options: Omit<AppReexportsOptions, "include"> = {},
82
- ): Plugin {
82
+ ): RolldownPluginLike {
83
83
  const resolved =
84
84
  typeof includeOrOptions === "string"
85
85
  ? { ...options, include: [includeOrOptions] }
@@ -1,6 +1,85 @@
1
- import { describe, expect, it } from "vitest";
1
+ import { mkdtemp, mkdir, writeFile } from "node:fs/promises";
2
+ import { tmpdir } from "node:os";
3
+ import path from "node:path";
4
+ import { rolldown } from "rolldown";
5
+ import { afterEach, describe, expect, it } from "vitest";
2
6
 
3
- import { emberBabel } from "./babel.ts";
7
+ import { emberBabel, type BabelOptions } from "./babel.ts";
8
+ import { emberTransform } from "./transform.ts";
9
+
10
+ let restoreCwd: (() => void) | undefined;
11
+
12
+ afterEach(() => {
13
+ restoreCwd?.();
14
+ restoreCwd = undefined;
15
+ });
16
+
17
+ /**
18
+ * A babel config whose only plugin rewrites the string `"MARKER"` to `name`, so
19
+ * the emitted code says which config file babel actually loaded.
20
+ */
21
+ function markerConfig(name: string): string {
22
+ return [
23
+ `export default {`,
24
+ ` plugins: [`,
25
+ ` function marker() {`,
26
+ ` return {`,
27
+ ` visitor: {`,
28
+ ` StringLiteral(path) {`,
29
+ ` if (path.node.value === 'MARKER') path.node.value = '${name}';`,
30
+ ` },`,
31
+ ` },`,
32
+ ` };`,
33
+ ` },`,
34
+ ` ],`,
35
+ `};`,
36
+ ].join("\n");
37
+ }
38
+
39
+ /**
40
+ * Builds a `.gts` entry (so babel actually runs -- `maybeBabel` skips files that
41
+ * need no transform) in a temp dir that becomes the cwd, the way config
42
+ * detection sees it under the tsdown CLI. Returns the emitted code.
43
+ */
44
+ async function bundleWithBabel(
45
+ files: Record<string, string>,
46
+ options?: BabelOptions,
47
+ ): Promise<string> {
48
+ const dir = await mkdtemp(path.join(tmpdir(), "ember-rolldown-babel-"));
49
+
50
+ const withDefaults: Record<string, string> = {
51
+ "package.json": JSON.stringify({ name: "fixture", version: "0.0.0", type: "module" }),
52
+ "index.gts": [
53
+ `export const marker = 'MARKER';`,
54
+ `export default <template>hi</template>;`,
55
+ ].join("\n"),
56
+ ...files,
57
+ };
58
+
59
+ for (const [relative, source] of Object.entries(withDefaults)) {
60
+ const full = path.join(dir, relative);
61
+ await mkdir(path.dirname(full), { recursive: true });
62
+ await writeFile(full, source, "utf8");
63
+ }
64
+
65
+ const previousCwd = process.cwd();
66
+ process.chdir(dir);
67
+ restoreCwd = () => process.chdir(previousCwd);
68
+
69
+ const build = await rolldown({
70
+ input: [path.join(dir, "index.gts")],
71
+ plugins: [emberTransform(), emberBabel(options)],
72
+ external: (id) => !(id.startsWith(".") || path.isAbsolute(id)),
73
+ onwarn() {},
74
+ });
75
+
76
+ const { output } = await build.generate({ format: "es" });
77
+
78
+ return output
79
+ .filter((chunk): chunk is typeof chunk & { code: string } => "code" in chunk)
80
+ .map((chunk) => chunk.code)
81
+ .join("\n");
82
+ }
4
83
 
5
84
  describe("emberBabel", () => {
6
85
  it("rejects templateTransforms combined with a config file", () => {
@@ -14,4 +93,48 @@ describe("emberBabel", () => {
14
93
  emberBabel({ configFile: false, templateTransforms: ["some-transform"] }),
15
94
  ).not.toThrow();
16
95
  });
96
+
97
+ describe("config detection", () => {
98
+ it("prefers babel.publish.config over babel.config", async () => {
99
+ const code = await bundleWithBabel({
100
+ "babel.config.mjs": markerConfig("dev"),
101
+ "babel.publish.config.mjs": markerConfig("publish"),
102
+ });
103
+
104
+ expect(code).toContain(`"publish"`);
105
+ expect(code).not.toContain(`"dev"`);
106
+ });
107
+
108
+ it("falls back to babel.config when there is no publish config", async () => {
109
+ const code = await bundleWithBabel({ "babel.config.mjs": markerConfig("dev") });
110
+
111
+ expect(code).toContain(`"dev"`);
112
+ });
113
+
114
+ it("uses an explicit configFile over either", async () => {
115
+ const code = await bundleWithBabel(
116
+ {
117
+ "babel.config.mjs": markerConfig("dev"),
118
+ "babel.publish.config.mjs": markerConfig("publish"),
119
+ "babel.explicit.config.mjs": markerConfig("explicit"),
120
+ },
121
+ { configFile: "./babel.explicit.config.mjs" },
122
+ );
123
+
124
+ expect(code).toContain(`"explicit"`);
125
+ expect(code).not.toContain(`"publish"`);
126
+ });
127
+
128
+ it("ignores every config file when configFile is false", async () => {
129
+ const code = await bundleWithBabel(
130
+ {
131
+ "babel.config.mjs": markerConfig("dev"),
132
+ "babel.publish.config.mjs": markerConfig("publish"),
133
+ },
134
+ { configFile: false },
135
+ );
136
+
137
+ expect(code).toContain(`"MARKER"`);
138
+ });
139
+ });
17
140
  });
@@ -3,6 +3,8 @@ import transformTypeScript from "@babel/plugin-transform-typescript";
3
3
  import templateCompilation from "babel-plugin-ember-template-compilation";
4
4
  import decoratorTransforms from "decorator-transforms";
5
5
  import { loadPartialConfigSync } from "@babel/core";
6
+ import { existsSync } from "node:fs";
7
+ import { resolve } from "node:path";
6
8
  import type { PluginItem } from "@babel/core";
7
9
  import type { Transform } from "babel-plugin-ember-template-compilation";
8
10
  import type { Plugin } from "rolldown";
@@ -12,8 +14,9 @@ export interface BabelOptions {
12
14
  /**
13
15
  * The babel config file to use.
14
16
  *
15
- * - `undefined`: auto-detect the project's babel config (via babel's own
16
- * config resolution).
17
+ * - `undefined`: auto-detect. A `babel.publish.config.*` (in the package root
18
+ * or `config/`) wins, because this is a publish build; otherwise babel's own
19
+ * config resolution applies (see `detectConfigFile`).
17
20
  * - a string: use that config file.
18
21
  * - `false`: ignore config files entirely.
19
22
  *
@@ -46,14 +49,55 @@ export interface BabelOptions {
46
49
  };
47
50
  }
48
51
 
52
+ /** Tried in order, so an ESM config wins over a JSON one of the same name. */
53
+ const PUBLISH_CONFIG_EXTENSIONS = ["mjs", "cjs", "js", "mts", "cts", "ts", "json"];
54
+
55
+ /**
56
+ * Tried in order: next to package.json first, then `config/` for libraries that
57
+ * keep their build configuration out of the package root.
58
+ */
59
+ const PUBLISH_CONFIG_DIRECTORIES = [".", "config"];
60
+
49
61
  /**
50
- * Resolve the project's root babel config the way babel itself does
51
- * (`babel.config.{js,cjs,mjs,cts,json}`, honoring `rootMode` semantics).
62
+ * A `babel.publish.config.*` (in the package root or `config/`), if there is
63
+ * one.
64
+ *
65
+ * A library's plain `babel.config.*` is its *development* config: it typically
66
+ * compiles `@embroider/macros` away, targets the wire format, and wires up
67
+ * whatever the in-package demo app or test suite needs. None of that belongs in
68
+ * a published artifact -- macros must stay for the consuming app to evaluate,
69
+ * and the wire format is private between one template compiler and one glimmer
70
+ * runtime. Babel's own resolution can't tell the two apart (it finds whatever
71
+ * `babel.config.*` exists), so a publish build has to prefer the config named
72
+ * for publishing.
73
+ */
74
+ function detectPublishConfigFile(): string | undefined {
75
+ for (const directory of PUBLISH_CONFIG_DIRECTORIES) {
76
+ for (const extension of PUBLISH_CONFIG_EXTENSIONS) {
77
+ const candidate = resolve(directory, `babel.publish.config.${extension}`);
78
+
79
+ if (existsSync(candidate)) return candidate;
80
+ }
81
+ }
82
+
83
+ return undefined;
84
+ }
85
+
86
+ /**
87
+ * The config this publish build should use: a `babel.publish.config.*` when the
88
+ * library has one, else the project's root babel config resolved the way babel
89
+ * itself does (`babel.config.{js,cjs,mjs,cts,json}`, honoring `rootMode`
90
+ * semantics) -- which for a library whose only config *is* its publish config
91
+ * is the same file either way.
52
92
  *
53
93
  * The sync API evaluates the config file; on node 24+ that works for native
54
94
  * ESM configs too (require(esm)).
55
95
  */
56
96
  function detectConfigFile(): string | undefined {
97
+ const publishConfig = detectPublishConfigFile();
98
+
99
+ if (publishConfig) return publishConfig;
100
+
57
101
  const partial = loadPartialConfigSync({ cwd: process.cwd() });
58
102
 
59
103
  return partial?.config ?? undefined;
@@ -112,9 +156,10 @@ function defaultPlugins(templateTransforms?: Transform[]): PluginItem[] {
112
156
  * to only the files that actually need it (template-tag, decorators, template
113
157
  * imports). Everything else stays on the native transform.
114
158
  *
115
- * The library's own babel config is used when it exists; without one,
116
- * `defaultPlugins` covers templates, decorators, and TypeScript, so no
117
- * config file is required.
159
+ * The library's own babel config is used when it exists -- its
160
+ * `babel.publish.config.*` (root or `config/`) in preference to its
161
+ * `babel.config.*`, since this is a publish build. Without one, `defaultPlugins` covers templates, decorators,
162
+ * and TypeScript, so no config file is required.
118
163
  *
119
164
  * Libraries default to `babelHelpers: "bundled"` so the emitted output is
120
165
  * self-contained.
@@ -55,12 +55,15 @@ function resolveTsconfigPath(option: string | boolean | undefined): string | und
55
55
  * sources -- isolated declarations then constrain exactly the code that gets
56
56
  * declarations emitted for it, and nothing else.
57
57
  *
58
- * Projects with no tsconfig (JavaScript libraries, or `tsconfig: false`) or
59
- * without the `typescript` package have no declarations to emit, so there is
60
- * nothing to check.
58
+ * Projects with no tsconfig (JavaScript libraries) or without the `typescript`
59
+ * package have no declarations to emit, so there is nothing to check.
60
+ * `tsconfig: false` is different: it is an explicit opt-out, and combined with
61
+ * declaration emit it produces a confusing "Source file not found" from the
62
+ * tsc-based pipeline, so it errors here instead.
61
63
  */
62
64
  export function emberIsolatedDeclarations(): Plugin {
63
65
  let tsconfigOption: string | boolean | undefined;
66
+ let emitsDeclarations = true;
64
67
 
65
68
  return {
66
69
  name: "ember:isolated-declarations",
@@ -69,9 +72,31 @@ export function emberIsolatedDeclarations(): Plugin {
69
72
  // -- i.e. the cwd's tsconfig.json, the only thing it could mean there.
70
73
  tsdownConfig(config: UserConfig) {
71
74
  tsconfigOption = config.tsconfig;
75
+ // `emberConfig()` turns dts on unless the library turned it off, so an
76
+ // explicit `false` is the only "no declarations" signal. Hook order
77
+ // between plugins isn't guaranteed, so don't rely on it having run.
78
+ emitsDeclarations = config.dts !== false;
72
79
  },
73
80
 
74
81
  async buildStart() {
82
+ if (tsconfigOption === false) {
83
+ if (!emitsDeclarations) return;
84
+
85
+ // Without a tsconfig there is no `isolatedDeclarations`, so tsdown
86
+ // falls back to the tsc-based declaration pipeline -- which reads
87
+ // source files from disk and dies with "Source file not found" on
88
+ // every `.gts`/`.gjs`, since those only exist compiled in the module
89
+ // graph. Say so here instead of leaving that to be decoded.
90
+ this.error(
91
+ `\`tsconfig: false\` cannot be combined with declaration emit.\n\n` +
92
+ `Declarations are emitted by the isolated-declarations pipeline, which needs a ` +
93
+ `tsconfig setting "compilerOptions.isolatedDeclarations": true -- it is the only ` +
94
+ `pipeline that can see compiled .gts/.gjs modules.\n\n` +
95
+ `Either point tsdown's \`tsconfig\` option at such a config, or set \`dts: false\` ` +
96
+ `if this library ships no types.`,
97
+ );
98
+ }
99
+
75
100
  const tsconfigPath = resolveTsconfigPath(tsconfigOption);
76
101
 
77
102
  if (!tsconfigPath || !existsSync(tsconfigPath)) return;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * What this package hands back: an object that rolldown and tsdown accept in
3
+ * `plugins`.
4
+ *
5
+ * Structurally this *is* rolldown's `Plugin` -- `name` is its only required
6
+ * member, every hook is optional -- so the two are assignable in both
7
+ * directions: a consumer who imports rolldown's own type can still write
8
+ * `const plugins: Plugin[] = ember()`, and tsdown's `plugins` option lists
9
+ * `{ name: string }` among the shapes it takes.
10
+ *
11
+ * Declaring it here rather than re-exporting rolldown's type is what keeps
12
+ * `rolldown` out of the published declarations. Otherwise it has to become a
13
+ * runtime `dependency` purely so consumers can resolve a type: leave it a
14
+ * devDependency and the declaration bundler inlines a ~200kB private copy of
15
+ * rolldown's types instead, nominally distinct from the consumer's own.
16
+ *
17
+ * The precise hook signatures still apply inside this package -- each plugin
18
+ * function is typed with rolldown's real `Plugin` (a devDependency), and this
19
+ * type only widens what crosses the package boundary.
20
+ */
21
+ export interface RolldownPluginLike {
22
+ name: string;
23
+ }