@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.
- package/CHANGELOG.md +2 -0
- package/dist/error-inspector/page/create-request-context.d.ts +1 -1
- package/dist/index.d.ts +39 -39
- package/dist/index.js +54 -54
- package/dist/packem_shared/{types.d-D1UE67tt.d.ts → types.d-Dm3db2h3.d.ts} +1 -1
- package/dist/server/open-in-editor.d.ts +12 -12
- package/dist/server/open-in-editor.js +1 -1
- package/package.json +1 -1
|
@@ -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
|
|
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};
|