@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/src/transform.ts CHANGED
@@ -7,9 +7,10 @@ import type { Plugin } from "rolldown";
7
7
  const processor = new Preprocessor();
8
8
 
9
9
  /**
10
- * `.d.ts` files emitted for `.gts` source reference the original `.gts`
11
- * specifiers. Consumers can't resolve those, so we rewrite them back to
12
- * extension-less specifiers.
10
+ * `.d.ts` files emitted for `.gts` source reference the original `.gts` specifiers.
11
+ *
12
+ * Consumers can't resolve those,
13
+ * so we rewrite them back to extension-less specifiers.
13
14
  */
14
15
  function fixDeclarationImports(content: string): string {
15
16
  return content
@@ -41,10 +42,12 @@ async function fixDtsExtensionsInDir(dir: string): Promise<void> {
41
42
  /**
42
43
  * A sourcemap mapping every generated line to the same line of the input.
43
44
  *
44
- * `AAAA` is the [0, 0, 0, 0] VLQ segment (first line maps to source 0, line 0,
45
- * column 0); `AACA` is [0, 0, +1, 0] (each following line advances the source
46
- * line by one). Exact at line granularity, which is all the specifier rewrite
47
- * can disturb.
45
+ * - `AAAA` is the [0, 0, 0, 0] VLQ segment
46
+ * (first line maps to source 0, line 0, column 0)
47
+ * - `AACA` is [0, 0, +1, 0]
48
+ * (each following line advances the source line by one)
49
+ *
50
+ * Exact at line granularity, which is all the specifier rewrite can disturb.
48
51
  */
49
52
  function lineIdentityMap(id: string, source: string) {
50
53
  return {
@@ -60,8 +63,10 @@ function lineIdentityMap(id: string, source: string) {
60
63
  }
61
64
 
62
65
  /**
63
- * Maps `.gts` -> `.ts` and `.gjs` -> `.js` (so rolldown can identify them as
64
- * ts/js) and preprocesses `<template>` via content-tag.
66
+ * Preprocesses `<template>` via content-tag, and maps
67
+ * `.gts` → `.ts`
68
+ * `.gjs` → `.js`
69
+ * so rolldown can identify them as ts / js.
65
70
  */
66
71
  export function emberTransform(): Plugin {
67
72
  return {
@@ -70,21 +75,26 @@ export function emberTransform(): Plugin {
70
75
  resolveId: {
71
76
  order: "pre",
72
77
  handler(id, importer) {
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).
78
+ // Entries have no importer.
79
+ // Their ids come straight from the build config
80
+ // (tsdown expands entry globs to on-disk paths).
81
+ //
82
+ // Resolve a `.gts` / `.gjs` entry to the same virtual `.ts` / `.js` id
83
+ // an imported module gets, so the load hook compiles it via content-tag
84
+ // instead of the raw `<template>` source hitting the parser.
85
+ //
86
+ // Entries may be any extension.
87
+ // The emitted `.js` / `.d.ts` paths mirror the entry paths either way
88
+ // (that's how tsdown's dts support works).
80
89
  if (!importer) {
81
90
  if (!id.endsWith(".gts") && !id.endsWith(".gjs")) return null;
82
91
  if (!existsSync(id)) return null;
83
92
 
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.
93
+ // rolldown's default resolver realpaths entry ids
94
+ // (e.g. macOS /var -> /private/var).
95
+ //
96
+ // Match it, or this same file imported from another entry
97
+ // resolves to a second module id and gets duplicated into both chunks.
88
98
  const fileName = realpathSync(path.resolve(id));
89
99
 
90
100
  return {
@@ -93,13 +103,16 @@ export function emberTransform(): Plugin {
93
103
  };
94
104
  }
95
105
 
96
- // An absolute specifier already names the file, so it needs no
97
- // importer-relative resolution — and joining it onto the importer's
98
- // directory would corrupt it. That is not hypothetical: a plugin's
99
- // virtual module (id prefixed with `\0`) can generate imports of
100
- // on-disk files by absolute path, and `path.dirname("\0./registry")`
101
- // is `"\0."`, so joining yields `"\0./Users/.../thing.gts"` — a path
102
- // no `existsSync`/`readFile` can accept (it has a null byte in it).
106
+ // An absolute specifier already names the file,
107
+ // so it needs no importer-relative resolution.
108
+ // Joining it onto the importer's directory would corrupt it.
109
+ //
110
+ // That is not hypothetical.
111
+ // A plugin's virtual module (id prefixed with `\0`)
112
+ // can generate imports of on-disk files by absolute path,
113
+ // and `path.dirname("\0./registry")` is `"\0."`.
114
+ // Joining then yields `"\0./Users/.../thing.gts"`:
115
+ // a path no `existsSync` / `readFile` can accept (it has a null byte in it).
103
116
  const fileName = path.isAbsolute(id) ? id : path.join(path.dirname(importer), id);
104
117
 
105
118
  if (id.endsWith(".gts")) {
@@ -116,15 +129,19 @@ export function emberTransform(): Plugin {
116
129
  };
117
130
  }
118
131
 
119
- // A `.ts`/`.js` specifier whose only backing file is a `.gts`/`.gjs`
120
- // resolves to the virtual module. This must also serve `.d.ts`
121
- // importers: rolldown-plugin-dts resolves a declaration module's
122
- // imports through the plugin pipeline (`this.resolve`), and — when the
123
- // resolution is a source file — loads it (registering its declaration)
124
- // before mapping the import to the declaration id. Virtual modules
125
- // exist nowhere else, so if we don't answer here the import either
126
- // fails to resolve (no file on disk) or, worse, resolves to a
127
- // declaration id that was never registered.
132
+ // A `.ts` / `.js` specifier whose only backing file is a `.gts` / `.gjs`
133
+ // resolves to the virtual module.
134
+ //
135
+ // This must also serve `.d.ts` importers.
136
+ // rolldown-plugin-dts resolves a declaration module's imports
137
+ // through the plugin pipeline (`this.resolve`).
138
+ // When the resolution is a source file, it loads it (registering its declaration)
139
+ // before mapping the import to the declaration id.
140
+ //
141
+ // Virtual modules exist nowhere else.
142
+ // If we don't answer here, the import either:
143
+ // - fails to resolve (no file on disk)
144
+ // - or, worse, resolves to a declaration id that was never registered
128
145
  if (id.endsWith(".ts")) {
129
146
  const gtsFileName = fileName.replace(/\.ts$/, ".gts");
130
147
  if (existsSync(gtsFileName) && !existsSync(fileName)) {
@@ -152,9 +169,11 @@ export function emberTransform(): Plugin {
152
169
  const meta = this.getModuleInfo(id)?.meta ?? {};
153
170
  let fileName = meta?.fileName;
154
171
 
155
- // A virtual id can be loaded without having passed through our
156
- // resolveId (rolldown-plugin-dts calls `this.load({ id })` with just
157
- // the id), so no meta is attached: recover the backing file from disk.
172
+ // A virtual id can be loaded without having passed through our resolveId
173
+ // (rolldown-plugin-dts calls `this.load({ id })` with just the id),
174
+ // so no meta is attached.
175
+ //
176
+ // Recover the backing file from disk.
158
177
  if (!fileName && !existsSync(id)) {
159
178
  if (id.endsWith(".ts") && existsSync(id.replace(/\.ts$/, ".gts"))) {
160
179
  fileName = id.replace(/\.ts$/, ".gts");
@@ -188,12 +207,13 @@ export function emberTransform(): Plugin {
188
207
  id: /\.(js|ts)$/,
189
208
  },
190
209
  handler(input, id) {
191
- // Rewrite `.gts` specifiers to `.ts` — the (virtual) source id — in
192
- // runtime modules AND declaration modules alike. Declaration modules
193
- // must NOT be rewritten to `.d.ts`: rolldown-plugin-dts's resolver
194
- // treats a source-file resolution as "load it (registering its
195
- // declaration), then map to the declaration id", while a `.d.ts` id is
196
- // returned as-is — unloadable when the module isn't registered yet
210
+ // Rewrite `.gts` specifiers to `.ts`, the (virtual) source id,
211
+ // in runtime modules AND declaration modules alike.
212
+ //
213
+ // Declaration modules must NOT be rewritten to `.d.ts`.
214
+ // rolldown-plugin-dts's resolver treats a source-file resolution as
215
+ // "load it (registering its declaration), then map to the declaration id".
216
+ // A `.d.ts` id is returned as-is: unloadable when the module isn't registered yet
197
217
  // (e.g. the `.gts` is only ever type-imported).
198
218
  const output = input.replace(
199
219
  /(['"`])((?:\.\.?\/|\/|@|[A-Za-z0-9_\-])[^'"]*?\.gts)\1/g,
@@ -204,9 +224,9 @@ export function emberTransform(): Plugin {
204
224
  return null;
205
225
  }
206
226
 
207
- // The rewrite only shortens import specifiers in place, so a
208
- // line-identity map is accurate to the line (and to the column for
209
- // everything before the first rewritten specifier on a line).
227
+ // The rewrite only shortens import specifiers in place,
228
+ // so a line-identity map is accurate to the line
229
+ // (and to the column, for everything before the first rewritten specifier on a line).
210
230
  return { code: output, map: lineIdentityMap(id, input) };
211
231
  },
212
232
  },
@@ -1,27 +0,0 @@
1
- //#region src/plugin-like.d.ts
2
- /**
3
- * What this package hands back: an object that rolldown and tsdown accept in
4
- * `plugins`.
5
- *
6
- * Structurally this *is* rolldown's `Plugin` -- `name` is its only required
7
- * member, every hook is optional -- so the two are assignable in both
8
- * directions: a consumer who imports rolldown's own type can still write
9
- * `const plugins: Plugin[] = ember()`, and tsdown's `plugins` option lists
10
- * `{ name: string }` among the shapes it takes.
11
- *
12
- * Declaring it here rather than re-exporting rolldown's type is what keeps
13
- * `rolldown` out of the published declarations. Otherwise it has to become a
14
- * runtime `dependency` purely so consumers can resolve a type: leave it a
15
- * devDependency and the declaration bundler inlines a ~200kB private copy of
16
- * rolldown's types instead, nominally distinct from the consumer's own.
17
- *
18
- * The precise hook signatures still apply inside this package -- each plugin
19
- * function is typed with rolldown's real `Plugin` (a devDependency), and this
20
- * type only widens what crosses the package boundary.
21
- */
22
- interface RolldownPluginLike {
23
- name: string;
24
- }
25
- //#endregion
26
- export { RolldownPluginLike as t };
27
- //# sourceMappingURL=plugin-like-CBvGkzCB.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin-like-CBvGkzCB.d.ts","names":[],"sources":["../src/plugin-like.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;UAoBiB;EACf"}