-
Notifications
You must be signed in to change notification settings - Fork 55
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
Watch copied files #27
Conversation
@@ -40,7 +40,7 @@ export default function copy(options = {}) { | |||
|
|||
return { | |||
name: 'copy', | |||
[hook]: async () => { | |||
async [hook]() { |
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.
This was necessary because the this
keyword was not available with the unbound arrow function syntax.
See this issue for more details: rollup/rollup#1518 (comment)
Codecov Report
@@ Coverage Diff @@
## master #27 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 1 1
Lines 36 38 +2
Branches 12 12
=====================================
+ Hits 36 38 +2
Continue to review full report at Codecov.
|
@@ -88,6 +88,10 @@ export default function copy(options = {}) { | |||
} | |||
|
|||
for (const { src, dest } of copyTargets) { | |||
try { | |||
this.addWatchFile(src) | |||
} catch { /* Cannot call addWatchFile after the build has finished. */ } |
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.
The addWatchFile
method cannot be used after the build has finished, so is not available in all hooks. Rather than hard-coding a list of valid hooks that might change, I figured I'd just try/catch it. When it throws an error, it has the error message seen in the comment
@@ -228,6 +228,93 @@ describe('Copy', () => { | |||
expect(await fs.pathExists('dist/scss-multiple/nested-renamed')).toBe(true) | |||
expect(await fs.pathExists('dist/scss-multiple/nested-renamed/scss-3.scss')).toBe(true) | |||
}) | |||
|
|||
test('Watches copied files in pre-build hook', async () => { |
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.
I based these off of the copyOnce
test
@blake-mealey hey, thanks for the PR. The question I have - when you add files using |
From the documentation: https://rollupjs.org/guide/en/#plugin-context
|
@blake-mealey the reason why I asked is because I've also found I've considered another solution using watcher, something like cheap-watch, but didn't look/try it or alternatives. |
Ahh, I see. So you just want to re-copy the individual file? Makes sense |
@blake-mealey yes, I see no reason in triggering a rebuild when non-dependent file is changed/removed. I think that currently there is no built-in way to add files to watcher with a function to trigger when they are changed/deleted w/o rebuild so another separate watcher should be probably used or smth. It might be a good idea to search for or open an issue in rollup to get an advice or suggestion about such watcher usage, they are usually kind and responsive :) |
@vladshcherbin yeah that makes total sense and I'm happy to close this. I would still really like this feature so I'll look into using a watcher library. I took a quick look and didn't find any issues on the topic. It's easy to check if rollup's watch mode is enabled ( Just from looking briefly at the one you linked (cheap-watch) vs what seems to be a very popular library (chokidar), here are my thoughts:
Given all that, I'd like to try a chokidar approach, being enabled based on |
@blake-mealey yep, The reason I mentioned |
@blake-mealey so all in all, I believe your idea is nice and should work fine, I planned to do the same thing one day 👍 |
Great!
…On Sun., Oct. 27, 2019, 10:17 p.m. Vlad Shcherbin, ***@***.***> wrote:
@blake-mealey <https://github.com/blake-mealey> so all in all, I believe
your idea is nice and should work fine, I planned to do the same thing one
day 👍
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#27?email_source=notifications&email_token=AASR46U7BP24OCHLOG52GF3QQZRWLA5CNFSM4JFVA5RKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECLUM3Y#issuecomment-546784879>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AASR46WGJUXELUCHLE4ZAC3QQZRWLANCNFSM4JFVA5RA>
.
|
Re: #5 (Support rollup's watch mode)
This adds all files that are copied directly to Rollup's watch list.