vize 0.0.1-alpha.20 → 0.1.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/README.md +1 -1
- package/bin/vize +1 -29
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +107 -0
- package/dist/cli.js.map +1 -0
- package/dist/config-CVmInrFP.js +126 -0
- package/dist/config-CVmInrFP.js.map +1 -0
- package/dist/config-Cu4Hn1JG.d.ts +422 -0
- package/dist/config-Cu4Hn1JG.d.ts.map +1 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/package.json +39 -5
- package/src/cli.ts +193 -0
- package/src/config.ts +192 -0
- package/src/index.ts +33 -0
- package/src/types.ts +515 -0
- package/scripts/postinstall.js +0 -138
package/src/config.ts
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { transform } from "oxc-transform";
|
|
5
|
+
import type {
|
|
6
|
+
VizeConfig,
|
|
7
|
+
LoadConfigOptions,
|
|
8
|
+
UserConfigExport,
|
|
9
|
+
ConfigEnv,
|
|
10
|
+
GlobalTypesConfig,
|
|
11
|
+
GlobalTypeDeclaration,
|
|
12
|
+
} from "./types.js";
|
|
13
|
+
|
|
14
|
+
const CONFIG_FILE_NAMES = [
|
|
15
|
+
"vize.config.ts",
|
|
16
|
+
"vize.config.js",
|
|
17
|
+
"vize.config.mjs",
|
|
18
|
+
"vize.config.json",
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const DEFAULT_CONFIG_ENV: ConfigEnv = {
|
|
22
|
+
mode: "development",
|
|
23
|
+
command: "serve",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Define a Vize configuration with type checking.
|
|
28
|
+
* Accepts a plain object or a function that receives ConfigEnv.
|
|
29
|
+
*/
|
|
30
|
+
export function defineConfig(config: UserConfigExport): UserConfigExport {
|
|
31
|
+
return config;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Load vize.config file from the specified directory
|
|
36
|
+
*/
|
|
37
|
+
export async function loadConfig(
|
|
38
|
+
root: string,
|
|
39
|
+
options: LoadConfigOptions = {},
|
|
40
|
+
): Promise<VizeConfig | null> {
|
|
41
|
+
const { mode = "root", configFile, env } = options;
|
|
42
|
+
|
|
43
|
+
if (mode === "none") {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Custom config file path
|
|
48
|
+
if (configFile) {
|
|
49
|
+
const absolutePath = path.isAbsolute(configFile) ? configFile : path.resolve(root, configFile);
|
|
50
|
+
if (fs.existsSync(absolutePath)) {
|
|
51
|
+
return loadConfigFile(absolutePath, env);
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Search for config file
|
|
57
|
+
if (mode === "auto") {
|
|
58
|
+
const configPath = findConfigFileAuto(root);
|
|
59
|
+
if (!configPath) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
return loadConfigFile(configPath, env);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// mode === "root"
|
|
66
|
+
const configPath = findConfigFileInDir(root);
|
|
67
|
+
if (!configPath) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return loadConfigFile(configPath, env);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Find config file in a specific directory
|
|
75
|
+
*/
|
|
76
|
+
function findConfigFileInDir(dir: string): string | null {
|
|
77
|
+
for (const name of CONFIG_FILE_NAMES) {
|
|
78
|
+
const filePath = path.join(dir, name);
|
|
79
|
+
if (fs.existsSync(filePath)) {
|
|
80
|
+
return filePath;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Find config file by searching from cwd upward
|
|
88
|
+
*/
|
|
89
|
+
function findConfigFileAuto(startDir: string): string | null {
|
|
90
|
+
let currentDir = path.resolve(startDir);
|
|
91
|
+
const root = path.parse(currentDir).root;
|
|
92
|
+
|
|
93
|
+
while (currentDir !== root) {
|
|
94
|
+
const configPath = findConfigFileInDir(currentDir);
|
|
95
|
+
if (configPath) {
|
|
96
|
+
return configPath;
|
|
97
|
+
}
|
|
98
|
+
currentDir = path.dirname(currentDir);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Load and evaluate a config file
|
|
106
|
+
*/
|
|
107
|
+
async function loadConfigFile(filePath: string, env?: ConfigEnv): Promise<VizeConfig | null> {
|
|
108
|
+
if (!fs.existsSync(filePath)) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const ext = path.extname(filePath);
|
|
113
|
+
|
|
114
|
+
if (ext === ".json") {
|
|
115
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
116
|
+
return JSON.parse(content);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (ext === ".ts") {
|
|
120
|
+
return loadTypeScriptConfig(filePath, env);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// .js, .mjs - ESM
|
|
124
|
+
return loadESMConfig(filePath, env);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Resolve a UserConfigExport to a VizeConfig
|
|
129
|
+
*/
|
|
130
|
+
async function resolveConfigExport(
|
|
131
|
+
exported: UserConfigExport,
|
|
132
|
+
env?: ConfigEnv,
|
|
133
|
+
): Promise<VizeConfig> {
|
|
134
|
+
if (typeof exported === "function") {
|
|
135
|
+
return exported(env ?? DEFAULT_CONFIG_ENV);
|
|
136
|
+
}
|
|
137
|
+
return exported;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Load TypeScript config file using oxc-transform
|
|
142
|
+
*/
|
|
143
|
+
async function loadTypeScriptConfig(filePath: string, env?: ConfigEnv): Promise<VizeConfig> {
|
|
144
|
+
const source = fs.readFileSync(filePath, "utf-8");
|
|
145
|
+
const result = transform(filePath, source, {
|
|
146
|
+
typescript: {
|
|
147
|
+
onlyRemoveTypeImports: true,
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const code = result.code;
|
|
152
|
+
|
|
153
|
+
// Write to temp file and import (use Date.now() to avoid race conditions)
|
|
154
|
+
const tempFile = filePath.replace(/\.ts$/, `.temp.${Date.now()}.mjs`);
|
|
155
|
+
fs.writeFileSync(tempFile, code);
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
const fileUrl = pathToFileURL(tempFile).href;
|
|
159
|
+
const module = await import(fileUrl);
|
|
160
|
+
const exported: UserConfigExport = module.default || module;
|
|
161
|
+
return resolveConfigExport(exported, env);
|
|
162
|
+
} finally {
|
|
163
|
+
fs.unlinkSync(tempFile);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Load ESM config file
|
|
169
|
+
*/
|
|
170
|
+
async function loadESMConfig(filePath: string, env?: ConfigEnv): Promise<VizeConfig> {
|
|
171
|
+
const fileUrl = pathToFileURL(filePath).href;
|
|
172
|
+
const module = await import(fileUrl);
|
|
173
|
+
const exported: UserConfigExport = module.default || module;
|
|
174
|
+
return resolveConfigExport(exported, env);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Normalize GlobalTypesConfig shorthand strings to GlobalTypeDeclaration objects
|
|
179
|
+
*/
|
|
180
|
+
export function normalizeGlobalTypes(
|
|
181
|
+
config: GlobalTypesConfig,
|
|
182
|
+
): Record<string, GlobalTypeDeclaration> {
|
|
183
|
+
const result: Record<string, GlobalTypeDeclaration> = {};
|
|
184
|
+
for (const [key, value] of Object.entries(config)) {
|
|
185
|
+
if (typeof value === "string") {
|
|
186
|
+
result[key] = { type: value };
|
|
187
|
+
} else {
|
|
188
|
+
result[key] = value;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return result;
|
|
192
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vize - High-performance Vue.js toolchain in Rust
|
|
3
|
+
*
|
|
4
|
+
* This package provides:
|
|
5
|
+
* - CLI binary for compilation, linting, and formatting
|
|
6
|
+
* - Configuration utilities for programmatic use
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Types
|
|
10
|
+
export type {
|
|
11
|
+
VizeConfig,
|
|
12
|
+
CompilerConfig,
|
|
13
|
+
VitePluginConfig,
|
|
14
|
+
LinterConfig,
|
|
15
|
+
TypeCheckerConfig,
|
|
16
|
+
FormatterConfig,
|
|
17
|
+
LspConfig,
|
|
18
|
+
MuseaConfig,
|
|
19
|
+
MuseaVrtConfig,
|
|
20
|
+
MuseaA11yConfig,
|
|
21
|
+
MuseaAutogenConfig,
|
|
22
|
+
GlobalTypesConfig,
|
|
23
|
+
GlobalTypeDeclaration,
|
|
24
|
+
LoadConfigOptions,
|
|
25
|
+
ConfigEnv,
|
|
26
|
+
UserConfigExport,
|
|
27
|
+
MaybePromise,
|
|
28
|
+
RuleSeverity,
|
|
29
|
+
RuleCategory,
|
|
30
|
+
} from "./types.js";
|
|
31
|
+
|
|
32
|
+
// Config utilities
|
|
33
|
+
export { defineConfig, loadConfig, normalizeGlobalTypes } from "./config.js";
|