@nullvoxpopuli/ember-rolldown 2.7.0 → 2.8.1

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
@@ -10,7 +10,9 @@ import pkg from "@embroider/core";
10
10
  import { Preprocessor } from "content-tag";
11
11
  import { readFile, readdir, writeFile } from "node:fs/promises";
12
12
  //#region src/babel.ts
13
- /** Tried in order, so an ESM config wins over a JSON one of the same name. */
13
+ /**
14
+ * Tried in order, so an ESM config wins over a JSON one of the same name.
15
+ */
14
16
  const PUBLISH_CONFIG_EXTENSIONS = [
15
17
  "mjs",
16
18
  "cjs",
@@ -21,22 +23,27 @@ const PUBLISH_CONFIG_EXTENSIONS = [
21
23
  "json"
22
24
  ];
23
25
  /**
24
- * Tried in order: next to package.json first, then `config/` for libraries that
25
- * keep their build configuration out of the package root.
26
+ * Tried in order:
27
+ * - next to package.json first
28
+ * - then `config/`, for libraries that keep their build configuration
29
+ * out of the package root
26
30
  */
27
31
  const PUBLISH_CONFIG_DIRECTORIES = [".", "config"];
28
32
  /**
29
- * A `babel.publish.config.*` (in the package root or `config/`), if there is
30
- * one.
31
- *
32
- * A library's plain `babel.config.*` is its *development* config: it typically
33
- * compiles `@embroider/macros` away, targets the wire format, and wires up
34
- * whatever the in-package demo app or test suite needs. None of that belongs in
35
- * a published artifact -- macros must stay for the consuming app to evaluate,
36
- * and the wire format is private between one template compiler and one glimmer
37
- * runtime. Babel's own resolution can't tell the two apart (it finds whatever
38
- * `babel.config.*` exists), so a publish build has to prefer the config named
39
- * for publishing.
33
+ * A `babel.publish.config.*` (in the package root or `config/`), if there is one.
34
+ *
35
+ * A library's plain `babel.config.*` is its *development* config.
36
+ * It typically:
37
+ * - compiles `@embroider/macros` away
38
+ * - targets the wire format
39
+ * - wires up whatever the in-package demo app or test suite needs
40
+ *
41
+ * None of that belongs in a published artifact:
42
+ * - macros must stay, for the consuming app to evaluate
43
+ * - the wire format is private between one template compiler and one glimmer runtime
44
+ *
45
+ * Babel's own resolution can't tell the two apart (it finds whatever `babel.config.*` exists),
46
+ * so a publish build has to prefer the config named for publishing.
40
47
  */
41
48
  function detectPublishConfigFile() {
42
49
  for (const directory of PUBLISH_CONFIG_DIRECTORIES) for (const extension of PUBLISH_CONFIG_EXTENSIONS) {
@@ -45,14 +52,16 @@ function detectPublishConfigFile() {
45
52
  }
46
53
  }
47
54
  /**
48
- * The config this publish build should use: a `babel.publish.config.*` when the
49
- * library has one, else the project's root babel config resolved the way babel
50
- * itself does (`babel.config.{js,cjs,mjs,cts,json}`, honoring `rootMode`
51
- * semantics) -- which for a library whose only config *is* its publish config
52
- * is the same file either way.
53
- *
54
- * The sync API evaluates the config file; on node 24+ that works for native
55
- * ESM configs too (require(esm)).
55
+ * The config this publish build must use:
56
+ * - a `babel.publish.config.*`, when the library has one
57
+ * - else the project's root babel config, resolved the way babel itself does
58
+ * (`babel.config.{js,cjs,mjs,cts,json}`, honoring `rootMode` semantics)
59
+ *
60
+ * For a library whose only config *is* its publish config,
61
+ * that is the same file either way.
62
+ *
63
+ * The sync API evaluates the config file.
64
+ * On node 24+ that works for native ESM configs too (require(esm)).
56
65
  */
57
66
  function detectConfigFile() {
58
67
  const publishConfig = detectPublishConfigFile();
@@ -63,17 +72,25 @@ function detectConfigFile() {
63
72
  * Everything a library without its own babel config needs:
64
73
  *
65
74
  * - TypeScript stripping
75
+ *
66
76
  * - template compilation to `precompileTemplate` (`targetFormat: "hbs"`).
67
- * Published libraries must NOT ship wire format: the wire format is
68
- * private between the template compiler and the glimmer runtime of the
69
- * same version, so baking it in ties the published artifact to the
70
- * consuming app's exact ember-source. The consuming app performs final
71
- * compilation.
72
- * - decorator-transforms, with its runtime left as a bare specifier so the
73
- * consuming app resolves it (the library keeps `decorator-transforms` as
74
- * a real dependency).
77
+ * Published libraries must NOT ship wire format.
78
+ * The wire format is private between the template compiler and the glimmer runtime
79
+ * of the same version, so baking it in ties the published artifact
80
+ * to the consuming app's exact ember-source.
81
+ * The consuming app performs final compilation.
82
+ *
83
+ * A bundle-mode build ships that exact ember-source,
84
+ * so it compiles to the wire format with ember-source's own compiler,
85
+ * and needs no compiler at runtime.
86
+ *
87
+ * - decorator-transforms, with its runtime left as a bare specifier
88
+ * so the consuming app resolves it.
89
+ * (the library keeps `decorator-transforms` as a real dependency)
90
+ *
91
+ * A bundle-mode build resolves it itself.
75
92
  */
76
- function defaultPlugins(templateTransforms) {
93
+ function defaultPlugins(templateTransforms, bundle = false) {
77
94
  return [
78
95
  [transformTypeScript, {
79
96
  allExtensions: true,
@@ -81,36 +98,41 @@ function defaultPlugins(templateTransforms) {
81
98
  allowDeclareFields: true
82
99
  }],
83
100
  [templateCompilation, {
84
- targetFormat: "hbs",
101
+ targetFormat: bundle ? "wire" : "hbs",
85
102
  transforms: templateTransforms ?? []
86
103
  }],
87
104
  [decoratorTransforms, { runtime: { import: "decorator-transforms/runtime-esm" } }]
88
105
  ];
89
106
  }
90
107
  /**
91
- * We still need babel (not just oxc/rolldown's native transforms) for two
92
- * reasons:
93
- *
94
- * - template compilation: `babel-plugin-ember-template-compilation` turns the
95
- * content-tag output into `precompileTemplate` calls; oxc has no equivalent.
96
- * - decorators: Ember uses the legacy/stage-1 decorator signature together
97
- * with `decorator-transforms`, which rewrites decorated class fields
98
- * (`@tracked x`) into getter/setters backed by a runtime. oxc's native
99
- * "legacy decorators" emit tsc-style `__decorate` output, which does not
100
- * match those semantics.
101
- *
102
- * But we don't want to send *every* file through babel and give back the speed
103
- * rolldown/oxc buys us -- so we run babel via `maybeBabel`, which filters down
104
- * to only the files that actually need it (template-tag, decorators, template
105
- * imports). Everything else stays on the native transform.
106
- *
107
- * The library's own babel config is used when it exists -- its
108
- * `babel.publish.config.*` (root or `config/`) in preference to its
109
- * `babel.config.*`, since this is a publish build. Without one, `defaultPlugins` covers templates, decorators,
110
- * and TypeScript, so no config file is required.
111
- *
112
- * Libraries default to `babelHelpers: "bundled"` so the emitted output is
113
- * self-contained.
108
+ * We still need babel (not just oxc / rolldown's native transforms) for two reasons:
109
+ *
110
+ * - template compilation.
111
+ * `babel-plugin-ember-template-compilation` turns the content-tag output
112
+ * into `precompileTemplate` calls.
113
+ * oxc has no equivalent.
114
+ *
115
+ * - decorators.
116
+ * Ember uses the legacy / stage-1 decorator signature together with `decorator-transforms`,
117
+ * which rewrites decorated class fields (`@tracked x`) into getter / setters backed by a runtime.
118
+ * oxc's native "legacy decorators" emit tsc-style `__decorate` output,
119
+ * which does not match those semantics.
120
+ *
121
+ * But we don't want to send *every* file through babel
122
+ * and give back the speed rolldown / oxc buys us.
123
+ *
124
+ * So we run babel via `maybeBabel`, which filters down to only the files that need it
125
+ * (template-tag, decorators, template imports).
126
+ * Everything else stays on the native transform.
127
+ *
128
+ * The library's own babel config is used when it exists.
129
+ * Its `babel.publish.config.*` (root or `config/`) wins over its `babel.config.*`,
130
+ * since this is a publish build.
131
+ *
132
+ * Without one, `defaultPlugins` covers templates, decorators, and TypeScript,
133
+ * so no config file is required.
134
+ *
135
+ * Libraries default to `babelHelpers: "bundled"`, so the emitted output is self-contained.
114
136
  */
115
137
  function emberBabel(options = {}) {
116
138
  const configFile = options.configFile === void 0 ? detectConfigFile() : options.configFile;
@@ -130,64 +152,10 @@ function emberBabel(options = {}) {
130
152
  ...shared,
131
153
  configFile: false,
132
154
  babelrc: false,
133
- plugins: defaultPlugins(options.templateTransforms).concat(options.plugins ?? [])
155
+ plugins: defaultPlugins(options.templateTransforms, options.bundle).concat(options.plugins ?? [])
134
156
  });
135
157
  }
136
158
  //#endregion
137
- //#region src/config.ts
138
- /**
139
- * Sensible defaults for an Ember v2 library, applied through plugin hooks so
140
- * they travel with `ember()` — you get them whether you use this package's
141
- * `defineConfig`, tsdown's, or a plain `tsdown.config.js` / `rolldown.config.js`.
142
- *
143
- * Every value is applied with `??=`, so anything you set explicitly wins.
144
- *
145
- * Under tsdown, the full set applies via the `tsdownConfig` hook (analogous to
146
- * Vite's `config` hook):
147
- *
148
- * - `sourcemap` — emit sourcemaps alongside the output.
149
- * - `clean` — wipe `dist/` between builds.
150
- * - `dts` — emit `.d.ts` declarations (via isolated declarations).
151
- * - `outExtensions` — `.js`/`.d.ts` rather than tsdown's default `.mjs`/`.d.mts`,
152
- * since exports maps conventionally point at `.js`/`.d.ts`.
153
- * - `report` — off; the size report is noise for a library build.
154
- * - `deps.neverBundle` — leave node builtins and the ember virtual packages to
155
- * the consuming app (`emberExternals()` handles the rest).
156
- *
157
- * A plain rolldown build has no notion of `clean`/`dts`/`outExtensions`/`report`
158
- * (those are tsdown-level concepts), so only the options with rolldown
159
- * equivalents are applied there, via rolldown's own `outputOptions` hook:
160
- *
161
- * - `output.sourcemap` — on (output option).
162
- *
163
- * Externals are handled by `emberExternals()` (a `resolveId` hook) in both cases.
164
- */
165
- function emberConfig() {
166
- return {
167
- name: "ember:config",
168
- tsdownConfig(config) {
169
- config.sourcemap ??= true;
170
- config.clean ??= true;
171
- config.dts ??= { sourcemap: true };
172
- config.outExtensions ??= () => ({
173
- js: ".js",
174
- dts: ".d.ts"
175
- });
176
- config.report ??= false;
177
- config.deps ??= {};
178
- config.deps.neverBundle ??= [
179
- "node:*",
180
- "@ember/*",
181
- "@glimmer/*"
182
- ];
183
- },
184
- outputOptions(options) {
185
- options.sourcemap ??= true;
186
- return options;
187
- }
188
- };
189
- }
190
- //#endregion
191
159
  //#region src/externals.ts
192
160
  const { emberVirtualPackages, emberVirtualPeerDeps, packageName, templateCompilationModules } = pkg;
193
161
  const compilationModules = new Set(templateCompilationModules.map((m) => m.module));
@@ -198,8 +166,8 @@ function readJsonSync(path) {
198
166
  return JSON.parse(readFileSync(path, { encoding: "utf8" }));
199
167
  }
200
168
  /**
201
- * Everything the library declares as a `dependency` or `peerDependency` is
202
- * resolvable by the consuming app, so we never bundle it.
169
+ * Everything the library declares as a `dependency` or `peerDependency`
170
+ * is resolvable by the consuming app, so we never bundle it.
203
171
  */
204
172
  function resolvableDependencies() {
205
173
  const deps = /* @__PURE__ */ new Set();
@@ -209,31 +177,44 @@ function resolvableDependencies() {
209
177
  return deps;
210
178
  }
211
179
  /**
212
- * The module names ember-source provides by renaming them into itself — the
213
- * keys of its `ember-addon.renamed-modules`, normalized from file paths to
214
- * import specifiers (`@glimmer/runtime/index.js` → `@glimmer/runtime`).
180
+ * The modules ember-source provides by renaming them into itself.
215
181
  *
216
- * This is the authoritative list of ember's provided modules, including
217
- * private API that @embroider/core's emberVirtualPackages doesn't cover
218
- * (e.g. `@glimmer/runtime`). It deliberately does NOT include real packages
219
- * like `@glimmer/component`, which a library may want bundled.
182
+ * This is its `ember-addon.renamed-modules`, keyed by module file path:
183
+ * `@glimmer/runtime/index.js` → `ember-source/@glimmer/runtime/index.js`
220
184
  *
221
- * Resolved from the library's own dependency graph; empty when ember-source
222
- * isn't resolvable there.
185
+ * It is the authoritative list of ember's provided modules.
186
+ * It includes private API that @embroider/core's emberVirtualPackages
187
+ * doesn't cover (e.g. `@glimmer/runtime`).
188
+ *
189
+ * It deliberately does NOT include real packages like `@glimmer/component`,
190
+ * which a library may want bundled.
191
+ *
192
+ * Empty when ember-source isn't resolvable from the library.
223
193
  */
224
194
  function emberSourceRenamedModules() {
225
- const provided = /* @__PURE__ */ new Set();
226
195
  try {
227
- const manifest = createRequire(path.resolve("package.json"))("ember-source/package.json");
228
- for (const key of Object.keys(manifest["ember-addon"]?.["renamed-modules"] ?? {})) provided.add(key.replace(/\.js$/, "").replace(/\/index$/, ""));
229
- } catch {}
196
+ return createRequire(path.resolve("package.json"))("ember-source/package.json")["ember-addon"]?.["renamed-modules"] ?? {};
197
+ } catch {
198
+ return {};
199
+ }
200
+ }
201
+ /**
202
+ * The renamed modules as import specifiers
203
+ * `@glimmer/runtime/index.js` → `@glimmer/runtime`
204
+ */
205
+ function emberSourceProvidedModules() {
206
+ const provided = /* @__PURE__ */ new Set();
207
+ for (const key of Object.keys(emberSourceRenamedModules())) provided.add(key.replace(/\.js$/, "").replace(/\/index$/, ""));
230
208
  return provided;
231
209
  }
232
210
  /**
233
- * Keeps the library's declared dependencies and the ember virtual packages
234
- * (things like `@ember/component`, `@glimmer/tracking`, the template compiler,
235
- * …) external, so the app that consumes the library resolves them instead of
236
- * the library bundling copies of them.
211
+ * Keeps external:
212
+ * - the library's declared dependencies
213
+ * - the ember virtual packages
214
+ * (things like `@ember/component`, `@glimmer/tracking`, the template compiler, …)
215
+ *
216
+ * So the app that consumes the library resolves them,
217
+ * instead of the library bundling copies of them.
237
218
  */
238
219
  function emberExternals() {
239
220
  let deps;
@@ -243,7 +224,7 @@ function emberExternals() {
243
224
  buildStart() {
244
225
  this.addWatchFile("package.json");
245
226
  deps = resolvableDependencies();
246
- renamedModules = emberSourceRenamedModules();
227
+ renamedModules = emberSourceProvidedModules();
247
228
  },
248
229
  resolveId: {
249
230
  order: "pre",
@@ -258,18 +239,155 @@ function emberExternals() {
258
239
  };
259
240
  }
260
241
  //#endregion
242
+ //#region src/bundle.ts
243
+ /**
244
+ * The package name a renamed-modules key belongs to
245
+ * `@ember/modifier/on.js` → `@ember/modifier`
246
+ * `rsvp/index.js` → `rsvp`
247
+ */
248
+ function packageOf(modulePath) {
249
+ const segments = modulePath.split("/");
250
+ const length = modulePath.startsWith("@") ? 2 : 1;
251
+ return segments.slice(0, length).join("/");
252
+ }
253
+ /**
254
+ * One alias per package ember-source provides, pointing into ember-source
255
+ * `@ember/modifier` → `ember-source/@ember/modifier`
256
+ *
257
+ * The provided packages are the ones named in `ember-addon.renamed-modules`
258
+ * (`@ember/*`, `@glimmer/tracking`, `rsvp`, `backburner.js`, …).
259
+ *
260
+ * Real packages such as `@glimmer/component` are not in it,
261
+ * so they keep resolving from node_modules.
262
+ */
263
+ function emberSourceAliases() {
264
+ const aliases = {};
265
+ for (const modulePath of Object.keys(emberSourceRenamedModules())) {
266
+ const name = packageOf(modulePath);
267
+ aliases[name] = `ember-source/${name}`;
268
+ }
269
+ return aliases;
270
+ }
271
+ /**
272
+ * Makes the modules ember-source provides resolvable,
273
+ * so a bundle-mode build can include them.
274
+ *
275
+ * ember-source exports every module under `./*`,
276
+ * with `development` and `production` conditions selecting one of its two builds.
277
+ *
278
+ * A bare `@ember/modifier` is not that path, though.
279
+ * It only exists as `ember-source/@ember/modifier`.
280
+ *
281
+ * So this plugin adds the alias for each provided package,
282
+ * and leaves the rest to the resolver:
283
+ * - the `default` condition selects the production build
284
+ * - `resolve.conditionNames: ["development"]` selects the development build
285
+ * (tsdown: `inputOptions.resolve.conditionNames`)
286
+ *
287
+ * Aliases set explicitly in the build config win over these.
288
+ */
289
+ function emberBundle() {
290
+ return {
291
+ name: "ember:bundle",
292
+ options(inputOptions) {
293
+ inputOptions.resolve ??= {};
294
+ inputOptions.resolve.alias = {
295
+ ...emberSourceAliases(),
296
+ ...inputOptions.resolve.alias
297
+ };
298
+ return inputOptions;
299
+ }
300
+ };
301
+ }
302
+ //#endregion
303
+ //#region src/config.ts
304
+ /**
305
+ * Sensible defaults for an Ember v2 library.
306
+ *
307
+ * Applied through plugin hooks, so they travel with `ember()`.
308
+ * You get them whether you use this package's `defineConfig`, tsdown's,
309
+ * or a plain `tsdown.config.js` / `rolldown.config.js`.
310
+ *
311
+ * Every value is applied with `??=`, so anything you set explicitly wins.
312
+ *
313
+ * Under tsdown, the full set applies via the `tsdownConfig` hook
314
+ * (analogous to Vite's `config` hook):
315
+ *
316
+ * - `sourcemap` — emit sourcemaps alongside the output
317
+ * - `clean` — wipe `dist/` between builds
318
+ * - `dts` — emit `.d.ts` declarations (via isolated declarations)
319
+ * - `outExtensions` — `.js` / `.d.ts` rather than tsdown's default `.mjs` / `.d.mts`
320
+ * (exports maps conventionally point at `.js` / `.d.ts`)
321
+ * - `report` — off.
322
+ * The size report is noise for a library build.
323
+ * - `deps.neverBundle` — leave node builtins and the ember virtual packages
324
+ * to the consuming app (`emberExternals()` handles the rest)
325
+ *
326
+ * A plain rolldown build has no notion of `clean` / `dts` / `outExtensions` / `report`.
327
+ * Those are tsdown-level concepts.
328
+ * So only the options with rolldown equivalents are applied there,
329
+ * via rolldown's own `outputOptions` hook:
330
+ *
331
+ * - `output.sourcemap` — on
332
+ *
333
+ * Externals are handled by `emberExternals()` (a `resolveId` hook) in both cases.
334
+ *
335
+ * Bundle mode flips the dependency defaults.
336
+ * The output is a self-contained browser artifact, so:
337
+ *
338
+ * - `platform` — `browser`
339
+ * - `deps.alwaysBundle` — everything but node builtins
340
+ * (including the package's own `dependencies` and `peerDependencies`,
341
+ * and the declarations' type imports)
342
+ * - `deps.neverBundle` — node builtins only
343
+ * - `deps.onlyBundle` — `false`
344
+ * (bundling node_modules is the point, so tsdown's hint about it is noise)
345
+ */
346
+ function emberConfig({ bundle = false } = {}) {
347
+ return {
348
+ name: "ember:config",
349
+ tsdownConfig(config) {
350
+ config.sourcemap ??= true;
351
+ config.clean ??= true;
352
+ config.dts ??= { sourcemap: true };
353
+ config.outExtensions ??= () => ({
354
+ js: ".js",
355
+ dts: ".d.ts"
356
+ });
357
+ config.report ??= false;
358
+ config.deps ??= {};
359
+ if (bundle) {
360
+ config.platform ??= "browser";
361
+ config.deps.alwaysBundle ??= (id) => !id.startsWith("node:");
362
+ config.deps.neverBundle ??= ["node:*"];
363
+ config.deps.onlyBundle ??= false;
364
+ return;
365
+ }
366
+ config.deps.neverBundle ??= [
367
+ "node:*",
368
+ "@ember/*",
369
+ "@glimmer/*"
370
+ ];
371
+ },
372
+ outputOptions(options) {
373
+ options.sourcemap ??= true;
374
+ return options;
375
+ }
376
+ };
377
+ }
378
+ //#endregion
261
379
  //#region src/isolated-declarations.ts
262
380
  /**
263
- * Resolve the tsconfig the build will actually use, mirroring tsdown's own
264
- * `tsconfig` option (`string | boolean`):
381
+ * Resolve the tsconfig the build will use.
265
382
  *
266
- * - `undefined` / `true`: `tsconfig.json` in the cwd.
267
- * - a path to a file: that file.
268
- * - a path to a directory: `tsconfig.json` inside it.
269
- * - `false`: no tsconfig at all.
383
+ * Mirrors tsdown's own `tsconfig` option (`string | boolean`):
384
+ * - `undefined` / `true`: `tsconfig.json` in the cwd
385
+ * - a path to a file: that file
386
+ * - a path to a directory: `tsconfig.json` inside it
387
+ * - `false`: no tsconfig at all
270
388
  *
271
- * Under plain rolldown there is no such option, so the cwd's `tsconfig.json`
272
- * is all there is.
389
+ * Under plain rolldown there is no such option,
390
+ * so the cwd's `tsconfig.json` is all there is.
273
391
  */
274
392
  function resolveTsconfigPath(option) {
275
393
  if (option === false) return void 0;
@@ -281,33 +399,41 @@ function resolveTsconfigPath(option) {
281
399
  return resolve("tsconfig.json");
282
400
  }
283
401
  /**
284
- * Errors the build when the tsconfig it builds with does not set
285
- * `isolatedDeclarations: true`.
286
- *
287
- * This is required: declarations for `.gts`/`.gjs` (template tag) modules can
288
- * only be emitted by the isolated-declarations pipeline, which reads compiled
289
- * modules from the bundler's module graph. The `tsc`-based pipeline reads
290
- * source files from disk, where the compiled modules don't exist, and fails
291
- * with "Source file not found".
292
- *
293
- * Failing fast here -- rather than only when declaration emit happens to run
294
- * -- keeps the project honest: editors and `tsc`/`ember-tsc` then check the
295
- * same rules the build enforces (exported values need explicit type
296
- * annotations, e.g. `export const X: TOC<Sig> = <template>...`).
297
- *
298
- * The tsconfig checked is the one tsdown's `tsconfig` option points at, not
299
- * necessarily `tsconfig.json`. A library whose package also holds dev-only code
300
- * (a demo app, in-package tests) can therefore keep a permissive
301
- * `tsconfig.json` covering everything for editors and `tsc --noEmit`, and point
302
- * the build at a `tsconfig.publish.json` that covers only the publishable
303
- * sources -- isolated declarations then constrain exactly the code that gets
304
- * declarations emitted for it, and nothing else.
305
- *
306
- * Projects with no tsconfig (JavaScript libraries) or without the `typescript`
307
- * package have no declarations to emit, so there is nothing to check.
308
- * `tsconfig: false` is different: it is an explicit opt-out, and combined with
309
- * declaration emit it produces a confusing "Source file not found" from the
310
- * tsc-based pipeline, so it errors here instead.
402
+ * Errors the build when the tsconfig it builds with
403
+ * does not set `isolatedDeclarations: true`.
404
+ *
405
+ * This is required.
406
+ * Declarations for `.gts` / `.gjs` (template tag) modules can only be emitted
407
+ * by the isolated-declarations pipeline,
408
+ * which reads compiled modules from the bundler's module graph.
409
+ *
410
+ * The `tsc`-based pipeline reads source files from disk.
411
+ * The compiled modules don't exist there, so it fails with "Source file not found".
412
+ *
413
+ * Failing fast here, rather than only when declaration emit happens to run,
414
+ * keeps the project honest.
415
+ * Editors and `tsc` / `ember-tsc` then check the same rules the build enforces:
416
+ * exported values need explicit type annotations,
417
+ * e.g. `export const X: TOC<Sig> = <template>...`
418
+ *
419
+ * The tsconfig checked is the one tsdown's `tsconfig` option points at,
420
+ * not necessarily `tsconfig.json`.
421
+ *
422
+ * So a library whose package also holds dev-only code (a demo app, in-package tests) can:
423
+ * - keep a permissive `tsconfig.json` covering everything,
424
+ * for editors and `tsc --noEmit`
425
+ * - point the build at a `tsconfig.publish.json` that covers only the publishable sources
426
+ *
427
+ * Isolated declarations then constrain exactly the code that gets declarations emitted,
428
+ * and nothing else.
429
+ *
430
+ * Projects with no tsconfig (JavaScript libraries) or without the `typescript` package
431
+ * have no declarations to emit, so there is nothing to check.
432
+ *
433
+ * `tsconfig: false` is different.
434
+ * It is an explicit opt-out.
435
+ * Combined with declaration emit, it produces a confusing "Source file not found"
436
+ * from the tsc-based pipeline, so it errors here instead.
311
437
  */
312
438
  function emberIsolatedDeclarations() {
313
439
  let tsconfigOption;
@@ -341,9 +467,10 @@ function emberIsolatedDeclarations() {
341
467
  //#region src/transform.ts
342
468
  const processor = new Preprocessor();
343
469
  /**
344
- * `.d.ts` files emitted for `.gts` source reference the original `.gts`
345
- * specifiers. Consumers can't resolve those, so we rewrite them back to
346
- * extension-less specifiers.
470
+ * `.d.ts` files emitted for `.gts` source reference the original `.gts` specifiers.
471
+ *
472
+ * Consumers can't resolve those,
473
+ * so we rewrite them back to extension-less specifiers.
347
474
  */
348
475
  function fixDeclarationImports(content) {
349
476
  return content.replace(/from\s+'([^']+)\.gts'/g, "from '$1'").replace(/from\s+"([^"]+)\.gts"/g, "from \"$1\"").replace(/import\("([^"]+)\.gts"\)/g, "import(\"$1\")").replace(/import\('([^']+)\.gts'\)/g, "import('$1')");
@@ -363,10 +490,12 @@ async function fixDtsExtensionsInDir(dir) {
363
490
  /**
364
491
  * A sourcemap mapping every generated line to the same line of the input.
365
492
  *
366
- * `AAAA` is the [0, 0, 0, 0] VLQ segment (first line maps to source 0, line 0,
367
- * column 0); `AACA` is [0, 0, +1, 0] (each following line advances the source
368
- * line by one). Exact at line granularity, which is all the specifier rewrite
369
- * can disturb.
493
+ * - `AAAA` is the [0, 0, 0, 0] VLQ segment
494
+ * (first line maps to source 0, line 0, column 0)
495
+ * - `AACA` is [0, 0, +1, 0]
496
+ * (each following line advances the source line by one)
497
+ *
498
+ * Exact at line granularity, which is all the specifier rewrite can disturb.
370
499
  */
371
500
  function lineIdentityMap(id, source) {
372
501
  return {
@@ -378,8 +507,10 @@ function lineIdentityMap(id, source) {
378
507
  };
379
508
  }
380
509
  /**
381
- * Maps `.gts` -> `.ts` and `.gjs` -> `.js` (so rolldown can identify them as
382
- * ts/js) and preprocesses `<template>` via content-tag.
510
+ * Preprocesses `<template>` via content-tag, and maps
511
+ * `.gts` → `.ts`
512
+ * `.gjs` → `.js`
513
+ * so rolldown can identify them as ts / js.
383
514
  */
384
515
  function emberTransform() {
385
516
  return {
@@ -470,30 +601,45 @@ function emberTransform() {
470
601
  //#endregion
471
602
  //#region index.ts
472
603
  /**
473
- * A batteries-included plugin for building Ember v2 libraries (addons) with
474
- * rolldown (or tsdown, which is built on rolldown).
475
- *
476
- * It bundles everything needed to compile `.gts`/`.gjs` and template-tag
477
- * (`<template>`) source into publishable output:
478
- *
479
- * - `emberConfig()` — applies sensible tsdown defaults for a library build
480
- * (sourcemaps, `clean`, `dts`, `.js`/`.d.ts` extensions, quiet logging);
481
- * anything you set explicitly still wins.
482
- * - `emberIsolatedDeclarations()` — errors when a tsconfig.json is present
483
- * without `isolatedDeclarations: true` (required: it is the only
484
- * declaration pipeline that can see compiled template-tag modules).
485
- * - `emberExternals()` — keeps your dependencies, peerDependencies, and the
486
- * ember virtual packages external, so consuming apps resolve them.
487
- * - `emberTransform()` — preprocesses `<template>` via content-tag and maps
488
- * `.gts`/`.gjs` to `.ts`/`.js` so rolldown can understand them.
489
- * - `emberBabel()` — runs babel (template compilation, decorators, type
490
- * stripping) with `babelHelpers: "bundled"`, but only on the files that
491
- * actually need it (via `maybeBabel`); everything else stays on the fast
492
- * native transform. The library's own `babel.config.js` is used when it
493
- * exists; no config file is required.
494
- *
495
- * Usage in `tsdown.config.js` (import `defineConfig` from `tsdown` — or from
496
- * `rolldown` for a `rolldown.config.js` — so it carries the correct types):
604
+ * A batteries-included plugin for building Ember v2 libraries (addons)
605
+ * with rolldown, or with tsdown (which is built on rolldown).
606
+ *
607
+ * It bundles everything needed to compile `.gts` / `.gjs` and
608
+ * template-tag (`<template>`) source into publishable output:
609
+ *
610
+ * - `emberConfig()`
611
+ * applies sensible tsdown defaults for a library build
612
+ * (sourcemaps, `clean`, `dts`, `.js` / `.d.ts` extensions, quiet logging).
613
+ * Anything you set explicitly still wins.
614
+ *
615
+ * - `emberIsolatedDeclarations()`
616
+ * errors when a tsconfig.json is present without `isolatedDeclarations: true`.
617
+ * That is the only declaration pipeline that can see compiled template-tag modules.
618
+ *
619
+ * - `emberExternals()`
620
+ * keeps your dependencies, peerDependencies, and the ember virtual packages external,
621
+ * so consuming apps resolve them.
622
+ *
623
+ * - `emberBundle()`
624
+ * bundle mode only, in place of `emberExternals()`.
625
+ * Aliases the ember virtual packages into ember-source,
626
+ * whose export conditions pick the build to bundle.
627
+ *
628
+ * - `emberTransform()`
629
+ * preprocesses `<template>` via content-tag,
630
+ * and maps `.gts` / `.gjs` to `.ts` / `.js` so rolldown can understand them.
631
+ *
632
+ * - `emberBabel()`
633
+ * runs babel (template compilation, decorators, type stripping)
634
+ * with `babelHelpers: "bundled"`.
635
+ * Only the files that need it go through babel (via `maybeBabel`).
636
+ * Everything else stays on the fast native transform.
637
+ * The library's own `babel.config.js` is used when it exists.
638
+ * No config file is required.
639
+ *
640
+ * Usage in `tsdown.config.js`.
641
+ * Import `defineConfig` from `tsdown` (or from `rolldown` for a `rolldown.config.js`)
642
+ * so it carries the correct types:
497
643
  *
498
644
  * ```js
499
645
  * import { defineConfig } from "tsdown";
@@ -506,12 +652,16 @@ function emberTransform() {
506
652
  * ```
507
653
  */
508
654
  function ember(config = {}) {
655
+ const bundle = config.bundle ?? false;
509
656
  return [
510
- emberConfig(),
657
+ emberConfig({ bundle }),
511
658
  emberIsolatedDeclarations(),
512
- emberExternals(),
659
+ bundle ? emberBundle() : emberExternals(),
513
660
  emberTransform(),
514
- emberBabel(config.babel)
661
+ emberBabel({
662
+ ...config.babel,
663
+ bundle
664
+ })
515
665
  ];
516
666
  }
517
667
  //#endregion