@merkur/cli 0.41.1 → 0.42.0
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.
- package/lib/index.cjs +7 -7
- package/lib/index.mjs +7 -7
- package/package.json +4 -3
- package/src/__tests__/utilsSpec.mjs +162 -0
- package/src/index.mjs +3 -1
- package/src/merkurConfig.mjs +30 -26
- package/src/utils.mjs +24 -0
package/lib/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var Y=Object.create;var m=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var W=(r,e)=>{for(var t in e)m(r,t,{get:e[t],enumerable:!0})},B=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of U(e))!K.call(r,n)&&n!==t&&m(r,n,{get:()=>e[n],enumerable:!(o=D(e,n))||o.enumerable});return r};var R=(r,e,t)=>(t=r!=null?Y(V(r)):{},B(e||!r||!r.__esModule?m(t,"default",{value:r,enumerable:!0}):t,r)),H=r=>B(m({},"__esModule",{value:!0}),r);var ce={};W(ce,{addServerConfig:()=>k,createLogger:()=>G});module.exports=H(ce);var M=(r=0)=>e=>`\x1B[${e+r}m`,I=(r=0)=>e=>`\x1B[${38+r};5;${e}m`,S=(r=0)=>(e,t,o)=>`\x1B[${38+r};2;${e};${t};${o}m`,i={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},ae=Object.keys(i.modifier),z=Object.keys(i.color),q=Object.keys(i.bgColor),fe=[...z,...q];function J(){let r=new Map;for(let[e,t]of Object.entries(i)){for(let[o,n]of Object.entries(t))i[o]={open:`\x1B[${n[0]}m`,close:`\x1B[${n[1]}m`},t[o]=i[o],r.set(n[0],n[1]);Object.defineProperty(i,e,{value:t,enumerable:!1})}return Object.defineProperty(i,"codes",{value:r,enumerable:!1}),i.color.close="\x1B[39m",i.bgColor.close="\x1B[49m",i.color.ansi=M(),i.color.ansi256=I(),i.color.ansi16m=S(),i.bgColor.ansi=M(10),i.bgColor.ansi256=I(10),i.bgColor.ansi16m=S(10),Object.defineProperties(i,{rgbToAnsi256:{value(e,t,o){return e===t&&t===o?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(o/255*5)},enumerable:!1},hexToRgb:{value(e){let t=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!t)return[0,0,0];let[o]=t;o.length===3&&(o=[...o].map(s=>s+s).join(""));let n=Number.parseInt(o,16);return[n>>16&255,n>>8&255,n&255]},enumerable:!1},hexToAnsi256:{value:e=>i.rgbToAnsi256(...i.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return 90+(e-8);let t,o,n;if(e>=232)t=((e-232)*10+8)/255,o=t,n=t;else{e-=16;let N=e%36;t=Math.floor(e/36)/5,o=Math.floor(N/6)/5,n=N%6/5}let s=Math.max(t,o,n)*2;if(s===0)return 30;let c=30+(Math.round(n)<<2|Math.round(o)<<1|Math.round(t));return s===2&&(c+=60),c},enumerable:!1},rgbToAnsi:{value:(e,t,o)=>i.ansi256ToAnsi(i.rgbToAnsi256(e,t,o)),enumerable:!1},hexToAnsi:{value:e=>i.ansi256ToAnsi(i.hexToAnsi256(e)),enumerable:!1}}),i}var Q=J(),a=Q;var O=R(require("node:process"),1),F=R(require("node:os"),1),y=R(require("node:tty"),1);function u(r,e=globalThis.Deno?globalThis.Deno.args:O.default.argv){let t=r.startsWith("-")?"":r.length===1?"-":"--",o=e.indexOf(t+r),n=e.indexOf("--");return o!==-1&&(n===-1||o<n)}var{env:l}=O.default,g;u("no-color")||u("no-colors")||u("color=false")||u("color=never")?g=0:(u("color")||u("colors")||u("color=true")||u("color=always"))&&(g=1);function X(){if("FORCE_COLOR"in l)return l.FORCE_COLOR==="true"?1:l.FORCE_COLOR==="false"?0:l.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(l.FORCE_COLOR,10),3)}function Z(r){return r===0?!1:{level:r,hasBasic:!0,has256:r>=2,has16m:r>=3}}function ee(r,{streamIsTTY:e,sniffFlags:t=!0}={}){let o=X();o!==void 0&&(g=o);let n=t?g:o;if(n===0)return 0;if(t){if(u("color=16m")||u("color=full")||u("color=truecolor"))return 3;if(u("color=256"))return 2}if("TF_BUILD"in l&&"AGENT_NAME"in l)return 1;if(r&&!e&&n===void 0)return 0;let s=n||0;if(l.TERM==="dumb")return s;if(O.default.platform==="win32"){let c=F.default.release().split(".");return Number(c[0])>=10&&Number(c[2])>=10586?Number(c[2])>=14931?3:2:1}if("CI"in l)return["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some(c=>c in l)?3:["TRAVIS","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(c=>c in l)||l.CI_NAME==="codeship"?1:s;if("TEAMCITY_VERSION"in l)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(l.TEAMCITY_VERSION)?1:0;if(l.COLORTERM==="truecolor"||l.TERM==="xterm-kitty"||l.TERM==="xterm-ghostty"||l.TERM==="wezterm")return 3;if("TERM_PROGRAM"in l){let c=Number.parseInt((l.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(l.TERM_PROGRAM){case"iTerm.app":return c>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(l.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(l.TERM)||"COLORTERM"in l?1:s}function v(r,e={}){let t=ee(r,{streamIsTTY:r&&r.isTTY,...e});return Z(t)}var re={stdout:v({isTTY:y.default.isatty(1)}),stderr:v({isTTY:y.default.isatty(2)})},_=re;function w(r,e,t){let o=r.indexOf(e);if(o===-1)return r;let n=e.length,s=0,c="";do c+=r.slice(s,o)+e+t,s=o+n,o=r.indexOf(e,s);while(o!==-1);return c+=r.slice(s),c}function j(r,e,t,o){let n=0,s="";do{let c=r[o-1]==="\r";s+=r.slice(n,c?o-1:o)+e+(c?`\r
|
|
2
2
|
`:`
|
|
3
|
-
`)+
|
|
4
|
-
`,n)}while(o!==-1);return s+=
|
|
5
|
-
`);return s!==-1&&(e=j(e,n,o,s)),o+e+n};Object.defineProperties(p.prototype,h);var
|
|
6
|
-
`)}info(e,
|
|
7
|
-
`)??"";this.#e("error",f.bold.red,`${f.underline(e.name)}: ${e.message.trim()}`,
|
|
3
|
+
`)+t,n=o+1,o=r.indexOf(`
|
|
4
|
+
`,n)}while(o!==-1);return s+=r.slice(n),s}var{stdout:L,stderr:$}=_,C=Symbol("GENERATOR"),b=Symbol("STYLER"),d=Symbol("IS_EMPTY"),P=["ansi","ansi","ansi256","ansi16m"],h=Object.create(null),te=(r,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let t=L?L.level:0;r.level=e.level===void 0?t:e.level};var oe=r=>{let e=(...t)=>t.join(" ");return te(e,r),Object.setPrototypeOf(e,p.prototype),e};function p(r){return oe(r)}Object.setPrototypeOf(p.prototype,Function.prototype);for(let[r,e]of Object.entries(a))h[r]={get(){let t=T(this,E(e.open,e.close,this[b]),this[d]);return Object.defineProperty(this,r,{value:t}),t}};h.visible={get(){let r=T(this,this[b],!0);return Object.defineProperty(this,"visible",{value:r}),r}};var A=(r,e,t,...o)=>r==="rgb"?e==="ansi16m"?a[t].ansi16m(...o):e==="ansi256"?a[t].ansi256(a.rgbToAnsi256(...o)):a[t].ansi(a.rgbToAnsi(...o)):r==="hex"?A("rgb",e,t,...a.hexToRgb(...o)):a[t][r](...o),ne=["rgb","hex","ansi256"];for(let r of ne){h[r]={get(){let{level:t}=this;return function(...o){let n=E(A(r,P[t],"color",...o),a.color.close,this[b]);return T(this,n,this[d])}}};let e="bg"+r[0].toUpperCase()+r.slice(1);h[e]={get(){let{level:t}=this;return function(...o){let n=E(A(r,P[t],"bgColor",...o),a.bgColor.close,this[b]);return T(this,n,this[d])}}}}var ie=Object.defineProperties(()=>{},{...h,level:{enumerable:!0,get(){return this[C].level},set(r){this[C].level=r}}}),E=(r,e,t)=>{let o,n;return t===void 0?(o=r,n=e):(o=t.openAll+r,n=e+t.closeAll),{open:r,close:e,openAll:o,closeAll:n,parent:t}},T=(r,e,t)=>{let o=(...n)=>le(o,n.length===1?""+n[0]:n.join(" "));return Object.setPrototypeOf(o,ie),o[C]=r,o[b]=e,o[d]=t,o},le=(r,e)=>{if(r.level<=0||!e)return r[d]?"":e;let t=r[b];if(t===void 0)return e;let{openAll:o,closeAll:n}=t;if(e.includes("\x1B"))for(;t!==void 0;)e=w(e,t.close,t.open),t=t.parent;let s=e.indexOf(`
|
|
5
|
+
`);return s!==-1&&(e=j(e,n,o,s)),o+e+n};Object.defineProperties(p.prototype,h);var se=p(),Oe=p({level:$?$.level:0});var f=se;var x=class{#r=null;#t=null;constructor(e,t){this.#r=e,this.#t=t}#e(e,t,o){e&&process.stdout.write(t(`${e}: ${this.#r?`(${this.#r}) `:""}`));try{o=o??typeof o,process.stdout.write(o)}catch(n){console.error(n)}process.stdout.write(`
|
|
6
|
+
`)}info(e,t){this.#e("info",f.bold.cyan,e,t)}log(e,t){this.#e(null,f.bold.cyan,e,t)}debug(e,t){this.#t?.verbose&&this.#e("debug",f.bold.cyan,e,t)}warn(e,t){this.#e("warn",f.bold.yellow,e,t)}error(e,t){if(e instanceof Error){let[o,...n]=e.stack?.split(`
|
|
7
|
+
`)??"";this.#e("error",f.bold.red,`${f.underline(e.name)}: ${e.message.trim()}`,t),process.stdout.write(`
|
|
8
8
|
${f.gray(n.join(`
|
|
9
9
|
`))}
|
|
10
|
-
`),e?.cause instanceof Error&&this.error(e.cause,
|
|
10
|
+
`),e?.cause instanceof Error&&this.error(e.cause,t)}else this.#e("error",f.bold.red,e,t)}};function G(r,e={}){return new x(r,e)}function k(r,{protocol:e,hostname:t,port:o}){e&&(r.protocol=e),o&&(r.port=o);let n=t??(o?r.host?.split(":")[0]:null);return n&&(r.host=`${n}:${r.port}`),r.protocol&&r.host&&(r.origin=new URL(`${r.protocol}//${r.host}`).origin),r}0&&(module.exports={addServerConfig,createLogger});
|
package/lib/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var E=(
|
|
1
|
+
var E=(r=0)=>e=>`\x1B[${e+r}m`,x=(r=0)=>e=>`\x1B[${38+r};5;${e}m`,N=(r=0)=>(e,t,o)=>`\x1B[${38+r};2;${e};${t};${o}m`,i={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},X=Object.keys(i.modifier),j=Object.keys(i.color),L=Object.keys(i.bgColor),Z=[...j,...L];function $(){let r=new Map;for(let[e,t]of Object.entries(i)){for(let[o,n]of Object.entries(t))i[o]={open:`\x1B[${n[0]}m`,close:`\x1B[${n[1]}m`},t[o]=i[o],r.set(n[0],n[1]);Object.defineProperty(i,e,{value:t,enumerable:!1})}return Object.defineProperty(i,"codes",{value:r,enumerable:!1}),i.color.close="\x1B[39m",i.bgColor.close="\x1B[49m",i.color.ansi=E(),i.color.ansi256=x(),i.color.ansi16m=N(),i.bgColor.ansi=E(10),i.bgColor.ansi256=x(10),i.bgColor.ansi16m=N(10),Object.defineProperties(i,{rgbToAnsi256:{value(e,t,o){return e===t&&t===o?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(o/255*5)},enumerable:!1},hexToRgb:{value(e){let t=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!t)return[0,0,0];let[o]=t;o.length===3&&(o=[...o].map(s=>s+s).join(""));let n=Number.parseInt(o,16);return[n>>16&255,n>>8&255,n&255]},enumerable:!1},hexToAnsi256:{value:e=>i.rgbToAnsi256(...i.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return 90+(e-8);let t,o,n;if(e>=232)t=((e-232)*10+8)/255,o=t,n=t;else{e-=16;let A=e%36;t=Math.floor(e/36)/5,o=Math.floor(A/6)/5,n=A%6/5}let s=Math.max(t,o,n)*2;if(s===0)return 30;let c=30+(Math.round(n)<<2|Math.round(o)<<1|Math.round(t));return s===2&&(c+=60),c},enumerable:!1},rgbToAnsi:{value:(e,t,o)=>i.ansi256ToAnsi(i.rgbToAnsi256(e,t,o)),enumerable:!1},hexToAnsi:{value:e=>i.ansi256ToAnsi(i.hexToAnsi256(e)),enumerable:!1}}),i}var P=$(),a=P;import O from"node:process";import G from"node:os";import B from"node:tty";function u(r,e=globalThis.Deno?globalThis.Deno.args:O.argv){let t=r.startsWith("-")?"":r.length===1?"-":"--",o=e.indexOf(t+r),n=e.indexOf("--");return o!==-1&&(n===-1||o<n)}var{env:l}=O,m;u("no-color")||u("no-colors")||u("color=false")||u("color=never")?m=0:(u("color")||u("colors")||u("color=true")||u("color=always"))&&(m=1);function k(){if("FORCE_COLOR"in l)return l.FORCE_COLOR==="true"?1:l.FORCE_COLOR==="false"?0:l.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(l.FORCE_COLOR,10),3)}function Y(r){return r===0?!1:{level:r,hasBasic:!0,has256:r>=2,has16m:r>=3}}function D(r,{streamIsTTY:e,sniffFlags:t=!0}={}){let o=k();o!==void 0&&(m=o);let n=t?m:o;if(n===0)return 0;if(t){if(u("color=16m")||u("color=full")||u("color=truecolor"))return 3;if(u("color=256"))return 2}if("TF_BUILD"in l&&"AGENT_NAME"in l)return 1;if(r&&!e&&n===void 0)return 0;let s=n||0;if(l.TERM==="dumb")return s;if(O.platform==="win32"){let c=G.release().split(".");return Number(c[0])>=10&&Number(c[2])>=10586?Number(c[2])>=14931?3:2:1}if("CI"in l)return["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some(c=>c in l)?3:["TRAVIS","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(c=>c in l)||l.CI_NAME==="codeship"?1:s;if("TEAMCITY_VERSION"in l)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(l.TEAMCITY_VERSION)?1:0;if(l.COLORTERM==="truecolor"||l.TERM==="xterm-kitty"||l.TERM==="xterm-ghostty"||l.TERM==="wezterm")return 3;if("TERM_PROGRAM"in l){let c=Number.parseInt((l.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(l.TERM_PROGRAM){case"iTerm.app":return c>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(l.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(l.TERM)||"COLORTERM"in l?1:s}function M(r,e={}){let t=D(r,{streamIsTTY:r&&r.isTTY,...e});return Y(t)}var U={stdout:M({isTTY:B.isatty(1)}),stderr:M({isTTY:B.isatty(2)})},I=U;function S(r,e,t){let o=r.indexOf(e);if(o===-1)return r;let n=e.length,s=0,c="";do c+=r.slice(s,o)+e+t,s=o+n,o=r.indexOf(e,s);while(o!==-1);return c+=r.slice(s),c}function v(r,e,t,o){let n=0,s="";do{let c=r[o-1]==="\r";s+=r.slice(n,c?o-1:o)+e+(c?`\r
|
|
2
2
|
`:`
|
|
3
|
-
`)+
|
|
4
|
-
`,n)}while(o!==-1);return s+=
|
|
5
|
-
`);return s!==-1&&(e=
|
|
6
|
-
`)}info(e,
|
|
7
|
-
`)??"";this.#e("error",f.bold.red,`${f.underline(e.name)}: ${e.message.trim()}`,
|
|
3
|
+
`)+t,n=o+1,o=r.indexOf(`
|
|
4
|
+
`,n)}while(o!==-1);return s+=r.slice(n),s}var{stdout:F,stderr:_}=I,T=Symbol("GENERATOR"),b=Symbol("STYLER"),d=Symbol("IS_EMPTY"),w=["ansi","ansi","ansi256","ansi16m"],h=Object.create(null),V=(r,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let t=F?F.level:0;r.level=e.level===void 0?t:e.level};var K=r=>{let e=(...t)=>t.join(" ");return V(e,r),Object.setPrototypeOf(e,p.prototype),e};function p(r){return K(r)}Object.setPrototypeOf(p.prototype,Function.prototype);for(let[r,e]of Object.entries(a))h[r]={get(){let t=g(this,y(e.open,e.close,this[b]),this[d]);return Object.defineProperty(this,r,{value:t}),t}};h.visible={get(){let r=g(this,this[b],!0);return Object.defineProperty(this,"visible",{value:r}),r}};var R=(r,e,t,...o)=>r==="rgb"?e==="ansi16m"?a[t].ansi16m(...o):e==="ansi256"?a[t].ansi256(a.rgbToAnsi256(...o)):a[t].ansi(a.rgbToAnsi(...o)):r==="hex"?R("rgb",e,t,...a.hexToRgb(...o)):a[t][r](...o),W=["rgb","hex","ansi256"];for(let r of W){h[r]={get(){let{level:t}=this;return function(...o){let n=y(R(r,w[t],"color",...o),a.color.close,this[b]);return g(this,n,this[d])}}};let e="bg"+r[0].toUpperCase()+r.slice(1);h[e]={get(){let{level:t}=this;return function(...o){let n=y(R(r,w[t],"bgColor",...o),a.bgColor.close,this[b]);return g(this,n,this[d])}}}}var H=Object.defineProperties(()=>{},{...h,level:{enumerable:!0,get(){return this[T].level},set(r){this[T].level=r}}}),y=(r,e,t)=>{let o,n;return t===void 0?(o=r,n=e):(o=t.openAll+r,n=e+t.closeAll),{open:r,close:e,openAll:o,closeAll:n,parent:t}},g=(r,e,t)=>{let o=(...n)=>z(o,n.length===1?""+n[0]:n.join(" "));return Object.setPrototypeOf(o,H),o[T]=r,o[b]=e,o[d]=t,o},z=(r,e)=>{if(r.level<=0||!e)return r[d]?"":e;let t=r[b];if(t===void 0)return e;let{openAll:o,closeAll:n}=t;if(e.includes("\x1B"))for(;t!==void 0;)e=S(e,t.close,t.open),t=t.parent;let s=e.indexOf(`
|
|
5
|
+
`);return s!==-1&&(e=v(e,n,o,s)),o+e+n};Object.defineProperties(p.prototype,h);var q=p(),ue=p({level:_?_.level:0});var f=q;var C=class{#r=null;#t=null;constructor(e,t){this.#r=e,this.#t=t}#e(e,t,o){e&&process.stdout.write(t(`${e}: ${this.#r?`(${this.#r}) `:""}`));try{o=o??typeof o,process.stdout.write(o)}catch(n){console.error(n)}process.stdout.write(`
|
|
6
|
+
`)}info(e,t){this.#e("info",f.bold.cyan,e,t)}log(e,t){this.#e(null,f.bold.cyan,e,t)}debug(e,t){this.#t?.verbose&&this.#e("debug",f.bold.cyan,e,t)}warn(e,t){this.#e("warn",f.bold.yellow,e,t)}error(e,t){if(e instanceof Error){let[o,...n]=e.stack?.split(`
|
|
7
|
+
`)??"";this.#e("error",f.bold.red,`${f.underline(e.name)}: ${e.message.trim()}`,t),process.stdout.write(`
|
|
8
8
|
${f.gray(n.join(`
|
|
9
9
|
`))}
|
|
10
|
-
`),e?.cause instanceof Error&&this.error(e.cause,
|
|
10
|
+
`),e?.cause instanceof Error&&this.error(e.cause,t)}else this.#e("error",f.bold.red,e,t)}};function J(r,e={}){return new C(r,e)}function Q(r,{protocol:e,hostname:t,port:o}){e&&(r.protocol=e),o&&(r.port=o);let n=t??(o?r.host?.split(":")[0]:null);return n&&(r.host=`${n}:${r.port}`),r.protocol&&r.host&&(r.origin=new URL(`${r.protocol}//${r.host}`).origin),r}export{Q as addServerConfig,J as createLogger};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@merkur/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.0",
|
|
4
4
|
"description": "Merkur is tiny and extensible library for creating front-end microservices.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"merkur": "./bin/merkur.mjs"
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "node ./scripts/build.mjs",
|
|
22
|
+
"test": "NODE_OPTIONS='--experimental-vm-modules' jest --no-watchman -c ./jest.config.js",
|
|
22
23
|
"dev": "node ./scripts/build.mjs --watch"
|
|
23
24
|
},
|
|
24
25
|
"repository": {
|
|
@@ -58,11 +59,11 @@
|
|
|
58
59
|
"ws": "^8.18.3"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
61
|
-
"@merkur/core": "^0.
|
|
62
|
+
"@merkur/core": "^0.42.0",
|
|
62
63
|
"@types/express": "^5.0.4"
|
|
63
64
|
},
|
|
64
65
|
"engines": {
|
|
65
66
|
"node": ">=20"
|
|
66
67
|
},
|
|
67
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "2dc0d2b36d51498d3ce2a981dfde9882fc28420e"
|
|
68
69
|
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { addServerConfig } from '../utils.mjs';
|
|
2
|
+
|
|
3
|
+
describe('server function', () => {
|
|
4
|
+
describe('addServerConfig', () => {
|
|
5
|
+
it('should update protocol when provided', () => {
|
|
6
|
+
const serverConfig = {
|
|
7
|
+
protocol: 'http:',
|
|
8
|
+
host: 'localhost:3000',
|
|
9
|
+
port: 3000,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const result = addServerConfig(serverConfig, { protocol: 'https:' });
|
|
13
|
+
|
|
14
|
+
expect(result.protocol).toBe('https:');
|
|
15
|
+
expect(result.origin).toBe('https://localhost:3000');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should update port when provided', () => {
|
|
19
|
+
const serverConfig = {
|
|
20
|
+
protocol: 'http:',
|
|
21
|
+
host: 'localhost:3000',
|
|
22
|
+
port: 3000,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const result = addServerConfig(serverConfig, { port: 8080 });
|
|
26
|
+
|
|
27
|
+
expect(result.port).toBe(8080);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should update host when hostname is provided', () => {
|
|
31
|
+
const serverConfig = {
|
|
32
|
+
protocol: 'http:',
|
|
33
|
+
host: 'localhost:3000',
|
|
34
|
+
port: 3000,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const result = addServerConfig(serverConfig, { hostname: '127.0.0.1' });
|
|
38
|
+
|
|
39
|
+
expect(result.host).toBe('127.0.0.1:3000');
|
|
40
|
+
expect(result.origin).toBe('http://127.0.0.1:3000');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should update host when port is provided without hostname', () => {
|
|
44
|
+
const serverConfig = {
|
|
45
|
+
protocol: 'http:',
|
|
46
|
+
host: 'localhost:3000',
|
|
47
|
+
port: 3000,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const result = addServerConfig(serverConfig, { port: 8080 });
|
|
51
|
+
|
|
52
|
+
expect(result.host).toBe('localhost:8080');
|
|
53
|
+
expect(result.port).toBe(8080);
|
|
54
|
+
expect(result.origin).toBe('http://localhost:8080');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should update host and port when both hostname and port are provided', () => {
|
|
58
|
+
const serverConfig = {
|
|
59
|
+
protocol: 'http:',
|
|
60
|
+
host: 'localhost:3000',
|
|
61
|
+
port: 3000,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const result = addServerConfig(serverConfig, {
|
|
65
|
+
hostname: 'example.com',
|
|
66
|
+
port: 8080,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
expect(result.host).toBe('example.com:8080');
|
|
70
|
+
expect(result.port).toBe(8080);
|
|
71
|
+
expect(result.origin).toBe('http://example.com:8080');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should update all fields when protocol, hostname, and port are provided', () => {
|
|
75
|
+
const serverConfig = {
|
|
76
|
+
protocol: 'http:',
|
|
77
|
+
host: 'localhost:3000',
|
|
78
|
+
port: 3000,
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const result = addServerConfig(serverConfig, {
|
|
82
|
+
protocol: 'https:',
|
|
83
|
+
hostname: 'example.com',
|
|
84
|
+
port: 443,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
expect(result.protocol).toBe('https:');
|
|
88
|
+
expect(result.host).toBe('example.com:443');
|
|
89
|
+
expect(result.port).toBe(443);
|
|
90
|
+
expect(result.origin).toBe('https://example.com');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should not update host when no hostname or port is provided', () => {
|
|
94
|
+
const serverConfig = {
|
|
95
|
+
protocol: 'http:',
|
|
96
|
+
host: 'localhost:3000',
|
|
97
|
+
port: 3000,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const result = addServerConfig(serverConfig, { protocol: 'https:' });
|
|
101
|
+
|
|
102
|
+
expect(result.host).toBe('localhost:3000');
|
|
103
|
+
expect(result.origin).toBe('https://localhost:3000');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('should handle serverConfig without existing host', () => {
|
|
107
|
+
const serverConfig = {
|
|
108
|
+
protocol: 'http:',
|
|
109
|
+
port: 3000,
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const result = addServerConfig(serverConfig, {
|
|
113
|
+
hostname: 'localhost',
|
|
114
|
+
port: 8080,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
expect(result.host).toBe('localhost:8080');
|
|
118
|
+
expect(result.port).toBe(8080);
|
|
119
|
+
expect(result.origin).toBe('http://localhost:8080');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('should handle serverConfig without existing host', () => {
|
|
123
|
+
const serverConfig = {};
|
|
124
|
+
|
|
125
|
+
const result = addServerConfig(serverConfig, {
|
|
126
|
+
port: 8080,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
expect(result.host).toBe(undefined);
|
|
130
|
+
expect(result.port).toBe(8080);
|
|
131
|
+
expect(result.origin).toBe(undefined);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('should return the modified serverConfig object', () => {
|
|
135
|
+
const serverConfig = {
|
|
136
|
+
protocol: 'http:',
|
|
137
|
+
host: 'localhost:3000',
|
|
138
|
+
port: 3000,
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const result = addServerConfig(serverConfig, {});
|
|
142
|
+
|
|
143
|
+
expect(result).toBe(serverConfig);
|
|
144
|
+
expect(result.origin).toBe('http://localhost:3000');
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('should handle empty options object', () => {
|
|
148
|
+
const serverConfig = {
|
|
149
|
+
protocol: 'http:',
|
|
150
|
+
host: 'localhost:3000',
|
|
151
|
+
port: 3000,
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const result = addServerConfig(serverConfig, {});
|
|
155
|
+
|
|
156
|
+
expect(result.protocol).toBe('http:');
|
|
157
|
+
expect(result.host).toBe('localhost:3000');
|
|
158
|
+
expect(result.port).toBe(3000);
|
|
159
|
+
expect(result.origin).toBe('http://localhost:3000');
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
});
|
package/src/index.mjs
CHANGED
package/src/merkurConfig.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { pathToFileURL } from 'node:url';
|
|
3
|
+
import { addServerConfig } from './utils.mjs';
|
|
3
4
|
|
|
4
5
|
import { EMITTER_EVENTS, emitter, RESULT_KEY } from './emitter.mjs';
|
|
5
6
|
import { updateCLIConfig } from './CLIConfig.mjs';
|
|
@@ -155,24 +156,22 @@ emitter.on(
|
|
|
155
156
|
EMITTER_EVENTS.MERKUR_CONFIG,
|
|
156
157
|
function devServer({ merkurConfig, cliConfig }) {
|
|
157
158
|
merkurConfig.devServer = {
|
|
159
|
+
...addServerConfig(
|
|
160
|
+
{},
|
|
161
|
+
{
|
|
162
|
+
protocol: 'http:',
|
|
163
|
+
hostname: 'localhost',
|
|
164
|
+
port: 4445,
|
|
165
|
+
},
|
|
166
|
+
),
|
|
167
|
+
staticPath: cliConfig.staticPath,
|
|
168
|
+
staticFolder: path.resolve(
|
|
169
|
+
cliConfig.projectFolder,
|
|
170
|
+
cliConfig.staticFolder,
|
|
171
|
+
),
|
|
158
172
|
...merkurConfig.devServer,
|
|
159
|
-
...{
|
|
160
|
-
protocol: 'http:',
|
|
161
|
-
host: 'localhost:4445',
|
|
162
|
-
port: 4445,
|
|
163
|
-
staticPath: cliConfig.staticPath,
|
|
164
|
-
staticFolder: path.resolve(
|
|
165
|
-
cliConfig.projectFolder,
|
|
166
|
-
cliConfig.staticFolder,
|
|
167
|
-
),
|
|
168
|
-
},
|
|
169
173
|
};
|
|
170
174
|
|
|
171
|
-
const { origin, host, protocol } = merkurConfig.devServer;
|
|
172
|
-
|
|
173
|
-
merkurConfig.devServer.origin =
|
|
174
|
-
origin ?? new URL(`${protocol}//${host}`).origin;
|
|
175
|
-
|
|
176
175
|
return merkurConfig;
|
|
177
176
|
},
|
|
178
177
|
);
|
|
@@ -247,9 +246,14 @@ emitter.on(
|
|
|
247
246
|
EMITTER_EVENTS.MERKUR_CONFIG,
|
|
248
247
|
function socketServer({ merkurConfig }) {
|
|
249
248
|
merkurConfig.socketServer = {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
249
|
+
...addServerConfig(
|
|
250
|
+
{},
|
|
251
|
+
{
|
|
252
|
+
protocol: 'ws:',
|
|
253
|
+
hostname: 'localhost',
|
|
254
|
+
port: 4321,
|
|
255
|
+
},
|
|
256
|
+
),
|
|
253
257
|
...merkurConfig.socketServer,
|
|
254
258
|
};
|
|
255
259
|
|
|
@@ -261,9 +265,14 @@ emitter.on(
|
|
|
261
265
|
EMITTER_EVENTS.MERKUR_CONFIG,
|
|
262
266
|
function widgetServer({ merkurConfig, cliConfig }) {
|
|
263
267
|
merkurConfig.widgetServer = {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
268
|
+
...addServerConfig(
|
|
269
|
+
{},
|
|
270
|
+
{
|
|
271
|
+
protocol: 'http:',
|
|
272
|
+
hostname: 'localhost',
|
|
273
|
+
port: 4444,
|
|
274
|
+
},
|
|
275
|
+
),
|
|
267
276
|
staticPath: cliConfig.staticPath,
|
|
268
277
|
staticFolder: path.resolve(
|
|
269
278
|
cliConfig.projectFolder,
|
|
@@ -285,11 +294,6 @@ emitter.on(
|
|
|
285
294
|
},
|
|
286
295
|
};
|
|
287
296
|
|
|
288
|
-
const { origin, host, protocol } = merkurConfig.widgetServer;
|
|
289
|
-
|
|
290
|
-
merkurConfig.widgetServer.origin =
|
|
291
|
-
origin ?? new URL(`${protocol}//${host}`).origin;
|
|
292
|
-
|
|
293
297
|
return merkurConfig;
|
|
294
298
|
},
|
|
295
299
|
);
|
package/src/utils.mjs
CHANGED
|
@@ -31,3 +31,27 @@ export function deepMerge(target, source) {
|
|
|
31
31
|
|
|
32
32
|
return target;
|
|
33
33
|
}
|
|
34
|
+
|
|
35
|
+
export function addServerConfig(serverConfig, { protocol, hostname, port }) {
|
|
36
|
+
if (protocol) {
|
|
37
|
+
serverConfig.protocol = protocol;
|
|
38
|
+
}
|
|
39
|
+
if (port) {
|
|
40
|
+
serverConfig.port = port;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const effectiveHostname =
|
|
44
|
+
hostname ?? (port ? serverConfig.host?.split(':')[0] : null);
|
|
45
|
+
|
|
46
|
+
if (effectiveHostname) {
|
|
47
|
+
serverConfig.host = `${effectiveHostname}:${serverConfig.port}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (serverConfig.protocol && serverConfig.host) {
|
|
51
|
+
serverConfig.origin = new URL(
|
|
52
|
+
`${serverConfig.protocol}//${serverConfig.host}`,
|
|
53
|
+
).origin;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return serverConfig;
|
|
57
|
+
}
|