@vizejs/vite-plugin 0.424.10 → 0.426.0

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 { t as vize } from "./plugin-BSxbzkGl.mjs";
2
+ export { vize };
@@ -0,0 +1,202 @@
1
+ import { i as resolveConfigExport, r as loadConfig } from "./config-PP6EAmWc.mjs";
2
+ import { createRequire } from "node:module";
3
+ import { randomUUID } from "node:crypto";
4
+ import path from "node:path";
5
+ import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
6
+ import { glob } from "tinyglobby";
7
+ import { spawn, spawnSync } from "node:child_process";
8
+ import os from "node:os";
9
+ import { rm, writeFile } from "node:fs/promises";
10
+ //#region src/vite-plus/types.ts
11
+ const sourceConfigKey = Symbol.for("@vizejs/vite-plugin/vite-plus/source");
12
+ const taskConfigKey = Symbol.for("@vizejs/vite-plugin/vite-plus");
13
+ //#endregion
14
+ //#region src/vite-plus/runtime.ts
15
+ function resolveVitePlus() {
16
+ const require = createRequire(path.resolve("package.json"));
17
+ let packageFile;
18
+ try {
19
+ packageFile = require.resolve("vite-plus/package.json");
20
+ } catch {
21
+ throw new Error("defineConfig requires vite-plus installed in this project. Install your preferred version first.");
22
+ }
23
+ const manifest = JSON.parse(readFileSync(packageFile, "utf8"));
24
+ return {
25
+ require,
26
+ binary: path.resolve(path.dirname(packageFile), manifest.bin.vp)
27
+ };
28
+ }
29
+ const catalogs = /* @__PURE__ */ new Map();
30
+ /** Only disable rules supported by the consumer's bundled Oxlint. */
31
+ function availableVueRules() {
32
+ const { binary } = resolveVitePlus();
33
+ const cached = catalogs.get(binary);
34
+ if (cached) return cached;
35
+ const directory = mkdtempSync(path.join(os.tmpdir(), "vize-oxlint-rules-"));
36
+ try {
37
+ writeFileSync(path.join(directory, "package.json"), "{\"name\":\"vize-rule-catalog\",\"private\":true}");
38
+ const result = spawnSync(process.execPath, [
39
+ binary,
40
+ "lint",
41
+ "--rules",
42
+ "--format=json"
43
+ ], {
44
+ cwd: directory,
45
+ encoding: "utf8",
46
+ timeout: 1e4,
47
+ maxBuffer: 4 * 1024 * 1024
48
+ });
49
+ if (result.error || result.status !== 0) throw new Error(`Cannot read installed Vite+ lint rules: ${result.error?.message ?? result.stderr}`);
50
+ const rules = JSON.parse(result.stdout);
51
+ if (!Array.isArray(rules)) throw new Error("Installed Vite+ returned an invalid lint rule catalog");
52
+ const available = new Set(rules.filter((rule) => rule.scope === "vue").map((rule) => rule.value));
53
+ catalogs.set(binary, available);
54
+ return available;
55
+ } finally {
56
+ rmSync(directory, {
57
+ recursive: true,
58
+ force: true
59
+ });
60
+ }
61
+ }
62
+ //#endregion
63
+ //#region src/vite-plus/runner.ts
64
+ /** Run every selected checker, even when an earlier tool reports diagnostics. */
65
+ async function runTools(task, args, metadata, vp, native, execute) {
66
+ const { options } = metadata;
67
+ const lint = task === "check" || task === "lint" || task === "lint:fix";
68
+ const fmt = task === "check" || task === "fmt" || task === "fmt:check";
69
+ const fix = task === "lint:fix" || args.includes("--fix");
70
+ const formatCheck = task === "fmt:check" || task === "check" && !fix || args.includes("--check");
71
+ if (task === "check" && args.some((arg) => arg.startsWith("-") && arg !== "--fix")) throw new Error("Vize check tasks accept paths and --fix. Put native tool options in defineConfig().");
72
+ let status = 0;
73
+ async function run(binary, argv) {
74
+ const code = await execute(process.execPath, [binary, ...argv]);
75
+ if (code >= 128) throw Object.assign(/* @__PURE__ */ new Error("Vize task interrupted"), { exitCode: code });
76
+ status = Math.max(status, code);
77
+ }
78
+ async function vize(command, argv) {
79
+ const code = await runNative(command, argv, metadata, native, execute);
80
+ if (code >= 128) throw Object.assign(/* @__PURE__ */ new Error("Vize task interrupted"), { exitCode: code });
81
+ status = Math.max(status, code);
82
+ }
83
+ if (options.check !== false && (task === "check" || task === "typecheck" || lint && metadata.lintTypecheck)) await vize("check", args.filter((arg) => arg !== "--fix"));
84
+ if (lint) {
85
+ const lintArgs = fix && !args.includes("--fix") ? ["--fix", ...args] : args;
86
+ if (options.lint !== false) await vize("lint", lintArgs);
87
+ await run(vp, ["lint", ...lintArgs]);
88
+ }
89
+ if (fmt) {
90
+ const patterns = args.filter((arg) => ![
91
+ "--check",
92
+ "--write",
93
+ "-w",
94
+ "--fix"
95
+ ].includes(arg));
96
+ if (patterns.some((arg) => arg.startsWith("-"))) throw new Error("Vize fmt tasks accept paths and --check/--write. Put native formatter options in defineConfig({ fmt: { vize: ... } }).");
97
+ if (options.fmt !== false) {
98
+ const vue = (await glob(patterns.length ? patterns : ["**/*.vue"], {
99
+ expandDirectories: true,
100
+ ignore: [
101
+ "**/node_modules/**",
102
+ "**/.git/**",
103
+ "**/.vize/**"
104
+ ]
105
+ })).filter((file) => file.endsWith(".vue"));
106
+ if (vue.length) await vize("fmt", [formatCheck ? "--check" : "--write", ...vue]);
107
+ }
108
+ await run(vp, [
109
+ "fmt",
110
+ formatCheck ? "--check" : "--write",
111
+ ...patterns
112
+ ]);
113
+ }
114
+ return status;
115
+ }
116
+ async function runTask(argv) {
117
+ const [task, ...rest] = argv;
118
+ const args = rest[0] === "--" ? rest.slice(1) : rest;
119
+ if (task === "editor:setup") {
120
+ const { setupEditor } = await import("./editor-D3tfVb0Z.mjs");
121
+ await setupEditor();
122
+ return 0;
123
+ }
124
+ const { require, binary: vp } = resolveVitePlus();
125
+ if ([
126
+ "build",
127
+ "dev",
128
+ "preview",
129
+ "test",
130
+ "pack"
131
+ ].includes(task)) return execute(process.execPath, [
132
+ vp,
133
+ task,
134
+ ...args
135
+ ]);
136
+ if (![
137
+ "check",
138
+ "typecheck",
139
+ "lint",
140
+ "lint:fix",
141
+ "fmt",
142
+ "fmt:check"
143
+ ].includes(task)) throw new Error(`Unknown Vize task: ${task}`);
144
+ const { loadConfigFromFile } = require("vite-plus");
145
+ const metadata = ((await loadConfigFromFile({
146
+ command: "build",
147
+ mode: "production"
148
+ }))?.config)?.[taskConfigKey];
149
+ if (!metadata) throw new Error("The current vite.config must use defineConfig from @vizejs/vite-plugin/vite-plus.");
150
+ return runTools(task, args, metadata, vp, nativeBinary(), execute);
151
+ }
152
+ async function execute(command, args) {
153
+ return new Promise((resolve) => {
154
+ const child = spawn(command, args, { stdio: "inherit" });
155
+ const forwardInt = () => child.kill("SIGINT");
156
+ const forwardTerm = () => child.kill("SIGTERM");
157
+ process.on("SIGINT", forwardInt);
158
+ process.on("SIGTERM", forwardTerm);
159
+ const cleanup = () => {
160
+ process.off("SIGINT", forwardInt);
161
+ process.off("SIGTERM", forwardTerm);
162
+ };
163
+ child.once("error", (error) => {
164
+ cleanup();
165
+ console.error(error.message);
166
+ resolve(1);
167
+ });
168
+ child.once("exit", (code, signal) => {
169
+ cleanup();
170
+ resolve(code ?? (signal === "SIGINT" ? 130 : signal === "SIGTERM" ? 143 : 1));
171
+ });
172
+ });
173
+ }
174
+ function nativeBinary() {
175
+ const require = createRequire(import.meta.url);
176
+ return path.resolve(path.dirname(require.resolve("vize")), "../bin/vize");
177
+ }
178
+ async function runNative(command, argv, metadata, native = nativeBinary(), spawn = execute) {
179
+ const env = {
180
+ mode: "production",
181
+ command
182
+ };
183
+ const config = metadata.config === void 0 ? await loadConfig(process.cwd(), { env }) ?? {} : await resolveConfigExport(metadata.config, env);
184
+ const file = path.resolve(`.vize-vp-${randomUUID()}.json`);
185
+ try {
186
+ await writeFile(file, JSON.stringify(config), {
187
+ flag: "wx",
188
+ mode: 384
189
+ });
190
+ return await spawn(process.execPath, [
191
+ native,
192
+ command,
193
+ "--config",
194
+ file,
195
+ ...argv
196
+ ]);
197
+ } finally {
198
+ await rm(file, { force: true });
199
+ }
200
+ }
201
+ //#endregion
202
+ export { sourceConfigKey as a, resolveVitePlus as i, runTask as n, taskConfigKey as o, availableVueRules as r, runNative as t };
@@ -0,0 +1,69 @@
1
+ import { i as resolveConfigExport, r as loadConfig } from "./config-PP6EAmWc.mjs";
2
+ //#region src/plugin/shared-config.ts
3
+ function mergeSharedConfig(baseConfig, overrideConfig) {
4
+ if (!baseConfig) return overrideConfig;
5
+ if (!overrideConfig) return baseConfig;
6
+ return {
7
+ ...baseConfig,
8
+ ...overrideConfig,
9
+ compiler: {
10
+ ...baseConfig.compiler,
11
+ ...overrideConfig.compiler
12
+ },
13
+ vite: {
14
+ ...baseConfig.vite,
15
+ ...overrideConfig.vite
16
+ },
17
+ linter: {
18
+ ...baseConfig.linter,
19
+ ...overrideConfig.linter
20
+ },
21
+ typeChecker: {
22
+ ...baseConfig.typeChecker,
23
+ ...overrideConfig.typeChecker
24
+ },
25
+ formatter: {
26
+ ...baseConfig.formatter,
27
+ ...overrideConfig.formatter
28
+ },
29
+ languageServer: {
30
+ ...baseConfig.languageServer,
31
+ ...overrideConfig.languageServer
32
+ },
33
+ musea: {
34
+ ...baseConfig.musea,
35
+ ...overrideConfig.musea
36
+ },
37
+ globalTypes: {
38
+ ...baseConfig.globalTypes,
39
+ ...overrideConfig.globalTypes
40
+ },
41
+ entries: [...baseConfig.entries, ...overrideConfig.entries]
42
+ };
43
+ }
44
+ async function resolveSharedConfig(options, root, env, logger) {
45
+ let fileConfig = null;
46
+ if (options.configMode !== false) {
47
+ const configFile = options.configFile ?? process.env["VIZE_CONFIG_FILE"];
48
+ try {
49
+ fileConfig = await loadConfig(root, {
50
+ mode: options.configMode ?? "root",
51
+ configFile,
52
+ env
53
+ });
54
+ if (fileConfig) logger.log("Loaded config from vize.config file");
55
+ } catch (error) {
56
+ logger.warn(`Failed to load vize config from ${configFile ?? root}:`, error);
57
+ }
58
+ }
59
+ let inlineConfig = null;
60
+ if (options.config) try {
61
+ inlineConfig = await resolveConfigExport(options.config, env);
62
+ logger.log("Loaded inline vize config from plugin options");
63
+ } catch (error) {
64
+ logger.warn("Failed to resolve inline vize config:", error);
65
+ }
66
+ return mergeSharedConfig(fileConfig, inlineConfig);
67
+ }
68
+ //#endregion
69
+ export { resolveSharedConfig as n, mergeSharedConfig as t };
@@ -1164,4 +1164,4 @@ interface VizeOptions extends ExperimentalPluginOptions {
1164
1164
  debug?: boolean;
1165
1165
  }
1166
1166
  //#endregion
1167
- export { VizeInspectorLintPlanProvider as a, VizeCompatibilityOptions as c, LoadConfigOptions as d, ResolvedVizeConfig as f, VizeVueFeatures as i, VizeVueVersion as l, VizeConfig as m, CompiledModule as n, VizeInspectorLintPlanRequest as o, UserConfigExport as p, MacroArtifact as r, VizeInspectorOptions as s, VizeOptions as t, ConfigEnv as u };
1167
+ export { LinterConfig as _, VizeInspectorLintPlanProvider as a, VizeCompatibilityOptions as c, LoadConfigOptions as d, ResolvedVizeConfig as f, FormatterConfig as g, CompilerConfig as h, VizeVueFeatures as i, VizeVueVersion as l, UserConfigExport as m, CompiledModule as n, VizeInspectorLintPlanRequest as o, UserConfig as p, MacroArtifact as r, VizeInspectorOptions as s, VizeOptions as t, ConfigEnv as u, TypeCheckerConfig as v, VizeConfig as y };
@@ -0,0 +1,65 @@
1
+ import { _ as LinterConfig, g as FormatterConfig, h as CompilerConfig, m as UserConfigExport, p as UserConfig$1, t as VizeOptions, v as TypeCheckerConfig } from "./types-CtulgM97.mjs";
2
+ import { ConfigEnv, UserConfig, defineConfig as defineConfig$1 } from "vite-plus";
3
+
4
+ //#region src/vite-plus/types.d.ts
5
+ /** Inherit configuration additions from the consumer's Vite+ version. */
6
+ type VitePlusConfig = Parameters<typeof defineConfig$1>[0];
7
+ type VizeCompilerOptions = Omit<CompilerConfig, "compatibility"> & Omit<VizeOptions, "config">;
8
+ interface VizeLintOptions extends LinterConfig {
9
+ /** Also run the native typechecker before linting. @default false */
10
+ typecheck?: boolean;
11
+ }
12
+ interface VizePackOptions {
13
+ /** Emit Vue and TypeScript declarations after the bundle succeeds. @default true */
14
+ dts?: boolean;
15
+ /** Override the native declaration output directory. Defaults to pack.outDir. */
16
+ declarationDir?: string;
17
+ /** Emit declaration maps pointing to authored sources. */
18
+ declarationMap?: boolean;
19
+ /** Enable compiler and bundle source maps. */
20
+ sourcemap?: boolean;
21
+ /** TypeScript project used for declaration generation. */
22
+ tsconfig?: string;
23
+ }
24
+ type WithPack<T> = T extends (infer Item)[] ? WithPack<Item>[] : T & {
25
+ vize?: VizePackOptions | false;
26
+ };
27
+ type VizeSharedConfig = UserConfig$1 & {
28
+ /** Alias of lint.vize; lint.vize takes precedence when both are provided. */lint?: VizeLintOptions | boolean;
29
+ };
30
+ interface VueIntegrationConfig {
31
+ extends?: VueConfig | VueConfig[];
32
+ compiler?: VizeCompilerOptions | false;
33
+ typecheck?: TypeCheckerConfig | boolean;
34
+ lint?: UserConfig["lint"] & {
35
+ vize?: VizeLintOptions | boolean;
36
+ };
37
+ fmt?: UserConfig["fmt"] & {
38
+ vize?: FormatterConfig | boolean;
39
+ };
40
+ pack?: WithPack<NonNullable<UserConfig["pack"]>>;
41
+ /** Shared native settings, including scopes, globals and editor settings. */
42
+ vize?: VizeSharedConfig | UserConfigExport;
43
+ }
44
+ type WithVize<T> = T extends ((...args: infer Args) => infer Result) ? (...args: Args) => WithVize<Result> : T extends Promise<infer Result> ? Promise<WithVize<Result>> : Omit<T, "lint" | "fmt" | "pack"> & VueIntegrationConfig;
45
+ type VueConfig = WithVize<VitePlusConfig>;
46
+ type VueConfigObject = Omit<UserConfig, "lint" | "fmt" | "pack"> & VueIntegrationConfig;
47
+ type VizeTask = "editor:setup" | "check" | "typecheck" | "lint" | "lint:fix" | "fmt" | "fmt:check" | "pack" | "build" | "dev" | "preview" | "test";
48
+ interface VizePlusOptions {
49
+ /** Compiler plugin options; prefer the compiler config section. */
50
+ plugin?: Omit<VizeOptions, "config"> | false;
51
+ check?: boolean;
52
+ lint?: boolean;
53
+ fmt?: boolean;
54
+ /** Disable overlapping Oxlint rules and exclude Vue from Oxfmt. @default true */
55
+ conflicts?: boolean;
56
+ /** Rename or disable generated tasks. Existing run.tasks take precedence. */
57
+ tasks?: false | Partial<Record<VizeTask, string | false>>;
58
+ }
59
+ type VizePlusConfigFactory = (env: ConfigEnv) => Promise<UserConfig>;
60
+ //#endregion
61
+ //#region src/vite-plus.d.ts
62
+ /** Extend the installed Vite+ configuration with the native Vue toolchain. */
63
+ declare function defineConfig(config?: VueConfig, integration?: VizePlusOptions): VizePlusConfigFactory;
64
+ //#endregion
65
+ export { type VitePlusConfig, type VizeCompilerOptions, type VizeLintOptions, type VizePackOptions, type VizePlusConfigFactory, type VizePlusOptions, type VizeTask, type VueConfig, type VueConfigObject, defineConfig, defineConfig as withVize, defineConfig as withVue };