@vixt/core 0.5.17 → 0.6.1

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,18 +1,31 @@
1
+ //#region src/client/app.d.ts
1
2
  interface VixtApp {
2
- appConfig: VixtAppConfig;
3
+ app: any;
4
+ appConfig: VixtAppConfig;
5
+ [key: string]: unknown;
6
+ }
7
+ interface CreateOptions {
8
+ app: any;
9
+ appConfig: VixtAppConfig;
3
10
  }
4
11
  interface VixtAppConfig extends Record<string, any> {
12
+ readonly baseURL?: string;
13
+ readonly rootId?: string;
5
14
  }
6
15
  declare function defineAppConfig(config: VixtAppConfig): VixtAppConfig;
7
-
16
+ declare function useAppConfig(): VixtAppConfig;
17
+ declare function useVixtApp(): VixtApp;
18
+ declare function createVixtApp(options: CreateOptions): VixtApp;
19
+ //#endregion
20
+ //#region src/client/plugin.d.ts
8
21
  interface PluginDefinition {
9
- name?: string;
10
- setup?: (this: void, vixt: VixtApp) => any;
22
+ name?: string;
23
+ setup?: (this: void, vixt: VixtApp) => any;
11
24
  }
12
25
  interface VixtPlugin {
13
- (this: void, vixt: VixtApp): any;
26
+ (this: void, vixt: VixtApp): any;
14
27
  }
15
28
  declare function defineVixtPlugin(definition: PluginDefinition | VixtPlugin): VixtPlugin;
16
-
17
- export { defineAppConfig, defineVixtPlugin };
18
- export type { PluginDefinition, VixtApp, VixtAppConfig, VixtPlugin };
29
+ declare function applyPlugins(vixt: VixtApp, plugins: VixtPlugin[]): Promise<void>;
30
+ //#endregion
31
+ export { CreateOptions, PluginDefinition, VixtApp, VixtAppConfig, VixtPlugin, applyPlugins, createVixtApp, defineAppConfig, defineVixtPlugin, useAppConfig, useVixtApp };
@@ -0,0 +1,28 @@
1
+ //#region src/client/app.ts
2
+ function defineAppConfig(config) {
3
+ return config;
4
+ }
5
+ function useAppConfig() {
6
+ return useVixtApp()?.appConfig ?? {};
7
+ }
8
+ function useVixtApp() {
9
+ return globalThis.useVixtApp?.();
10
+ }
11
+ function createVixtApp(options) {
12
+ const vixtApp = { ...options };
13
+ globalThis.useVixtApp = () => vixtApp;
14
+ return vixtApp;
15
+ }
16
+
17
+ //#endregion
18
+ //#region src/client/plugin.ts
19
+ function defineVixtPlugin(definition) {
20
+ if (typeof definition == "function") return defineVixtPlugin({ setup: definition });
21
+ return (vixt) => definition.setup?.(vixt);
22
+ }
23
+ async function applyPlugins(vixt, plugins) {
24
+ for (const plugin of plugins) typeof plugin === "function" && await plugin(vixt);
25
+ }
26
+
27
+ //#endregion
28
+ export { applyPlugins, createVixtApp, defineAppConfig, defineVixtPlugin, useAppConfig, useVixtApp };
@@ -1,135 +1,274 @@
1
- import * as c12 from 'c12';
2
- import { LoadConfigOptions, ConfigLayer, ConfigLayerMeta } from 'c12';
3
- import * as vite from 'vite';
4
- import { PluginOption, ResolvedConfig } from 'vite';
5
- import { RawVueCompilerOptions } from '@vue/language-core';
6
- import { TSConfig } from 'pkg-types';
7
- import Checker from 'vite-plugin-checker';
8
-
9
- type Property = Record<string, string>;
10
- interface AppHead {
11
- meta?: Property[];
12
- link?: Property[];
13
- style?: Property[];
14
- script?: Property[];
15
- title?: Property[];
16
- noscript?: Property[];
17
- }
18
- interface AppOptions {
19
- head?: AppHead;
20
- /**
21
- * @default /
22
- */
23
- baseURL?: string;
24
- /**
25
- * @default 'app'
26
- */
27
- rootId?: string;
28
- /**
29
- * @default 'div'
30
- */
31
- rootTag?: string;
32
- /** inject css files */
33
- css?: string[];
34
- /**
35
- * @default './loading.html'
36
- */
37
- loadingTemplate?: string;
38
- /**
39
- * @default '/src/main.ts'(vue)
40
- * @default '/src/main.tsx'(react)
41
- * @example 'entry.ts'(means '/src/entry.ts') or './entry.ts'
42
- */
43
- entryFile?: string;
44
- }
1
+ import * as c120 from "c12";
2
+ import { ConfigLayer, ConfigLayerMeta, LoadConfigOptions } from "c12";
3
+ import * as vite0 from "vite";
4
+ import { HtmlTagDescriptor, InlineConfig, LogLevel, PluginOption, ServerOptions, UserConfig } from "vite";
5
+ import Legacy from "@vitejs/plugin-legacy";
6
+ import Analyzer from "vite-bundle-analyzer";
7
+ import Ssl from "@vitejs/plugin-basic-ssl";
8
+ import Checker from "vite-plugin-checker";
9
+ import { RawVueCompilerOptions } from "@vue/language-core";
10
+ import { TSConfig } from "pkg-types";
45
11
 
12
+ //#region src/node/vixt.d.ts
46
13
  interface Vixt {
47
- options: VixtOptions;
48
- _layers: VixtConfigLayer[];
49
- _modules: VixtModule[];
14
+ options: VixtOptions;
15
+ _layers: VixtConfigLayer[];
16
+ _modules: VixtModule[];
50
17
  }
51
18
  declare function loadVixt(opts?: LoadConfigOptions<VixtOptions>): Promise<Vixt>;
52
- declare function createVixtPlugin(loadOptions: LoadConfigOptions<VixtOptions>): (options?: VixtOptions | undefined) => vite.PluginOption;
53
-
54
- type PluginOptions<Options = any> = (Options extends (...args: any[]) => any ? Parameters<Options>[0] : Options);
19
+ declare function createVixtPlugin(loadOptions: LoadConfigOptions<VixtOptions>): (options?: VixtOptions | undefined) => vite0.PluginOption;
20
+ //#endregion
21
+ //#region src/node/module.d.ts
22
+ type ExtractPluginOptions<Options = any> = (Options extends ((...args: any[]) => any) ? Parameters<Options>[0] : Options);
55
23
  type ModuleOptions = Record<string, any>;
56
24
  interface ModuleMeta extends Record<string, any> {
57
- name?: string;
58
- configKey?: string;
25
+ name?: string;
26
+ configKey?: string;
59
27
  }
60
28
  interface ModuleDefinition<T extends ModuleOptions = ModuleOptions> {
61
- meta?: ModuleMeta;
62
- defaults?: T | ((vixt: Vixt) => T);
63
- setup?: (this: void, resolvedOptions: T, vixt: Vixt) => PluginOption | void;
29
+ meta?: ModuleMeta;
30
+ defaults?: Partial<T> | ((vixt: Vixt) => Partial<T>);
31
+ setup?: (this: void, resolvedOptions: T, vixt: Vixt) => PluginOption | void;
64
32
  }
65
33
  interface VixtModule<T extends ModuleOptions = ModuleOptions> {
66
- (this: void, inlineOptions: T, vixt: Vixt): PluginOption;
67
- getOptions?: (inlineOptions?: T, Vixt?: Vixt) => T;
68
- getMeta?: () => ModuleMeta;
34
+ (this: void, resolvedOptions: T, vixt: Vixt): PluginOption;
35
+ getOptions?: (inlineOptions: Partial<T>, Vixt: Vixt) => T;
36
+ getMeta?: () => ModuleMeta;
69
37
  }
70
38
  declare function defineVitePlugin<Options = any>(pluginFn: (options?: Options) => PluginOption): (options?: Options) => PluginOption;
71
39
  declare function defineVixtModule<T extends ModuleOptions>(definition: ModuleDefinition<T> | VixtModule<T>): VixtModule<T>;
72
- declare function installModule(module: VixtModule, inlineOptions: any, vixt: Vixt): PluginOption;
40
+ declare function installModule<T extends ModuleOptions = ModuleOptions>(module: VixtModule<T>, inlineOptions: any, vixt: Vixt): PluginOption;
73
41
  declare function applyLayerModules(layers: VixtConfigLayer[]): Promise<VixtModule[]>;
74
-
75
- interface VixtOptions extends Record<string, any> {
76
- /**
77
- * @default process.cwd()
78
- */
79
- rootDir?: string;
80
- /**
81
- * @default '<rootDir>/.vixt'
82
- */
83
- buildDir?: string;
84
- /**
85
- * @default '<buildDir>/types'
86
- */
87
- buildTypesDir?: string;
88
- /**
89
- * @default '<buildDir>/layers'
90
- */
91
- buildLayersDir?: string;
92
- /**
93
- * @default '<buildDir>/imports'
94
- */
95
- buildImportsDir?: string;
96
- /**
97
- * @default '<rootDir>/src'
98
- */
99
- srcDir?: string;
100
- /** modules */
101
- modules?: VixtModule[];
102
- /** use on configResolved */
103
- vite?: ResolvedConfig;
104
- meta?: VixtConfigLayerMeta;
105
- /** layers */
106
- extends?: string[];
107
- app?: AppOptions;
42
+ //#endregion
43
+ //#region src/node/config.d.ts
44
+ interface VixtOptions {
45
+ /**
46
+ * Vixt App configuration.
47
+ */
48
+ app?: AppOptions;
49
+ /**
50
+ * Shared build configuration.
51
+ */
52
+ build?: BuildOptions;
53
+ /**
54
+ * Define the root directory of your application.
55
+ * @default process.cwd()
56
+ */
57
+ rootDir?: string;
58
+ /**
59
+ * Define the monorepo workspace directory of your application.
60
+ */
61
+ workspaceDir?: string;
62
+ /**
63
+ * Define the source directory of your application.
64
+ * @default '<rootDir>/src'
65
+ */
66
+ srcDir?: string;
67
+ /**
68
+ * Define the server directory of your application.
69
+ * @default '<rootDir>/server'
70
+ */
71
+ serverDir?: string;
72
+ /**
73
+ * Define the directory where your built files will be placed.
74
+ * @default '<rootDir>/.vixt'
75
+ */
76
+ buildDir?: string;
77
+ /**
78
+ * @default '<buildDir>/types'
79
+ */
80
+ buildTypesDir?: string;
81
+ /**
82
+ * @default '<buildDir>/layers'
83
+ */
84
+ buildLayersDir?: string;
85
+ /**
86
+ * @default '<buildDir>/imports'
87
+ */
88
+ buildImportsDir?: string;
89
+ /**
90
+ * Define the directory of your Vixt modules.
91
+ * @default '<srcDir>/modules'
92
+ */
93
+ modulesDir?: string;
94
+ /**
95
+ * Define the directory of your Vixt plugins.
96
+ * @default '<srcDir>/plugins'
97
+ */
98
+ pluginsDir?: string;
99
+ /**
100
+ * Whether your app is running in development mode.
101
+ * @default false
102
+ */
103
+ dev?: boolean;
104
+ /**
105
+ * Whether your app is being unit tested.
106
+ * @default false
107
+ */
108
+ test?: boolean;
109
+ /**
110
+ * Set to `true` to enable debug mode.
111
+ * @default false
112
+ */
113
+ debug?: boolean;
114
+ /**
115
+ * Whether to enable rendering of HTML.
116
+ * @default false
117
+ */
118
+ ssr?: boolean;
119
+ /**
120
+ * You can improve your DX by defining additional aliases to access custom directories within your JavaScript and CSS.
121
+ */
122
+ alias?: AliasOptions;
123
+ /**
124
+ * Configuration that will be passed directly to Vite.
125
+ */
126
+ appConfig?: Record<string, any>;
127
+ devServer?: DevServerOptions;
128
+ /** Vite config input */
129
+ vite?: Omit<UserConfig, 'plugins'>;
130
+ /** layer meta */
131
+ meta?: VixtConfigLayerMeta;
132
+ /** layers */
133
+ extends?: string[];
134
+ /** modules */
135
+ modules?: VixtModule[];
136
+ /** plugins */
137
+ plugins?: string[];
138
+ /** typescript */
139
+ typescript?: TypescriptOptions;
140
+ /** custom options */
141
+ [key: string]: any;
142
+ }
143
+ interface AppHeadAttrs {
144
+ children?: string;
145
+ injectTo?: HtmlTagDescriptor['injectTo'];
146
+ [key: string]: string | boolean | undefined;
147
+ }
148
+ interface AppHead {
149
+ title?: AppHeadAttrs[];
150
+ link?: AppHeadAttrs[];
151
+ meta?: AppHeadAttrs[];
152
+ style?: AppHeadAttrs[];
153
+ script?: AppHeadAttrs[];
154
+ noscript?: AppHeadAttrs[];
155
+ }
156
+ interface AppOptions {
157
+ /**
158
+ * The base path of your Nuxt application.
159
+ * @default '/'
160
+ */
161
+ baseURL?: string;
162
+ /**
163
+ * You can define the CSS files/modules/libraries you want to set globally.
164
+ */
165
+ css?: string[];
166
+ /**
167
+ * The entry file relative to <srcDir>
168
+ * @default 'main.ts'(vue)
169
+ * @default 'main.tsx'(react)
170
+ * @example 'entry.ts'(means '/<srcDir>/entry.ts')
171
+ */
172
+ entryFile?: string;
173
+ entryCode?: string;
174
+ /**
175
+ * Set default configuration for `<head>`.
176
+ */
177
+ head?: AppHead;
178
+ /**
179
+ * The path to an HTML file with the contents of which will be inserted into index.html.
180
+ * Some good sources for spinners are [SpinKit](https://github.com/tobiasahlin/SpinKit) or [SVG Spinners](https://icones.js.org/collection/svg-spinners).
181
+ */
182
+ loadingTemplate?: string;
183
+ /**
184
+ * Customize Vixt root element id.
185
+ * @default 'app'
186
+ */
187
+ rootId?: string;
188
+ /**
189
+ * Customize Vixt root element tag.
190
+ * @default 'div'
191
+ */
192
+ rootTag?: string;
193
+ }
194
+ interface AliasOptions {
195
+ [find: string]: string;
196
+ }
197
+ interface DevServerOptions extends Pick<ServerOptions, 'port' | 'host' | 'cors'> {
198
+ /** https://github.com/vitejs/vite-plugin-basic-ssl */
199
+ https?: boolean | ExtractPluginOptions<typeof Ssl> & {
200
+ enabled?: boolean;
201
+ };
202
+ /**
203
+ * The watch property lets you define patterns that will restart the dev server when changed.
204
+ */
205
+ watch?: string[];
206
+ }
207
+ interface BuildOptions {
208
+ /** https://github.com/nonzzz/vite-bundle-analyzer */
209
+ analyze?: boolean | ExtractPluginOptions<typeof Analyzer> & {
210
+ enabled?: boolean;
211
+ };
212
+ /** https://github.com/vitejs/vite/tree/main/packages/plugin-legacy */
213
+ legacy?: boolean | ExtractPluginOptions<typeof Legacy> & {
214
+ enabled?: boolean;
215
+ };
216
+ }
217
+ interface TypescriptOptions {
218
+ references?: (string | {
219
+ path?: string;
220
+ content?: string;
221
+ })[];
222
+ tsConfig?: TSConfig & {
223
+ vueCompilerOptions?: RawVueCompilerOptions;
224
+ };
225
+ /** https://github.com/fi3ework/vite-plugin-checker */
226
+ typeCheck?: ExtractPluginOptions<typeof Checker>;
227
+ /**
228
+ * Generate a `*.vue` shim
229
+ * @default false
230
+ */
231
+ shim?: boolean;
108
232
  }
109
233
  interface VixtConfigLayerMeta extends ConfigLayerMeta {
110
- /** layer name */
111
- name?: string;
112
- /** layer alias */
113
- alias?: string;
234
+ /** layer name */
235
+ name?: string;
236
+ /** layer alias */
237
+ alias?: string;
114
238
  }
115
239
  interface VixtConfigLayer extends ConfigLayer<VixtOptions, VixtConfigLayerMeta> {
116
- /** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, and change cwd */
117
- cwd?: string;
240
+ /** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, and change cwd */
241
+ cwd?: string;
118
242
  }
119
243
  declare function defineVixtConfig(input: VixtOptions): VixtOptions;
120
- declare function loadVixtConfig(opts?: LoadConfigOptions<VixtOptions>): Promise<c12.ResolvedConfig<VixtOptions, ConfigLayerMeta>>;
121
- declare function applyLayers(layers: VixtConfigLayer[], config: VixtOptions): {
122
- meta: VixtConfigLayerMeta;
123
- /** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, and change cwd */
124
- cwd?: string;
125
- config: VixtOptions | null;
126
- source?: string;
127
- sourceOptions?: c12.SourceOptions<VixtOptions, VixtConfigLayerMeta> | undefined;
128
- configFile?: string;
129
- }[];
244
+ declare function loadVixtConfig(opts?: LoadConfigOptions<VixtOptions>): Promise<c120.ResolvedConfig<VixtOptions, ConfigLayerMeta>>;
245
+ declare function applyLayers(layers: VixtConfigLayer[], config: VixtOptions): VixtConfigLayer[];
130
246
  declare function isSamePath(a: string, b: string): boolean;
131
247
  declare function resolveLayersDirs(layers?: VixtConfigLayer[]): Record<string, string[] | undefined>;
132
-
248
+ declare const VixtClientAutoImports: Record<string, string[]>;
249
+ //#endregion
250
+ //#region src/node/env.d.ts
251
+ /** https://github.com/vitejs/vite/blob/v8.0.0-beta.3/packages/vite/src/node/cli.ts */
252
+ interface GlobalCLIOptions {
253
+ '--'?: string[];
254
+ 'c'?: boolean | string;
255
+ 'config'?: string;
256
+ 'base'?: string;
257
+ 'l'?: LogLevel;
258
+ 'logLevel'?: LogLevel;
259
+ 'clearScreen'?: boolean;
260
+ 'configLoader'?: InlineConfig['configLoader'];
261
+ 'd'?: boolean | string;
262
+ 'debug'?: boolean | string;
263
+ 'f'?: string;
264
+ 'filter'?: string;
265
+ 'm'?: string;
266
+ 'mode'?: string;
267
+ 'force'?: boolean;
268
+ 'w'?: boolean;
269
+ }
270
+ declare function loadCLIOptions(): GlobalCLIOptions;
271
+ declare function loadMode(): string | undefined;
133
272
  /**
134
273
  * Load workspace and cwd env variables by default
135
274
  */
@@ -142,41 +281,13 @@ declare function findUpWorkspaceDir(): string | undefined;
142
281
  * Load workspace env variables
143
282
  */
144
283
  declare function loadWorkspaceEnv(mode?: string, prefixes?: string | string[]): Record<string, string>;
145
-
146
- declare const config: VixtModule<ModuleOptions>;
147
-
148
- declare module '@vixt/core' {
149
- interface VixtOptions {
150
- typescript?: TypescriptOptions;
151
- }
152
- }
153
- interface TypescriptOptions {
154
- references?: (string | {
155
- path?: string;
156
- content?: string;
157
- })[];
158
- tsConfig?: TSConfig & {
159
- vueCompilerOptions?: RawVueCompilerOptions;
160
- };
161
- /** https://github.com/fi3ework/vite-plugin-checker */
162
- typeCheck?: Parameters<typeof Checker>[0];
163
- /**
164
- * Generate a `*.vue` shim
165
- * @default false
166
- */
167
- shim?: boolean;
168
- }
169
- declare const typescript: VixtModule<TypescriptOptions>;
170
-
171
- declare function generateAppConfig(vixt: Vixt): string;
172
-
173
- declare function generateClient(vixt: Vixt): void;
174
-
175
- declare function generateCss(options: AppOptions): string;
176
-
177
- declare function generateIndexHtml(options: AppOptions, vixt: Vixt): string;
178
-
179
- declare function generatePlugins(vixt: Vixt): string;
180
-
181
- export { applyLayerModules, applyLayers, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, findUpWorkspaceDir, generateAppConfig, generateClient, generateCss, generateIndexHtml, generatePlugins, installModule, isSamePath, loadEnv, loadVixt, loadVixtConfig, loadWorkspaceEnv, resolveLayersDirs, typescript };
182
- export type { AppHead, AppOptions, ModuleDefinition, ModuleMeta, ModuleOptions, PluginOptions, TypescriptOptions, Vixt, VixtConfigLayer, VixtConfigLayerMeta, VixtModule, VixtOptions };
284
+ //#endregion
285
+ //#region src/node/modules/index.d.ts
286
+ declare const virtualModuleIds: {
287
+ css: string | undefined;
288
+ appConfig: string | undefined;
289
+ plugins: string | undefined;
290
+ };
291
+ declare const builtinModules: (VixtModule<ModuleOptions> | VixtModule<AliasOptions> | VixtModule<AppOptions> | VixtModule<BuildOptions> | VixtModule<DevServerOptions> | VixtModule<TypescriptOptions>)[];
292
+ //#endregion
293
+ export { AliasOptions, AppHead, AppHeadAttrs, AppOptions, BuildOptions, DevServerOptions, ExtractPluginOptions, GlobalCLIOptions, ModuleDefinition, ModuleMeta, ModuleOptions, TypescriptOptions, Vixt, VixtClientAutoImports, VixtConfigLayer, VixtConfigLayerMeta, VixtModule, VixtOptions, applyLayerModules, applyLayers, builtinModules, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, findUpWorkspaceDir, installModule, isSamePath, loadCLIOptions, loadEnv, loadMode, loadVixt, loadVixtConfig, loadWorkspaceEnv, resolveLayersDirs, virtualModuleIds };