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