@nullvoxpopuli/ember-rolldown 2.0.0 → 2.2.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 +101 -1
- package/dist/app-reexports.js +97 -0
- package/dist/index.js +61 -48
- package/package.json +8 -3
- package/rolldown.config.js +5 -3
- package/src/app-reexports.test.ts +220 -0
- package/src/app-reexports.ts +152 -0
- package/src/babel.test.ts +17 -0
- package/src/babel.ts +21 -3
- package/src/config.ts +1 -1
- package/src/dts.test.ts +366 -0
- package/src/transform.test.ts +208 -0
- package/src/transform.ts +64 -31
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, extname, join, matchesGlob, relative, resolve, sep } from "node:path";
|
|
3
|
+
|
|
4
|
+
import type { Plugin } from "rolldown";
|
|
5
|
+
|
|
6
|
+
export interface AppReexportsOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Globs, matched against each built filename (relative to the output
|
|
9
|
+
* directory), selecting which modules get an app re-export.
|
|
10
|
+
*
|
|
11
|
+
* Defaults to `["services/*"]` -- top-level services only. Under strict
|
|
12
|
+
* mode, components and helpers are imported, but services are still
|
|
13
|
+
* injected by name, so they are the one thing an app must always be able
|
|
14
|
+
* to resolve.
|
|
15
|
+
*
|
|
16
|
+
* `.d.ts` files never match.
|
|
17
|
+
*/
|
|
18
|
+
include?: string[];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Globs removing files that `include` matched.
|
|
22
|
+
*/
|
|
23
|
+
exclude?: string[];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Rename a re-export: receives the built filename, returns the filename the
|
|
27
|
+
* app sees. Defaults to the built filename unchanged.
|
|
28
|
+
*/
|
|
29
|
+
mapFilename?: (filename: string) => string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Which bindings a file's re-export module forwards: an array of names
|
|
33
|
+
* (default `["default"]`), or a raw export clause string such as `"*"`.
|
|
34
|
+
*/
|
|
35
|
+
exports?: (filename: string) => string[] | string | undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Merges built modules into the consuming app's namespace, so classic
|
|
40
|
+
* resolution (`{{a-component}}`, service/helper lookup by name) finds them --
|
|
41
|
+
* the same job as `@embroider/addon-dev`'s `appReexports` rollup plugin.
|
|
42
|
+
*
|
|
43
|
+
* For every built file matching `include` (minus `exclude` and `.d.ts`), it
|
|
44
|
+
* writes a tiny module under `<outDir>/_app_/` re-exporting from the
|
|
45
|
+
* library's own name, and records the full set in `package.json` under
|
|
46
|
+
* `ember-addon.app-js`.
|
|
47
|
+
*
|
|
48
|
+
* Unlike the embroider plugin, nothing is written unless its content actually
|
|
49
|
+
* differs from what is on disk: the `_app_/` modules are compared
|
|
50
|
+
* byte-for-byte, and `package.json` is only rewritten when the `app-js` map
|
|
51
|
+
* itself changed (so an equivalent map in different formatting is left
|
|
52
|
+
* alone). This keeps rebuilds from re-triggering file watchers.
|
|
53
|
+
*
|
|
54
|
+
* This is a separate import, because most libraries don't need it:
|
|
55
|
+
*
|
|
56
|
+
* ```js
|
|
57
|
+
* import { defineConfig } from "tsdown";
|
|
58
|
+
* import { ember } from "@nullvoxpopuli/ember-rolldown";
|
|
59
|
+
* import { appReexports } from "@nullvoxpopuli/ember-rolldown/app-reexports";
|
|
60
|
+
*
|
|
61
|
+
* export default defineConfig({
|
|
62
|
+
* entry: ["./src/index.ts", "./src/services/session.ts"],
|
|
63
|
+
* plugins: [ember(), appReexports()],
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* With no arguments, top-level services (`services/*`) are re-exported. A
|
|
68
|
+
* string argument is an include glob; an object gives full control:
|
|
69
|
+
*
|
|
70
|
+
* ```js
|
|
71
|
+
* appReexports(); // services/*
|
|
72
|
+
* appReexports("components/**"); // one include glob
|
|
73
|
+
* appReexports({ include: ["services/*", "helpers/*"], exclude: [...] });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export function appReexports(options: string | AppReexportsOptions = {}): Plugin {
|
|
77
|
+
const resolved = typeof options === "string" ? { include: [options] } : options;
|
|
78
|
+
const include = resolved.include ?? ["services/*"];
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
name: "ember:app-reexports",
|
|
82
|
+
|
|
83
|
+
writeBundle(outputOptions, bundle) {
|
|
84
|
+
const manifest = readJsonSync("package.json");
|
|
85
|
+
const outDir = outputOptions.dir ?? dirname(outputOptions.file ?? "dist");
|
|
86
|
+
const appJs: Record<string, string> = {};
|
|
87
|
+
|
|
88
|
+
// Sorted so the app-js map (and therefore package.json) is stable
|
|
89
|
+
// across builds regardless of chunk emission order.
|
|
90
|
+
for (const builtFilename of Object.keys(bundle).sort()) {
|
|
91
|
+
if (!isIncluded(builtFilename, include, resolved.exclude)) continue;
|
|
92
|
+
|
|
93
|
+
const appFilename = resolved.mapFilename?.(builtFilename) ?? builtFilename;
|
|
94
|
+
const names = resolved.exports?.(builtFilename) || ["default"];
|
|
95
|
+
const clause = typeof names === "string" ? names : `{ ${names.join(", ")} }`;
|
|
96
|
+
const withoutExtension = builtFilename.slice(0, -extname(builtFilename).length);
|
|
97
|
+
const reexportPath = join(outDir, "_app_", appFilename);
|
|
98
|
+
|
|
99
|
+
appJs[`./${appFilename}`] = `./${toPosix(relative(process.cwd(), resolve(reexportPath)))}`;
|
|
100
|
+
|
|
101
|
+
writeFileIfChanged(
|
|
102
|
+
reexportPath,
|
|
103
|
+
`export ${clause} from "${manifest.name}/${withoutExtension}";\n`,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const existing = manifest["ember-addon"]?.["app-js"] ?? {};
|
|
108
|
+
|
|
109
|
+
if (!sameStringRecord(existing, appJs)) {
|
|
110
|
+
manifest["ember-addon"] = { ...manifest["ember-addon"], "app-js": appJs };
|
|
111
|
+
writeFileSync("package.json", JSON.stringify(manifest, null, 2) + "\n");
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function readJsonSync(path: string) {
|
|
118
|
+
return JSON.parse(readFileSync(path, { encoding: "utf8" }));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function isIncluded(filename: string, include: string[], exclude?: string[]): boolean {
|
|
122
|
+
if (matchesGlob(filename, "**/*.d.ts")) return false;
|
|
123
|
+
if (!include.some((glob) => matchesGlob(filename, glob))) return false;
|
|
124
|
+
if (exclude?.some((glob) => matchesGlob(filename, glob))) return false;
|
|
125
|
+
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function writeFileIfChanged(path: string, content: string) {
|
|
130
|
+
let existing: string | undefined;
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
existing = readFileSync(path, { encoding: "utf8" });
|
|
134
|
+
} catch {
|
|
135
|
+
// Doesn't exist yet (or isn't readable) -- write it.
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (existing === content) return;
|
|
139
|
+
|
|
140
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
141
|
+
writeFileSync(path, content);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function sameStringRecord(a: Record<string, string>, b: Record<string, string>): boolean {
|
|
145
|
+
const aKeys = Object.keys(a);
|
|
146
|
+
|
|
147
|
+
return aKeys.length === Object.keys(b).length && aKeys.every((key) => a[key] === b[key]);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function toPosix(path: string): string {
|
|
151
|
+
return path.split(sep).join("/");
|
|
152
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { emberBabel } from "./babel.ts";
|
|
4
|
+
|
|
5
|
+
describe("emberBabel", () => {
|
|
6
|
+
it("rejects templateTransforms combined with a config file", () => {
|
|
7
|
+
expect(() =>
|
|
8
|
+
emberBabel({ configFile: "./babel.config.js", templateTransforms: ["some-transform"] }),
|
|
9
|
+
).toThrow(/pass the transforms/);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("allows templateTransforms when config files are opted out", () => {
|
|
13
|
+
expect(() =>
|
|
14
|
+
emberBabel({ configFile: false, templateTransforms: ["some-transform"] }),
|
|
15
|
+
).not.toThrow();
|
|
16
|
+
});
|
|
17
|
+
});
|
package/src/babel.ts
CHANGED
|
@@ -4,6 +4,7 @@ import templateCompilation from "babel-plugin-ember-template-compilation";
|
|
|
4
4
|
import decoratorTransforms from "decorator-transforms";
|
|
5
5
|
import { loadPartialConfigSync } from "@babel/core";
|
|
6
6
|
import type { PluginItem } from "@babel/core";
|
|
7
|
+
import type { Transform } from "babel-plugin-ember-template-compilation";
|
|
7
8
|
import type { Plugin } from "rolldown";
|
|
8
9
|
|
|
9
10
|
export interface BabelOptions {
|
|
@@ -24,6 +25,15 @@ export interface BabelOptions {
|
|
|
24
25
|
* Extra babel plugins to run, appended after the config's plugins.
|
|
25
26
|
*/
|
|
26
27
|
plugins?: PluginItem[];
|
|
28
|
+
/**
|
|
29
|
+
* Template AST transforms (e.g. ember-scoped-css's `scopedCSS.template()`)
|
|
30
|
+
* passed to the default `babel-plugin-ember-template-compilation` entry.
|
|
31
|
+
*
|
|
32
|
+
* Only valid without a babel config file: with your own config, you list
|
|
33
|
+
* `babel-plugin-ember-template-compilation` yourself, so its `transforms`
|
|
34
|
+
* belong there.
|
|
35
|
+
*/
|
|
36
|
+
templateTransforms?: Transform[];
|
|
27
37
|
/**
|
|
28
38
|
* Opt additional files into babel (see maybeBabel's `filter`). Use this to
|
|
29
39
|
* cover addons that ship code needing babel (e.g. `ember-concurrency`).
|
|
@@ -63,7 +73,7 @@ function detectConfigFile(): string | undefined {
|
|
|
63
73
|
* consuming app resolves it (the library keeps `decorator-transforms` as
|
|
64
74
|
* a real dependency).
|
|
65
75
|
*/
|
|
66
|
-
function defaultPlugins(): PluginItem[] {
|
|
76
|
+
function defaultPlugins(templateTransforms?: Transform[]): PluginItem[] {
|
|
67
77
|
return [
|
|
68
78
|
[
|
|
69
79
|
transformTypeScript,
|
|
@@ -73,7 +83,7 @@ function defaultPlugins(): PluginItem[] {
|
|
|
73
83
|
allowDeclareFields: true,
|
|
74
84
|
},
|
|
75
85
|
],
|
|
76
|
-
[templateCompilation, { targetFormat: "hbs" }],
|
|
86
|
+
[templateCompilation, { targetFormat: "hbs", transforms: templateTransforms ?? [] }],
|
|
77
87
|
[
|
|
78
88
|
decoratorTransforms,
|
|
79
89
|
{
|
|
@@ -118,6 +128,14 @@ export function emberBabel(options: BabelOptions = {}): Plugin {
|
|
|
118
128
|
};
|
|
119
129
|
|
|
120
130
|
if (configFile) {
|
|
131
|
+
if (options.templateTransforms?.length) {
|
|
132
|
+
throw new Error(
|
|
133
|
+
`\`babel.templateTransforms\` cannot be combined with a babel config file (found ${configFile}). ` +
|
|
134
|
+
`Your config lists babel-plugin-ember-template-compilation itself, so pass the transforms ` +
|
|
135
|
+
`to its \`transforms\` option there instead.`,
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
121
139
|
return maybeBabel({
|
|
122
140
|
...shared,
|
|
123
141
|
configFile,
|
|
@@ -131,6 +149,6 @@ export function emberBabel(options: BabelOptions = {}): Plugin {
|
|
|
131
149
|
// for one -- we provide the whole plugin list inline.
|
|
132
150
|
configFile: false,
|
|
133
151
|
babelrc: false,
|
|
134
|
-
plugins: defaultPlugins().concat(options.plugins ?? []),
|
|
152
|
+
plugins: defaultPlugins(options.templateTransforms).concat(options.plugins ?? []),
|
|
135
153
|
}) as unknown as Plugin;
|
|
136
154
|
}
|
package/src/config.ts
CHANGED
|
@@ -34,7 +34,7 @@ export function emberConfig(): TsdownPlugin {
|
|
|
34
34
|
tsdownConfig(config: UserConfig) {
|
|
35
35
|
config.sourcemap ??= true;
|
|
36
36
|
config.clean ??= true;
|
|
37
|
-
config.dts ??= true;
|
|
37
|
+
config.dts ??= { sourcemap: true };
|
|
38
38
|
config.outExtensions ??= () => ({ js: ".js", dts: ".d.ts" });
|
|
39
39
|
config.report ??= false;
|
|
40
40
|
|
package/src/dts.test.ts
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { mkdtemp, mkdir, readdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { build } from "tsdown";
|
|
5
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
6
|
+
|
|
7
|
+
import { ember } from "../index.ts";
|
|
8
|
+
|
|
9
|
+
interface Dist {
|
|
10
|
+
/** Sorted dist-relative paths of every emitted file. */
|
|
11
|
+
files: string[];
|
|
12
|
+
/** dist-relative path -> content, for every emitted .d.ts and .css file. */
|
|
13
|
+
contents: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let restoreCwd: (() => void) | undefined;
|
|
17
|
+
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
restoreCwd?.();
|
|
20
|
+
restoreCwd = undefined;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Drives `ember()` through a real tsdown build (the dts pipeline included).
|
|
25
|
+
* `files` is a map of relative path -> source, written into a temp dir that
|
|
26
|
+
* becomes the cwd for the build (the externals and isolated-declarations
|
|
27
|
+
* plugins read package.json / tsconfig.json from cwd, like the tsdown CLI).
|
|
28
|
+
*
|
|
29
|
+
* Returns the emitted file list plus the full contents of every declaration
|
|
30
|
+
* and css file (js output is covered by transform.test.ts).
|
|
31
|
+
*/
|
|
32
|
+
async function buildFixture(files: Record<string, string>, entry: string[]): Promise<Dist> {
|
|
33
|
+
const dir = await mkdtemp(path.join(tmpdir(), "ember-rolldown-dts-"));
|
|
34
|
+
|
|
35
|
+
const withDefaults: Record<string, string> = {
|
|
36
|
+
"package.json": JSON.stringify({
|
|
37
|
+
name: "fixture",
|
|
38
|
+
version: "0.0.0",
|
|
39
|
+
type: "module",
|
|
40
|
+
exports: { "./*": { types: "./dist/*.d.ts", default: "./dist/*.js" } },
|
|
41
|
+
}),
|
|
42
|
+
"tsconfig.json": JSON.stringify({
|
|
43
|
+
compilerOptions: { isolatedDeclarations: true, declaration: true },
|
|
44
|
+
}),
|
|
45
|
+
...files,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
for (const [relative, source] of Object.entries(withDefaults)) {
|
|
49
|
+
const full = path.join(dir, relative);
|
|
50
|
+
await mkdir(path.dirname(full), { recursive: true });
|
|
51
|
+
await writeFile(full, source, "utf8");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const previousCwd = process.cwd();
|
|
55
|
+
process.chdir(dir);
|
|
56
|
+
restoreCwd = () => process.chdir(previousCwd);
|
|
57
|
+
|
|
58
|
+
await build({
|
|
59
|
+
entry,
|
|
60
|
+
config: false,
|
|
61
|
+
logLevel: "silent",
|
|
62
|
+
plugins: [ember()],
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const distDir = path.join(dir, "dist");
|
|
66
|
+
const dist: Dist = { files: [], contents: {} };
|
|
67
|
+
|
|
68
|
+
for (const entry of await readdir(distDir, { withFileTypes: true, recursive: true })) {
|
|
69
|
+
if (!entry.isFile()) continue;
|
|
70
|
+
|
|
71
|
+
const relative = path.relative(distDir, path.join(entry.parentPath, entry.name));
|
|
72
|
+
dist.files.push(relative);
|
|
73
|
+
|
|
74
|
+
if (relative.endsWith(".d.ts") || relative.endsWith(".css")) {
|
|
75
|
+
dist.contents[relative] = await readFile(path.join(distDir, relative), "utf8");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
dist.files.sort();
|
|
80
|
+
|
|
81
|
+
return dist;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** One printable document of every captured file, for a single snapshot. */
|
|
85
|
+
function printed(dist: Dist): string {
|
|
86
|
+
return Object.entries(dist.contents)
|
|
87
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
88
|
+
.map(([file, content]) => `//=== ${file}\n${content}`)
|
|
89
|
+
.join("\n");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
describe("declarations (full ember() via tsdown)", () => {
|
|
93
|
+
it("emits .d.ts for an entry that type-imports from a non-entry .gts", async () => {
|
|
94
|
+
// Mirrors a design-system shape: the component is in the runtime graph via
|
|
95
|
+
// the index entry, while a second entry (a service) only *type*-imports
|
|
96
|
+
// from it. The service's declaration then references the component's
|
|
97
|
+
// (virtual) .d.ts, which only exists in the bundler's module graph.
|
|
98
|
+
const dist = await buildFixture(
|
|
99
|
+
{
|
|
100
|
+
"src/index.ts": `export { default as Popup } from './popup.gts';`,
|
|
101
|
+
"src/service.ts": [
|
|
102
|
+
`import type { PopupBlock } from './popup.gts';`,
|
|
103
|
+
``,
|
|
104
|
+
`export class TooltipService {`,
|
|
105
|
+
` registerPopup(context: PopupBlock): void {`,
|
|
106
|
+
` void context;`,
|
|
107
|
+
` }`,
|
|
108
|
+
`}`,
|
|
109
|
+
].join("\n"),
|
|
110
|
+
"src/popup.gts": [
|
|
111
|
+
`import Component from '@glimmer/component';`,
|
|
112
|
+
``,
|
|
113
|
+
`export interface PopupBlock {`,
|
|
114
|
+
` open: () => void;`,
|
|
115
|
+
`}`,
|
|
116
|
+
``,
|
|
117
|
+
`export interface PopupSignature {`,
|
|
118
|
+
` Element: HTMLDivElement;`,
|
|
119
|
+
` Blocks: { default: [PopupBlock] };`,
|
|
120
|
+
`}`,
|
|
121
|
+
``,
|
|
122
|
+
`export default class Popup extends Component<PopupSignature> {`,
|
|
123
|
+
` <template>popup</template>`,
|
|
124
|
+
`}`,
|
|
125
|
+
].join("\n"),
|
|
126
|
+
},
|
|
127
|
+
["./src/index.ts", "./src/service.ts"],
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
expect(dist.files).toMatchInlineSnapshot(`
|
|
131
|
+
[
|
|
132
|
+
"index.d.ts",
|
|
133
|
+
"index.js",
|
|
134
|
+
"index.js.map",
|
|
135
|
+
"popup-CjMmUEVb.d.ts",
|
|
136
|
+
"popup-CjMmUEVb.d.ts.map",
|
|
137
|
+
"service.d.ts",
|
|
138
|
+
"service.d.ts.map",
|
|
139
|
+
"service.js",
|
|
140
|
+
"service.js.map",
|
|
141
|
+
]
|
|
142
|
+
`);
|
|
143
|
+
|
|
144
|
+
expect(printed(dist)).toMatchInlineSnapshot(`
|
|
145
|
+
"//=== index.d.ts
|
|
146
|
+
import { t as Popup } from "./popup-CjMmUEVb.js";
|
|
147
|
+
export { Popup };
|
|
148
|
+
//=== popup-CjMmUEVb.d.ts
|
|
149
|
+
import Component from "@glimmer/component";
|
|
150
|
+
//#region src/popup.d.ts
|
|
151
|
+
interface PopupBlock {
|
|
152
|
+
open: () => void;
|
|
153
|
+
}
|
|
154
|
+
interface PopupSignature {
|
|
155
|
+
Element: HTMLDivElement;
|
|
156
|
+
Blocks: {
|
|
157
|
+
default: [PopupBlock];
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
declare class Popup extends Component<PopupSignature> {}
|
|
161
|
+
//#endregion
|
|
162
|
+
export { PopupBlock as n, Popup as t };
|
|
163
|
+
//# sourceMappingURL=popup-CjMmUEVb.d.ts.map
|
|
164
|
+
//=== service.d.ts
|
|
165
|
+
import { n as PopupBlock } from "./popup-CjMmUEVb.js";
|
|
166
|
+
//#region src/service.d.ts
|
|
167
|
+
declare class TooltipService {
|
|
168
|
+
registerPopup(context: PopupBlock): void;
|
|
169
|
+
}
|
|
170
|
+
//#endregion
|
|
171
|
+
export { TooltipService };
|
|
172
|
+
//# sourceMappingURL=service.d.ts.map"
|
|
173
|
+
`);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it("emits .d.ts when a .gts module is only ever type-imported", async () => {
|
|
177
|
+
// Nothing value-imports popup.gts, so its virtual module never enters the
|
|
178
|
+
// runtime graph: the only route to its declaration is the dts resolver
|
|
179
|
+
// loading it on demand. The declaration pipeline registers modules as
|
|
180
|
+
// their (virtual) source loads, so the import must resolve to the source
|
|
181
|
+
// id — a pre-rewritten `.d.ts` id skips that registration and dangles.
|
|
182
|
+
const dist = await buildFixture(
|
|
183
|
+
{
|
|
184
|
+
"src/service.ts": [
|
|
185
|
+
`import type { PopupBlock } from './components/popup.gts';`,
|
|
186
|
+
``,
|
|
187
|
+
`export class TooltipService {`,
|
|
188
|
+
` registerPopup(context: PopupBlock): void {`,
|
|
189
|
+
` void context;`,
|
|
190
|
+
` }`,
|
|
191
|
+
`}`,
|
|
192
|
+
].join("\n"),
|
|
193
|
+
"src/components/popup.gts": [
|
|
194
|
+
`import Component from '@glimmer/component';`,
|
|
195
|
+
``,
|
|
196
|
+
`export interface PopupBlock {`,
|
|
197
|
+
` open: () => void;`,
|
|
198
|
+
`}`,
|
|
199
|
+
``,
|
|
200
|
+
`export default class Popup extends Component {`,
|
|
201
|
+
` <template>popup</template>`,
|
|
202
|
+
`}`,
|
|
203
|
+
].join("\n"),
|
|
204
|
+
},
|
|
205
|
+
["./src/service.ts"],
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
expect(dist.files).toMatchInlineSnapshot(`
|
|
209
|
+
[
|
|
210
|
+
"service.d.ts",
|
|
211
|
+
"service.d.ts.map",
|
|
212
|
+
"service.js",
|
|
213
|
+
"service.js.map",
|
|
214
|
+
]
|
|
215
|
+
`);
|
|
216
|
+
|
|
217
|
+
expect(printed(dist)).toMatchInlineSnapshot(`
|
|
218
|
+
"//=== service.d.ts
|
|
219
|
+
import "@glimmer/component";
|
|
220
|
+
//#region src/components/popup.d.ts
|
|
221
|
+
interface PopupBlock {
|
|
222
|
+
open: () => void;
|
|
223
|
+
}
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/service.d.ts
|
|
226
|
+
declare class TooltipService {
|
|
227
|
+
registerPopup(context: PopupBlock): void;
|
|
228
|
+
}
|
|
229
|
+
//#endregion
|
|
230
|
+
export { TooltipService };
|
|
231
|
+
//# sourceMappingURL=service.d.ts.map"
|
|
232
|
+
`);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("emits .d.ts for a .gts that type-imports another (otherwise unimported) .gts", async () => {
|
|
236
|
+
// A nested component type-imports a sibling from the parent directory;
|
|
237
|
+
// its declaration then carries a relative source specifier for a module
|
|
238
|
+
// that exists only in the bundler's graph (never on disk, never in the
|
|
239
|
+
// runtime graph).
|
|
240
|
+
const dist = await buildFixture(
|
|
241
|
+
{
|
|
242
|
+
"src/index.ts": `export { default as OptionList } from './components/select/option-list.gts';`,
|
|
243
|
+
"src/components/select/option-list.gts": [
|
|
244
|
+
`import Component from '@glimmer/component';`,
|
|
245
|
+
`import type { PopupBlock } from '../popup.gts';`,
|
|
246
|
+
``,
|
|
247
|
+
`export interface OptionListArgs {`,
|
|
248
|
+
` registerPopup: (context: PopupBlock) => void;`,
|
|
249
|
+
`}`,
|
|
250
|
+
``,
|
|
251
|
+
`export default class OptionList extends Component {`,
|
|
252
|
+
` <template>options</template>`,
|
|
253
|
+
`}`,
|
|
254
|
+
].join("\n"),
|
|
255
|
+
"src/components/popup.gts": [
|
|
256
|
+
`import Component from '@glimmer/component';`,
|
|
257
|
+
``,
|
|
258
|
+
`export interface PopupBlock {`,
|
|
259
|
+
` open: () => void;`,
|
|
260
|
+
`}`,
|
|
261
|
+
``,
|
|
262
|
+
`export default class Popup extends Component {`,
|
|
263
|
+
` <template>popup</template>`,
|
|
264
|
+
`}`,
|
|
265
|
+
].join("\n"),
|
|
266
|
+
},
|
|
267
|
+
["./src/index.ts"],
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
expect(dist.files).toMatchInlineSnapshot(`
|
|
271
|
+
[
|
|
272
|
+
"index.d.ts",
|
|
273
|
+
"index.d.ts.map",
|
|
274
|
+
"index.js",
|
|
275
|
+
"index.js.map",
|
|
276
|
+
]
|
|
277
|
+
`);
|
|
278
|
+
|
|
279
|
+
expect(printed(dist)).toMatchInlineSnapshot(`
|
|
280
|
+
"//=== index.d.ts
|
|
281
|
+
import Component from "@glimmer/component";
|
|
282
|
+
//#region src/components/select/option-list.d.ts
|
|
283
|
+
declare class OptionList extends Component {}
|
|
284
|
+
//#endregion
|
|
285
|
+
export { OptionList };
|
|
286
|
+
//# sourceMappingURL=index.d.ts.map"
|
|
287
|
+
`);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("bundles co-located CSS (via @tsdown/css) without breaking declarations", async () => {
|
|
291
|
+
// Ember components routinely import a co-located .css file. Without CSS
|
|
292
|
+
// handling the build dies on tsdown's css-guard — and because the failing
|
|
293
|
+
// component module never loads, every declaration that references it
|
|
294
|
+
// dangles (surfacing as misleading UNLOADABLE_DEPENDENCY errors on
|
|
295
|
+
// <component>.d.ts). @tsdown/css makes both work.
|
|
296
|
+
const dist = await buildFixture(
|
|
297
|
+
{
|
|
298
|
+
"src/index.ts": `export { default as Popup } from './popup.gts';`,
|
|
299
|
+
"src/service.ts": [
|
|
300
|
+
`import type { PopupBlock } from './popup.gts';`,
|
|
301
|
+
``,
|
|
302
|
+
`export function register(context: PopupBlock): void {`,
|
|
303
|
+
` void context;`,
|
|
304
|
+
`}`,
|
|
305
|
+
].join("\n"),
|
|
306
|
+
"src/popup.css": `.popup { color: red; }`,
|
|
307
|
+
"src/popup.gts": [
|
|
308
|
+
`import './popup.css';`,
|
|
309
|
+
`import Component from '@glimmer/component';`,
|
|
310
|
+
``,
|
|
311
|
+
`export interface PopupBlock {`,
|
|
312
|
+
` open: () => void;`,
|
|
313
|
+
`}`,
|
|
314
|
+
``,
|
|
315
|
+
`export default class Popup extends Component {`,
|
|
316
|
+
` <template>popup</template>`,
|
|
317
|
+
`}`,
|
|
318
|
+
].join("\n"),
|
|
319
|
+
},
|
|
320
|
+
["./src/index.ts", "./src/service.ts"],
|
|
321
|
+
);
|
|
322
|
+
|
|
323
|
+
expect(dist.files).toMatchInlineSnapshot(`
|
|
324
|
+
[
|
|
325
|
+
"index.d.ts",
|
|
326
|
+
"index.js",
|
|
327
|
+
"index.js.map",
|
|
328
|
+
"popup-CytznrQX.d.ts",
|
|
329
|
+
"popup-CytznrQX.d.ts.map",
|
|
330
|
+
"service.d.ts",
|
|
331
|
+
"service.d.ts.map",
|
|
332
|
+
"service.js",
|
|
333
|
+
"service.js.map",
|
|
334
|
+
"style.css",
|
|
335
|
+
]
|
|
336
|
+
`);
|
|
337
|
+
|
|
338
|
+
expect(printed(dist)).toMatchInlineSnapshot(`
|
|
339
|
+
"//=== index.d.ts
|
|
340
|
+
import { t as Popup } from "./popup-CytznrQX.js";
|
|
341
|
+
export { Popup };
|
|
342
|
+
//=== popup-CytznrQX.d.ts
|
|
343
|
+
import Component from "@glimmer/component";
|
|
344
|
+
//#region src/popup.d.ts
|
|
345
|
+
interface PopupBlock {
|
|
346
|
+
open: () => void;
|
|
347
|
+
}
|
|
348
|
+
declare class Popup extends Component {}
|
|
349
|
+
//#endregion
|
|
350
|
+
export { PopupBlock as n, Popup as t };
|
|
351
|
+
//# sourceMappingURL=popup-CytznrQX.d.ts.map
|
|
352
|
+
//=== service.d.ts
|
|
353
|
+
import { n as PopupBlock } from "./popup-CytznrQX.js";
|
|
354
|
+
//#region src/service.d.ts
|
|
355
|
+
declare function register(context: PopupBlock): void;
|
|
356
|
+
//#endregion
|
|
357
|
+
export { register };
|
|
358
|
+
//# sourceMappingURL=service.d.ts.map
|
|
359
|
+
//=== style.css
|
|
360
|
+
.popup {
|
|
361
|
+
color: red;
|
|
362
|
+
}
|
|
363
|
+
"
|
|
364
|
+
`);
|
|
365
|
+
});
|
|
366
|
+
});
|