@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,352 @@
1
+ import { i as resolveConfigExport, r as loadConfig } from "./config-PP6EAmWc.mjs";
2
+ import { t as mergeSharedConfig } from "./shared-config-dMxrrTkb.mjs";
3
+ import { a as sourceConfigKey, i as resolveVitePlus, o as taskConfigKey, r as availableVueRules, t as runNative } from "./runner-DvShtC55.mjs";
4
+ import { randomUUID } from "node:crypto";
5
+ import path from "node:path";
6
+ import { readFileSync } from "node:fs";
7
+ import { fileURLToPath } from "node:url";
8
+ import { readFile, rm, stat, writeFile } from "node:fs/promises";
9
+ import { parse } from "jsonc-parser";
10
+ //#region src/vite-plus/conflicts.ts
11
+ const overlappingVueRules = [
12
+ "component-definition-name-casing",
13
+ "define-emits-declaration",
14
+ "define-props-declaration",
15
+ "define-props-destructuring",
16
+ "no-arrow-functions-in-watch",
17
+ "no-async-in-computed-properties",
18
+ "no-deprecated-data-object-declaration",
19
+ "no-deprecated-destroyed-lifecycle",
20
+ "no-deprecated-events-api",
21
+ "no-deprecated-props-default-this",
22
+ "no-dupe-keys",
23
+ "no-export-in-script-setup",
24
+ "no-import-compiler-macros",
25
+ "no-multiple-slot-args",
26
+ "no-required-prop-with-default",
27
+ "no-reserved-component-names",
28
+ "no-reserved-keys",
29
+ "no-reserved-props",
30
+ "no-side-effects-in-computed-properties",
31
+ "prefer-import-from-vue",
32
+ "prop-name-casing",
33
+ "require-default-prop",
34
+ "require-prop-type-constructor",
35
+ "require-prop-types",
36
+ "require-typed-ref",
37
+ "return-in-computed-property",
38
+ "return-in-emits-validator",
39
+ "valid-define-emits",
40
+ "valid-define-options",
41
+ "valid-define-props",
42
+ "valid-next-tick"
43
+ ];
44
+ function configureTools(config, options) {
45
+ if (options.conflicts === false) return config;
46
+ const supported = options.lint === false ? /* @__PURE__ */ new Set() : availableVueRules();
47
+ return {
48
+ ...config,
49
+ lint: options.lint === false ? config.lint : {
50
+ ...config.lint,
51
+ ignorePatterns: [...new Set([
52
+ ...config.lint?.ignorePatterns ?? [],
53
+ "**/node_modules/**",
54
+ "**/.vize/**"
55
+ ])],
56
+ plugins: [...new Set(["vue", ...config.lint?.plugins ?? [
57
+ "eslint",
58
+ "typescript",
59
+ "unicorn",
60
+ "oxc"
61
+ ]])],
62
+ rules: {
63
+ ...Object.fromEntries(overlappingVueRules.filter((rule) => supported.has(rule)).map((rule) => [`vue/${rule}`, "off"])),
64
+ ...config.lint?.rules
65
+ }
66
+ },
67
+ fmt: options.fmt === false ? config.fmt : {
68
+ ...config.fmt,
69
+ ignorePatterns: [...new Set([
70
+ ...config.fmt?.ignorePatterns ?? [],
71
+ "**/node_modules/**",
72
+ "**/.vize/**",
73
+ "**/*.vue"
74
+ ])]
75
+ }
76
+ };
77
+ }
78
+ //#endregion
79
+ //#region src/vite-plus/tasks.ts
80
+ const tasks = [
81
+ "editor:setup",
82
+ "check",
83
+ "typecheck",
84
+ "lint",
85
+ "lint:fix",
86
+ "fmt",
87
+ "fmt:check",
88
+ "build",
89
+ "pack",
90
+ "dev",
91
+ "preview",
92
+ "test"
93
+ ];
94
+ function createTasks(existing = {}, names = {}) {
95
+ if (names === false) return {};
96
+ const runner = fileURLToPath(import.meta.resolve("@vizejs/vite-plugin/internal/vite-plus-task"));
97
+ let scripts = {};
98
+ try {
99
+ scripts = JSON.parse(readFileSync(path.resolve("package.json"), "utf8")).scripts ?? {};
100
+ } catch (error) {
101
+ if (error.code !== "ENOENT") throw error;
102
+ }
103
+ const result = {};
104
+ for (const task of tasks) {
105
+ if (names[task] === false) continue;
106
+ const name = names[task] ?? (task in scripts ? `vize:${task}` : task);
107
+ if (name in existing) continue;
108
+ if (name in scripts || name in result) throw new Error(`defineConfig task "${name}" already exists. Choose another name with options.tasks.`);
109
+ result[name] = {
110
+ command: `node ${quote(runner)} ${task}`,
111
+ cache: false
112
+ };
113
+ }
114
+ return result;
115
+ }
116
+ function quote(value) {
117
+ if (process.platform === "win32") {
118
+ if (/["%\r\n]/u.test(value)) throw new Error("Unsupported character in Vize installation path");
119
+ return `"${value}"`;
120
+ }
121
+ return `'${value.replaceAll("'", "'\\''")}'`;
122
+ }
123
+ //#endregion
124
+ //#region src/vite-plus/config.ts
125
+ async function resolveConfig(config, env, parents = /* @__PURE__ */ new Set()) {
126
+ if (parents.has(config)) throw new Error("Circular extends in Vize's Vite+ config");
127
+ parents.add(config);
128
+ try {
129
+ if (typeof config === "function" && sourceConfigKey in config) return resolveConfig(config[sourceConfigKey], env, parents);
130
+ const { extends: bases, ...own } = await (typeof config === "function" ? config(env) : config);
131
+ if (!bases) return own;
132
+ let result = {};
133
+ const { mergeConfig } = resolveVitePlus().require("vite-plus");
134
+ for (const base of Array.isArray(bases) ? bases : bases ? [bases] : []) result = mergeConfig(result, await resolveConfig(base, env, parents));
135
+ return mergeConfig(result, own);
136
+ } finally {
137
+ parents.delete(config);
138
+ }
139
+ }
140
+ function normalizeConfig(source, integration) {
141
+ const { compiler: compilerOption, typecheck, vize, lint, fmt, extends: _bases, ...rest } = source;
142
+ const { vize: nativeLint, ...oxlint } = lint ?? {};
143
+ const { vize: nativeFmt, ...oxfmt } = fmt ?? {};
144
+ const alias = vize && typeof vize === "object" && !Array.isArray(vize) ? vize.lint : void 0;
145
+ const lintConfig = typeof alias === "object" && typeof nativeLint === "object" ? {
146
+ ...alias,
147
+ ...nativeLint,
148
+ rules: {
149
+ ...alias.rules,
150
+ ...nativeLint.rules
151
+ }
152
+ } : nativeLint === void 0 ? alias : nativeLint;
153
+ const compiler = compilerOption ?? integration.plugin ?? {};
154
+ const options = {
155
+ ...integration,
156
+ check: typecheck === false ? false : typeof typecheck === "object" ? typecheck.enabled !== false : typecheck ?? integration.check,
157
+ lint: lintConfig === void 0 ? integration.lint : lintConfig !== false,
158
+ fmt: nativeFmt === void 0 ? integration.fmt : nativeFmt !== false
159
+ };
160
+ const config = async (env) => {
161
+ let base = vize;
162
+ if (vize && typeof vize === "object" && !Array.isArray(vize)) {
163
+ const { lint: _alias, ...shared } = vize;
164
+ base = shared;
165
+ }
166
+ return mergeSharedConfig(base === void 0 ? await loadConfig(process.cwd(), { env }) : await resolveConfigExport(base, env), await resolveConfigExport({
167
+ ...compiler === false ? {} : { compiler: nativeCompiler(compiler) },
168
+ ...typeof typecheck === "object" ? { typeChecker: typecheck } : {},
169
+ ...typeof lintConfig === "object" ? { linter: withoutTypecheck(lintConfig) } : {},
170
+ ...typeof nativeFmt === "object" ? { formatter: nativeFmt } : {}
171
+ }, env)) ?? {};
172
+ };
173
+ const metadata = {
174
+ config,
175
+ options,
176
+ lintTypecheck: typeof lintConfig === "object" && lintConfig.typecheck === true
177
+ };
178
+ return {
179
+ vp: {
180
+ ...rest,
181
+ lint: lint ? oxlint : void 0,
182
+ fmt: fmt ? oxfmt : void 0
183
+ },
184
+ metadata,
185
+ compiler
186
+ };
187
+ }
188
+ function withoutTypecheck(config) {
189
+ const { typecheck: _typecheck, ...native } = config;
190
+ return native;
191
+ }
192
+ function nativeCompiler(options) {
193
+ const { compatibility, ...compiler } = options;
194
+ const version = options.vueVersion ?? compatibility?.vueVersion;
195
+ const versions = {
196
+ .11: "0.11",
197
+ 1: "1",
198
+ 2: "2",
199
+ "2.7": "2.7",
200
+ 3: "3",
201
+ legacy: "2"
202
+ };
203
+ return {
204
+ ...compiler,
205
+ compatibility: {
206
+ ...compatibility,
207
+ vueVersion: version === void 0 ? void 0 : versions[version]
208
+ }
209
+ };
210
+ }
211
+ //#endregion
212
+ //#region src/vite-plus/declarations.ts
213
+ /** Keep authored tsconfigs untouched, including maps and project references. */
214
+ async function emitDeclarations(options, metadata) {
215
+ const config = metadata.config ? await resolveConfigExport(metadata.config, {
216
+ command: "check",
217
+ mode: "production"
218
+ }) : void 0;
219
+ const files = [];
220
+ const copies = /* @__PURE__ */ new Map();
221
+ async function withMaps(file) {
222
+ file = path.resolve(file);
223
+ if ((await stat(file)).isDirectory()) file = path.join(file, "tsconfig.json");
224
+ const known = copies.get(file);
225
+ if (known) return known;
226
+ const errors = [];
227
+ const source = parse(await readFile(file, "utf8"), errors, { allowTrailingComma: true });
228
+ if (errors.length || !source || typeof source !== "object") throw new Error(`Invalid TypeScript config: ${file}`);
229
+ const temporary = path.join(path.dirname(file), `.vize-vp-${randomUUID()}.json`);
230
+ copies.set(file, temporary);
231
+ const references = source.references ? await Promise.all(source.references.map(async (reference) => ({
232
+ ...reference,
233
+ path: await withMaps(path.resolve(path.dirname(file), reference.path))
234
+ }))) : void 0;
235
+ files.push(temporary);
236
+ await writeFile(temporary, JSON.stringify({
237
+ extends: file,
238
+ compilerOptions: {
239
+ declaration: true,
240
+ declarationMap: options.declarationMap
241
+ },
242
+ references
243
+ }), {
244
+ flag: "wx",
245
+ mode: 384
246
+ });
247
+ return temporary;
248
+ }
249
+ try {
250
+ let tsconfig = options.tsconfig ?? config?.typeChecker?.tsconfig ?? "tsconfig.json";
251
+ if (options.declarationMap !== void 0) tsconfig = await withMaps(tsconfig);
252
+ const args = [
253
+ "--declaration",
254
+ "--tsconfig",
255
+ tsconfig
256
+ ];
257
+ if (options.declarationDir) args.push("--declaration-dir", path.resolve(options.declarationDir));
258
+ const status = await runNative("check", args, metadata);
259
+ if (status !== 0) throw new Error(`Vize declaration generation failed (exit ${status})`);
260
+ } finally {
261
+ await Promise.all(files.map((file) => rm(file, { force: true })));
262
+ }
263
+ }
264
+ //#endregion
265
+ //#region src/vite-plus/pack.ts
266
+ async function configurePack(input, compiler, metadata) {
267
+ if (input === void 0) return void 0;
268
+ if (Array.isArray(input)) return Promise.all(input.map(async (entry) => await configurePack(entry, compiler, metadata)));
269
+ const { vize: native, ...pack } = input;
270
+ if (native === false) return pack;
271
+ const sourcemap = native?.sourcemap ?? pack.sourcemap;
272
+ const plugins = Array.isArray(pack.plugins) ? [...pack.plugins] : pack.plugins ? [pack.plugins] : [];
273
+ if (compiler !== false) {
274
+ const { default: vize } = await import("@vizejs/unplugin/rolldown");
275
+ const shared = metadata.config ? await resolveConfigExport(metadata.config, {
276
+ command: "build",
277
+ mode: "production"
278
+ }) : void 0;
279
+ plugins.unshift(vize({
280
+ ...shared?.compiler,
281
+ compatibility: compiler.compatibility,
282
+ ...compiler,
283
+ isProduction: true,
284
+ sourceMap: native?.sourcemap ?? compiler.sourceMap ?? Boolean(sourcemap)
285
+ }));
286
+ }
287
+ if (!native || native.dts === false) return {
288
+ ...pack,
289
+ sourcemap,
290
+ plugins
291
+ };
292
+ return {
293
+ ...pack,
294
+ sourcemap,
295
+ plugins,
296
+ dts: false,
297
+ async hooks(hooks) {
298
+ if (typeof pack.hooks === "function") await pack.hooks(hooks);
299
+ else if (pack.hooks) hooks.addHooks(pack.hooks);
300
+ hooks.hook("build:done", async (context) => {
301
+ await emitDeclarations({
302
+ ...native,
303
+ tsconfig: native.tsconfig ?? (typeof pack.tsconfig === "string" ? pack.tsconfig : void 0),
304
+ declarationDir: native.declarationDir ?? context.options.outDir
305
+ }, metadata);
306
+ });
307
+ }
308
+ };
309
+ }
310
+ //#endregion
311
+ //#region src/vite-plus.ts
312
+ /** Extend the installed Vite+ configuration with the native Vue toolchain. */
313
+ function defineConfig(config = {}, integration = {}) {
314
+ return Object.assign(async (env) => {
315
+ const source = await resolveConfig(config, env);
316
+ const { vp, metadata, compiler } = normalizeConfig(source, integration);
317
+ const { options } = metadata;
318
+ const plugins = compiler === false ? [...vp.plugins ?? []] : await withoutVueCompiler(vp.plugins ?? []);
319
+ if (compiler !== false) {
320
+ const { vize } = await import("./plugin-CewswkDY.mjs");
321
+ plugins.unshift(vize({
322
+ ...compiler,
323
+ configMode: false,
324
+ config: metadata.config
325
+ }));
326
+ }
327
+ return {
328
+ ...configureTools(vp, options),
329
+ plugins,
330
+ pack: await configurePack(source.pack, compiler, metadata),
331
+ run: options.tasks === false ? vp.run : {
332
+ ...vp.run,
333
+ tasks: {
334
+ ...createTasks(vp.run?.tasks, options.tasks),
335
+ ...vp.run?.tasks
336
+ }
337
+ },
338
+ [taskConfigKey]: metadata
339
+ };
340
+ }, { [sourceConfigKey]: config });
341
+ }
342
+ async function withoutVueCompiler(plugins) {
343
+ const result = [];
344
+ for (const option of plugins) {
345
+ const plugin = await option;
346
+ if (Array.isArray(plugin)) result.push(...await withoutVueCompiler(plugin));
347
+ else if (plugin && plugin.name !== "vite:vue") result.push(plugin);
348
+ }
349
+ return result;
350
+ }
351
+ //#endregion
352
+ export { defineConfig, defineConfig as withVize, defineConfig as withVue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/vite-plugin",
3
- "version": "0.424.10",
3
+ "version": "0.426.0",
4
4
  "description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
5
5
  "keywords": [
6
6
  "compiler",
@@ -35,6 +35,12 @@
35
35
  "import": "./dist/index.mjs",
36
36
  "default": "./dist/index.mjs"
37
37
  },
38
+ "./vite-plus": {
39
+ "types": "./dist/vite-plus.d.mts",
40
+ "import": "./dist/vite-plus.mjs",
41
+ "default": "./dist/vite-plus.mjs"
42
+ },
43
+ "./internal/vite-plus-task": "./dist/internal/vite-plus-task.mjs",
38
44
  "./internal/config-bridge": {
39
45
  "types": "./dist/internal/config-bridge.d.mts",
40
46
  "import": "./dist/internal/config-bridge.mjs",
@@ -45,29 +51,43 @@
45
51
  "access": "public"
46
52
  },
47
53
  "dependencies": {
48
- "@vizejs/native": "0.424.10",
54
+ "@vizejs/native": "0.426.0",
55
+ "@vizejs/unplugin": "0.426.0",
56
+ "jsonc-parser": "^3.3.1",
49
57
  "oxc-parser": "0.144.0",
50
58
  "tinyglobby": "0.2.17",
51
- "vize": "0.424.10"
59
+ "vize": "0.426.0"
52
60
  },
53
61
  "devDependencies": {
54
62
  "@types/node": "25.9.2",
55
63
  "typescript": "6.0.3",
56
64
  "vite": "npm:@voidzero-dev/vite-plus-core@0.1.24",
57
- "vite-plus": "0.1.24"
65
+ "vite-plus": "^0.2.3"
58
66
  },
59
67
  "peerDependencies": {
60
- "vite": "^7.3.0 || ^8.0.0"
68
+ "vite": "^7.3.0 || ^8.0.0",
69
+ "vite-plus": ">=0.2.3"
70
+ },
71
+ "peerDependenciesMeta": {
72
+ "vite-plus": {
73
+ "optional": true
74
+ }
61
75
  },
62
76
  "engines": {
63
77
  "node": ">=22"
64
78
  },
79
+ "metadata": {
80
+ "vize": {
81
+ "stability": "alpha-supported",
82
+ "stabilityDocs": "https://github.com/ubugeeei-prod/vize/blob/main/docs/content/stability.md#package-support-tiers"
83
+ }
84
+ },
65
85
  "scripts": {
66
86
  "build": "vp pack",
67
87
  "dev": "vp pack --watch",
68
88
  "check": "vp check src vite.config.ts",
69
89
  "check:fix": "vp check --fix src vite.config.ts",
70
90
  "fmt": "vp fmt --write src vite.config.ts",
71
- "test": "pnpm --dir ../../native build:debug && node src/test.ts"
91
+ "test": "pnpm --dir ../../native build:debug && node src/test.ts && node --test src/vite-plus/*.test.ts"
72
92
  }
73
93
  }