@nullvoxpopuli/ember-rolldown 2.3.0 → 2.5.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 CHANGED
@@ -58,11 +58,30 @@ A `babel.config.js` is optional. Without one, `ember()` compiles templates
58
58
  [decorator-transforms](https://github.com/ef4/decorator-transforms)), and
59
59
  TypeScript; with one, your config runs instead.
60
60
 
61
+ ### Entrypoints
62
+
63
+ Entries may be any extension — `.ts`, `.js`, `.gts`, `.gjs`:
64
+
65
+ ```js
66
+ export default defineConfig({
67
+ entry: ["./src/index.ts", "./src/components/menu.gts"],
68
+ plugins: [ember()],
69
+ });
70
+ ```
71
+
72
+ Whatever the source extension, the emitted `.js` and `.d.ts` paths mirror the
73
+ entry paths (that's how tsdown's dts support works): the example emits
74
+ `dist/index.js` + `dist/index.d.ts` and `dist/components/menu.js` +
75
+ `dist/components/menu.d.ts`. Type imports resolve against those emitted
76
+ paths, so your entries — together with your `exports` map — _are_ your
77
+ public API: a module that isn't an entry has no stable `dist/` path of its
78
+ own and is only reachable through the entrypoints that re-export it.
79
+
61
80
  ### Declarations
62
81
 
63
82
  Declarations are emitted with isolated declarations — the only declaration
64
83
  pipeline that can see `<template>` (`.gts`/`.gjs`) modules, which exist only
65
- inside the bundler's module graph. Your `tsconfig.json` must enable it
84
+ inside the bundler's module graph. The tsconfig your build uses must enable it
66
85
  (`ember()` errors otherwise):
67
86
 
68
87
  ```jsonc
@@ -82,6 +101,33 @@ import type { TOC } from "@ember/component/template-only";
82
101
  export const Badge: TOC<BadgeSignature> = <template>...</template>;
83
102
  ```
84
103
 
104
+ #### Keeping the constraint off dev-only code
105
+
106
+ `isolatedDeclarations` is a constraint on how _published_ code is written, so it
107
+ should cover only the code you emit declarations for. If your package also holds
108
+ dev-only code — a demo app, in-package tests — putting the flag on the single
109
+ `tsconfig.json` that covers everything would force explicit annotations on demo
110
+ components and test helpers that never get a `.d.ts` emitted for them.
111
+
112
+ The tsconfig `ember()` checks is the one
113
+ [tsdown's `tsconfig` option](https://tsdown.dev/options/tsconfig) points at, so
114
+ point the build at a publish-only config and leave `tsconfig.json` alone for
115
+ editors and `tsc --noEmit`:
116
+
117
+ ```js
118
+ // tsdown.config.js
119
+ export default defineConfig({
120
+ entry: ["./src/index.ts"],
121
+ // include: ["src/**/*"], isolatedDeclarations: true
122
+ tsconfig: "./tsconfig.publish.json",
123
+ plugins: [ember()],
124
+ });
125
+ ```
126
+
127
+ The tradeoff: isolated-declaration errors in `src` then surface when you build
128
+ rather than in your editor, since the editor uses `tsconfig.json`. Run the build
129
+ (or `tsc --noEmit -p tsconfig.publish.json`) in CI so nothing lands unchecked.
130
+
85
131
  ## CSS
86
132
 
87
133
  Components that import co-located CSS (`import './popup.css'`) need
@@ -140,8 +186,9 @@ it.
140
186
 
141
187
  `ember()` returns an array of rolldown plugins:
142
188
 
143
- - **`emberIsolatedDeclarations()`** — errors when a `tsconfig.json` is present
144
- without `isolatedDeclarations: true`.
189
+ - **`emberIsolatedDeclarations()`** — errors when the tsconfig the build uses
190
+ (tsdown's `tsconfig` option, defaulting to `tsconfig.json`) is present without
191
+ `isolatedDeclarations: true`.
145
192
  - **`emberExternals()`** — keeps your `dependencies`, `peerDependencies`, and
146
193
  the ember virtual packages (e.g. `@ember/component`, `@glimmer/tracking`, the
147
194
  template compiler) external, so the consuming app resolves them.
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import transformTypeScript from "@babel/plugin-transform-typescript";
3
3
  import templateCompilation from "babel-plugin-ember-template-compilation";
4
4
  import decoratorTransforms from "decorator-transforms";
5
5
  import { loadPartialConfigSync } from "@babel/core";
6
- import { existsSync, readFileSync } from "node:fs";
6
+ import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
7
7
  import { createRequire } from "node:module";
8
8
  import path, { dirname, resolve } from "node:path";
9
9
  import pkg from "@embroider/core";
@@ -220,7 +220,28 @@ function emberExternals() {
220
220
  //#endregion
221
221
  //#region src/isolated-declarations.ts
222
222
  /**
223
- * Errors the build when a `tsconfig.json` is present without
223
+ * Resolve the tsconfig the build will actually use, mirroring tsdown's own
224
+ * `tsconfig` option (`string | boolean`):
225
+ *
226
+ * - `undefined` / `true`: `tsconfig.json` in the cwd.
227
+ * - a path to a file: that file.
228
+ * - a path to a directory: `tsconfig.json` inside it.
229
+ * - `false`: no tsconfig at all.
230
+ *
231
+ * Under plain rolldown there is no such option, so the cwd's `tsconfig.json`
232
+ * is all there is.
233
+ */
234
+ function resolveTsconfigPath(option) {
235
+ if (option === false) return void 0;
236
+ if (typeof option === "string") {
237
+ const asPath = resolve(option);
238
+ if (existsSync(asPath) && statSync(asPath).isDirectory()) return resolve(asPath, "tsconfig.json");
239
+ return asPath;
240
+ }
241
+ return resolve("tsconfig.json");
242
+ }
243
+ /**
244
+ * Errors the build when the tsconfig it builds with does not set
224
245
  * `isolatedDeclarations: true`.
225
246
  *
226
247
  * This is required: declarations for `.gts`/`.gjs` (template tag) modules can
@@ -234,16 +255,28 @@ function emberExternals() {
234
255
  * same rules the build enforces (exported values need explicit type
235
256
  * annotations, e.g. `export const X: TOC<Sig> = <template>...`).
236
257
  *
237
- * Projects without a `tsconfig.json` (JavaScript libraries) or without the
238
- * `typescript` package have no declarations to emit, so there is nothing to
239
- * check.
258
+ * The tsconfig checked is the one tsdown's `tsconfig` option points at, not
259
+ * necessarily `tsconfig.json`. A library whose package also holds dev-only code
260
+ * (a demo app, in-package tests) can therefore keep a permissive
261
+ * `tsconfig.json` covering everything for editors and `tsc --noEmit`, and point
262
+ * the build at a `tsconfig.publish.json` that covers only the publishable
263
+ * sources -- isolated declarations then constrain exactly the code that gets
264
+ * declarations emitted for it, and nothing else.
265
+ *
266
+ * Projects with no tsconfig (JavaScript libraries, or `tsconfig: false`) or
267
+ * without the `typescript` package have no declarations to emit, so there is
268
+ * nothing to check.
240
269
  */
241
270
  function emberIsolatedDeclarations() {
271
+ let tsconfigOption;
242
272
  return {
243
273
  name: "ember:isolated-declarations",
274
+ tsdownConfig(config) {
275
+ tsconfigOption = config.tsconfig;
276
+ },
244
277
  async buildStart() {
245
- const tsconfigPath = resolve("tsconfig.json");
246
- if (!existsSync(tsconfigPath)) return;
278
+ const tsconfigPath = resolveTsconfigPath(tsconfigOption);
279
+ if (!tsconfigPath || !existsSync(tsconfigPath)) return;
247
280
  let ts;
248
281
  try {
249
282
  ts = (await import("typescript")).default;
@@ -252,7 +285,7 @@ function emberIsolatedDeclarations() {
252
285
  }
253
286
  const { config, error } = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
254
287
  if (error) return;
255
- if (ts.parseJsonConfigFileContent(config, ts.sys, dirname(tsconfigPath)).options.isolatedDeclarations !== true) this.error(`${tsconfigPath} must set "compilerOptions.isolatedDeclarations": true.\n\nDeclarations for .gts/.gjs (template tag) modules can only be emitted by the isolated-declarations pipeline, which reads compiled modules from the bundler's module graph -- the tsc-based pipeline reads from disk and cannot see them.\n\nIsolated declarations require exported values to have explicit type annotations, e.g. \`export const X: TOC<Sig> = <template>...\`.`);
288
+ if (ts.parseJsonConfigFileContent(config, ts.sys, dirname(tsconfigPath)).options.isolatedDeclarations !== true) this.error(`${tsconfigPath} must set "compilerOptions.isolatedDeclarations": true.\n\nDeclarations for .gts/.gjs (template tag) modules can only be emitted by the isolated-declarations pipeline, which reads compiled modules from the bundler's module graph -- the tsc-based pipeline reads from disk and cannot see them.\n\nIsolated declarations require exported values to have explicit type annotations, e.g. \`export const X: TOC<Sig> = <template>...\`.\n\nIf this tsconfig also covers dev-only code (a demo app, in-package tests) that should not be constrained this way, point tsdown's \`tsconfig\` option at a publish-only tsconfig that sets the flag and covers just the published sources.`);
256
289
  }
257
290
  };
258
291
  }
@@ -306,7 +339,15 @@ function emberTransform() {
306
339
  resolveId: {
307
340
  order: "pre",
308
341
  handler(id, importer) {
309
- if (!importer) return null;
342
+ if (!importer) {
343
+ if (!id.endsWith(".gts") && !id.endsWith(".gjs")) return null;
344
+ if (!existsSync(id)) return null;
345
+ const fileName = realpathSync(path.resolve(id));
346
+ return {
347
+ id: fileName.replace(/\.gts$/, ".ts").replace(/\.gjs$/, ".js"),
348
+ meta: { fileName }
349
+ };
350
+ }
310
351
  const fileName = path.join(path.dirname(importer), id);
311
352
  if (id.endsWith(".gts")) return {
312
353
  id: fileName.replace(/\.gts$/, ".ts"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nullvoxpopuli/ember-rolldown",
3
- "version": "2.3.0",
3
+ "version": "2.5.0",
4
4
  "description": "Meta plugin for building ember v2 libraries/addons with rolldown & tsdown.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -0,0 +1,122 @@
1
+ import { mkdir, mkdtemp, 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
+ let restoreCwd: (() => void) | undefined;
10
+
11
+ afterEach(() => {
12
+ restoreCwd?.();
13
+ restoreCwd = undefined;
14
+ });
15
+
16
+ /**
17
+ * Runs a real tsdown build of a single trivial entry in a temp dir, so the
18
+ * isolated-declarations guard reads the tsconfig files written by the test the
19
+ * same way it does under the tsdown CLI. Returns the build's rejection, or
20
+ * `undefined` when it succeeded.
21
+ */
22
+ async function buildFixture(
23
+ files: Record<string, string>,
24
+ tsconfig?: string | boolean,
25
+ ): Promise<Error | undefined> {
26
+ const dir = await mkdtemp(path.join(tmpdir(), "ember-rolldown-isolated-declarations-"));
27
+
28
+ const withDefaults: Record<string, string> = {
29
+ "package.json": JSON.stringify({ name: "fixture", version: "0.0.0", type: "module" }),
30
+ "src/index.ts": `export const greeting: string = 'hello';`,
31
+ ...files,
32
+ };
33
+
34
+ for (const [relative, source] of Object.entries(withDefaults)) {
35
+ const full = path.join(dir, relative);
36
+ await mkdir(path.dirname(full), { recursive: true });
37
+ await writeFile(full, source, "utf8");
38
+ }
39
+
40
+ const previousCwd = process.cwd();
41
+ process.chdir(dir);
42
+ restoreCwd = () => process.chdir(previousCwd);
43
+
44
+ try {
45
+ await build({
46
+ entry: ["./src/index.ts"],
47
+ config: false,
48
+ logLevel: "silent",
49
+ tsconfig,
50
+ plugins: [ember()],
51
+ });
52
+
53
+ return undefined;
54
+ } catch (error) {
55
+ return error as Error;
56
+ }
57
+ }
58
+
59
+ const withFlag = JSON.stringify({
60
+ compilerOptions: { isolatedDeclarations: true, declaration: true },
61
+ });
62
+ const withoutFlag = JSON.stringify({ compilerOptions: { declaration: true } });
63
+
64
+ describe("isolated declarations guard", () => {
65
+ it("errors when the cwd tsconfig.json does not set the flag", async () => {
66
+ const error = await buildFixture({ "tsconfig.json": withoutFlag });
67
+
68
+ expect(error?.message).toContain(`must set "compilerOptions.isolatedDeclarations": true`);
69
+ });
70
+
71
+ it("passes when the cwd tsconfig.json sets the flag", async () => {
72
+ expect(await buildFixture({ "tsconfig.json": withFlag })).toBeUndefined();
73
+ });
74
+
75
+ it("checks the tsconfig the `tsconfig` option points at, not tsconfig.json", async () => {
76
+ // The shape a library with in-package dev code wants: a permissive
77
+ // tsconfig.json for editors and `tsc --noEmit` over everything, and a
78
+ // publish-only tsconfig -- the one the build uses -- carrying the flag.
79
+ const error = await buildFixture(
80
+ { "tsconfig.json": withoutFlag, "tsconfig.publish.json": withFlag },
81
+ "./tsconfig.publish.json",
82
+ );
83
+
84
+ expect(error).toBeUndefined();
85
+ });
86
+
87
+ it("errors when the tsconfig the `tsconfig` option points at lacks the flag", async () => {
88
+ const error = await buildFixture(
89
+ { "tsconfig.json": withFlag, "tsconfig.publish.json": withoutFlag },
90
+ "./tsconfig.publish.json",
91
+ );
92
+
93
+ expect(error?.message).toContain("tsconfig.publish.json");
94
+ expect(error?.message).toContain(`must set "compilerOptions.isolatedDeclarations": true`);
95
+ });
96
+
97
+ it("resolves a directory `tsconfig` option to the tsconfig.json inside it", async () => {
98
+ const error = await buildFixture(
99
+ { "tsconfig.json": withFlag, "config/tsconfig.json": withoutFlag },
100
+ "./config",
101
+ );
102
+
103
+ expect(error?.message).toContain(`must set "compilerOptions.isolatedDeclarations": true`);
104
+ });
105
+
106
+ it("skips the check when there is no tsconfig at all", async () => {
107
+ expect(await buildFixture({})).toBeUndefined();
108
+ });
109
+
110
+ it("skips the check when tsconfig is disabled", async () => {
111
+ expect(await buildFixture({ "tsconfig.json": withoutFlag }, false)).toBeUndefined();
112
+ });
113
+
114
+ it("inherits the flag through an extends chain", async () => {
115
+ const error = await buildFixture({
116
+ "tsconfig.base.json": withFlag,
117
+ "tsconfig.json": JSON.stringify({ extends: "./tsconfig.base.json" }),
118
+ });
119
+
120
+ expect(error).toBeUndefined();
121
+ });
122
+ });
@@ -1,10 +1,39 @@
1
- import { existsSync } from "node:fs";
1
+ import { existsSync, statSync } from "node:fs";
2
2
  import { dirname, resolve } from "node:path";
3
3
 
4
4
  import type { Plugin } from "rolldown";
5
+ import type { UserConfig } from "tsdown";
5
6
 
6
7
  /**
7
- * Errors the build when a `tsconfig.json` is present without
8
+ * Resolve the tsconfig the build will actually use, mirroring tsdown's own
9
+ * `tsconfig` option (`string | boolean`):
10
+ *
11
+ * - `undefined` / `true`: `tsconfig.json` in the cwd.
12
+ * - a path to a file: that file.
13
+ * - a path to a directory: `tsconfig.json` inside it.
14
+ * - `false`: no tsconfig at all.
15
+ *
16
+ * Under plain rolldown there is no such option, so the cwd's `tsconfig.json`
17
+ * is all there is.
18
+ */
19
+ function resolveTsconfigPath(option: string | boolean | undefined): string | undefined {
20
+ if (option === false) return undefined;
21
+
22
+ if (typeof option === "string") {
23
+ const asPath = resolve(option);
24
+
25
+ if (existsSync(asPath) && statSync(asPath).isDirectory()) {
26
+ return resolve(asPath, "tsconfig.json");
27
+ }
28
+
29
+ return asPath;
30
+ }
31
+
32
+ return resolve("tsconfig.json");
33
+ }
34
+
35
+ /**
36
+ * Errors the build when the tsconfig it builds with does not set
8
37
  * `isolatedDeclarations: true`.
9
38
  *
10
39
  * This is required: declarations for `.gts`/`.gjs` (template tag) modules can
@@ -18,18 +47,34 @@ import type { Plugin } from "rolldown";
18
47
  * same rules the build enforces (exported values need explicit type
19
48
  * annotations, e.g. `export const X: TOC<Sig> = <template>...`).
20
49
  *
21
- * Projects without a `tsconfig.json` (JavaScript libraries) or without the
22
- * `typescript` package have no declarations to emit, so there is nothing to
23
- * check.
50
+ * The tsconfig checked is the one tsdown's `tsconfig` option points at, not
51
+ * necessarily `tsconfig.json`. A library whose package also holds dev-only code
52
+ * (a demo app, in-package tests) can therefore keep a permissive
53
+ * `tsconfig.json` covering everything for editors and `tsc --noEmit`, and point
54
+ * the build at a `tsconfig.publish.json` that covers only the publishable
55
+ * sources -- isolated declarations then constrain exactly the code that gets
56
+ * declarations emitted for it, and nothing else.
57
+ *
58
+ * Projects with no tsconfig (JavaScript libraries, or `tsconfig: false`) or
59
+ * without the `typescript` package have no declarations to emit, so there is
60
+ * nothing to check.
24
61
  */
25
62
  export function emberIsolatedDeclarations(): Plugin {
63
+ let tsconfigOption: string | boolean | undefined;
64
+
26
65
  return {
27
66
  name: "ember:isolated-declarations",
28
67
 
68
+ // Not called under plain rolldown, which leaves `tsconfigOption` undefined
69
+ // -- i.e. the cwd's tsconfig.json, the only thing it could mean there.
70
+ tsdownConfig(config: UserConfig) {
71
+ tsconfigOption = config.tsconfig;
72
+ },
73
+
29
74
  async buildStart() {
30
- const tsconfigPath = resolve("tsconfig.json");
75
+ const tsconfigPath = resolveTsconfigPath(tsconfigOption);
31
76
 
32
- if (!existsSync(tsconfigPath)) return;
77
+ if (!tsconfigPath || !existsSync(tsconfigPath)) return;
33
78
 
34
79
  let ts: typeof import("typescript");
35
80
 
@@ -57,7 +102,10 @@ export function emberIsolatedDeclarations(): Plugin {
57
102
  `isolated-declarations pipeline, which reads compiled modules from the bundler's ` +
58
103
  `module graph -- the tsc-based pipeline reads from disk and cannot see them.\n\n` +
59
104
  `Isolated declarations require exported values to have explicit type annotations, ` +
60
- `e.g. \`export const X: TOC<Sig> = <template>...\`.`,
105
+ `e.g. \`export const X: TOC<Sig> = <template>...\`.\n\n` +
106
+ `If this tsconfig also covers dev-only code (a demo app, in-package tests) that ` +
107
+ `should not be constrained this way, point tsdown's \`tsconfig\` option at a ` +
108
+ `publish-only tsconfig that sets the flag and covers just the published sources.`,
61
109
  );
62
110
  }
63
111
  },
@@ -13,7 +13,10 @@ import { emberTransform } from "./transform.ts";
13
13
  * `.gts`/`.gjs`/`.ts` handling and doesn't need real dependencies installed.
14
14
  * Returns the concatenated code of every emitted chunk.
15
15
  */
16
- async function bundle(files: Record<string, string>): Promise<string> {
16
+ async function bundle(
17
+ files: Record<string, string>,
18
+ { input = ["index.ts"] }: { input?: string[] } = {},
19
+ ): Promise<string> {
17
20
  const dir = await mkdtemp(path.join(tmpdir(), "ember-rolldown-build-"));
18
21
 
19
22
  for (const [relative, source] of Object.entries(files)) {
@@ -25,7 +28,7 @@ async function bundle(files: Record<string, string>): Promise<string> {
25
28
  const isLocal = (id: string) => id.startsWith(".") || id.startsWith("/") || path.isAbsolute(id);
26
29
 
27
30
  const build = await rolldown({
28
- input: path.join(dir, "index.ts"),
31
+ input: input.map((relative) => path.join(dir, relative)),
29
32
  plugins: [emberTransform()],
30
33
  external: (id) => !isLocal(id),
31
34
  onwarn() {},
@@ -171,6 +174,54 @@ describe("emberTransform (full plugin via rolldown)", () => {
171
174
  `);
172
175
  });
173
176
 
177
+ it("compiles a .gts module used directly as an entry (no importer)", async () => {
178
+ const code = await bundle(
179
+ {
180
+ // Both an entry .gts and a .ts entry importing it: the shared module
181
+ // must resolve to ONE id (the entry resolution realpaths, matching
182
+ // rolldown's own resolver) so it lands in the entry chunk and the
183
+ // index chunk imports it, rather than duplicating the code.
184
+ "index.ts": `export { default as Foo } from './foo.gts';`,
185
+ "foo.gts": [
186
+ `import Component from '@glimmer/component';`,
187
+ `export default class Foo extends Component {`,
188
+ ` <template>Entry</template>`,
189
+ `}`,
190
+ ].join("\n"),
191
+ },
192
+ { input: ["index.ts", "foo.gts"] },
193
+ );
194
+
195
+ expect(code).not.toContain("<template>");
196
+ expect(code).toContain("template(");
197
+ expect(code).toContain(`from "@glimmer/component"`);
198
+ // deduplicated: the class body appears exactly once, in foo's own chunk
199
+ expect(code.match(/extends Component/g)).toHaveLength(1);
200
+ expect(code).toContain(`from "./foo.js"`);
201
+
202
+ expect(code).toMatchInlineSnapshot(`
203
+ "import { template } from "@ember/template-compiler";
204
+ import Component from "@glimmer/component";
205
+ //#region foo.ts
206
+ var Foo = class extends Component {
207
+ static {
208
+ template(\`Entry\`, {
209
+ component: this,
210
+ eval() {
211
+ return eval(arguments[0]);
212
+ }
213
+ });
214
+ }
215
+ };
216
+ //#endregion
217
+ export { Foo as default };
218
+
219
+ import Foo from "./foo.js";
220
+ export { Foo };
221
+ "
222
+ `);
223
+ });
224
+
174
225
  it("emits sourcemaps for the specifier rewrite (no SOURCEMAP_BROKEN warnings)", async () => {
175
226
  const dir = await mkdtemp(path.join(tmpdir(), "ember-rolldown-map-"));
176
227
 
package/src/transform.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Preprocessor } from "content-tag";
2
- import { existsSync } from "node:fs";
2
+ import { existsSync, realpathSync } from "node:fs";
3
3
  import { readFile, writeFile, readdir } from "node:fs/promises";
4
4
  import path from "node:path";
5
5
  import type { Plugin } from "rolldown";
@@ -70,7 +70,28 @@ export function emberTransform(): Plugin {
70
70
  resolveId: {
71
71
  order: "pre",
72
72
  handler(id, importer) {
73
- if (!importer) return null;
73
+ // Entries have no importer: their ids come straight from the build
74
+ // config (tsdown expands entry globs to on-disk paths). Resolve a
75
+ // `.gts`/`.gjs` entry to the same virtual `.ts`/`.js` id an imported
76
+ // module gets, so the load hook compiles it via content-tag instead
77
+ // of the raw `<template>` source hitting the parser. Entries may be
78
+ // any extension — the emitted `.js`/`.d.ts` paths mirror the entry
79
+ // paths either way (that's how tsdown's dts support works).
80
+ if (!importer) {
81
+ if (!id.endsWith(".gts") && !id.endsWith(".gjs")) return null;
82
+ if (!existsSync(id)) return null;
83
+
84
+ // rolldown's default resolver realpaths entry ids (e.g. macOS
85
+ // /var -> /private/var). Match it, or this same file imported from
86
+ // another entry resolves to a second module id and gets duplicated
87
+ // into both chunks.
88
+ const fileName = realpathSync(path.resolve(id));
89
+
90
+ return {
91
+ id: fileName.replace(/\.gts$/, ".ts").replace(/\.gjs$/, ".js"),
92
+ meta: { fileName },
93
+ };
94
+ }
74
95
 
75
96
  const fileName = path.join(path.dirname(importer), id);
76
97