vueless 1.5.2-beta.2 → 1.5.2-beta.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/package.json +1 -1
- package/utils/tests/ui.test.ts +8 -30
- package/utils/ui.ts +7 -28
package/package.json
CHANGED
package/utils/tests/ui.test.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { describe, it, expect, vi
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
2
|
|
|
3
3
|
import { COLOR_MODE_KEY } from "../../constants.js";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import type { Config } from "../../types";
|
|
4
|
+
import { setVuelessConfig } from "../ui";
|
|
7
5
|
|
|
8
6
|
/* jsdom doesn't implement matchMedia, which theme.ts evaluates on import. */
|
|
9
7
|
const prefersDark = { matches: false, addEventListener: vi.fn(), removeEventListener: vi.fn() };
|
|
@@ -12,37 +10,17 @@ window.matchMedia = vi.fn(() => prefersDark) as unknown as typeof window.matchMe
|
|
|
12
10
|
|
|
13
11
|
const { getThemeCookieName } = await import("../theme");
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe("loadSSRVuelessConfig", () => {
|
|
20
|
-
it.each([
|
|
21
|
-
["resolves", () => ({ cookiePrefix: "from-file" })],
|
|
22
|
-
[
|
|
23
|
-
"fails",
|
|
24
|
-
() => {
|
|
25
|
-
throw new Error("Cannot find module '/vueless.config'");
|
|
26
|
-
},
|
|
27
|
-
],
|
|
28
|
-
])("keeps the injected config when a deferred import %s", async (_, settle: () => Config) => {
|
|
29
|
-
let release!: () => void;
|
|
30
|
-
const released = new Promise<void>((resolve) => (release = resolve));
|
|
31
|
-
|
|
32
|
-
const loading = loadSSRVuelessConfig(() => released.then(() => ({ default: settle() })));
|
|
33
|
-
|
|
13
|
+
describe("setVuelessConfig", () => {
|
|
14
|
+
it("uses the injected config", () => {
|
|
34
15
|
setVuelessConfig({ cookiePrefix: "app-a" });
|
|
35
|
-
expect(getThemeCookieName(COLOR_MODE_KEY)).toBe(`app-a-${COLOR_MODE_KEY}`);
|
|
36
|
-
|
|
37
|
-
release();
|
|
38
|
-
await loading;
|
|
39
16
|
|
|
40
17
|
expect(getThemeCookieName(COLOR_MODE_KEY)).toBe(`app-a-${COLOR_MODE_KEY}`);
|
|
41
18
|
});
|
|
42
19
|
|
|
43
|
-
it("
|
|
44
|
-
|
|
20
|
+
it("keeps the current config when an empty one is injected", () => {
|
|
21
|
+
setVuelessConfig({ cookiePrefix: "app-a" });
|
|
22
|
+
setVuelessConfig({});
|
|
45
23
|
|
|
46
|
-
expect(getThemeCookieName(COLOR_MODE_KEY)).toBe(`
|
|
24
|
+
expect(getThemeCookieName(COLOR_MODE_KEY)).toBe(`app-a-${COLOR_MODE_KEY}`);
|
|
47
25
|
});
|
|
48
26
|
});
|
package/utils/ui.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { cx as cvaCx } from "cva";
|
|
|
3
3
|
import { defineConfig } from "cva/config";
|
|
4
4
|
import { extendTailwindMerge } from "tailwind-merge";
|
|
5
5
|
|
|
6
|
-
import { isCSR, isSSR } from "./helper";
|
|
7
6
|
import { createGetMergedConfig } from "./node/mergeConfigs";
|
|
8
7
|
import { COMPONENT_NAME as U_ICON } from "../ui.image-icon/constants";
|
|
9
8
|
import { ICON_NON_PROPS_DEFAULTS, TAILWIND_MERGE_EXTENSION } from "../constants";
|
|
@@ -30,7 +29,13 @@ type GetMergedConfig = (options: MergedConfigOptions) => unknown;
|
|
|
30
29
|
* Load Vueless config from the project root.
|
|
31
30
|
* Both for server and client side renderings.
|
|
32
31
|
*/
|
|
33
|
-
export let vuelessConfig: Config =
|
|
32
|
+
export let vuelessConfig: Config =
|
|
33
|
+
Object.values(
|
|
34
|
+
import.meta.glob(["/vueless.config.{js,ts}"], {
|
|
35
|
+
eager: true,
|
|
36
|
+
import: "default",
|
|
37
|
+
}),
|
|
38
|
+
)[0] || {};
|
|
34
39
|
|
|
35
40
|
export function setVuelessConfig(config?: Config) {
|
|
36
41
|
config = config || {};
|
|
@@ -38,32 +43,6 @@ export function setVuelessConfig(config?: Config) {
|
|
|
38
43
|
vuelessConfig = Object.keys(config).length ? config : vuelessConfig;
|
|
39
44
|
}
|
|
40
45
|
|
|
41
|
-
if (isCSR) {
|
|
42
|
-
vuelessConfig =
|
|
43
|
-
Object.values(
|
|
44
|
-
import.meta.glob(["/vueless.config.{js,ts}"], {
|
|
45
|
-
eager: true,
|
|
46
|
-
import: "default",
|
|
47
|
-
}),
|
|
48
|
-
)[0] || {};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** Load Vueless config on the server; a config injected via `createVueless` meanwhile wins. */
|
|
52
|
-
export async function loadSSRVuelessConfig(
|
|
53
|
-
// @ts-expect-error: vueless.config.{js,ts} is optional
|
|
54
|
-
importConfig = () => import(/* @vite-ignore */ "/vueless.config"),
|
|
55
|
-
) {
|
|
56
|
-
try {
|
|
57
|
-
const { default: config } = await importConfig();
|
|
58
|
-
|
|
59
|
-
if (!Object.keys(vuelessConfig).length) vuelessConfig = config;
|
|
60
|
-
} catch {
|
|
61
|
-
/* No config file: keep the current config. */
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (isSSR) loadSSRVuelessConfig();
|
|
66
|
-
|
|
67
46
|
/**
|
|
68
47
|
* Extend twMerge (tailwind merge) by vueless and user config:
|
|
69
48
|
*/
|