@metajoy-preview/unplugin 0.0.1
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/README.md +128 -0
- package/dist/astro.d.mts +6 -0
- package/dist/astro.mjs +11 -0
- package/dist/client.d.mts +35 -0
- package/dist/client.mjs +1 -0
- package/dist/config-C0xYNXLv.d.mts +2664 -0
- package/dist/config.d.mts +2 -0
- package/dist/config.mjs +69 -0
- package/dist/esbuild.d.mts +6 -0
- package/dist/esbuild.mjs +6 -0
- package/dist/farm.d.mts +6 -0
- package/dist/farm.mjs +6 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.mjs +2 -0
- package/dist/nuxt.d.mts +7 -0
- package/dist/nuxt.mjs +10053 -0
- package/dist/option.d.mts +24 -0
- package/dist/option.mjs +9 -0
- package/dist/prompt-C9gMgpSA.mjs +847 -0
- package/dist/rollup.d.mts +6 -0
- package/dist/rollup.mjs +6 -0
- package/dist/rspack.d.mts +6 -0
- package/dist/rspack.mjs +6 -0
- package/dist/src-2HigwrEC.mjs +118 -0
- package/dist/vite.d.mts +7 -0
- package/dist/vite.mjs +6 -0
- package/dist/webpack.d.mts +6 -0
- package/dist/webpack.mjs +6 -0
- package/package.json +66 -0
package/dist/config.mjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { assign, get, isString, merge } from "lodash-es";
|
|
2
|
+
import { defineConfig, watchConfig as watchConfig$1 } from "@metajoy/config";
|
|
3
|
+
import { createHooks } from "hookable";
|
|
4
|
+
//#region src/config.ts
|
|
5
|
+
let config;
|
|
6
|
+
const hooks = createHooks();
|
|
7
|
+
/**
|
|
8
|
+
* 加载配置
|
|
9
|
+
* @returns 配置对象
|
|
10
|
+
*/
|
|
11
|
+
async function loadConfig(options) {
|
|
12
|
+
return config = config ?? await watchConfig$1(merge({
|
|
13
|
+
async acceptHMR(...args) {
|
|
14
|
+
await hooks.callHook("acceptHMR", ...args);
|
|
15
|
+
},
|
|
16
|
+
async onUpdate(...args) {
|
|
17
|
+
await hooks.callHook("onUpdate", ...args);
|
|
18
|
+
},
|
|
19
|
+
async onWatch(...args) {
|
|
20
|
+
await hooks.callHook("onWatch", ...args);
|
|
21
|
+
}
|
|
22
|
+
}, options));
|
|
23
|
+
}
|
|
24
|
+
function getConfig(pathOrOptions, mayBeOptions) {
|
|
25
|
+
const path = isString(pathOrOptions) ? pathOrOptions : void 0;
|
|
26
|
+
const options = isString(pathOrOptions) ? mayBeOptions : pathOrOptions;
|
|
27
|
+
if (path) return merge({}, options?.defaults, get(config?.config, path), options?.overrides);
|
|
28
|
+
return merge({}, options?.defaults, config?.config, options?.overrides);
|
|
29
|
+
}
|
|
30
|
+
function useConfig(pathOrOptions, mayBeOptions) {
|
|
31
|
+
const path = isString(pathOrOptions) ? pathOrOptions : void 0;
|
|
32
|
+
const options = isString(pathOrOptions) ? mayBeOptions : pathOrOptions;
|
|
33
|
+
if (path) {
|
|
34
|
+
const result = getConfig(path, options);
|
|
35
|
+
const resultRef = new WeakRef(result);
|
|
36
|
+
function onUpdate({ newConfig }) {
|
|
37
|
+
const result = resultRef.deref();
|
|
38
|
+
if (result) assign(result, options?.defaults, get(newConfig, path), options?.overrides);
|
|
39
|
+
else hooks.removeHook("onUpdate", onUpdate);
|
|
40
|
+
}
|
|
41
|
+
new FinalizationRegistry((value) => hooks.removeHook("onUpdate", value)).register(result, onUpdate);
|
|
42
|
+
hooks.hook("onUpdate", onUpdate);
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
const result = getConfig(options);
|
|
46
|
+
const resultRef = new WeakRef(result);
|
|
47
|
+
function onUpdate({ newConfig }) {
|
|
48
|
+
const result = resultRef.deref();
|
|
49
|
+
if (result) assign(result, options?.defaults, newConfig, options?.overrides);
|
|
50
|
+
else hooks.removeHook("onUpdate", onUpdate);
|
|
51
|
+
}
|
|
52
|
+
new FinalizationRegistry((value) => hooks.removeHook("onUpdate", value)).register(result, onUpdate);
|
|
53
|
+
hooks.hook("onUpdate", onUpdate);
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
function watchConfig(pathOrCallback, mayBeCallback) {
|
|
57
|
+
const path = typeof pathOrCallback === "string" ? pathOrCallback : void 0;
|
|
58
|
+
const callback = typeof pathOrCallback === "string" ? mayBeCallback : pathOrCallback;
|
|
59
|
+
return hooks.hook("onUpdate", ({ getDiff, newConfig, oldConfig }) => {
|
|
60
|
+
const diffs = getDiff();
|
|
61
|
+
if (path && diffs.some((diff) => diff.key.startsWith(path))) {
|
|
62
|
+
callback?.(get(newConfig, path), get(oldConfig, path));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
callback?.(newConfig, oldConfig);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { defineConfig, getConfig, loadConfig, useConfig, watchConfig };
|
package/dist/esbuild.mjs
ADDED
package/dist/farm.d.mts
ADDED
package/dist/farm.mjs
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Options } from "./option.mjs";
|
|
2
|
+
import * as _$unplugin from "unplugin";
|
|
3
|
+
import { UnpluginFactory } from "unplugin";
|
|
4
|
+
|
|
5
|
+
//#region src/index.d.ts
|
|
6
|
+
declare const metajoyUnpluginFactory: UnpluginFactory<Options | undefined>;
|
|
7
|
+
declare const metajoyUnplugin: _$unplugin.UnpluginInstance<Options | undefined, boolean>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { metajoyUnplugin as default, metajoyUnplugin, metajoyUnpluginFactory };
|
package/dist/index.mjs
ADDED
package/dist/nuxt.d.mts
ADDED