Skip to content

Commit 24df22e

Browse files
committed
[FEATURE] Provide EXT:my_extension as alias
In addition to the `@my_extension` alias, now it's also possible to use `EXT:my_extension` in all paths resolved by vite, such as ESM modules or URLs in CSS files.
1 parent d39f0ba commit 24df22e

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

src/utils.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from "node:fs";
22
import { dirname, join, resolve } from "node:path";
33
import type { InputOption } from "rollup";
4-
import type { AliasOptions, Logger } from "vite";
4+
import type { Alias, AliasOptions, Logger } from "vite";
55
import fg from "fast-glob";
66
import colors from "picocolors";
77
import type {
@@ -185,8 +185,10 @@ export function outputDebugInformation(
185185
const extensionList = relevantExtensions.map(
186186
(extension) => extension.extensionKey,
187187
);
188-
const aliasList = extensionList.map(
189-
(extensionKey) => "@" + extensionKey,
188+
const aliasList = extensionList.reduce(
189+
(aliasList: string[], extensionKey) =>
190+
aliasList.concat(["@" + extensionKey, "EXT:" + extensionKey]),
191+
[],
190192
);
191193
logger.info(
192194
`The following extensions with vite entrypoints have been recognized: ${colors.green(extensionList.join(", "))}`,
@@ -230,12 +232,20 @@ export function addAliases(
230232
alias: AliasOptions | undefined,
231233
extensions: Typo3ExtensionContext[],
232234
): AliasOptions {
233-
const additionalAliases = extensions.map((extension) => ({
234-
find: "@" + extension.extensionKey,
235-
replacement: extension.path.endsWith("/")
236-
? extension.path
237-
: extension.path + "/",
238-
}));
235+
const additionalAliases = extensions.reduce(
236+
(aliases: Alias[], extension) => {
237+
const replacement = extension.path.endsWith("/")
238+
? extension.path
239+
: extension.path + "/";
240+
aliases.push({ find: "@" + extension.extensionKey, replacement });
241+
aliases.push({
242+
find: "EXT:" + extension.extensionKey,
243+
replacement,
244+
});
245+
return aliases;
246+
},
247+
[],
248+
);
239249

240250
alias ??= [];
241251
if (!Array.isArray(alias)) {

tests/unit/addAliases.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ describe("addAliases", () => {
1717
find: "@test_extension",
1818
replacement: "/path/to/dummy/extension1/",
1919
},
20+
{
21+
find: "EXT:test_extension",
22+
replacement: "/path/to/dummy/extension1/",
23+
},
2024
]);
2125
});
2226
test("existing aliases as object", () => {
@@ -39,6 +43,10 @@ describe("addAliases", () => {
3943
find: "@test_extension",
4044
replacement: "/path/to/dummy/extension1/",
4145
},
46+
{
47+
find: "EXT:test_extension",
48+
replacement: "/path/to/dummy/extension1/",
49+
},
4250
]);
4351
});
4452
test("existing aliases as array", () => {
@@ -80,6 +88,10 @@ describe("addAliases", () => {
8088
find: "@test_extension",
8189
replacement: "/path/to/dummy/extension1/",
8290
},
91+
{
92+
find: "EXT:test_extension",
93+
replacement: "/path/to/dummy/extension1/",
94+
},
8395
]);
8496
});
8597
test("no double slashes in added alias paths", () => {
@@ -96,6 +108,10 @@ describe("addAliases", () => {
96108
find: "@test_extension",
97109
replacement: "/path/to/dummy/extension1/",
98110
},
111+
{
112+
find: "EXT:test_extension",
113+
replacement: "/path/to/dummy/extension1/",
114+
},
99115
]);
100116
});
101117
});

tests/unit/outputDebugInformation.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ describe("outputDebugInformation", () => {
4949
expect(logger.info).toHaveBeenNthCalledWith(
5050
2,
5151
"The following aliases have been defined: " +
52-
colors.green("@test_extension1, @test_extension2"),
52+
colors.green(
53+
"@test_extension1, EXT:test_extension1, @test_extension2, EXT:test_extension2",
54+
),
5355
{ timestamp: true },
5456
);
5557
expect(logger.info).toHaveBeenNthCalledWith(

0 commit comments

Comments
 (0)