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

Replace glob packages with lighter alternatives – fast-glob + is-glob -> tinyglobby, micromatch -> picomatch #3680

Open
wants to merge 3 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
48 changes: 42 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,28 +133,27 @@
"debug": "^4.4.0",
"dependency-graph": "^1.0.0",
"entities": "^6.0.0",
"fast-glob": "^3.3.3",
"filesize": "^10.1.6",
"graceful-fs": "^4.2.11",
"gray-matter": "^4.0.3",
"is-glob": "^4.0.3",
"iso-639-1": "^3.1.4",
"js-yaml": "^4.1.0",
"kleur": "^4.1.5",
"liquidjs": "^10.21.0",
"luxon": "^3.5.0",
"markdown-it": "^14.1.0",
"micromatch": "^4.0.8",
"minimist": "^1.2.8",
"moo": "^0.5.2",
"node-retrieve-globals": "^6.0.0",
"nunjucks": "^3.2.4",
"p-map": "^7.0.3",
"picomatch": "^4.0.2",
"please-upgrade-node": "^3.2.0",
"posthtml": "^0.16.6",
"posthtml-match-helper": "^2.0.3",
"semver": "^7.7.1",
"slugify": "^1.6.6"
"slugify": "^1.6.6",
"tinyglobby": "^0.2.12"
},
"overrides": {
"gray-matter": {
Expand Down
4 changes: 2 additions & 2 deletions src/FileSystemSearch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fastglob from "fast-glob";
import { glob } from "tinyglobby";
import { TemplatePath } from "@11ty/eleventy-utils";
import debugUtil from "debug";

Expand Down Expand Up @@ -52,7 +52,7 @@ class FileSystemSearch {

this.count++;

this.promises[cacheKey] = fastglob(
this.promises[cacheKey] = glob(
globs,
Object.assign(
{
Expand Down
6 changes: 3 additions & 3 deletions src/TemplatePassthrough.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from "node:path";

import isGlob from "is-glob";
import { isDynamicPattern } from "tinyglobby";
import { filesize } from "filesize";
import copy from "@11ty/recursive-copy";
import { TemplatePath } from "@11ty/eleventy-utils";
Expand Down Expand Up @@ -48,7 +48,7 @@ class TemplatePassthrough {
// inputPath is relative to the root of your project and not your Eleventy input directory.
// TODO normalize these with forward slashes
this.inputPath = this.normalizeIfDirectory(path.inputPath);
this.#isInputPathGlob = isGlob(this.inputPath);
this.#isInputPathGlob = isDynamicPattern(this.inputPath);

this.outputPath = path.outputPath;
this.copyOptions = path.copyOptions; // custom options for recursive-copy
Expand Down Expand Up @@ -219,7 +219,7 @@ class TemplatePassthrough {
}

// TODO VirtualFileSystem candidate
if (!isGlob(this.inputPath) && this.isExists(this.inputPath)) {
if (!isDynamicPattern(this.inputPath) && this.isExists(this.inputPath)) {
return [
{
inputPath: this.inputPath,
Expand Down
8 changes: 6 additions & 2 deletions src/TemplatePassthroughManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isGlob from "is-glob";
import { isDynamicPattern } from "tinyglobby";
import { TemplatePath } from "@11ty/eleventy-utils";
import debugUtil from "debug";

Expand Down Expand Up @@ -244,7 +244,11 @@ class TemplatePassthroughManager {
if (TemplatePath.startsWithSubPath(changedFile, path.inputPath)) {
return path;
}
if (changedFile && isGlob(path.inputPath) && isGlobMatch(changedFile, [path.inputPath])) {
if (
changedFile &&
isDynamicPattern(path.inputPath) &&
isGlobMatch(changedFile, [path.inputPath])
) {
return path;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Util/GlobMatcher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import micromatch from "micromatch";
import picomatch from "picomatch";
import { TemplatePath } from "@11ty/eleventy-utils";

function isGlobMatch(filepath, globs = [], options = undefined) {
Expand All @@ -16,7 +16,7 @@ function isGlobMatch(filepath, globs = [], options = undefined) {
);

// globs: string or array of strings
return micromatch.isMatch(inputPath, globs, opts);
return picomatch.isMatch(inputPath, globs, opts);
}

export { isGlobMatch };
6 changes: 3 additions & 3 deletions src/Util/ProjectDirectories.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "node:fs";
import path from "node:path";
import { TemplatePath } from "@11ty/eleventy-utils";
import isGlob from "is-glob";
import { isDynamicPattern } from "tinyglobby";

/* Directories internally should always use *nix forward slashes */
class ProjectDirectories {
Expand Down Expand Up @@ -143,9 +143,9 @@ class ProjectDirectories {
if (inputExists) {
this.inputFile = ProjectDirectories.normalizePath(dirOrFile);
} else {
if (!isGlob(dirOrFile)) {
if (!isDynamicPattern(dirOrFile)) {
throw new Error(
`The "${dirOrFile}" \`input\` parameter (directory or file path) must exist on the file system (unless detected as a glob by the \`is-glob\` package)`,
`The "${dirOrFile}" \`input\` parameter (directory or file path) must exist on the file system (unless detected as a glob by the \`tinyglobby\` package)`,
);
}

Expand Down
39 changes: 0 additions & 39 deletions test/EleventyFilesGitIgnoreEleventyIgnoreTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,45 +193,6 @@ test("Get ignores (both .eleventyignore and .gitignore exists, but .gitignore is
]);
});

test("Bad expected output, this indicates a bug upstream in a dependency (update, was fixed in [email protected]). Input to 'src' and empty includes dir (issue #403, full paths in eleventyignore)", async (t) => {
let eleventyConfig = await getTemplateConfigInstanceCustomCallback({
input: "test/stubs-403",
output: "_site",
includes: "",
data: false,
}, function(eleventyConfig) {
eleventyConfig.setUseGitIgnore(false);
});

let { eleventyFiles: evf } = getEleventyFilesInstance(["liquid"], eleventyConfig);
evf._setEleventyIgnoreContent("!" + TemplatePath.absolutePath("test/stubs-403/_includes") + "/**");
evf.init(); // duplicate init

t.deepEqual(await evf.getFiles(), [
"./test/stubs-403/template.liquid",
// UPDATE: this was fixed in [email protected]
// This should be excluded from this list but is not because the ignore content used an absolutePath above.
// "./test/stubs-403/_includes/include.liquid",
]);
});

test("Workaround for Bad expected output, this indicates a bug upstream in a dependency. Input to 'src' and empty includes dir (issue #403, full paths in eleventyignore)", async (t) => {
let eleventyConfig = await getTemplateConfigInstanceCustomCallback({
input: "test/stubs-403",
output: "_site",
includes: "",
data: false,
}, function(eleventyConfig) {
eleventyConfig.setUseGitIgnore(false);
});

let { eleventyFiles: evf } = getEleventyFilesInstance(["liquid"], eleventyConfig);
evf._setEleventyIgnoreContent("!./test/stubs-403/_includes/**");
evf.init(); // duplicate init

t.deepEqual(await evf.getFiles(), ["./test/stubs-403/template.liquid"]);
});

Comment on lines -196 to -234
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed these tests as from what I gather they were related to a bug in an old fast-glob version. Down to add them back as a sanity check though.

test("Issue #403: all .eleventyignores should be relative paths not absolute paths", async (t) => {
let eleventyConfig = await getTemplateConfigInstanceCustomCallback({
input: "test/stubs-403",
Expand Down
Loading