@nullvoxpopuli/ember-rolldown 2.7.0 → 2.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +138 -98
- package/dist/app-reexports.d.ts +36 -26
- package/dist/app-reexports.d.ts.map +1 -1
- package/dist/app-reexports.js +21 -15
- package/dist/app-reexports.js.map +1 -1
- package/dist/index.d.ts +88 -35
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +351 -201
- package/dist/index.js.map +1 -1
- package/dist/plugin-like-BmC0mYXP.d.ts +30 -0
- package/dist/plugin-like-BmC0mYXP.d.ts.map +1 -0
- package/index.ts +66 -28
- package/package.json +2 -2
- package/src/app-reexports.test.ts +4 -3
- package/src/app-reexports.ts +37 -27
- package/src/babel.test.ts +10 -5
- package/src/babel.ts +117 -72
- package/src/bundle.test.ts +149 -0
- package/src/bundle.ts +71 -0
- package/src/config.ts +42 -18
- package/src/dts.test.ts +42 -26
- package/src/externals.test.ts +16 -11
- package/src/externals.ts +45 -28
- package/src/isolated-declarations.ts +56 -43
- package/src/plugin-like.ts +18 -15
- package/src/published-types.test.ts +18 -13
- package/src/transform.test.ts +26 -17
- package/src/transform.ts +68 -48
- package/dist/plugin-like-CBvGkzCB.d.ts +0 -27
- package/dist/plugin-like-CBvGkzCB.d.ts.map +0 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/babel.ts","../src/config.ts","../src/externals.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 babelHelpers?: \"bundled\" | \"runtime\" | \"inline\" | \"external\";\n /**\n * The babel config file to use.\n *\n * - `undefined`: auto-detect. A `babel.publish.config.*` (in the package root\n * or `config/`) wins, because this is a publish build; otherwise babel's own\n * 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\n * handled (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 (e.g. ember-scoped-css's `scopedCSS.template()`)\n * passed to the default `babel-plugin-ember-template-compilation` entry.\n *\n * Only valid without a babel config file: with your own config, you list\n * `babel-plugin-ember-template-compilation` yourself, so its `transforms`\n * belong there.\n */\n templateTransforms?: Transform[];\n /**\n * Opt additional files into babel (see maybeBabel's `filter`). Use this to\n * cover addons that ship code needing babel (e.g. `ember-concurrency`).\n */\n filter?: {\n include: {\n imports: string[];\n code: (string | RegExp)[];\n };\n };\n}\n\n/** Tried in order, so an ESM config wins over a JSON one of the same name. */\nconst PUBLISH_CONFIG_EXTENSIONS = [\"mjs\", \"cjs\", \"js\", \"mts\", \"cts\", \"ts\", \"json\"];\n\n/**\n * Tried in order: next to package.json first, then `config/` for libraries that\n * keep their build configuration 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\n * one.\n *\n * A library's plain `babel.config.*` is its *development* config: it typically\n * compiles `@embroider/macros` away, targets the wire format, and wires up\n * whatever the in-package demo app or test suite needs. None of that belongs in\n * a published artifact -- macros must stay for the consuming app to evaluate,\n * and the wire format is private between one template compiler and one glimmer\n * runtime. Babel's own resolution can't tell the two apart (it finds whatever\n * `babel.config.*` exists), so a publish build has to prefer the config named\n * 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 should use: a `babel.publish.config.*` when the\n * library has one, else the project's root babel config resolved the way babel\n * itself does (`babel.config.{js,cjs,mjs,cts,json}`, honoring `rootMode`\n * semantics) -- which for a library whose only config *is* its publish config\n * is the same file either way.\n *\n * The sync API evaluates the config file; on node 24+ that works for native\n * 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 * - template compilation to `precompileTemplate` (`targetFormat: \"hbs\"`).\n * Published libraries must NOT ship wire format: the wire format is\n * private between the template compiler and the glimmer runtime of the\n * same version, so baking it in ties the published artifact to the\n * consuming app's exact ember-source. The consuming app performs final\n * compilation.\n * - decorator-transforms, with its runtime left as a bare specifier so the\n * consuming app resolves it (the library keeps `decorator-transforms` as\n * a real dependency).\n */\nfunction defaultPlugins(templateTransforms?: Transform[]): PluginItem[] {\n return [\n [\n transformTypeScript,\n {\n allExtensions: true,\n onlyRemoveTypeImports: true,\n allowDeclareFields: true,\n },\n ],\n [templateCompilation, { targetFormat: \"hbs\", transforms: templateTransforms ?? [] }],\n [\n decoratorTransforms,\n {\n // Emit `import ... from \"decorator-transforms/runtime-esm\"` as a bare\n // specifier 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\n * reasons:\n *\n * - template compilation: `babel-plugin-ember-template-compilation` turns the\n * content-tag output into `precompileTemplate` calls; oxc has no equivalent.\n * - decorators: Ember uses the legacy/stage-1 decorator signature together\n * with `decorator-transforms`, which rewrites decorated class fields\n * (`@tracked x`) into getter/setters backed by a runtime. oxc's native\n * \"legacy decorators\" emit tsc-style `__decorate` output, which does not\n * match those semantics.\n *\n * But we don't want to send *every* file through babel and give back the speed\n * rolldown/oxc buys us -- so we run babel via `maybeBabel`, which filters down\n * to only the files that actually need it (template-tag, decorators, template\n * imports). Everything else stays on the native transform.\n *\n * The library's own babel config is used when it exists -- its\n * `babel.publish.config.*` (root or `config/`) in preference to its\n * `babel.config.*`, since this is a publish build. Without one, `defaultPlugins` covers templates, decorators,\n * and TypeScript, so no config file is required.\n *\n * Libraries default to `babelHelpers: \"bundled\"` so the emitted output is\n * 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): don't let babel go looking\n // for one -- we provide the whole plugin list inline.\n configFile: false,\n babelrc: false,\n plugins: defaultPlugins(options.templateTransforms).concat(options.plugins ?? []),\n }) as unknown as Plugin;\n}\n","import type { TsdownPlugin, UserConfig } from \"tsdown\";\n\n/**\n * Sensible defaults for an Ember v2 library, applied through plugin hooks so\n * they travel with `ember()` — you get them whether you use this package's\n * `defineConfig`, tsdown's, 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 (analogous to\n * 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 * since exports maps conventionally point at `.js`/`.d.ts`.\n * - `report` — off; the size report is noise for a library build.\n * - `deps.neverBundle` — leave node builtins and the ember virtual packages to\n * 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), so only the options with rolldown\n * equivalents are applied there, via rolldown's own `outputOptions` hook:\n *\n * - `output.sourcemap` — on (output option).\n *\n * Externals are handled by `emberExternals()` (a `resolveId` hook) in both cases.\n */\nexport function emberConfig(): 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 config.deps.neverBundle ??= [\"node:*\", \"@ember/*\", \"@glimmer/*\"];\n },\n\n outputOptions(options) {\n options.sourcemap ??= true;\n return options;\n },\n };\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` is\n * 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 module names ember-source provides by renaming them into itself — the\n * keys of its `ember-addon.renamed-modules`, normalized from file paths to\n * import specifiers (`@glimmer/runtime/index.js` → `@glimmer/runtime`).\n *\n * This is the authoritative list of ember's provided modules, including\n * private API that @embroider/core's emberVirtualPackages doesn't cover\n * (e.g. `@glimmer/runtime`). It deliberately does NOT include real packages\n * like `@glimmer/component`, which a library may want bundled.\n *\n * Resolved from the library's own dependency graph; empty when ember-source\n * isn't resolvable there.\n */\nfunction emberSourceRenamedModules(): Set<string> {\n const provided = new Set<string>();\n\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 for (const key of Object.keys(manifest[\"ember-addon\"]?.[\"renamed-modules\"] ?? {})) {\n provided.add(key.replace(/\\.js$/, \"\").replace(/\\/index$/, \"\"));\n }\n } catch {\n // The library doesn't have ember-source in its graph; nothing to provide.\n }\n\n return provided;\n}\n\n/**\n * Keeps the library's declared dependencies and the ember virtual packages\n * (things like `@ember/component`, `@glimmer/tracking`, the template compiler,\n * …) external, so the app that consumes the library resolves them instead of\n * 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 = emberSourceRenamedModules();\n },\n\n resolveId: {\n order: \"pre\",\n handler(source) {\n // Anything with a protocol (`node:`, virtual modules, …) is not ours\n // 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`) — private API like\n // `@glimmer/runtime` that only exists inside the app's ember-source.\n // Matched on the full specifier: the renamed modules are module\n // paths, not packages.\n if (renamedModules.has(source)) {\n return false;\n }\n\n return undefined;\n },\n },\n };\n}\n","import { existsSync, statSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\n\nimport type { Plugin } from \"rolldown\";\nimport type { UserConfig } from \"tsdown\";\n\n/**\n * Resolve the tsconfig the build will actually use, mirroring tsdown's own\n * `tsconfig` option (`string | boolean`):\n *\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, so the cwd's `tsconfig.json`\n * 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 does not set\n * `isolatedDeclarations: true`.\n *\n * This is required: declarations for `.gts`/`.gjs` (template tag) modules can\n * only be emitted by the isolated-declarations pipeline, which reads compiled\n * modules from the bundler's module graph. The `tsc`-based pipeline reads\n * source files from disk, where the compiled modules don't exist, and fails\n * with \"Source file not found\".\n *\n * Failing fast here -- rather than only when declaration emit happens to run\n * -- keeps the project honest: editors and `tsc`/`ember-tsc` then check the\n * same rules the build enforces (exported values need explicit type\n * annotations, e.g. `export const X: TOC<Sig> = <template>...`).\n *\n * The tsconfig checked is the one tsdown's `tsconfig` option points at, not\n * necessarily `tsconfig.json`. A library whose package also holds dev-only code\n * (a demo app, in-package tests) can therefore keep a permissive\n * `tsconfig.json` covering everything for editors and `tsc --noEmit`, and point\n * the build at a `tsconfig.publish.json` that covers only the publishable\n * sources -- isolated declarations then constrain exactly the code that gets\n * declarations emitted for it, and nothing else.\n *\n * Projects with no tsconfig (JavaScript libraries) or without the `typescript`\n * package have no declarations to emit, so there is nothing to check.\n * `tsconfig: false` is different: it is an explicit opt-out, and combined with\n * declaration emit it produces a confusing \"Source file not found\" from the\n * 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 // -- i.e. 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, so an\n // explicit `false` is the only \"no declarations\" signal. Hook order\n // between plugins isn't guaranteed, so don't rely on it having run.\n emitsDeclarations = config.dts !== false;\n },\n\n async buildStart() {\n if (tsconfigOption === false) {\n if (!emitsDeclarations) return;\n\n // Without a tsconfig there is no `isolatedDeclarations`, so tsdown\n // falls back to the tsc-based declaration pipeline -- which reads\n // source files from disk and dies with \"Source file not found\" on\n // every `.gts`/`.gjs`, since those only exist compiled in the module\n // graph. 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 ts: typeof import(\"typescript\");\n\n try {\n ts = (await import(\"typescript\")).default;\n } catch {\n return;\n }\n\n const { config, error } = ts.readConfigFile(tsconfigPath, ts.sys.readFile);\n\n if (error) {\n // Unreadable/unparsable tsconfig: tsc itself will report this with a\n // better message than we can.\n return;\n }\n\n // Resolves `extends` chains, so the flag may come from a base config.\n const parsed = ts.parseJsonConfigFileContent(config, ts.sys, dirname(tsconfigPath));\n\n if (parsed.options.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","import { Preprocessor } from \"content-tag\";\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`\n * specifiers. Consumers can't resolve those, so we rewrite them back to\n * 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 mapping every generated line to the same line of the input.\n *\n * `AAAA` is the [0, 0, 0, 0] VLQ segment (first line maps to source 0, line 0,\n * column 0); `AACA` is [0, 0, +1, 0] (each following line advances the source\n * line by one). Exact at line granularity, which is all the specifier rewrite\n * can disturb.\n */\nfunction lineIdentityMap(id: string, source: string) {\n return {\n version: 3,\n sources: [id],\n sourcesContent: [source],\n names: [],\n mappings: source\n .split(\"\\n\")\n .map((_, line) => (line === 0 ? \"AAAA\" : \"AACA\"))\n .join(\";\"),\n };\n}\n\n/**\n * Maps `.gts` -> `.ts` and `.gjs` -> `.js` (so rolldown can identify them as\n * ts/js) and preprocesses `<template>` via content-tag.\n */\nexport function emberTransform(): Plugin {\n return {\n name: \"ember:transform\",\n\n resolveId: {\n order: \"pre\",\n handler(id, importer) {\n // Entries have no importer: their ids come straight from the build\n // config (tsdown expands entry globs to on-disk paths). Resolve a\n // `.gts`/`.gjs` entry to the same virtual `.ts`/`.js` id an imported\n // module gets, so the load hook compiles it via content-tag instead\n // of the raw `<template>` source hitting the parser. Entries may be\n // any extension — the emitted `.js`/`.d.ts` paths mirror the entry\n // paths either way (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 (e.g. macOS\n // /var -> /private/var). Match it, or this same file imported from\n // another entry resolves to a second module id and gets duplicated\n // 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, so it needs no\n // importer-relative resolution — and joining it onto the importer's\n // directory would corrupt it. That is not hypothetical: a plugin's\n // virtual module (id prefixed with `\\0`) can generate imports of\n // on-disk files by absolute path, and `path.dirname(\"\\0./registry\")`\n // is `\"\\0.\"`, so joining yields `\"\\0./Users/.../thing.gts\"` — a path\n // 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. This must also serve `.d.ts`\n // importers: rolldown-plugin-dts resolves a declaration module's\n // imports through the plugin pipeline (`this.resolve`), and — when the\n // resolution is a source file — loads it (registering its declaration)\n // before mapping the import to the declaration id. Virtual modules\n // exist nowhere else, so if we don't answer here the import either\n // fails to resolve (no file on disk) or, worse, resolves to a\n // 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\n // resolveId (rolldown-plugin-dts calls `this.load({ id })` with just\n // the id), so no meta is attached: 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 return { code, map };\n }\n\n return source;\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 — in\n // runtime modules AND declaration modules alike. Declaration modules\n // must NOT be rewritten to `.d.ts`: rolldown-plugin-dts's resolver\n // treats a source-file resolution as \"load it (registering its\n // declaration), then map to the declaration id\", while a `.d.ts` id is\n // returned as-is — unloadable when the module isn't registered yet\n // (e.g. the `.gts` is only ever type-imported).\n const output = input.replace(\n /(['\"`])((?:\\.\\.?\\/|\\/|@|[A-Za-z0-9_\\-])[^'\"]*?\\.gts)\\1/g,\n (_m, q, p) => `${q}${p.replace(/\\.gts$/, \".ts\")}${q}`,\n );\n\n if (output === input) {\n return null;\n }\n\n // The rewrite only shortens import specifiers in place, so a\n // line-identity map is accurate to the line (and to the column for\n // everything before the first rewritten specifier on a line).\n return { code: output, map: lineIdentityMap(id, input) };\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 { 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 * Options for the babel step; see `BabelOptions`.\n */\n babel?: BabelOptions;\n}\n\n/**\n * A batteries-included plugin for building Ember v2 libraries (addons) with\n * rolldown (or tsdown, which is built on rolldown).\n *\n * It bundles everything needed to compile `.gts`/`.gjs` and template-tag\n * (`<template>`) source into publishable output:\n *\n * - `emberConfig()` — 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 * - `emberIsolatedDeclarations()` — errors when a tsconfig.json is present\n * without `isolatedDeclarations: true` (required: it is the only\n * declaration pipeline that can see compiled template-tag modules).\n * - `emberExternals()` — keeps your dependencies, peerDependencies, and the\n * ember virtual packages external, so consuming apps resolve them.\n * - `emberTransform()` — preprocesses `<template>` via content-tag and maps\n * `.gts`/`.gjs` to `.ts`/`.js` so rolldown can understand them.\n * - `emberBabel()` — runs babel (template compilation, decorators, type\n * stripping) with `babelHelpers: \"bundled\"`, but only on the files that\n * actually need it (via `maybeBabel`); everything else stays on the fast\n * native transform. The library's own `babel.config.js` is used when it\n * exists; no config file is required.\n *\n * Usage in `tsdown.config.js` (import `defineConfig` from `tsdown` — or from\n * `rolldown` for a `rolldown.config.js` — 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 return [\n emberConfig(),\n emberIsolatedDeclarations(),\n emberExternals(),\n emberTransform(),\n emberBabel(config.babel),\n ];\n}\n"],"mappings":";;;;;;;;;;;;;AAoDA,MAAM,4BAA4B;CAAC;CAAO;CAAO;CAAM;CAAO;CAAO;CAAM;AAAM;;;;;AAMjF,MAAM,6BAA6B,CAAC,KAAK,QAAQ;;;;;;;;;;;;;;AAejD,SAAS,0BAA8C;CACrD,KAAK,MAAM,aAAa,4BACtB,KAA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SAAS,KAAK,KAAK,WAAW,GAAG,QAAQ,SAAS,MAAM,CAAC,GACrE,WAAW,GAAG,QAAQ,SAAS,MAAM;IAAA;IAIzC,IAAI,UAAU;KACZ,KAAK,aAAa,QAAQ;KAC1B,MAAM,SAAS,MAAM,SAAS,UAAU,EAAE,UAAU,OAAO,CAAC;KAE5D,IAAI,OAAO,SAAS,YAAY,GAAG;MACjC,MAAM,EAAE,MAAM,QAAQ,UAAU,QAAQ,QAAQ,EAC9C,UAAU,SACZ,CAAC;MACD,OAAO;OAAE;OAAM;MAAI;KACrB;KAEA,OAAO;IACT;IAEA,OAAO;GACT;EACF;EAEA,WAAW;GACT,OAAO;GACP,QAAQ;IACN,MAAM;IACN,IAAI;GACN;GACA,QAAQ,OAAO,IAAI;IAQjB,MAAM,SAAS,MAAM,QACnB,4DACC,IAAI,GAAG,MAAM,GAAG,IAAI,EAAE,QAAQ,UAAU,KAAK,IAAI,GACpD;IAEA,IAAI,WAAW,OACb,OAAO;IAMT,OAAO;KAAE,MAAM;KAAQ,KAAK,gBAAgB,IAAI,KAAK;IAAE;GACzD;EACF;EAEA,aAAa,EACX,MAAM,QAAQ,SAAS;GACrB,MAAM,SAAU,QAA6B;GAC7C,IAAI,QACF,MAAM,sBAAsB,KAAK,QAAQ,MAAM,CAAC;EAEpD,EACF;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC5KA,SAAgB,MAAM,SAAiB,CAAC,GAAyB;CAC/D,OAAO;EACL,YAAY;EACZ,0BAA0B;EAC1B,eAAe;EACf,eAAe;EACf,WAAW,OAAO,KAAK;CACzB;AACF"}
|
|
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 { dirname, resolve } from \"node:path\";\n\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) or without the `typescript` package\n * have no declarations to emit, so there is nothing to check.\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 async buildStart() {\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 ts: typeof import(\"typescript\");\n\n try {\n ts = (await import(\"typescript\")).default;\n } catch {\n return;\n }\n\n const { config, error } = ts.readConfigFile(tsconfigPath, ts.sys.readFile);\n\n if (error) {\n // Unreadable / unparsable tsconfig.\n // tsc itself will report this with a better message than we can.\n return;\n }\n\n // Resolves `extends` chains, so the flag may come from a base config.\n const parsed = ts.parseJsonConfigFileContent(config, ts.sys, dirname(tsconfigPath));\n\n if (parsed.options.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","import { Preprocessor } from \"content-tag\";\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 mapping every generated line to the same line of the input.\n *\n * - `AAAA` is the [0, 0, 0, 0] VLQ segment\n * (first line maps to source 0, line 0, column 0)\n * - `AACA` is [0, 0, +1, 0]\n * (each following line advances the source line by one)\n *\n * Exact at line granularity, which is all the specifier rewrite can disturb.\n */\nfunction lineIdentityMap(id: string, source: string) {\n return {\n version: 3,\n sources: [id],\n sourcesContent: [source],\n names: [],\n mappings: source\n .split(\"\\n\")\n .map((_, line) => (line === 0 ? \"AAAA\" : \"AACA\"))\n .join(\";\"),\n };\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 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 return { code, map };\n }\n\n return source;\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 = input.replace(\n /(['\"`])((?:\\.\\.?\\/|\\/|@|[A-Za-z0-9_\\-])[^'\"]*?\\.gts)\\1/g,\n (_m, q, p) => `${q}${p.replace(/\\.gts$/, \".ts\")}${q}`,\n );\n\n if (output === input) {\n return null;\n }\n\n // The rewrite only shortens import specifiers in place,\n // so a line-identity map is accurate to the line\n // (and to the column, for everything before the first rewritten specifier on a line).\n return { code: output, map: lineIdentityMap(id, input) };\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;C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,GAAG,OAAO;GAAO;EAAO,CAAC;CACxC;AACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/plugin-like.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* What this package hands back:
|
|
4
|
+
* an object that rolldown and tsdown accept in `plugins`.
|
|
5
|
+
*
|
|
6
|
+
* Structurally this *is* rolldown's `Plugin`.
|
|
7
|
+
* `name` is its only required member, every hook is optional.
|
|
8
|
+
*
|
|
9
|
+
* So the two are assignable in both directions:
|
|
10
|
+
* - a consumer who imports rolldown's own type can still write
|
|
11
|
+
* `const plugins: Plugin[] = ember()`
|
|
12
|
+
* - tsdown's `plugins` option lists `{ name: string }` among the shapes it takes
|
|
13
|
+
*
|
|
14
|
+
* Declaring it here, rather than re-exporting rolldown's type,
|
|
15
|
+
* keeps `rolldown` out of the published declarations.
|
|
16
|
+
*
|
|
17
|
+
* Otherwise it has to become a runtime `dependency`, purely so consumers can resolve a type.
|
|
18
|
+
* Leave it a devDependency, and the declaration bundler inlines a ~200kB private copy
|
|
19
|
+
* of rolldown's types instead, nominally distinct from the consumer's own.
|
|
20
|
+
*
|
|
21
|
+
* The precise hook signatures still apply inside this package.
|
|
22
|
+
* Each plugin function is typed with rolldown's real `Plugin` (a devDependency).
|
|
23
|
+
* This type only widens what crosses the package boundary.
|
|
24
|
+
*/
|
|
25
|
+
interface RolldownPluginLike {
|
|
26
|
+
name: string;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { RolldownPluginLike as t };
|
|
30
|
+
//# sourceMappingURL=plugin-like-BmC0mYXP.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-like-BmC0mYXP.d.ts","names":[],"sources":["../src/plugin-like.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;UAuBiB;EACf"}
|
package/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { emberBabel, type BabelOptions } from "./src/babel.ts";
|
|
2
|
+
import { emberBundle } from "./src/bundle.ts";
|
|
2
3
|
import { emberConfig } from "./src/config.ts";
|
|
3
4
|
import { emberExternals } from "./src/externals.ts";
|
|
4
5
|
import { emberIsolatedDeclarations } from "./src/isolated-declarations.ts";
|
|
@@ -7,36 +8,71 @@ import type { RolldownPluginLike } from "./src/plugin-like.ts";
|
|
|
7
8
|
|
|
8
9
|
interface Config {
|
|
9
10
|
/**
|
|
10
|
-
*
|
|
11
|
+
* Build a self-contained package instead of a library.
|
|
12
|
+
*
|
|
13
|
+
* `false` (the default) builds a library for Ember apps:
|
|
14
|
+
* - ember, the package's dependencies, and its peerDependencies stay external
|
|
15
|
+
* - templates are shipped as `precompileTemplate` calls,
|
|
16
|
+
* for the consuming app to compile
|
|
17
|
+
*
|
|
18
|
+
* `true` builds an artifact that runs on any page, such as a custom element:
|
|
19
|
+
* - ember-source, `@glimmer/component`, `decorator-transforms`,
|
|
20
|
+
* and every other dependency are bundled in
|
|
21
|
+
* - templates are compiled to the wire format with that same ember-source
|
|
22
|
+
* - declarations bundle their type imports as well
|
|
23
|
+
*
|
|
24
|
+
* Which ember-source build is bundled follows the export conditions:
|
|
25
|
+
* - production by default
|
|
26
|
+
* - development with `resolve.conditionNames: ["development"]`
|
|
27
|
+
*/
|
|
28
|
+
bundle?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Options for the babel step.
|
|
31
|
+
* See `BabelOptions`.
|
|
11
32
|
*/
|
|
12
33
|
babel?: BabelOptions;
|
|
13
34
|
}
|
|
14
35
|
|
|
15
36
|
/**
|
|
16
|
-
* A batteries-included plugin for building Ember v2 libraries (addons)
|
|
17
|
-
* rolldown
|
|
18
|
-
*
|
|
19
|
-
* It bundles everything needed to compile `.gts
|
|
20
|
-
* (`<template>`) source into publishable output:
|
|
21
|
-
*
|
|
22
|
-
* - `emberConfig()`
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
37
|
+
* A batteries-included plugin for building Ember v2 libraries (addons)
|
|
38
|
+
* with rolldown, or with tsdown (which is built on rolldown).
|
|
39
|
+
*
|
|
40
|
+
* It bundles everything needed to compile `.gts` / `.gjs` and
|
|
41
|
+
* template-tag (`<template>`) source into publishable output:
|
|
42
|
+
*
|
|
43
|
+
* - `emberConfig()`
|
|
44
|
+
* applies sensible tsdown defaults for a library build
|
|
45
|
+
* (sourcemaps, `clean`, `dts`, `.js` / `.d.ts` extensions, quiet logging).
|
|
46
|
+
* Anything you set explicitly still wins.
|
|
47
|
+
*
|
|
48
|
+
* - `emberIsolatedDeclarations()`
|
|
49
|
+
* errors when a tsconfig.json is present without `isolatedDeclarations: true`.
|
|
50
|
+
* That is the only declaration pipeline that can see compiled template-tag modules.
|
|
51
|
+
*
|
|
52
|
+
* - `emberExternals()`
|
|
53
|
+
* keeps your dependencies, peerDependencies, and the ember virtual packages external,
|
|
54
|
+
* so consuming apps resolve them.
|
|
55
|
+
*
|
|
56
|
+
* - `emberBundle()`
|
|
57
|
+
* bundle mode only, in place of `emberExternals()`.
|
|
58
|
+
* Aliases the ember virtual packages into ember-source,
|
|
59
|
+
* whose export conditions pick the build to bundle.
|
|
60
|
+
*
|
|
61
|
+
* - `emberTransform()`
|
|
62
|
+
* preprocesses `<template>` via content-tag,
|
|
63
|
+
* and maps `.gts` / `.gjs` to `.ts` / `.js` so rolldown can understand them.
|
|
64
|
+
*
|
|
65
|
+
* - `emberBabel()`
|
|
66
|
+
* runs babel (template compilation, decorators, type stripping)
|
|
67
|
+
* with `babelHelpers: "bundled"`.
|
|
68
|
+
* Only the files that need it go through babel (via `maybeBabel`).
|
|
69
|
+
* Everything else stays on the fast native transform.
|
|
70
|
+
* The library's own `babel.config.js` is used when it exists.
|
|
71
|
+
* No config file is required.
|
|
72
|
+
*
|
|
73
|
+
* Usage in `tsdown.config.js`.
|
|
74
|
+
* Import `defineConfig` from `tsdown` (or from `rolldown` for a `rolldown.config.js`)
|
|
75
|
+
* so it carries the correct types:
|
|
40
76
|
*
|
|
41
77
|
* ```js
|
|
42
78
|
* import { defineConfig } from "tsdown";
|
|
@@ -49,11 +85,13 @@ interface Config {
|
|
|
49
85
|
* ```
|
|
50
86
|
*/
|
|
51
87
|
export function ember(config: Config = {}): RolldownPluginLike[] {
|
|
88
|
+
const bundle = config.bundle ?? false;
|
|
89
|
+
|
|
52
90
|
return [
|
|
53
|
-
emberConfig(),
|
|
91
|
+
emberConfig({ bundle }),
|
|
54
92
|
emberIsolatedDeclarations(),
|
|
55
|
-
emberExternals(),
|
|
93
|
+
bundle ? emberBundle() : emberExternals(),
|
|
56
94
|
emberTransform(),
|
|
57
|
-
emberBabel(config.babel),
|
|
95
|
+
emberBabel({ ...config.babel, bundle }),
|
|
58
96
|
];
|
|
59
97
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nullvoxpopuli/ember-rolldown",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.1",
|
|
4
4
|
"description": "Meta plugin for building ember v2 libraries/addons with rolldown & tsdown.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"babel-plugin-ember-template-compilation": "^4.0.0",
|
|
37
37
|
"content-tag": "^4.2.0",
|
|
38
38
|
"decorator-transforms": "^2.3.2",
|
|
39
|
-
"@nullvoxpopuli/ember-build-tooling-utils": "1.1.
|
|
39
|
+
"@nullvoxpopuli/ember-build-tooling-utils": "1.1.1"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|
|
42
42
|
"node": ">= 24"
|
|
@@ -8,9 +8,10 @@ import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
|
8
8
|
import { appReexports, type AppReexportsOptions } from "./app-reexports.ts";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* The plugin reads and writes package.json relative to the current working
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* The plugin reads and writes package.json relative to the current working directory
|
|
12
|
+
* (matching the other plugins in this package).
|
|
13
|
+
*
|
|
14
|
+
* So each test runs inside its own temp project.
|
|
14
15
|
*/
|
|
15
16
|
describe("appReexports", () => {
|
|
16
17
|
let projectDir: string;
|
package/src/app-reexports.ts
CHANGED
|
@@ -5,13 +5,14 @@ import type { RolldownPluginLike } from "./plugin-like.ts";
|
|
|
5
5
|
|
|
6
6
|
export interface AppReexportsOptions {
|
|
7
7
|
/**
|
|
8
|
-
* Globs
|
|
9
|
-
*
|
|
8
|
+
* Globs selecting which modules get an app re-export.
|
|
9
|
+
* Matched against each built filename, relative to the output directory.
|
|
10
10
|
*
|
|
11
|
-
* Defaults to `["services/*"]
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
* Defaults to `["services/*"]`: top-level services only.
|
|
12
|
+
*
|
|
13
|
+
* Under strict mode, components and helpers are imported.
|
|
14
|
+
* Services are still injected by name,
|
|
15
|
+
* so they are the one thing an app must always be able to resolve.
|
|
15
16
|
*
|
|
16
17
|
* `.d.ts` files never match.
|
|
17
18
|
*/
|
|
@@ -23,33 +24,39 @@ export interface AppReexportsOptions {
|
|
|
23
24
|
exclude?: string[];
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
|
-
* Rename a re-export
|
|
27
|
-
*
|
|
27
|
+
* Rename a re-export.
|
|
28
|
+
*
|
|
29
|
+
* Receives the built filename, returns the filename the app sees.
|
|
30
|
+
* Defaults to the built filename unchanged.
|
|
28
31
|
*/
|
|
29
32
|
mapFilename?: (filename: string) => string;
|
|
30
33
|
|
|
31
34
|
/**
|
|
32
|
-
* Which bindings a file's re-export module forwards:
|
|
33
|
-
* (default `["default"]`)
|
|
35
|
+
* Which bindings a file's re-export module forwards:
|
|
36
|
+
* - an array of names (default `["default"]`)
|
|
37
|
+
* - or a raw export clause string such as `"*"`
|
|
34
38
|
*/
|
|
35
39
|
exports?: (filename: string) => string[] | string | undefined;
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
/**
|
|
39
|
-
* Merges built modules into the consuming app's namespace,
|
|
40
|
-
*
|
|
41
|
-
*
|
|
43
|
+
* Merges built modules into the consuming app's namespace,
|
|
44
|
+
* so classic resolution finds them
|
|
45
|
+
* (`{{a-component}}`, service / helper lookup by name).
|
|
46
|
+
*
|
|
47
|
+
* The same job as `@embroider/addon-dev`'s `appReexports` rollup plugin.
|
|
42
48
|
*
|
|
43
|
-
* For every built file matching `include` (minus `exclude` and `.d.ts`)
|
|
44
|
-
* writes a tiny module under `<outDir>/_app_
|
|
45
|
-
* library's own name
|
|
46
|
-
* `ember-addon.app-js
|
|
49
|
+
* For every built file matching `include` (minus `exclude` and `.d.ts`):
|
|
50
|
+
* - writes a tiny module under `<outDir>/_app_/`,
|
|
51
|
+
* re-exporting from the library's own name
|
|
52
|
+
* - records the full set in `package.json` under `ember-addon.app-js`
|
|
47
53
|
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
54
|
+
* Nothing is written unless its content differs from what is on disk:
|
|
55
|
+
* - the `_app_/` modules are compared byte-for-byte
|
|
56
|
+
* - `package.json` is only rewritten when the `app-js` map itself changed
|
|
57
|
+
* (an equivalent map in different formatting is left alone)
|
|
58
|
+
*
|
|
59
|
+
* This keeps rebuilds from re-triggering file watchers.
|
|
53
60
|
*
|
|
54
61
|
* This is a separate import, because most libraries don't need it:
|
|
55
62
|
*
|
|
@@ -64,9 +71,12 @@ export interface AppReexportsOptions {
|
|
|
64
71
|
* });
|
|
65
72
|
* ```
|
|
66
73
|
*
|
|
67
|
-
* With no arguments, top-level services (`services/*`) are re-exported.
|
|
68
|
-
*
|
|
69
|
-
*
|
|
74
|
+
* With no arguments, top-level services (`services/*`) are re-exported.
|
|
75
|
+
*
|
|
76
|
+
* The first argument can be:
|
|
77
|
+
* - a string or array of strings: the include glob(s),
|
|
78
|
+
* optionally followed by the remaining options
|
|
79
|
+
* - an object: full control
|
|
70
80
|
*
|
|
71
81
|
* ```js
|
|
72
82
|
* appReexports(); // services/*
|
|
@@ -97,7 +107,7 @@ export function appReexports(
|
|
|
97
107
|
const appJs: Record<string, string> = {};
|
|
98
108
|
|
|
99
109
|
// Sorted so the app-js map (and therefore package.json) is stable
|
|
100
|
-
// across builds regardless of chunk emission order.
|
|
110
|
+
// across builds, regardless of chunk emission order.
|
|
101
111
|
for (const builtFilename of Object.keys(bundle).sort()) {
|
|
102
112
|
if (!isIncluded(builtFilename, include, resolved.exclude)) continue;
|
|
103
113
|
|
|
@@ -143,7 +153,7 @@ function writeFileIfChanged(path: string, content: string) {
|
|
|
143
153
|
try {
|
|
144
154
|
existing = readFileSync(path, { encoding: "utf8" });
|
|
145
155
|
} catch {
|
|
146
|
-
// Doesn't exist yet (or isn't readable)
|
|
156
|
+
// Doesn't exist yet (or isn't readable): write it.
|
|
147
157
|
}
|
|
148
158
|
|
|
149
159
|
if (existing === content) return;
|
package/src/babel.test.ts
CHANGED
|
@@ -15,8 +15,9 @@ afterEach(() => {
|
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* A babel config whose only plugin rewrites the string `"MARKER"` to `name
|
|
19
|
-
*
|
|
18
|
+
* A babel config whose only plugin rewrites the string `"MARKER"` to `name`.
|
|
19
|
+
*
|
|
20
|
+
* So the emitted code says which config file babel loaded.
|
|
20
21
|
*/
|
|
21
22
|
function markerConfig(name: string): string {
|
|
22
23
|
return [
|
|
@@ -37,9 +38,13 @@ function markerConfig(name: string): string {
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
/**
|
|
40
|
-
* Builds a `.gts` entry
|
|
41
|
-
*
|
|
42
|
-
*
|
|
41
|
+
* Builds a `.gts` entry in a temp dir that becomes the cwd,
|
|
42
|
+
* the way config detection sees it under the tsdown CLI.
|
|
43
|
+
*
|
|
44
|
+
* A `.gts` entry so babel runs at all:
|
|
45
|
+
* `maybeBabel` skips files that need no transform.
|
|
46
|
+
*
|
|
47
|
+
* Returns the emitted code.
|
|
43
48
|
*/
|
|
44
49
|
async function bundleWithBabel(
|
|
45
50
|
files: Record<string, string>,
|