@nullvoxpopuli/ember-rolldown 2.12.0 → 2.13.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/README.md +6 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -6
- package/dist/index.js.map +1 -1
- package/index.ts +3 -0
- package/package.json +1 -1
- package/src/config.test.ts +78 -0
- package/src/config.ts +19 -0
- package/src/isolated-declarations.ts +28 -28
package/README.md
CHANGED
|
@@ -206,6 +206,12 @@ module graph. Without it, the bundled CSS is emitted but nothing loads it.
|
|
|
206
206
|
|
|
207
207
|
`ember()` returns an array of rolldown plugins:
|
|
208
208
|
|
|
209
|
+
- **`emberConfig()`** applies the library-build defaults (sourcemaps,
|
|
210
|
+
`clean`, `dts`, `.js` / `.d.ts` extensions). It also turns off rolldown's
|
|
211
|
+
constant inlining (`optimization.inlineConst`). The rolldown default puts an
|
|
212
|
+
imported constant's literal into `precompileTemplate` scope objects, and the
|
|
213
|
+
consuming app's template compiler accepts only direct references there.
|
|
214
|
+
Anything you set explicitly still wins.
|
|
209
215
|
- **`emberIsolatedDeclarations()`** errors when the tsconfig the build uses
|
|
210
216
|
(tsdown's `tsconfig` option, defaulting to `tsconfig.json`) is present without
|
|
211
217
|
`isolatedDeclarations: true`.
|
package/dist/index.d.ts
CHANGED
|
@@ -97,6 +97,9 @@ interface Config {
|
|
|
97
97
|
* - `emberConfig()`
|
|
98
98
|
* applies sensible tsdown defaults for a library build
|
|
99
99
|
* (sourcemaps, `clean`, `dts`, `.js` / `.d.ts` extensions, quiet logging).
|
|
100
|
+
* It also turns off rolldown's constant inlining.
|
|
101
|
+
* Inlined literals break `precompileTemplate` scope objects,
|
|
102
|
+
* which must hold direct references.
|
|
100
103
|
* Anything you set explicitly still wins.
|
|
101
104
|
*
|
|
102
105
|
* - `emberIsolatedDeclarations()`
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/babel.ts","../index.ts"],"mappings":";;;;UAWiB;;;;;;;;;;;;;;EAcf;EACA;;;;;;;;;;;;;;EAcA;;;;EAIA,UAAU;;;;;;;;;;EAUV,qBAAqB;;;;;;;EAOrB;IACE;MACE;MACA,gBAAgB;;;;;;UCxDZ;;;;;;;;;;;;;;;;;;;EAmBR;;;;;EAKA,QAAQ
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/babel.ts","../index.ts"],"mappings":";;;;UAWiB;;;;;;;;;;;;;;EAcf;EACA;;;;;;;;;;;;;;EAcA;;;;EAIA,UAAU;;;;;;;;;;EAUV,qBAAqB;;;;;;;EAOrB;IACE;MACE;MACA,gBAAgB;;;;;;UCxDZ;;;;;;;;;;;;;;;;;;;EAmBR;;;;;EAKA,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyDM,MAAM,SAAQ,SAAc"}
|
package/dist/index.js
CHANGED
|
@@ -333,6 +333,19 @@ function emberBundle() {
|
|
|
333
333
|
*
|
|
334
334
|
* - `output.sourcemap` — on
|
|
335
335
|
*
|
|
336
|
+
* One default applies through rolldown's `options` hook,
|
|
337
|
+
* so it holds under both tools:
|
|
338
|
+
*
|
|
339
|
+
* - `optimization.inlineConst` — off.
|
|
340
|
+
* Rolldown's default (`mode: "smart"`) puts an imported constant's literal
|
|
341
|
+
* into `precompileTemplate` scope objects:
|
|
342
|
+
* `scope: () => ({ EMPTY })` becomes `scope: () => ({ EMPTY: "—" })`.
|
|
343
|
+
* The consuming app's template compiler accepts only direct references there.
|
|
344
|
+
* The library still builds, type-checks, and lints clean,
|
|
345
|
+
* so the app boot is the first place the error shows.
|
|
346
|
+
* The compiler-side fix, which accepts literal scope values, is
|
|
347
|
+
* https://github.com/emberjs/babel-plugin-ember-template-compilation/pull/125
|
|
348
|
+
*
|
|
336
349
|
* Externals are handled by `emberExternals()` (a `resolveId` hook) in both cases.
|
|
337
350
|
*
|
|
338
351
|
* Bundle mode flips the dependency defaults.
|
|
@@ -372,6 +385,11 @@ function emberConfig({ bundle = false } = {}) {
|
|
|
372
385
|
"@glimmer/*"
|
|
373
386
|
];
|
|
374
387
|
},
|
|
388
|
+
options(options) {
|
|
389
|
+
options.optimization ??= {};
|
|
390
|
+
options.optimization.inlineConst ??= false;
|
|
391
|
+
return options;
|
|
392
|
+
},
|
|
375
393
|
outputOptions(options) {
|
|
376
394
|
options.sourcemap ??= true;
|
|
377
395
|
return options;
|
|
@@ -443,12 +461,21 @@ function resolveTsconfigPath(option) {
|
|
|
443
461
|
*/
|
|
444
462
|
function emberIsolatedDeclarations() {
|
|
445
463
|
let tsconfigOption;
|
|
446
|
-
let emitsDeclarations = true;
|
|
447
464
|
return {
|
|
448
465
|
name: "ember:isolated-declarations",
|
|
449
466
|
tsdownConfig(config) {
|
|
450
467
|
tsconfigOption = config.tsconfig;
|
|
451
|
-
|
|
468
|
+
},
|
|
469
|
+
/**
|
|
470
|
+
* Runs after every plugin's `tsdownConfig`, so `dts` is final here.
|
|
471
|
+
*
|
|
472
|
+
* Must run before the build starts:
|
|
473
|
+
* tsdown sets up rolldown-plugin-dts while it resolves build options,
|
|
474
|
+
* and without a tsconfig that throws before any `buildStart` hook.
|
|
475
|
+
*/
|
|
476
|
+
tsdownConfigResolved(config) {
|
|
477
|
+
if (config.tsconfig !== false || !config.dts) return;
|
|
478
|
+
throw new Error("`tsconfig: false` cannot be combined with declaration emit.\n\nDeclarations are emitted by the isolated-declarations pipeline, which needs a tsconfig setting \"compilerOptions.isolatedDeclarations\": true -- it is the only pipeline that can see compiled .gts/.gjs modules.\n\nEither point tsdown's `tsconfig` option at such a config, or set `dts: false` if this library ships no types.");
|
|
452
479
|
},
|
|
453
480
|
buildStart: {
|
|
454
481
|
/**
|
|
@@ -460,10 +487,6 @@ function emberIsolatedDeclarations() {
|
|
|
460
487
|
*/
|
|
461
488
|
order: "pre",
|
|
462
489
|
async handler() {
|
|
463
|
-
if (tsconfigOption === false) {
|
|
464
|
-
if (!emitsDeclarations) return;
|
|
465
|
-
this.error("`tsconfig: false` cannot be combined with declaration emit.\n\nDeclarations are emitted by the isolated-declarations pipeline, which needs a tsconfig setting \"compilerOptions.isolatedDeclarations\": true -- it is the only pipeline that can see compiled .gts/.gjs modules.\n\nEither point tsdown's `tsconfig` option at such a config, or set `dts: false` if this library ships no types.");
|
|
466
|
-
}
|
|
467
490
|
const tsconfigPath = resolveTsconfigPath(tsconfigOption);
|
|
468
491
|
if (!tsconfigPath || !existsSync(tsconfigPath)) return;
|
|
469
492
|
let tsconfig;
|
|
@@ -672,6 +695,9 @@ function emberTransform() {
|
|
|
672
695
|
* - `emberConfig()`
|
|
673
696
|
* applies sensible tsdown defaults for a library build
|
|
674
697
|
* (sourcemaps, `clean`, `dts`, `.js` / `.d.ts` extensions, quiet logging).
|
|
698
|
+
* It also turns off rolldown's constant inlining.
|
|
699
|
+
* Inlined literals break `precompileTemplate` scope objects,
|
|
700
|
+
* which must hold direct references.
|
|
675
701
|
* Anything you set explicitly still wins.
|
|
676
702
|
*
|
|
677
703
|
* - `emberIsolatedDeclarations()`
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/babel.ts","../src/externals.ts","../src/bundle.ts","../src/config.ts","../src/isolated-declarations.ts","../src/transform.ts","../index.ts"],"sourcesContent":["import { maybeBabel } from \"@nullvoxpopuli/ember-build-tooling-utils\";\nimport transformTypeScript from \"@babel/plugin-transform-typescript\";\nimport templateCompilation from \"babel-plugin-ember-template-compilation\";\nimport decoratorTransforms from \"decorator-transforms\";\nimport { loadPartialConfigSync } from \"@babel/core\";\nimport { existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { PluginItem } from \"@babel/core\";\nimport type { Transform } from \"babel-plugin-ember-template-compilation\";\nimport type { Plugin } from \"rolldown\";\n\nexport interface BabelOptions {\n /**\n * Compile templates to the wire format instead of `precompileTemplate`.\n *\n * For a build that bundles its own ember-source.\n * The wire format is private between one template compiler and one\n * glimmer runtime of the same version, so this is only safe when both\n * ship together.\n *\n * The compiler is ember-source's own, resolved from the package.\n *\n * Set by `ember({ bundle: true })`.\n * Only applies without a babel config file.\n */\n bundle?: boolean;\n babelHelpers?: \"bundled\" | \"runtime\" | \"inline\" | \"external\";\n /**\n * The babel config file to use.\n *\n * - `undefined`: auto-detect.\n * A `babel.publish.config.*` (in the package root or `config/`) wins,\n * because this is a publish build.\n * Otherwise babel's own config resolution applies (see `detectConfigFile`).\n * - a string: use that config file.\n * - `false`: ignore config files entirely.\n *\n * Without a config file, templates, decorators, and TypeScript are still handled\n * (see `defaultPlugins`).\n */\n configFile?: string | false;\n /**\n * Extra babel plugins to run, appended after the config's plugins.\n */\n plugins?: PluginItem[];\n /**\n * Template AST transforms passed to the default\n * `babel-plugin-ember-template-compilation` entry.\n * e.g. ember-scoped-css's `scopedCSS.template()`\n *\n * Only valid without a babel config file.\n * With your own config, you list `babel-plugin-ember-template-compilation` yourself,\n * so its `transforms` belong there.\n */\n templateTransforms?: Transform[];\n /**\n * Opt additional files into babel (see maybeBabel's `filter`).\n *\n * Use this to cover addons that ship code needing babel\n * (e.g. `ember-concurrency`).\n */\n filter?: {\n include: {\n imports: string[];\n code: (string | RegExp)[];\n };\n };\n}\n\n/**\n * Tried in order, so an ESM config wins over a JSON one of the same name.\n */\nconst PUBLISH_CONFIG_EXTENSIONS = [\"mjs\", \"cjs\", \"js\", \"mts\", \"cts\", \"ts\", \"json\"];\n\n/**\n * Tried in order:\n * - next to package.json first\n * - then `config/`, for libraries that keep their build configuration\n * out of the package root\n */\nconst PUBLISH_CONFIG_DIRECTORIES = [\".\", \"config\"];\n\n/**\n * A `babel.publish.config.*` (in the package root or `config/`), if there is one.\n *\n * A library's plain `babel.config.*` is its *development* config.\n * It typically:\n * - compiles `@embroider/macros` away\n * - targets the wire format\n * - wires up whatever the in-package demo app or test suite needs\n *\n * None of that belongs in a published artifact:\n * - macros must stay, for the consuming app to evaluate\n * - the wire format is private between one template compiler and one glimmer runtime\n *\n * Babel's own resolution can't tell the two apart (it finds whatever `babel.config.*` exists),\n * so a publish build has to prefer the config named for publishing.\n */\nfunction detectPublishConfigFile(): string | undefined {\n for (const directory of PUBLISH_CONFIG_DIRECTORIES) {\n for (const extension of PUBLISH_CONFIG_EXTENSIONS) {\n const candidate = resolve(directory, `babel.publish.config.${extension}`);\n\n if (existsSync(candidate)) return candidate;\n }\n }\n\n return undefined;\n}\n\n/**\n * The config this publish build must use:\n * - a `babel.publish.config.*`, when the library has one\n * - else the project's root babel config, resolved the way babel itself does\n * (`babel.config.{js,cjs,mjs,cts,json}`, honoring `rootMode` semantics)\n *\n * For a library whose only config *is* its publish config,\n * that is the same file either way.\n *\n * The sync API evaluates the config file.\n * On node 24+ that works for native ESM configs too (require(esm)).\n */\nfunction detectConfigFile(): string | undefined {\n const publishConfig = detectPublishConfigFile();\n\n if (publishConfig) return publishConfig;\n\n const partial = loadPartialConfigSync({ cwd: process.cwd() });\n\n return partial?.config ?? undefined;\n}\n\n/**\n * Everything a library without its own babel config needs:\n *\n * - TypeScript stripping\n *\n * - template compilation to `precompileTemplate` (`targetFormat: \"hbs\"`).\n * Published libraries must NOT ship wire format.\n * The wire format is private between the template compiler and the glimmer runtime\n * of the same version, so baking it in ties the published artifact\n * to the consuming app's exact ember-source.\n * The consuming app performs final compilation.\n *\n * A bundle-mode build ships that exact ember-source,\n * so it compiles to the wire format with ember-source's own compiler,\n * and needs no compiler at runtime.\n *\n * - decorator-transforms, with its runtime left as a bare specifier\n * so the consuming app resolves it.\n * (the library keeps `decorator-transforms` as a real dependency)\n *\n * A bundle-mode build resolves it itself.\n */\nfunction defaultPlugins(templateTransforms?: Transform[], bundle = false): PluginItem[] {\n return [\n [\n transformTypeScript,\n {\n allExtensions: true,\n onlyRemoveTypeImports: true,\n allowDeclareFields: true,\n },\n ],\n [\n templateCompilation,\n { targetFormat: bundle ? \"wire\" : \"hbs\", transforms: templateTransforms ?? [] },\n ],\n [\n decoratorTransforms,\n {\n // Emit `import ... from \"decorator-transforms/runtime-esm\"` as a bare specifier,\n // so it stays external and the consuming app resolves it.\n runtime: { import: \"decorator-transforms/runtime-esm\" },\n },\n ],\n ];\n}\n\n/**\n * We still need babel (not just oxc / rolldown's native transforms) for two reasons:\n *\n * - template compilation.\n * `babel-plugin-ember-template-compilation` turns the content-tag output\n * into `precompileTemplate` calls.\n * oxc has no equivalent.\n *\n * - decorators.\n * Ember uses the legacy / stage-1 decorator signature together with `decorator-transforms`,\n * which rewrites decorated class fields (`@tracked x`) into getter / setters backed by a runtime.\n * oxc's native \"legacy decorators\" emit tsc-style `__decorate` output,\n * which does not match those semantics.\n *\n * But we don't want to send *every* file through babel\n * and give back the speed rolldown / oxc buys us.\n *\n * So we run babel via `maybeBabel`, which filters down to only the files that need it\n * (template-tag, decorators, template imports).\n * Everything else stays on the native transform.\n *\n * The library's own babel config is used when it exists.\n * Its `babel.publish.config.*` (root or `config/`) wins over its `babel.config.*`,\n * since this is a publish build.\n *\n * Without one, `defaultPlugins` covers templates, decorators, and TypeScript,\n * so no config file is required.\n *\n * Libraries default to `babelHelpers: \"bundled\"`, so the emitted output is self-contained.\n */\nexport function emberBabel(options: BabelOptions = {}): Plugin {\n const configFile = options.configFile === undefined ? detectConfigFile() : options.configFile;\n\n const shared = {\n babelHelpers: options.babelHelpers ?? \"bundled\",\n filter: options.filter,\n };\n\n if (configFile) {\n if (options.templateTransforms?.length) {\n throw new Error(\n `\\`babel.templateTransforms\\` cannot be combined with a babel config file (found ${configFile}). ` +\n `Your config lists babel-plugin-ember-template-compilation itself, so pass the transforms ` +\n `to its \\`transforms\\` option there instead.`,\n );\n }\n\n return maybeBabel({\n ...shared,\n configFile,\n plugins: options.plugins ?? [],\n }) as unknown as Plugin;\n }\n\n return maybeBabel({\n ...shared,\n // No config file (or the caller opted out).\n // Don't let babel go looking for one: we provide the whole plugin list inline.\n configFile: false,\n babelrc: false,\n plugins: defaultPlugins(options.templateTransforms, options.bundle).concat(\n options.plugins ?? [],\n ),\n }) as unknown as Plugin;\n}\n","import { readFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\n\nimport type { Plugin } from \"rolldown\";\n\n// @embroider/core is cjs, so we default-import and destructure.\nimport pkg from \"@embroider/core\";\nconst { emberVirtualPackages, emberVirtualPeerDeps, packageName, templateCompilationModules } = pkg;\n\nconst compilationModules = new Set(templateCompilationModules.map((m) => m.module));\n\n/**\n * @param {string} path\n */\nfunction readJsonSync(path: string) {\n return JSON.parse(readFileSync(path, { encoding: \"utf8\" }));\n}\n\n/**\n * Everything the library declares as a `dependency` or `peerDependency`\n * is resolvable by the consuming app, so we never bundle it.\n */\nfunction resolvableDependencies(): Set<string> {\n const deps = new Set<string>();\n const manifest = readJsonSync(\"package.json\");\n\n for (const name of Object.keys(manifest.dependencies ?? {})) {\n deps.add(name);\n }\n for (const name of Object.keys(manifest.peerDependencies ?? {})) {\n deps.add(name);\n }\n\n return deps;\n}\n\n/**\n * The modules ember-source provides by renaming them into itself.\n *\n * This is its `ember-addon.renamed-modules`, keyed by module file path:\n * `@glimmer/runtime/index.js` → `ember-source/@glimmer/runtime/index.js`\n *\n * It is the authoritative list of ember's provided modules.\n * It includes private API that @embroider/core's emberVirtualPackages\n * doesn't cover (e.g. `@glimmer/runtime`).\n *\n * It deliberately does NOT include real packages like `@glimmer/component`,\n * which a library may want bundled.\n *\n * Empty when ember-source isn't resolvable from the library.\n */\nexport function emberSourceRenamedModules(): Record<string, string> {\n try {\n const require = createRequire(path.resolve(\"package.json\"));\n const manifest = require(\"ember-source/package.json\") as {\n \"ember-addon\"?: { \"renamed-modules\"?: Record<string, string> };\n };\n\n return manifest[\"ember-addon\"]?.[\"renamed-modules\"] ?? {};\n } catch {\n // The library doesn't have ember-source in its graph; nothing to provide.\n return {};\n }\n}\n\n/**\n * The renamed modules as import specifiers\n * `@glimmer/runtime/index.js` → `@glimmer/runtime`\n */\nfunction emberSourceProvidedModules(): Set<string> {\n const provided = new Set<string>();\n\n for (const key of Object.keys(emberSourceRenamedModules())) {\n provided.add(key.replace(/\\.js$/, \"\").replace(/\\/index$/, \"\"));\n }\n\n return provided;\n}\n\n/**\n * Keeps external:\n * - the library's declared dependencies\n * - the ember virtual packages\n * (things like `@ember/component`, `@glimmer/tracking`, the template compiler, …)\n *\n * So the app that consumes the library resolves them,\n * instead of the library bundling copies of them.\n */\nexport function emberExternals(): Plugin {\n let deps: Set<string>;\n let renamedModules: Set<string>;\n\n return {\n name: \"ember:externals\",\n\n buildStart() {\n this.addWatchFile(\"package.json\");\n deps = resolvableDependencies();\n renamedModules = emberSourceProvidedModules();\n },\n\n resolveId: {\n order: \"pre\",\n handler(source) {\n // Anything with a protocol (`node:`, virtual modules, …)\n // is not ours to externalize.\n if (source.includes(\":\")) {\n return null;\n }\n\n const pkgName = packageName(source);\n\n if (!pkgName) {\n // No package name means a relative import, which we don't deal with.\n return null;\n }\n\n if (\n deps.has(pkgName) ||\n emberVirtualPeerDeps.has(pkgName) ||\n emberVirtualPackages.has(pkgName) ||\n compilationModules.has(pkgName)\n ) {\n // `false` tells rolldown to treat the id as external.\n return false;\n }\n\n // Modules ember-source provides by renaming them into itself\n // (`ember-addon.renamed-modules`).\n //\n // Private API like `@glimmer/runtime`,\n // which only exists inside the app's ember-source.\n //\n // Matched on the full specifier:\n // the renamed modules are module paths, not packages.\n if (renamedModules.has(source)) {\n return false;\n }\n\n return undefined;\n },\n },\n };\n}\n","import type { Plugin } from \"rolldown\";\n\nimport { emberSourceRenamedModules } from \"./externals.ts\";\n\n/**\n * The package name a renamed-modules key belongs to\n * `@ember/modifier/on.js` → `@ember/modifier`\n * `rsvp/index.js` → `rsvp`\n */\nfunction packageOf(modulePath: string): string {\n const segments = modulePath.split(\"/\");\n const length = modulePath.startsWith(\"@\") ? 2 : 1;\n\n return segments.slice(0, length).join(\"/\");\n}\n\n/**\n * One alias per package ember-source provides, pointing into ember-source\n * `@ember/modifier` → `ember-source/@ember/modifier`\n *\n * The provided packages are the ones named in `ember-addon.renamed-modules`\n * (`@ember/*`, `@glimmer/tracking`, `rsvp`, `backburner.js`, …).\n *\n * Real packages such as `@glimmer/component` are not in it,\n * so they keep resolving from node_modules.\n */\nexport function emberSourceAliases(): Record<string, string> {\n const aliases: Record<string, string> = {};\n\n for (const modulePath of Object.keys(emberSourceRenamedModules())) {\n const name = packageOf(modulePath);\n\n aliases[name] = `ember-source/${name}`;\n }\n\n return aliases;\n}\n\n/**\n * Makes the modules ember-source provides resolvable,\n * so a bundle-mode build can include them.\n *\n * ember-source exports every module under `./*`,\n * with `development` and `production` conditions selecting one of its two builds.\n *\n * A bare `@ember/modifier` is not that path, though.\n * It only exists as `ember-source/@ember/modifier`.\n *\n * So this plugin adds the alias for each provided package,\n * and leaves the rest to the resolver:\n * - the `default` condition selects the production build\n * - `resolve.conditionNames: [\"development\"]` selects the development build\n * (tsdown: `inputOptions.resolve.conditionNames`)\n *\n * Aliases set explicitly in the build config win over these.\n */\nexport function emberBundle(): Plugin {\n return {\n name: \"ember:bundle\",\n\n options(inputOptions) {\n inputOptions.resolve ??= {};\n inputOptions.resolve.alias = {\n ...emberSourceAliases(),\n ...inputOptions.resolve.alias,\n };\n\n return inputOptions;\n },\n };\n}\n","import type { TsdownPlugin, UserConfig } from \"tsdown\";\n\n/**\n * Sensible defaults for an Ember v2 library.\n *\n * Applied through plugin hooks, so they travel with `ember()`.\n * You get them whether you use this package's `defineConfig`, tsdown's,\n * or a plain `tsdown.config.js` / `rolldown.config.js`.\n *\n * Every value is applied with `??=`, so anything you set explicitly wins.\n *\n * Under tsdown, the full set applies via the `tsdownConfig` hook\n * (analogous to Vite's `config` hook):\n *\n * - `sourcemap` — emit sourcemaps alongside the output\n * - `clean` — wipe `dist/` between builds\n * - `dts` — emit `.d.ts` declarations (via isolated declarations)\n * - `outExtensions` — `.js` / `.d.ts` rather than tsdown's default `.mjs` / `.d.mts`\n * (exports maps conventionally point at `.js` / `.d.ts`)\n * - `report` — off.\n * The size report is noise for a library build.\n * - `deps.neverBundle` — leave node builtins and the ember virtual packages\n * to the consuming app (`emberExternals()` handles the rest)\n *\n * A plain rolldown build has no notion of `clean` / `dts` / `outExtensions` / `report`.\n * Those are tsdown-level concepts.\n * So only the options with rolldown equivalents are applied there,\n * via rolldown's own `outputOptions` hook:\n *\n * - `output.sourcemap` — on\n *\n * Externals are handled by `emberExternals()` (a `resolveId` hook) in both cases.\n *\n * Bundle mode flips the dependency defaults.\n * The output is a self-contained browser artifact, so:\n *\n * - `platform` — `browser`\n * - `deps.alwaysBundle` — everything but node builtins\n * (including the package's own `dependencies` and `peerDependencies`,\n * and the declarations' type imports)\n * - `deps.neverBundle` — node builtins only\n * - `deps.onlyBundle` — `false`\n * (bundling node_modules is the point, so tsdown's hint about it is noise)\n */\nexport function emberConfig({ bundle = false }: { bundle?: boolean } = {}): TsdownPlugin {\n return {\n name: \"ember:config\",\n\n tsdownConfig(config: UserConfig) {\n config.sourcemap ??= true;\n config.clean ??= true;\n config.dts ??= { sourcemap: true };\n config.outExtensions ??= () => ({ js: \".js\", dts: \".d.ts\" });\n config.report ??= false;\n\n config.deps ??= {};\n\n if (bundle) {\n config.platform ??= \"browser\";\n config.deps.alwaysBundle ??= (id) => !id.startsWith(\"node:\");\n config.deps.neverBundle ??= [\"node:*\"];\n config.deps.onlyBundle ??= false;\n return;\n }\n\n config.deps.neverBundle ??= [\"node:*\", \"@ember/*\", \"@glimmer/*\"];\n },\n\n outputOptions(options) {\n options.sourcemap ??= true;\n return options;\n },\n };\n}\n","import { existsSync, statSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\n\nimport { parseTsconfig, type TsConfigJsonResolved } from \"get-tsconfig\";\nimport type { Plugin } from \"rolldown\";\nimport type { UserConfig } from \"tsdown\";\n\n/**\n * Resolve the tsconfig the build will use.\n *\n * Mirrors tsdown's own `tsconfig` option (`string | boolean`):\n * - `undefined` / `true`: `tsconfig.json` in the cwd\n * - a path to a file: that file\n * - a path to a directory: `tsconfig.json` inside it\n * - `false`: no tsconfig at all\n *\n * Under plain rolldown there is no such option,\n * so the cwd's `tsconfig.json` is all there is.\n */\nfunction resolveTsconfigPath(option: string | boolean | undefined): string | undefined {\n if (option === false) return undefined;\n\n if (typeof option === \"string\") {\n const asPath = resolve(option);\n\n if (existsSync(asPath) && statSync(asPath).isDirectory()) {\n return resolve(asPath, \"tsconfig.json\");\n }\n\n return asPath;\n }\n\n return resolve(\"tsconfig.json\");\n}\n\n/**\n * Errors the build when the tsconfig it builds with\n * does not set `isolatedDeclarations: true`.\n *\n * This is required.\n * Declarations for `.gts` / `.gjs` (template tag) modules can only be emitted\n * by the isolated-declarations pipeline,\n * which reads compiled modules from the bundler's module graph.\n *\n * The `tsc`-based pipeline reads source files from disk.\n * The compiled modules don't exist there, so it fails with \"Source file not found\".\n *\n * Failing fast here, rather than only when declaration emit happens to run,\n * keeps the project honest.\n * Editors and `tsc` / `ember-tsc` then check the same rules the build enforces:\n * exported values need explicit type annotations,\n * e.g. `export const X: TOC<Sig> = <template>...`\n *\n * The tsconfig checked is the one tsdown's `tsconfig` option points at,\n * not necessarily `tsconfig.json`.\n *\n * So a library whose package also holds dev-only code (a demo app, in-package tests) can:\n * - keep a permissive `tsconfig.json` covering everything,\n * for editors and `tsc --noEmit`\n * - point the build at a `tsconfig.publish.json` that covers only the publishable sources\n *\n * Isolated declarations then constrain exactly the code that gets declarations emitted,\n * and nothing else.\n *\n * Projects with no tsconfig (JavaScript libraries) have no declarations to emit,\n * so there is nothing to check.\n *\n * The tsconfig is read without the `typescript` package.\n * TypeScript 7 has no JavaScript API, and a TypeScript 7 library can have no TypeScript 6.\n *\n * `tsconfig: false` is different.\n * It is an explicit opt-out.\n * Combined with declaration emit, it produces a confusing \"Source file not found\"\n * from the tsc-based pipeline, so it errors here instead.\n */\nexport function emberIsolatedDeclarations(): Plugin {\n let tsconfigOption: string | boolean | undefined;\n let emitsDeclarations = true;\n\n return {\n name: \"ember:isolated-declarations\",\n\n // Not called under plain rolldown, which leaves `tsconfigOption` undefined.\n // That means the cwd's tsconfig.json, the only thing it could mean there.\n tsdownConfig(config: UserConfig) {\n tsconfigOption = config.tsconfig;\n // `emberConfig()` turns dts on unless the library turned it off,\n // so an explicit `false` is the only \"no declarations\" signal.\n //\n // Hook order between plugins isn't guaranteed,\n // so don't rely on it having run.\n emitsDeclarations = config.dts !== false;\n },\n\n buildStart: {\n /**\n * Before rolldown-plugin-dts, whose buildStart loads the `typescript` package\n * when isolatedDeclarations is off.\n *\n * In a TypeScript 7 library that package is TypeScript 7, which has no JavaScript API,\n * so it crashes before this message can show.\n */\n order: \"pre\",\n async handler() {\n if (tsconfigOption === false) {\n if (!emitsDeclarations) return;\n\n // Without a tsconfig there is no `isolatedDeclarations`,\n // so tsdown falls back to the tsc-based declaration pipeline.\n //\n // That pipeline reads source files from disk,\n // and dies with \"Source file not found\" on every `.gts` / `.gjs`,\n // since those only exist compiled in the module graph.\n //\n // Say so here instead of leaving that to be decoded.\n this.error(\n `\\`tsconfig: false\\` cannot be combined with declaration emit.\\n\\n` +\n `Declarations are emitted by the isolated-declarations pipeline, which needs a ` +\n `tsconfig setting \"compilerOptions.isolatedDeclarations\": true -- it is the only ` +\n `pipeline that can see compiled .gts/.gjs modules.\\n\\n` +\n `Either point tsdown's \\`tsconfig\\` option at such a config, or set \\`dts: false\\` ` +\n `if this library ships no types.`,\n );\n }\n\n const tsconfigPath = resolveTsconfigPath(tsconfigOption);\n\n if (!tsconfigPath || !existsSync(tsconfigPath)) return;\n\n let tsconfig: TsConfigJsonResolved;\n\n try {\n // Resolves `extends` chains, so the flag may come from a base config.\n tsconfig = parseTsconfig(tsconfigPath);\n } catch {\n // Unreadable / unparsable tsconfig.\n // tsc itself will report this with a better message than we can.\n return;\n }\n\n if (tsconfig.compilerOptions?.isolatedDeclarations !== true) {\n this.error(\n `${tsconfigPath} must set \"compilerOptions.isolatedDeclarations\": true.\\n\\n` +\n `Declarations for .gts/.gjs (template tag) modules can only be emitted by the ` +\n `isolated-declarations pipeline, which reads compiled modules from the bundler's ` +\n `module graph -- the tsc-based pipeline reads from disk and cannot see them.\\n\\n` +\n `Isolated declarations require exported values to have explicit type annotations, ` +\n `e.g. \\`export const X: TOC<Sig> = <template>...\\`.\\n\\n` +\n `If this tsconfig also covers dev-only code (a demo app, in-package tests) that ` +\n `should not be constrained this way, point tsdown's \\`tsconfig\\` option at a ` +\n `publish-only tsconfig that sets the flag and covers just the published sources.`,\n );\n }\n },\n },\n };\n}\n","import remapping, { type EncodedSourceMap } from \"@jridgewell/remapping\";\nimport { Preprocessor } from \"content-tag\";\nimport MagicString from \"magic-string\";\nimport { existsSync, realpathSync } from \"node:fs\";\nimport { readFile, writeFile, readdir } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { Plugin } from \"rolldown\";\n\nconst processor = new Preprocessor();\n\n/**\n * `.d.ts` files emitted for `.gts` source reference the original `.gts` specifiers.\n *\n * Consumers can't resolve those,\n * so we rewrite them back to extension-less specifiers.\n */\nfunction fixDeclarationImports(content: string): string {\n return content\n .replace(/from\\s+'([^']+)\\.gts'/g, \"from '$1'\")\n .replace(/from\\s+\"([^\"]+)\\.gts\"/g, 'from \"$1\"')\n .replace(/import\\(\"([^\"]+)\\.gts\"\\)/g, 'import(\"$1\")')\n .replace(/import\\('([^']+)\\.gts'\\)/g, \"import('$1')\");\n}\n\nasync function fixDtsExtensionsInDir(dir: string): Promise<void> {\n const entries = await readdir(dir, { withFileTypes: true });\n\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n\n if (entry.isDirectory()) {\n await fixDtsExtensionsInDir(fullPath);\n } else if (entry.name.endsWith(\".d.ts\")) {\n const content = await readFile(fullPath, { encoding: \"utf8\" });\n const fixed = fixDeclarationImports(content);\n\n if (fixed !== content) {\n await writeFile(fullPath, fixed);\n }\n }\n }\n}\n\n/**\n * A sourcemap from `code` back to `source`, with a segment for every column.\n *\n * rolldown traces each output position back through the map of every hook.\n * A position between two segments resolves to the segment before it,\n * so fewer segments move positions to an earlier column.\n *\n * content-tag's output often puts a doc comment's end and a declaration on one line.\n * With one segment per line, the declaration resolves to the comment.\n */\nfunction columnMap(code: MagicString, source: string) {\n return code.generateMap({ source, includeContent: true, hires: true });\n}\n\n/**\n * The `.gts` / `.gjs` file behind a virtual `.ts` / `.js` id,\n * and content-tag's map back to it (absent when there was no `<template>` to compile).\n */\ninterface Backing {\n fileName: string;\n map?: string;\n}\n\n/**\n * Points a declaration map at the `.gts` / `.gjs` files behind its virtual sources.\n *\n * rolldown-plugin-dts generates declarations from the loaded module (content-tag's output).\n * So its maps name:\n * - the virtual id, a file that does not exist\n * - content-tag's line numbers, which do not match the source\n *\n * Tracing through content-tag's map gives the file and line\n * that a consumer's \"go to definition\" can open.\n *\n * Returns `undefined` when no source is virtual.\n */\nfunction remapDeclarationMap(\n json: string,\n mapDir: string,\n backings: Map<string, Backing>,\n): string | undefined {\n const map = JSON.parse(json) as EncodedSourceMap;\n\n if (!map.sources.some((source) => source && backings.has(path.resolve(mapDir, source)))) {\n return undefined;\n }\n\n const remapped = remapping(\n map,\n (source, context) => {\n // Only the declaration map's own sources can be virtual.\n if (context.depth > 1) return null;\n\n const backing = backings.get(path.resolve(mapDir, source));\n if (!backing) return null;\n\n context.source = backing.fileName;\n return backing.map ?? null;\n },\n // Like the rest of the declaration map, point at the published sources.\n // Do not embed them.\n { excludeContent: true },\n );\n\n // Backing files come back absolute.\n // The other sources are relative to the map's directory.\n remapped.sources = remapped.sources.map((source) =>\n source && path.isAbsolute(source)\n ? path.relative(mapDir, source).split(path.sep).join(\"/\")\n : source,\n );\n\n return remapped.toString();\n}\n\n/**\n * Preprocesses `<template>` via content-tag, and maps\n * `.gts` → `.ts`\n * `.gjs` → `.js`\n * so rolldown can identify them as ts / js.\n */\nexport function emberTransform(): Plugin {\n // virtual id -> what it was loaded from\n const backings = new Map<string, Backing>();\n\n return {\n name: \"ember:transform\",\n\n resolveId: {\n order: \"pre\",\n handler(id, importer) {\n // Entries have no importer.\n // Their ids come straight from the build config\n // (tsdown expands entry globs to on-disk paths).\n //\n // Resolve a `.gts` / `.gjs` entry to the same virtual `.ts` / `.js` id\n // an imported module gets, so the load hook compiles it via content-tag\n // instead of the raw `<template>` source hitting the parser.\n //\n // Entries may be any extension.\n // The emitted `.js` / `.d.ts` paths mirror the entry paths either way\n // (that's how tsdown's dts support works).\n if (!importer) {\n if (!id.endsWith(\".gts\") && !id.endsWith(\".gjs\")) return null;\n if (!existsSync(id)) return null;\n\n // rolldown's default resolver realpaths entry ids\n // (e.g. macOS /var -> /private/var).\n //\n // Match it, or this same file imported from another entry\n // resolves to a second module id and gets duplicated into both chunks.\n const fileName = realpathSync(path.resolve(id));\n\n return {\n id: fileName.replace(/\\.gts$/, \".ts\").replace(/\\.gjs$/, \".js\"),\n meta: { fileName },\n };\n }\n\n // An absolute specifier already names the file,\n // so it needs no importer-relative resolution.\n // Joining it onto the importer's directory would corrupt it.\n //\n // That is not hypothetical.\n // A plugin's virtual module (id prefixed with `\\0`)\n // can generate imports of on-disk files by absolute path,\n // and `path.dirname(\"\\0./registry\")` is `\"\\0.\"`.\n // Joining then yields `\"\\0./Users/.../thing.gts\"`:\n // a path no `existsSync` / `readFile` can accept (it has a null byte in it).\n const fileName = path.isAbsolute(id) ? id : path.join(path.dirname(importer), id);\n\n if (id.endsWith(\".gts\")) {\n return {\n id: fileName.replace(/\\.gts$/, \".ts\"),\n meta: { fileName },\n };\n }\n\n if (id.endsWith(\".gjs\")) {\n return {\n id: fileName.replace(/\\.gjs$/, \".js\"),\n meta: { fileName },\n };\n }\n\n // A `.ts` / `.js` specifier whose only backing file is a `.gts` / `.gjs`\n // resolves to the virtual module.\n //\n // This must also serve `.d.ts` importers.\n // rolldown-plugin-dts resolves a declaration module's imports\n // through the plugin pipeline (`this.resolve`).\n // When the resolution is a source file, it loads it (registering its declaration)\n // before mapping the import to the declaration id.\n //\n // Virtual modules exist nowhere else.\n // If we don't answer here, the import either:\n // - fails to resolve (no file on disk)\n // - or, worse, resolves to a declaration id that was never registered\n if (id.endsWith(\".ts\")) {\n const gtsFileName = fileName.replace(/\\.ts$/, \".gts\");\n if (existsSync(gtsFileName) && !existsSync(fileName)) {\n return { id: fileName, meta: { fileName: gtsFileName } };\n }\n }\n\n if (id.endsWith(\".js\")) {\n const gjsFileName = fileName.replace(/\\.js$/, \".gjs\");\n if (existsSync(gjsFileName) && !existsSync(fileName)) {\n return { id: fileName, meta: { fileName: gjsFileName } };\n }\n }\n\n return null;\n },\n },\n\n load: {\n order: \"pre\",\n filter: {\n id: /\\.(ts|js)$/,\n },\n async handler(id) {\n const meta = this.getModuleInfo(id)?.meta ?? {};\n let fileName = meta?.fileName;\n\n // A virtual id can be loaded without having passed through our resolveId\n // (rolldown-plugin-dts calls `this.load({ id })` with just the id),\n // so no meta is attached.\n //\n // Recover the backing file from disk.\n if (!fileName && !existsSync(id)) {\n if (id.endsWith(\".ts\") && existsSync(id.replace(/\\.ts$/, \".gts\"))) {\n fileName = id.replace(/\\.ts$/, \".gts\");\n } else if (id.endsWith(\".js\") && existsSync(id.replace(/\\.js$/, \".gjs\"))) {\n fileName = id.replace(/\\.js$/, \".gjs\");\n }\n }\n\n if (fileName) {\n this.addWatchFile(fileName);\n const source = await readFile(fileName, { encoding: \"utf8\" });\n\n if (source.includes(\"<template>\")) {\n const { code, map } = processor.process(source, {\n filename: fileName,\n });\n backings.set(id, { fileName, map });\n return { code, map };\n }\n\n // The map names the `.gts` / `.gjs` file.\n // Without it, the `.js.map` names the virtual id, which is not on disk.\n //\n // The backing needs no map, because its declaration lines match the source.\n backings.set(id, { fileName });\n return { code: source, map: columnMap(new MagicString(source), fileName) };\n }\n\n return null;\n },\n },\n\n transform: {\n order: \"pre\",\n filter: {\n code: /\\.gts/,\n id: /\\.(js|ts)$/,\n },\n handler(input, id) {\n // Rewrite `.gts` specifiers to `.ts`, the (virtual) source id,\n // in runtime modules AND declaration modules alike.\n //\n // Declaration modules must NOT be rewritten to `.d.ts`.\n // rolldown-plugin-dts's resolver treats a source-file resolution as\n // \"load it (registering its declaration), then map to the declaration id\".\n // A `.d.ts` id is returned as-is: unloadable when the module isn't registered yet\n // (e.g. the `.gts` is only ever type-imported).\n const output = new MagicString(input);\n\n for (const match of input.matchAll(\n /(['\"`])((?:\\.\\.?\\/|\\/|@|[A-Za-z0-9_\\-])[^'\"]*?\\.gts)\\1/g,\n )) {\n // `.gts` ends the specifier, just before the closing quote.\n const end = match.index + match[0].length - 1;\n output.overwrite(end - \".gts\".length, end, \".ts\");\n }\n\n if (!output.hasChanged()) {\n return null;\n }\n\n return { code: output.toString(), map: columnMap(output, id) };\n },\n },\n\n generateBundle(options, bundle) {\n const outDir = options.dir ?? (options.file && path.dirname(options.file));\n if (!outDir || backings.size === 0) return;\n\n for (const output of Object.values(bundle)) {\n if (output.type !== \"asset\" || !output.fileName.endsWith(\".d.ts.map\")) continue;\n if (typeof output.source !== \"string\") continue;\n\n const mapDir = path.dirname(path.resolve(outDir, output.fileName));\n const remapped = remapDeclarationMap(output.source, mapDir, backings);\n\n if (remapped) output.source = remapped;\n }\n },\n\n writeBundle: {\n async handler(options) {\n const outDir = (options as { dir?: string }).dir;\n if (outDir) {\n await fixDtsExtensionsInDir(path.resolve(outDir));\n }\n },\n },\n };\n}\n","import { emberBabel, type BabelOptions } from \"./src/babel.ts\";\nimport { emberBundle } from \"./src/bundle.ts\";\nimport { emberConfig } from \"./src/config.ts\";\nimport { emberExternals } from \"./src/externals.ts\";\nimport { emberIsolatedDeclarations } from \"./src/isolated-declarations.ts\";\nimport { emberTransform } from \"./src/transform.ts\";\nimport type { RolldownPluginLike } from \"./src/plugin-like.ts\";\n\ninterface Config {\n /**\n * Build a self-contained package instead of a library.\n *\n * `false` (the default) builds a library for Ember apps:\n * - ember, the package's dependencies, and its peerDependencies stay external\n * - templates are shipped as `precompileTemplate` calls,\n * for the consuming app to compile\n *\n * `true` builds an artifact that runs on any page, such as a custom element:\n * - ember-source, `@glimmer/component`, `decorator-transforms`,\n * and every other dependency are bundled in\n * - templates are compiled to the wire format with that same ember-source\n * - declarations bundle their type imports as well\n *\n * Which ember-source build is bundled follows the export conditions:\n * - production by default\n * - development with `resolve.conditionNames: [\"development\"]`\n */\n bundle?: boolean;\n /**\n * Options for the babel step.\n * See `BabelOptions`.\n */\n babel?: BabelOptions;\n}\n\n/**\n * A batteries-included plugin for building Ember v2 libraries (addons)\n * with rolldown, or with tsdown (which is built on rolldown).\n *\n * It bundles everything needed to compile `.gts` / `.gjs` and\n * template-tag (`<template>`) source into publishable output:\n *\n * - `emberConfig()`\n * applies sensible tsdown defaults for a library build\n * (sourcemaps, `clean`, `dts`, `.js` / `.d.ts` extensions, quiet logging).\n * Anything you set explicitly still wins.\n *\n * - `emberIsolatedDeclarations()`\n * errors when a tsconfig.json is present without `isolatedDeclarations: true`.\n * That is the only declaration pipeline that can see compiled template-tag modules.\n *\n * - `emberExternals()`\n * keeps your dependencies, peerDependencies, and the ember virtual packages external,\n * so consuming apps resolve them.\n *\n * - `emberBundle()`\n * bundle mode only, in place of `emberExternals()`.\n * Aliases the ember virtual packages into ember-source,\n * whose export conditions pick the build to bundle.\n *\n * - `emberTransform()`\n * preprocesses `<template>` via content-tag,\n * and maps `.gts` / `.gjs` to `.ts` / `.js` so rolldown can understand them.\n *\n * - `emberBabel()`\n * runs babel (template compilation, decorators, type stripping)\n * with `babelHelpers: \"bundled\"`.\n * Only the files that need it go through babel (via `maybeBabel`).\n * Everything else stays on the fast native transform.\n * The library's own `babel.config.js` is used when it exists.\n * No config file is required.\n *\n * Usage in `tsdown.config.js`.\n * Import `defineConfig` from `tsdown` (or from `rolldown` for a `rolldown.config.js`)\n * so it carries the correct types:\n *\n * ```js\n * import { defineConfig } from \"tsdown\";\n * import { ember } from \"@nullvoxpopuli/ember-rolldown\";\n *\n * export default defineConfig({\n * entry: [\"./src/index.ts\"],\n * plugins: [ember()],\n * });\n * ```\n */\nexport function ember(config: Config = {}): RolldownPluginLike[] {\n const bundle = config.bundle ?? false;\n\n return [\n emberConfig({ bundle }),\n emberIsolatedDeclarations(),\n bundle ? emberBundle() : emberExternals(),\n emberTransform(),\n emberBabel({ ...config.babel, bundle }),\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwEA,MAAM,4BAA4B;CAAC;CAAO;CAAO;CAAM;CAAO;CAAO;CAAM;AAAM;;;;;;;AAQjF,MAAM,6BAA6B,CAAC,KAAK,QAAQ;;;;;;;;;;;;;;;;;AAkBjD,SAAS,0BAA8C;CACrD,KAAK,MAAM,aAAa,4BACtB,KAAK,MAAM,aAAa,2BAA2B;EACjD,MAAM,YAAY,QAAQ,WAAW,wBAAwB,WAAW;EAExE,IAAI,WAAW,SAAS,GAAG,OAAO;CACpC;AAIJ;;;;;;;;;;;;;AAcA,SAAS,mBAAuC;CAC9C,MAAM,gBAAgB,wBAAwB;CAE9C,IAAI,eAAe,OAAO;CAI1B,OAFgB,sBAAsB,EAAE,KAAK,QAAQ,IAAI,EAAE,CAE9C,CAAC,EAAE,UAAU,KAAA;AAC5B;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAS,eAAe,oBAAkC,SAAS,OAAqB;CACtF,OAAO;EACL,CACE,qBACA;GACE,eAAe;GACf,uBAAuB;GACvB,oBAAoB;EACtB,CACF;EACA,CACE,qBACA;GAAE,cAAc,SAAS,SAAS;GAAO,YAAY,sBAAsB,CAAC;EAAE,CAChF;EACA,CACE,qBACA,EAGE,SAAS,EAAE,QAAQ,mCAAmC,EACxD,CACF;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAgB,WAAW,UAAwB,CAAC,GAAW;CAC7D,MAAM,aAAa,QAAQ,eAAe,KAAA,IAAY,iBAAiB,IAAI,QAAQ;CAEnF,MAAM,SAAS;EACb,cAAc,QAAQ,gBAAgB;EACtC,QAAQ,QAAQ;CAClB;CA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3,"file":"index.js","names":[],"sources":["../src/babel.ts","../src/externals.ts","../src/bundle.ts","../src/config.ts","../src/isolated-declarations.ts","../src/transform.ts","../index.ts"],"sourcesContent":["import { maybeBabel } from \"@nullvoxpopuli/ember-build-tooling-utils\";\nimport transformTypeScript from \"@babel/plugin-transform-typescript\";\nimport templateCompilation from \"babel-plugin-ember-template-compilation\";\nimport decoratorTransforms from \"decorator-transforms\";\nimport { loadPartialConfigSync } from \"@babel/core\";\nimport { existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { PluginItem } from \"@babel/core\";\nimport type { Transform } from \"babel-plugin-ember-template-compilation\";\nimport type { Plugin } from \"rolldown\";\n\nexport interface BabelOptions {\n /**\n * Compile templates to the wire format instead of `precompileTemplate`.\n *\n * For a build that bundles its own ember-source.\n * The wire format is private between one template compiler and one\n * glimmer runtime of the same version, so this is only safe when both\n * ship together.\n *\n * The compiler is ember-source's own, resolved from the package.\n *\n * Set by `ember({ bundle: true })`.\n * Only applies without a babel config file.\n */\n bundle?: boolean;\n babelHelpers?: \"bundled\" | \"runtime\" | \"inline\" | \"external\";\n /**\n * The babel config file to use.\n *\n * - `undefined`: auto-detect.\n * A `babel.publish.config.*` (in the package root or `config/`) wins,\n * because this is a publish build.\n * Otherwise babel's own config resolution applies (see `detectConfigFile`).\n * - a string: use that config file.\n * - `false`: ignore config files entirely.\n *\n * Without a config file, templates, decorators, and TypeScript are still handled\n * (see `defaultPlugins`).\n */\n configFile?: string | false;\n /**\n * Extra babel plugins to run, appended after the config's plugins.\n */\n plugins?: PluginItem[];\n /**\n * Template AST transforms passed to the default\n * `babel-plugin-ember-template-compilation` entry.\n * e.g. ember-scoped-css's `scopedCSS.template()`\n *\n * Only valid without a babel config file.\n * With your own config, you list `babel-plugin-ember-template-compilation` yourself,\n * so its `transforms` belong there.\n */\n templateTransforms?: Transform[];\n /**\n * Opt additional files into babel (see maybeBabel's `filter`).\n *\n * Use this to cover addons that ship code needing babel\n * (e.g. `ember-concurrency`).\n */\n filter?: {\n include: {\n imports: string[];\n code: (string | RegExp)[];\n };\n };\n}\n\n/**\n * Tried in order, so an ESM config wins over a JSON one of the same name.\n */\nconst PUBLISH_CONFIG_EXTENSIONS = [\"mjs\", \"cjs\", \"js\", \"mts\", \"cts\", \"ts\", \"json\"];\n\n/**\n * Tried in order:\n * - next to package.json first\n * - then `config/`, for libraries that keep their build configuration\n * out of the package root\n */\nconst PUBLISH_CONFIG_DIRECTORIES = [\".\", \"config\"];\n\n/**\n * A `babel.publish.config.*` (in the package root or `config/`), if there is one.\n *\n * A library's plain `babel.config.*` is its *development* config.\n * It typically:\n * - compiles `@embroider/macros` away\n * - targets the wire format\n * - wires up whatever the in-package demo app or test suite needs\n *\n * None of that belongs in a published artifact:\n * - macros must stay, for the consuming app to evaluate\n * - the wire format is private between one template compiler and one glimmer runtime\n *\n * Babel's own resolution can't tell the two apart (it finds whatever `babel.config.*` exists),\n * so a publish build has to prefer the config named for publishing.\n */\nfunction detectPublishConfigFile(): string | undefined {\n for (const directory of PUBLISH_CONFIG_DIRECTORIES) {\n for (const extension of PUBLISH_CONFIG_EXTENSIONS) {\n const candidate = resolve(directory, `babel.publish.config.${extension}`);\n\n if (existsSync(candidate)) return candidate;\n }\n }\n\n return undefined;\n}\n\n/**\n * The config this publish build must use:\n * - a `babel.publish.config.*`, when the library has one\n * - else the project's root babel config, resolved the way babel itself does\n * (`babel.config.{js,cjs,mjs,cts,json}`, honoring `rootMode` semantics)\n *\n * For a library whose only config *is* its publish config,\n * that is the same file either way.\n *\n * The sync API evaluates the config file.\n * On node 24+ that works for native ESM configs too (require(esm)).\n */\nfunction detectConfigFile(): string | undefined {\n const publishConfig = detectPublishConfigFile();\n\n if (publishConfig) return publishConfig;\n\n const partial = loadPartialConfigSync({ cwd: process.cwd() });\n\n return partial?.config ?? undefined;\n}\n\n/**\n * Everything a library without its own babel config needs:\n *\n * - TypeScript stripping\n *\n * - template compilation to `precompileTemplate` (`targetFormat: \"hbs\"`).\n * Published libraries must NOT ship wire format.\n * The wire format is private between the template compiler and the glimmer runtime\n * of the same version, so baking it in ties the published artifact\n * to the consuming app's exact ember-source.\n * The consuming app performs final compilation.\n *\n * A bundle-mode build ships that exact ember-source,\n * so it compiles to the wire format with ember-source's own compiler,\n * and needs no compiler at runtime.\n *\n * - decorator-transforms, with its runtime left as a bare specifier\n * so the consuming app resolves it.\n * (the library keeps `decorator-transforms` as a real dependency)\n *\n * A bundle-mode build resolves it itself.\n */\nfunction defaultPlugins(templateTransforms?: Transform[], bundle = false): PluginItem[] {\n return [\n [\n transformTypeScript,\n {\n allExtensions: true,\n onlyRemoveTypeImports: true,\n allowDeclareFields: true,\n },\n ],\n [\n templateCompilation,\n { targetFormat: bundle ? \"wire\" : \"hbs\", transforms: templateTransforms ?? [] },\n ],\n [\n decoratorTransforms,\n {\n // Emit `import ... from \"decorator-transforms/runtime-esm\"` as a bare specifier,\n // so it stays external and the consuming app resolves it.\n runtime: { import: \"decorator-transforms/runtime-esm\" },\n },\n ],\n ];\n}\n\n/**\n * We still need babel (not just oxc / rolldown's native transforms) for two reasons:\n *\n * - template compilation.\n * `babel-plugin-ember-template-compilation` turns the content-tag output\n * into `precompileTemplate` calls.\n * oxc has no equivalent.\n *\n * - decorators.\n * Ember uses the legacy / stage-1 decorator signature together with `decorator-transforms`,\n * which rewrites decorated class fields (`@tracked x`) into getter / setters backed by a runtime.\n * oxc's native \"legacy decorators\" emit tsc-style `__decorate` output,\n * which does not match those semantics.\n *\n * But we don't want to send *every* file through babel\n * and give back the speed rolldown / oxc buys us.\n *\n * So we run babel via `maybeBabel`, which filters down to only the files that need it\n * (template-tag, decorators, template imports).\n * Everything else stays on the native transform.\n *\n * The library's own babel config is used when it exists.\n * Its `babel.publish.config.*` (root or `config/`) wins over its `babel.config.*`,\n * since this is a publish build.\n *\n * Without one, `defaultPlugins` covers templates, decorators, and TypeScript,\n * so no config file is required.\n *\n * Libraries default to `babelHelpers: \"bundled\"`, so the emitted output is self-contained.\n */\nexport function emberBabel(options: BabelOptions = {}): Plugin {\n const configFile = options.configFile === undefined ? detectConfigFile() : options.configFile;\n\n const shared = {\n babelHelpers: options.babelHelpers ?? \"bundled\",\n filter: options.filter,\n };\n\n if (configFile) {\n if (options.templateTransforms?.length) {\n throw new Error(\n `\\`babel.templateTransforms\\` cannot be combined with a babel config file (found ${configFile}). ` +\n `Your config lists babel-plugin-ember-template-compilation itself, so pass the transforms ` +\n `to its \\`transforms\\` option there instead.`,\n );\n }\n\n return maybeBabel({\n ...shared,\n configFile,\n plugins: options.plugins ?? [],\n }) as unknown as Plugin;\n }\n\n return maybeBabel({\n ...shared,\n // No config file (or the caller opted out).\n // Don't let babel go looking for one: we provide the whole plugin list inline.\n configFile: false,\n babelrc: false,\n plugins: defaultPlugins(options.templateTransforms, options.bundle).concat(\n options.plugins ?? [],\n ),\n }) as unknown as Plugin;\n}\n","import { readFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\n\nimport type { Plugin } from \"rolldown\";\n\n// @embroider/core is cjs, so we default-import and destructure.\nimport pkg from \"@embroider/core\";\nconst { emberVirtualPackages, emberVirtualPeerDeps, packageName, templateCompilationModules } = pkg;\n\nconst compilationModules = new Set(templateCompilationModules.map((m) => m.module));\n\n/**\n * @param {string} path\n */\nfunction readJsonSync(path: string) {\n return JSON.parse(readFileSync(path, { encoding: \"utf8\" }));\n}\n\n/**\n * Everything the library declares as a `dependency` or `peerDependency`\n * is resolvable by the consuming app, so we never bundle it.\n */\nfunction resolvableDependencies(): Set<string> {\n const deps = new Set<string>();\n const manifest = readJsonSync(\"package.json\");\n\n for (const name of Object.keys(manifest.dependencies ?? {})) {\n deps.add(name);\n }\n for (const name of Object.keys(manifest.peerDependencies ?? {})) {\n deps.add(name);\n }\n\n return deps;\n}\n\n/**\n * The modules ember-source provides by renaming them into itself.\n *\n * This is its `ember-addon.renamed-modules`, keyed by module file path:\n * `@glimmer/runtime/index.js` → `ember-source/@glimmer/runtime/index.js`\n *\n * It is the authoritative list of ember's provided modules.\n * It includes private API that @embroider/core's emberVirtualPackages\n * doesn't cover (e.g. `@glimmer/runtime`).\n *\n * It deliberately does NOT include real packages like `@glimmer/component`,\n * which a library may want bundled.\n *\n * Empty when ember-source isn't resolvable from the library.\n */\nexport function emberSourceRenamedModules(): Record<string, string> {\n try {\n const require = createRequire(path.resolve(\"package.json\"));\n const manifest = require(\"ember-source/package.json\") as {\n \"ember-addon\"?: { \"renamed-modules\"?: Record<string, string> };\n };\n\n return manifest[\"ember-addon\"]?.[\"renamed-modules\"] ?? {};\n } catch {\n // The library doesn't have ember-source in its graph; nothing to provide.\n return {};\n }\n}\n\n/**\n * The renamed modules as import specifiers\n * `@glimmer/runtime/index.js` → `@glimmer/runtime`\n */\nfunction emberSourceProvidedModules(): Set<string> {\n const provided = new Set<string>();\n\n for (const key of Object.keys(emberSourceRenamedModules())) {\n provided.add(key.replace(/\\.js$/, \"\").replace(/\\/index$/, \"\"));\n }\n\n return provided;\n}\n\n/**\n * Keeps external:\n * - the library's declared dependencies\n * - the ember virtual packages\n * (things like `@ember/component`, `@glimmer/tracking`, the template compiler, …)\n *\n * So the app that consumes the library resolves them,\n * instead of the library bundling copies of them.\n */\nexport function emberExternals(): Plugin {\n let deps: Set<string>;\n let renamedModules: Set<string>;\n\n return {\n name: \"ember:externals\",\n\n buildStart() {\n this.addWatchFile(\"package.json\");\n deps = resolvableDependencies();\n renamedModules = emberSourceProvidedModules();\n },\n\n resolveId: {\n order: \"pre\",\n handler(source) {\n // Anything with a protocol (`node:`, virtual modules, …)\n // is not ours to externalize.\n if (source.includes(\":\")) {\n return null;\n }\n\n const pkgName = packageName(source);\n\n if (!pkgName) {\n // No package name means a relative import, which we don't deal with.\n return null;\n }\n\n if (\n deps.has(pkgName) ||\n emberVirtualPeerDeps.has(pkgName) ||\n emberVirtualPackages.has(pkgName) ||\n compilationModules.has(pkgName)\n ) {\n // `false` tells rolldown to treat the id as external.\n return false;\n }\n\n // Modules ember-source provides by renaming them into itself\n // (`ember-addon.renamed-modules`).\n //\n // Private API like `@glimmer/runtime`,\n // which only exists inside the app's ember-source.\n //\n // Matched on the full specifier:\n // the renamed modules are module paths, not packages.\n if (renamedModules.has(source)) {\n return false;\n }\n\n return undefined;\n },\n },\n };\n}\n","import type { Plugin } from \"rolldown\";\n\nimport { emberSourceRenamedModules } from \"./externals.ts\";\n\n/**\n * The package name a renamed-modules key belongs to\n * `@ember/modifier/on.js` → `@ember/modifier`\n * `rsvp/index.js` → `rsvp`\n */\nfunction packageOf(modulePath: string): string {\n const segments = modulePath.split(\"/\");\n const length = modulePath.startsWith(\"@\") ? 2 : 1;\n\n return segments.slice(0, length).join(\"/\");\n}\n\n/**\n * One alias per package ember-source provides, pointing into ember-source\n * `@ember/modifier` → `ember-source/@ember/modifier`\n *\n * The provided packages are the ones named in `ember-addon.renamed-modules`\n * (`@ember/*`, `@glimmer/tracking`, `rsvp`, `backburner.js`, …).\n *\n * Real packages such as `@glimmer/component` are not in it,\n * so they keep resolving from node_modules.\n */\nexport function emberSourceAliases(): Record<string, string> {\n const aliases: Record<string, string> = {};\n\n for (const modulePath of Object.keys(emberSourceRenamedModules())) {\n const name = packageOf(modulePath);\n\n aliases[name] = `ember-source/${name}`;\n }\n\n return aliases;\n}\n\n/**\n * Makes the modules ember-source provides resolvable,\n * so a bundle-mode build can include them.\n *\n * ember-source exports every module under `./*`,\n * with `development` and `production` conditions selecting one of its two builds.\n *\n * A bare `@ember/modifier` is not that path, though.\n * It only exists as `ember-source/@ember/modifier`.\n *\n * So this plugin adds the alias for each provided package,\n * and leaves the rest to the resolver:\n * - the `default` condition selects the production build\n * - `resolve.conditionNames: [\"development\"]` selects the development build\n * (tsdown: `inputOptions.resolve.conditionNames`)\n *\n * Aliases set explicitly in the build config win over these.\n */\nexport function emberBundle(): Plugin {\n return {\n name: \"ember:bundle\",\n\n options(inputOptions) {\n inputOptions.resolve ??= {};\n inputOptions.resolve.alias = {\n ...emberSourceAliases(),\n ...inputOptions.resolve.alias,\n };\n\n return inputOptions;\n },\n };\n}\n","import type { TsdownPlugin, UserConfig } from \"tsdown\";\n\n/**\n * Sensible defaults for an Ember v2 library.\n *\n * Applied through plugin hooks, so they travel with `ember()`.\n * You get them whether you use this package's `defineConfig`, tsdown's,\n * or a plain `tsdown.config.js` / `rolldown.config.js`.\n *\n * Every value is applied with `??=`, so anything you set explicitly wins.\n *\n * Under tsdown, the full set applies via the `tsdownConfig` hook\n * (analogous to Vite's `config` hook):\n *\n * - `sourcemap` — emit sourcemaps alongside the output\n * - `clean` — wipe `dist/` between builds\n * - `dts` — emit `.d.ts` declarations (via isolated declarations)\n * - `outExtensions` — `.js` / `.d.ts` rather than tsdown's default `.mjs` / `.d.mts`\n * (exports maps conventionally point at `.js` / `.d.ts`)\n * - `report` — off.\n * The size report is noise for a library build.\n * - `deps.neverBundle` — leave node builtins and the ember virtual packages\n * to the consuming app (`emberExternals()` handles the rest)\n *\n * A plain rolldown build has no notion of `clean` / `dts` / `outExtensions` / `report`.\n * Those are tsdown-level concepts.\n * So only the options with rolldown equivalents are applied there,\n * via rolldown's own `outputOptions` hook:\n *\n * - `output.sourcemap` — on\n *\n * One default applies through rolldown's `options` hook,\n * so it holds under both tools:\n *\n * - `optimization.inlineConst` — off.\n * Rolldown's default (`mode: \"smart\"`) puts an imported constant's literal\n * into `precompileTemplate` scope objects:\n * `scope: () => ({ EMPTY })` becomes `scope: () => ({ EMPTY: \"—\" })`.\n * The consuming app's template compiler accepts only direct references there.\n * The library still builds, type-checks, and lints clean,\n * so the app boot is the first place the error shows.\n * The compiler-side fix, which accepts literal scope values, is\n * https://github.com/emberjs/babel-plugin-ember-template-compilation/pull/125\n *\n * Externals are handled by `emberExternals()` (a `resolveId` hook) in both cases.\n *\n * Bundle mode flips the dependency defaults.\n * The output is a self-contained browser artifact, so:\n *\n * - `platform` — `browser`\n * - `deps.alwaysBundle` — everything but node builtins\n * (including the package's own `dependencies` and `peerDependencies`,\n * and the declarations' type imports)\n * - `deps.neverBundle` — node builtins only\n * - `deps.onlyBundle` — `false`\n * (bundling node_modules is the point, so tsdown's hint about it is noise)\n */\nexport function emberConfig({ bundle = false }: { bundle?: boolean } = {}): TsdownPlugin {\n return {\n name: \"ember:config\",\n\n tsdownConfig(config: UserConfig) {\n config.sourcemap ??= true;\n config.clean ??= true;\n config.dts ??= { sourcemap: true };\n config.outExtensions ??= () => ({ js: \".js\", dts: \".d.ts\" });\n config.report ??= false;\n\n config.deps ??= {};\n\n if (bundle) {\n config.platform ??= \"browser\";\n config.deps.alwaysBundle ??= (id) => !id.startsWith(\"node:\");\n config.deps.neverBundle ??= [\"node:*\"];\n config.deps.onlyBundle ??= false;\n return;\n }\n\n config.deps.neverBundle ??= [\"node:*\", \"@ember/*\", \"@glimmer/*\"];\n },\n\n options(options) {\n options.optimization ??= {};\n options.optimization.inlineConst ??= false;\n return options;\n },\n\n outputOptions(options) {\n options.sourcemap ??= true;\n return options;\n },\n };\n}\n","import { existsSync, statSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\n\nimport { parseTsconfig, type TsConfigJsonResolved } from \"get-tsconfig\";\nimport type { Plugin } from \"rolldown\";\nimport type { ResolvedConfig, UserConfig } from \"tsdown\";\n\n/**\n * Resolve the tsconfig the build will use.\n *\n * Mirrors tsdown's own `tsconfig` option (`string | boolean`):\n * - `undefined` / `true`: `tsconfig.json` in the cwd\n * - a path to a file: that file\n * - a path to a directory: `tsconfig.json` inside it\n * - `false`: no tsconfig at all\n *\n * Under plain rolldown there is no such option,\n * so the cwd's `tsconfig.json` is all there is.\n */\nfunction resolveTsconfigPath(option: string | boolean | undefined): string | undefined {\n if (option === false) return undefined;\n\n if (typeof option === \"string\") {\n const asPath = resolve(option);\n\n if (existsSync(asPath) && statSync(asPath).isDirectory()) {\n return resolve(asPath, \"tsconfig.json\");\n }\n\n return asPath;\n }\n\n return resolve(\"tsconfig.json\");\n}\n\n/**\n * Errors the build when the tsconfig it builds with\n * does not set `isolatedDeclarations: true`.\n *\n * This is required.\n * Declarations for `.gts` / `.gjs` (template tag) modules can only be emitted\n * by the isolated-declarations pipeline,\n * which reads compiled modules from the bundler's module graph.\n *\n * The `tsc`-based pipeline reads source files from disk.\n * The compiled modules don't exist there, so it fails with \"Source file not found\".\n *\n * Failing fast here, rather than only when declaration emit happens to run,\n * keeps the project honest.\n * Editors and `tsc` / `ember-tsc` then check the same rules the build enforces:\n * exported values need explicit type annotations,\n * e.g. `export const X: TOC<Sig> = <template>...`\n *\n * The tsconfig checked is the one tsdown's `tsconfig` option points at,\n * not necessarily `tsconfig.json`.\n *\n * So a library whose package also holds dev-only code (a demo app, in-package tests) can:\n * - keep a permissive `tsconfig.json` covering everything,\n * for editors and `tsc --noEmit`\n * - point the build at a `tsconfig.publish.json` that covers only the publishable sources\n *\n * Isolated declarations then constrain exactly the code that gets declarations emitted,\n * and nothing else.\n *\n * Projects with no tsconfig (JavaScript libraries) have no declarations to emit,\n * so there is nothing to check.\n *\n * The tsconfig is read without the `typescript` package.\n * TypeScript 7 has no JavaScript API, and a TypeScript 7 library can have no TypeScript 6.\n *\n * `tsconfig: false` is different.\n * It is an explicit opt-out.\n * Combined with declaration emit, it produces a confusing \"Source file not found\"\n * from the tsc-based pipeline, so it errors here instead.\n */\nexport function emberIsolatedDeclarations(): Plugin {\n let tsconfigOption: string | boolean | undefined;\n\n return {\n name: \"ember:isolated-declarations\",\n\n // Not called under plain rolldown, which leaves `tsconfigOption` undefined.\n // That means the cwd's tsconfig.json, the only thing it could mean there.\n tsdownConfig(config: UserConfig) {\n tsconfigOption = config.tsconfig;\n },\n\n /**\n * Runs after every plugin's `tsdownConfig`, so `dts` is final here.\n *\n * Must run before the build starts:\n * tsdown sets up rolldown-plugin-dts while it resolves build options,\n * and without a tsconfig that throws before any `buildStart` hook.\n */\n tsdownConfigResolved(config: ResolvedConfig) {\n if (config.tsconfig !== false || !config.dts) return;\n\n // Without a tsconfig there is no `isolatedDeclarations`,\n // so tsdown falls back to the tsc-based declaration pipeline.\n //\n // That pipeline reads source files from disk,\n // and dies with \"Source file not found\" on every `.gts` / `.gjs`,\n // since those only exist compiled in the module graph.\n //\n // Say so here instead of leaving that to be decoded.\n throw new Error(\n `\\`tsconfig: false\\` cannot be combined with declaration emit.\\n\\n` +\n `Declarations are emitted by the isolated-declarations pipeline, which needs a ` +\n `tsconfig setting \"compilerOptions.isolatedDeclarations\": true -- it is the only ` +\n `pipeline that can see compiled .gts/.gjs modules.\\n\\n` +\n `Either point tsdown's \\`tsconfig\\` option at such a config, or set \\`dts: false\\` ` +\n `if this library ships no types.`,\n );\n },\n\n buildStart: {\n /**\n * Before rolldown-plugin-dts, whose buildStart loads the `typescript` package\n * when isolatedDeclarations is off.\n *\n * In a TypeScript 7 library that package is TypeScript 7, which has no JavaScript API,\n * so it crashes before this message can show.\n */\n order: \"pre\",\n async handler() {\n const tsconfigPath = resolveTsconfigPath(tsconfigOption);\n\n if (!tsconfigPath || !existsSync(tsconfigPath)) return;\n\n let tsconfig: TsConfigJsonResolved;\n\n try {\n // Resolves `extends` chains, so the flag may come from a base config.\n tsconfig = parseTsconfig(tsconfigPath);\n } catch {\n // Unreadable / unparsable tsconfig.\n // tsc itself will report this with a better message than we can.\n return;\n }\n\n if (tsconfig.compilerOptions?.isolatedDeclarations !== true) {\n this.error(\n `${tsconfigPath} must set \"compilerOptions.isolatedDeclarations\": true.\\n\\n` +\n `Declarations for .gts/.gjs (template tag) modules can only be emitted by the ` +\n `isolated-declarations pipeline, which reads compiled modules from the bundler's ` +\n `module graph -- the tsc-based pipeline reads from disk and cannot see them.\\n\\n` +\n `Isolated declarations require exported values to have explicit type annotations, ` +\n `e.g. \\`export const X: TOC<Sig> = <template>...\\`.\\n\\n` +\n `If this tsconfig also covers dev-only code (a demo app, in-package tests) that ` +\n `should not be constrained this way, point tsdown's \\`tsconfig\\` option at a ` +\n `publish-only tsconfig that sets the flag and covers just the published sources.`,\n );\n }\n },\n },\n };\n}\n","import remapping, { type EncodedSourceMap } from \"@jridgewell/remapping\";\nimport { Preprocessor } from \"content-tag\";\nimport MagicString from \"magic-string\";\nimport { existsSync, realpathSync } from \"node:fs\";\nimport { readFile, writeFile, readdir } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { Plugin } from \"rolldown\";\n\nconst processor = new Preprocessor();\n\n/**\n * `.d.ts` files emitted for `.gts` source reference the original `.gts` specifiers.\n *\n * Consumers can't resolve those,\n * so we rewrite them back to extension-less specifiers.\n */\nfunction fixDeclarationImports(content: string): string {\n return content\n .replace(/from\\s+'([^']+)\\.gts'/g, \"from '$1'\")\n .replace(/from\\s+\"([^\"]+)\\.gts\"/g, 'from \"$1\"')\n .replace(/import\\(\"([^\"]+)\\.gts\"\\)/g, 'import(\"$1\")')\n .replace(/import\\('([^']+)\\.gts'\\)/g, \"import('$1')\");\n}\n\nasync function fixDtsExtensionsInDir(dir: string): Promise<void> {\n const entries = await readdir(dir, { withFileTypes: true });\n\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n\n if (entry.isDirectory()) {\n await fixDtsExtensionsInDir(fullPath);\n } else if (entry.name.endsWith(\".d.ts\")) {\n const content = await readFile(fullPath, { encoding: \"utf8\" });\n const fixed = fixDeclarationImports(content);\n\n if (fixed !== content) {\n await writeFile(fullPath, fixed);\n }\n }\n }\n}\n\n/**\n * A sourcemap from `code` back to `source`, with a segment for every column.\n *\n * rolldown traces each output position back through the map of every hook.\n * A position between two segments resolves to the segment before it,\n * so fewer segments move positions to an earlier column.\n *\n * content-tag's output often puts a doc comment's end and a declaration on one line.\n * With one segment per line, the declaration resolves to the comment.\n */\nfunction columnMap(code: MagicString, source: string) {\n return code.generateMap({ source, includeContent: true, hires: true });\n}\n\n/**\n * The `.gts` / `.gjs` file behind a virtual `.ts` / `.js` id,\n * and content-tag's map back to it (absent when there was no `<template>` to compile).\n */\ninterface Backing {\n fileName: string;\n map?: string;\n}\n\n/**\n * Points a declaration map at the `.gts` / `.gjs` files behind its virtual sources.\n *\n * rolldown-plugin-dts generates declarations from the loaded module (content-tag's output).\n * So its maps name:\n * - the virtual id, a file that does not exist\n * - content-tag's line numbers, which do not match the source\n *\n * Tracing through content-tag's map gives the file and line\n * that a consumer's \"go to definition\" can open.\n *\n * Returns `undefined` when no source is virtual.\n */\nfunction remapDeclarationMap(\n json: string,\n mapDir: string,\n backings: Map<string, Backing>,\n): string | undefined {\n const map = JSON.parse(json) as EncodedSourceMap;\n\n if (!map.sources.some((source) => source && backings.has(path.resolve(mapDir, source)))) {\n return undefined;\n }\n\n const remapped = remapping(\n map,\n (source, context) => {\n // Only the declaration map's own sources can be virtual.\n if (context.depth > 1) return null;\n\n const backing = backings.get(path.resolve(mapDir, source));\n if (!backing) return null;\n\n context.source = backing.fileName;\n return backing.map ?? null;\n },\n // Like the rest of the declaration map, point at the published sources.\n // Do not embed them.\n { excludeContent: true },\n );\n\n // Backing files come back absolute.\n // The other sources are relative to the map's directory.\n remapped.sources = remapped.sources.map((source) =>\n source && path.isAbsolute(source)\n ? path.relative(mapDir, source).split(path.sep).join(\"/\")\n : source,\n );\n\n return remapped.toString();\n}\n\n/**\n * Preprocesses `<template>` via content-tag, and maps\n * `.gts` → `.ts`\n * `.gjs` → `.js`\n * so rolldown can identify them as ts / js.\n */\nexport function emberTransform(): Plugin {\n // virtual id -> what it was loaded from\n const backings = new Map<string, Backing>();\n\n return {\n name: \"ember:transform\",\n\n resolveId: {\n order: \"pre\",\n handler(id, importer) {\n // Entries have no importer.\n // Their ids come straight from the build config\n // (tsdown expands entry globs to on-disk paths).\n //\n // Resolve a `.gts` / `.gjs` entry to the same virtual `.ts` / `.js` id\n // an imported module gets, so the load hook compiles it via content-tag\n // instead of the raw `<template>` source hitting the parser.\n //\n // Entries may be any extension.\n // The emitted `.js` / `.d.ts` paths mirror the entry paths either way\n // (that's how tsdown's dts support works).\n if (!importer) {\n if (!id.endsWith(\".gts\") && !id.endsWith(\".gjs\")) return null;\n if (!existsSync(id)) return null;\n\n // rolldown's default resolver realpaths entry ids\n // (e.g. macOS /var -> /private/var).\n //\n // Match it, or this same file imported from another entry\n // resolves to a second module id and gets duplicated into both chunks.\n const fileName = realpathSync(path.resolve(id));\n\n return {\n id: fileName.replace(/\\.gts$/, \".ts\").replace(/\\.gjs$/, \".js\"),\n meta: { fileName },\n };\n }\n\n // An absolute specifier already names the file,\n // so it needs no importer-relative resolution.\n // Joining it onto the importer's directory would corrupt it.\n //\n // That is not hypothetical.\n // A plugin's virtual module (id prefixed with `\\0`)\n // can generate imports of on-disk files by absolute path,\n // and `path.dirname(\"\\0./registry\")` is `\"\\0.\"`.\n // Joining then yields `\"\\0./Users/.../thing.gts\"`:\n // a path no `existsSync` / `readFile` can accept (it has a null byte in it).\n const fileName = path.isAbsolute(id) ? id : path.join(path.dirname(importer), id);\n\n if (id.endsWith(\".gts\")) {\n return {\n id: fileName.replace(/\\.gts$/, \".ts\"),\n meta: { fileName },\n };\n }\n\n if (id.endsWith(\".gjs\")) {\n return {\n id: fileName.replace(/\\.gjs$/, \".js\"),\n meta: { fileName },\n };\n }\n\n // A `.ts` / `.js` specifier whose only backing file is a `.gts` / `.gjs`\n // resolves to the virtual module.\n //\n // This must also serve `.d.ts` importers.\n // rolldown-plugin-dts resolves a declaration module's imports\n // through the plugin pipeline (`this.resolve`).\n // When the resolution is a source file, it loads it (registering its declaration)\n // before mapping the import to the declaration id.\n //\n // Virtual modules exist nowhere else.\n // If we don't answer here, the import either:\n // - fails to resolve (no file on disk)\n // - or, worse, resolves to a declaration id that was never registered\n if (id.endsWith(\".ts\")) {\n const gtsFileName = fileName.replace(/\\.ts$/, \".gts\");\n if (existsSync(gtsFileName) && !existsSync(fileName)) {\n return { id: fileName, meta: { fileName: gtsFileName } };\n }\n }\n\n if (id.endsWith(\".js\")) {\n const gjsFileName = fileName.replace(/\\.js$/, \".gjs\");\n if (existsSync(gjsFileName) && !existsSync(fileName)) {\n return { id: fileName, meta: { fileName: gjsFileName } };\n }\n }\n\n return null;\n },\n },\n\n load: {\n order: \"pre\",\n filter: {\n id: /\\.(ts|js)$/,\n },\n async handler(id) {\n const meta = this.getModuleInfo(id)?.meta ?? {};\n let fileName = meta?.fileName;\n\n // A virtual id can be loaded without having passed through our resolveId\n // (rolldown-plugin-dts calls `this.load({ id })` with just the id),\n // so no meta is attached.\n //\n // Recover the backing file from disk.\n if (!fileName && !existsSync(id)) {\n if (id.endsWith(\".ts\") && existsSync(id.replace(/\\.ts$/, \".gts\"))) {\n fileName = id.replace(/\\.ts$/, \".gts\");\n } else if (id.endsWith(\".js\") && existsSync(id.replace(/\\.js$/, \".gjs\"))) {\n fileName = id.replace(/\\.js$/, \".gjs\");\n }\n }\n\n if (fileName) {\n this.addWatchFile(fileName);\n const source = await readFile(fileName, { encoding: \"utf8\" });\n\n if (source.includes(\"<template>\")) {\n const { code, map } = processor.process(source, {\n filename: fileName,\n });\n backings.set(id, { fileName, map });\n return { code, map };\n }\n\n // The map names the `.gts` / `.gjs` file.\n // Without it, the `.js.map` names the virtual id, which is not on disk.\n //\n // The backing needs no map, because its declaration lines match the source.\n backings.set(id, { fileName });\n return { code: source, map: columnMap(new MagicString(source), fileName) };\n }\n\n return null;\n },\n },\n\n transform: {\n order: \"pre\",\n filter: {\n code: /\\.gts/,\n id: /\\.(js|ts)$/,\n },\n handler(input, id) {\n // Rewrite `.gts` specifiers to `.ts`, the (virtual) source id,\n // in runtime modules AND declaration modules alike.\n //\n // Declaration modules must NOT be rewritten to `.d.ts`.\n // rolldown-plugin-dts's resolver treats a source-file resolution as\n // \"load it (registering its declaration), then map to the declaration id\".\n // A `.d.ts` id is returned as-is: unloadable when the module isn't registered yet\n // (e.g. the `.gts` is only ever type-imported).\n const output = new MagicString(input);\n\n for (const match of input.matchAll(\n /(['\"`])((?:\\.\\.?\\/|\\/|@|[A-Za-z0-9_\\-])[^'\"]*?\\.gts)\\1/g,\n )) {\n // `.gts` ends the specifier, just before the closing quote.\n const end = match.index + match[0].length - 1;\n output.overwrite(end - \".gts\".length, end, \".ts\");\n }\n\n if (!output.hasChanged()) {\n return null;\n }\n\n return { code: output.toString(), map: columnMap(output, id) };\n },\n },\n\n generateBundle(options, bundle) {\n const outDir = options.dir ?? (options.file && path.dirname(options.file));\n if (!outDir || backings.size === 0) return;\n\n for (const output of Object.values(bundle)) {\n if (output.type !== \"asset\" || !output.fileName.endsWith(\".d.ts.map\")) continue;\n if (typeof output.source !== \"string\") continue;\n\n const mapDir = path.dirname(path.resolve(outDir, output.fileName));\n const remapped = remapDeclarationMap(output.source, mapDir, backings);\n\n if (remapped) output.source = remapped;\n }\n },\n\n writeBundle: {\n async handler(options) {\n const outDir = (options as { dir?: string }).dir;\n if (outDir) {\n await fixDtsExtensionsInDir(path.resolve(outDir));\n }\n },\n },\n };\n}\n","import { emberBabel, type BabelOptions } from \"./src/babel.ts\";\nimport { emberBundle } from \"./src/bundle.ts\";\nimport { emberConfig } from \"./src/config.ts\";\nimport { emberExternals } from \"./src/externals.ts\";\nimport { emberIsolatedDeclarations } from \"./src/isolated-declarations.ts\";\nimport { emberTransform } from \"./src/transform.ts\";\nimport type { RolldownPluginLike } from \"./src/plugin-like.ts\";\n\ninterface Config {\n /**\n * Build a self-contained package instead of a library.\n *\n * `false` (the default) builds a library for Ember apps:\n * - ember, the package's dependencies, and its peerDependencies stay external\n * - templates are shipped as `precompileTemplate` calls,\n * for the consuming app to compile\n *\n * `true` builds an artifact that runs on any page, such as a custom element:\n * - ember-source, `@glimmer/component`, `decorator-transforms`,\n * and every other dependency are bundled in\n * - templates are compiled to the wire format with that same ember-source\n * - declarations bundle their type imports as well\n *\n * Which ember-source build is bundled follows the export conditions:\n * - production by default\n * - development with `resolve.conditionNames: [\"development\"]`\n */\n bundle?: boolean;\n /**\n * Options for the babel step.\n * See `BabelOptions`.\n */\n babel?: BabelOptions;\n}\n\n/**\n * A batteries-included plugin for building Ember v2 libraries (addons)\n * with rolldown, or with tsdown (which is built on rolldown).\n *\n * It bundles everything needed to compile `.gts` / `.gjs` and\n * template-tag (`<template>`) source into publishable output:\n *\n * - `emberConfig()`\n * applies sensible tsdown defaults for a library build\n * (sourcemaps, `clean`, `dts`, `.js` / `.d.ts` extensions, quiet logging).\n * It also turns off rolldown's constant inlining.\n * Inlined literals break `precompileTemplate` scope objects,\n * which must hold direct references.\n * Anything you set explicitly still wins.\n *\n * - `emberIsolatedDeclarations()`\n * errors when a tsconfig.json is present without `isolatedDeclarations: true`.\n * That is the only declaration pipeline that can see compiled template-tag modules.\n *\n * - `emberExternals()`\n * keeps your dependencies, peerDependencies, and the ember virtual packages external,\n * so consuming apps resolve them.\n *\n * - `emberBundle()`\n * bundle mode only, in place of `emberExternals()`.\n * Aliases the ember virtual packages into ember-source,\n * whose export conditions pick the build to bundle.\n *\n * - `emberTransform()`\n * preprocesses `<template>` via content-tag,\n * and maps `.gts` / `.gjs` to `.ts` / `.js` so rolldown can understand them.\n *\n * - `emberBabel()`\n * runs babel (template compilation, decorators, type stripping)\n * with `babelHelpers: \"bundled\"`.\n * Only the files that need it go through babel (via `maybeBabel`).\n * Everything else stays on the fast native transform.\n * The library's own `babel.config.js` is used when it exists.\n * No config file is required.\n *\n * Usage in `tsdown.config.js`.\n * Import `defineConfig` from `tsdown` (or from `rolldown` for a `rolldown.config.js`)\n * so it carries the correct types:\n *\n * ```js\n * import { defineConfig } from \"tsdown\";\n * import { ember } from \"@nullvoxpopuli/ember-rolldown\";\n *\n * export default defineConfig({\n * entry: [\"./src/index.ts\"],\n * plugins: [ember()],\n * });\n * ```\n */\nexport function ember(config: Config = {}): RolldownPluginLike[] {\n const bundle = config.bundle ?? false;\n\n return [\n emberConfig({ bundle }),\n emberIsolatedDeclarations(),\n bundle ? emberBundle() : emberExternals(),\n emberTransform(),\n emberBabel({ ...config.babel, bundle }),\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwEA,MAAM,4BAA4B;CAAC;CAAO;CAAO;CAAM;CAAO;CAAO;CAAM;AAAM;;;;;;;AAQjF,MAAM,6BAA6B,CAAC,KAAK,QAA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,OAAO,SAAS;KAAG,KAAK,UAAU,QAAQ,EAAE;IAAE;GAC/D;EACF;EAEA,eAAe,SAAS,QAAQ;GAC9B,MAAM,SAAS,QAAQ,QAAQ,QAAQ,QAAQ,KAAK,QAAQ,QAAQ,IAAI;GACxE,IAAI,CAAC,UAAU,SAAS,SAAS,GAAG;GAEpC,KAAK,MAAM,UAAU,OAAO,OAAO,MAAM,GAAG;IAC1C,IAAI,OAAO,SAAS,WAAW,CAAC,OAAO,SAAS,SAAS,WAAW,GAAG;IACvE,IAAI,OAAO,OAAO,WAAW,UAAU;IAEvC,MAAM,SAAS,KAAK,QAAQ,KAAK,QAAQ,QAAQ,OAAO,QAAQ,CAAC;IACjE,MAAM,WAAW,oBAAoB,OAAO,QAAQ,QAAQ,QAAQ;IAEpE,IAAI,UAAU,OAAO,SAAS;GAChC;EACF;EAEA,aAAa,EACX,MAAM,QAAQ,SAAS;GACrB,MAAM,SAAU,QAA6B;GAC7C,IAAI,QACF,MAAM,sBAAsB,KAAK,QAAQ,MAAM,CAAC;EAEpD,EACF;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACzOA,SAAgB,MAAM,SAAiB,CAAC,GAAyB;CAC/D,MAAM,SAAS,OAAO,UAAU;CAEhC,OAAO;EACL,YAAY,EAAE,OAAO,CAAC;EACtB,0BAA0B;EAC1B,SAAS,YAAY,IAAI,eAAe;EACxC,eAAe;EACf,WAAW;GAAE,GAAG,OAAO;GAAO;EAAO,CAAC;CACxC;AACF"}
|
package/index.ts
CHANGED
|
@@ -43,6 +43,9 @@ interface Config {
|
|
|
43
43
|
* - `emberConfig()`
|
|
44
44
|
* applies sensible tsdown defaults for a library build
|
|
45
45
|
* (sourcemaps, `clean`, `dts`, `.js` / `.d.ts` extensions, quiet logging).
|
|
46
|
+
* It also turns off rolldown's constant inlining.
|
|
47
|
+
* Inlined literals break `precompileTemplate` scope objects,
|
|
48
|
+
* which must hold direct references.
|
|
46
49
|
* Anything you set explicitly still wins.
|
|
47
50
|
*
|
|
48
51
|
* - `emberIsolatedDeclarations()`
|
package/package.json
CHANGED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { mkdtemp, writeFile } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { rolldown, type InputOptions } from "rolldown";
|
|
5
|
+
import { describe, expect, it } from "vitest";
|
|
6
|
+
|
|
7
|
+
import { emberConfig } from "./config.ts";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A module pair shaped like babel's template-compilation output: an imported
|
|
11
|
+
* constant referenced from a `precompileTemplate` scope object. The constant's
|
|
12
|
+
* value is shorter than its name — the case rolldown's default constant
|
|
13
|
+
* inlining (`optimization.inlineConst`, `mode: "smart"`) substitutes, turning
|
|
14
|
+
* `scope: () => ({ EMPTY })` into `scope: () => ({ EMPTY: "—" })`. Scope
|
|
15
|
+
* entries must be direct references to in-scope values, so the consuming app's
|
|
16
|
+
* template compiler rejects the substituted form.
|
|
17
|
+
*/
|
|
18
|
+
async function scopeFixture(): Promise<string> {
|
|
19
|
+
const dir = await mkdtemp(path.join(tmpdir(), "ember-rolldown-config-"));
|
|
20
|
+
|
|
21
|
+
await writeFile(path.join(dir, "constants.js"), `export const EMPTY = "—";\n`);
|
|
22
|
+
await writeFile(
|
|
23
|
+
path.join(dir, "entry.js"),
|
|
24
|
+
`import { setComponentTemplate } from "@ember/component";\n` +
|
|
25
|
+
`import templateOnly from "@ember/component/template-only";\n` +
|
|
26
|
+
`import { precompileTemplate } from "@ember/template-compilation";\n` +
|
|
27
|
+
`import { EMPTY } from "./constants.js";\n` +
|
|
28
|
+
`export const X = setComponentTemplate(precompileTemplate("{{EMPTY}}", {\n` +
|
|
29
|
+
` strictMode: true,\n` +
|
|
30
|
+
` scope: () => ({\n` +
|
|
31
|
+
` EMPTY\n` +
|
|
32
|
+
` })\n` +
|
|
33
|
+
`}), templateOnly());\n`,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return dir;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function buildScopeFixture(options: Partial<InputOptions> = {}): Promise<string> {
|
|
40
|
+
const dir = await scopeFixture();
|
|
41
|
+
const build = await rolldown({
|
|
42
|
+
input: path.join(dir, "entry.js"),
|
|
43
|
+
external: /^@ember\//,
|
|
44
|
+
...options,
|
|
45
|
+
});
|
|
46
|
+
const { output } = await build.generate({});
|
|
47
|
+
return output[0].code;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe("emberConfig", () => {
|
|
51
|
+
it("documents the rolldown default this guards against: short constants inline into scope objects", async () => {
|
|
52
|
+
// If this starts preserving the reference, rolldown changed its default
|
|
53
|
+
// and the guard below may no longer be needed.
|
|
54
|
+
const code = await buildScopeFixture();
|
|
55
|
+
expect(code).toContain(`scope: () => ({ EMPTY: "—" })`);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("keeps scope-object constants as references", async () => {
|
|
59
|
+
const code = await buildScopeFixture({ plugins: [emberConfig()] });
|
|
60
|
+
expect(code).toContain(`scope: () => ({ EMPTY })`);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("an explicit optimization.inlineConst still wins", async () => {
|
|
64
|
+
const code = await buildScopeFixture({
|
|
65
|
+
plugins: [emberConfig()],
|
|
66
|
+
optimization: { inlineConst: { mode: "smart" } },
|
|
67
|
+
});
|
|
68
|
+
expect(code).toContain(`scope: () => ({ EMPTY: "—" })`);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("leaves other explicit optimization options alone while defaulting inlineConst off", async () => {
|
|
72
|
+
const code = await buildScopeFixture({
|
|
73
|
+
plugins: [emberConfig()],
|
|
74
|
+
optimization: { pifeForModuleWrappers: false },
|
|
75
|
+
});
|
|
76
|
+
expect(code).toContain(`scope: () => ({ EMPTY })`);
|
|
77
|
+
});
|
|
78
|
+
});
|
package/src/config.ts
CHANGED
|
@@ -29,6 +29,19 @@ import type { TsdownPlugin, UserConfig } from "tsdown";
|
|
|
29
29
|
*
|
|
30
30
|
* - `output.sourcemap` — on
|
|
31
31
|
*
|
|
32
|
+
* One default applies through rolldown's `options` hook,
|
|
33
|
+
* so it holds under both tools:
|
|
34
|
+
*
|
|
35
|
+
* - `optimization.inlineConst` — off.
|
|
36
|
+
* Rolldown's default (`mode: "smart"`) puts an imported constant's literal
|
|
37
|
+
* into `precompileTemplate` scope objects:
|
|
38
|
+
* `scope: () => ({ EMPTY })` becomes `scope: () => ({ EMPTY: "—" })`.
|
|
39
|
+
* The consuming app's template compiler accepts only direct references there.
|
|
40
|
+
* The library still builds, type-checks, and lints clean,
|
|
41
|
+
* so the app boot is the first place the error shows.
|
|
42
|
+
* The compiler-side fix, which accepts literal scope values, is
|
|
43
|
+
* https://github.com/emberjs/babel-plugin-ember-template-compilation/pull/125
|
|
44
|
+
*
|
|
32
45
|
* Externals are handled by `emberExternals()` (a `resolveId` hook) in both cases.
|
|
33
46
|
*
|
|
34
47
|
* Bundle mode flips the dependency defaults.
|
|
@@ -66,6 +79,12 @@ export function emberConfig({ bundle = false }: { bundle?: boolean } = {}): Tsdo
|
|
|
66
79
|
config.deps.neverBundle ??= ["node:*", "@ember/*", "@glimmer/*"];
|
|
67
80
|
},
|
|
68
81
|
|
|
82
|
+
options(options) {
|
|
83
|
+
options.optimization ??= {};
|
|
84
|
+
options.optimization.inlineConst ??= false;
|
|
85
|
+
return options;
|
|
86
|
+
},
|
|
87
|
+
|
|
69
88
|
outputOptions(options) {
|
|
70
89
|
options.sourcemap ??= true;
|
|
71
90
|
return options;
|
|
@@ -3,7 +3,7 @@ import { resolve } from "node:path";
|
|
|
3
3
|
|
|
4
4
|
import { parseTsconfig, type TsConfigJsonResolved } from "get-tsconfig";
|
|
5
5
|
import type { Plugin } from "rolldown";
|
|
6
|
-
import type { UserConfig } from "tsdown";
|
|
6
|
+
import type { ResolvedConfig, UserConfig } from "tsdown";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Resolve the tsconfig the build will use.
|
|
@@ -75,7 +75,6 @@ function resolveTsconfigPath(option: string | boolean | undefined): string | und
|
|
|
75
75
|
*/
|
|
76
76
|
export function emberIsolatedDeclarations(): Plugin {
|
|
77
77
|
let tsconfigOption: string | boolean | undefined;
|
|
78
|
-
let emitsDeclarations = true;
|
|
79
78
|
|
|
80
79
|
return {
|
|
81
80
|
name: "ember:isolated-declarations",
|
|
@@ -84,12 +83,34 @@ export function emberIsolatedDeclarations(): Plugin {
|
|
|
84
83
|
// That means the cwd's tsconfig.json, the only thing it could mean there.
|
|
85
84
|
tsdownConfig(config: UserConfig) {
|
|
86
85
|
tsconfigOption = config.tsconfig;
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Runs after every plugin's `tsdownConfig`, so `dts` is final here.
|
|
90
|
+
*
|
|
91
|
+
* Must run before the build starts:
|
|
92
|
+
* tsdown sets up rolldown-plugin-dts while it resolves build options,
|
|
93
|
+
* and without a tsconfig that throws before any `buildStart` hook.
|
|
94
|
+
*/
|
|
95
|
+
tsdownConfigResolved(config: ResolvedConfig) {
|
|
96
|
+
if (config.tsconfig !== false || !config.dts) return;
|
|
97
|
+
|
|
98
|
+
// Without a tsconfig there is no `isolatedDeclarations`,
|
|
99
|
+
// so tsdown falls back to the tsc-based declaration pipeline.
|
|
89
100
|
//
|
|
90
|
-
//
|
|
91
|
-
//
|
|
92
|
-
|
|
101
|
+
// That pipeline reads source files from disk,
|
|
102
|
+
// and dies with "Source file not found" on every `.gts` / `.gjs`,
|
|
103
|
+
// since those only exist compiled in the module graph.
|
|
104
|
+
//
|
|
105
|
+
// Say so here instead of leaving that to be decoded.
|
|
106
|
+
throw new Error(
|
|
107
|
+
`\`tsconfig: false\` cannot be combined with declaration emit.\n\n` +
|
|
108
|
+
`Declarations are emitted by the isolated-declarations pipeline, which needs a ` +
|
|
109
|
+
`tsconfig setting "compilerOptions.isolatedDeclarations": true -- it is the only ` +
|
|
110
|
+
`pipeline that can see compiled .gts/.gjs modules.\n\n` +
|
|
111
|
+
`Either point tsdown's \`tsconfig\` option at such a config, or set \`dts: false\` ` +
|
|
112
|
+
`if this library ships no types.`,
|
|
113
|
+
);
|
|
93
114
|
},
|
|
94
115
|
|
|
95
116
|
buildStart: {
|
|
@@ -102,27 +123,6 @@ export function emberIsolatedDeclarations(): Plugin {
|
|
|
102
123
|
*/
|
|
103
124
|
order: "pre",
|
|
104
125
|
async handler() {
|
|
105
|
-
if (tsconfigOption === false) {
|
|
106
|
-
if (!emitsDeclarations) return;
|
|
107
|
-
|
|
108
|
-
// Without a tsconfig there is no `isolatedDeclarations`,
|
|
109
|
-
// so tsdown falls back to the tsc-based declaration pipeline.
|
|
110
|
-
//
|
|
111
|
-
// That pipeline reads source files from disk,
|
|
112
|
-
// and dies with "Source file not found" on every `.gts` / `.gjs`,
|
|
113
|
-
// since those only exist compiled in the module graph.
|
|
114
|
-
//
|
|
115
|
-
// Say so here instead of leaving that to be decoded.
|
|
116
|
-
this.error(
|
|
117
|
-
`\`tsconfig: false\` cannot be combined with declaration emit.\n\n` +
|
|
118
|
-
`Declarations are emitted by the isolated-declarations pipeline, which needs a ` +
|
|
119
|
-
`tsconfig setting "compilerOptions.isolatedDeclarations": true -- it is the only ` +
|
|
120
|
-
`pipeline that can see compiled .gts/.gjs modules.\n\n` +
|
|
121
|
-
`Either point tsdown's \`tsconfig\` option at such a config, or set \`dts: false\` ` +
|
|
122
|
-
`if this library ships no types.`,
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
126
|
const tsconfigPath = resolveTsconfigPath(tsconfigOption);
|
|
127
127
|
|
|
128
128
|
if (!tsconfigPath || !existsSync(tsconfigPath)) return;
|