@visulima/ono 2.0.10 → 2.0.11

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.
@@ -32,7 +32,7 @@ declare enum Editors {
32
32
  webstorm = "WebStorm",
33
33
  windsurf = "Windsurf",
34
34
  xcode = "Xcode",
35
- zed = "Zed",
35
+ zed = "Zed"
36
36
  }
37
37
  type Theme = "dark" | "light" | "auto";
38
38
  type ContentPage = {
@@ -11,18 +11,18 @@ type OpenInEditorOptions = {
11
11
  projectRoot?: string;
12
12
  };
13
13
  /**
14
- * Single universal handler factory for Node HTTP and Connect/Express.
15
- * Accepts POST JSON or GET query (?file&line&column&editor).
16
- * Enforces projectRoot unless allowOutsideProject is true.
17
- * @example
18
- * ```typescript
19
- * const openInEditor = createOpenInEditorMiddleware({ projectRoot: process.cwd() })
20
- * // Node http
21
- * if (url.pathname === '/__open-in-editor') return openInEditor(req, res)
22
- * // Express/Connect
23
- * app.post('/__open-in-editor', openInEditor)
24
- * ```
25
- */
14
+ * Single universal handler factory for Node HTTP and Connect/Express.
15
+ * Accepts POST JSON or GET query (?file&line&column&editor).
16
+ * Enforces projectRoot unless allowOutsideProject is true.
17
+ * @example
18
+ * ```typescript
19
+ * const openInEditor = createOpenInEditorMiddleware({ projectRoot: process.cwd() })
20
+ * // Node http
21
+ * if (url.pathname === '/__open-in-editor') return openInEditor(req, res)
22
+ * // Express/Connect
23
+ * app.post('/__open-in-editor', openInEditor)
24
+ * ```
25
+ */
26
26
  declare const createOpenInEditorMiddleware: (options?: OpenInEditorOptions) => UniversalHandler;
27
27
  declare const createNodeHttpHandler: (options?: OpenInEditorOptions) => NodeHttpHandler;
28
28
  declare const createExpressHandler: (options?: OpenInEditorOptions) => UniversalHandler;
@@ -1 +1 @@
1
- import{createRequire as S}from"node:module";import C from"launch-editor-middleware";import{a as $}from"../packem_shared/process-DVasYamT.js";const x=S(import.meta.url),h=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,O=e=>{if(typeof h<"u"&&h.versions&&h.versions.node){const[s,r]=h.versions.node.split(".").map(Number);if(s>22||s===22&&r>=3||s===20&&r>=16)return h.getBuiltinModule(e)}return x(e)},{realpathSync:w}=O("node:fs"),N=/^[A-Z]:\//i,v=(e="")=>e&&e.replaceAll("\\","/").replace(N,s=>s.toUpperCase()),R=/^[/\\]{2}/,T=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i,W=/^[A-Z]:$/i,P=/^\/([A-Z]:)?$/i,E=()=>typeof process.cwd=="function"?process.cwd().replaceAll("\\","/"):"/",j=(e,s)=>{let r="",t=0,n=-1,o=0,c;for(let l=0;l<=e.length;++l){if(l<e.length)c=e[l];else{if(c==="/")break;c="/"}if(c==="/"){if(!(n===l-1||o===1))if(o===2){if(r.length<2||t!==2||!r.endsWith(".")||r.at(-2)!=="."){if(r.length>2){const a=r.lastIndexOf("/");a===-1?(r="",t=0):(r=r.slice(0,a),t=r.length-1-r.lastIndexOf("/")),n=l,o=0;continue}else if(r.length>0){r="",t=0,n=l,o=0;continue}}s&&(r+=r.length>0?"/..":"..",t=2)}else r.length>0?r+=`/${e.slice(n+1,l)}`:r=e.slice(n+1,l),t=l-n-1;n=l,o=0}else c==="."&&o!==-1?++o:o=-1}return r},u=e=>T.test(e),p=function(e){if(e.length===0)return".";e=v(e);const s=R.exec(e),r=u(e),t=e.at(-1)==="/";return e=j(e,!r),e.length===0?r?"/":t?"./":".":(t&&(e+="/"),W.test(e)&&(e+="/"),s?r?`//${e}`:`//./${e}`:r&&!u(e)?`/${e}`:e)},g=function(...e){e=e.map(t=>v(t));let s="",r=!1;for(let t=e.length-1;t>=-1&&!r;t--){const n=t>=0?e[t]:E();!n||n.length===0||(s=`${n}/${s}`,r=u(n))}return s=j(s,!r),r&&!u(s)?`/${s}`:s.length>0?s:"."},b=function(e,s){const r=g(e).replace(P,"$1").split("/"),t=g(s).replace(P,"$1").split("/");if(t[0][1]===":"&&r[0][1]===":"&&r[0]!==t[0])return t.join("/");const n=Math.min(r.length,t.length);let o=0;for(;o<n&&r[o]===t[o];)o+=1;const c=r.length-o;return[...Array.from({length:c}).fill(".."),...t.slice(o)].join("/")},I=/^[\w.+-]+$/,_=e=>{if(typeof e.status=="function"){e.status(400).send("Failed to open editor");return}e.statusCode=400,e.end("Failed to open editor")},A=(e={})=>{const s=async t=>{if((t.method??"GET").toUpperCase()==="POST")return t.body&&typeof t.body=="object"?t.body:new Promise(o=>{try{let c="";const l=()=>{typeof t.removeListener=="function"&&(t.removeListener("data",a),t.removeListener("end",i),t.removeListener("error",f))},a=d=>{c+=String(d),c.length>1e6&&(l(),o({}))},i=()=>{l();try{o(c?JSON.parse(c):{})}catch{o({})}},f=()=>{l(),o({})};t.on("data",a),t.on("end",i),t.on("error",f)}catch{o({})}});const n=new URL(t.url??"","http://localhost");return{column:Number(n.searchParams.get("column")??1),editor:n.searchParams.get("editor")??void 0,file:n.searchParams.get("file")??void 0,line:Number(n.searchParams.get("line")??1)}},r=(t,n,o)=>{if(!t)return;const c=u(t)?t:g(n,t);if(!o)try{const l=w(n),a=w(c),i=p(l),f=p(a),d=$()==="win32"||$()==="darwin",m=d?i.toLowerCase():i,L=d?f.toLowerCase():f,y=b(i,f);if(y.startsWith("..")||u(y)||d&&!L.startsWith(m))return}catch{const l=b(p(n),p(c));if(l.startsWith("..")||u(l))return}return c};return async function(t,n,o){try{const c=await s(t),l=e.projectRoot??process.cwd(),a=r(c.file,l,e.allowOutsideProject??!1);if(!a){_(n);return}const i=c.editor&&I.test(c.editor)?c.editor:void 0,f=C(i,l),d=new URLSearchParams({column:String(c.column??1),file:a,line:String(c.line??1)});if(i&&d.set("editor",i),t.url=`/?${d.toString()}`,typeof o=="function"){f(t,n,o);return}await new Promise(m=>{f(t,n,()=>{m()})})}catch{_(n)}}},q=(e={})=>{const s=A(e);return async(r,t)=>s(r,t)},B=(e={})=>A(e);export{B as createExpressHandler,q as createNodeHttpHandler,A as createOpenInEditorMiddleware};
1
+ import{createRequire as S}from"node:module";import C from"launch-editor-middleware";import{a as $}from"../packem_shared/process-DVasYamT.js";let x;const O=e=>(x??=S(import.meta.url))(e),h=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,R=e=>{if(typeof h<"u"&&h.versions&&h.versions.node){const[s,r]=h.versions.node.split(".").map(Number);if(s>22||s===22&&r>=3||s===20&&r>=16)return h.getBuiltinModule(e)}return O(e)},{realpathSync:w}=R("node:fs"),N=/^[A-Z]:\//i,j=(e="")=>e&&e.replaceAll("\\","/").replace(N,s=>s.toUpperCase()),T=/^[/\\]{2}/,W=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i,q=/^[A-Z]:$/i,_=/^\/([A-Z]:)?$/i,E=()=>typeof process.cwd=="function"?process.cwd().replaceAll("\\","/"):"/",v=(e,s)=>{let r="",t=0,n=-1,o=0,c;for(let l=0;l<=e.length;++l){if(l<e.length)c=e[l];else{if(c==="/")break;c="/"}if(c==="/"){if(!(n===l-1||o===1))if(o===2){if(r.length<2||t!==2||!r.endsWith(".")||r.at(-2)!=="."){if(r.length>2){const a=r.lastIndexOf("/");a===-1?(r="",t=0):(r=r.slice(0,a),t=r.length-1-r.lastIndexOf("/")),n=l,o=0;continue}else if(r.length>0){r="",t=0,n=l,o=0;continue}}s&&(r+=r.length>0?"/..":"..",t=2)}else r.length>0?r+=`/${e.slice(n+1,l)}`:r=e.slice(n+1,l),t=l-n-1;n=l,o=0}else c==="."&&o!==-1?++o:o=-1}return r},d=e=>W.test(e),p=function(e){if(e.length===0)return".";e=j(e);const s=T.exec(e),r=d(e),t=e.at(-1)==="/";return e=v(e,!r),e.length===0?r?"/":t?"./":".":(t&&(e+="/"),q.test(e)&&(e+="/"),s?r?`//${e}`:`//./${e}`:r&&!d(e)?`/${e}`:e)},g=function(...e){e=e.map(t=>j(t));let s="",r=!1;for(let t=e.length-1;t>=-1&&!r;t--){const n=t>=0?e[t]:E();!n||n.length===0||(s=`${n}/${s}`,r=d(n))}return s=v(s,!r),r&&!d(s)?`/${s}`:s.length>0?s:"."},P=function(e,s){const r=g(e).replace(_,"$1").split("/"),t=g(s).replace(_,"$1").split("/");if(t[0][1]===":"&&r[0][1]===":"&&r[0]!==t[0])return t.join("/");const n=Math.min(r.length,t.length);let o=0;for(;o<n&&r[o]===t[o];)o+=1;const c=r.length-o;return[...Array.from({length:c}).fill(".."),...t.slice(o)].join("/")},I=/^[\w.+-]+$/,b=e=>{if(typeof e.status=="function"){e.status(400).send("Failed to open editor");return}e.statusCode=400,e.end("Failed to open editor")},A=(e={})=>{const s=async t=>{if((t.method??"GET").toUpperCase()==="POST")return t.body&&typeof t.body=="object"?t.body:new Promise(o=>{try{let c="";const l=()=>{typeof t.removeListener=="function"&&(t.removeListener("data",a),t.removeListener("end",i),t.removeListener("error",f))},a=u=>{c+=String(u),c.length>1e6&&(l(),o({}))},i=()=>{l();try{o(c?JSON.parse(c):{})}catch{o({})}},f=()=>{l(),o({})};t.on("data",a),t.on("end",i),t.on("error",f)}catch{o({})}});const n=new URL(t.url??"","http://localhost");return{column:Number(n.searchParams.get("column")??1),editor:n.searchParams.get("editor")??void 0,file:n.searchParams.get("file")??void 0,line:Number(n.searchParams.get("line")??1)}},r=(t,n,o)=>{if(!t)return;const c=d(t)?t:g(n,t);if(!o)try{const l=w(n),a=w(c),i=p(l),f=p(a),u=$()==="win32"||$()==="darwin",m=u?i.toLowerCase():i,L=u?f.toLowerCase():f,y=P(i,f);if(y.startsWith("..")||d(y)||u&&!L.startsWith(m))return}catch{const l=P(p(n),p(c));if(l.startsWith("..")||d(l))return}return c};return async function(t,n,o){try{const c=await s(t),l=e.projectRoot??process.cwd(),a=r(c.file,l,e.allowOutsideProject??!1);if(!a){b(n);return}const i=c.editor&&I.test(c.editor)?c.editor:void 0,f=C(i,l),u=new URLSearchParams({column:String(c.column??1),file:a,line:String(c.line??1)});if(i&&u.set("editor",i),t.url=`/?${u.toString()}`,typeof o=="function"){f(t,n,o);return}await new Promise(m=>{f(t,n,()=>{m()})})}catch{b(n)}}},B=(e={})=>{const s=A(e);return async(r,t)=>s(r,t)},H=(e={})=>A(e);export{H as createExpressHandler,B as createNodeHttpHandler,A as createOpenInEditorMiddleware};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/ono",
3
- "version": "2.0.10",
3
+ "version": "2.0.11",
4
4
  "description": "Ono is an error-parsing library that pretty prints JavaScript errors on a web page or the terminal.",
5
5
  "keywords": [
6
6
  "anolilab",