@nullvoxpopuli/ember-rolldown 0.0.0 → 2.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 NullVoxPopuli
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -20,10 +20,15 @@ modern TypeScript when type-checking: 6+ with `lib` covering `es2025` (e.g.
20
20
 
21
21
  ## Usage
22
22
 
23
+ Import `defineConfig` from the bundler you're using — `tsdown` or `rolldown` —
24
+ so it carries that tool's own config types; `@nullvoxpopuli/ember-rolldown`
25
+ provides `ember()` (the defaults travel with the plugin, not `defineConfig`).
26
+
23
27
  In your `tsdown.config.js` (recommended — emits declarations):
24
28
 
25
29
  ```js
26
- import { defineConfig, ember } from "@nullvoxpopuli/ember-rolldown";
30
+ import { defineConfig } from "tsdown";
31
+ import { ember } from "@nullvoxpopuli/ember-rolldown";
27
32
 
28
33
  export default defineConfig({
29
34
  entry: ["./src/index.ts"],
package/dist/index.js ADDED
@@ -0,0 +1,391 @@
1
+ import { maybeBabel } from "@nullvoxpopuli/ember-build-tooling-utils";
2
+ import transformTypeScript from "@babel/plugin-transform-typescript";
3
+ import templateCompilation from "babel-plugin-ember-template-compilation";
4
+ import decoratorTransforms from "decorator-transforms";
5
+ import { loadPartialConfigSync } from "@babel/core";
6
+ import { existsSync, readFileSync } from "node:fs";
7
+ import pkg from "@embroider/core";
8
+ import path, { dirname, resolve } from "node:path";
9
+ import { Preprocessor } from "content-tag";
10
+ import { readFile, readdir, writeFile } from "node:fs/promises";
11
+ //#region src/babel.ts
12
+ /**
13
+ * Resolve the project's root babel config the way babel itself does
14
+ * (`babel.config.{js,cjs,mjs,cts,json}`, honoring `rootMode` semantics).
15
+ *
16
+ * The sync API evaluates the config file; on node 24+ that works for native
17
+ * ESM configs too (require(esm)).
18
+ */
19
+ function detectConfigFile() {
20
+ return loadPartialConfigSync({ cwd: process.cwd() })?.config ?? void 0;
21
+ }
22
+ /**
23
+ * Everything a library without its own babel config needs:
24
+ *
25
+ * - TypeScript stripping
26
+ * - template compilation to `precompileTemplate` (`targetFormat: "hbs"`).
27
+ * Published libraries must NOT ship wire format: the wire format is
28
+ * private between the template compiler and the glimmer runtime of the
29
+ * same version, so baking it in ties the published artifact to the
30
+ * consuming app's exact ember-source. The consuming app performs final
31
+ * compilation.
32
+ * - decorator-transforms, with its runtime left as a bare specifier so the
33
+ * consuming app resolves it (the library keeps `decorator-transforms` as
34
+ * a real dependency).
35
+ */
36
+ function defaultPlugins() {
37
+ return [
38
+ [transformTypeScript, {
39
+ allExtensions: true,
40
+ onlyRemoveTypeImports: true,
41
+ allowDeclareFields: true
42
+ }],
43
+ [templateCompilation, { targetFormat: "hbs" }],
44
+ [decoratorTransforms, { runtime: { import: "decorator-transforms/runtime-esm" } }]
45
+ ];
46
+ }
47
+ /**
48
+ * We still need babel (not just oxc/rolldown's native transforms) for two
49
+ * reasons:
50
+ *
51
+ * - template compilation: `babel-plugin-ember-template-compilation` turns the
52
+ * content-tag output into `precompileTemplate` calls; oxc has no equivalent.
53
+ * - decorators: Ember uses the legacy/stage-1 decorator signature together
54
+ * with `decorator-transforms`, which rewrites decorated class fields
55
+ * (`@tracked x`) into getter/setters backed by a runtime. oxc's native
56
+ * "legacy decorators" emit tsc-style `__decorate` output, which does not
57
+ * match those semantics.
58
+ *
59
+ * But we don't want to send *every* file through babel and give back the speed
60
+ * rolldown/oxc buys us -- so we run babel via `maybeBabel`, which filters down
61
+ * to only the files that actually need it (template-tag, decorators, template
62
+ * imports). Everything else stays on the native transform.
63
+ *
64
+ * The library's own babel config is used when it exists; without one,
65
+ * `defaultPlugins` covers templates, decorators, and TypeScript, so no
66
+ * config file is required.
67
+ *
68
+ * Libraries default to `babelHelpers: "bundled"` so the emitted output is
69
+ * self-contained.
70
+ */
71
+ function emberBabel(options = {}) {
72
+ const configFile = options.configFile === void 0 ? detectConfigFile() : options.configFile;
73
+ const shared = {
74
+ babelHelpers: options.babelHelpers ?? "bundled",
75
+ filter: options.filter
76
+ };
77
+ if (configFile) return maybeBabel({
78
+ ...shared,
79
+ configFile,
80
+ plugins: options.plugins ?? []
81
+ });
82
+ return maybeBabel({
83
+ ...shared,
84
+ configFile: false,
85
+ babelrc: false,
86
+ plugins: defaultPlugins().concat(options.plugins ?? [])
87
+ });
88
+ }
89
+ //#endregion
90
+ //#region src/config.ts
91
+ /**
92
+ * Sensible defaults for an Ember v2 library, applied through plugin hooks so
93
+ * they travel with `ember()` — you get them whether you use this package's
94
+ * `defineConfig`, tsdown's, or a plain `tsdown.config.js` / `rolldown.config.js`.
95
+ *
96
+ * Every value is applied with `??=`, so anything you set explicitly wins.
97
+ *
98
+ * Under tsdown, the full set applies via the `tsdownConfig` hook (analogous to
99
+ * Vite's `config` hook):
100
+ *
101
+ * - `sourcemap` — emit sourcemaps alongside the output.
102
+ * - `clean` — wipe `dist/` between builds.
103
+ * - `dts` — emit `.d.ts` declarations (via isolated declarations).
104
+ * - `outExtensions` — `.js`/`.d.ts` rather than tsdown's default `.mjs`/`.d.mts`,
105
+ * since exports maps conventionally point at `.js`/`.d.ts`.
106
+ * - `report` — off; the size report is noise for a library build.
107
+ * - `deps.neverBundle` — leave node builtins and the ember virtual packages to
108
+ * the consuming app (`emberExternals()` handles the rest).
109
+ *
110
+ * A plain rolldown build has no notion of `clean`/`dts`/`outExtensions`/`report`
111
+ * (those are tsdown-level concepts), so only the options with rolldown
112
+ * equivalents are applied there, via rolldown's own `outputOptions` hook:
113
+ *
114
+ * - `output.sourcemap` — on (output option).
115
+ *
116
+ * Externals are handled by `emberExternals()` (a `resolveId` hook) in both cases.
117
+ */
118
+ function emberConfig() {
119
+ return {
120
+ name: "ember:config",
121
+ tsdownConfig(config) {
122
+ config.sourcemap ??= true;
123
+ config.clean ??= true;
124
+ config.dts ??= true;
125
+ config.outExtensions ??= () => ({
126
+ js: ".js",
127
+ dts: ".d.ts"
128
+ });
129
+ config.report ??= false;
130
+ config.deps ??= {};
131
+ config.deps.neverBundle ??= [
132
+ "node:*",
133
+ "@ember/*",
134
+ "@glimmer/*"
135
+ ];
136
+ },
137
+ outputOptions(options) {
138
+ options.sourcemap ??= true;
139
+ return options;
140
+ }
141
+ };
142
+ }
143
+ //#endregion
144
+ //#region src/externals.ts
145
+ const { emberVirtualPackages, emberVirtualPeerDeps, packageName, templateCompilationModules } = pkg;
146
+ const compilationModules = new Set(templateCompilationModules.map((m) => m.module));
147
+ /**
148
+ * @param {string} path
149
+ */
150
+ function readJsonSync(path) {
151
+ return JSON.parse(readFileSync(path, { encoding: "utf8" }));
152
+ }
153
+ /**
154
+ * Everything the library declares as a `dependency` or `peerDependency` is
155
+ * resolvable by the consuming app, so we never bundle it.
156
+ */
157
+ function resolvableDependencies() {
158
+ const deps = /* @__PURE__ */ new Set();
159
+ const manifest = readJsonSync("package.json");
160
+ for (const name of Object.keys(manifest.dependencies ?? {})) deps.add(name);
161
+ for (const name of Object.keys(manifest.peerDependencies ?? {})) deps.add(name);
162
+ return deps;
163
+ }
164
+ /**
165
+ * Keeps the library's declared dependencies and the ember virtual packages
166
+ * (things like `@ember/component`, `@glimmer/tracking`, the template compiler,
167
+ * …) external, so the app that consumes the library resolves them instead of
168
+ * the library bundling copies of them.
169
+ */
170
+ function emberExternals() {
171
+ let deps;
172
+ return {
173
+ name: "ember:externals",
174
+ buildStart() {
175
+ this.addWatchFile("package.json");
176
+ deps = resolvableDependencies();
177
+ },
178
+ resolveId: {
179
+ order: "pre",
180
+ handler(source) {
181
+ if (source.includes(":")) return null;
182
+ const pkgName = packageName(source);
183
+ if (!pkgName) return null;
184
+ if (deps.has(pkgName) || emberVirtualPeerDeps.has(pkgName) || emberVirtualPackages.has(pkgName) || compilationModules.has(pkgName)) return false;
185
+ }
186
+ }
187
+ };
188
+ }
189
+ //#endregion
190
+ //#region src/isolated-declarations.ts
191
+ /**
192
+ * Errors the build when a `tsconfig.json` is present without
193
+ * `isolatedDeclarations: true`.
194
+ *
195
+ * This is required: declarations for `.gts`/`.gjs` (template tag) modules can
196
+ * only be emitted by the isolated-declarations pipeline, which reads compiled
197
+ * modules from the bundler's module graph. The `tsc`-based pipeline reads
198
+ * source files from disk, where the compiled modules don't exist, and fails
199
+ * with "Source file not found".
200
+ *
201
+ * Failing fast here -- rather than only when declaration emit happens to run
202
+ * -- keeps the project honest: editors and `tsc`/`ember-tsc` then check the
203
+ * same rules the build enforces (exported values need explicit type
204
+ * annotations, e.g. `export const X: TOC<Sig> = <template>...`).
205
+ *
206
+ * Projects without a `tsconfig.json` (JavaScript libraries) or without the
207
+ * `typescript` package have no declarations to emit, so there is nothing to
208
+ * check.
209
+ */
210
+ function emberIsolatedDeclarations() {
211
+ return {
212
+ name: "ember:isolated-declarations",
213
+ async buildStart() {
214
+ const tsconfigPath = resolve("tsconfig.json");
215
+ if (!existsSync(tsconfigPath)) return;
216
+ let ts;
217
+ try {
218
+ ts = (await import("typescript")).default;
219
+ } catch {
220
+ return;
221
+ }
222
+ const { config, error } = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
223
+ if (error) return;
224
+ if (ts.parseJsonConfigFileContent(config, ts.sys, dirname(tsconfigPath)).options.isolatedDeclarations !== true) this.error(`${tsconfigPath} must set "compilerOptions.isolatedDeclarations": true.\n\nDeclarations for .gts/.gjs (template tag) modules can only be emitted by the isolated-declarations pipeline, which reads compiled modules from the bundler's module graph -- the tsc-based pipeline reads from disk and cannot see them.\n\nIsolated declarations require exported values to have explicit type annotations, e.g. \`export const X: TOC<Sig> = <template>...\`.`);
225
+ }
226
+ };
227
+ }
228
+ //#endregion
229
+ //#region src/transform.ts
230
+ const processor = new Preprocessor();
231
+ /**
232
+ * `.d.ts` files emitted for `.gts` source reference the original `.gts`
233
+ * specifiers. Consumers can't resolve those, so we rewrite them back to
234
+ * extension-less specifiers.
235
+ */
236
+ function fixDeclarationImports(content) {
237
+ 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')");
238
+ }
239
+ async function fixDtsExtensionsInDir(dir) {
240
+ const entries = await readdir(dir, { withFileTypes: true });
241
+ for (const entry of entries) {
242
+ const fullPath = path.join(dir, entry.name);
243
+ if (entry.isDirectory()) await fixDtsExtensionsInDir(fullPath);
244
+ else if (entry.name.endsWith(".d.ts")) {
245
+ const content = await readFile(fullPath, { encoding: "utf8" });
246
+ const fixed = fixDeclarationImports(content);
247
+ if (fixed !== content) await writeFile(fullPath, fixed);
248
+ }
249
+ }
250
+ }
251
+ /**
252
+ * Maps `.gts` -> `.ts` and `.gjs` -> `.js` (so rolldown can identify them as
253
+ * ts/js) and preprocesses `<template>` via content-tag.
254
+ */
255
+ function emberTransform() {
256
+ const virtualFiles = /* @__PURE__ */ new Set();
257
+ return {
258
+ name: "ember:transform",
259
+ resolveId: {
260
+ order: "pre",
261
+ handler(id, importer) {
262
+ if (!importer) return null;
263
+ const fileName = path.join(path.dirname(importer), id);
264
+ if (id.endsWith(".gts") && !importer.endsWith(".d.ts")) {
265
+ virtualFiles.add(fileName);
266
+ return {
267
+ id: fileName.replace(/\.gts$/, ".ts"),
268
+ meta: { fileName }
269
+ };
270
+ }
271
+ if (id.endsWith(".gjs") && !importer.endsWith(".d.ts")) {
272
+ virtualFiles.add(fileName);
273
+ return {
274
+ id: fileName.replace(/\.gjs$/, ".js"),
275
+ meta: { fileName }
276
+ };
277
+ }
278
+ if (id.endsWith(".d.ts") && importer.endsWith(".d.ts")) {
279
+ const gtsFile = fileName.replace(".d.ts", ".gts");
280
+ if (virtualFiles.has(gtsFile)) return fileName;
281
+ }
282
+ if (id.endsWith(".ts") && !importer.endsWith(".d.ts")) {
283
+ const gtsFileName = fileName.replace(/\.ts$/, ".gts");
284
+ if (existsSync(gtsFileName) && !existsSync(fileName)) {
285
+ virtualFiles.add(gtsFileName);
286
+ return {
287
+ id: fileName,
288
+ meta: { fileName: gtsFileName }
289
+ };
290
+ }
291
+ }
292
+ if (id.endsWith(".js") && !importer.endsWith(".d.ts")) {
293
+ const gjsFileName = fileName.replace(/\.js$/, ".gjs");
294
+ if (existsSync(gjsFileName) && !existsSync(fileName)) {
295
+ virtualFiles.add(gjsFileName);
296
+ return {
297
+ id: fileName,
298
+ meta: { fileName: gjsFileName }
299
+ };
300
+ }
301
+ }
302
+ return null;
303
+ }
304
+ },
305
+ load: {
306
+ order: "pre",
307
+ filter: { id: /\.(ts|js)$/ },
308
+ async handler(id) {
309
+ const fileName = (this.getModuleInfo(id)?.meta ?? {})?.fileName;
310
+ if (fileName) {
311
+ this.addWatchFile(fileName);
312
+ const source = await readFile(fileName, { encoding: "utf8" });
313
+ if (source.includes("<template>")) {
314
+ const { code, map } = processor.process(source, { filename: fileName });
315
+ return {
316
+ code,
317
+ map
318
+ };
319
+ }
320
+ return source;
321
+ }
322
+ return null;
323
+ }
324
+ },
325
+ transform: {
326
+ order: "pre",
327
+ filter: {
328
+ code: /\.gts/,
329
+ id: /\.(js|ts)$/
330
+ },
331
+ handler(input, id) {
332
+ if (input.includes(".gts") && id.endsWith(".d.ts")) return input.replace(/(['"`])((?:\.\.?\/|\/|@|[A-Za-z0-9_\-])[^'"]*?\.gts)\1/g, (_m, q, p) => `${q}${p.replace(/\.gts$/, ".d.ts")}${q}`);
333
+ if (input.includes(".gts") && !id.endsWith(".d.ts")) return input.replace(/(['"`])((?:\.\.?\/|\/|@|[A-Za-z0-9_\-])[^'"]*?\.gts)\1/g, (_m, q, p) => `${q}${p.replace(/\.gts$/, ".ts")}${q}`);
334
+ return input;
335
+ }
336
+ },
337
+ writeBundle: { async handler(options) {
338
+ const outDir = options.dir;
339
+ if (outDir) await fixDtsExtensionsInDir(path.resolve(outDir));
340
+ } }
341
+ };
342
+ }
343
+ //#endregion
344
+ //#region index.ts
345
+ /**
346
+ * A batteries-included plugin for building Ember v2 libraries (addons) with
347
+ * rolldown (or tsdown, which is built on rolldown).
348
+ *
349
+ * It bundles everything needed to compile `.gts`/`.gjs` and template-tag
350
+ * (`<template>`) source into publishable output:
351
+ *
352
+ * - `emberConfig()` — applies sensible tsdown defaults for a library build
353
+ * (sourcemaps, `clean`, `dts`, `.js`/`.d.ts` extensions, quiet logging);
354
+ * anything you set explicitly still wins.
355
+ * - `emberIsolatedDeclarations()` — errors when a tsconfig.json is present
356
+ * without `isolatedDeclarations: true` (required: it is the only
357
+ * declaration pipeline that can see compiled template-tag modules).
358
+ * - `emberExternals()` — keeps your dependencies, peerDependencies, and the
359
+ * ember virtual packages external, so consuming apps resolve them.
360
+ * - `emberTransform()` — preprocesses `<template>` via content-tag and maps
361
+ * `.gts`/`.gjs` to `.ts`/`.js` so rolldown can understand them.
362
+ * - `emberBabel()` — runs babel (template compilation, decorators, type
363
+ * stripping) with `babelHelpers: "bundled"`, but only on the files that
364
+ * actually need it (via `maybeBabel`); everything else stays on the fast
365
+ * native transform. The library's own `babel.config.js` is used when it
366
+ * exists; no config file is required.
367
+ *
368
+ * Usage in `tsdown.config.js` (import `defineConfig` from `tsdown` — or from
369
+ * `rolldown` for a `rolldown.config.js` — so it carries the correct types):
370
+ *
371
+ * ```js
372
+ * import { defineConfig } from "tsdown";
373
+ * import { ember } from "@nullvoxpopuli/ember-rolldown";
374
+ *
375
+ * export default defineConfig({
376
+ * entry: ["./src/index.ts"],
377
+ * plugins: [ember()],
378
+ * });
379
+ * ```
380
+ */
381
+ function ember(config = {}) {
382
+ return [
383
+ emberConfig(),
384
+ emberIsolatedDeclarations(),
385
+ emberExternals(),
386
+ emberTransform(),
387
+ emberBabel(config.babel)
388
+ ];
389
+ }
390
+ //#endregion
391
+ export { ember };
package/index.ts CHANGED
@@ -1,12 +1,11 @@
1
1
  import type { Plugin } from "rolldown";
2
2
 
3
3
  import { emberBabel, type BabelOptions } from "./src/babel.ts";
4
+ import { emberConfig } from "./src/config.ts";
4
5
  import { emberExternals } from "./src/externals.ts";
5
6
  import { emberIsolatedDeclarations } from "./src/isolated-declarations.ts";
6
7
  import { emberTransform } from "./src/transform.ts";
7
8
 
8
- export { defineConfig } from "./src/define-config.ts";
9
-
10
9
  interface Config {
11
10
  /**
12
11
  * Options for the babel step; see `BabelOptions`.
@@ -21,6 +20,9 @@ interface Config {
21
20
  * It bundles everything needed to compile `.gts`/`.gjs` and template-tag
22
21
  * (`<template>`) source into publishable output:
23
22
  *
23
+ * - `emberConfig()` — applies sensible tsdown defaults for a library build
24
+ * (sourcemaps, `clean`, `dts`, `.js`/`.d.ts` extensions, quiet logging);
25
+ * anything you set explicitly still wins.
24
26
  * - `emberIsolatedDeclarations()` — errors when a tsconfig.json is present
25
27
  * without `isolatedDeclarations: true` (required: it is the only
26
28
  * declaration pipeline that can see compiled template-tag modules).
@@ -34,20 +36,22 @@ interface Config {
34
36
  * native transform. The library's own `babel.config.js` is used when it
35
37
  * exists; no config file is required.
36
38
  *
37
- * Usage in `tsdown.config.js` / `rolldown.config.js`:
39
+ * Usage in `tsdown.config.js` (import `defineConfig` from `tsdown` — or from
40
+ * `rolldown` for a `rolldown.config.js` — so it carries the correct types):
38
41
  *
39
42
  * ```js
43
+ * import { defineConfig } from "tsdown";
40
44
  * import { ember } from "@nullvoxpopuli/ember-rolldown";
41
45
  *
42
46
  * export default defineConfig({
43
47
  * entry: ["./src/index.ts"],
44
- * dts: true,
45
48
  * plugins: [ember()],
46
49
  * });
47
50
  * ```
48
51
  */
49
52
  export function ember(config: Config = {}): Plugin[] {
50
53
  return [
54
+ emberConfig(),
51
55
  emberIsolatedDeclarations(),
52
56
  emberExternals(),
53
57
  emberTransform(),
package/package.json CHANGED
@@ -1,12 +1,9 @@
1
1
  {
2
2
  "name": "@nullvoxpopuli/ember-rolldown",
3
- "version": "0.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "Meta plugin for building ember v2 libraries/addons with rolldown & tsdown.",
5
5
  "type": "module",
6
- "main": "index.ts",
7
- "publishConfig": {
8
- "main": "dist/index.js"
9
- },
6
+ "main": "dist/index.js",
10
7
  "keywords": [
11
8
  "rolldown",
12
9
  "tsdown",
@@ -22,19 +19,14 @@
22
19
  "url": "https://github.com/NullVoxPopuli/ember.nvp",
23
20
  "directory": "packages/rolldown"
24
21
  },
25
- "scripts": {
26
- "build": "rolldown --config",
27
- "prepack": "pnpm build"
28
- },
29
- "packageManager": "pnpm@10.28.0",
30
22
  "dependencies": {
31
23
  "@babel/core": "^7.28.10",
32
24
  "@babel/plugin-transform-typescript": "^7.28.10",
33
25
  "@embroider/core": "^4.4.2",
34
- "@nullvoxpopuli/ember-build-tooling-utils": "workspace:*",
35
26
  "babel-plugin-ember-template-compilation": "^4.0.0",
36
27
  "content-tag": "^4.2.0",
37
- "decorator-transforms": "^2.3.2"
28
+ "decorator-transforms": "^2.3.2",
29
+ "@nullvoxpopuli/ember-build-tooling-utils": "1.1.0"
38
30
  },
39
31
  "engines": {
40
32
  "node": ">= 24"
@@ -55,5 +47,8 @@
55
47
  "rolldown": "^1.1.2",
56
48
  "tsdown": "^0.22.7",
57
49
  "typescript": "^6.0.3"
50
+ },
51
+ "scripts": {
52
+ "build": "rolldown --config"
58
53
  }
59
- }
54
+ }
package/src/config.ts ADDED
@@ -0,0 +1,50 @@
1
+ import type { TsdownPlugin, UserConfig } from "tsdown";
2
+
3
+ /**
4
+ * Sensible defaults for an Ember v2 library, applied through plugin hooks so
5
+ * they travel with `ember()` — you get them whether you use this package's
6
+ * `defineConfig`, tsdown's, or a plain `tsdown.config.js` / `rolldown.config.js`.
7
+ *
8
+ * Every value is applied with `??=`, so anything you set explicitly wins.
9
+ *
10
+ * Under tsdown, the full set applies via the `tsdownConfig` hook (analogous to
11
+ * Vite's `config` hook):
12
+ *
13
+ * - `sourcemap` — emit sourcemaps alongside the output.
14
+ * - `clean` — wipe `dist/` between builds.
15
+ * - `dts` — emit `.d.ts` declarations (via isolated declarations).
16
+ * - `outExtensions` — `.js`/`.d.ts` rather than tsdown's default `.mjs`/`.d.mts`,
17
+ * since exports maps conventionally point at `.js`/`.d.ts`.
18
+ * - `report` — off; the size report is noise for a library build.
19
+ * - `deps.neverBundle` — leave node builtins and the ember virtual packages to
20
+ * the consuming app (`emberExternals()` handles the rest).
21
+ *
22
+ * A plain rolldown build has no notion of `clean`/`dts`/`outExtensions`/`report`
23
+ * (those are tsdown-level concepts), so only the options with rolldown
24
+ * equivalents are applied there, via rolldown's own `outputOptions` hook:
25
+ *
26
+ * - `output.sourcemap` — on (output option).
27
+ *
28
+ * Externals are handled by `emberExternals()` (a `resolveId` hook) in both cases.
29
+ */
30
+ export function emberConfig(): TsdownPlugin {
31
+ return {
32
+ name: "ember:config",
33
+
34
+ tsdownConfig(config: UserConfig) {
35
+ config.sourcemap ??= true;
36
+ config.clean ??= true;
37
+ config.dts ??= true;
38
+ config.outExtensions ??= () => ({ js: ".js", dts: ".d.ts" });
39
+ config.report ??= false;
40
+
41
+ config.deps ??= {};
42
+ config.deps.neverBundle ??= ["node:*", "@ember/*", "@glimmer/*"];
43
+ },
44
+
45
+ outputOptions(options) {
46
+ options.sourcemap ??= true;
47
+ return options;
48
+ },
49
+ };
50
+ }
@@ -1,32 +0,0 @@
1
- import type { UserConfig } from "tsdown";
2
-
3
- /**
4
- * tsdown's config, set up for an Ember v2 library: builds your entry to
5
- * `dist/*.js` and `dist/*.d.ts` with sourcemaps, cleaning `dist/` between
6
- * builds and leaving the ember virtual packages to the consuming app.
7
- *
8
- * You choose the `entry` and the `plugins` (e.g. `ember()`); any tsdown
9
- * option you pass wins.
10
- *
11
- * ```js
12
- * import { defineConfig, ember } from "@nullvoxpopuli/ember-rolldown";
13
- *
14
- * export default defineConfig({
15
- * entry: ["./src/index.ts"],
16
- * plugins: [ember()],
17
- * });
18
- * ```
19
- */
20
- export function defineConfig(config: UserConfig): UserConfig {
21
- return {
22
- sourcemap: true,
23
- clean: true,
24
- dts: true,
25
- // tsdown's extensions are .mjs/.d.mts otherwise, even in type-module
26
- // packages; exports maps conventionally point at .js/.d.ts
27
- outExtensions: () => ({ js: ".js", dts: ".d.ts" }),
28
- // provided by the consuming app
29
- neverBundle: ["node:*", "@ember/*", "@glimmer/*"],
30
- ...config,
31
- };
32
- }