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

Provide the watcher on the plugin context #2261

Merged
merged 3 commits into from
Jun 16, 2018
Merged

Conversation

guybedford
Copy link
Contributor

This allows for plugins that can track the watcher lifecycle like notifiers. Resolves #2117.

let curWatcher: Watcher;
export function setWatcher(watcher: Watcher) {
curWatcher = watcher;
}
Copy link
Contributor Author

@guybedford guybedford Jun 11, 2018

Choose a reason for hiding this comment

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

This indirection is done so that setting the watcher is a private API and not exposed.

Alternatively the main rollup function could just be wrapped.

Copy link
Member

Choose a reason for hiding this comment

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

I thought about this but yes, this seems like a reasonable approach.

Copy link
Member

Choose a reason for hiding this comment

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

On a totally unrelated note, I wonder why the diff in Github looks so messy. IntelliJ is able to create a nice and focused diff for this file. I hope Github can improve this at some point...

Copy link
Contributor Author

@guybedford guybedford Jun 15, 2018

Choose a reason for hiding this comment

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

Just discovered that if you select "Diff settings -> Hide Whitespace Changes -> Apply and Reload" this gets cleaned up nicely!

Copy link
Member

Choose a reason for hiding this comment

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

Oh you are right, thanks!

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

Looks nice! I hope in the future we could also be able to provide more feedback APIs to enable e.g. more fine-grained progress visualization plugins for the actual bundling process. But I would hope for an external developer to step forward first to ask for this to be able to involve more people here.

'END',
() => {
assert.equal(run('../_tmp/output/bundle.js'), 43);
watcher.close();
Copy link
Member

Choose a reason for hiding this comment

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

I would also like to check the events again here to see our hook still works.


export * from './rollup/index';
export * from './watch/index';

Copy link
Member

Choose a reason for hiding this comment

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

Interesting. We were doing wild things here. So as long as nobody imported the classes in watch/index.js I guess we should be fine here. Nice catch!

return new Watcher(configs);
const watcher = new Watcher(configs);

return watcher;
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for splitting this up?

let curWatcher: Watcher;
export function setWatcher(watcher: Watcher) {
curWatcher = watcher;
}
Copy link
Member

Choose a reason for hiding this comment

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

I thought about this but yes, this seems like a reasonable approach.

@@ -1,12 +1,12 @@
// Return the first non-null or -undefined result from an array of
// maybe-sync, maybe-promise-returning functions
export default function first<T>(
export default function first<T, Context>(
Copy link
Member

Choose a reason for hiding this comment

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

Not 100% happy about this as this new context handling is not too obvious from the function name. What about making the context and explicit parameter of this function and not add the context if we do not pass the parameter? In that case, I would be ok with keeping the function name as it is.

That would make the comment above true again. Otherwise, this function is now very specific to certain usages and may have unintended side-effects.

Copy link
Member

Choose a reason for hiding this comment

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

Also, why did you perform this change? It touches quite a bit of existing functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function is only used for calling plugin hooks. And all plugin hooks now need context to be passed through it. It seems like a natural extension to me that the caller should set the context for the individual functions, as if the caller calls all functions as a single function.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe. But it also sets the context if the caller does not want to set the context. But I guess this doesn't matter. But then, firstSync should be changed as well for symmetry.

let curWatcher: Watcher;
export function setWatcher(watcher: Watcher) {
curWatcher = watcher;
}
Copy link
Member

Choose a reason for hiding this comment

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

On a totally unrelated note, I wonder why the diff in Github looks so messy. IntelliJ is able to create a nice and focused diff for this file. I hope Github can improve this at some point...

@lukastaegert lukastaegert added this to In progress in Release 1.0.0 via automation Jun 16, 2018
@lukastaegert lukastaegert added this to the 1.0.0 milestone Jun 16, 2018
@lukastaegert lukastaegert moved this from In progress to In Review in Release 1.0.0 Jun 16, 2018
@lukastaegert lukastaegert merged commit 4c73906 into master Jun 16, 2018
Release 1.0.0 automation moved this from In Review to Done Jun 16, 2018
@lukastaegert lukastaegert deleted the watcher-plugin-context branch June 16, 2018 18:37
@lukastaegert lukastaegert modified the milestones: 1.0.0, 0.61.0 Jun 20, 2018
@lukastaegert
Copy link
Member

It appears this PR has broken the memory leak test. Will try to find out if this can be fixed easily so that master can be released.

@lukastaegert
Copy link
Member

Found and pushed a fix for the leak: 2361e3d#diff-c5fd8e65630bd641bf07130346ee8778R173

(Sorry about the diff, it's mostly changed indentation) Not sure what the actual cause way. I reverted the rather cosmetic change of replacing the try-catch with running the initial code inside a promise.

calebeby pushed a commit to Pigmice2733/scouting-frontend that referenced this pull request Jun 21, 2018
This Pull Request updates dependency [rollup](https://github.com/rollup/rollup) from `v0.60.7` to `v0.61.1`



<details>
<summary>Release Notes</summary>

### [`v0.61.1`](https://github.com/rollup/rollup/blob/master/CHANGELOG.md#&#8203;0611)
[Compare Source](rollup/rollup@v0.61.0...697f36d)
*2018-06-21*
* Do not try to deconflict "undefined" ([#&#8203;2291](`rollup/rollup#2291))
* Properly track values for loop interator declarations and reassigned namespaces, add smoke test ([#&#8203;2292](`rollup/rollup#2292))

---

### [`v0.61.0`](https://github.com/rollup/rollup/blob/master/CHANGELOG.md#&#8203;0610)
[Compare Source](rollup/rollup@v0.60.7...v0.61.0)
*2018-06-20*
* Declare file dependencies via transform plugin hooks ([#&#8203;2259](`rollup/rollup#2259))
* Handle undefined values when evaluating conditionals ([#&#8203;2264](`rollup/rollup#2264))
* Handle known undefined properties when evaluating conditionals ([#&#8203;2265](`rollup/rollup#2265))
* Access watch events via the plugin context ([#&#8203;2261](`rollup/rollup#2261))
* Add option to suppress `__esModule` flag in output ([#&#8203;2287](`rollup/rollup#2287))
* Fix issue when re-declaring variables, track reassignments in more cases ([#&#8203;2279](`rollup/rollup#2279))
* Add VSCode debug settings ([#&#8203;2276](`rollup/rollup#2276))

---

</details>




---

This PR has been generated by [Renovate Bot](https://renovatebot.com).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Release 1.0.0
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants