@joystick.js/cli-canary 0.0.0-canary.607 → 0.0.0-canary.609
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
import _ from"query-string";import{WebSocketServer as i}from"ws";import
|
|
1
|
+
import _ from"query-string";import{WebSocketServer as i}from"ws";import N from"../generate_id.js";import g from"./get_translations.js";process.title="joystick_hmr";var u=(()=>{const r=new i({port:parseInt(process.env.PORT,10)+1,path:"/_joystick/hmr"});process.on("message",async c=>{const e=JSON.parse(c);if(console.log("message callback",{connections:process.HMR_CONNECTIONS,connections_type:typeof process.HMR_CONNECTIONS,parsed_message:e}),typeof process.HMR_CONNECTIONS=="object"&&e?.type){const o=Object.values(process.HMR_CONNECTIONS);for(let n=0;n<o?.length;n+=1){const s=o[n];if(s?.connection?.send){if(e?.type==="BUILD_ERROR")return s.connection.send(JSON.stringify({type:"BUILD_ERROR"}));if(e?.type==="FILE_CHANGE")return s.connection.send(JSON.stringify({type:"FILE_CHANGE",settings:e?.settings?{global:e?.settings?.global,public:e?.settings?.public}:null,i18n:e?.i18n_change?await g("./.joystick/build",s?.page_component_path,{headers:{"accept-language":s?.browser_language},context:{user:{language:s?.user_language}}}):null,index_html_changed:e?.index_html_change,index_css_changed:e?.index_css_change,index_client_changed:e?.index_client_change}))}}}}),r.on("connection",function(e,o={}){const n=N(16),[s,a]=o?.url?.split("?"),t=_.parse(a);console.log("ADD CONNECTION",n),process.HMR_CONNECTIONS={...process.HMR_CONNECTIONS||{},[n]:{connection:e,browser_language:t?.browser_language,user_language:t?.user_language,page_component_path:t?.page_component_path}},console.log("connection callback",process.HMR_CONNECTIONS),Object.keys(process.HMR_CONNECTIONS||{})?.length>0&&process.send({type:"HAS_HMR_CONNECTIONS"}),e.on("message",p=>{JSON.parse(p)?.type==="HMR_UPDATE_COMPLETE"&&process.send({type:"HMR_UPDATE_COMPLETE"})}),e.on("close",()=>{process.HMR_CONNECTIONS[n]&&(delete process.HMR_CONNECTIONS[n],console.log("DELETE CONNECTION",n),Object.keys(process.HMR_CONNECTIONS||{})?.length===0&&process.send({type:"HAS_NO_HMR_CONNECTIONS"}))})})})();export{u as default};
|
package/package.json
CHANGED
|
@@ -64,6 +64,8 @@ export default (() => {
|
|
|
64
64
|
const [_path, params] = connection_request?.url?.split("?");
|
|
65
65
|
const connection_params = queryString.parse(params);
|
|
66
66
|
|
|
67
|
+
console.log('ADD CONNECTION', connection_id);
|
|
68
|
+
|
|
67
69
|
process.HMR_CONNECTIONS = {
|
|
68
70
|
...(process.HMR_CONNECTIONS || {}),
|
|
69
71
|
[connection_id]: {
|
|
@@ -92,6 +94,8 @@ export default (() => {
|
|
|
92
94
|
if (process.HMR_CONNECTIONS[connection_id]) {
|
|
93
95
|
delete process.HMR_CONNECTIONS[connection_id];
|
|
94
96
|
|
|
97
|
+
console.log('DELETE CONNECTION', connection_id);
|
|
98
|
+
|
|
95
99
|
if (Object.keys(process.HMR_CONNECTIONS || {})?.length === 0) {
|
|
96
100
|
process.send({ type: "HAS_NO_HMR_CONNECTIONS" });
|
|
97
101
|
}
|