@vixt/core 0.3.5 → 0.4.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.
package/package.json CHANGED
@@ -1,33 +1,30 @@
1
1
  {
2
2
  "name": "@vixt/core",
3
3
  "type": "module",
4
- "version": "0.3.5",
4
+ "version": "0.4.0",
5
5
  "author": "SoulLyoko<https://github.com/SoulLyoko>",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/SoulLyoko/vixt#readme",
8
8
  "repository": "https://github.com/SoulLyoko/vixt.git",
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.mjs"
11
+ "types": "./dist/node/index.d.ts",
12
+ "import": "./dist/node/index.mjs"
13
13
  },
14
14
  "./client": {
15
15
  "types": "./dist/client/index.d.ts",
16
16
  "import": "./dist/client/index.mjs"
17
- },
18
- "./client/App.vue": {
19
- "import": "./dist/client/App.vue"
20
17
  }
21
18
  },
22
- "main": "dist/index.mjs",
23
- "types": "dist/index.d.ts",
19
+ "main": "./dist/node/index.mjs",
20
+ "types": "./dist/node/index.d.ts",
24
21
  "files": [
25
22
  "dist"
26
23
  ],
27
24
  "dependencies": {
28
25
  "@types/fs-extra": "^11.0.4",
29
26
  "@vue/tsconfig": "^0.7.0",
30
- "c12": "^3.0.3",
27
+ "c12": "^3.0.4",
31
28
  "cac": "^6.7.14",
32
29
  "defu": "^6.1.4",
33
30
  "find-up": "^7.0.0",
@@ -37,10 +34,10 @@
37
34
  "pkg-types": "^2.1.0",
38
35
  "tsx": "^4.19.4",
39
36
  "vite": "^6.3.5",
40
- "vite-plugin-checker": "^0.9.3",
41
- "vue-tsc": "^2.2.10"
37
+ "vite-plugin-checker": "^0.9.3"
42
38
  },
43
39
  "scripts": {
44
- "build": "unbuild"
40
+ "build": "unbuild",
41
+ "dev": "unbuild --stub"
45
42
  }
46
43
  }
@@ -1,3 +0,0 @@
1
- <template>
2
- <RouterView />
3
- </template>
@@ -1,29 +0,0 @@
1
- import { f as VixtAppConfig } from '../shared/core.zLZQlpAE.mjs';
2
- import { Pinia } from 'pinia';
3
- import { App, Plugin } from 'vue';
4
- import { Router, RouteRecord } from 'vue-router';
5
- import 'c12';
6
- import 'vite';
7
-
8
- interface VixtApp {
9
- app: App;
10
- router: Router;
11
- routes: RouteRecord[];
12
- pinia: Pinia;
13
- appConfig: VixtAppConfig;
14
- }
15
-
16
- interface PluginDefinition {
17
- name?: string;
18
- setup?: (this: void, vixt: VixtApp) => any;
19
- }
20
- interface VixtPlugin {
21
- (this: void, vixt: VixtApp): any;
22
- }
23
-
24
- declare function defineAppConfig(config: VixtAppConfig): VixtAppConfig;
25
-
26
- declare function defineVuePlugin<Options = any[]>(plugin: Plugin<Options>): Plugin<Options>;
27
- declare function defineVixtPlugin(definition: PluginDefinition | VixtPlugin): VixtPlugin;
28
-
29
- export { type PluginDefinition, type VixtApp, VixtAppConfig, type VixtPlugin, defineAppConfig, defineVixtPlugin, defineVuePlugin };
@@ -1,29 +0,0 @@
1
- import { f as VixtAppConfig } from '../shared/core.zLZQlpAE.js';
2
- import { Pinia } from 'pinia';
3
- import { App, Plugin } from 'vue';
4
- import { Router, RouteRecord } from 'vue-router';
5
- import 'c12';
6
- import 'vite';
7
-
8
- interface VixtApp {
9
- app: App;
10
- router: Router;
11
- routes: RouteRecord[];
12
- pinia: Pinia;
13
- appConfig: VixtAppConfig;
14
- }
15
-
16
- interface PluginDefinition {
17
- name?: string;
18
- setup?: (this: void, vixt: VixtApp) => any;
19
- }
20
- interface VixtPlugin {
21
- (this: void, vixt: VixtApp): any;
22
- }
23
-
24
- declare function defineAppConfig(config: VixtAppConfig): VixtAppConfig;
25
-
26
- declare function defineVuePlugin<Options = any[]>(plugin: Plugin<Options>): Plugin<Options>;
27
- declare function defineVixtPlugin(definition: PluginDefinition | VixtPlugin): VixtPlugin;
28
-
29
- export { type PluginDefinition, type VixtApp, VixtAppConfig, type VixtPlugin, defineAppConfig, defineVixtPlugin, defineVuePlugin };
@@ -1,14 +0,0 @@
1
- function defineAppConfig(config) {
2
- return config;
3
- }
4
-
5
- function defineVuePlugin(plugin) {
6
- return plugin;
7
- }
8
- function defineVixtPlugin(definition) {
9
- if (typeof definition == "function")
10
- return defineVixtPlugin({ setup: definition });
11
- return (vixt) => definition.setup?.(vixt);
12
- }
13
-
14
- export { defineAppConfig, defineVixtPlugin, defineVuePlugin };
package/dist/index.d.mts DELETED
@@ -1,70 +0,0 @@
1
- import { V as VixtOptions, a as VixtConfigLayer, b as VixtConfigLayerMeta, M as ModuleOptions, c as ModuleDefinition, d as VixtModule, e as Vixt } from './shared/core.zLZQlpAE.mjs';
2
- export { g as ModuleMeta, P as PluginOptions, f as VixtAppConfig } from './shared/core.zLZQlpAE.mjs';
3
- import * as c12 from 'c12';
4
- import { LoadConfigOptions } from 'c12';
5
- import { RawVueCompilerOptions } from '@vue/language-core';
6
- import { TSConfig } from 'pkg-types';
7
- import Checker from 'vite-plugin-checker';
8
- import * as vite from 'vite';
9
- import { PluginOption } from 'vite';
10
-
11
- declare function defineVixtConfig(input: VixtOptions): VixtOptions;
12
- declare function loadVixtConfig(opts?: LoadConfigOptions<VixtOptions>): Promise<c12.ResolvedConfig<VixtOptions, c12.ConfigLayerMeta>>;
13
- declare function applyLayers(layers: VixtConfigLayer[], config: VixtOptions): {
14
- meta: VixtConfigLayerMeta;
15
- cwd?: string;
16
- config: VixtOptions | null;
17
- source?: string;
18
- sourceOptions?: c12.SourceOptions<VixtOptions, VixtConfigLayerMeta> | undefined;
19
- configFile?: string;
20
- }[];
21
- declare function isSamePath(a: string, b: string): boolean;
22
- declare function resolveLayersDirs(layers?: VixtConfigLayer[]): Record<string, string[] | undefined>;
23
-
24
- /**
25
- * Load workspace and cwd env variables by default
26
- */
27
- declare function loadEnv(mode?: string, envDir?: string | false, prefixes?: string | string[]): ImportMeta["env"];
28
- /**
29
- * find the workspace dir
30
- */
31
- declare function findUpWorkspaceDir(): string | undefined;
32
- /**
33
- * Load workspace env variables
34
- */
35
- declare function loadWorkspaceEnv(mode?: string, prefixes?: string | string[]): Record<string, string>;
36
-
37
- declare function defineVitePlugin<Options = any>(pluginFn: (options?: Options) => PluginOption): (options?: Options) => PluginOption;
38
- declare function defineVixtModule<T extends ModuleOptions>(definition: ModuleDefinition<T> | VixtModule<T>): VixtModule<T>;
39
- declare function installModule(module: VixtModule, inlineOptions: any, vixt: Vixt): PluginOption;
40
- declare function applyLayerModules(layers: VixtConfigLayer[]): Promise<VixtModule[]>;
41
-
42
- declare const config: VixtModule<ModuleOptions>;
43
-
44
- declare module '@vixt/core' {
45
- interface VixtOptions {
46
- typescript?: TypescriptOptions;
47
- }
48
- }
49
- interface TypescriptOptions {
50
- references?: (string | {
51
- path?: string;
52
- content?: string;
53
- })[];
54
- tsConfig?: TSConfig & {
55
- vueCompilerOptions?: RawVueCompilerOptions;
56
- };
57
- /** https://github.com/fi3ework/vite-plugin-checker */
58
- typeCheck?: Parameters<typeof Checker>[0];
59
- /**
60
- * Generate a `*.vue` shim
61
- * @default false
62
- */
63
- shim?: boolean;
64
- }
65
- declare const typescript: VixtModule<TypescriptOptions>;
66
-
67
- declare function loadVixt(opts?: LoadConfigOptions<VixtOptions>): Promise<Vixt>;
68
- declare function createVixtPlugin(loadOptions: LoadConfigOptions<VixtOptions>): (options?: VixtOptions | undefined) => vite.PluginOption;
69
-
70
- export { ModuleDefinition, ModuleOptions, type TypescriptOptions, Vixt, VixtConfigLayer, VixtConfigLayerMeta, VixtModule, type VixtOptions, applyLayerModules, applyLayers, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, findUpWorkspaceDir, installModule, isSamePath, loadEnv, loadVixt, loadVixtConfig, loadWorkspaceEnv, resolveLayersDirs, typescript };
package/dist/index.d.ts DELETED
@@ -1,70 +0,0 @@
1
- import { V as VixtOptions, a as VixtConfigLayer, b as VixtConfigLayerMeta, M as ModuleOptions, c as ModuleDefinition, d as VixtModule, e as Vixt } from './shared/core.zLZQlpAE.js';
2
- export { g as ModuleMeta, P as PluginOptions, f as VixtAppConfig } from './shared/core.zLZQlpAE.js';
3
- import * as c12 from 'c12';
4
- import { LoadConfigOptions } from 'c12';
5
- import { RawVueCompilerOptions } from '@vue/language-core';
6
- import { TSConfig } from 'pkg-types';
7
- import Checker from 'vite-plugin-checker';
8
- import * as vite from 'vite';
9
- import { PluginOption } from 'vite';
10
-
11
- declare function defineVixtConfig(input: VixtOptions): VixtOptions;
12
- declare function loadVixtConfig(opts?: LoadConfigOptions<VixtOptions>): Promise<c12.ResolvedConfig<VixtOptions, c12.ConfigLayerMeta>>;
13
- declare function applyLayers(layers: VixtConfigLayer[], config: VixtOptions): {
14
- meta: VixtConfigLayerMeta;
15
- cwd?: string;
16
- config: VixtOptions | null;
17
- source?: string;
18
- sourceOptions?: c12.SourceOptions<VixtOptions, VixtConfigLayerMeta> | undefined;
19
- configFile?: string;
20
- }[];
21
- declare function isSamePath(a: string, b: string): boolean;
22
- declare function resolveLayersDirs(layers?: VixtConfigLayer[]): Record<string, string[] | undefined>;
23
-
24
- /**
25
- * Load workspace and cwd env variables by default
26
- */
27
- declare function loadEnv(mode?: string, envDir?: string | false, prefixes?: string | string[]): ImportMeta["env"];
28
- /**
29
- * find the workspace dir
30
- */
31
- declare function findUpWorkspaceDir(): string | undefined;
32
- /**
33
- * Load workspace env variables
34
- */
35
- declare function loadWorkspaceEnv(mode?: string, prefixes?: string | string[]): Record<string, string>;
36
-
37
- declare function defineVitePlugin<Options = any>(pluginFn: (options?: Options) => PluginOption): (options?: Options) => PluginOption;
38
- declare function defineVixtModule<T extends ModuleOptions>(definition: ModuleDefinition<T> | VixtModule<T>): VixtModule<T>;
39
- declare function installModule(module: VixtModule, inlineOptions: any, vixt: Vixt): PluginOption;
40
- declare function applyLayerModules(layers: VixtConfigLayer[]): Promise<VixtModule[]>;
41
-
42
- declare const config: VixtModule<ModuleOptions>;
43
-
44
- declare module '@vixt/core' {
45
- interface VixtOptions {
46
- typescript?: TypescriptOptions;
47
- }
48
- }
49
- interface TypescriptOptions {
50
- references?: (string | {
51
- path?: string;
52
- content?: string;
53
- })[];
54
- tsConfig?: TSConfig & {
55
- vueCompilerOptions?: RawVueCompilerOptions;
56
- };
57
- /** https://github.com/fi3ework/vite-plugin-checker */
58
- typeCheck?: Parameters<typeof Checker>[0];
59
- /**
60
- * Generate a `*.vue` shim
61
- * @default false
62
- */
63
- shim?: boolean;
64
- }
65
- declare const typescript: VixtModule<TypescriptOptions>;
66
-
67
- declare function loadVixt(opts?: LoadConfigOptions<VixtOptions>): Promise<Vixt>;
68
- declare function createVixtPlugin(loadOptions: LoadConfigOptions<VixtOptions>): (options?: VixtOptions | undefined) => vite.PluginOption;
69
-
70
- export { ModuleDefinition, ModuleOptions, type TypescriptOptions, Vixt, VixtConfigLayer, VixtConfigLayerMeta, VixtModule, type VixtOptions, applyLayerModules, applyLayers, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, findUpWorkspaceDir, installModule, isSamePath, loadEnv, loadVixt, loadVixtConfig, loadWorkspaceEnv, resolveLayersDirs, typescript };
package/dist/index.mjs DELETED
@@ -1,346 +0,0 @@
1
- import { loadConfig } from 'c12';
2
- import fs from 'fs-extra';
3
- import path, { resolve, normalize } from 'pathe';
4
- import { env, cwd } from 'node:process';
5
- import { cac } from 'cac';
6
- import { findUpSync } from 'find-up';
7
- import { loadEnv as loadEnv$1 } from 'vite';
8
- import defu from 'defu';
9
- import { pathToFileURL } from 'mlly';
10
- import 'tsx/esm';
11
- import Checker from 'vite-plugin-checker';
12
-
13
- function defineVixtConfig(input) {
14
- return input;
15
- }
16
- async function loadVixtConfig(opts) {
17
- const result = await loadConfig({
18
- name: "vixt",
19
- rcFile: false,
20
- ...opts
21
- });
22
- const { config, cwd } = result;
23
- config.rootDir ??= cwd;
24
- config.buildDir ??= resolve(config.rootDir, ".vixt");
25
- config.buildTypesDir ??= resolve(config.buildDir, "types");
26
- config.buildLayersDir ??= resolve(config.buildDir, "layers");
27
- config.buildImportsDir ??= resolve(config.buildDir, "imports");
28
- config.srcDir ??= resolve(config.rootDir, "src");
29
- return result;
30
- }
31
- function applyLayers(layers, config) {
32
- const { rootDir, buildLayersDir } = config;
33
- return layers.filter((e) => e.cwd).map((layer) => {
34
- const meta = layer.config?.meta ?? {};
35
- const layerName = meta.name || layer.cwd.split("/").pop();
36
- if (!isSamePath(layer.cwd, resolve(rootDir))) {
37
- meta.alias = `#/layers/${layerName}`;
38
- }
39
- if (layer.cwd?.includes("node_modules")) {
40
- const newCwd = resolve(buildLayersDir, layerName);
41
- fs.copySync(layer.cwd, newCwd, {
42
- filter: (src) => {
43
- const nodeModulesPath = resolve(layer.cwd, "node_modules");
44
- const tsConfigPath = resolve(layer.cwd, "tsconfig.json");
45
- return !isSamePath(src, nodeModulesPath) && !isSamePath(src, tsConfigPath);
46
- }
47
- });
48
- layer.cwd = newCwd;
49
- }
50
- layer.config ??= {};
51
- layer.config.rootDir ??= layer.cwd;
52
- layer.config.srcDir ??= resolve(layer.config.rootDir, "src");
53
- return { ...layer, meta };
54
- });
55
- }
56
- function isSamePath(a, b) {
57
- return normalize(a) === normalize(b);
58
- }
59
- function resolveLayersDirs(layers = []) {
60
- const dirs = {};
61
- for (const layer of layers) {
62
- const srcPath = layer.config.srcDir;
63
- const isExist = fs.existsSync(srcPath);
64
- const contents = isExist ? fs.readdirSync(srcPath) : [];
65
- for (const content of contents) {
66
- const fileOrDirPath = resolve(srcPath, content);
67
- if (fs.statSync(fileOrDirPath).isDirectory()) {
68
- dirs[content] ??= [];
69
- dirs[content].push(fileOrDirPath);
70
- }
71
- }
72
- }
73
- return dirs;
74
- }
75
-
76
- function loadEnv(mode, envDir, prefixes) {
77
- const parsedArgv = cac().parse();
78
- mode = mode || parsedArgv.options.mode || parsedArgv.options.m || env.NODE_ENV;
79
- return {
80
- MODE: mode,
81
- DEV: env.NODE_ENV !== "production",
82
- PROD: env.NODE_ENV === "production",
83
- ...loadWorkspaceEnv(mode, prefixes),
84
- ...loadEnv$1(mode, envDir || cwd(), prefixes)
85
- };
86
- }
87
- function findUpWorkspaceDir() {
88
- const workspaceManifestLocation = findUpSync(["pnpm-workspace.yaml", "pnpm-workspace.yml"]);
89
- return workspaceManifestLocation && path.dirname(workspaceManifestLocation);
90
- }
91
- function loadWorkspaceEnv(mode, prefixes) {
92
- const workspaceDir = findUpWorkspaceDir();
93
- return workspaceDir ? loadEnv$1(mode, workspaceDir, prefixes) : {};
94
- }
95
-
96
- function defineVitePlugin(pluginFn) {
97
- return pluginFn;
98
- }
99
- function defineVixtModule(definition) {
100
- if (typeof definition == "function")
101
- return defineVixtModule({ setup: definition });
102
- const module = definition;
103
- function getOptions(inlineOptions, vixt) {
104
- const configKey = module.meta?.configKey || module.meta?.name;
105
- const configOptions = configKey ? vixt.options[configKey] : {};
106
- const defaultOptions = typeof module.defaults === "function" ? module.defaults(vixt) : module.defaults;
107
- const resolvedOptions = defu(inlineOptions, configOptions, defaultOptions);
108
- if (configKey) {
109
- vixt.options[configKey] = resolvedOptions;
110
- }
111
- return resolvedOptions;
112
- }
113
- function normalizedModule(inlineOptions, vixt) {
114
- const options = getOptions(inlineOptions, vixt);
115
- return module.setup?.(options, vixt);
116
- }
117
- normalizedModule.getMeta = () => module.meta;
118
- normalizedModule.getOptions = getOptions;
119
- return normalizedModule;
120
- }
121
- function installModule(module, inlineOptions, vixt) {
122
- return module(inlineOptions, vixt);
123
- }
124
- async function applyLayerModules(layers) {
125
- const { modules: modulesDirs = [] } = resolveLayersDirs(layers);
126
- const modules = [];
127
- for (const m of modulesDirs) {
128
- if (fs.existsSync(m)) {
129
- const files = fs.readdirSync(m);
130
- for (const f of files) {
131
- const p = path.resolve(m, f);
132
- const module = await import(
133
- /* @vite-ignore */
134
- pathToFileURL(p)
135
- ).then((m2) => m2.default);
136
- modules.push(module);
137
- }
138
- }
139
- }
140
- return modules;
141
- }
142
-
143
- const name$1 = "vixt:config";
144
- const config = defineVixtModule({
145
- meta: { name: name$1 },
146
- setup(_, vixt) {
147
- let env;
148
- return {
149
- name: name$1,
150
- enforce: "pre",
151
- config(config2) {
152
- const { rootDir, buildDir, srcDir } = vixt.options;
153
- const defaultAlias = {
154
- "@": srcDir,
155
- "~": srcDir,
156
- "@@": rootDir,
157
- "~~": rootDir
158
- };
159
- for (const layer of vixt._layers) {
160
- if (layer.meta?.alias) {
161
- defaultAlias[layer.meta.alias] = layer.cwd;
162
- }
163
- }
164
- defaultAlias["#"] = buildDir;
165
- env = loadEnv(config2.mode, config2.envDir, config2.envPrefix);
166
- const defineEnv = Object.fromEntries(
167
- Object.entries(env).filter(([k]) => !["MODE", "DEV", "PROD"].includes(k)).map(([k, v]) => [`import.meta.env.${k}`, JSON.stringify(v)])
168
- );
169
- return {
170
- root: rootDir,
171
- resolve: {
172
- alias: defaultAlias
173
- },
174
- define: defineEnv
175
- };
176
- },
177
- configResolved(config2) {
178
- Object.assign(config2.env, { ...env, ...config2.env });
179
- vixt.options.vite = config2;
180
- },
181
- configureServer(server) {
182
- const mode = server.config.mode;
183
- const watchFiles = [];
184
- const configFiles = vixt._layers.map((layer) => layer.configFile).filter((e) => !e.includes("node_modules"));
185
- const modulesDirs = vixt._layers.map((layer) => path.resolve(layer.config.srcDir, "modules")).filter((e) => !e.includes("node_modules"));
186
- watchFiles.push(...configFiles, ...modulesDirs);
187
- const workspaceManifestLocation = findUpSync(["pnpm-workspace.yaml", "pnpm-workspace.yml"]);
188
- if (workspaceManifestLocation) {
189
- const workspaceDir = path.dirname(workspaceManifestLocation);
190
- const envFiles = [`${workspaceDir}/.env`, `${workspaceDir}/.env.local`, `${workspaceDir}/.env.${mode}`, `${workspaceDir}/.env.${mode}.local`];
191
- watchFiles.push(...envFiles);
192
- }
193
- server.watcher.add(watchFiles);
194
- server.watcher.on("all", (_2, file) => {
195
- const match = watchFiles.some((e) => path.normalize(file).match(e));
196
- if (match)
197
- server.restart();
198
- });
199
- }
200
- };
201
- }
202
- });
203
-
204
- function generateTsConfig(options, vixt) {
205
- const { buildDir } = vixt.options;
206
- const codePath = path.resolve(buildDir, "tsconfig.json");
207
- const code = JSON.stringify(options.tsConfig, null, 2);
208
- fs.outputFileSync(codePath, code);
209
- }
210
- function generateVixtDts(options, vixt) {
211
- const { buildDir } = vixt.options;
212
- const codePath = path.resolve(buildDir, "vixt.d.ts");
213
- const code = options.references?.map((reference) => {
214
- if (typeof reference === "string") {
215
- return `/// <reference path="${reference}" />`;
216
- } else if (typeof reference === "object" && reference.path && reference.content) {
217
- fs.outputFileSync(path.resolve(buildDir, reference.path), reference.content);
218
- return `/// <reference path="${reference.path}" />`;
219
- } else {
220
- return "";
221
- }
222
- }).concat("export {}").join("\n");
223
- if (code)
224
- fs.outputFileSync(codePath, code);
225
- }
226
- function genarateShim(options, vixt) {
227
- if (!options.shim)
228
- return;
229
- const { buildTypesDir } = vixt.options;
230
- const code = `
231
- declare module '*.vue' {
232
- import type { DefineComponent } from 'vue'
233
-
234
- const component: DefineComponent
235
- export default component
236
- }
237
- `;
238
- const codePath = path.resolve(buildTypesDir, "vue-shim.d.ts");
239
- fs.outputFileSync(codePath, code);
240
- }
241
- function genarateGlobalComponents(options, vixt) {
242
- const { buildTypesDir } = vixt.options;
243
- const codePath = path.resolve(buildTypesDir, "global-components.d.ts");
244
- const code = `
245
- import type { GlobalComponents as _GlobalComponents } from '@vue/runtime-core'
246
-
247
- declare module 'vue'{
248
- interface GlobalComponents extends _GlobalComponents {}
249
- }
250
- `;
251
- fs.outputFileSync(codePath, code);
252
- }
253
- function generateEnvDts(env, vixt) {
254
- const { buildTypesDir } = vixt.options;
255
- const codePath = path.resolve(buildTypesDir, "vite-env.d.ts");
256
- const values = Object.entries(env).map(([key, value]) => `/** ${key}=${value} */
257
- ${key}: ${typeof value}`).join("\n ");
258
- const code = `interface ImportMeta {
259
- readonly env: ImportMetaEnv
260
- }
261
- interface ImportMetaEnv {
262
- ${values}
263
- }
264
- `;
265
- fs.outputFileSync(codePath, code);
266
- }
267
- const name = "vixt:typescript";
268
- const typescript = defineVixtModule({
269
- meta: { name, configKey: "typescript" },
270
- defaults(vixt) {
271
- const { rootDir, srcDir } = vixt.options;
272
- const rootAlias = {};
273
- if (rootDir)
274
- rootAlias["@@/*"] = rootAlias["~~/*"] = [`${rootDir}/*`];
275
- const srcAlias = {};
276
- if (srcDir)
277
- srcAlias["@/*"] = srcAlias["~/*"] = [`${srcDir}/*`];
278
- const layersDirs = [];
279
- const layersAlias = {};
280
- for (const layer of vixt._layers) {
281
- layersDirs.push(layer.cwd);
282
- if (layer.meta?.alias)
283
- layersAlias[`${layer.meta.alias}/*`] = [`${layer.cwd}/*`];
284
- }
285
- return {
286
- tsConfig: {
287
- extends: "@vue/tsconfig/tsconfig.dom.json",
288
- compilerOptions: {
289
- baseUrl: rootDir,
290
- paths: { "#/*": ["./*"], ...layersAlias, ...rootAlias, ...srcAlias },
291
- types: ["vite/client"]
292
- },
293
- include: ["./**/*", ...layersDirs]
294
- },
295
- typeCheck: {
296
- enableBuild: false,
297
- overlay: { initialIsOpen: false }
298
- }
299
- };
300
- },
301
- setup(options, vixt) {
302
- return [
303
- {
304
- name,
305
- configResolved(config) {
306
- generateTsConfig(options, vixt);
307
- generateVixtDts(options, vixt);
308
- genarateShim(options, vixt);
309
- genarateGlobalComponents(options, vixt);
310
- generateEnvDts(config.env, vixt);
311
- }
312
- },
313
- Checker(options.typeCheck ?? {})
314
- ];
315
- }
316
- });
317
-
318
- async function loadVixt(opts) {
319
- const result = await loadVixtConfig(defu(opts, {
320
- defaults: {
321
- modules: [config, typescript]
322
- }
323
- }));
324
- const parsedArgv = cac().parse();
325
- const isForce = !!parsedArgv.options.force;
326
- if (isForce) {
327
- fs.removeSync(result.config.buildDir);
328
- }
329
- result.layers = applyLayers(result.layers ?? [], result.config);
330
- const layerModules = await applyLayerModules(result.layers ?? []);
331
- const vixt = {
332
- options: result.config,
333
- _layers: result.layers ?? [],
334
- _modules: [...result.config.modules ?? [], ...layerModules]
335
- };
336
- return vixt;
337
- }
338
- function createVixtPlugin(loadOptions) {
339
- return defineVitePlugin(async (vixtOptions) => {
340
- const vixt = await loadVixt(defu({ defaults: vixtOptions }, loadOptions));
341
- const plugins = vixt._modules.map((module) => module({}, vixt));
342
- return plugins;
343
- });
344
- }
345
-
346
- export { applyLayerModules, applyLayers, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, findUpWorkspaceDir, installModule, isSamePath, loadEnv, loadVixt, loadVixtConfig, loadWorkspaceEnv, resolveLayersDirs, typescript };
@@ -1,73 +0,0 @@
1
- import { ConfigLayer, ConfigLayerMeta } from 'c12';
2
- import { PluginOption, ResolvedConfig } from 'vite';
3
-
4
- interface Vixt {
5
- options: VixtOptions;
6
- _layers: VixtConfigLayer[];
7
- _modules: VixtModule[];
8
- }
9
-
10
- type PluginOptions<Options = any> = (Options extends (...args: any[]) => any ? Parameters<Options>[0] : Options);
11
- type ModuleOptions = Record<string, any>;
12
- interface ModuleMeta extends Record<string, any> {
13
- name?: string;
14
- configKey?: string;
15
- }
16
- interface ModuleDefinition<T extends ModuleOptions = ModuleOptions> {
17
- meta?: ModuleMeta;
18
- defaults?: T | ((vixt: Vixt) => T);
19
- setup?: (this: void, resolvedOptions: T, vixt: Vixt) => PluginOption | void;
20
- }
21
- interface VixtModule<T extends ModuleOptions = ModuleOptions> {
22
- (this: void, inlineOptions: T, vixt: Vixt): PluginOption;
23
- getOptions?: (inlineOptions?: T, Vixt?: Vixt) => T;
24
- getMeta?: () => ModuleMeta;
25
- }
26
-
27
- interface VixtOptions extends Record<string, any> {
28
- /**
29
- * @default process.cwd()
30
- */
31
- rootDir?: string;
32
- /**
33
- * @default '<rootDir>/.vixt'
34
- */
35
- buildDir?: string;
36
- /**
37
- * @default '<buildDir>/types'
38
- */
39
- buildTypesDir?: string;
40
- /**
41
- * @default '<buildDir>/layers'
42
- */
43
- buildLayersDir?: string;
44
- /**
45
- * @default '<buildDir>/imports'
46
- */
47
- buildImportsDir?: string;
48
- /**
49
- * @default '<rootDir>/src'
50
- */
51
- srcDir?: string;
52
- /** modules */
53
- modules?: VixtModule[];
54
- /** use on configResolved */
55
- vite?: ResolvedConfig;
56
- meta?: VixtConfigLayerMeta;
57
- /** layers */
58
- extends?: string[];
59
- }
60
- interface VixtConfigLayerMeta extends ConfigLayerMeta {
61
- /** layer name */
62
- name?: string;
63
- /** layer alias */
64
- alias?: string;
65
- }
66
- interface VixtConfigLayer extends ConfigLayer<VixtOptions, VixtConfigLayerMeta> {
67
- /** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, and change cwd */
68
- cwd?: string;
69
- }
70
- interface VixtAppConfig extends Record<string, any> {
71
- }
72
-
73
- export type { ModuleOptions as M, PluginOptions as P, VixtOptions as V, VixtConfigLayer as a, VixtConfigLayerMeta as b, ModuleDefinition as c, VixtModule as d, Vixt as e, VixtAppConfig as f, ModuleMeta as g };
@@ -1,73 +0,0 @@
1
- import { ConfigLayer, ConfigLayerMeta } from 'c12';
2
- import { PluginOption, ResolvedConfig } from 'vite';
3
-
4
- interface Vixt {
5
- options: VixtOptions;
6
- _layers: VixtConfigLayer[];
7
- _modules: VixtModule[];
8
- }
9
-
10
- type PluginOptions<Options = any> = (Options extends (...args: any[]) => any ? Parameters<Options>[0] : Options);
11
- type ModuleOptions = Record<string, any>;
12
- interface ModuleMeta extends Record<string, any> {
13
- name?: string;
14
- configKey?: string;
15
- }
16
- interface ModuleDefinition<T extends ModuleOptions = ModuleOptions> {
17
- meta?: ModuleMeta;
18
- defaults?: T | ((vixt: Vixt) => T);
19
- setup?: (this: void, resolvedOptions: T, vixt: Vixt) => PluginOption | void;
20
- }
21
- interface VixtModule<T extends ModuleOptions = ModuleOptions> {
22
- (this: void, inlineOptions: T, vixt: Vixt): PluginOption;
23
- getOptions?: (inlineOptions?: T, Vixt?: Vixt) => T;
24
- getMeta?: () => ModuleMeta;
25
- }
26
-
27
- interface VixtOptions extends Record<string, any> {
28
- /**
29
- * @default process.cwd()
30
- */
31
- rootDir?: string;
32
- /**
33
- * @default '<rootDir>/.vixt'
34
- */
35
- buildDir?: string;
36
- /**
37
- * @default '<buildDir>/types'
38
- */
39
- buildTypesDir?: string;
40
- /**
41
- * @default '<buildDir>/layers'
42
- */
43
- buildLayersDir?: string;
44
- /**
45
- * @default '<buildDir>/imports'
46
- */
47
- buildImportsDir?: string;
48
- /**
49
- * @default '<rootDir>/src'
50
- */
51
- srcDir?: string;
52
- /** modules */
53
- modules?: VixtModule[];
54
- /** use on configResolved */
55
- vite?: ResolvedConfig;
56
- meta?: VixtConfigLayerMeta;
57
- /** layers */
58
- extends?: string[];
59
- }
60
- interface VixtConfigLayerMeta extends ConfigLayerMeta {
61
- /** layer name */
62
- name?: string;
63
- /** layer alias */
64
- alias?: string;
65
- }
66
- interface VixtConfigLayer extends ConfigLayer<VixtOptions, VixtConfigLayerMeta> {
67
- /** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, and change cwd */
68
- cwd?: string;
69
- }
70
- interface VixtAppConfig extends Record<string, any> {
71
- }
72
-
73
- export type { ModuleOptions as M, PluginOptions as P, VixtOptions as V, VixtConfigLayer as a, VixtConfigLayerMeta as b, ModuleDefinition as c, VixtModule as d, Vixt as e, VixtAppConfig as f, ModuleMeta as g };