@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/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
|
-
*
|
|
12
|
-
*
|
|
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
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
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
|
-
*
|
|
64
|
-
* ts
|
|
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
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
//
|
|
79
|
-
//
|
|
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
|
|
85
|
-
// /var -> /private/var).
|
|
86
|
-
//
|
|
87
|
-
//
|
|
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,
|
|
97
|
-
//
|
|
98
|
-
// directory would corrupt it.
|
|
99
|
-
//
|
|
100
|
-
//
|
|
101
|
-
//
|
|
102
|
-
//
|
|
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
|
|
120
|
-
// resolves to the virtual module.
|
|
121
|
-
//
|
|
122
|
-
//
|
|
123
|
-
//
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
//
|
|
127
|
-
//
|
|
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
|
-
//
|
|
157
|
-
//
|
|
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
|
|
192
|
-
// runtime modules AND declaration modules alike.
|
|
193
|
-
//
|
|
194
|
-
//
|
|
195
|
-
//
|
|
196
|
-
//
|
|
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,
|
|
208
|
-
// line-identity map is accurate to the line
|
|
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"}
|