Skip to content

Commit 60fea97

Browse files
refactor: let rollup normalize patterns
1 parent 15d9969 commit 60fea97

File tree

3 files changed

+2
-38
lines changed

3 files changed

+2
-38
lines changed

src/helpers.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { FilterPattern, normalizePath } from "@rollup/pluginutils";
21
import path from "path";
32
import { OutputOptions } from "rollup";
43

@@ -25,16 +24,3 @@ export function getRelativeImportPath(from: string, to: string) {
2524

2625
return import_path;
2726
}
28-
29-
export function normalizeFilterPattern(pattern?: FilterPattern): FilterPattern | undefined {
30-
if (typeof pattern === "string") return normalizePath(pattern);
31-
32-
if (Array.isArray(pattern)) {
33-
return pattern.map(element => {
34-
if (typeof element === "string") return normalizePath(element);
35-
return element;
36-
});
37-
}
38-
39-
return pattern;
40-
}

src/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from "path";
33
import { Plugin } from "rollup";
44
import { createFilter, FilterPattern, normalizePath } from "@rollup/pluginutils";
55
import { parse, print, types, visit } from "recast";
6-
import { getOutputId, getRelativeImportPath, normalizeFilterPattern } from "./helpers";
6+
import { getOutputId, getRelativeImportPath } from "./helpers";
77

88
const PLUGIN_NAME = "external-assets";
99
const PREFIX = `\0${PLUGIN_NAME}:`;
@@ -34,8 +34,6 @@ export default function externalAssets(
3434
exclude?: FilterPattern,
3535
options?: Options,
3636
): Plugin {
37-
include = normalizeFilterPattern(include);
38-
exclude = normalizeFilterPattern(exclude);
3937
const idFilter = createFilter(include, exclude, options);
4038
const assets = new Map<string, Buffer>();
4139

tests/unit.test.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from "path";
2-
import { getOutputId, normalizeFilterPattern } from "../src/helpers";
2+
import { getOutputId } from "../src/helpers";
33

44
test("getOutputId", () => {
55
expect(getOutputId("a.ext", { dir: "out" })).toBe(path.resolve("out/a.ext"));
@@ -12,23 +12,3 @@ test("getOutputId", () => {
1212
expect(getOutputId("a.ext", {})).toBe(path.resolve("a.ext"));
1313
expect(getOutputId("a/b.ext", {})).toBe(path.resolve("a/b.ext"));
1414
});
15-
16-
test("normalizeFilterPattern", () => {
17-
expect(normalizeFilterPattern()).toBeUndefined();
18-
expect(normalizeFilterPattern(null)).toBeNull();
19-
expect(normalizeFilterPattern(/\.txt/g)).toStrictEqual(/\.txt/g);
20-
expect(normalizeFilterPattern("abc/def/**/*")).toBe("abc/def/**/*");
21-
expect(normalizeFilterPattern("abc\\def\\**\\*")).toBe("abc/def/**/*");
22-
expect(normalizeFilterPattern(path.resolve("abc/def/**/*"))).toBe(path.resolve("abc/def/**/*").replace(/\\/g, "/"));
23-
expect([
24-
normalizeFilterPattern(/\.txt/g),
25-
normalizeFilterPattern("abc/def/**/*"),
26-
normalizeFilterPattern("abc\\def\\**\\*"),
27-
normalizeFilterPattern(path.resolve("abc/def/**/*")),
28-
]).toStrictEqual([
29-
/\.txt/g,
30-
"abc/def/**/*",
31-
"abc/def/**/*",
32-
path.resolve("abc/def/**/*").replace(/\\/g, "/"),
33-
]);
34-
});

0 commit comments

Comments
 (0)