@nullvoxpopuli/ember-rolldown 2.6.0 → 2.6.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/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/transform.test.ts +50 -2
- package/src/transform.ts +8 -1
package/dist/index.js
CHANGED
|
@@ -396,7 +396,7 @@ function emberTransform() {
|
|
|
396
396
|
meta: { fileName }
|
|
397
397
|
};
|
|
398
398
|
}
|
|
399
|
-
const fileName = path.join(path.dirname(importer), id);
|
|
399
|
+
const fileName = path.isAbsolute(id) ? id : path.join(path.dirname(importer), id);
|
|
400
400
|
if (id.endsWith(".gts")) return {
|
|
401
401
|
id: fileName.replace(/\.gts$/, ".ts"),
|
|
402
402
|
meta: { fileName }
|
package/package.json
CHANGED
package/src/transform.test.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { mkdtemp, mkdir, writeFile } from "node:fs/promises";
|
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { rolldown } from "rolldown";
|
|
5
|
+
import type { Plugin } from "rolldown";
|
|
5
6
|
import { describe, expect, it } from "vitest";
|
|
6
7
|
|
|
7
8
|
import { emberTransform } from "./transform.ts";
|
|
@@ -15,7 +16,10 @@ import { emberTransform } from "./transform.ts";
|
|
|
15
16
|
*/
|
|
16
17
|
async function bundle(
|
|
17
18
|
files: Record<string, string>,
|
|
18
|
-
{
|
|
19
|
+
{
|
|
20
|
+
input = ["index.ts"],
|
|
21
|
+
plugins = () => [],
|
|
22
|
+
}: { input?: string[]; plugins?: (dir: string) => Plugin[] } = {},
|
|
19
23
|
): Promise<string> {
|
|
20
24
|
const dir = await mkdtemp(path.join(tmpdir(), "ember-rolldown-build-"));
|
|
21
25
|
|
|
@@ -29,7 +33,7 @@ async function bundle(
|
|
|
29
33
|
|
|
30
34
|
const build = await rolldown({
|
|
31
35
|
input: input.map((relative) => path.join(dir, relative)),
|
|
32
|
-
plugins: [emberTransform()],
|
|
36
|
+
plugins: [emberTransform(), ...plugins(dir)],
|
|
33
37
|
external: (id) => !isLocal(id),
|
|
34
38
|
onwarn() {},
|
|
35
39
|
});
|
|
@@ -174,6 +178,50 @@ describe("emberTransform (full plugin via rolldown)", () => {
|
|
|
174
178
|
`);
|
|
175
179
|
});
|
|
176
180
|
|
|
181
|
+
it("resolves an absolute .gts specifier imported from a plugin's virtual module", async () => {
|
|
182
|
+
/**
|
|
183
|
+
* The shape a code-generating plugin emits: a virtual module (id prefixed
|
|
184
|
+
* with `\0`, so it exists nowhere on disk) whose generated source imports
|
|
185
|
+
* real files by absolute path, because it has no directory to be relative
|
|
186
|
+
* to. `path.dirname` of such an id is `"\0."`, so the specifier must not be
|
|
187
|
+
* resolved against the importer's directory.
|
|
188
|
+
*/
|
|
189
|
+
const registry = (dir: string): Plugin[] => {
|
|
190
|
+
const source = "./registry?virtual=views";
|
|
191
|
+
const virtualId = `\0${source}`;
|
|
192
|
+
|
|
193
|
+
return [
|
|
194
|
+
{
|
|
195
|
+
name: "test:virtual-registry",
|
|
196
|
+
resolveId(id) {
|
|
197
|
+
return id === source ? virtualId : null;
|
|
198
|
+
},
|
|
199
|
+
load(id) {
|
|
200
|
+
if (id !== virtualId) return null;
|
|
201
|
+
|
|
202
|
+
return [
|
|
203
|
+
`import example from '${path.join(dir, "components/view/example.gts")}';`,
|
|
204
|
+
`export const views = { example };`,
|
|
205
|
+
].join("\n");
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
];
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const code = await bundle(
|
|
212
|
+
{
|
|
213
|
+
"index.ts": `export { views } from './registry?virtual=views';`,
|
|
214
|
+
"components/view/example.gts": `<template>example</template>`,
|
|
215
|
+
},
|
|
216
|
+
{ plugins: registry },
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
// The absolutely-specified .gts got compiled and bundled in.
|
|
220
|
+
expect(code).not.toContain("<template>");
|
|
221
|
+
expect(code).toContain("template(");
|
|
222
|
+
expect(code).toContain("example");
|
|
223
|
+
});
|
|
224
|
+
|
|
177
225
|
it("compiles a .gts module used directly as an entry (no importer)", async () => {
|
|
178
226
|
const code = await bundle(
|
|
179
227
|
{
|
package/src/transform.ts
CHANGED
|
@@ -93,7 +93,14 @@ export function emberTransform(): Plugin {
|
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
|
|
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).
|
|
103
|
+
const fileName = path.isAbsolute(id) ? id : path.join(path.dirname(importer), id);
|
|
97
104
|
|
|
98
105
|
if (id.endsWith(".gts")) {
|
|
99
106
|
return {
|