@initx-plugin/core 0.0.30 → 0.0.31

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/dist/index.d.mts CHANGED
@@ -107,7 +107,7 @@ declare abstract class InitxPlugin<TStore extends object = object> {
107
107
  private executeHandle;
108
108
  }
109
109
 
110
- declare function createStore(name: string, defaultStore?: Record<string, any>): any;
110
+ declare function createStore(name: string, defaultStore?: Record<string, any>): Record<string, any>;
111
111
  declare function writeStore(name: string): void;
112
112
 
113
113
  export { type HandlerInfo, type InitxBaseContext, type InitxContext, type InitxMatcherRules, InitxPlugin, type InitxPluginInfo, type LoadPluginResult, type MatchedPlugin, type PackageInfo, createStore, fetchPlugins, loadPlugins, matchPlugins, writeStore };
package/dist/index.d.ts CHANGED
@@ -107,7 +107,7 @@ declare abstract class InitxPlugin<TStore extends object = object> {
107
107
  private executeHandle;
108
108
  }
109
109
 
110
- declare function createStore(name: string, defaultStore?: Record<string, any>): any;
110
+ declare function createStore(name: string, defaultStore?: Record<string, any>): Record<string, any>;
111
111
  declare function writeStore(name: string): void;
112
112
 
113
113
  export { type HandlerInfo, type InitxBaseContext, type InitxContext, type InitxMatcherRules, InitxPlugin, type InitxPluginInfo, type LoadPluginResult, type MatchedPlugin, type PackageInfo, createStore, fetchPlugins, loadPlugins, matchPlugins, writeStore };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{useInitxMatcher as j}from"matchinitx";import{homedir as k}from"node:os";import s from"node:path";import{defu as v}from"defu";import c from"fs-extra";import f from"node:process";import{c as I}from"@initx-plugin/utils";let m=null;const d=s.resolve(k(),".initx"),O="store.json",y=o=>s.resolve(d,o,O);function g(o,t={}){c.ensureDirSync(s.resolve(d,o));const n=y(o),i=r=>(x(n,r),P(r));if(!c.existsSync(n))return i(t);let e;try{const r=c.readJsonSync(n);e=v(r,t)}catch{e=t}return i(e)}function h(o){m&&x(y(o),m)}function x(o,t){c.writeJsonSync(o,t,{spaces:2})}function P(o={}){const t=i=>Object.prototype.toString.call(i)==="[object Object]",n=i=>new Proxy(i,{get(e,r){const a=Reflect.get(e,r);return t(a)?n(a):a},set(e,r,a){const l=Reflect.set(e,r,a);return m=e,l}});return n(o)}const p={plugin:/^(?:@initx-plugin\/|initx-plugin-)/,exclude:/@initx-plugin\/(?:core|utils)$/};async function $(){const o=s.join(f.cwd(),"package.json");if(!c.existsSync(o))return[];const t=c.readJsonSync(o),{dependencies:n={},devDependencies:i={}}=t;return Object.keys({...n,...i}).filter(e=>p.plugin.test(e)&&!p.exclude.test(e)).map(e=>({name:e,root:s.join(f.cwd(),"node_modules",e)}))}async function S(){const{content:o}=await I("npm",["root","-g"]),t=c.readdirSync(o),n=s.join(o,"@initx-plugin");return[...c.existsSync(n)?c.readdirSync(n).map(i=>`@initx-plugin/${i}`):[],...t].filter(i=>p.plugin.test(i)&&!p.exclude.test(i)).map(i=>({name:i,root:s.join(o,i)}))}async function b(){const o=await $(),t=o.map(({name:e})=>e),n=[...(await S()).filter(({name:e})=>!t.includes(e)),...o],i=await import("importx");return Promise.all(n.map(async({root:e})=>{const r=await i.import(e,import.meta.url).then(l=>l.default),a=c.readJsonSync(s.join(e,"package.json"));return{packageInfo:{root:e,name:a.name,version:a.version,description:a.description,author:a.author,homepage:a.homepage},instance:new r}}))}async function J(o,{key:t,cliOptions:n},...i){const e=[];for(const r of o){const{instance:a,packageInfo:l}=r,w=await a.run({key:t,cliOptions:n,packageInfo:l,optionsList:Object.keys(n).filter(u=>n[u]===!0).map(u=>`--${u}`)},...i);e.push(...w.map(u=>({handler:u.handler,description:u.description,packageInfo:l})))}return e}function D(o,t){return o.some(n=>typeof n=="string"||typeof n>"u"?n===t:n.test(t))}class H{defaultStore;async run(t,...n){const i=j((e,...r)=>({handler:()=>this.executeHandle(t,e,...r),...e}));return(await Promise.all(i.match(this.rules,t.key,...n).map(async e=>e.verify&&!e.verify(t,...n)||e.optional&&!D(e.optional,n[0])?!1:e))).filter(Boolean)}async executeHandle(t,n,...i){const e=g(t.packageInfo.name,this.defaultStore);await this.handle({...t,rule:n,store:e},...i),h(t.packageInfo.name)}}export{H as InitxPlugin,g as createStore,S as fetchPlugins,b as loadPlugins,J as matchPlugins,h as writeStore};
1
+ import{useInitxMatcher as k}from"matchinitx";import{homedir as P}from"node:os";import{defu as v}from"defu";import c from"fs-extra";import s from"pathe";import d from"node:process";import{c as I}from"@initx-plugin/utils";let f=!1,m={};const y=s.resolve(P(),".initx"),$="store.json",g=r=>s.resolve(y,r,$);function h(r,n={}){c.ensureDirSync(s.resolve(y,r));const t=g(r),o=i=>(j(t,i),b(i));if(!c.existsSync(t))return o(n);let e;try{const i=c.readJsonSync(t);e=v(i,n)}catch{e=n}return o(e)}function x(r){f&&j(g(r),m)}function j(r,n){c.writeJsonSync(r,n,{spaces:2})}function b(r={}){const n=o=>typeof o=="object"&&o!==null&&new Set(["[object Object]","[object Array]"]).has(Object.prototype.toString.call(o)),t=o=>new Proxy(o,{get(e,i){const a=Reflect.get(e,i);return n(a)?t(a):a},set(e,i,a){const l=Reflect.set(e,i,a);return f=!0,l},deleteProperty(e,i){const a=Reflect.deleteProperty(e,i);return f=!0,a}});return m=t(r),m}const p={plugin:/^(?:@initx-plugin\/|initx-plugin-)/,exclude:/@initx-plugin\/(?:core|utils)$/};async function O(){const r=s.join(d.cwd(),"package.json");if(!c.existsSync(r))return[];const n=c.readJsonSync(r),{dependencies:t={},devDependencies:o={}}=n;return Object.keys({...t,...o}).filter(e=>p.plugin.test(e)&&!p.exclude.test(e)).map(e=>({name:e,root:s.join(d.cwd(),"node_modules",e)}))}async function S(){const{content:r}=await I("npm",["root","-g"]),n=c.readdirSync(r),t=s.join(r,"@initx-plugin");return[...c.existsSync(t)?c.readdirSync(t).map(o=>`@initx-plugin/${o}`):[],...n].filter(o=>p.plugin.test(o)&&!p.exclude.test(o)).map(o=>({name:o,root:s.join(r,o)}))}async function J(){const r=await O(),n=r.map(({name:e})=>e),t=[...(await S()).filter(({name:e})=>!n.includes(e)),...r],o=await import("importx");return Promise.all(t.map(async({root:e})=>{const i=await o.import(e,import.meta.url).then(l=>l.default),a=c.readJsonSync(s.join(e,"package.json"));return{packageInfo:{root:e,name:a.name,version:a.version,description:a.description,author:a.author,homepage:a.homepage},instance:new i}}))}async function R(r,{key:n,cliOptions:t},...o){const e=[];for(const i of r){const{instance:a,packageInfo:l}=i,w=await a.run({key:n,cliOptions:t,packageInfo:l,optionsList:Object.keys(t).filter(u=>t[u]===!0).map(u=>`--${u}`)},...o);e.push(...w.map(u=>({handler:u.handler,description:u.description,packageInfo:l})))}return e}function D(r,n){return r.some(t=>typeof t=="string"||typeof t>"u"?t===n:t.test(n))}class H{defaultStore;async run(n,...t){const o=k((e,...i)=>({handler:()=>this.executeHandle(n,e,...i),...e}));return(await Promise.all(o.match(this.rules,n.key,...t).map(async e=>e.verify&&!e.verify(n,...t)||e.optional&&!D(e.optional,t[0])?!1:e))).filter(Boolean)}async executeHandle(n,t,...o){const e=h(n.packageInfo.name,this.defaultStore);await this.handle({...n,rule:t,store:e},...o),x(n.packageInfo.name)}}export{H as InitxPlugin,h as createStore,S as fetchPlugins,J as loadPlugins,R as matchPlugins,x as writeStore};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@initx-plugin/core",
3
3
  "type": "module",
4
- "version": "0.0.30",
4
+ "version": "0.0.31",
5
5
  "description": "core module for initx plugins",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/initx-collective/initx#readme",
@@ -26,7 +26,8 @@
26
26
  "fs-extra": "^11.3.0",
27
27
  "importx": "^0.5.2",
28
28
  "matchinitx": "^0.0.4",
29
- "@initx-plugin/utils": "0.0.30"
29
+ "pathe": "^2.0.3",
30
+ "@initx-plugin/utils": "0.0.31"
30
31
  },
31
32
  "devDependencies": {
32
33
  "@types/fs-extra": "^11.0.4"