-
-
Notifications
You must be signed in to change notification settings - Fork 493
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
Add support for passthrough with directory remapping #452
Conversation
@MadeByMike this issue is possibly relevant to you. |
Thanks @edwardhorsford it's pretty close to what is suggested there maybe we can build on this. |
👍 can't wait for this enhancement! |
Can you add tests for paths that escape the input or output directory, please? config.addPassthroughCopy({
"static": "..", // escapes output directory
"..": "." // escapes input directory
}); They should throw an error. Also, I’d prefer if no examples or tests use a leading forward slash as it usually represents the file system’s root directory. The tests don’t seem to do that, but you use it in your comments. I think it could be confusing and lead users to believe that they can target the root directory. And finally, what does the following do? I don’t understand why there would be a boolean. config.addPassthroughCopy({
"static": true,
}); |
@kleinfreund It's how the old API worked. I would not expect anyone to do this, but that's what happens behind the scenes when you do |
@MadeByMike Thank you so much for implementing this feature! Quick question regarding:
(emphasis mine) Could you explain that a bit more? Is this a path resolution issue with the way Node/JavaScript handles globbing? For reference, I'm coming from the Ruby world where code like
|
@jgarber623 yes exactly right! So imagine our key was the glob you mentioned and the output folder was
We need to make a decision about what this means because it is ambiguous and what we choose will impose some limitations on users. My assumption is to match all .scss files and move them to the However you could also assume that the user intends to copy all .scss files from If we match globs and then map files to a single directory, this means you only get the last file. If the match returns 2 files with the same name. Eg:
If it's not a glob we can recursively copy the directory.
So it's that 3rd option of being able to recursively copy a directory and filter the results by regex that is tricky. I suggest that it should not be in scope for this PR but maybe we make a new issue to resolve it immediately after merging this? |
@kleinfreund I wrote a test and updated code to catch files attempting to be written outside the site output directory but I can figure out how to silence the errors in the console. If you'd like to help with this I'd love feedback. @zachleat I'd love your input on this one too! |
I'm kinda of the opinion that anything that returns a promise should always return a promise and you reject rather than throw. This gives a better call stack in the error messages and makes it easier to catch on I dunno I'm sure there are people with better opinions on this and who can articulate it better. |
I’m not sure why the errors are still thrown. Something is broken. The example test in ava Assertions: test('throws', async t => {
await t.throwsAsync(async () => {
throw new TypeError('🦄');
}, {instanceOf: TypeError, message: '🦄'});
}); Another note: Some of your tests have duplicate entries in the And a question: What issue is commit 96fbd65 fixing? I don’t think we should normalize Windows path separators anywhere in the code. |
dot: true, | ||
junk: false, | ||
results: false | ||
return Promise.all(promises).catch(err => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the things that TemplatePassthrough write
did before was to return an unresolved promise. I believe this is waiting for the promises to resolve before returning, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After a bit more review it looks like this case only hits when you’re using glob paths right? It keeps the previous behavior with files or directory. I think that’s okay.
…eally know why but order is different and it matters
…. Pearent should catch
4ad976e
to
acd9763
Compare
Hey! I fixed the conflicts here and am going to merge this but as a follow up I am opening an issue for the last remaining piece of feedback here. #615 |
OMG OMG MERGED 😂😂😂 |
Shipping with the next version! |
Resolves #18. Many thanks to 11ty/eleventy#452.
Modifies the
addPassthroughCopy
function so that it accepts a 2nd param that allows you to remap the output directory.This means you can do something like the following:
This will map all files and folders to the root directory.
After reading this issue I've updated it so that you can use globs. This will map all js files to the root directory:
Because of the way that globs work, it's not possible to retain nested directory structures and all matched files will be output to the specified directory. For example, this will find all file in nested folders named
js
and will output them to the 'js` folder in the root:This means if there are multiple
index.js
files in these folders they will be overwritten by the last copy.To get around this and keep the option to recursively copy directories if the inputPath is not a glob and matches a directory, the directory will be recursively copied to the output path. For example, here all files in
src/static/js
will be copied to thejs
folder in root including any all sub directories:For backward compatibility passing
true
also works, and the output would be resolved tostatic/js
:Not passing an object has the same result: