Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix glob expression illegal operations on directories #1308

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
292 changes: 91 additions & 201 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/gulp-purgecss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"test": "jest"
},
"dependencies": {
"glob": "^11.0.0",
"fast-glob": "^3.3.2",
"plugin-error": "^2.0.0",
"purgecss": "^7.0.2",
"through2": "^4.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/gulp-purgecss/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as glob from "glob";
import glob from "fast-glob";
import PluginError from "plugin-error";
import { PurgeCSS } from "purgecss";
import * as internal from "stream";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require("path");
const glob = require("glob");
const glob = require("fast-glob");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const {PurgeCSSPlugin} = require("../../../src/");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require("path");
const glob = require("glob");
const glob = require("fast-glob");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const { PurgeCSSPlugin } = require("../../../src/");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require("path");
const glob = require("glob");
const glob = require("fast-glob");

const customExtractor = (content) => {
const res = content.match(/[A-z0-9-:/]+/g) || [];
Expand All @@ -19,4 +19,4 @@ module.exports = {
extensions: ["html", "js"],
},
],
}
}
24 changes: 24 additions & 0 deletions packages/purgecss/__tests__/globs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { PurgeCSS } from "../src/";
import { ROOT_TEST_EXAMPLES } from "./utils";

describe("Glob", () => {
it("glob expressions in content/css work", async () => {
const resultsPurge = await new PurgeCSS().purge({
content: [`${ROOT_TEST_EXAMPLES}comments/**/*.{js,html,json,svg}`],
css: [`${ROOT_TEST_EXAMPLES}comments/**/*.css`],
});

expect(resultsPurge[0].file).toBe(
`${ROOT_TEST_EXAMPLES}comments/ignore_comment.css`,
);
expect(resultsPurge[0].css.includes("/* purgecss ignore */")).toBe(false);
expect(resultsPurge[0].css.includes("/* purgecss ignore current */")).toBe(
false,
);

expect(resultsPurge[1].file).toBe(
`${ROOT_TEST_EXAMPLES}comments/ignore_comment_range.css`,
);
expect(resultsPurge[1].css.includes("h4")).toBe(false);
});
});
2 changes: 1 addition & 1 deletion packages/purgecss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"dependencies": {
"commander": "^12.1.0",
"glob": "^11.0.0",
"fast-glob": "^3.3.2",
"postcss": "^8.4.47",
"postcss-selector-parser": "^6.1.2"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/purgecss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import * as fs from "fs";
import * as glob from "glob";
import * as glob from "fast-glob";
import * as path from "path";
import * as postcss from "postcss";
import selectorParser from "postcss-selector-parser";
Expand Down Expand Up @@ -451,7 +451,7 @@ class PurgeCSS {
} catch (err) {
filesNames.push(
...glob.sync(globFile, {
nodir: true,
onlyFiles: true,
ignore: this.options.skippedContentGlobs.map((glob) =>
glob.replace(/^\.\//, ""),
),
Expand Down Expand Up @@ -645,7 +645,7 @@ class PurgeCSS {
if (typeof option === "string") {
processedOptions.push(
...glob.sync(option, {
nodir: true,
onlyFiles: true,
ignore: this.options.skippedContentGlobs,
}),
);
Expand Down