@moneko/core 3.55.15 → 3.55.16

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,5 +1,12 @@
1
1
  import { type ChildProcess } from 'node:child_process';
2
2
  import { type CertificateResult } from '@moneko/utils';
3
+ export declare const CA_ORGANIZATION = "Local Root Certificate Authority - Moneko";
4
+ /**
5
+ * 检查根证书是否已安装
6
+ * @param organization 颁发机构
7
+ * @returns Promise<boolean> 是否已安装
8
+ */
9
+ export declare function isCertificateInstalled(organization: string): Promise<boolean>;
3
10
  /**
4
11
  * 安装本地根 CA 到用户证书存储区(开发时信任 HTTPS 证书)
5
12
  * @param certPath 本地 CA 证书路径
package/lib/commom/ca.mjs CHANGED
@@ -1 +1 @@
1
- import{exec as t}from"node:child_process";import{join as e,relative as r}from"node:path";import{platform as o}from"node:process";import{promisify as i}from"node:util";import{fileExists as a,generateCert as l,loadFile as n,normalCertificateAuthority as c,println as s,saveFile as m}from"@moneko/utils";import u from"./log.mjs";import{getIPv4 as d}from"./net.mjs";import f from"./paths.mjs";let p=i(t);async function y(t){try{if("darwin"===o){let{stdout:e}=await p(`security find-certificate -c "${t}" -a`);return e.length>0}if("win32"===o){let{stdout:e}=await p(`certutil -store -user Root | findstr /C:"${t}"`);return e.length>0}}catch(t){u(t)}return!1}function h(t,e,r){if(t&&!r.includes("already exists"))return void u(t)}export function installCA(e){return"darwin"===o?t(`sudo security add-trusted-cert -d -r trustRoot -k "/Library/Keychains/System.keychain" "${e}"`,h):"win32"===o?t(`certutil -addstore -user "Root" "${e}"`,h):void s(`⚠️ 暂不支持自动安装 CA 的平台: ${o}`)}export async function setupCert(t="localhost",o=!0){let i=r(f.programPath,`${f.corePath}/cert/cert.pem`),s=r(f.programPath,`${f.corePath}/cert/key.pem`),u=!a(i)||!a(s);if(u){let t=c();await Promise.allSettled([m(i,t.cert),m(s,t.key)])}o&&(!await y("Local Root Certificate Authority - Moneko")||u)&&installCA(i);let p=e(f.CA_DIR,`${t}_cert.pem`),h=e(f.CA_DIR,`${t}_key.pem`);if(u||!a(p)||!a(h)){let e=await Promise.all([n(i),n(s)]),r=l(e[0],e[1],[...new Set([t,"localhost","127.0.0.1",d()].filter(Boolean))]);await Promise.allSettled([m(p,r.cert),m(h,r.key)])}let w=await Promise.all([n(p),n(h)]);return{cert:w[0],key:w[1]}}
1
+ import{exec as t}from"node:child_process";import{join as e,relative as r}from"node:path";import{platform as o}from"node:process";import{promisify as i}from"node:util";import{fileExists as a,generateCert as l,loadFile as n,normalCertificateAuthority as c,println as s,saveFile as m}from"@moneko/utils";import f from"./log.mjs";import{getIPv4 as u}from"./net.mjs";import d from"./paths.mjs";let p=i(t);export const CA_ORGANIZATION="Local Root Certificate Authority - Moneko";export async function isCertificateInstalled(t){try{if("darwin"===o){let{stdout:e}=await p(`security find-certificate -c "${t}" -a`);return e.length>0}if("win32"===o){let{stdout:e}=await p(`certutil -store -user Root | findstr /C:"${t}"`);return e.length>0}}catch(t){f(t)}return!1}function y(t,e,r){if(t&&!r.includes("already exists"))return void f(t)}export function installCA(e){return"darwin"===o?t(`sudo security add-trusted-cert -d -r trustRoot -k "/Library/Keychains/System.keychain" "${e}"`,y):"win32"===o?t(`certutil -addstore -user "Root" "${e}"`,y):void s(`⚠️ 暂不支持自动安装 CA 的平台: ${o}`)}export async function setupCert(t="localhost",o=!0){let i=r(d.programPath,`${d.corePath}/cert/cert.pem`),s=r(d.programPath,`${d.corePath}/cert/key.pem`),f=!a(i)||!a(s);if(f){let t=c();await Promise.allSettled([m(i,t.cert),m(s,t.key)])}o&&(!await isCertificateInstalled("Local Root Certificate Authority - Moneko")||f)&&installCA(i);let p=e(d.CA_DIR,`${t}_cert.pem`),y=e(d.CA_DIR,`${t}_key.pem`);if(f||!a(p)||!a(y)){let e=await Promise.all([n(i),n(s)]),r=l(e[0],e[1],[...new Set([t,"localhost","127.0.0.1",u()].filter(Boolean))]);await Promise.allSettled([m(p,r.cert),m(y,r.key)])}let h=await Promise.all([n(p),n(y)]);return{cert:h[0],key:h[1]}}
@@ -1 +1 @@
1
- import{createServer as e}from"node:http";import{createServer as t}from"node:https";import{extname as o,join as r}from"node:path";import n from"../commom/mime.mjs";import i from"../commom/open.mjs";import a from"../commom/paths.mjs";import{CONFIG as s}from"../config.mjs";import m from"../dev/get-cert.mjs";import{setupProxy as c}from"../dev/proxy.mjs";import l,{cacheBody as d}from"./mock.mjs";let p={"Access-Control-Allow-Credentials":"true","Access-Control-Allow-Headers":"Authorization, Content-Type, Accept, X-Requested-With, Origin, DNT, User-Agent, Cache-Control, X-CSRF-Token, X-API-Key, X-Client-Version, X-Device-ID, Content-Language, Accept-Language, X-Custom-Header, X-Mx-ReqToken, Keep-Alive, If-Modified-Since","Access-Control-Allow-Methods":"GET, DELETE, HEAD, OPTIONS, POST, PUT, PATCH, PURGE, LINK, UNLINK, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, REPORT, SEARCH, CONNECT, TRACE","Access-Control-Allow-Origin":"*","Cache-Control":"no-store, no-cache, must-revalidate, proxy-revalidate",Pragma:"no-cache",Expires:"0"};async function C(C){let h=r(C.root_dir,"index.html"),f=l({directory:a.mockPath});function u(e,t,r){let i=e.headers["accept-encoding"],a=i?.includes("br"),s=`${r}.${a?"br":"gz"}`,m=C.fileSystem.existsSync(s);m&&t.setHeader("Content-Encoding",a?"br":"gzip");let c=C.fileSystem.createReadStream(m?s:r,{autoClose:!0});c.on("open",()=>{t.writeHead(200,Object.assign({},p,C.headers,{"Access-Control-Allow-Origin":e.headers.origin??"*","Content-Type":n[o(r)]||"application/octet-stream"}))}),c.on("error",e=>{switch(c.destroy(),e.code){case"ENOENT":t.writeHead(301,{Location:"/index.html"}),t.end();break;case"EACCES":t.writeHead(403,{"Content-Type":"text/plain"}),t.end(`Forbidden: ${e.message}`);break;default:t.writeHead(500,{"Content-Type":"text/plain"}),t.end(`Internal Server Error: ${e.message}`)}}),c.pipe(t)}async function A(e,t){if(d(e),!(C.onRequest&&C.onRequest(e,t))){if(!(s.proxy&&await c(e,t,s.proxy)||t.writableEnded||f&&f(e,t))&&!t.writableEnded){if("GET"===e.method){let o="/"===e.url?h:decodeURIComponent(r(C.root_dir,e.url.replace(C.basename??"/","/")));if(C.fileSystem.existsSync(o))return u(e,t,o)}if(e.headers.accept?.includes("text/html"))return u(e,t,h);t.writeHead(404,{"Content-Type":"text/plain"}),t.end("File Not Found")}}}let E=C.https?t(await m(C.host,!0===C.https?{install:!0}:C.https),A):e(A);return E.listen(C.port),C.open&&i(`${C.https?"https:":"http:"}//${C.host}:${C.port}${"/"===C.basename?"":C.basename}`),E}export default C;
1
+ import{createServer as e}from"node:http";import{createServer as t}from"node:https";import{platform as o}from"node:os";import{extname as r,join as n,sep as i}from"node:path";import{env as s}from"node:process";import{ink as a,println as m}from"@moneko/utils";import{CA_ORGANIZATION as p,isCertificateInstalled as c}from"../commom/ca.mjs";import l from"../commom/mime.mjs";import d from"../commom/open.mjs";import C from"../commom/paths.mjs";import{CONFIG as f}from"../config.mjs";import h from"../dev/get-cert.mjs";import{setupProxy as u}from"../dev/proxy.mjs";import y,{cacheBody as A}from"./mock.mjs";let E={"Access-Control-Allow-Credentials":"true","Access-Control-Allow-Headers":"Authorization, Content-Type, Accept, X-Requested-With, Origin, DNT, User-Agent, Cache-Control, X-CSRF-Token, X-API-Key, X-Client-Version, X-Device-ID, Content-Language, Accept-Language, X-Custom-Header, X-Mx-ReqToken, Keep-Alive, If-Modified-Since","Access-Control-Allow-Methods":"GET, DELETE, HEAD, OPTIONS, POST, PUT, PATCH, PURGE, LINK, UNLINK, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, REPORT, SEARCH, CONNECT, TRACE","Access-Control-Allow-Origin":"*","Cache-Control":"no-store, no-cache, must-revalidate, proxy-revalidate",Pragma:"no-cache",Expires:"0"};async function T(T){let g=n(T.root_dir,"index.html"),w=y({directory:C.mockPath});function O(e,t,o){let n=e.headers["accept-encoding"],i=n?.includes("br"),s=`${o}.${i?"br":"gz"}`,a=T.fileSystem.existsSync(s);a&&t.setHeader("Content-Encoding",i?"br":"gzip");let m=T.fileSystem.createReadStream(a?s:o,{autoClose:!0});m.on("open",()=>{t.writeHead(200,Object.assign({},E,T.headers,{"Access-Control-Allow-Origin":e.headers.origin??"*","Content-Type":l[r(o)]||"application/octet-stream"}))}),m.on("error",e=>{switch(m.destroy(),e.code){case"ENOENT":t.writeHead(301,{Location:"/index.html"}),t.end();break;case"EACCES":t.writeHead(403,{"Content-Type":"text/plain"}),t.end(`Forbidden: ${e.message}`);break;default:t.writeHead(500,{"Content-Type":"text/plain"}),t.end(`Internal Server Error: ${e.message}`)}}),m.pipe(t)}async function x(e,t){if(A(e),!(T.onRequest&&T.onRequest(e,t))){if(!(f.proxy&&await u(e,t,f.proxy)||t.writableEnded||w&&w(e,t))&&!t.writableEnded){if("GET"===e.method){let o="/"===e.url?g:decodeURIComponent(n(T.root_dir,e.url.replace(T.basename??"/","/")));if(T.fileSystem.existsSync(o))return O(e,t,o)}if(e.headers.accept?.includes("text/html"))return O(e,t,g);t.writeHead(404,{"Content-Type":"text/plain"}),t.end("File Not Found")}}}let S=T.https?t(await h(T.host,!0===T.https?{install:!0}:T.https),x):e(x);if(S.listen(T.port),T.https&&!await c(p)&&"darwin"===o()){let e=s.npm_execpath?.split(i).pop()?.split(".").shift()||"npm",t=s.npm_lifecycle_event??"start",o=`> sudo ${e} ${t}`;m(a("⚠️ 未检测到本地 SSL 证书,请通过以下命令重启项目以安装证书: ","yellow")),m(a(o,"yellow")),m("")}return T.open&&d(`${T.https?"https:":"http:"}//${T.host}:${T.port}${"/"===T.basename?"":T.basename}`),S}export default T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneko/core",
3
- "version": "3.55.15",
3
+ "version": "3.55.16",
4
4
  "description": "core",
5
5
  "main": "lib/index.mjs",
6
6
  "type": "module",
@@ -111,12 +111,12 @@
111
111
  "@moneko/convert": "1.1.3",
112
112
  "@moneko/eslint": "1.9.3",
113
113
  "@moneko/mdx": "0.1.44",
114
- "@moneko/raw-import": "1.0.1",
114
+ "@moneko/raw-import": "1.1.0",
115
115
  "@moneko/request": "1.6.2",
116
116
  "@moneko/stylelint": "1.5.0",
117
- "@moneko/transform-imports": "1.1.0",
117
+ "@moneko/transform-imports": "1.2.0",
118
118
  "@moneko/utils": "0.3.3",
119
- "@swc/core": "1.13.19",
119
+ "@swc/core": "1.13.20",
120
120
  "browserslist": "4.26.2",
121
121
  "chokidar": "4.0.3",
122
122
  "core-js": "3.45.1",
@@ -126,7 +126,7 @@
126
126
  "less-loader": "12.3.0",
127
127
  "lightningcss": "1.30.1",
128
128
  "marked-completed": "1.2.14",
129
- "memfs": "4.46.1",
129
+ "memfs": "4.47.0",
130
130
  "mini-css-extract-plugin": "2.9.4",
131
131
  "style-loader": "4.0.0",
132
132
  "swc-loader": "0.2.6",
@@ -156,4 +156,4 @@
156
156
  "typings"
157
157
  ],
158
158
  "packageManager": "pnpm@10.15.0"
159
- }
159
+ }