eleventy icon indicating copy to clipboard operation
eleventy copied to clipboard

Possible bug in addPassthroughCopy, but maybe a doc issue

Open cfjedimaster opened this issue 3 years ago • 4 comments

Describe the bug

I'm not sure if this is a bug, as it seems new, but it may also be a doc issue. I built an incredibly simple site:

/index.liquid /random.jpg /.eleventy.js

My .eleventy.js was:

module.exports = function(eleventyConfig) {

	eleventyConfig.addPassthroughCopy("**/*.jpg");

};

I was doing this to test something else. When I ran this, it worked just fine, copying the result to /_site.

However, if I ran it a second time, I got:

[11ty] Error with passthrough copy: (more in DEBUG output)
[11ty] 1. Having trouble copying './**/*.jpg' (via TemplatePassthroughManagerCopyError)
[11ty] 2. Error copying passthrough files: ENOENT: no such file or directory, open '_site/Cobra-Commander.jpg' (via TemplatePassthroughError)
[11ty] 3. ENOENT: no such file or directory, open '_site/Cobra-Commander.jpg' (via Error)

I noticed that my _site folder now also had a _site folder:

image

It's almost like the glob is picking up stuff in _site, which... I mean I guess the glob would match stuff there, but I feel like in the past Eleventy didn't have this issue. I also assume if I were using directories like so:

/_site /src /.eleventy.js

Where I told Eleventy to use src as the input folder, it wouldn't have this same issue.

So... is this a bug, or is it expected, and if expected, maybe the docs for addPassthroughCopy should use a 'safer' glob as an example?

  • Eleventy Version: 1.0.1

cfjedimaster avatar Jun 29 '22 17:06 cfjedimaster

~~Yeah, probably just missing a .gitignore file? Though honestly my perspective on the reliance on .gitignore here may be shifting a bit after reading through #857 again.~~ Disregard this comment

zachleat avatar Jun 30 '22 19:06 zachleat

Just diving in a little bit deeper here I think the confusion is probably that globs passed to addPassthroughCopy bypass ignores!

Here are the fast-glob that bypass ignores worth looking into here:

  • https://github.com/11ty/eleventy/blob/8674f34600852fa2d1305deb012420d984a691f8/src/TemplatePassthrough.js#L110
  • https://github.com/11ty/eleventy/blob/8674f34600852fa2d1305deb012420d984a691f8/src/TemplateData.js#L231
  • https://github.com/11ty/eleventy/blob/8674f34600852fa2d1305deb012420d984a691f8/src/Engines/TemplateEngine.js#L122

zachleat avatar Jun 30 '22 22:06 zachleat

Now, I’m not saying it shouldn’t bypass ignores but just that behavior is not obvious—especially given that I’m guessing this version of passthrough copy does obey ignores https://www.11ty.dev/docs/copy/#passthrough-by-file-extension and maybe even non-glob arguments to addPassthroughCopy but I haven’t confirmed that yet

zachleat avatar Jun 30 '22 22:06 zachleat

Ran into this, too, I bypassed this by ignoring _site in the glob pattern.

eleventyConfig.addPassthroughCopy("{,!(_site)/**/}*.jpg");

SuaYoo avatar Sep 06 '22 15:09 SuaYoo

Going to coalesce over at #1134 which is a duplicate of this one—please subscribe over there!

zachleat avatar Nov 18 '22 18:11 zachleat