@untestutils/vite 0.5.2 → 0.5.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 CHANGED
@@ -1,12 +1,22 @@
1
- import { type FrameworkBaseOptions, type Recipe } from "@untestutils/core";
1
+ import { type Driver, type FrameworkBaseOptions, type Recipe } from "@untestutils/core";
2
2
  export type ViteRun = "preview" | "dev";
3
+ /** Typed Vite config overrides (JSON-serializable subset / plain UserConfig fields). */
4
+ export type ViteConfigOverride = Record<string, unknown>;
3
5
  export interface ViteOptions extends FrameworkBaseOptions {
4
6
  run?: ViteRun;
7
+ /**
8
+ * Merged onto the app's vite.config via `mergeConfig` (ephemeral `--config` in outDir).
9
+ * Same role as Nuxt `nuxtConfig` overrides.
10
+ */
11
+ viteConfig?: ViteConfigOverride;
5
12
  }
13
+ export type ViteMatrixVariant = Partial<Pick<ViteOptions, "env" | "hashInputs" | "run" | "readyPath" | "readyTimeoutMs" | "workspaceDeps" | "viteConfig">>;
6
14
  /**
7
15
  * Vite SPA Recipe factory.
8
16
  * `run: 'preview'` (default) — `vite build` then `vite preview`
9
17
  * `run: 'dev'` — `vite` with strictPort (never shared)
10
18
  */
11
- export declare function vite(opts: ViteOptions): Recipe;
19
+ export declare const vite: Driver<ViteOptions>;
20
+ /** Expand one Vite recipe base into many recipes with distinct ids. */
21
+ export declare function matrix(base: ViteOptions, variants: Record<string, ViteMatrixVariant>): Record<string, Recipe>;
12
22
  export default vite;
package/dist/index.d.ts CHANGED
@@ -1,13 +1,23 @@
1
- import { type FrameworkBaseOptions, type Recipe } from '@untestutils/core';
1
+ import { type Driver, type FrameworkBaseOptions, type Recipe } from '@untestutils/core';
2
2
  export type ViteRun = 'preview' | 'dev';
3
+ /** Typed Vite config overrides (JSON-serializable subset / plain UserConfig fields). */
4
+ export type ViteConfigOverride = Record<string, unknown>;
3
5
  export interface ViteOptions extends FrameworkBaseOptions {
4
6
  run?: ViteRun;
7
+ /**
8
+ * Merged onto the app's vite.config via `mergeConfig` (ephemeral `--config` in outDir).
9
+ * Same role as Nuxt `nuxtConfig` overrides.
10
+ */
11
+ viteConfig?: ViteConfigOverride;
5
12
  }
13
+ export type ViteMatrixVariant = Partial<Pick<ViteOptions, 'env' | 'hashInputs' | 'run' | 'readyPath' | 'readyTimeoutMs' | 'workspaceDeps' | 'viteConfig'>>;
6
14
  /**
7
15
  * Vite SPA Recipe factory.
8
16
  * `run: 'preview'` (default) — `vite build` then `vite preview`
9
17
  * `run: 'dev'` — `vite` with strictPort (never shared)
10
18
  */
11
- export declare function vite(opts: ViteOptions): Recipe;
19
+ export declare const vite: Driver<ViteOptions>;
20
+ /** Expand one Vite recipe base into many recipes with distinct ids. */
21
+ export declare function matrix(base: ViteOptions, variants: Record<string, ViteMatrixVariant>): Record<string, Recipe>;
12
22
  export default vite;
13
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,oBAAoB,EACzB,KAAK,MAAM,EACZ,MAAM,mBAAmB,CAAC;AAE3B,MAAM,MAAM,OAAO,GAAG,SAAS,GAAG,KAAK,CAAC;AAExC,MAAM,WAAW,WAAY,SAAQ,oBAAoB;IACvD,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAYD;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CA4C9C;AAED,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAUL,KAAK,MAAM,EACX,KAAK,oBAAoB,EACzB,KAAK,MAAM,EACZ,MAAM,mBAAmB,CAAC;AAE3B,MAAM,MAAM,OAAO,GAAG,SAAS,GAAG,KAAK,CAAC;AAExC,wFAAwF;AACxF,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEzD,MAAM,WAAW,WAAY,SAAQ,oBAAoB;IACvD,GAAG,CAAC,EAAE,OAAO,CAAC;IACd;;;OAGG;IACH,UAAU,CAAC,EAAE,kBAAkB,CAAC;CACjC;AAED,MAAM,MAAM,iBAAiB,GAAG,OAAO,CACrC,IAAI,CACF,WAAW,EACX,KAAK,GAAG,YAAY,GAAG,KAAK,GAAG,WAAW,GAAG,gBAAgB,GAAG,eAAe,GAAG,YAAY,CAC/F,CACF,CAAC;AAgCF;;;;GAIG;AACH,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,WAAW,CAwEnC,CAAC;AAEH,uEAAuE;AACvE,wBAAgB,MAAM,CACpB,IAAI,EAAE,WAAW,EACjB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAC1C,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAkBxB;AAED,eAAe,IAAI,CAAC"}
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { resolve } from "pathe";
2
- import { cliFrameworkRecipe, frameworkRoots, resolveBin } from "@untestutils/core";
1
+ import { resolve, join } from "pathe";
2
+ import { cliFrameworkRecipe, configOverrideHashInput, deepMergePlain, defineDriver, frameworkRoots, matrixRecipe, resolveBin, serializeViteMergeConfigModule, writeEphemeralConfig } from "@untestutils/core";
3
3
  function resolveViteBin(root) {
4
4
  return resolveBin({
5
5
  label: "vite",
@@ -9,8 +9,22 @@ function resolveViteBin(root) {
9
9
  binRelative: ["bin/vite.js", "bin/vite.mjs"]
10
10
  });
11
11
  }
12
+ function hashInputsFor(opts, root, runTag) {
13
+ const inputs = [...opts.hashInputs ?? [root], runTag];
14
+ if (opts.viteConfig) inputs.push(configOverrideHashInput("viteConfig", opts.viteConfig));
15
+ return inputs;
16
+ }
17
+ async function viteConfigArgs(root, outDir, viteConfig) {
18
+ if (!viteConfig || !Object.keys(viteConfig).length) return [];
19
+ const configPath = join(outDir, "vite.untestutils.mjs");
20
+ await writeEphemeralConfig(configPath, serializeViteMergeConfigModule({
21
+ appRoot: root,
22
+ overrides: viteConfig
23
+ }));
24
+ return ["--config", configPath];
25
+ }
12
26
 
13
- export function vite(opts) {
27
+ export const vite = defineDriver((opts) => {
14
28
  const root = resolve(opts.root);
15
29
  const runMode = opts.run ?? "preview";
16
30
  const id = opts.id ?? `vite-${runMode}-${root.split("/").pop()}`;
@@ -22,13 +36,58 @@ export function vite(opts) {
22
36
  label: "vite",
23
37
  share: "never",
24
38
  env: opts.env,
25
- hashInputs: opts.hashInputs ?? [root, "run:dev"],
39
+ hashInputs: hashInputsFor(opts, root, "run:dev"),
26
40
  readyPath: opts.readyPath,
27
41
  readyTimeoutMs: opts.readyTimeoutMs,
28
- start: ({ port }) => ({
42
+ workspaceDeps: opts.workspaceDeps,
43
+ start: async ({ port, outDir }) => {
44
+ const configArgs = await viteConfigArgs(root, outDir, opts.viteConfig);
45
+ return {
46
+ command: process.execPath,
47
+ args: [
48
+ bin(),
49
+ ...configArgs,
50
+ "--host",
51
+ "127.0.0.1",
52
+ "--port",
53
+ String(port),
54
+ "--strictPort"
55
+ ],
56
+ cwd: root
57
+ };
58
+ }
59
+ });
60
+ }
61
+ return cliFrameworkRecipe({
62
+ id,
63
+ root,
64
+ label: "vite",
65
+ share: "always",
66
+ env: opts.env,
67
+ hashInputs: hashInputsFor(opts, root, "run:preview"),
68
+ readyPath: opts.readyPath,
69
+ readyTimeoutMs: opts.readyTimeoutMs,
70
+ workspaceDeps: opts.workspaceDeps,
71
+ prepare: async ({ outDir }) => {
72
+ const configArgs = await viteConfigArgs(root, outDir, opts.viteConfig);
73
+ return {
29
74
  command: process.execPath,
30
75
  args: [
31
76
  bin(),
77
+ "build",
78
+ ...configArgs
79
+ ],
80
+ cwd: root
81
+ };
82
+ },
83
+ start: async ({ port, outDir }) => {
84
+ const configArgs = await viteConfigArgs(root, outDir, opts.viteConfig);
85
+ return {
86
+ command: process.execPath,
87
+ args: [
88
+ bin(),
89
+ "preview",
90
+ ...configArgs,
32
91
  "--host",
33
92
  "127.0.0.1",
34
93
  "--port",
@@ -36,35 +95,28 @@ export function vite(opts) {
36
95
  "--strictPort"
37
96
  ],
38
97
  cwd: root
39
- })
40
- });
41
- }
42
- return cliFrameworkRecipe({
43
- id,
44
- root,
98
+ };
99
+ }
100
+ });
101
+ });
102
+
103
+ export function matrix(base, variants) {
104
+ return matrixRecipe(vite, base, variants, {
45
105
  label: "vite",
46
- share: "always",
47
- env: opts.env,
48
- hashInputs: opts.hashInputs ?? [root, "run:preview"],
49
- readyPath: opts.readyPath,
50
- readyTimeoutMs: opts.readyTimeoutMs,
51
- prepare: () => ({
52
- command: process.execPath,
53
- args: [bin(), "build"],
54
- cwd: root
55
- }),
56
- start: ({ port }) => ({
57
- command: process.execPath,
58
- args: [
59
- bin(),
60
- "preview",
61
- "--host",
62
- "127.0.0.1",
63
- "--port",
64
- String(port),
65
- "--strictPort"
66
- ],
67
- cwd: root
106
+ merge: (b, patch, id, name) => ({
107
+ ...b,
108
+ ...patch,
109
+ id,
110
+ env: {
111
+ ...b.env ?? {},
112
+ ...patch.env ?? {}
113
+ },
114
+ viteConfig: b.viteConfig || patch.viteConfig ? deepMergePlain(b.viteConfig ?? {}, patch.viteConfig ?? {}) : undefined,
115
+ hashInputs: [
116
+ ...b.hashInputs ?? [b.root],
117
+ ...patch.hashInputs ?? [],
118
+ `variant:${name}`
119
+ ]
68
120
  })
69
121
  });
70
122
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@untestutils/vite",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "homepage": "https://s00d.github.io/untestutils/",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "pathe": "^2.0.3",
31
- "@untestutils/core": "0.5.2"
31
+ "@untestutils/core": "0.5.3"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/node": "^26.6.1",