@joystick.js/cli-canary 0.0.0-canary.582 → 0.0.0-canary.584
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
|
|
1
|
+
import p from"query-string";import{WebSocketServer as g}from"ws";import N from"../generate_id.js";import l from"./get_translations.js";process.title="joystick_hmr";var h=(()=>{const r=new g({port:parseInt(process.env.PORT,10)+1,path:"/_joystick/hmr"});process.on("message",async a=>{const e=JSON.parse(a);if(typeof process.HMR_CONNECTIONS=="object"&&e?.type){const t=Object.values(process.HMR_CONNECTIONS);for(let s=0;s<t?.length;s+=1){const n=t[s];if(n?.connection?.send)switch(e?.type){case"BUILD_ERROR":return n.connection.send(JSON.stringify({type:"BUILD_ERROR"}));case"FILE_CHANGE":default:return n.connection.send(JSON.stringify({type:"FILE_CHANGE",settings:e?.settings?{global:e?.settings?.global,public:e?.settings?.public}:null,i18n:e?.i18n_change?await l("./.joystick/build",n?.page_component_path,{headers:{"accept-language":n?.browser_language},context:{user:{language:n?.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,t={}){const s=N(16),[n,_]=t?.url?.split("?"),o=p.parse(_);process.HMR_CONNECTIONS={...process.HMR_CONNECTIONS||{},[s]:{connection:e,browser_language:o?.browser_language,user_language:o?.user_language,page_component_path:o?.page_component_path,watchlist:[]}},Object.keys(process.HMR_CONNECTIONS||{})?.length>0&&process.send({type:"HAS_HMR_CONNECTIONS"}),e.on("message",i=>{const c=JSON.parse(i);c?.type==="HMR_UPDATE_COMPLETE"&&process.send({type:"HMR_UPDATE_COMPLETE"}),c?.type==="HMR_WATCHLIST"&&process.HMR_CONNECTIONS[s]?.watchlist?.push(...c?.tags||[])}),e.on("close",()=>{process.HMR_CONNECTIONS[s]&&(delete process.HMR_CONNECTIONS[s],Object.keys(process.HMR_CONNECTIONS||{})?.length===0&&process.send({type:"HAS_NO_HMR_CONNECTIONS"}))})})})();export{h as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import f from"chokidar";import h from"fs";import{dirname as m}from"path";import
|
|
1
|
+
import f from"chokidar";import h from"fs";import{dirname as m}from"path";import y from"../../build/build_files.js";import g from"../../debounce.js";import s from"./get_after_run_tasks.js";import k from"./get_file_codependencies.js";import l from"../../build/get_file_operation.js";import v from"../../build/get_path_platform.js";import w from"../../types.js";import R from"./watch_paths.js";const{mkdir:p,copyFile:b,rm:d}=h.promises,c=async(e={},i={})=>{const a=process.initial_build_complete?await k(e?.path):[];if(i?.is_build_file&&await y({files:[{path:e?.path,platform:v(e?.path)}]}).catch((t=[])=>{if(!process.initial_build_complete&&t?.length>0&&process.exit(0),process.initial_build_complete&&t?.length>0)throw process.app_server_process.send(JSON.stringify({type:"BUILD_ERROR",paths:t.filter(({success:r})=>!r)})),process.hmr_server_process.send(JSON.stringify({type:"BUILD_ERROR"})),new Error("BUILD_ERROR")}),a?.length>0)for(let t=0;t<a?.length;t+=1){const r=a[t];return c({path:r})}return Promise.resolve()},D=async(e={})=>{switch(e?.operation){case"add_directory":return p(`.joystick/build/${e?.path}`,{recursive:!0});case"build_file":return c(e,{is_build_file:!0});case"copy_file":return await p(m(`.joystick/build/${e?.path}`),{recursive:!0}),await b(e?.path,`.joystick/build/${e?.path}`),c(e,{is_build_file:!1});case"delete_directory":return d(`.joystick/build/${e?.path}`,{recursive:!0});case"delete_file":return await d(`.joystick/build/${e?.path}`,{recursive:!0}),c(e,{is_build_file:!1});default:return!0}},O=(e={})=>({operation:e?.event,path:e?.path,after_run_tasks:process.initial_build_complete?s(e?.path):["start_app_server","start_hmr_server"]}),$=(e={})=>({operation:e?.event,path:e?.path,after_run_tasks:process.initial_build_complete?s(e?.path):["start_app_server","start_hmr_server"]}),E=(e={})=>({operation:e?.event,path:e?.path,after_run_tasks:process.initial_build_complete?s(e?.path):["start_app_server","start_hmr_server"]}),B=(e={})=>({operation:l(e?.path),path:e?.path,after_run_tasks:process.initial_build_complete?s(e?.path):["start_app_server","start_hmr_server"]}),I=(e={})=>({operation:l(e?.path),path:e?.path,after_run_tasks:process.initial_build_complete?s(e?.path):["start_app_server","start_hmr_server"]}),L=(e={})=>{switch(e?.event){case"add_file":return I(e);case"change_file":return B(e);case"delete_file":return E(e);case"add_directory":return $(e);case"delete_directory":return O(e)}},S=async(e=[],i={})=>{try{const a=new Set([]);for(let r=0;r<e?.length;r+=1){const _=e[r],n=L(_);if(await D(n),n?.after_run_tasks)for(let o=0;o<n?.after_run_tasks?.length;o+=1){const u=n?.after_run_tasks[o];a.add(u)}}const t=Array.from(a);for(let r=0;r<t?.length;r+=1){const _=t[r];w.is_function(i[_])&&await i[_](e)}}catch{}},U=(e="")=>{switch(e){case"add":return"add_file";case"change":return"change_file";case"unlink":return"delete_file";case"addDir":return"add_directory";case"unlinkDir":return"delete_directory"}},x=(e={})=>{const i=f.watch(R.map(({path:t})=>t),{ignored:".joystick"});let a=[];process.initial_build_complete=!1,i.on("error",t=>console.error(t)),i.on("all",(t,r)=>{a.push({event:U(t),path:r}),g(async()=>{await S(a,e),process.initial_build_complete=!0,a=[]},100)})};var M=x;export{M as default};
|
package/package.json
CHANGED
|
@@ -14,33 +14,39 @@ export default (() => {
|
|
|
14
14
|
process.on("message", async (message) => {
|
|
15
15
|
const parsed_message = JSON.parse(message);
|
|
16
16
|
|
|
17
|
-
if (typeof process.HMR_CONNECTIONS === "object" && parsed_message?.type
|
|
17
|
+
if (typeof process.HMR_CONNECTIONS === "object" && !!parsed_message?.type) {
|
|
18
18
|
const connections = Object.values(process.HMR_CONNECTIONS);
|
|
19
19
|
for (let i = 0; i < connections?.length; i += 1) {
|
|
20
20
|
const connection = connections[i];
|
|
21
21
|
if (connection?.connection?.send) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
type:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
22
|
+
switch(parsed_message?.type) {
|
|
23
|
+
case 'BUILD_ERROR':
|
|
24
|
+
return connection.connection.send(JSON.stringify({ type: 'BUILD_ERROR' }));
|
|
25
|
+
case 'FILE_CHANGE':
|
|
26
|
+
default:
|
|
27
|
+
return connection.connection.send(
|
|
28
|
+
JSON.stringify({
|
|
29
|
+
type: "FILE_CHANGE",
|
|
30
|
+
settings: parsed_message?.settings ? {
|
|
31
|
+
global: parsed_message?.settings?.global,
|
|
32
|
+
public: parsed_message?.settings?.public,
|
|
33
|
+
} : null,
|
|
34
|
+
i18n: parsed_message?.i18n_change ? await get_translations('./.joystick/build', connection?.page_component_path, {
|
|
35
|
+
headers: {
|
|
36
|
+
'accept-language': connection?.browser_language,
|
|
37
|
+
},
|
|
38
|
+
context: {
|
|
39
|
+
user: {
|
|
40
|
+
language: connection?.user_language,
|
|
41
|
+
},
|
|
42
|
+
}
|
|
43
|
+
}) : null,
|
|
44
|
+
index_html_changed: parsed_message?.index_html_change,
|
|
45
|
+
index_css_changed: parsed_message?.index_css_change,
|
|
46
|
+
index_client_changed: parsed_message?.index_client_change,
|
|
47
|
+
})
|
|
48
|
+
);
|
|
49
|
+
}
|
|
44
50
|
}
|
|
45
51
|
}
|
|
46
52
|
}
|
|
@@ -27,6 +27,17 @@ const handle_build_files = async (job = {}, options = {}) => {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
if (process.initial_build_complete && errors?.length > 0) {
|
|
30
|
+
process.app_server_process.send(
|
|
31
|
+
JSON.stringify({
|
|
32
|
+
type: "BUILD_ERROR",
|
|
33
|
+
paths: errors.filter(({ success }) => !success),
|
|
34
|
+
})
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
process.hmr_server_process.send(JSON.stringify({
|
|
38
|
+
type: 'BUILD_ERROR',
|
|
39
|
+
}));
|
|
40
|
+
|
|
30
41
|
throw new Error('BUILD_ERROR');
|
|
31
42
|
}
|
|
32
43
|
});
|
|
@@ -148,9 +159,9 @@ const process_file_watcher_jobs = async (jobs = [], after_run_functions = {}) =>
|
|
|
148
159
|
}
|
|
149
160
|
}
|
|
150
161
|
} catch(error) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
162
|
+
// NOTE: Dead catch as we just want to avoid after_run_tasks from running. Actual
|
|
163
|
+
// errors are handled as part of run_job() (e.g., build errors are handled as a part
|
|
164
|
+
// of handle_build_files()).
|
|
154
165
|
}
|
|
155
166
|
};
|
|
156
167
|
|