@yongdall/plugins 0.6.1 → 0.6.4
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/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
//#region cli/plugins/index.d.mts
|
|
2
2
|
/**
|
|
3
|
+
* @deprecated
|
|
3
4
|
* @template {object} T
|
|
4
5
|
* @param {string} name
|
|
5
6
|
* @param {'script' | 'data'} [type]
|
|
@@ -9,20 +10,20 @@ declare function loadPluginProfileAndPaths<T extends object>(name: string, type?
|
|
|
9
10
|
/**
|
|
10
11
|
* @template {object} T
|
|
11
12
|
* @overload
|
|
12
|
-
* @param {string} name
|
|
13
|
+
* @param {string | string[]} name
|
|
13
14
|
* @param {'script' | 'data'} [type]
|
|
14
15
|
* @returns {AsyncIterableIterator<[plugin: string, config: T, path: string]>}
|
|
15
16
|
*/
|
|
16
|
-
declare function loadPluginProfiles<T extends object>(name: string, type?: "script" | "data" | undefined): AsyncIterableIterator<[plugin: string, config: T, path: string]>;
|
|
17
|
+
declare function loadPluginProfiles<T extends object>(name: string | string[], type?: "script" | "data" | undefined): AsyncIterableIterator<[plugin: string, config: T, path: string]>;
|
|
17
18
|
/**
|
|
18
19
|
* @template {object} T
|
|
19
20
|
* @overload
|
|
20
|
-
* @param {string} name
|
|
21
|
+
* @param {string | string[]} name
|
|
21
22
|
* @param {(config: any, plugin: string, load: (path: string) => Promise<any>) => Iterable<T> | AsyncIterable<T>} preprocess
|
|
22
23
|
* @param {'script' | 'data'} [type]
|
|
23
24
|
* @returns {AsyncIterableIterator<T>}
|
|
24
25
|
*/
|
|
25
|
-
declare function loadPluginProfiles<T extends object>(name: string, preprocess: (config: any, plugin: string, load: (path: string) => Promise<any>) => Iterable<T> | AsyncIterable<T>, type?: "script" | "data" | undefined): AsyncIterableIterator<T>;
|
|
26
|
+
declare function loadPluginProfiles<T extends object>(name: string | string[], preprocess: (config: any, plugin: string, load: (path: string) => Promise<any>) => Iterable<T> | AsyncIterable<T>, type?: "script" | "data" | undefined): AsyncIterableIterator<T>;
|
|
26
27
|
/**
|
|
27
28
|
* @template {object} T
|
|
28
29
|
* @param {string} name
|
package/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { i as plugins_default, n as loadPluginProfiles, r as loadPluginScripts, t as loadPluginProfileAndPaths } from "./plugins-
|
|
1
|
+
import { i as plugins_default, n as loadPluginProfiles, r as loadPluginScripts, t as loadPluginProfileAndPaths } from "./plugins-C9dIsxfg.mjs";
|
|
2
2
|
|
|
3
3
|
export { plugins_default as default, loadPluginProfileAndPaths, loadPluginProfiles, loadPluginScripts };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yongdall/plugins",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"plugins.yongdall": "./bin.mjs"
|
|
@@ -10,11 +10,14 @@
|
|
|
10
10
|
"#index": "./index.mjs"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@yongdall/common": "^0.6.
|
|
14
|
-
"@yongdall/configuration": "^0.6.
|
|
15
|
-
"@yongdall/load-configuration": "^0.6.
|
|
13
|
+
"@yongdall/common": "^0.6.4",
|
|
14
|
+
"@yongdall/configuration": "^0.6.4",
|
|
15
|
+
"@yongdall/load-configuration": "^0.6.4",
|
|
16
16
|
"yaml": "^2.5.0"
|
|
17
17
|
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@yongdall/core": "^0.6.4"
|
|
20
|
+
},
|
|
18
21
|
"exports": {
|
|
19
22
|
".": "./index.mjs"
|
|
20
23
|
}
|
|
@@ -2,7 +2,7 @@ import * as pathFn from "node:path";
|
|
|
2
2
|
import * as fsPromises from "node:fs/promises";
|
|
3
3
|
import { pluginIdRegex } from "@yongdall/common";
|
|
4
4
|
import { loadCfgWithPath, loadProjectConfiguration, loadProjectConfigurationPath } from "@yongdall/configuration";
|
|
5
|
-
import loadConfiguration, { loadConfigurationWithPath } from "@yongdall/load-configuration";
|
|
5
|
+
import loadConfiguration, { loadConfigurationWithPath, loadProfiles } from "@yongdall/load-configuration";
|
|
6
6
|
|
|
7
7
|
//#region cli/plugins/index.mjs
|
|
8
8
|
/**
|
|
@@ -85,6 +85,7 @@ for (const [plugin, define, basePath] of await getPlugins()) {
|
|
|
85
85
|
}
|
|
86
86
|
var plugins_default = pluginRoots;
|
|
87
87
|
/**
|
|
88
|
+
* @deprecated
|
|
88
89
|
* @template {object} T
|
|
89
90
|
* @param {string} name
|
|
90
91
|
* @param {'script' | 'data'} [type]
|
|
@@ -106,56 +107,36 @@ async function* loadPluginProfileAndPaths(name, type) {
|
|
|
106
107
|
}
|
|
107
108
|
/**
|
|
108
109
|
* @template {object} T
|
|
109
|
-
* @param {string} name
|
|
110
|
-
* @param {(config: any, plugin: string, load: (path: string) => Promise<any>) => Iterable<T> | AsyncIterable<T>} preprocess
|
|
111
|
-
* @param {'script' | 'data'} [type]
|
|
112
|
-
* @returns {AsyncIterableIterator<T>}
|
|
113
|
-
*/
|
|
114
|
-
async function* loadPluginsByPreprocess(name, preprocess, type) {
|
|
115
|
-
for await (const [plugin, config, path] of loadPluginProfileAndPaths(name, type)) {
|
|
116
|
-
const basePath = pathFn.dirname(path);
|
|
117
|
-
yield* preprocess(config, plugin, (path) => {
|
|
118
|
-
const index = path.indexOf("#");
|
|
119
|
-
const file = index < 0 ? path : path.slice(0, index);
|
|
120
|
-
return import(pathFn.resolve(basePath, file)).then((mod) => {
|
|
121
|
-
const key = index < 0 ? path.slice(index + 1) : "";
|
|
122
|
-
let val = mod;
|
|
123
|
-
for (const k of key.split(".").filter(Boolean)) {
|
|
124
|
-
if (!val || typeof val !== "object") return;
|
|
125
|
-
val = val[k];
|
|
126
|
-
}
|
|
127
|
-
if (typeof val === "function") return val();
|
|
128
|
-
}, (e) => {
|
|
129
|
-
console.error(e);
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* @template {object} T
|
|
136
110
|
* @overload
|
|
137
|
-
* @param {string} name
|
|
111
|
+
* @param {string | string[]} name
|
|
138
112
|
* @param {'script' | 'data'} [type]
|
|
139
113
|
* @returns {AsyncIterableIterator<[plugin: string, config: T, path: string]>}
|
|
140
114
|
*/
|
|
141
115
|
/**
|
|
142
116
|
* @template {object} T
|
|
143
117
|
* @overload
|
|
144
|
-
* @param {string} name
|
|
118
|
+
* @param {string | string[]} name
|
|
145
119
|
* @param {(config: any, plugin: string, load: (path: string) => Promise<any>) => Iterable<T> | AsyncIterable<T>} preprocess
|
|
146
120
|
* @param {'script' | 'data'} [type]
|
|
147
121
|
* @returns {AsyncIterableIterator<T>}
|
|
148
122
|
*/
|
|
149
123
|
/**
|
|
150
124
|
* @template {object} T
|
|
151
|
-
* @param {string} name
|
|
125
|
+
* @param {string | string[]} name
|
|
152
126
|
* @param {((config: any, plugin: string, load: (path: string) => Promise<any>) => Iterable<T> | AsyncIterable<T>) | 'script' | 'data'} [preprocess]
|
|
153
127
|
* @param {'script' | 'data'} [type]
|
|
154
128
|
* @returns {AsyncIterableIterator<[plugin: string, config: T, path: string] | T>}
|
|
155
129
|
*/
|
|
156
|
-
function loadPluginProfiles(name, preprocess, type) {
|
|
157
|
-
if (typeof preprocess === "function")
|
|
158
|
-
|
|
130
|
+
async function* loadPluginProfiles(name, preprocess, type) {
|
|
131
|
+
if (typeof preprocess === "function") {
|
|
132
|
+
for (const [plugin, { root }] of Object.entries(pluginRoots)) yield* loadProfiles(root, name, (config, _, load) => preprocess(config, plugin, load), type);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
for (const [plugin, { root }] of Object.entries(pluginRoots)) for await (const [config, path] of loadProfiles(root, name, type)) yield [
|
|
136
|
+
plugin,
|
|
137
|
+
config,
|
|
138
|
+
path
|
|
139
|
+
];
|
|
159
140
|
}
|
|
160
141
|
/**
|
|
161
142
|
* @template {object} T
|
|
@@ -173,4 +154,4 @@ async function* loadPluginScripts(name) {
|
|
|
173
154
|
|
|
174
155
|
//#endregion
|
|
175
156
|
export { plugins_default as i, loadPluginProfiles as n, loadPluginScripts as r, loadPluginProfileAndPaths as t };
|
|
176
|
-
//# sourceMappingURL=plugins-
|
|
157
|
+
//# sourceMappingURL=plugins-C9dIsxfg.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins-C9dIsxfg.mjs","names":[],"sources":["../../cli/plugins/index.mjs"],"sourcesContent":["import * as pathFn from 'node:path';\nimport * as fsPromises from 'node:fs/promises';\nimport { pluginIdRegex } from '@yongdall/common';\nimport { loadCfgWithPath, loadProjectConfiguration, loadProjectConfigurationPath } from '@yongdall/configuration';\nimport loadConfiguration, { loadConfigurationWithPath, loadProfiles } from '@yongdall/load-configuration';\n\n\n/**\n * \n * @param {string} root \n * @param {string} name \n */\nasync function findNodeModule(root, name) {\n\tfor (let basepath = root; ;) {\n\t\tconst path = pathFn.resolve(basepath, 'node_modules', name);\n\t\tconst packageJson = await fsPromises.readFile(pathFn.resolve(path, 'package.json'), 'utf-8').then(v => JSON.parse(v)).catch(() => null);\n\t\tconst version = packageJson?.version;\n\t\tif (version && typeof version === 'string') {\n\t\t\treturn path;\n\t\t}\n\t\tconst parent = pathFn.dirname(basepath);\n\t\tif (parent === basepath) { break; }\n\t\tbasepath = parent;\n\t}\n\treturn null;\n}\n/**\n * @returns {Promise<[string, string | boolean | {path?: string; development?: boolean}, string][]>}\n */\nasync function getPlugins() {\n\tconst result = await loadCfgWithPath('plugins').catch(() => { });\n\tconst [path, pluginList] = result && result[1] ? result : [\n\t\tawait loadProjectConfigurationPath(),\n\t\tawait loadProjectConfiguration().then(v => v.plugins),\n\t];\n\tif (!pluginList) { return []; }\n\tconst basePath = pathFn.dirname(path);\n\tif (Array.isArray(pluginList)) {\n\t\treturn pluginList.map(a => [a, true, basePath]);\n\t}\n\treturn Object.entries(pluginList).map(([a, b]) => [a, b, basePath]);\n}\n/**\n * \n * @param {string} plugin \n * @param {string | boolean | { path?: string; development?: boolean }} define \n * @param {string} basePath \n * @returns \n */\nasync function loadPlugin(plugin, define, basePath) {\n\tconst r = pluginIdRegex.exec(plugin);\n\tif (!r) { throw new Error(`无效的应用名称:${plugin}`); }\n\tconst path = typeof define === 'object' && define ? define.path : define;\n\tconst development = typeof define === 'object' && define ? define.development : false;\n\n\tconst url = typeof path === 'string' ? path : '';\n\tconst index = url.indexOf('#');\n\tconst packagePath = index >= 0 ? url.slice(0, index) : url;\n\tconst packageName = pluginIdRegex.test(packagePath) ? packagePath : '';\n\n\tconst source = !packageName && packagePath\n\t\t? pathFn.resolve(basePath, packagePath)\n\t\t: await findNodeModule(basePath, packageName || plugin);\n\tif (!source) { throw new Error(`找不到应用:${plugin}`); }\n\tlet pluginPath = source;\n\n\tif (index >= 0) {\n\t\tconst dirOptional = url[index + 1] === '?';\n\t\tconst dir = url.slice(dirOptional ? index + 2 : index + 1);\n\t\tif (dir) {\n\t\t\tconst pluginDir = pathFn.join(pluginPath, dir);\n\t\t\tif (await fsPromises.stat(pluginDir).then(s => s.isDirectory(), () => false)) {\n\t\t\t\tpluginPath = pluginDir;\n\t\t\t} else if (!dirOptional) {\n\t\t\t\tthrow new Error(`找不到应用 ${plugin} 的目录: ${dir}`);\n\t\t\t}\n\t\t}\n\t}\n\t/** @type {{label?: string; configurator?: any}?} */\n\tconst data = await loadConfiguration(pathFn.resolve(pluginPath, `yongdall.plugin`), 'data').catch(() => null);\n\treturn {\n\t\troot: pluginPath,\n\t\tsource,\n\t\tdevelopment: Boolean(development),\n\t\tlabel: data?.label,\n\t\tconfigurator: data?.configurator,\n\t};\n}\n\n/** @type {Record<string, {root: string; source: string; development: boolean; configurator?: any; label?: string}>} */\nconst pluginRoots = Object.create(null);\nfor (const [plugin, define, basePath] of await getPlugins()) {\n\tif (!define) { continue; }\n\n\tpluginRoots[plugin] = await loadPlugin(plugin, define, basePath);\n}\n\nexport default pluginRoots;\n\n/** \n * @deprecated\n * @template {object} T\n * @param {string} name\n * @param {'script' | 'data'} [type] \n * @returns {AsyncIterableIterator<[plugin: string, config: T, path: string]>}\n */\nexport async function* loadPluginProfileAndPaths(name, type) {\n\tfor (const [plugin, { root }] of Object.entries(pluginRoots)) {\n\t\t/** @type {[string, T | null] | null} */\n\t\tconst result = await loadConfigurationWithPath(pathFn.resolve(root, `${name}.yongdall`), type)\n\t\t\t|| await loadConfigurationWithPath(pathFn.resolve(root, `yongdall/${name}`), type)\n\t\t\t|| await loadConfigurationWithPath(pathFn.resolve(root, `${name}/yongdall`), type);\n\t\tif (!result) { continue; }\n\t\tconst [path, config] = result;\n\t\tif (!config) { continue; }\n\t\tyield [plugin, config, path];\n\t}\n}\n\n\n\n/** \n * @template {object} T\n * @overload\n * @param {string | string[]} name\n * @param {'script' | 'data'} [type] \n * @returns {AsyncIterableIterator<[plugin: string, config: T, path: string]>}\n */\n/** \n * @template {object} T\n * @overload\n * @param {string | string[]} name\n * @param {(config: any, plugin: string, load: (path: string) => Promise<any>) => Iterable<T> | AsyncIterable<T>} preprocess\n * @param {'script' | 'data'} [type] \n * @returns {AsyncIterableIterator<T>}\n */\n/** \n * @template {object} T\n * @param {string | string[]} name\n * @param {((config: any, plugin: string, load: (path: string) => Promise<any>) => Iterable<T> | AsyncIterable<T>) | 'script' | 'data'} [preprocess]\n * @param {'script' | 'data'} [type] \n * @returns {AsyncIterableIterator<[plugin: string, config: T, path: string] | T>}\n */\nexport async function* loadPluginProfiles(name, preprocess, type) {\n\tif (typeof preprocess === 'function') {\n\t\tfor (const [plugin, { root }] of Object.entries(pluginRoots)) {\n\t\t\tyield* loadProfiles(root, name, (config, _, load) => preprocess(config, plugin, load), type)\n\t\t}\n\t\treturn\n\t}\n\tfor (const [plugin, { root }] of Object.entries(pluginRoots)) {\n\t\tfor await (const [config, path] of loadProfiles(root, name, type)) {\n\t\t\tyield [plugin, /** @type {T} */(config), path];\n\t\t}\n\t}\n}\n\n/** \n * @template {object} T\n * @param {string} name\n * @returns {AsyncIterableIterator<[plugin: string, config: T]>}\n */\nexport async function* loadPluginScripts(name) {\n\tfor (const [plugin, { root }] of Object.entries(pluginRoots)) {\n\t\t/** @type {T | null} */\n\t\tconst result = await loadConfiguration(pathFn.resolve(root, `${name}.yongdall`), 'script')\n\t\t\t|| await loadConfiguration(pathFn.resolve(root, `yongdall/${name}`), 'script')\n\t\t\t|| await loadConfiguration(pathFn.resolve(root, `${name}/yongdall`), 'script');\n\t\tif (result === null) { continue; }\n\t\tyield [plugin, result];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AAYA,eAAe,eAAe,MAAM,MAAM;AACzC,MAAK,IAAI,WAAW,QAAS;EAC5B,MAAM,OAAO,OAAO,QAAQ,UAAU,gBAAgB,KAAK;EAE3D,MAAM,WADc,MAAM,WAAW,SAAS,OAAO,QAAQ,MAAM,eAAe,EAAE,QAAQ,CAAC,MAAK,MAAK,KAAK,MAAM,EAAE,CAAC,CAAC,YAAY,KAAK,GAC1G;AAC7B,MAAI,WAAW,OAAO,YAAY,SACjC,QAAO;EAER,MAAM,SAAS,OAAO,QAAQ,SAAS;AACvC,MAAI,WAAW,SAAY;AAC3B,aAAW;;AAEZ,QAAO;;;;;AAKR,eAAe,aAAa;CAC3B,MAAM,SAAS,MAAM,gBAAgB,UAAU,CAAC,YAAY,GAAI;CAChE,MAAM,CAAC,MAAM,cAAc,UAAU,OAAO,KAAK,SAAS,CACzD,MAAM,8BAA8B,EACpC,MAAM,0BAA0B,CAAC,MAAK,MAAK,EAAE,QAAQ,CACrD;AACD,KAAI,CAAC,WAAc,QAAO,EAAE;CAC5B,MAAM,WAAW,OAAO,QAAQ,KAAK;AACrC,KAAI,MAAM,QAAQ,WAAW,CAC5B,QAAO,WAAW,KAAI,MAAK;EAAC;EAAG;EAAM;EAAS,CAAC;AAEhD,QAAO,OA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kBAAkB,OAAO,QAAQ,MAAM,YAAY,OAAO,EAAE,SAAS,IAC3E,MAAM,kBAAkB,OAAO,QAAQ,MAAM,GAAG,KAAK,WAAW,EAAE,SAAS;AAC/E,MAAI,WAAW,KAAQ;AACvB,QAAM,CAAC,QAAQ,OAAO"}
|
package/yongdall/enumeration.mjs
CHANGED
package/plugins-BsoRxhdM.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugins-BsoRxhdM.mjs","names":[],"sources":["../../cli/plugins/index.mjs"],"sourcesContent":["import * as pathFn from 'node:path';\nimport * as fsPromises from 'node:fs/promises';\nimport { pluginIdRegex } from '@yongdall/common';\nimport { loadCfgWithPath, loadProjectConfiguration, loadProjectConfigurationPath } from '@yongdall/configuration';\nimport loadConfiguration, { loadConfigurationWithPath } from '@yongdall/load-configuration';\n\n\n/**\n * \n * @param {string} root \n * @param {string} name \n */\nasync function findNodeModule(root, name) {\n\tfor (let basepath = root; ;) {\n\t\tconst path = pathFn.resolve(basepath, 'node_modules', name);\n\t\tconst packageJson = await fsPromises.readFile(pathFn.resolve(path, 'package.json'), 'utf-8').then(v => JSON.parse(v)).catch(() => null);\n\t\tconst version = packageJson?.version;\n\t\tif (version && typeof version === 'string') {\n\t\t\treturn path;\n\t\t}\n\t\tconst parent = pathFn.dirname(basepath);\n\t\tif (parent === basepath) { break; }\n\t\tbasepath = parent;\n\t}\n\treturn null;\n}\n/**\n * @returns {Promise<[string, string | boolean | {path?: string; development?: boolean}, string][]>}\n */\nasync function getPlugins() {\n\tconst result = await loadCfgWithPath('plugins').catch(() => { });\n\tconst [path, pluginList] = result && result[1] ? result : [\n\t\tawait loadProjectConfigurationPath(),\n\t\tawait loadProjectConfiguration().then(v => v.plugins),\n\t];\n\tif (!pluginList) { return []; }\n\tconst basePath = pathFn.dirname(path);\n\tif (Array.isArray(pluginList)) {\n\t\treturn pluginList.map(a => [a, true, basePath]);\n\t}\n\treturn Object.entries(pluginList).map(([a, b]) => [a, b, basePath]);\n}\n/**\n * \n * @param {string} plugin \n * @param {string | boolean | { path?: string; development?: boolean }} define \n * @param {string} basePath \n * @returns \n */\nasync function loadPlugin(plugin, define, basePath) {\n\tconst r = pluginIdRegex.exec(plugin);\n\tif (!r) { throw new Error(`无效的应用名称:${plugin}`); }\n\tconst path = typeof define === 'object' && define ? define.path : define;\n\tconst development = typeof define === 'object' && define ? define.development : false;\n\n\tconst url = typeof path === 'string' ? path : '';\n\tconst index = url.indexOf('#');\n\tconst packagePath = index >= 0 ? url.slice(0, index) : url;\n\tconst packageName = pluginIdRegex.test(packagePath) ? packagePath : '';\n\n\tconst source = !packageName && packagePath\n\t\t? pathFn.resolve(basePath, packagePath)\n\t\t: await findNodeModule(basePath, packageName || plugin);\n\tif (!source) { throw new Error(`找不到应用:${plugin}`); }\n\tlet pluginPath = source;\n\n\tif (index >= 0) {\n\t\tconst dirOptional = url[index + 1] === '?';\n\t\tconst dir = url.slice(dirOptional ? index + 2 : index + 1);\n\t\tif (dir) {\n\t\t\tconst pluginDir = pathFn.join(pluginPath, dir);\n\t\t\tif (await fsPromises.stat(pluginDir).then(s => s.isDirectory(), () => false)) {\n\t\t\t\tpluginPath = pluginDir;\n\t\t\t} else if (!dirOptional) {\n\t\t\t\tthrow new Error(`找不到应用 ${plugin} 的目录: ${dir}`);\n\t\t\t}\n\t\t}\n\t}\n\t/** @type {{label?: string; configurator?: any}?} */\n\tconst data = await loadConfiguration(pathFn.resolve(pluginPath, `yongdall.plugin`), 'data').catch(() => null);\n\treturn {\n\t\troot: pluginPath,\n\t\tsource,\n\t\tdevelopment: Boolean(development),\n\t\tlabel: data?.label,\n\t\tconfigurator: data?.configurator,\n\t};\n}\n\n/** @type {Record<string, {root: string; source: string; development: boolean; configurator?: any; label?: string}>} */\nconst pluginRoots = Object.create(null);\nfor (const [plugin, define, basePath] of await getPlugins()) {\n\tif (!define) { continue; }\n\n\tpluginRoots[plugin] = await loadPlugin(plugin, define, basePath);\n}\n\nexport default pluginRoots;\n\n/** \n * @template {object} T\n * @param {string} name\n * @param {'script' | 'data'} [type] \n * @returns {AsyncIterableIterator<[plugin: string, config: T, path: string]>}\n */\nexport async function* loadPluginProfileAndPaths(name, type) {\n\tfor (const [plugin, { root }] of Object.entries(pluginRoots)) {\n\t\t/** @type {[string, T | null] | null} */\n\t\tconst result = await loadConfigurationWithPath(pathFn.resolve(root, `${name}.yongdall`), type)\n\t\t\t|| await loadConfigurationWithPath(pathFn.resolve(root, `yongdall/${name}`), type)\n\t\t\t|| await loadConfigurationWithPath(pathFn.resolve(root, `${name}/yongdall`), type);\n\t\tif (!result) { continue; }\n\t\tconst [path, config] = result;\n\t\tif (!config) { continue; }\n\t\tyield [plugin, config, path];\n\t}\n}\n\n/** \n * @template {object} T\n * @param {string} name\n * @param {(config: any, plugin: string, load: (path: string) => Promise<any>) => Iterable<T> | AsyncIterable<T>} preprocess\n * @param {'script' | 'data'} [type] \n * @returns {AsyncIterableIterator<T>}\n */\nasync function* loadPluginsByPreprocess(name, preprocess, type) {\n\tfor await (const [plugin, config, path] of loadPluginProfileAndPaths(name, type)) {\n\t\tconst basePath = pathFn.dirname(path);\n\t\tyield* preprocess(config, plugin, path => {\n\t\t\tconst index = path.indexOf('#');\n\t\t\tconst file = index < 0 ? path : path.slice(0, index);\n\t\t\treturn import(pathFn.resolve(basePath, file)).then(mod => {\n\t\t\t\tconst key = index < 0 ? path.slice(index + 1) : '';\n\t\t\t\tlet val = mod;\n\t\t\t\tfor (const k of key.split('.').filter(Boolean)) {\n\t\t\t\t\tif (!val || typeof val !== 'object') { return; }\n\t\t\t\t\tval = val[k];\n\t\t\t\t}\n\t\t\t\tif (typeof val === 'function') {\n\t\t\t\t\treturn val();\n\t\t\t\t}\n\t\t\t}, (e) => {\n\t\t\t\tconsole.error(e);\n\t\t\t});\n\t\t});\n\t}\n}\n\n\n/** \n * @template {object} T\n * @overload\n * @param {string} name\n * @param {'script' | 'data'} [type] \n * @returns {AsyncIterableIterator<[plugin: string, config: T, path: string]>}\n */\n/** \n * @template {object} T\n * @overload\n * @param {string} name\n * @param {(config: any, plugin: string, load: (path: string) => Promise<any>) => Iterable<T> | AsyncIterable<T>} preprocess\n * @param {'script' | 'data'} [type] \n * @returns {AsyncIterableIterator<T>}\n */\n/** \n * @template {object} T\n * @param {string} name\n * @param {((config: any, plugin: string, load: (path: string) => Promise<any>) => Iterable<T> | AsyncIterable<T>) | 'script' | 'data'} [preprocess]\n * @param {'script' | 'data'} [type] \n * @returns {AsyncIterableIterator<[plugin: string, config: T, path: string] | T>}\n */\nexport function loadPluginProfiles(name, preprocess, type) {\n\tif (typeof preprocess === 'function') {\n\t\treturn loadPluginsByPreprocess(name, preprocess, type);\n\t}\n\treturn loadPluginProfileAndPaths(name, preprocess);\n}\n\n/** \n * @template {object} T\n * @param {string} name\n * @returns {AsyncIterableIterator<[plugin: string, config: T]>}\n */\nexport async function* loadPluginScripts(name) {\n\tfor (const [plugin, { root }] of Object.entries(pluginRoots)) {\n\t\t/** @type {T | null} */\n\t\tconst result = await loadConfiguration(pathFn.resolve(root, `${name}.yongdall`), 'script')\n\t\t\t|| await loadConfiguration(pathFn.resolve(root, `yongdall/${name}`), 'script')\n\t\t\t|| await loadConfiguration(pathFn.resolve(root, `${name}/yongdall`), 'script');\n\t\tif (result === null) { continue; }\n\t\tyield [plugin, result];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AAYA,eAAe,eAAe,MAAM,MAAM;AACzC,MAAK,IAAI,WAAW,QAAS;EAC5B,MAAM,OAAO,OAAO,QAAQ,UAAU,gBAAgB,KAAK;EAE3D,MAAM,WADc,MAAM,WAAW,SAAS,OAAO,QAAQ,MAAM,eAAe,EAAE,QAAQ,CAAC,MAAK,MAAK,KAAK,MAAM,EAAE,CAAC,CAAC,YAAY,KAAK,GAC1G;AAC7B,MAAI,WAAW,OAAO,YAAY,SACjC,QAAO;EAER,MAAM,SAAS,OAAO,QAAQ,SAAS;AACvC,MAAI,WAAW,SAAY;AAC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