@initx-plugin/core 0.3.1 → 0.3.3
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 +4 -81
- package/dist/index.d.ts +4 -81
- package/dist/index.mjs +1 -1
- package/package.json +3 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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;
|
|
5
6
|
declare const STORE_FILE_NAME = "store.json";
|
|
6
7
|
declare const PLUGIN_DIR: string;
|
|
7
|
-
declare const PLUGINS_CACHE_FILE = ".plugins.json";
|
|
8
8
|
declare const NODE_MODULES_DIR: string;
|
|
9
9
|
|
|
10
10
|
type MaybePromise<T> = T | Promise<T>;
|
|
@@ -120,88 +120,11 @@ declare abstract class InitxPlugin<TStore extends object = object> {
|
|
|
120
120
|
declare function detectManager(): Promise<boolean>;
|
|
121
121
|
declare function installManager(): Promise<void>;
|
|
122
122
|
|
|
123
|
-
interface PluginOptions {
|
|
124
|
-
/**
|
|
125
|
-
* Custom plugin directory path
|
|
126
|
-
* @default `~/.initx/plugins`
|
|
127
|
-
*/
|
|
128
|
-
pluginDir?: string;
|
|
129
|
-
/**
|
|
130
|
-
* Custom npm registry URL
|
|
131
|
-
* @default 'https://registry.npmjs.org'
|
|
132
|
-
*/
|
|
133
|
-
registry?: string;
|
|
134
|
-
/**
|
|
135
|
-
* Custom npm executable path
|
|
136
|
-
* @default 'npm'
|
|
137
|
-
*/
|
|
138
|
-
npmPath?: string;
|
|
139
|
-
}
|
|
140
|
-
interface PluginSystem<T = any> {
|
|
141
|
-
search: (keyword: string) => Promise<SearchResult[]>;
|
|
142
|
-
install: (packageName: string, version?: string) => Promise<void>;
|
|
143
|
-
uninstall: (packageName: string) => Promise<void>;
|
|
144
|
-
list: () => Promise<PluginInfo[]>;
|
|
145
|
-
update: (packageName: string, version?: string) => Promise<void>;
|
|
146
|
-
load: (packageName: string) => Promise<T>;
|
|
147
|
-
resolve: (packageName: string, ...paths: string[]) => string;
|
|
148
|
-
}
|
|
149
|
-
interface SearchResult {
|
|
150
|
-
name: string;
|
|
151
|
-
version: string;
|
|
152
|
-
description: string;
|
|
153
|
-
}
|
|
154
|
-
interface PluginInfo {
|
|
155
|
-
name: string;
|
|
156
|
-
version: string;
|
|
157
|
-
description: string;
|
|
158
|
-
isLocal: boolean;
|
|
159
|
-
}
|
|
160
|
-
interface NpmPackageInfo {
|
|
161
|
-
version: string;
|
|
162
|
-
resolved: string;
|
|
163
|
-
overridden: boolean;
|
|
164
|
-
description: string;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* NPM-based plugin system using native Node.js APIs
|
|
169
|
-
*/
|
|
170
|
-
declare class NpmPluginSystem<T = any> implements PluginSystem<T> {
|
|
171
|
-
private readonly npmManager;
|
|
172
|
-
private readonly pluginLoader;
|
|
173
|
-
private readonly pluginDir;
|
|
174
|
-
constructor(id: string, options?: PluginOptions);
|
|
175
|
-
search(keyword: string): Promise<SearchResult[]>;
|
|
176
|
-
install(packageName: string, version?: string): Promise<void>;
|
|
177
|
-
uninstall(packageName: string): Promise<void>;
|
|
178
|
-
list(): Promise<PluginInfo[]>;
|
|
179
|
-
update(packageName: string, version?: string): Promise<void>;
|
|
180
|
-
load(packageName: string): Promise<T>;
|
|
181
|
-
resolve(packageName: string, ...paths: string[]): string;
|
|
182
|
-
/**
|
|
183
|
-
* Ensure plugin cache is valid. Rebuild if invalid.
|
|
184
|
-
* Call this after updating core packages or if cache was manually deleted.
|
|
185
|
-
*/
|
|
186
|
-
ensureCacheValid(): Promise<void>;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
123
|
type Constructor<T> = new (...args: any[]) => T;
|
|
190
|
-
|
|
191
|
-
* Create a plugin system instance
|
|
192
|
-
*/
|
|
193
|
-
declare function createNpmPlugin<T = any>(id: string, options?: {
|
|
194
|
-
pluginDir?: string;
|
|
195
|
-
registry?: string;
|
|
196
|
-
npmPath?: string;
|
|
197
|
-
}): NpmPluginSystem<T>;
|
|
198
|
-
/**
|
|
199
|
-
* Global plugin system instance for initx
|
|
200
|
-
*/
|
|
201
|
-
declare const pluginSystem: NpmPluginSystem<Constructor<InitxPlugin<object>>>;
|
|
124
|
+
declare const pluginSystem: npm_plugin_kit.PluginSystem<Constructor<InitxPlugin<object>>>;
|
|
202
125
|
|
|
203
126
|
declare function createStore(name: string, defaultStore?: Record<string, any>): Record<string, any>;
|
|
204
127
|
declare function writeStore(name: string): void;
|
|
205
128
|
|
|
206
|
-
export { INITX_DIR, InitxPlugin, NODE_MODULES_DIR,
|
|
207
|
-
export type { HandlerInfo, InitxBaseContext, InitxContext, InitxMatcherRules, InitxPluginInfo, LoadPluginResult, MatchedPlugin,
|
|
129
|
+
export { INITX_DIR, InitxPlugin, NODE_MODULES_DIR, PLUGIN_DIR, STORE_DIR, STORE_FILE_NAME, createStore, detectManager, fetchPlugins, installManager, loadPlugins, matchPlugins, pluginSystem, withPluginPrefix, writeStore };
|
|
130
|
+
export type { HandlerInfo, InitxBaseContext, InitxContext, InitxMatcherRules, InitxPluginInfo, LoadPluginResult, MatchedPlugin, PackageInfo };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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;
|
|
5
6
|
declare const STORE_FILE_NAME = "store.json";
|
|
6
7
|
declare const PLUGIN_DIR: string;
|
|
7
|
-
declare const PLUGINS_CACHE_FILE = ".plugins.json";
|
|
8
8
|
declare const NODE_MODULES_DIR: string;
|
|
9
9
|
|
|
10
10
|
type MaybePromise<T> = T | Promise<T>;
|
|
@@ -120,88 +120,11 @@ declare abstract class InitxPlugin<TStore extends object = object> {
|
|
|
120
120
|
declare function detectManager(): Promise<boolean>;
|
|
121
121
|
declare function installManager(): Promise<void>;
|
|
122
122
|
|
|
123
|
-
interface PluginOptions {
|
|
124
|
-
/**
|
|
125
|
-
* Custom plugin directory path
|
|
126
|
-
* @default `~/.initx/plugins`
|
|
127
|
-
*/
|
|
128
|
-
pluginDir?: string;
|
|
129
|
-
/**
|
|
130
|
-
* Custom npm registry URL
|
|
131
|
-
* @default 'https://registry.npmjs.org'
|
|
132
|
-
*/
|
|
133
|
-
registry?: string;
|
|
134
|
-
/**
|
|
135
|
-
* Custom npm executable path
|
|
136
|
-
* @default 'npm'
|
|
137
|
-
*/
|
|
138
|
-
npmPath?: string;
|
|
139
|
-
}
|
|
140
|
-
interface PluginSystem<T = any> {
|
|
141
|
-
search: (keyword: string) => Promise<SearchResult[]>;
|
|
142
|
-
install: (packageName: string, version?: string) => Promise<void>;
|
|
143
|
-
uninstall: (packageName: string) => Promise<void>;
|
|
144
|
-
list: () => Promise<PluginInfo[]>;
|
|
145
|
-
update: (packageName: string, version?: string) => Promise<void>;
|
|
146
|
-
load: (packageName: string) => Promise<T>;
|
|
147
|
-
resolve: (packageName: string, ...paths: string[]) => string;
|
|
148
|
-
}
|
|
149
|
-
interface SearchResult {
|
|
150
|
-
name: string;
|
|
151
|
-
version: string;
|
|
152
|
-
description: string;
|
|
153
|
-
}
|
|
154
|
-
interface PluginInfo {
|
|
155
|
-
name: string;
|
|
156
|
-
version: string;
|
|
157
|
-
description: string;
|
|
158
|
-
isLocal: boolean;
|
|
159
|
-
}
|
|
160
|
-
interface NpmPackageInfo {
|
|
161
|
-
version: string;
|
|
162
|
-
resolved: string;
|
|
163
|
-
overridden: boolean;
|
|
164
|
-
description: string;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* NPM-based plugin system using native Node.js APIs
|
|
169
|
-
*/
|
|
170
|
-
declare class NpmPluginSystem<T = any> implements PluginSystem<T> {
|
|
171
|
-
private readonly npmManager;
|
|
172
|
-
private readonly pluginLoader;
|
|
173
|
-
private readonly pluginDir;
|
|
174
|
-
constructor(id: string, options?: PluginOptions);
|
|
175
|
-
search(keyword: string): Promise<SearchResult[]>;
|
|
176
|
-
install(packageName: string, version?: string): Promise<void>;
|
|
177
|
-
uninstall(packageName: string): Promise<void>;
|
|
178
|
-
list(): Promise<PluginInfo[]>;
|
|
179
|
-
update(packageName: string, version?: string): Promise<void>;
|
|
180
|
-
load(packageName: string): Promise<T>;
|
|
181
|
-
resolve(packageName: string, ...paths: string[]): string;
|
|
182
|
-
/**
|
|
183
|
-
* Ensure plugin cache is valid. Rebuild if invalid.
|
|
184
|
-
* Call this after updating core packages or if cache was manually deleted.
|
|
185
|
-
*/
|
|
186
|
-
ensureCacheValid(): Promise<void>;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
123
|
type Constructor<T> = new (...args: any[]) => T;
|
|
190
|
-
|
|
191
|
-
* Create a plugin system instance
|
|
192
|
-
*/
|
|
193
|
-
declare function createNpmPlugin<T = any>(id: string, options?: {
|
|
194
|
-
pluginDir?: string;
|
|
195
|
-
registry?: string;
|
|
196
|
-
npmPath?: string;
|
|
197
|
-
}): NpmPluginSystem<T>;
|
|
198
|
-
/**
|
|
199
|
-
* Global plugin system instance for initx
|
|
200
|
-
*/
|
|
201
|
-
declare const pluginSystem: NpmPluginSystem<Constructor<InitxPlugin<object>>>;
|
|
124
|
+
declare const pluginSystem: npm_plugin_kit.PluginSystem<Constructor<InitxPlugin<object>>>;
|
|
202
125
|
|
|
203
126
|
declare function createStore(name: string, defaultStore?: Record<string, any>): Record<string, any>;
|
|
204
127
|
declare function writeStore(name: string): void;
|
|
205
128
|
|
|
206
|
-
export { INITX_DIR, InitxPlugin, NODE_MODULES_DIR,
|
|
207
|
-
export type { HandlerInfo, InitxBaseContext, InitxContext, InitxMatcherRules, InitxPluginInfo, LoadPluginResult, MatchedPlugin,
|
|
129
|
+
export { INITX_DIR, InitxPlugin, NODE_MODULES_DIR, PLUGIN_DIR, STORE_DIR, STORE_FILE_NAME, createStore, detectManager, fetchPlugins, installManager, loadPlugins, matchPlugins, pluginSystem, withPluginPrefix, writeStore };
|
|
130
|
+
export type { HandlerInfo, InitxBaseContext, InitxContext, InitxMatcherRules, InitxPluginInfo, LoadPluginResult, MatchedPlugin, PackageInfo };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{homedir as
|
|
1
|
+
import{homedir as j}from"node:os";import c 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=c.existsSync(m(p,"lib"))?"lib/node_modules":"node_modules";let h=!1,x={};const v=e=>u.resolve(g,e,S);function w(e,o={}){c.ensureDirSync(u.resolve(g,e));const t=v(e),r=i=>(k(t,i),N(i));if(!c.existsSync(t))return r(o);let n;try{const i=c.readJsonSync(t);n=D(i,o)}catch{n=o}return r(n)}function I(e){h&&k(v(e),x)}function k(e,o){c.writeJsonSync(e,o,{spaces:2})}function N(e={}){const o=r=>typeof r=="object"&&r!==null&&new Set(["[object Object]","[object Array]"]).has(Object.prototype.toString.call(r)),t=r=>new Proxy(r,{get(n,i){const s=Reflect.get(n,i);return o(s)?t(s):s},set(n,i,s){const a=Reflect.set(n,i,s);return h=!0,a},deleteProperty(n,i){const s=Reflect.deleteProperty(n,i);return h=!0,s}});return x=t(e),x}const f=E("initx",{pluginDir:p}),d={plugin:/^(?:@initx-plugin\/|initx-plugin-)/,exclude:/@initx-plugin\/(?:core|utils)$/};async function J(e){const o=u.resolve(e,"package.json");if(!c.existsSync(o))return[];const t=c.readJsonSync(o),{dependencies:r={},devDependencies:n={}}=t,i=[];return Object.keys({...r,...n}).forEach(s=>{if(!d.plugin.test(s)||d.exclude.test(s))return;const a=u.resolve(e,"node_modules",s);c.existsSync(a)&&i.push({name:s,version:t.version,description:t.description,root:a})}),i}async function L(){return J(R.cwd())}async function P(){return(await f.list()).filter(e=>d.plugin.test(e.name)&&!d.exclude.test(e.name)).map(e=>({name:e.name,version:e.version,description:e.description,root:u.resolve(p,"node_modules",e.name)}))}async function T(){const e=await L(),o=e.map(({name:r})=>r),t=[...(await P()).filter(({name:r})=>!o.includes(r)),...e];return Promise.all(t.map(async({name:r,root:n})=>{const i=await f.load(r),s=c.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:o,cliOptions:t},...r){const n=[];for(const i of e){const{instance:s,packageInfo:a}=i,_=await s.run({key:o,cliOptions:t,packageInfo:a,optionsList:Object.keys(t).filter(l=>t[l]===!0).map(l=>`--${l}`)},...r);n.push(..._.map(l=>({handler:l.handler,description:l.description,packageInfo:a})))}return n}function H(e,o){return e.some(t=>typeof t=="string"||typeof t>"u"?t===o:t.test(o))}function U(e){return e.push("--prefix",p),e}class B{defaultStore;async run(o,...t){const r=b((n,...i)=>({handler:()=>this.executeHandle(o,n,...i),...n}));return(await Promise.all(r.match(this.rules,o.key,...t).map(async n=>n.verify&&!n.verify(o,...t)||n.optional&&!H(n.optional,t[0])?!1:n))).filter(Boolean)}async executeHandle(o,t,...r){const n=w(o.packageInfo.name,this.defaultStore);await this.handle({...o,rule:t,store:n},...r),I(o.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,w as createStore,F as detectManager,P as fetchPlugins,G as installManager,T as loadPlugins,A as matchPlugins,f as pluginSystem,U as withPluginPrefix,I 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.3.
|
|
4
|
+
"version": "0.3.3",
|
|
5
5
|
"description": "core module for initx plugins",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/initx-collective/initx#readme",
|
|
@@ -25,8 +25,9 @@
|
|
|
25
25
|
"defu": "^6.1.4",
|
|
26
26
|
"fs-extra": "^11.3.4",
|
|
27
27
|
"matchinitx": "^0.0.4",
|
|
28
|
+
"npm-plugin-kit": "^0.4.0",
|
|
28
29
|
"pathe": "^2.0.3",
|
|
29
|
-
"@initx-plugin/utils": "0.3.
|
|
30
|
+
"@initx-plugin/utils": "0.3.3"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@types/fs-extra": "^11.0.4"
|