@initx-plugin/core 0.0.35 → 0.0.36

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
@@ -114,9 +114,10 @@ declare abstract class InitxPlugin<TStore extends object = object> {
114
114
  private executeHandle;
115
115
  }
116
116
 
117
+ declare function detectManager(): boolean;
117
118
  declare function installManager(): Promise<void>;
118
119
 
119
120
  declare function createStore(name: string, defaultStore?: Record<string, any>): Record<string, any>;
120
121
  declare function writeStore(name: string): void;
121
122
 
122
- export { type HandlerInfo, INITX_DIR, type InitxBaseContext, type InitxContext, type InitxMatcherRules, InitxPlugin, type InitxPluginInfo, type LoadPluginResult, type MatchedPlugin, NODE_MODULES_DIR, PLUGIN_DIR, type PackageInfo, STORE_DIR, STORE_FILE_NAME, createStore, fetchPlugins, installManager, loadPlugins, matchPlugins, withPluginPrefix, writeStore };
123
+ export { type HandlerInfo, INITX_DIR, type InitxBaseContext, type InitxContext, type InitxMatcherRules, InitxPlugin, type InitxPluginInfo, type LoadPluginResult, type MatchedPlugin, NODE_MODULES_DIR, PLUGIN_DIR, type PackageInfo, STORE_DIR, STORE_FILE_NAME, createStore, detectManager, fetchPlugins, installManager, loadPlugins, matchPlugins, withPluginPrefix, writeStore };
package/dist/index.d.ts CHANGED
@@ -114,9 +114,10 @@ declare abstract class InitxPlugin<TStore extends object = object> {
114
114
  private executeHandle;
115
115
  }
116
116
 
117
+ declare function detectManager(): boolean;
117
118
  declare function installManager(): Promise<void>;
118
119
 
119
120
  declare function createStore(name: string, defaultStore?: Record<string, any>): Record<string, any>;
120
121
  declare function writeStore(name: string): void;
121
122
 
122
- export { type HandlerInfo, INITX_DIR, type InitxBaseContext, type InitxContext, type InitxMatcherRules, InitxPlugin, type InitxPluginInfo, type LoadPluginResult, type MatchedPlugin, NODE_MODULES_DIR, PLUGIN_DIR, type PackageInfo, STORE_DIR, STORE_FILE_NAME, createStore, fetchPlugins, installManager, loadPlugins, matchPlugins, withPluginPrefix, writeStore };
123
+ export { type HandlerInfo, INITX_DIR, type InitxBaseContext, type InitxContext, type InitxMatcherRules, InitxPlugin, type InitxPluginInfo, type LoadPluginResult, type MatchedPlugin, NODE_MODULES_DIR, PLUGIN_DIR, type PackageInfo, STORE_DIR, STORE_FILE_NAME, createStore, detectManager, fetchPlugins, installManager, loadPlugins, matchPlugins, withPluginPrefix, writeStore };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{platform as R,homedir as b}from"node:os";import a,{resolve as m}from"pathe";import{useInitxMatcher as $}from"matchinitx";import{defu as E}from"defu";import c from"fs-extra";import S from"node:process";import{c as J}from"@initx-plugin/utils";const L=R()==="win32",y=m(b(),".initx"),g=m(y,"stores"),w="store.json",l=m(y,"plugins"),f=L?"node_modules":"lib/node_modules";let h=!1,x={};const I=o=>a.resolve(g,o,w);function v(o,t={}){c.ensureDirSync(a.resolve(g,o));const n=I(o),r=i=>(P(n,i),M(i));if(!c.existsSync(n))return r(t);let e;try{const i=c.readJsonSync(n);e=E(i,t)}catch{e=t}return r(e)}function k(o){h&&P(I(o),x)}function P(o,t){c.writeJsonSync(o,t,{spaces:2})}function M(o={}){const t=r=>typeof r=="object"&&r!==null&&new Set(["[object Object]","[object Array]"]).has(Object.prototype.toString.call(r)),n=r=>new Proxy(r,{get(e,i){const s=Reflect.get(e,i);return t(s)?n(s):s},set(e,i,s){const u=Reflect.set(e,i,s);return h=!0,u},deleteProperty(e,i){const s=Reflect.deleteProperty(e,i);return h=!0,s}});return x=n(o),x}const d={plugin:/^(?:@initx-plugin\/|initx-plugin-)/,exclude:/@initx-plugin\/(?:core|utils)$/};async function N(){const o=a.resolve(S.cwd(),"package.json");if(!c.existsSync(o))return[];const t=c.readJsonSync(o),{dependencies:n={},devDependencies:r={}}=t;return Object.keys({...n,...r}).filter(e=>d.plugin.test(e)&&!d.exclude.test(e)).map(e=>({name:e,root:a.resolve(S.cwd(),"node_modules",e)}))}async function O(){c.ensureDirSync(l);const o=c.readdirSync(a.resolve(l,f)),t=a.resolve(l,f,"@initx-plugin");return[...c.existsSync(t)?c.readdirSync(t).map(n=>`@initx-plugin/${n}`):[],...o].filter(n=>d.plugin.test(n)&&!d.exclude.test(n)).map(n=>({name:n,root:a.resolve(l,f,n)}))}async function T(){const o=await N(),t=o.map(({name:e})=>e),n=[...(await O()).filter(({name:e})=>!t.includes(e)),...o],r=await import("importx");return Promise.all(n.map(async({root:e})=>{const i=await r.import(e,import.meta.url).then(u=>u.default),s=c.readJsonSync(a.resolve(e,"package.json"));return{packageInfo:{root:e,name:s.name,version:s.version,description:s.description,author:s.author,homepage:s.homepage},instance:new i}}))}async function A(o,{key:t,cliOptions:n},...r){const e=[];for(const i of o){const{instance:s,packageInfo:u}=i,D=await s.run({key:t,cliOptions:n,packageInfo:u,optionsList:Object.keys(n).filter(p=>n[p]===!0).map(p=>`--${p}`)},...r);e.push(...D.map(p=>({handler:p.handler,description:p.description,packageInfo:u})))}return e}function H(o,t){return o.some(n=>typeof n=="string"||typeof n>"u"?n===t:n.test(t))}function j(o){return o.push("--prefix",l),o}class U{defaultStore;async run(t,...n){const r=$((e,...i)=>({handler:()=>this.executeHandle(t,e,...i),...e}));return(await Promise.all(r.match(this.rules,t.key,...n).map(async e=>e.verify&&!e.verify(t,...n)||e.optional&&!H(e.optional,n[0])?!1:e))).filter(Boolean)}async executeHandle(t,n,...r){const e=v(t.packageInfo.name,this.defaultStore);await this.handle({...t,rule:n,store:e},...r),k(t.packageInfo.name)}}const _="@initx-plugin/manager";function B(){return c.existsSync(m(l,f,_))}async function F(){B()||await J("npm",j(["install",_]))}export{y as INITX_DIR,U as InitxPlugin,f as NODE_MODULES_DIR,l as PLUGIN_DIR,g as STORE_DIR,w as STORE_FILE_NAME,v as createStore,O as fetchPlugins,F as installManager,T as loadPlugins,A as matchPlugins,j as withPluginPrefix,k as writeStore};
1
+ import{homedir as D}from"node:os";import c from"fs-extra";import a,{resolve as f}from"pathe";import{useInitxMatcher as R}from"matchinitx";import{defu as E}from"defu";import S from"node:process";import{c as $}from"@initx-plugin/utils";const y=f(D(),".initx"),g=f(y,"stores"),w="store.json",l=f(y,"plugins"),m=c.existsSync(f(l,"lib"))?"lib/node_modules":"node_modules";let h=!1,x={};const I=o=>a.resolve(g,o,w);function v(o,t={}){c.ensureDirSync(a.resolve(g,o));const n=I(o),r=i=>(P(n,i),M(i));if(!c.existsSync(n))return r(t);let e;try{const i=c.readJsonSync(n);e=E(i,t)}catch{e=t}return r(e)}function k(o){h&&P(I(o),x)}function P(o,t){c.writeJsonSync(o,t,{spaces:2})}function M(o={}){const t=r=>typeof r=="object"&&r!==null&&new Set(["[object Object]","[object Array]"]).has(Object.prototype.toString.call(r)),n=r=>new Proxy(r,{get(e,i){const s=Reflect.get(e,i);return t(s)?n(s):s},set(e,i,s){const u=Reflect.set(e,i,s);return h=!0,u},deleteProperty(e,i){const s=Reflect.deleteProperty(e,i);return h=!0,s}});return x=n(o),x}const d={plugin:/^(?:@initx-plugin\/|initx-plugin-)/,exclude:/@initx-plugin\/(?:core|utils)$/};async function J(){const o=a.resolve(S.cwd(),"package.json");if(!c.existsSync(o))return[];const t=c.readJsonSync(o),{dependencies:n={},devDependencies:r={}}=t;return Object.keys({...n,...r}).filter(e=>d.plugin.test(e)&&!d.exclude.test(e)).map(e=>({name:e,root:a.resolve(S.cwd(),"node_modules",e)}))}async function O(){c.ensureDirSync(l);const o=c.readdirSync(a.resolve(l,m)),t=a.resolve(l,m,"@initx-plugin");return[...c.existsSync(t)?c.readdirSync(t).map(n=>`@initx-plugin/${n}`):[],...o].filter(n=>d.plugin.test(n)&&!d.exclude.test(n)).map(n=>({name:n,root:a.resolve(l,m,n)}))}async function L(){const o=await J(),t=o.map(({name:e})=>e),n=[...(await O()).filter(({name:e})=>!t.includes(e)),...o],r=await import("importx");return Promise.all(n.map(async({root:e})=>{const i=await r.import(e,import.meta.url).then(u=>u.default),s=c.readJsonSync(a.resolve(e,"package.json"));return{packageInfo:{root:e,name:s.name,version:s.version,description:s.description,author:s.author,homepage:s.homepage},instance:new i}}))}async function N(o,{key:t,cliOptions:n},...r){const e=[];for(const i of o){const{instance:s,packageInfo:u}=i,b=await s.run({key:t,cliOptions:n,packageInfo:u,optionsList:Object.keys(n).filter(p=>n[p]===!0).map(p=>`--${p}`)},...r);e.push(...b.map(p=>({handler:p.handler,description:p.description,packageInfo:u})))}return e}function T(o,t){return o.some(n=>typeof n=="string"||typeof n>"u"?n===t:n.test(t))}function j(o){return o.push("--prefix",l),o}class A{defaultStore;async run(t,...n){const r=R((e,...i)=>({handler:()=>this.executeHandle(t,e,...i),...e}));return(await Promise.all(r.match(this.rules,t.key,...n).map(async e=>e.verify&&!e.verify(t,...n)||e.optional&&!T(e.optional,n[0])?!1:e))).filter(Boolean)}async executeHandle(t,n,...r){const e=v(t.packageInfo.name,this.defaultStore);await this.handle({...t,rule:n,store:e},...r),k(t.packageInfo.name)}}const _="@initx-plugin/manager";function H(){return c.existsSync(f(l,m,_))}async function U(){await $("npm",j(["install",_]))}export{y as INITX_DIR,A as InitxPlugin,m as NODE_MODULES_DIR,l as PLUGIN_DIR,g as STORE_DIR,w as STORE_FILE_NAME,v as createStore,H as detectManager,O as fetchPlugins,U as installManager,L as loadPlugins,N as matchPlugins,j as withPluginPrefix,k 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.35",
4
+ "version": "0.0.36",
5
5
  "description": "core module for initx plugins",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/initx-collective/initx#readme",
@@ -27,7 +27,7 @@
27
27
  "importx": "^0.5.2",
28
28
  "matchinitx": "^0.0.4",
29
29
  "pathe": "^2.0.3",
30
- "@initx-plugin/utils": "0.0.35"
30
+ "@initx-plugin/utils": "0.0.36"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/fs-extra": "^11.0.4"