@vixt/core 0.12.2 → 0.13.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.
@@ -1,5 +1,5 @@
1
1
  import { ConfigLayer, ConfigLayerMeta, LoadConfigOptions, ResolvedConfig } from "c12";
2
- import { HtmlTagDescriptor, InlineConfig, LogLevel, PluginOption, ServerOptions, UserConfig } from "vite";
2
+ import { HtmlTagDescriptor, PluginOption, ServerOptions, UserConfig } from "vite";
3
3
  import Legacy from "@vitejs/plugin-legacy";
4
4
  import Analyzer from "vite-bundle-analyzer";
5
5
  import Ssl from "@vitejs/plugin-basic-ssl";
@@ -27,7 +27,7 @@ interface Vixt {
27
27
  _layers: VixtConfigLayer[];
28
28
  _modules: VixtModule[];
29
29
  }
30
- type ExtractPluginOptions<Options = any> = (Options extends ((...args: any[]) => any) ? Parameters<Options>[0] : Options);
30
+ type ExtractPluginOptions<Options = any> = Options extends ((...args: any[]) => any) ? Parameters<Options>[0] : Options;
31
31
  //#endregion
32
32
  //#region src/node/types/module.d.ts
33
33
  type ModuleOptions = Record<string, any>;
@@ -179,24 +179,24 @@ interface BuildOptions {
179
179
  /**
180
180
  * Set to true to enable bundle analysis, or pass an object with `enabled: true` and options: [vite-bundle-analyzer](https://github.com/nonzzz/vite-bundle-analyzer)
181
181
  */
182
- analyze?: boolean | ExtractPluginOptions<typeof Analyzer> & {
182
+ analyze?: boolean | (ExtractPluginOptions<typeof Analyzer> & {
183
183
  enabled?: boolean;
184
- };
184
+ });
185
185
  /**
186
186
  * Set to true to enable legacy mode, or pass an object with `enabled: true` and options: [@vitejs/plugin-legacy](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy)
187
187
  */
188
- legacy?: boolean | ExtractPluginOptions<typeof Legacy> & {
188
+ legacy?: boolean | (ExtractPluginOptions<typeof Legacy> & {
189
189
  enabled?: boolean;
190
- };
190
+ });
191
191
  }
192
192
  interface DevServerOptions extends Pick<ServerOptions, 'port' | 'host' | 'cors'> {
193
193
  /**
194
194
  * Whether to enable HTTPS by using [@vitejs/plugin-basic-ssl](https://github.com/vitejs/vite-plugin-basic-ssl).
195
195
  * @default false
196
196
  */
197
- https?: boolean | ExtractPluginOptions<typeof Ssl> & {
197
+ https?: boolean | (ExtractPluginOptions<typeof Ssl> & {
198
198
  enabled?: boolean;
199
- };
199
+ });
200
200
  /**
201
201
  * The watch property lets you define patterns that will restart the dev server when changed.
202
202
  */
@@ -401,27 +401,124 @@ declare function applyLayers({ config, layers }: ResolvedVixtConfig): VixtConfig
401
401
  declare function isSamePath(a: string, b: string): boolean;
402
402
  declare function resolveLayersDirs(layers?: VixtConfigLayer[]): Record<string, string[] | undefined>;
403
403
  //#endregion
404
+ //#region ../../node_modules/.pnpm/citty@0.2.2/node_modules/citty/dist/index.d.mts
405
+ //#region src/types.d.ts
406
+ type ArgType = "boolean" | "string" | "enum" | "positional" | undefined;
407
+ type _ArgDef<T extends ArgType, VT extends boolean | number | string> = {
408
+ type?: T;
409
+ description?: string;
410
+ valueHint?: string;
411
+ alias?: string | string[];
412
+ default?: VT;
413
+ required?: boolean;
414
+ options?: string[];
415
+ };
416
+ type BooleanArgDef = Omit<_ArgDef<"boolean", boolean>, "options"> & {
417
+ negativeDescription?: string;
418
+ };
419
+ type StringArgDef = Omit<_ArgDef<"string", string>, "options">;
420
+ type EnumArgDef = _ArgDef<"enum", string>;
421
+ type PositionalArgDef = Omit<_ArgDef<"positional", string>, "alias" | "options">;
422
+ type ArgDef = BooleanArgDef | StringArgDef | PositionalArgDef | EnumArgDef;
423
+ type ArgsDef = Record<string, ArgDef>;
424
+ type ResolveParsedArgType<T extends ArgDef, VT> = T extends {
425
+ default?: any;
426
+ required?: boolean;
427
+ } ? T["default"] extends NonNullable<VT> ? VT : T["required"] extends true ? VT : VT | undefined : VT | undefined;
428
+ type ParsedPositionalArg<T extends ArgDef> = T extends {
429
+ type: "positional";
430
+ } ? ResolveParsedArgType<T, string> : never;
431
+ type ParsedStringArg<T extends ArgDef> = T extends {
432
+ type: "string";
433
+ } ? ResolveParsedArgType<T, string> : never;
434
+ type ParsedBooleanArg<T extends ArgDef> = T extends {
435
+ type: "boolean";
436
+ } ? ResolveParsedArgType<T, boolean> : never;
437
+ type ParsedEnumArg<T extends ArgDef> = T extends {
438
+ type: "enum";
439
+ options: infer U;
440
+ } ? U extends Array<any> ? ResolveParsedArgType<T, U[number]> : never : never;
441
+ type RawArgs = {
442
+ _: string[];
443
+ };
444
+ type ParsedArg<T extends ArgDef> = T["type"] extends "positional" ? ParsedPositionalArg<T> : T["type"] extends "boolean" ? ParsedBooleanArg<T> : T["type"] extends "string" ? ParsedStringArg<T> : T["type"] extends "enum" ? ParsedEnumArg<T> : never;
445
+ type ParsedArgs<T extends ArgsDef = ArgsDef> = RawArgs & { [K in keyof T]: ParsedArg<T[K]>; } & { [K in keyof T as T[K] extends {
446
+ alias: string;
447
+ } ? T[K]["alias"] : never]: ParsedArg<T[K]>; } & { [K in keyof T as T[K] extends {
448
+ alias: string[];
449
+ } ? T[K]["alias"][number] : never]: ParsedArg<T[K]>; } & Record<string, string | number | boolean | string[]>;
450
+ //#endregion
404
451
  //#region src/node/env.d.ts
405
- /** https://github.com/vitejs/vite/blob/main/packages/vite/src/node/cli.ts */
406
- interface GlobalCLIOptions {
407
- '--'?: string[];
408
- 'c'?: boolean | string;
409
- 'config'?: string;
410
- 'base'?: string;
411
- 'l'?: LogLevel;
412
- 'logLevel'?: LogLevel;
413
- 'clearScreen'?: boolean;
414
- 'configLoader'?: InlineConfig['configLoader'];
415
- 'd'?: boolean | string;
416
- 'debug'?: boolean | string;
417
- 'f'?: string;
418
- 'filter'?: string;
419
- 'm'?: string;
420
- 'mode'?: string;
421
- 'force'?: boolean;
422
- 'w'?: boolean;
423
- }
424
- declare function loadCLIOptions(): GlobalCLIOptions;
452
+ declare function loadCLIOptions(): ParsedArgs<{
453
+ https: {
454
+ type: "boolean";
455
+ description: string;
456
+ };
457
+ host: {
458
+ type: "string";
459
+ description: string;
460
+ };
461
+ port: {
462
+ type: "string";
463
+ description: string;
464
+ alias: string[];
465
+ };
466
+ open: {
467
+ type: "boolean";
468
+ description: string;
469
+ alias: string[];
470
+ default: false;
471
+ };
472
+ cors: {
473
+ type: "boolean";
474
+ description: string;
475
+ };
476
+ strictPort: {
477
+ type: "boolean";
478
+ description: string;
479
+ };
480
+ root: {
481
+ type: "positional";
482
+ description: string;
483
+ required: false;
484
+ default: undefined;
485
+ };
486
+ debug: {
487
+ type: "boolean";
488
+ description: string;
489
+ alias: string[];
490
+ default: false;
491
+ };
492
+ mode: {
493
+ type: "string";
494
+ description: string;
495
+ alias: string[];
496
+ };
497
+ logLevel: {
498
+ type: "enum";
499
+ description: string;
500
+ options: ("error" | "warn" | "info" | "silent")[];
501
+ alias: string[];
502
+ };
503
+ clear: {
504
+ type: "boolean";
505
+ description: string;
506
+ default: false;
507
+ };
508
+ force: {
509
+ type: "boolean";
510
+ description: string;
511
+ default: false;
512
+ };
513
+ legacy: {
514
+ type: "boolean";
515
+ description: string;
516
+ };
517
+ analyze: {
518
+ type: "boolean";
519
+ description: string;
520
+ };
521
+ }>;
425
522
  declare function loadMode(): string | undefined;
426
523
  /**
427
524
  * Load workspace and cwd env variables by default
@@ -508,4 +605,4 @@ declare const builtinModules: (VixtModule<ModuleOptions> | VixtModule<AliasOptio
508
605
  declare function loadVixt(opts?: LoadConfigOptions<VixtOptions>): Promise<Vixt>;
509
606
  declare function createVixtPlugin(loadOptions: LoadConfigOptions<VixtOptions>): (options?: VixtOptions | undefined) => import("vite").PluginOption;
510
607
  //#endregion
511
- export { AliasOptions, AppHead, AppHeadAttrs, AppOptions, BuildOptions, DevServerOptions, ExtractPluginOptions, GlobalCLIOptions, ImportsOptions, LoadVixtConfigOptions, ModuleDefinition, ModuleMeta, ModuleOptions, NitroOptions, ResolvedVixtConfig, TypescriptOptions, Vixt, VixtConfig, VixtConfigLayer, VixtConfigLayerMeta, VixtModule, VixtOptions, applyLayerModules, applyLayers, builtinModules, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, findUpWorkspaceDir, installModule, isSamePath, loadCLIOptions, loadEnv, loadMode, loadVixt, loadVixtConfig, loadWorkspaceEnv, resolveLayersDirs, virtualModuleIds };
608
+ export { AliasOptions, AppHead, AppHeadAttrs, AppOptions, BuildOptions, DevServerOptions, ExtractPluginOptions, ImportsOptions, LoadVixtConfigOptions, ModuleDefinition, ModuleMeta, ModuleOptions, NitroOptions, ResolvedVixtConfig, TypescriptOptions, Vixt, VixtConfig, VixtConfigLayer, VixtConfigLayerMeta, VixtModule, VixtOptions, applyLayerModules, applyLayers, builtinModules, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, findUpWorkspaceDir, installModule, isSamePath, loadCLIOptions, loadEnv, loadMode, loadVixt, loadVixtConfig, loadWorkspaceEnv, resolveLayersDirs, virtualModuleIds };
@@ -1,8 +1,8 @@
1
+ import { cwd, env } from "node:process";
1
2
  import { loadConfig } from "c12";
2
3
  import fs from "fs-extra";
3
4
  import path, { normalize, resolve } from "pathe";
4
- import { cwd, env } from "node:process";
5
- import { cac } from "cac";
5
+ import { parseVixtArgs } from "@vixt/cli";
6
6
  import { findUpSync } from "find-up";
7
7
  import { loadEnv as loadEnv$1, mergeConfig, parseAst } from "vite";
8
8
  import defu from "defu";
@@ -18,11 +18,11 @@ import Checker from "vite-plugin-checker";
18
18
  import { builders, parseExpression, parseModule } from "magicast";
19
19
  //#region src/node/env.ts
20
20
  function loadCLIOptions() {
21
- return cac().parse().options ?? {};
21
+ return parseVixtArgs();
22
22
  }
23
23
  function loadMode() {
24
- const { mode, m } = loadCLIOptions();
25
- return mode || m || env.NODE_ENV;
24
+ const { mode } = loadCLIOptions();
25
+ return mode || env.NODE_ENV;
26
26
  }
27
27
  /**
28
28
  * Load workspace and cwd env variables by default
@@ -69,10 +69,12 @@ function defineVixtConfig(input) {
69
69
  return input;
70
70
  }
71
71
  async function loadVixtConfig(opts) {
72
+ const cliOptions = loadCLIOptions();
72
73
  const result = await loadConfig({
73
74
  name: "vixt",
74
75
  rcFile: false,
75
- ...opts
76
+ ...opts,
77
+ ...cliOptions.root ? { cwd: cliOptions.root } : {}
76
78
  });
77
79
  const { config, cwd } = result;
78
80
  config.rootDir ??= cwd;
@@ -83,6 +85,10 @@ async function loadVixtConfig(opts) {
83
85
  config.srcDir ??= resolve(config.rootDir, "src");
84
86
  config.modulesDir ??= resolve(config.srcDir, "modules");
85
87
  config.pluginsDir ??= resolve(config.srcDir, "plugins");
88
+ config.debug = !!cliOptions.debug;
89
+ config.dev = env.NODE_ENV !== "production";
90
+ config.test = env.NODE_ENV === "test";
91
+ cliOptions.force && fs.removeSync(config.buildDir);
86
92
  return result;
87
93
  }
88
94
  function applyLayers({ config, layers = [] }) {
@@ -201,7 +207,9 @@ function defineVixtModule(definition) {
201
207
  const module = definition;
202
208
  function getOptions(inlineOptions, vixt) {
203
209
  const configKey = module.meta?.configKey || module.meta?.name;
204
- const resolvedOptions = defu(inlineOptions, configKey ? vixt.options[configKey] : {}, typeof module.defaults === "function" ? module.defaults(vixt) : module.defaults);
210
+ const configOptions = configKey ? vixt.options[configKey] : {};
211
+ const defaultOptions = typeof module.defaults === "function" ? module.defaults(vixt) : module.defaults;
212
+ const resolvedOptions = defu(inlineOptions, configOptions, defaultOptions);
205
213
  if (configKey) vixt.options[configKey] = resolvedOptions;
206
214
  return resolvedOptions;
207
215
  }
@@ -360,13 +368,16 @@ var build_default = defineVixtModule({
360
368
  configKey: "build"
361
369
  },
362
370
  setup(options) {
371
+ const cliOptions = loadCLIOptions();
363
372
  const analyzeOptions = {
364
373
  enabled: !!options.analyze,
365
- ...typeof options.analyze === "object" ? options.analyze : {}
374
+ ...typeof options.analyze === "object" ? options.analyze : {},
375
+ ...cliOptions.analyze ? { enabled: true } : {}
366
376
  };
367
377
  const legacyOptions = {
368
378
  enabled: !!options.legacy,
369
- ...typeof options.legacy === "object" ? options.legacy : {}
379
+ ...typeof options.legacy === "object" ? options.legacy : {},
380
+ ...cliOptions.legacy ? { enabled: true } : {}
370
381
  };
371
382
  return [analyzeOptions.enabled && Analyzer(analyzeOptions), legacyOptions.enabled && Legacy(legacyOptions)];
372
383
  }
@@ -398,9 +409,11 @@ var dev_server_default = defineVixtModule({
398
409
  return { watch: watchFiles };
399
410
  },
400
411
  setup(options) {
412
+ const cliOptions = loadCLIOptions();
401
413
  const sslOptions = {
402
414
  enabled: !!options.https,
403
- ...typeof options.https === "object" ? options.https : {}
415
+ ...typeof options.https === "object" ? options.https : {},
416
+ ...cliOptions.https ? { enabled: true } : {}
404
417
  };
405
418
  const watchFiles = options.watch ?? [];
406
419
  let timer;
@@ -761,13 +774,8 @@ const builtinModules = [
761
774
  ];
762
775
  //#endregion
763
776
  //#region src/node/vixt.ts
764
- async function loadVixt(opts) {
777
+ async function loadVixt(opts = {}) {
765
778
  const result = await loadVixtConfig(opts);
766
- const cliOptions = loadCLIOptions();
767
- cliOptions.force && fs.removeSync(result.config.buildDir);
768
- result.config.debug = !!cliOptions.debug;
769
- result.config.dev = env.NODE_ENV !== "production";
770
- result.config.test = env.NODE_ENV === "test";
771
779
  result.layers = applyLayers(result);
772
780
  const layerModules = await applyLayerModules(result);
773
781
  return {
package/package.json CHANGED
@@ -1,54 +1,53 @@
1
1
  {
2
2
  "name": "@vixt/core",
3
- "type": "module",
4
- "version": "0.12.2",
5
- "author": "SoulLyoko<https://github.com/SoulLyoko>",
6
- "license": "MIT",
3
+ "version": "0.13.0",
4
+ "keywords": [
5
+ "nuxt",
6
+ "react",
7
+ "uni",
8
+ "vite",
9
+ "vitepress",
10
+ "vixt",
11
+ "vue"
12
+ ],
7
13
  "homepage": "https://soullyoko.github.io/vixt/",
14
+ "license": "MIT",
15
+ "author": "SoulLyoko<https://github.com/SoulLyoko>",
8
16
  "repository": {
9
17
  "type": "git",
10
18
  "url": "https://github.com/SoulLyoko/vixt.git"
11
19
  },
12
- "keywords": [
13
- "vixt",
14
- "vite",
15
- "nuxt",
16
- "vue",
17
- "uni",
18
- "vitepress",
19
- "react"
20
+ "files": [
21
+ "dist"
20
22
  ],
23
+ "type": "module",
24
+ "main": "./dist/node/index.mjs",
25
+ "browser": "./dist/client/index.js",
26
+ "types": "./dist/node/index.d.mts",
21
27
  "exports": {
22
28
  ".": "./dist/node/index.mjs",
23
- "./cli": "./dist/cli/index.mjs",
24
29
  "./client": "./dist/client/index.js",
25
30
  "./package.json": "./package.json"
26
31
  },
27
- "main": "./dist/node/index.mjs",
28
- "types": "./dist/node/index.d.mts",
29
- "browser": "./dist/client/index.js",
30
- "files": [
31
- "dist"
32
- ],
33
32
  "dependencies": {
33
+ "@types/fs-extra": "^11.0.4",
34
34
  "@vitejs/plugin-basic-ssl": "^2.3.0",
35
- "@vitejs/plugin-legacy": "^8.2.1",
35
+ "@vitejs/plugin-legacy": "^8.2.3",
36
+ "@vixt/cli": "0.13.0",
36
37
  "@vue/tsconfig": "^0.9.1",
37
38
  "c12": "^3.3.4",
38
- "cac": "^7.0.0",
39
- "citty": "^0.2.2",
40
39
  "defu": "^6.1.7",
41
40
  "find-up": "^8.0.0",
42
- "fs-extra": "^11.3.6",
41
+ "fs-extra": "^11.4.0",
43
42
  "jiti": "^2.7.0",
44
- "magicast": "^0.5.3",
43
+ "magicast": "^0.5.4",
45
44
  "mlly": "^1.8.2",
46
45
  "nitro": "^3.0.260610-beta",
47
46
  "pathe": "^2.0.3",
48
47
  "pkg-types": "^2.3.1",
49
- "unplugin-auto-import": "^21.0.0",
50
- "vite": "^8.1.5",
48
+ "unplugin-auto-import": "^21.1.0",
49
+ "vite": "^8.2.2",
51
50
  "vite-bundle-analyzer": "^1.3.9",
52
- "vite-plugin-checker": "^0.14.4"
51
+ "vite-plugin-checker": "^0.14.5"
53
52
  }
54
53
  }
@@ -1 +0,0 @@
1
- export { };
@@ -1,27 +0,0 @@
1
- import { defineCommand, runMain } from "citty";
2
- //#region src/cli/index.ts
3
- runMain(defineCommand({
4
- meta: {
5
- name: "vixt",
6
- description: "Vixt CLI"
7
- },
8
- args: { command: {
9
- type: "positional",
10
- required: true
11
- } },
12
- subCommands: { prepare: defineCommand({
13
- meta: {
14
- name: "prepare",
15
- description: "Prepare Vixt"
16
- },
17
- async run() {
18
- const { loadConfigFromFile } = await import("vite");
19
- await loadConfigFromFile({
20
- command: "serve",
21
- mode: "dev"
22
- }, void 0, void 0, void 0, void 0, "native");
23
- }
24
- }) }
25
- }));
26
- //#endregion
27
- export {};