From cc70a2ad0afac133e5eafa29f35a0423e59244f8 Mon Sep 17 00:00:00 2001 From: zodern Date: Thu, 14 Jan 2021 16:54:45 -0600 Subject: [PATCH] Move hot api to hot-module-replacement package --- packages/hot-module-replacement/hot-api.js | 45 ++++++++++++++++++++++ packages/hot-module-replacement/package.js | 5 ++- packages/modules-runtime-hot/modern.js | 45 ---------------------- 3 files changed, 49 insertions(+), 46 deletions(-) create mode 100644 packages/hot-module-replacement/hot-api.js diff --git a/packages/hot-module-replacement/hot-api.js b/packages/hot-module-replacement/hot-api.js new file mode 100644 index 0000000000..98010f4580 --- /dev/null +++ b/packages/hot-module-replacement/hot-api.js @@ -0,0 +1,45 @@ +const meteorInstall = Package['modules-runtime'].meteorInstall; + +Object.defineProperty(meteorInstall.Module.prototype, "hot", { + get: function () { + if (!this._hotState) { + this._hotState = { + // if null, whether it accepts depends on all of the modules that + // required it + _hotAccepts: null, + _disposeHandlers: [], + data: null + }; + } + + let hotState = this._hotState; + let module = this; + + return { + accept() { + if (arguments.length > 0) { + console.warn('hot.accept does not support any arguments.'); + } + hotState._hotAccepts = true; + }, + decline() { + if (arguments.length > 0) { + throw new Error('hot.decline does not support any arguments.'); + } + + hotState._hotAccepts = false; + }, + dispose(cb) { + hotState._disposeHandlers.push(cb); + }, + onRequire(callbacks) { + return module._onRequire(callbacks); + }, + _canAcceptUpdate() { + return hotState._hotAccepts; + }, + data: hotState.data + } + }, + set() { } +}); diff --git a/packages/hot-module-replacement/package.js b/packages/hot-module-replacement/package.js index 398a74a36f..851aced13f 100644 --- a/packages/hot-module-replacement/package.js +++ b/packages/hot-module-replacement/package.js @@ -10,7 +10,10 @@ Package.onUse(function (api) { api.use('modules'); api.use('meteor'); api.imply('modules-runtime-hot@0.12.0'); - api.addFiles('./client.js', 'client'); + api.addFiles([ + './hot-api.js', + './client.js' + ], 'client'); api.addFiles('./server.js', 'server'); }); diff --git a/packages/modules-runtime-hot/modern.js b/packages/modules-runtime-hot/modern.js index ac803c635f..2445856d2d 100644 --- a/packages/modules-runtime-hot/modern.js +++ b/packages/modules-runtime-hot/modern.js @@ -20,51 +20,6 @@ meteorInstall = makeInstaller({ let Module = Package['modules-runtime'].meteorInstall.Module; meteorInstall.Module.prototype.link = Module.prototype.link; -Object.defineProperty(meteorInstall.Module.prototype, "hot", { - get: function () { - if (!this._hotState) { - this._hotState = { - // if null, whether it accepts depends on all of the modules that - // required it - _hotAccepts: null, - _disposeHandlers: [], - data: null - }; - } - - let hotState = this._hotState; - let module = this; - - return { - accept() { - if (arguments.length > 0) { - // TODO: support same options as webpack - console.warn('hot.accept does not support any arguments.'); - } - hotState._hotAccepts = true; - }, - decline() { - if (arguments.length > 0) { - throw new Error('hot.decline does not support any arguments.'); - } - - hotState._hotAccepts = false; - }, - dispose(cb) { - hotState._disposeHandlers.push(cb); - }, - onRequire(callbacks) { - return module._onRequire(callbacks); - }, - _canAcceptUpdate() { - return hotState._hotAccepts; - }, - data: hotState.data - } - }, - set() {} -}); - // This package should be running after modules-runtime but before modules. // We want modules to use our patched meteorInstall Package['modules-runtime'].meteorInstall = meteorInstall;