@nullvoxpopuli/ember-rolldown 2.8.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -100
- 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 +54 -37
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +193 -146
- 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 +37 -24
- package/package.json +5 -5
- 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 +88 -69
- package/src/config.ts +21 -17
- package/src/dts.test.ts +42 -26
- package/src/externals.test.ts +16 -11
- package/src/externals.ts +18 -12
- 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.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as RolldownPluginLike } from "./plugin-like-
|
|
1
|
+
import { t as RolldownPluginLike } from "./plugin-like-BmC0mYXP.js";
|
|
2
2
|
import { Transform } from "babel-plugin-ember-template-compilation";
|
|
3
3
|
import { PluginItem } from "@babel/core";
|
|
4
4
|
//#region src/babel.d.ts
|
|
@@ -21,14 +21,15 @@ interface BabelOptions {
|
|
|
21
21
|
/**
|
|
22
22
|
* The babel config file to use.
|
|
23
23
|
*
|
|
24
|
-
* - `undefined`: auto-detect.
|
|
25
|
-
*
|
|
26
|
-
*
|
|
24
|
+
* - `undefined`: auto-detect.
|
|
25
|
+
* A `babel.publish.config.*` (in the package root or `config/`) wins,
|
|
26
|
+
* because this is a publish build.
|
|
27
|
+
* Otherwise babel's own config resolution applies (see `detectConfigFile`).
|
|
27
28
|
* - a string: use that config file.
|
|
28
29
|
* - `false`: ignore config files entirely.
|
|
29
30
|
*
|
|
30
|
-
* Without a config file, templates, decorators, and TypeScript are still
|
|
31
|
-
*
|
|
31
|
+
* Without a config file, templates, decorators, and TypeScript are still handled
|
|
32
|
+
* (see `defaultPlugins`).
|
|
32
33
|
*/
|
|
33
34
|
configFile?: string | false;
|
|
34
35
|
/**
|
|
@@ -36,17 +37,20 @@ interface BabelOptions {
|
|
|
36
37
|
*/
|
|
37
38
|
plugins?: PluginItem[];
|
|
38
39
|
/**
|
|
39
|
-
* Template AST transforms
|
|
40
|
-
*
|
|
40
|
+
* Template AST transforms passed to the default
|
|
41
|
+
* `babel-plugin-ember-template-compilation` entry.
|
|
42
|
+
* e.g. ember-scoped-css's `scopedCSS.template()`
|
|
41
43
|
*
|
|
42
|
-
* Only valid without a babel config file
|
|
43
|
-
* `babel-plugin-ember-template-compilation` yourself,
|
|
44
|
-
* belong there.
|
|
44
|
+
* Only valid without a babel config file.
|
|
45
|
+
* With your own config, you list `babel-plugin-ember-template-compilation` yourself,
|
|
46
|
+
* so its `transforms` belong there.
|
|
45
47
|
*/
|
|
46
48
|
templateTransforms?: Transform[];
|
|
47
49
|
/**
|
|
48
|
-
* Opt additional files into babel (see maybeBabel's `filter`).
|
|
49
|
-
*
|
|
50
|
+
* Opt additional files into babel (see maybeBabel's `filter`).
|
|
51
|
+
*
|
|
52
|
+
* Use this to cover addons that ship code needing babel
|
|
53
|
+
* (e.g. `ember-concurrency`).
|
|
50
54
|
*/
|
|
51
55
|
filter?: {
|
|
52
56
|
include: {
|
|
@@ -78,38 +82,51 @@ interface Config {
|
|
|
78
82
|
*/
|
|
79
83
|
bundle?: boolean;
|
|
80
84
|
/**
|
|
81
|
-
* Options for the babel step
|
|
85
|
+
* Options for the babel step.
|
|
86
|
+
* See `BabelOptions`.
|
|
82
87
|
*/
|
|
83
88
|
babel?: BabelOptions;
|
|
84
89
|
}
|
|
85
90
|
/**
|
|
86
|
-
* A batteries-included plugin for building Ember v2 libraries (addons)
|
|
87
|
-
* rolldown
|
|
91
|
+
* A batteries-included plugin for building Ember v2 libraries (addons)
|
|
92
|
+
* with rolldown, or with tsdown (which is built on rolldown).
|
|
93
|
+
*
|
|
94
|
+
* It bundles everything needed to compile `.gts` / `.gjs` and
|
|
95
|
+
* template-tag (`<template>`) source into publishable output:
|
|
96
|
+
*
|
|
97
|
+
* - `emberConfig()`
|
|
98
|
+
* applies sensible tsdown defaults for a library build
|
|
99
|
+
* (sourcemaps, `clean`, `dts`, `.js` / `.d.ts` extensions, quiet logging).
|
|
100
|
+
* Anything you set explicitly still wins.
|
|
88
101
|
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
102
|
+
* - `emberIsolatedDeclarations()`
|
|
103
|
+
* errors when a tsconfig.json is present without `isolatedDeclarations: true`.
|
|
104
|
+
* That is the only declaration pipeline that can see compiled template-tag modules.
|
|
91
105
|
*
|
|
92
|
-
* - `
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* ember virtual packages external, so consuming apps resolve them.
|
|
100
|
-
* - `emberBundle()` — bundle mode only, in place of `emberExternals()`:
|
|
101
|
-
* aliases the ember virtual packages into ember-source,
|
|
106
|
+
* - `emberExternals()`
|
|
107
|
+
* keeps your dependencies, peerDependencies, and the ember virtual packages external,
|
|
108
|
+
* so consuming apps resolve them.
|
|
109
|
+
*
|
|
110
|
+
* - `emberBundle()`
|
|
111
|
+
* bundle mode only, in place of `emberExternals()`.
|
|
112
|
+
* Aliases the ember virtual packages into ember-source,
|
|
102
113
|
* whose export conditions pick the build to bundle.
|
|
103
|
-
* - `emberTransform()` — preprocesses `<template>` via content-tag and maps
|
|
104
|
-
* `.gts`/`.gjs` to `.ts`/`.js` so rolldown can understand them.
|
|
105
|
-
* - `emberBabel()` — runs babel (template compilation, decorators, type
|
|
106
|
-
* stripping) with `babelHelpers: "bundled"`, but only on the files that
|
|
107
|
-
* actually need it (via `maybeBabel`); everything else stays on the fast
|
|
108
|
-
* native transform. The library's own `babel.config.js` is used when it
|
|
109
|
-
* exists; no config file is required.
|
|
110
114
|
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
115
|
+
* - `emberTransform()`
|
|
116
|
+
* preprocesses `<template>` via content-tag,
|
|
117
|
+
* and maps `.gts` / `.gjs` to `.ts` / `.js` so rolldown can understand them.
|
|
118
|
+
*
|
|
119
|
+
* - `emberBabel()`
|
|
120
|
+
* runs babel (template compilation, decorators, type stripping)
|
|
121
|
+
* with `babelHelpers: "bundled"`.
|
|
122
|
+
* Only the files that need it go through babel (via `maybeBabel`).
|
|
123
|
+
* Everything else stays on the fast native transform.
|
|
124
|
+
* The library's own `babel.config.js` is used when it exists.
|
|
125
|
+
* No config file is required.
|
|
126
|
+
*
|
|
127
|
+
* Usage in `tsdown.config.js`.
|
|
128
|
+
* Import `defineConfig` from `tsdown` (or from `rolldown` for a `rolldown.config.js`)
|
|
129
|
+
* so it carries the correct types:
|
|
113
130
|
*
|
|
114
131
|
* ```js
|
|
115
132
|
* import { defineConfig } from "tsdown";
|
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
|
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsDM,MAAM,SAAQ,SAAc"}
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,9 @@ import pkg from "@embroider/core";
|
|
|
10
10
|
import { Preprocessor } from "content-tag";
|
|
11
11
|
import { readFile, readdir, writeFile } from "node:fs/promises";
|
|
12
12
|
//#region src/babel.ts
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Tried in order, so an ESM config wins over a JSON one of the same name.
|
|
15
|
+
*/
|
|
14
16
|
const PUBLISH_CONFIG_EXTENSIONS = [
|
|
15
17
|
"mjs",
|
|
16
18
|
"cjs",
|
|
@@ -21,22 +23,27 @@ const PUBLISH_CONFIG_EXTENSIONS = [
|
|
|
21
23
|
"json"
|
|
22
24
|
];
|
|
23
25
|
/**
|
|
24
|
-
* Tried in order:
|
|
25
|
-
*
|
|
26
|
+
* Tried in order:
|
|
27
|
+
* - next to package.json first
|
|
28
|
+
* - then `config/`, for libraries that keep their build configuration
|
|
29
|
+
* out of the package root
|
|
26
30
|
*/
|
|
27
31
|
const PUBLISH_CONFIG_DIRECTORIES = [".", "config"];
|
|
28
32
|
/**
|
|
29
|
-
* A `babel.publish.config.*` (in the package root or `config/`), if there is
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* compiles `@embroider/macros` away
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
33
|
+
* A `babel.publish.config.*` (in the package root or `config/`), if there is one.
|
|
34
|
+
*
|
|
35
|
+
* A library's plain `babel.config.*` is its *development* config.
|
|
36
|
+
* It typically:
|
|
37
|
+
* - compiles `@embroider/macros` away
|
|
38
|
+
* - targets the wire format
|
|
39
|
+
* - wires up whatever the in-package demo app or test suite needs
|
|
40
|
+
*
|
|
41
|
+
* None of that belongs in a published artifact:
|
|
42
|
+
* - macros must stay, for the consuming app to evaluate
|
|
43
|
+
* - the wire format is private between one template compiler and one glimmer runtime
|
|
44
|
+
*
|
|
45
|
+
* Babel's own resolution can't tell the two apart (it finds whatever `babel.config.*` exists),
|
|
46
|
+
* so a publish build has to prefer the config named for publishing.
|
|
40
47
|
*/
|
|
41
48
|
function detectPublishConfigFile() {
|
|
42
49
|
for (const directory of PUBLISH_CONFIG_DIRECTORIES) for (const extension of PUBLISH_CONFIG_EXTENSIONS) {
|
|
@@ -45,14 +52,16 @@ function detectPublishConfigFile() {
|
|
|
45
52
|
}
|
|
46
53
|
}
|
|
47
54
|
/**
|
|
48
|
-
* The config this publish build
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
55
|
+
* The config this publish build must use:
|
|
56
|
+
* - a `babel.publish.config.*`, when the library has one
|
|
57
|
+
* - else the project's root babel config, resolved the way babel itself does
|
|
58
|
+
* (`babel.config.{js,cjs,mjs,cts,json}`, honoring `rootMode` semantics)
|
|
59
|
+
*
|
|
60
|
+
* For a library whose only config *is* its publish config,
|
|
61
|
+
* that is the same file either way.
|
|
62
|
+
*
|
|
63
|
+
* The sync API evaluates the config file.
|
|
64
|
+
* On node 24+ that works for native ESM configs too (require(esm)).
|
|
56
65
|
*/
|
|
57
66
|
function detectConfigFile() {
|
|
58
67
|
const publishConfig = detectPublishConfigFile();
|
|
@@ -63,20 +72,21 @@ function detectConfigFile() {
|
|
|
63
72
|
* Everything a library without its own babel config needs:
|
|
64
73
|
*
|
|
65
74
|
* - TypeScript stripping
|
|
75
|
+
*
|
|
66
76
|
* - template compilation to `precompileTemplate` (`targetFormat: "hbs"`).
|
|
67
|
-
* Published libraries must NOT ship wire format
|
|
68
|
-
* private between the template compiler and the glimmer runtime
|
|
69
|
-
* same version, so baking it in ties the published artifact
|
|
70
|
-
* consuming app's exact ember-source.
|
|
71
|
-
* compilation.
|
|
77
|
+
* Published libraries must NOT ship wire format.
|
|
78
|
+
* The wire format is private between the template compiler and the glimmer runtime
|
|
79
|
+
* of the same version, so baking it in ties the published artifact
|
|
80
|
+
* to the consuming app's exact ember-source.
|
|
81
|
+
* The consuming app performs final compilation.
|
|
72
82
|
*
|
|
73
83
|
* A bundle-mode build ships that exact ember-source,
|
|
74
84
|
* so it compiles to the wire format with ember-source's own compiler,
|
|
75
85
|
* and needs no compiler at runtime.
|
|
76
86
|
*
|
|
77
|
-
* - decorator-transforms, with its runtime left as a bare specifier
|
|
78
|
-
* consuming app resolves it
|
|
79
|
-
* a real dependency)
|
|
87
|
+
* - decorator-transforms, with its runtime left as a bare specifier
|
|
88
|
+
* so the consuming app resolves it.
|
|
89
|
+
* (the library keeps `decorator-transforms` as a real dependency)
|
|
80
90
|
*
|
|
81
91
|
* A bundle-mode build resolves it itself.
|
|
82
92
|
*/
|
|
@@ -95,29 +105,34 @@ function defaultPlugins(templateTransforms, bundle = false) {
|
|
|
95
105
|
];
|
|
96
106
|
}
|
|
97
107
|
/**
|
|
98
|
-
* We still need babel (not just oxc/rolldown's native transforms) for two
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
108
|
+
* We still need babel (not just oxc / rolldown's native transforms) for two reasons:
|
|
109
|
+
*
|
|
110
|
+
* - template compilation.
|
|
111
|
+
* `babel-plugin-ember-template-compilation` turns the content-tag output
|
|
112
|
+
* into `precompileTemplate` calls.
|
|
113
|
+
* oxc has no equivalent.
|
|
114
|
+
*
|
|
115
|
+
* - decorators.
|
|
116
|
+
* Ember uses the legacy / stage-1 decorator signature together with `decorator-transforms`,
|
|
117
|
+
* which rewrites decorated class fields (`@tracked x`) into getter / setters backed by a runtime.
|
|
118
|
+
* oxc's native "legacy decorators" emit tsc-style `__decorate` output,
|
|
119
|
+
* which does not match those semantics.
|
|
120
|
+
*
|
|
121
|
+
* But we don't want to send *every* file through babel
|
|
122
|
+
* and give back the speed rolldown / oxc buys us.
|
|
123
|
+
*
|
|
124
|
+
* So we run babel via `maybeBabel`, which filters down to only the files that need it
|
|
125
|
+
* (template-tag, decorators, template imports).
|
|
126
|
+
* Everything else stays on the native transform.
|
|
127
|
+
*
|
|
128
|
+
* The library's own babel config is used when it exists.
|
|
129
|
+
* Its `babel.publish.config.*` (root or `config/`) wins over its `babel.config.*`,
|
|
130
|
+
* since this is a publish build.
|
|
131
|
+
*
|
|
132
|
+
* Without one, `defaultPlugins` covers templates, decorators, and TypeScript,
|
|
133
|
+
* so no config file is required.
|
|
134
|
+
*
|
|
135
|
+
* Libraries default to `babelHelpers: "bundled"`, so the emitted output is self-contained.
|
|
121
136
|
*/
|
|
122
137
|
function emberBabel(options = {}) {
|
|
123
138
|
const configFile = options.configFile === void 0 ? detectConfigFile() : options.configFile;
|
|
@@ -151,8 +166,8 @@ function readJsonSync(path) {
|
|
|
151
166
|
return JSON.parse(readFileSync(path, { encoding: "utf8" }));
|
|
152
167
|
}
|
|
153
168
|
/**
|
|
154
|
-
* Everything the library declares as a `dependency` or `peerDependency`
|
|
155
|
-
* resolvable by the consuming app, so we never bundle it.
|
|
169
|
+
* Everything the library declares as a `dependency` or `peerDependency`
|
|
170
|
+
* is resolvable by the consuming app, so we never bundle it.
|
|
156
171
|
*/
|
|
157
172
|
function resolvableDependencies() {
|
|
158
173
|
const deps = /* @__PURE__ */ new Set();
|
|
@@ -193,10 +208,13 @@ function emberSourceProvidedModules() {
|
|
|
193
208
|
return provided;
|
|
194
209
|
}
|
|
195
210
|
/**
|
|
196
|
-
* Keeps
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
211
|
+
* Keeps external:
|
|
212
|
+
* - the library's declared dependencies
|
|
213
|
+
* - the ember virtual packages
|
|
214
|
+
* (things like `@ember/component`, `@glimmer/tracking`, the template compiler, …)
|
|
215
|
+
*
|
|
216
|
+
* So the app that consumes the library resolves them,
|
|
217
|
+
* instead of the library bundling copies of them.
|
|
200
218
|
*/
|
|
201
219
|
function emberExternals() {
|
|
202
220
|
let deps;
|
|
@@ -284,29 +302,33 @@ function emberBundle() {
|
|
|
284
302
|
//#endregion
|
|
285
303
|
//#region src/config.ts
|
|
286
304
|
/**
|
|
287
|
-
* Sensible defaults for an Ember v2 library
|
|
288
|
-
*
|
|
289
|
-
*
|
|
305
|
+
* Sensible defaults for an Ember v2 library.
|
|
306
|
+
*
|
|
307
|
+
* Applied through plugin hooks, so they travel with `ember()`.
|
|
308
|
+
* You get them whether you use this package's `defineConfig`, tsdown's,
|
|
309
|
+
* or a plain `tsdown.config.js` / `rolldown.config.js`.
|
|
290
310
|
*
|
|
291
311
|
* Every value is applied with `??=`, so anything you set explicitly wins.
|
|
292
312
|
*
|
|
293
|
-
* Under tsdown, the full set applies via the `tsdownConfig` hook
|
|
294
|
-
* Vite's `config` hook):
|
|
313
|
+
* Under tsdown, the full set applies via the `tsdownConfig` hook
|
|
314
|
+
* (analogous to Vite's `config` hook):
|
|
295
315
|
*
|
|
296
|
-
* - `sourcemap` — emit sourcemaps alongside the output
|
|
297
|
-
* - `clean` — wipe `dist/` between builds
|
|
298
|
-
* - `dts` — emit `.d.ts` declarations (via isolated declarations)
|
|
299
|
-
* - `outExtensions` — `.js
|
|
300
|
-
*
|
|
301
|
-
* - `report` — off
|
|
302
|
-
*
|
|
303
|
-
*
|
|
316
|
+
* - `sourcemap` — emit sourcemaps alongside the output
|
|
317
|
+
* - `clean` — wipe `dist/` between builds
|
|
318
|
+
* - `dts` — emit `.d.ts` declarations (via isolated declarations)
|
|
319
|
+
* - `outExtensions` — `.js` / `.d.ts` rather than tsdown's default `.mjs` / `.d.mts`
|
|
320
|
+
* (exports maps conventionally point at `.js` / `.d.ts`)
|
|
321
|
+
* - `report` — off.
|
|
322
|
+
* The size report is noise for a library build.
|
|
323
|
+
* - `deps.neverBundle` — leave node builtins and the ember virtual packages
|
|
324
|
+
* to the consuming app (`emberExternals()` handles the rest)
|
|
304
325
|
*
|
|
305
|
-
* A plain rolldown build has no notion of `clean
|
|
306
|
-
*
|
|
307
|
-
*
|
|
326
|
+
* A plain rolldown build has no notion of `clean` / `dts` / `outExtensions` / `report`.
|
|
327
|
+
* Those are tsdown-level concepts.
|
|
328
|
+
* So only the options with rolldown equivalents are applied there,
|
|
329
|
+
* via rolldown's own `outputOptions` hook:
|
|
308
330
|
*
|
|
309
|
-
* - `output.sourcemap` — on
|
|
331
|
+
* - `output.sourcemap` — on
|
|
310
332
|
*
|
|
311
333
|
* Externals are handled by `emberExternals()` (a `resolveId` hook) in both cases.
|
|
312
334
|
*
|
|
@@ -356,16 +378,16 @@ function emberConfig({ bundle = false } = {}) {
|
|
|
356
378
|
//#endregion
|
|
357
379
|
//#region src/isolated-declarations.ts
|
|
358
380
|
/**
|
|
359
|
-
* Resolve the tsconfig the build will
|
|
360
|
-
* `tsconfig` option (`string | boolean`):
|
|
381
|
+
* Resolve the tsconfig the build will use.
|
|
361
382
|
*
|
|
362
|
-
*
|
|
363
|
-
* -
|
|
364
|
-
* - a path to a
|
|
365
|
-
* -
|
|
383
|
+
* Mirrors tsdown's own `tsconfig` option (`string | boolean`):
|
|
384
|
+
* - `undefined` / `true`: `tsconfig.json` in the cwd
|
|
385
|
+
* - a path to a file: that file
|
|
386
|
+
* - a path to a directory: `tsconfig.json` inside it
|
|
387
|
+
* - `false`: no tsconfig at all
|
|
366
388
|
*
|
|
367
|
-
* Under plain rolldown there is no such option,
|
|
368
|
-
* is all there is.
|
|
389
|
+
* Under plain rolldown there is no such option,
|
|
390
|
+
* so the cwd's `tsconfig.json` is all there is.
|
|
369
391
|
*/
|
|
370
392
|
function resolveTsconfigPath(option) {
|
|
371
393
|
if (option === false) return void 0;
|
|
@@ -377,33 +399,41 @@ function resolveTsconfigPath(option) {
|
|
|
377
399
|
return resolve("tsconfig.json");
|
|
378
400
|
}
|
|
379
401
|
/**
|
|
380
|
-
* Errors the build when the tsconfig it builds with
|
|
381
|
-
* `isolatedDeclarations: true`.
|
|
382
|
-
*
|
|
383
|
-
* This is required
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
402
|
+
* Errors the build when the tsconfig it builds with
|
|
403
|
+
* does not set `isolatedDeclarations: true`.
|
|
404
|
+
*
|
|
405
|
+
* This is required.
|
|
406
|
+
* Declarations for `.gts` / `.gjs` (template tag) modules can only be emitted
|
|
407
|
+
* by the isolated-declarations pipeline,
|
|
408
|
+
* which reads compiled modules from the bundler's module graph.
|
|
409
|
+
*
|
|
410
|
+
* The `tsc`-based pipeline reads source files from disk.
|
|
411
|
+
* The compiled modules don't exist there, so it fails with "Source file not found".
|
|
412
|
+
*
|
|
413
|
+
* Failing fast here, rather than only when declaration emit happens to run,
|
|
414
|
+
* keeps the project honest.
|
|
415
|
+
* Editors and `tsc` / `ember-tsc` then check the same rules the build enforces:
|
|
416
|
+
* exported values need explicit type annotations,
|
|
417
|
+
* e.g. `export const X: TOC<Sig> = <template>...`
|
|
418
|
+
*
|
|
419
|
+
* The tsconfig checked is the one tsdown's `tsconfig` option points at,
|
|
420
|
+
* not necessarily `tsconfig.json`.
|
|
421
|
+
*
|
|
422
|
+
* So a library whose package also holds dev-only code (a demo app, in-package tests) can:
|
|
423
|
+
* - keep a permissive `tsconfig.json` covering everything,
|
|
424
|
+
* for editors and `tsc --noEmit`
|
|
425
|
+
* - point the build at a `tsconfig.publish.json` that covers only the publishable sources
|
|
426
|
+
*
|
|
427
|
+
* Isolated declarations then constrain exactly the code that gets declarations emitted,
|
|
428
|
+
* and nothing else.
|
|
429
|
+
*
|
|
430
|
+
* Projects with no tsconfig (JavaScript libraries) or without the `typescript` package
|
|
431
|
+
* have no declarations to emit, so there is nothing to check.
|
|
432
|
+
*
|
|
433
|
+
* `tsconfig: false` is different.
|
|
434
|
+
* It is an explicit opt-out.
|
|
435
|
+
* Combined with declaration emit, it produces a confusing "Source file not found"
|
|
436
|
+
* from the tsc-based pipeline, so it errors here instead.
|
|
407
437
|
*/
|
|
408
438
|
function emberIsolatedDeclarations() {
|
|
409
439
|
let tsconfigOption;
|
|
@@ -437,9 +467,10 @@ function emberIsolatedDeclarations() {
|
|
|
437
467
|
//#region src/transform.ts
|
|
438
468
|
const processor = new Preprocessor();
|
|
439
469
|
/**
|
|
440
|
-
* `.d.ts` files emitted for `.gts` source reference the original `.gts`
|
|
441
|
-
*
|
|
442
|
-
*
|
|
470
|
+
* `.d.ts` files emitted for `.gts` source reference the original `.gts` specifiers.
|
|
471
|
+
*
|
|
472
|
+
* Consumers can't resolve those,
|
|
473
|
+
* so we rewrite them back to extension-less specifiers.
|
|
443
474
|
*/
|
|
444
475
|
function fixDeclarationImports(content) {
|
|
445
476
|
return content.replace(/from\s+'([^']+)\.gts'/g, "from '$1'").replace(/from\s+"([^"]+)\.gts"/g, "from \"$1\"").replace(/import\("([^"]+)\.gts"\)/g, "import(\"$1\")").replace(/import\('([^']+)\.gts'\)/g, "import('$1')");
|
|
@@ -459,10 +490,12 @@ async function fixDtsExtensionsInDir(dir) {
|
|
|
459
490
|
/**
|
|
460
491
|
* A sourcemap mapping every generated line to the same line of the input.
|
|
461
492
|
*
|
|
462
|
-
* `AAAA` is the [0, 0, 0, 0] VLQ segment
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
*
|
|
493
|
+
* - `AAAA` is the [0, 0, 0, 0] VLQ segment
|
|
494
|
+
* (first line maps to source 0, line 0, column 0)
|
|
495
|
+
* - `AACA` is [0, 0, +1, 0]
|
|
496
|
+
* (each following line advances the source line by one)
|
|
497
|
+
*
|
|
498
|
+
* Exact at line granularity, which is all the specifier rewrite can disturb.
|
|
466
499
|
*/
|
|
467
500
|
function lineIdentityMap(id, source) {
|
|
468
501
|
return {
|
|
@@ -474,8 +507,10 @@ function lineIdentityMap(id, source) {
|
|
|
474
507
|
};
|
|
475
508
|
}
|
|
476
509
|
/**
|
|
477
|
-
*
|
|
478
|
-
* ts
|
|
510
|
+
* Preprocesses `<template>` via content-tag, and maps
|
|
511
|
+
* `.gts` → `.ts`
|
|
512
|
+
* `.gjs` → `.js`
|
|
513
|
+
* so rolldown can identify them as ts / js.
|
|
479
514
|
*/
|
|
480
515
|
function emberTransform() {
|
|
481
516
|
return {
|
|
@@ -566,33 +601,45 @@ function emberTransform() {
|
|
|
566
601
|
//#endregion
|
|
567
602
|
//#region index.ts
|
|
568
603
|
/**
|
|
569
|
-
* A batteries-included plugin for building Ember v2 libraries (addons)
|
|
570
|
-
* rolldown
|
|
571
|
-
*
|
|
572
|
-
* It bundles everything needed to compile `.gts
|
|
573
|
-
* (`<template>`) source into publishable output:
|
|
574
|
-
*
|
|
575
|
-
* - `emberConfig()`
|
|
576
|
-
*
|
|
577
|
-
*
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
*
|
|
582
|
-
*
|
|
583
|
-
*
|
|
584
|
-
*
|
|
604
|
+
* A batteries-included plugin for building Ember v2 libraries (addons)
|
|
605
|
+
* with rolldown, or with tsdown (which is built on rolldown).
|
|
606
|
+
*
|
|
607
|
+
* It bundles everything needed to compile `.gts` / `.gjs` and
|
|
608
|
+
* template-tag (`<template>`) source into publishable output:
|
|
609
|
+
*
|
|
610
|
+
* - `emberConfig()`
|
|
611
|
+
* applies sensible tsdown defaults for a library build
|
|
612
|
+
* (sourcemaps, `clean`, `dts`, `.js` / `.d.ts` extensions, quiet logging).
|
|
613
|
+
* Anything you set explicitly still wins.
|
|
614
|
+
*
|
|
615
|
+
* - `emberIsolatedDeclarations()`
|
|
616
|
+
* errors when a tsconfig.json is present without `isolatedDeclarations: true`.
|
|
617
|
+
* That is the only declaration pipeline that can see compiled template-tag modules.
|
|
618
|
+
*
|
|
619
|
+
* - `emberExternals()`
|
|
620
|
+
* keeps your dependencies, peerDependencies, and the ember virtual packages external,
|
|
621
|
+
* so consuming apps resolve them.
|
|
622
|
+
*
|
|
623
|
+
* - `emberBundle()`
|
|
624
|
+
* bundle mode only, in place of `emberExternals()`.
|
|
625
|
+
* Aliases the ember virtual packages into ember-source,
|
|
585
626
|
* whose export conditions pick the build to bundle.
|
|
586
|
-
*
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
*
|
|
590
|
-
*
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
*
|
|
594
|
-
*
|
|
595
|
-
*
|
|
627
|
+
*
|
|
628
|
+
* - `emberTransform()`
|
|
629
|
+
* preprocesses `<template>` via content-tag,
|
|
630
|
+
* and maps `.gts` / `.gjs` to `.ts` / `.js` so rolldown can understand them.
|
|
631
|
+
*
|
|
632
|
+
* - `emberBabel()`
|
|
633
|
+
* runs babel (template compilation, decorators, type stripping)
|
|
634
|
+
* with `babelHelpers: "bundled"`.
|
|
635
|
+
* Only the files that need it go through babel (via `maybeBabel`).
|
|
636
|
+
* Everything else stays on the fast native transform.
|
|
637
|
+
* The library's own `babel.config.js` is used when it exists.
|
|
638
|
+
* No config file is required.
|
|
639
|
+
*
|
|
640
|
+
* Usage in `tsdown.config.js`.
|
|
641
|
+
* Import `defineConfig` from `tsdown` (or from `rolldown` for a `rolldown.config.js`)
|
|
642
|
+
* so it carries the correct types:
|
|
596
643
|
*
|
|
597
644
|
* ```js
|
|
598
645
|
* import { defineConfig } from "tsdown";
|