diff --git a/package.json b/package.json index 571067b28..7cba51f93 100755 --- a/package.json +++ b/package.json @@ -135,7 +135,6 @@ "micromatch": "^4.0.7", "minimist": "^1.2.8", "moo": "^0.5.2", - "multimatch": "^7.0.0", "node-retrieve-globals": "^6.0.0", "normalize-path": "^3.0.0", "nunjucks": "^3.2.4", diff --git a/src/EleventyServe.js b/src/EleventyServe.js index 931743eb9..fbaec98f1 100644 --- a/src/EleventyServe.js +++ b/src/EleventyServe.js @@ -1,7 +1,8 @@ import assert from "node:assert"; + +import debugUtil from "debug"; import { Merge, DeepCopy, TemplatePath } from "@11ty/eleventy-utils"; import EleventyDevServer from "@11ty/eleventy-dev-server"; -import debugUtil from "debug"; import EleventyBaseError from "./Errors/EleventyBaseError.js"; import ConsoleLogger from "./Util/ConsoleLogger.js"; @@ -9,6 +10,7 @@ import PathPrefixer from "./Util/PathPrefixer.js"; import checkPassthroughCopyBehavior from "./Util/PassthroughCopyBehaviorCheck.js"; import { getModulePackageJson } from "./Util/ImportJsonSync.js"; import { EleventyImport } from "./Util/Require.js"; +import { isGlobMatch } from "./Util/GlobMatcher.js"; const debug = debugUtil("Eleventy:EleventyServe"); @@ -271,6 +273,10 @@ class EleventyServe { } } + isEmulatedPassthroughCopyMatch(filepath) { + return isGlobMatch(filepath, this._watchedFiles); + } + hasOptionsChanged() { try { assert.deepStrictEqual(this.config.serverOptions, this._savedConfigOptions); diff --git a/src/FileSystemSearch.js b/src/FileSystemSearch.js index c18afc21e..6cccd367f 100644 --- a/src/FileSystemSearch.js +++ b/src/FileSystemSearch.js @@ -1,8 +1,9 @@ import fastglob from "fast-glob"; -import micromatch from "micromatch"; import { TemplatePath } from "@11ty/eleventy-utils"; import debugUtil from "debug"; +import { isGlobMatch } from "./Util/GlobMatcher.js"; + const debug = debugUtil("Eleventy:FastGlobManager"); class FileSystemSearch { @@ -80,11 +81,9 @@ class FileSystemSearch { for (let key in this.inputs) { let { input, options } = this.inputs[key]; if ( - micromatch([path], input, { - dot: true, - nocase: true, // insensitive + isGlobMatch(path, input, { ignore: options.ignore, - }).length > 0 + }) ) { this.outputs[key][setOperation](normalized); } diff --git a/src/TemplateCollection.js b/src/TemplateCollection.js index cb32a9105..6b75b2fe6 100755 --- a/src/TemplateCollection.js +++ b/src/TemplateCollection.js @@ -1,8 +1,8 @@ -import multimatch from "multimatch"; import { TemplatePath } from "@11ty/eleventy-utils"; -import Sortable from "./Util/Objects/Sortable.js"; import TemplateData from "./Data/TemplateData.js"; +import Sortable from "./Util/Objects/Sortable.js"; +import { isGlobMatch } from "./Util/GlobMatcher.js"; class TemplateCollection extends Sortable { constructor() { @@ -48,11 +48,7 @@ class TemplateCollection extends Sortable { } let filtered = this.getAllSorted().filter((item) => { - if (multimatch([item.inputPath], globs).length) { - return true; - } - - return false; + return isGlobMatch(item.inputPath, globs); }); this._dirty = false; this._filteredByGlobsCache.set(key, [...filtered]); diff --git a/src/TemplatePassthroughManager.js b/src/TemplatePassthroughManager.js index 078a25748..563c33d1e 100644 --- a/src/TemplatePassthroughManager.js +++ b/src/TemplatePassthroughManager.js @@ -1,4 +1,3 @@ -import multimatch from "multimatch"; import isGlob from "is-glob"; import { TemplatePath } from "@11ty/eleventy-utils"; import debugUtil from "debug"; @@ -7,6 +6,7 @@ import EleventyExtensionMap from "./EleventyExtensionMap.js"; import EleventyBaseError from "./Errors/EleventyBaseError.js"; import TemplatePassthrough from "./TemplatePassthrough.js"; import checkPassthroughCopyBehavior from "./Util/PassthroughCopyBehaviorCheck.js"; +import { isGlobMatch } from "./Util/GlobMatcher.js"; const debug = debugUtil("Eleventy:TemplatePassthroughManager"); const debugDev = debugUtil("Dev:Eleventy:TemplatePassthroughManager"); @@ -213,11 +213,7 @@ class TemplatePassthroughManager { if (TemplatePath.startsWithSubPath(changedFile, path.inputPath)) { return path; } - if ( - changedFile && - isGlob(path.inputPath) && - multimatch([changedFile], [path.inputPath]).length - ) { + if (changedFile && isGlob(path.inputPath) && isGlobMatch(changedFile, [path.inputPath])) { return path; } } diff --git a/src/Util/GlobMatcher.js b/src/Util/GlobMatcher.js new file mode 100644 index 000000000..8af08797f --- /dev/null +++ b/src/Util/GlobMatcher.js @@ -0,0 +1,21 @@ +import micromatch from "micromatch"; +import { TemplatePath } from "@11ty/eleventy-utils"; + +function isGlobMatch(filepath, globs = [], options = undefined) { + if (!filepath || !Array.isArray(globs) || globs.length === 0) { + return false; + } + + let inputPath = TemplatePath.stripLeadingDotSlash(filepath); + let opts = Object.assign( + { + dot: true, + nocase: true, // insensitive + }, + options, + ); + + return micromatch.isMatch(inputPath, globs, opts); +} + +export { isGlobMatch }; diff --git a/test/TemplateCollectionTest.js b/test/TemplateCollectionTest.js index 443a1b4c9..8558794da 100644 --- a/test/TemplateCollectionTest.js +++ b/test/TemplateCollectionTest.js @@ -1,6 +1,6 @@ import test from "ava"; -import multimatch from "multimatch"; +import { isGlobMatch } from "../src/Util/GlobMatcher.js"; import Collection from "../src/TemplateCollection.js"; import Sortable from "../src/Util/Objects/Sortable.js"; @@ -257,26 +257,27 @@ test("partial match on tag string, issue 95", async (t) => { t.is(posts.length, 1); }); -test("multimatch assumptions, issue #127", async (t) => { - t.deepEqual( - multimatch(["src/bookmarks/test.md"], "**/+(bookmarks|posts|screencasts)/**/!(index)*.md"), - ["src/bookmarks/test.md"], +// Swapped to micromatch in 3.0.0-alpha.17 +test("micromatch assumptions, issue #127", async (t) => { + function isMatch(filepath, globs) { + return isGlobMatch(filepath, globs); + } + t.true( + isMatch("src/bookmarks/test.md", ["**/+(bookmarks|posts|screencasts)/**/!(index)*.md"]), ); - t.deepEqual( - multimatch(["./src/bookmarks/test.md"], "./**/+(bookmarks|posts|screencasts)/**/!(index)*.md"), - ["./src/bookmarks/test.md"], + + t.true( + isMatch("./src/bookmarks/test.md", ["./**/+(bookmarks|posts|screencasts)/**/!(index)*.md"]), ); let c = new Collection(); let globs = c.getGlobs("**/+(bookmarks|posts|screencasts)/**/!(index)*.md"); t.deepEqual(globs, ["./**/+(bookmarks|posts|screencasts)/**/!(index)*.md"]); - t.deepEqual(multimatch(["./src/bookmarks/test.md"], globs), ["./src/bookmarks/test.md"]); - t.deepEqual(multimatch(["./src/bookmarks/index.md"], globs), []); - t.deepEqual(multimatch(["./src/bookmarks/index2.md"], globs), []); - t.deepEqual(multimatch(["./src/_content/bookmarks/2018-03-27-git-message.md"], globs), [ - "./src/_content/bookmarks/2018-03-27-git-message.md", - ]); + t.true(isMatch("./src/bookmarks/test.md", globs)); + t.false(isMatch("./src/bookmarks/index.md", globs)); + t.false(isMatch("./src/bookmarks/index2.md", globs)); + t.true(isMatch("./src/_content/bookmarks/2018-03-27-git-message.md", globs)); }); test("Sort in place (issue #352)", async (t) => {