refactor: implementationChanged
This commit is contained in:
parent
52cf407f9e
commit
71d6674de2
|
@ -533,6 +533,21 @@ class Flecks {
|
|||
return get(this.config, path, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether an updated module changed its hook implementation.
|
||||
*
|
||||
* @param {*} fleck The fleck implementing the hook.
|
||||
* @param {*} hook The hook.
|
||||
* @param {*} M The updated module.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
implementationChanged(fleck, hook, M) {
|
||||
return (
|
||||
(this.fleckImplementation(fleck, hook) || M.hooks?.[hook])
|
||||
&& this.fleckImplementation(fleck, hook)?.toString() !== M.hooks?.[hook]?.toString()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interpolate a string with flecks configuration values.
|
||||
* @param {string} string
|
||||
|
|
|
@ -8,19 +8,12 @@ const {
|
|||
|
||||
export const hooks = {
|
||||
'@flecks/core.hmr': (path, M, flecks) => {
|
||||
if (
|
||||
flecks.fleckImplementation(path, '@flecks/server.up')
|
||||
|| M.hooks?.['@flecks/server.up']) {
|
||||
if (
|
||||
flecks.fleckImplementation(path, '@flecks/server.up')?.toString()
|
||||
!== M.hooks?.['@flecks/server.up']?.toString()
|
||||
) {
|
||||
if (cluster.isWorker) {
|
||||
cluster.worker.disconnect();
|
||||
const error = new Error('@flecks/server.up implementation changed!');
|
||||
error.stack = '';
|
||||
throw error;
|
||||
}
|
||||
if (flecks.implementationChanged(path, '@flecks/server.up', M)) {
|
||||
if (cluster.isWorker) {
|
||||
cluster.worker.disconnect();
|
||||
const error = new Error('@flecks/server.up implementation changed!');
|
||||
error.stack = '';
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,14 +1,7 @@
|
|||
export const hooks = {
|
||||
'@flecks/core.hmr': (path, M, flecks) => {
|
||||
if (
|
||||
flecks.fleckImplementation(path, '@flecks/web/client.up')
|
||||
|| M.hooks?.['@flecks/web/client.up']) {
|
||||
if (
|
||||
flecks.fleckImplementation(path, '@flecks/web/client.up')?.toString()
|
||||
!== M.hooks?.['@flecks/web/client.up']?.toString()
|
||||
) {
|
||||
throw new Error('@flecks/web/client.up implementation changed!');
|
||||
}
|
||||
if (flecks.implementationChanged(path, '@flecks/web/client.up', M)) {
|
||||
throw new Error('@flecks/web/client.up implementation changed!');
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user