@initx-plugin/core 0.1.1 → 0.1.2

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