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
Plugins are not informed of shutdown and can leave resources dangling (e.g. typescript plugin) #3821
Comments
@lukastaegert should we move this one to the main repo? |
Makes sense. |
So it sounds like we need a new plugin hook here, or extend the |
I think it should be extended even more - to support watcher hooks generally (and watch-only plugins, may be?..) Currently I trying to make true incremental building for rollup (with preserveModules and disabled treeshaking, at least). It seems what such plugin can be made purely in user-land - but only if it will know which files is triggers rebuild. So, basically, for watcher plugin we should just add hooks in public methods of
It can be done in 50 lines of code, I think. @lukastaegert how you about to accept such PR? |
Simple config example for incremental plugin: import incremental from 'rollup-plugin-incremental'
const inc = incremental({})
export default {
input: 'src/main.js',
treeshake: false,
output: {
dir: 'dist',
format: 'es',
preserveModules: true,
preserveModulesRoot: 'src',
},
watcher: {
plugins: [
inc.getWatcherPlugin({}),
]
},
plugins: [
inc,
]
} |
So, this is definitely a good idea, I wondered about these things myself, but there was always little time... So, thoughts:
|
Oh, don't mind about watchChange. Yep, i think with it all is totally possible to implement without a watcher plugins. But watcher is coupled with a cache, and to modify it watcher events should be accessible inside of plugins. |
I can throw my support behind this as well |
Ok, but do you need any additional events besides |
Ok, after implementing incremental plugin (https://github.com/mprt-org/rollup-plugin-incremental), i've see that
So I think there should be such patch for types: --- src/rollup/types.d.ts (revision 7d42c4d43a0aaf2db73fef93c136c35af09cf19b)
+++ src/rollup/types.d.ts (date 1603808293818)
@@ -195,6 +195,7 @@
getFileName: (fileReferenceId: string) => string;
getModuleIds: () => IterableIterator<string>;
getModuleInfo: GetModuleInfo;
+ getWatchFiles: () => string[];
/** @deprecated Use `this.resolve` instead */
isExternal: IsExternal;
/** @deprecated Use `this.getModuleIds` instead */
@@ -345,13 +346,14 @@
export interface PluginHooks extends OutputPluginHooks {
buildEnd: (this: PluginContext, err?: Error) => Promise<void> | void;
buildStart: (this: PluginContext, options: NormalizedInputOptions) => Promise<void> | void;
+ closeWatcher: (this: PluginContext) => void;
load: LoadHook;
moduleParsed: ModuleParsedHook;
options: (this: MinimalPluginContext, options: InputOptions) => InputOptions | null | undefined;
resolveDynamicImport: ResolveDynamicImportHook;
resolveId: ResolveIdHook;
transform: TransformHook;
- watchChange: (id: string) => void;
+ watchChange: (this: PluginContext, id: string, isDeleted: boolean) => void;
}
interface OutputPluginHooks { |
Makes sense. With regard to the
Because if you follow the code path, this is triggered by the So in general I would be very open to these changes, but there is some work involved (most notably at the moment, the watcher code immediately forgets about the type of event). |
Expected Behavior
When calling
close()
on a watcher created viawatch()
, it should also tell all used plugins that shutdown is imminent so that those plugins can close any resources they have allocated. Ifclose()
is called on a watcher, and there are no other open resources,node
should exit.Actual Behavior
Plugins are never informed of shutdown, the PluginHooks do not include a shutdown/close hook, and so the plugins are completely unaware that shutdown has been initiated. Plugins which have allocated internal resources, like for example the watcher used by the TypeScript plugin are not cleaned up. If using the TypeScript plugin, the watcher it has created internally is never removed, and so it is left running. As a result,
node
does not exit and hangs forever.This is the reproduction in the linked repo, this script does not exit after printing
closing
. If the TypeScript plugin is removed it exits as normal.The text was updated successfully, but these errors were encountered: