@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.
@@ -0,0 +1,2 @@
1
+ import { a as useConfig, i as loadConfig, n as defineConfig, o as watchConfig, r as getConfig, t as MetajoyConfig } from "./config-C0xYNXLv.mjs";
2
+ export { MetajoyConfig, defineConfig, getConfig, loadConfig, useConfig, watchConfig };
@@ -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 };
@@ -0,0 +1,6 @@
1
+ import { Options } from "./option.mjs";
2
+
3
+ //#region src/esbuild.d.ts
4
+ declare const _default: (options?: Options | undefined) => EsbuildPlugin;
5
+ //#endregion
6
+ export { _default as default };
@@ -0,0 +1,6 @@
1
+ import { n as metajoyUnpluginFactory } from "./src-2HigwrEC.mjs";
2
+ import { createEsbuildPlugin } from "unplugin";
3
+ //#region src/esbuild.ts
4
+ var esbuild_default = createEsbuildPlugin(metajoyUnpluginFactory);
5
+ //#endregion
6
+ export { esbuild_default as default };
@@ -0,0 +1,6 @@
1
+ import { Options } from "./option.mjs";
2
+
3
+ //#region src/farm.d.ts
4
+ declare const _default: (options?: Options | undefined) => JsPlugin;
5
+ //#endregion
6
+ export { _default as default };
package/dist/farm.mjs ADDED
@@ -0,0 +1,6 @@
1
+ import { n as metajoyUnpluginFactory } from "./src-2HigwrEC.mjs";
2
+ import { createFarmPlugin } from "unplugin";
3
+ //#region src/farm.ts
4
+ var farm_default = createFarmPlugin(metajoyUnpluginFactory);
5
+ //#endregion
6
+ export { farm_default as default };
@@ -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
@@ -0,0 +1,2 @@
1
+ import { n as metajoyUnpluginFactory, t as metajoyUnplugin } from "./src-2HigwrEC.mjs";
2
+ export { metajoyUnplugin as default, metajoyUnplugin, metajoyUnpluginFactory };
@@ -0,0 +1,7 @@
1
+ import { Options } from "./option.mjs";
2
+
3
+ //#region src/nuxt.d.ts
4
+ interface ModuleOptions extends Options {}
5
+ declare const _default: NuxtModule<TOptions, TOptions, false>;
6
+ //#endregion
7
+ export { ModuleOptions, _default as default };