@vizejs/vite-plugin 0.0.1-alpha.76 → 0.0.1-alpha.77

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.ts CHANGED
@@ -1,7 +1,406 @@
1
1
  import { Plugin } from "vite";
2
2
 
3
+ //#region ../vize/src/types.d.ts
4
+ type MaybePromise<T> = T | Promise<T>;
5
+ interface ConfigEnv {
6
+ mode: string;
7
+ command: "serve" | "build" | "check" | "lint" | "fmt";
8
+ isSsrBuild?: boolean;
9
+ }
10
+ type UserConfigExport = VizeConfig | ((env: ConfigEnv) => MaybePromise<VizeConfig>);
11
+ type RuleSeverity = "off" | "warn" | "error";
12
+ type RuleCategory = "correctness" | "suspicious" | "style" | "perf" | "a11y" | "security";
13
+ /**
14
+ * Vize configuration options
15
+ */
16
+ interface VizeConfig {
17
+ /**
18
+ * Vue compiler options
19
+ */
20
+ compiler?: CompilerConfig;
21
+ /**
22
+ * Vite plugin options
23
+ */
24
+ vite?: VitePluginConfig;
25
+ /**
26
+ * Linter options
27
+ */
28
+ linter?: LinterConfig;
29
+ /**
30
+ * Type checker options
31
+ */
32
+ typeChecker?: TypeCheckerConfig;
33
+ /**
34
+ * Formatter options
35
+ */
36
+ formatter?: FormatterConfig;
37
+ /**
38
+ * LSP options
39
+ */
40
+ lsp?: LspConfig;
41
+ /**
42
+ * Musea component gallery options
43
+ */
44
+ musea?: MuseaConfig;
45
+ /**
46
+ * Global type declarations
47
+ */
48
+ globalTypes?: GlobalTypesConfig;
49
+ }
50
+ /**
51
+ * Compiler configuration
52
+ */
53
+ interface CompilerConfig {
54
+ /**
55
+ * Compilation mode
56
+ * @default 'module'
57
+ */
58
+ mode?: "module" | "function";
59
+ /**
60
+ * Enable Vapor mode compilation
61
+ * @default false
62
+ */
63
+ vapor?: boolean;
64
+ /**
65
+ * Enable SSR mode
66
+ * @default false
67
+ */
68
+ ssr?: boolean;
69
+ /**
70
+ * Enable source map generation
71
+ * @default true in development, false in production
72
+ */
73
+ sourceMap?: boolean;
74
+ /**
75
+ * Prefix template identifiers with _ctx
76
+ * @default false
77
+ */
78
+ prefixIdentifiers?: boolean;
79
+ /**
80
+ * Hoist static nodes
81
+ * @default true
82
+ */
83
+ hoistStatic?: boolean;
84
+ /**
85
+ * Cache v-on handlers
86
+ * @default true
87
+ */
88
+ cacheHandlers?: boolean;
89
+ /**
90
+ * Enable TypeScript parsing in <script> blocks
91
+ * @default true
92
+ */
93
+ isTs?: boolean;
94
+ /**
95
+ * Script file extension for generated output
96
+ * @default 'ts'
97
+ */
98
+ scriptExt?: "ts" | "js";
99
+ /**
100
+ * Module name for runtime imports
101
+ * @default 'vue'
102
+ */
103
+ runtimeModuleName?: string;
104
+ /**
105
+ * Global variable name for runtime (IIFE builds)
106
+ * @default 'Vue'
107
+ */
108
+ runtimeGlobalName?: string;
109
+ }
110
+ /**
111
+ * Vite plugin configuration
112
+ */
113
+ interface VitePluginConfig {
114
+ /**
115
+ * Files to include in compilation
116
+ * @default /\.vue$/
117
+ */
118
+ include?: string | RegExp | (string | RegExp)[];
119
+ /**
120
+ * Files to exclude from compilation
121
+ * @default /node_modules/
122
+ */
123
+ exclude?: string | RegExp | (string | RegExp)[];
124
+ /**
125
+ * Glob patterns to scan for .vue files during pre-compilation
126
+ * @default ['**\/*.vue']
127
+ */
128
+ scanPatterns?: string[];
129
+ /**
130
+ * Glob patterns to ignore during pre-compilation
131
+ * @default ['node_modules/**', 'dist/**', '.git/**']
132
+ */
133
+ ignorePatterns?: string[];
134
+ }
135
+ /**
136
+ * Linter configuration
137
+ */
138
+ interface LinterConfig {
139
+ /**
140
+ * Enable linting
141
+ */
142
+ enabled?: boolean;
143
+ /**
144
+ * Rules to enable/disable
145
+ */
146
+ rules?: Record<string, RuleSeverity>;
147
+ /**
148
+ * Category-level severity overrides
149
+ */
150
+ categories?: Partial<Record<RuleCategory, RuleSeverity>>;
151
+ }
152
+ /**
153
+ * Type checker configuration
154
+ */
155
+ interface TypeCheckerConfig {
156
+ /**
157
+ * Enable type checking
158
+ * @default false
159
+ */
160
+ enabled?: boolean;
161
+ /**
162
+ * Enable strict mode
163
+ * @default false
164
+ */
165
+ strict?: boolean;
166
+ /**
167
+ * Check component props
168
+ * @default true
169
+ */
170
+ checkProps?: boolean;
171
+ /**
172
+ * Check component emits
173
+ * @default true
174
+ */
175
+ checkEmits?: boolean;
176
+ /**
177
+ * Check template bindings
178
+ * @default true
179
+ */
180
+ checkTemplateBindings?: boolean;
181
+ /**
182
+ * Path to tsconfig.json
183
+ * @default auto-detected
184
+ */
185
+ tsconfig?: string;
186
+ /**
187
+ * Path to tsgo binary
188
+ */
189
+ tsgoPath?: string;
190
+ }
191
+ /**
192
+ * Formatter configuration
193
+ */
194
+ interface FormatterConfig {
195
+ /**
196
+ * Max line width
197
+ * @default 80
198
+ */
199
+ printWidth?: number;
200
+ /**
201
+ * Indentation width
202
+ * @default 2
203
+ */
204
+ tabWidth?: number;
205
+ /**
206
+ * Use tabs for indentation
207
+ * @default false
208
+ */
209
+ useTabs?: boolean;
210
+ /**
211
+ * Print semicolons
212
+ * @default true
213
+ */
214
+ semi?: boolean;
215
+ /**
216
+ * Use single quotes
217
+ * @default false
218
+ */
219
+ singleQuote?: boolean;
220
+ /**
221
+ * Trailing commas
222
+ * @default 'all'
223
+ */
224
+ trailingComma?: "all" | "none" | "es5";
225
+ }
226
+ /**
227
+ * LSP configuration
228
+ */
229
+ interface LspConfig {
230
+ /**
231
+ * Enable LSP
232
+ * @default true
233
+ */
234
+ enabled?: boolean;
235
+ /**
236
+ * Enable diagnostics
237
+ * @default true
238
+ */
239
+ diagnostics?: boolean;
240
+ /**
241
+ * Enable completions
242
+ * @default true
243
+ */
244
+ completion?: boolean;
245
+ /**
246
+ * Enable hover information
247
+ * @default true
248
+ */
249
+ hover?: boolean;
250
+ /**
251
+ * Enable go-to-definition
252
+ * @default true
253
+ */
254
+ definition?: boolean;
255
+ /**
256
+ * Enable formatting via LSP
257
+ * @default true
258
+ */
259
+ formatting?: boolean;
260
+ /**
261
+ * Enable code actions
262
+ * @default true
263
+ */
264
+ codeActions?: boolean;
265
+ /**
266
+ * Use tsgo for type checking in LSP
267
+ * @default false
268
+ */
269
+ tsgo?: boolean;
270
+ }
271
+ /**
272
+ * VRT (Visual Regression Testing) configuration for Musea
273
+ */
274
+ interface MuseaVrtConfig {
275
+ /**
276
+ * Threshold for pixel comparison (0-1)
277
+ * @default 0.1
278
+ */
279
+ threshold?: number;
280
+ /**
281
+ * Output directory for screenshots
282
+ * @default '__musea_snapshots__'
283
+ */
284
+ outDir?: string;
285
+ /**
286
+ * Viewport sizes
287
+ */
288
+ viewports?: Array<{
289
+ width: number;
290
+ height: number;
291
+ name?: string;
292
+ }>;
293
+ }
294
+ /**
295
+ * A11y configuration for Musea
296
+ */
297
+ interface MuseaA11yConfig {
298
+ /**
299
+ * Enable a11y checking
300
+ * @default false
301
+ */
302
+ enabled?: boolean;
303
+ /**
304
+ * Axe-core rules to enable/disable
305
+ */
306
+ rules?: Record<string, boolean>;
307
+ }
308
+ /**
309
+ * Autogen configuration for Musea
310
+ */
311
+ interface MuseaAutogenConfig {
312
+ /**
313
+ * Enable auto-generation of variants
314
+ * @default false
315
+ */
316
+ enabled?: boolean;
317
+ /**
318
+ * Max variants to generate per component
319
+ * @default 10
320
+ */
321
+ maxVariants?: number;
322
+ }
323
+ /**
324
+ * Musea component gallery configuration
325
+ */
326
+ interface MuseaConfig {
327
+ /**
328
+ * Glob patterns for art files
329
+ * @default ['**\/*.art.vue']
330
+ */
331
+ include?: string[];
332
+ /**
333
+ * Glob patterns to exclude
334
+ * @default ['node_modules/**', 'dist/**']
335
+ */
336
+ exclude?: string[];
337
+ /**
338
+ * Base path for gallery
339
+ * @default '/__musea__'
340
+ */
341
+ basePath?: string;
342
+ /**
343
+ * Enable Storybook compatibility
344
+ * @default false
345
+ */
346
+ storybookCompat?: boolean;
347
+ /**
348
+ * Enable inline art detection in .vue files
349
+ * @default false
350
+ */
351
+ inlineArt?: boolean;
352
+ /**
353
+ * VRT configuration
354
+ */
355
+ vrt?: MuseaVrtConfig;
356
+ /**
357
+ * A11y configuration
358
+ */
359
+ a11y?: MuseaA11yConfig;
360
+ /**
361
+ * Autogen configuration
362
+ */
363
+ autogen?: MuseaAutogenConfig;
364
+ }
365
+ /**
366
+ * Global type declaration
367
+ */
368
+ interface GlobalTypeDeclaration {
369
+ /**
370
+ * TypeScript type string
371
+ */
372
+ type: string;
373
+ /**
374
+ * Default value
375
+ */
376
+ defaultValue?: string;
377
+ }
378
+ /**
379
+ * Global types configuration
380
+ */
381
+ type GlobalTypesConfig = Record<string, GlobalTypeDeclaration | string>;
382
+ /**
383
+ * Options for loading vize.config file
384
+ */
385
+ interface LoadConfigOptions {
386
+ /**
387
+ * Config file search mode
388
+ * - 'root': Search only in the specified root directory
389
+ * - 'auto': Search from cwd upward until finding a config file
390
+ * - 'none': Don't load config file
391
+ * @default 'root'
392
+ */
393
+ mode?: "root" | "auto" | "none";
394
+ /**
395
+ * Custom config file path (overrides automatic search)
396
+ */
397
+ configFile?: string;
398
+ /**
399
+ * Config environment for dynamic config resolution
400
+ */
401
+ env?: ConfigEnv;
402
+ } //#endregion
3
403
  //#region src/types.d.ts
4
-
5
404
  interface VizeOptions {
6
405
  /**
7
406
  * Files to include in compilation
@@ -75,96 +474,25 @@ interface CompiledModule {
75
474
  styleHash?: string;
76
475
  scriptHash?: string;
77
476
  }
78
- /**
79
- * Vize configuration options
80
- */
81
- interface VizeConfig {
82
- /**
83
- * Vue compiler options
84
- */
85
- compiler?: {
86
- /**
87
- * Enable Vapor mode compilation
88
- * @default false
89
- */
90
- vapor?: boolean;
91
- /**
92
- * Enable SSR mode
93
- * @default false
94
- */
95
- ssr?: boolean;
96
- /**
97
- * Enable source map generation
98
- * @default true in development, false in production
99
- */
100
- sourceMap?: boolean;
101
- };
102
- /**
103
- * Vite plugin options
104
- */
105
- vite?: {
106
- /**
107
- * Files to include in compilation
108
- * @default /\.vue$/
109
- */
110
- include?: string | RegExp | (string | RegExp)[];
111
- /**
112
- * Files to exclude from compilation
113
- * @default /node_modules/
114
- */
115
- exclude?: string | RegExp | (string | RegExp)[];
116
- /**
117
- * Glob patterns to scan for .vue files during pre-compilation
118
- * @default ['**\/*.vue']
119
- */
120
- scanPatterns?: string[];
121
- /**
122
- * Glob patterns to ignore during pre-compilation
123
- * @default ['node_modules/**', 'dist/**', '.git/**']
124
- */
125
- ignorePatterns?: string[];
126
- };
127
- /**
128
- * Linter options
129
- */
130
- linter?: {
131
- /**
132
- * Enable linting
133
- */
134
- enabled?: boolean;
135
- /**
136
- * Rules to enable/disable
137
- */
138
- rules?: Record<string, "off" | "warn" | "error">;
139
- };
140
- }
141
- /**
142
- * Options for loading vize.config file
143
- */
144
- interface LoadConfigOptions {
145
- /**
146
- * Config file search mode
147
- * - 'root': Search only in the specified root directory
148
- * - 'auto': Search from cwd upward until finding a config file
149
- * - 'none': Don't load config file
150
- * @default 'root'
151
- */
152
- mode?: "root" | "auto" | "none";
153
- /**
154
- * Custom config file path (overrides automatic search)
155
- */
156
- configFile?: string;
157
- } //#endregion
477
+
478
+ //#endregion
158
479
  //#region src/index.d.ts
159
480
  /**
160
- * Define a Vize configuration with type checking
481
+ * Define a Vize configuration with type checking.
482
+ * Accepts a plain object or a function that receives ConfigEnv.
161
483
  */
162
- declare function defineConfig(config: VizeConfig): VizeConfig;
484
+ declare function defineConfig(config: UserConfigExport): UserConfigExport;
163
485
  /**
164
486
  * Load Vize configuration from file
165
487
  */
166
488
  declare function loadConfig(root: string, options?: LoadConfigOptions): Promise<VizeConfig | null>;
489
+ /**
490
+ * Shared config store for inter-plugin communication.
491
+ * Key = project root, Value = resolved VizeConfig.
492
+ * Used by musea() and other plugins to access the unified config.
493
+ */
494
+ declare const vizeConfigStore: Map<string, VizeConfig>;
167
495
  declare function vize(options?: VizeOptions): Plugin;
168
496
 
169
497
  //#endregion
170
- export { CompiledModule, LoadConfigOptions, VizeConfig, VizeOptions, vize as default, defineConfig, loadConfig, vize };
498
+ export { CompiledModule, LoadConfigOptions, VizeConfig, VizeOptions, vize as default, defineConfig, loadConfig, vize, vizeConfigStore };
package/dist/index.js CHANGED
@@ -179,11 +179,15 @@ const CONFIG_FILES = [
179
179
  "vize.config.ts",
180
180
  "vize.config.js",
181
181
  "vize.config.mjs",
182
- "vize.config.cjs",
183
182
  "vize.config.json"
184
183
  ];
184
+ const DEFAULT_CONFIG_ENV = {
185
+ mode: "development",
186
+ command: "serve"
187
+ };
185
188
  /**
186
- * Define a Vize configuration with type checking
189
+ * Define a Vize configuration with type checking.
190
+ * Accepts a plain object or a function that receives ConfigEnv.
187
191
  */
188
192
  function defineConfig(config) {
189
193
  return config;
@@ -192,27 +196,38 @@ function defineConfig(config) {
192
196
  * Load Vize configuration from file
193
197
  */
194
198
  async function loadConfig(root, options = {}) {
195
- const { mode = "root", configFile } = options;
199
+ const { mode = "root", configFile, env } = options;
196
200
  if (mode === "none") return null;
197
- const searchMode = mode === "auto" ? "nearest" : mode;
198
201
  if (configFile) {
199
202
  const configPath = path.isAbsolute(configFile) ? configFile : path.resolve(root, configFile);
200
- return loadConfigFile(configPath);
203
+ return loadConfigFile(configPath, env);
201
204
  }
202
- let searchDir = root;
203
- while (true) {
204
- for (const filename of CONFIG_FILES) {
205
- const configPath = path.join(searchDir, filename);
206
- if (fs.existsSync(configPath)) return loadConfigFile(configPath);
205
+ if (mode === "auto") {
206
+ let searchDir = root;
207
+ while (true) {
208
+ const found$1 = findConfigInDir(searchDir);
209
+ if (found$1) return loadConfigFile(found$1, env);
210
+ const parentDir = path.dirname(searchDir);
211
+ if (parentDir === searchDir) break;
212
+ searchDir = parentDir;
207
213
  }
208
- if (searchMode === "root") break;
209
- const parentDir = path.dirname(searchDir);
210
- if (parentDir === searchDir) break;
211
- searchDir = parentDir;
214
+ return null;
215
+ }
216
+ const found = findConfigInDir(root);
217
+ return found ? loadConfigFile(found, env) : null;
218
+ }
219
+ function findConfigInDir(dir) {
220
+ for (const filename of CONFIG_FILES) {
221
+ const configPath = path.join(dir, filename);
222
+ if (fs.existsSync(configPath)) return configPath;
212
223
  }
213
224
  return null;
214
225
  }
215
- async function loadConfigFile(configPath) {
226
+ async function resolveConfigExport(exported, env) {
227
+ if (typeof exported === "function") return exported(env ?? DEFAULT_CONFIG_ENV);
228
+ return exported;
229
+ }
230
+ async function loadConfigFile(configPath, env) {
216
231
  if (!fs.existsSync(configPath)) return null;
217
232
  const ext = path.extname(configPath);
218
233
  if (ext === ".json") {
@@ -221,12 +236,19 @@ async function loadConfigFile(configPath) {
221
236
  }
222
237
  try {
223
238
  const module = await import(configPath);
224
- return module.default ?? module;
239
+ const exported = module.default ?? module;
240
+ return resolveConfigExport(exported, env);
225
241
  } catch (e) {
226
242
  console.warn(`[vize] Failed to load config from ${configPath}:`, e);
227
243
  return null;
228
244
  }
229
245
  }
246
+ /**
247
+ * Shared config store for inter-plugin communication.
248
+ * Key = project root, Value = resolved VizeConfig.
249
+ * Used by musea() and other plugins to access the unified config.
250
+ */
251
+ const vizeConfigStore = new Map();
230
252
  const VIRTUAL_PREFIX = "\0vize:";
231
253
  const VIRTUAL_CSS_MODULE = "virtual:vize-styles";
232
254
  const RESOLVED_CSS_MODULE = "\0vize:all-styles.css";
@@ -312,13 +334,22 @@ function vize(options = {}) {
312
334
  root = options.root ?? resolvedConfig.root;
313
335
  isProduction = options.isProduction ?? resolvedConfig.isProduction;
314
336
  extractCss = isProduction;
337
+ const configEnv = {
338
+ mode: resolvedConfig.mode,
339
+ command: resolvedConfig.command === "build" ? "build" : "serve",
340
+ isSsrBuild: !!resolvedConfig.build?.ssr
341
+ };
315
342
  let fileConfig = null;
316
343
  if (options.configMode !== false) {
317
344
  fileConfig = await loadConfig(root, {
318
345
  mode: options.configMode ?? "root",
319
- configFile: options.configFile
346
+ configFile: options.configFile,
347
+ env: configEnv
320
348
  });
321
- if (fileConfig) logger.log("Loaded config from vize.config file");
349
+ if (fileConfig) {
350
+ logger.log("Loaded config from vize.config file");
351
+ vizeConfigStore.set(root, fileConfig);
352
+ }
322
353
  }
323
354
  const viteConfig = fileConfig?.vite ?? {};
324
355
  const compilerConfig = fileConfig?.compiler ?? {};
@@ -492,4 +523,4 @@ function vize(options = {}) {
492
523
  var src_default = vize;
493
524
 
494
525
  //#endregion
495
- export { src_default as default, defineConfig, loadConfig, vize };
526
+ export { src_default as default, defineConfig, loadConfig, vize, vizeConfigStore };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/vite-plugin",
3
- "version": "0.0.1-alpha.76",
3
+ "version": "0.0.1-alpha.77",
4
4
  "description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
5
5
  "publishConfig": {
6
6
  "provenance": true,
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "tinyglobby": "^0.2.0",
47
- "@vizejs/native": "0.0.1-alpha.76"
47
+ "@vizejs/native": "0.0.1-alpha.77"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "tsdown",