@teamvelix/cli 5.3.3 → 5.3.5
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/LICENSE +21 -0
- package/dist/{build-R6YPQMKQ.js → build-54KS3AON.js} +3 -3
- package/dist/{chunk-QVHVWNX3.js → chunk-PAUSXGWF.js} +4 -2
- package/dist/{chunk-QVHVWNX3.js.map → chunk-PAUSXGWF.js.map} +1 -1
- package/dist/{create-ECJXHPS4.js → create-UWF6XCR3.js} +3 -3
- package/dist/{dev-H632BVX7.js → dev-HZLANTXK.js} +3 -3
- package/dist/{doctor-4ZBGISX6.js → doctor-GBSK3EJ3.js} +3 -3
- package/dist/{generate-F5PULUKX.js → generate-MZ7LZO4K.js} +3 -3
- package/dist/index.js +11 -11
- package/dist/{pack-IHVEY27S.js → pack-OXFEH5L5.js} +5 -5
- package/dist/{pack-IHVEY27S.js.map → pack-OXFEH5L5.js.map} +1 -1
- package/dist/src-BXA4CRFC.js +822 -0
- package/dist/src-BXA4CRFC.js.map +1 -0
- package/dist/{ui-2KJQ4SG6.js → ui-CFSX57E3.js} +3 -3
- package/package.json +8 -6
- package/dist/chunk-7D4SUZUM.js +0 -38
- package/dist/chunk-7D4SUZUM.js.map +0 -1
- package/dist/src-YLSZ2QML.js +0 -8173
- package/dist/src-YLSZ2QML.js.map +0 -1
- /package/dist/{build-R6YPQMKQ.js.map → build-54KS3AON.js.map} +0 -0
- /package/dist/{create-ECJXHPS4.js.map → create-UWF6XCR3.js.map} +0 -0
- /package/dist/{dev-H632BVX7.js.map → dev-HZLANTXK.js.map} +0 -0
- /package/dist/{doctor-4ZBGISX6.js.map → doctor-GBSK3EJ3.js.map} +0 -0
- /package/dist/{generate-F5PULUKX.js.map → generate-MZ7LZO4K.js.map} +0 -0
- /package/dist/{ui-2KJQ4SG6.js.map → ui-CFSX57E3.js.map} +0 -0
|
@@ -0,0 +1,822 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// ../velix-pack/src/index.ts
|
|
4
|
+
import path9 from "path";
|
|
5
|
+
import fs6 from "fs";
|
|
6
|
+
|
|
7
|
+
// ../velix-pack/src/resolver/index.ts
|
|
8
|
+
import fs2 from "fs";
|
|
9
|
+
import path2 from "path";
|
|
10
|
+
|
|
11
|
+
// ../velix-pack/src/resolver/aliases.ts
|
|
12
|
+
import fs from "fs";
|
|
13
|
+
import path from "path";
|
|
14
|
+
function loadPathAliases(projectRoot) {
|
|
15
|
+
const tsconfigPath = path.join(projectRoot, "tsconfig.json");
|
|
16
|
+
if (!fs.existsSync(tsconfigPath)) return [];
|
|
17
|
+
try {
|
|
18
|
+
const raw = fs.readFileSync(tsconfigPath, "utf-8");
|
|
19
|
+
const jsonStr = raw.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, "");
|
|
20
|
+
const tsconfig = JSON.parse(jsonStr);
|
|
21
|
+
const compilerOptions = tsconfig?.compilerOptions || {};
|
|
22
|
+
const paths = compilerOptions.paths || {};
|
|
23
|
+
const baseUrl = compilerOptions.baseUrl ? path.resolve(projectRoot, compilerOptions.baseUrl) : projectRoot;
|
|
24
|
+
const aliases = [];
|
|
25
|
+
for (const [key, value] of Object.entries(paths)) {
|
|
26
|
+
if (Array.isArray(value) && value.length > 0) {
|
|
27
|
+
const prefix = key.replace(/\/\*$/, "");
|
|
28
|
+
const targetRelative = value[0].replace(/\/\*$/, "");
|
|
29
|
+
aliases.push({
|
|
30
|
+
prefix,
|
|
31
|
+
target: path.resolve(baseUrl, targetRelative)
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return aliases;
|
|
36
|
+
} catch {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ../velix-pack/src/resolver/index.ts
|
|
42
|
+
var Resolver = class {
|
|
43
|
+
projectRoot;
|
|
44
|
+
aliases;
|
|
45
|
+
extensions;
|
|
46
|
+
constructor(options) {
|
|
47
|
+
this.projectRoot = options.projectRoot;
|
|
48
|
+
this.aliases = loadPathAliases(this.projectRoot);
|
|
49
|
+
this.extensions = options.extensions || [".tsx", ".ts", ".jsx", ".js", ".json", ".css"];
|
|
50
|
+
}
|
|
51
|
+
resolve(importPath, importerPath) {
|
|
52
|
+
if (!importPath.startsWith(".") && !importPath.startsWith("/") && !this.isAliasMatch(importPath)) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
let targetPath = importPath;
|
|
56
|
+
for (const alias of this.aliases) {
|
|
57
|
+
if (importPath === alias.prefix || importPath.startsWith(alias.prefix + "/")) {
|
|
58
|
+
targetPath = importPath.replace(alias.prefix, alias.target);
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
let absolutePath = targetPath;
|
|
63
|
+
if (!path2.isAbsolute(targetPath)) {
|
|
64
|
+
absolutePath = path2.resolve(path2.dirname(importerPath), targetPath);
|
|
65
|
+
}
|
|
66
|
+
if (fs2.existsSync(absolutePath) && fs2.statSync(absolutePath).isFile()) {
|
|
67
|
+
return absolutePath;
|
|
68
|
+
}
|
|
69
|
+
if (absolutePath.endsWith(".js")) {
|
|
70
|
+
const tsPath = absolutePath.slice(0, -3) + ".ts";
|
|
71
|
+
const tsxPath = absolutePath.slice(0, -3) + ".tsx";
|
|
72
|
+
if (fs2.existsSync(tsPath) && fs2.statSync(tsPath).isFile()) return tsPath;
|
|
73
|
+
if (fs2.existsSync(tsxPath) && fs2.statSync(tsxPath).isFile()) return tsxPath;
|
|
74
|
+
}
|
|
75
|
+
for (const ext of this.extensions) {
|
|
76
|
+
const pathWithExt = absolutePath + ext;
|
|
77
|
+
if (fs2.existsSync(pathWithExt) && fs2.statSync(pathWithExt).isFile()) {
|
|
78
|
+
return pathWithExt;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
for (const ext of this.extensions) {
|
|
82
|
+
const indexPath = path2.join(absolutePath, `index${ext}`);
|
|
83
|
+
if (fs2.existsSync(indexPath) && fs2.statSync(indexPath).isFile()) {
|
|
84
|
+
return indexPath;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
isAliasMatch(importPath) {
|
|
90
|
+
return this.aliases.some((alias) => importPath === alias.prefix || importPath.startsWith(alias.prefix + "/"));
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// ../velix-pack/src/graph/module-graph.ts
|
|
95
|
+
import path3 from "path";
|
|
96
|
+
|
|
97
|
+
// ../velix-pack/src/graph/module.ts
|
|
98
|
+
var Module = class {
|
|
99
|
+
id;
|
|
100
|
+
path;
|
|
101
|
+
type;
|
|
102
|
+
dependencies = /* @__PURE__ */ new Set();
|
|
103
|
+
dependents = /* @__PURE__ */ new Set();
|
|
104
|
+
hash;
|
|
105
|
+
lastModified;
|
|
106
|
+
isEntry;
|
|
107
|
+
constructor(id, path10, type = "shared") {
|
|
108
|
+
this.id = id;
|
|
109
|
+
this.path = path10;
|
|
110
|
+
this.type = type;
|
|
111
|
+
}
|
|
112
|
+
addDependency(depId) {
|
|
113
|
+
this.dependencies.add(depId);
|
|
114
|
+
}
|
|
115
|
+
removeDependency(depId) {
|
|
116
|
+
this.dependencies.delete(depId);
|
|
117
|
+
}
|
|
118
|
+
addDependent(dependentId) {
|
|
119
|
+
this.dependents.add(dependentId);
|
|
120
|
+
}
|
|
121
|
+
removeDependent(dependentId) {
|
|
122
|
+
this.dependents.delete(dependentId);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// ../velix-pack/src/graph/boundary.ts
|
|
127
|
+
function isServerModule(filePath, content) {
|
|
128
|
+
const normalized = filePath.replace(/\\/g, "/");
|
|
129
|
+
if (normalized.includes("/server/") || normalized.startsWith("server/")) return true;
|
|
130
|
+
if (content) {
|
|
131
|
+
const firstLines = content.split("\n").slice(0, 5).map((l) => l.trim());
|
|
132
|
+
if (firstLines.some((l) => l === "'use server'" || l === '"use server"')) {
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
function isClientModule(filePath, content) {
|
|
139
|
+
if (content) {
|
|
140
|
+
const firstLines = content.split("\n").slice(0, 5).map((l) => l.trim());
|
|
141
|
+
if (firstLines.some((l) => l === "'use client'" || l === '"use client"' || l === "'use island'" || l === '"use island"')) {
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
function checkBoundaryViolations(modules) {
|
|
148
|
+
const violations = [];
|
|
149
|
+
for (const [id, mod] of modules.entries()) {
|
|
150
|
+
if (mod.type === "client") {
|
|
151
|
+
for (const depId of mod.dependencies) {
|
|
152
|
+
const dep = modules.get(depId);
|
|
153
|
+
if (dep && dep.type === "server") {
|
|
154
|
+
violations.push({
|
|
155
|
+
clientModule: id,
|
|
156
|
+
serverModule: depId,
|
|
157
|
+
importStatement: `Import of server module "${depId}" from client module "${id}"`
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return violations;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// ../velix-pack/src/graph/module-graph.ts
|
|
167
|
+
var ModuleGraph = class {
|
|
168
|
+
modules = /* @__PURE__ */ new Map();
|
|
169
|
+
projectRoot;
|
|
170
|
+
constructor(projectRoot) {
|
|
171
|
+
this.projectRoot = projectRoot;
|
|
172
|
+
}
|
|
173
|
+
getModule(id) {
|
|
174
|
+
return this.modules.get(id);
|
|
175
|
+
}
|
|
176
|
+
getModuleByPath(filePath) {
|
|
177
|
+
const id = this.toRelativeId(filePath);
|
|
178
|
+
return this.modules.get(id);
|
|
179
|
+
}
|
|
180
|
+
addModule(filePath, type = "shared") {
|
|
181
|
+
const id = this.toRelativeId(filePath);
|
|
182
|
+
let mod = this.modules.get(id);
|
|
183
|
+
if (!mod) {
|
|
184
|
+
mod = new Module(id, filePath, type);
|
|
185
|
+
this.modules.set(id, mod);
|
|
186
|
+
} else {
|
|
187
|
+
mod.type = type;
|
|
188
|
+
}
|
|
189
|
+
return mod;
|
|
190
|
+
}
|
|
191
|
+
removeModule(filePath) {
|
|
192
|
+
const id = this.toRelativeId(filePath);
|
|
193
|
+
const mod = this.modules.get(id);
|
|
194
|
+
const affectedDependents = /* @__PURE__ */ new Set();
|
|
195
|
+
if (mod) {
|
|
196
|
+
for (const depId of mod.dependents) {
|
|
197
|
+
affectedDependents.add(depId);
|
|
198
|
+
const depMod = this.modules.get(depId);
|
|
199
|
+
if (depMod) {
|
|
200
|
+
depMod.removeDependency(id);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
for (const depId of mod.dependencies) {
|
|
204
|
+
const depMod = this.modules.get(depId);
|
|
205
|
+
if (depMod) {
|
|
206
|
+
depMod.removeDependent(id);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
this.modules.delete(id);
|
|
210
|
+
}
|
|
211
|
+
return affectedDependents;
|
|
212
|
+
}
|
|
213
|
+
updateDependencies(filePath, dependencyPaths) {
|
|
214
|
+
const id = this.toRelativeId(filePath);
|
|
215
|
+
const mod = this.getModule(id);
|
|
216
|
+
if (!mod) return;
|
|
217
|
+
const newDepIds = new Set(dependencyPaths.map((p) => this.toRelativeId(p)));
|
|
218
|
+
for (const oldDepId of Array.from(mod.dependencies)) {
|
|
219
|
+
if (!newDepIds.has(oldDepId)) {
|
|
220
|
+
mod.removeDependency(oldDepId);
|
|
221
|
+
const depMod = this.modules.get(oldDepId);
|
|
222
|
+
if (depMod) {
|
|
223
|
+
depMod.removeDependent(id);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
for (const newDepId of newDepIds) {
|
|
228
|
+
if (!mod.dependencies.has(newDepId)) {
|
|
229
|
+
mod.addDependency(newDepId);
|
|
230
|
+
const depMod = this.modules.get(newDepId);
|
|
231
|
+
if (depMod) {
|
|
232
|
+
depMod.addDependent(id);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Finds all affected modules recursively when a file changes
|
|
239
|
+
*/
|
|
240
|
+
getAffectedModules(filePath) {
|
|
241
|
+
const startId = this.toRelativeId(filePath);
|
|
242
|
+
const affected = /* @__PURE__ */ new Set();
|
|
243
|
+
const queue = [startId];
|
|
244
|
+
while (queue.length > 0) {
|
|
245
|
+
const currentId = queue.shift();
|
|
246
|
+
if (!affected.has(currentId)) {
|
|
247
|
+
affected.add(currentId);
|
|
248
|
+
const mod = this.modules.get(currentId);
|
|
249
|
+
if (mod) {
|
|
250
|
+
for (const dependentId of mod.dependents) {
|
|
251
|
+
queue.push(dependentId);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return affected;
|
|
257
|
+
}
|
|
258
|
+
getAllModules() {
|
|
259
|
+
return this.modules;
|
|
260
|
+
}
|
|
261
|
+
checkBoundaries() {
|
|
262
|
+
return checkBoundaryViolations(this.modules);
|
|
263
|
+
}
|
|
264
|
+
toRelativeId(filePath) {
|
|
265
|
+
const relative = path3.relative(this.projectRoot, filePath);
|
|
266
|
+
return relative.replace(/\\/g, "/");
|
|
267
|
+
}
|
|
268
|
+
clear() {
|
|
269
|
+
this.modules.clear();
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// ../velix-pack/src/transform/index.ts
|
|
274
|
+
import fs3 from "fs";
|
|
275
|
+
import path5 from "path";
|
|
276
|
+
import crypto from "crypto";
|
|
277
|
+
|
|
278
|
+
// ../velix-pack/src/transform/typescript.ts
|
|
279
|
+
import esbuild from "esbuild";
|
|
280
|
+
import path4 from "path";
|
|
281
|
+
async function transformTypeScript(filePath, content, resolver) {
|
|
282
|
+
const ext = path4.extname(filePath);
|
|
283
|
+
const loader = ext === ".tsx" ? "tsx" : ext === ".jsx" ? "jsx" : "ts";
|
|
284
|
+
const result = await esbuild.transform(content, {
|
|
285
|
+
loader,
|
|
286
|
+
target: "es2022",
|
|
287
|
+
format: "esm",
|
|
288
|
+
jsx: "automatic",
|
|
289
|
+
sourcemap: "inline",
|
|
290
|
+
sourcefile: filePath
|
|
291
|
+
});
|
|
292
|
+
const imports = extractImports(content, filePath, resolver);
|
|
293
|
+
let type = "shared";
|
|
294
|
+
if (isServerModule(filePath, content)) {
|
|
295
|
+
type = "server";
|
|
296
|
+
} else if (isClientModule(filePath, content)) {
|
|
297
|
+
type = "client";
|
|
298
|
+
}
|
|
299
|
+
return {
|
|
300
|
+
code: result.code,
|
|
301
|
+
map: result.map,
|
|
302
|
+
imports,
|
|
303
|
+
type
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
function extractImports(content, filePath, resolver) {
|
|
307
|
+
const imports = [];
|
|
308
|
+
const importRegex = /(?:import|export)\s+(?:[\s\S]*?\s+from\s+)?['"]([^'"]+)['"]|import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
309
|
+
let match;
|
|
310
|
+
while ((match = importRegex.exec(content)) !== null) {
|
|
311
|
+
const importPath = match[1] || match[2];
|
|
312
|
+
if (importPath) {
|
|
313
|
+
const resolved = resolver.resolve(importPath, filePath);
|
|
314
|
+
if (resolved) {
|
|
315
|
+
imports.push(resolved);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return Array.from(new Set(imports));
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// ../velix-pack/src/transform/css.ts
|
|
323
|
+
async function transformCSS(filePath, content) {
|
|
324
|
+
return {
|
|
325
|
+
code: content,
|
|
326
|
+
imports: [],
|
|
327
|
+
type: "shared"
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// ../velix-pack/src/transform/json.ts
|
|
332
|
+
async function transformJSON(filePath, content) {
|
|
333
|
+
let code = "";
|
|
334
|
+
try {
|
|
335
|
+
const json = JSON.parse(content);
|
|
336
|
+
code = `export default ${JSON.stringify(json)};`;
|
|
337
|
+
} catch {
|
|
338
|
+
code = `export default {};`;
|
|
339
|
+
}
|
|
340
|
+
return {
|
|
341
|
+
code,
|
|
342
|
+
imports: [],
|
|
343
|
+
type: "shared"
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// ../velix-pack/src/transform/index.ts
|
|
348
|
+
var TransformPipeline = class {
|
|
349
|
+
resolver;
|
|
350
|
+
constructor(resolver) {
|
|
351
|
+
this.resolver = resolver;
|
|
352
|
+
}
|
|
353
|
+
async transform(filePath) {
|
|
354
|
+
const content = fs3.readFileSync(filePath, "utf-8");
|
|
355
|
+
const hash = crypto.createHash("md5").update(content).digest("hex");
|
|
356
|
+
const ext = path5.extname(filePath);
|
|
357
|
+
if (ext === ".ts" || ext === ".tsx" || ext === ".js" || ext === ".jsx") {
|
|
358
|
+
const result = await transformTypeScript(filePath, content, this.resolver);
|
|
359
|
+
return { ...result, hash };
|
|
360
|
+
} else if (ext === ".css") {
|
|
361
|
+
const result = await transformCSS(filePath, content);
|
|
362
|
+
return { ...result, hash };
|
|
363
|
+
} else if (ext === ".json") {
|
|
364
|
+
const result = await transformJSON(filePath, content);
|
|
365
|
+
return { ...result, hash };
|
|
366
|
+
}
|
|
367
|
+
return {
|
|
368
|
+
code: content,
|
|
369
|
+
imports: [],
|
|
370
|
+
type: "shared",
|
|
371
|
+
hash
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
// ../velix-pack/src/cache/fs-cache.ts
|
|
377
|
+
import fs4 from "fs";
|
|
378
|
+
import path6 from "path";
|
|
379
|
+
var FSCache = class {
|
|
380
|
+
cacheDir;
|
|
381
|
+
memoryCache = /* @__PURE__ */ new Map();
|
|
382
|
+
constructor(projectRoot) {
|
|
383
|
+
this.cacheDir = path6.join(projectRoot, ".velix", "cache", "pack");
|
|
384
|
+
this.ensureCacheDir();
|
|
385
|
+
}
|
|
386
|
+
ensureCacheDir() {
|
|
387
|
+
if (!fs4.existsSync(this.cacheDir)) {
|
|
388
|
+
fs4.mkdirSync(this.cacheDir, { recursive: true });
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
get(id, currentHash) {
|
|
392
|
+
const mem = this.memoryCache.get(id);
|
|
393
|
+
if (mem && mem.hash === currentHash) {
|
|
394
|
+
return mem;
|
|
395
|
+
}
|
|
396
|
+
const safeFilename = encodeURIComponent(id) + ".json";
|
|
397
|
+
const filePath = path6.join(this.cacheDir, safeFilename);
|
|
398
|
+
if (fs4.existsSync(filePath)) {
|
|
399
|
+
try {
|
|
400
|
+
const raw = fs4.readFileSync(filePath, "utf-8");
|
|
401
|
+
const entry = JSON.parse(raw);
|
|
402
|
+
if (entry.hash === currentHash) {
|
|
403
|
+
this.memoryCache.set(id, entry);
|
|
404
|
+
return entry;
|
|
405
|
+
}
|
|
406
|
+
} catch {
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
set(id, entry) {
|
|
412
|
+
this.memoryCache.set(id, entry);
|
|
413
|
+
const safeFilename = encodeURIComponent(id) + ".json";
|
|
414
|
+
const filePath = path6.join(this.cacheDir, safeFilename);
|
|
415
|
+
try {
|
|
416
|
+
this.ensureCacheDir();
|
|
417
|
+
fs4.writeFileSync(filePath, JSON.stringify(entry), "utf-8");
|
|
418
|
+
} catch {
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
invalidate(id) {
|
|
422
|
+
this.memoryCache.delete(id);
|
|
423
|
+
const safeFilename = encodeURIComponent(id) + ".json";
|
|
424
|
+
const filePath = path6.join(this.cacheDir, safeFilename);
|
|
425
|
+
if (fs4.existsSync(filePath)) {
|
|
426
|
+
try {
|
|
427
|
+
fs4.unlinkSync(filePath);
|
|
428
|
+
} catch {
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
clear() {
|
|
433
|
+
this.memoryCache.clear();
|
|
434
|
+
if (fs4.existsSync(this.cacheDir)) {
|
|
435
|
+
try {
|
|
436
|
+
fs4.rmSync(this.cacheDir, { recursive: true, force: true });
|
|
437
|
+
this.ensureCacheDir();
|
|
438
|
+
} catch {
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
// ../velix-pack/src/cache/index.ts
|
|
445
|
+
var CacheManager = class {
|
|
446
|
+
fsCache;
|
|
447
|
+
hits = 0;
|
|
448
|
+
misses = 0;
|
|
449
|
+
constructor(projectRoot) {
|
|
450
|
+
this.fsCache = new FSCache(projectRoot);
|
|
451
|
+
}
|
|
452
|
+
get(id, currentHash) {
|
|
453
|
+
const entry = this.fsCache.get(id, currentHash);
|
|
454
|
+
if (entry) {
|
|
455
|
+
this.hits++;
|
|
456
|
+
return entry;
|
|
457
|
+
}
|
|
458
|
+
this.misses++;
|
|
459
|
+
return null;
|
|
460
|
+
}
|
|
461
|
+
set(id, entry) {
|
|
462
|
+
this.fsCache.set(id, entry);
|
|
463
|
+
}
|
|
464
|
+
invalidate(id) {
|
|
465
|
+
this.fsCache.invalidate(id);
|
|
466
|
+
}
|
|
467
|
+
clear() {
|
|
468
|
+
this.fsCache.clear();
|
|
469
|
+
this.hits = 0;
|
|
470
|
+
this.misses = 0;
|
|
471
|
+
}
|
|
472
|
+
getStats() {
|
|
473
|
+
return {
|
|
474
|
+
hits: this.hits,
|
|
475
|
+
misses: this.misses,
|
|
476
|
+
hitRatio: this.hits + this.misses > 0 ? this.hits / (this.hits + this.misses) * 100 : 0
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
// ../velix-pack/src/bundler/index.ts
|
|
482
|
+
import esbuild2 from "esbuild";
|
|
483
|
+
import path7 from "path";
|
|
484
|
+
import fs5 from "fs";
|
|
485
|
+
|
|
486
|
+
// ../velix-pack/src/bundler/chunk.ts
|
|
487
|
+
var Chunk = class {
|
|
488
|
+
name;
|
|
489
|
+
isInitial;
|
|
490
|
+
type;
|
|
491
|
+
modules = /* @__PURE__ */ new Set();
|
|
492
|
+
size = 0;
|
|
493
|
+
constructor(options) {
|
|
494
|
+
this.name = options.name;
|
|
495
|
+
this.isInitial = options.isInitial ?? false;
|
|
496
|
+
this.type = options.type;
|
|
497
|
+
}
|
|
498
|
+
addModule(moduleId, moduleSize = 0) {
|
|
499
|
+
this.modules.add(moduleId);
|
|
500
|
+
this.size += moduleSize;
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
// ../velix-pack/src/bundler/code-splitter.ts
|
|
505
|
+
var CodeSplitter = class {
|
|
506
|
+
moduleGraph;
|
|
507
|
+
constructor(moduleGraph) {
|
|
508
|
+
this.moduleGraph = moduleGraph;
|
|
509
|
+
}
|
|
510
|
+
splitIntoChunks() {
|
|
511
|
+
const chunks = [];
|
|
512
|
+
const allModules = Array.from(this.moduleGraph.getAllModules().values());
|
|
513
|
+
const serverChunk = new Chunk({ name: "server-bundle", isInitial: true, type: "server" });
|
|
514
|
+
const clientInitialChunk = new Chunk({ name: "client-main", isInitial: true, type: "client" });
|
|
515
|
+
const routeChunksMap = /* @__PURE__ */ new Map();
|
|
516
|
+
for (const mod of allModules) {
|
|
517
|
+
const estimatedSize = mod.path.length * 10;
|
|
518
|
+
if (mod.type === "server") {
|
|
519
|
+
serverChunk.addModule(mod.id, estimatedSize);
|
|
520
|
+
} else {
|
|
521
|
+
const isRoute = (mod.id.includes("app/") || mod.id.includes("app\\")) && (mod.id.endsWith("page.tsx") || mod.id.endsWith("page.jsx"));
|
|
522
|
+
if (isRoute) {
|
|
523
|
+
const normalizedId = mod.id.replace(/\\/g, "/");
|
|
524
|
+
const routeName = normalizedId.replace(/^app\//, "").replace(/(?:^|\/)page\.[tj]sx?$/, "").replace(/[\/\\]/g, "_") || "home";
|
|
525
|
+
let chunk = routeChunksMap.get(routeName);
|
|
526
|
+
if (!chunk) {
|
|
527
|
+
chunk = new Chunk({ name: `route-${routeName}`, isInitial: false, type: "client" });
|
|
528
|
+
routeChunksMap.set(routeName, chunk);
|
|
529
|
+
}
|
|
530
|
+
chunk.addModule(mod.id, estimatedSize);
|
|
531
|
+
} else {
|
|
532
|
+
clientInitialChunk.addModule(mod.id, estimatedSize);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
chunks.push(serverChunk);
|
|
537
|
+
chunks.push(clientInitialChunk);
|
|
538
|
+
for (const routeChunk of routeChunksMap.values()) {
|
|
539
|
+
chunks.push(routeChunk);
|
|
540
|
+
}
|
|
541
|
+
return chunks;
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
// ../velix-pack/src/bundler/index.ts
|
|
546
|
+
var Bundler = class {
|
|
547
|
+
projectRoot;
|
|
548
|
+
outDir;
|
|
549
|
+
minify;
|
|
550
|
+
sourcemap;
|
|
551
|
+
constructor(options) {
|
|
552
|
+
this.projectRoot = options.projectRoot;
|
|
553
|
+
this.outDir = options.outDir;
|
|
554
|
+
this.minify = options.minify ?? false;
|
|
555
|
+
this.sourcemap = options.sourcemap ?? true;
|
|
556
|
+
}
|
|
557
|
+
async bundle(moduleGraph) {
|
|
558
|
+
const splitter = new CodeSplitter(moduleGraph);
|
|
559
|
+
const chunks = splitter.splitIntoChunks();
|
|
560
|
+
const entryFiles = Array.from(moduleGraph.getAllModules().values()).map((m) => m.path).filter((p) => fs5.existsSync(p));
|
|
561
|
+
if (entryFiles.length === 0) return chunks;
|
|
562
|
+
const serverOutDir = path7.join(this.outDir, "server");
|
|
563
|
+
const clientOutDir = path7.join(this.outDir, "client");
|
|
564
|
+
if (!fs5.existsSync(serverOutDir)) fs5.mkdirSync(serverOutDir, { recursive: true });
|
|
565
|
+
if (!fs5.existsSync(clientOutDir)) fs5.mkdirSync(clientOutDir, { recursive: true });
|
|
566
|
+
await esbuild2.build({
|
|
567
|
+
entryPoints: entryFiles,
|
|
568
|
+
outdir: serverOutDir,
|
|
569
|
+
bundle: false,
|
|
570
|
+
format: "esm",
|
|
571
|
+
platform: "node",
|
|
572
|
+
target: "es2022",
|
|
573
|
+
minify: this.minify,
|
|
574
|
+
sourcemap: this.sourcemap,
|
|
575
|
+
jsx: "automatic",
|
|
576
|
+
logLevel: "silent"
|
|
577
|
+
});
|
|
578
|
+
return chunks;
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
// ../velix-pack/src/watcher/index.ts
|
|
583
|
+
import chokidar from "chokidar";
|
|
584
|
+
import path8 from "path";
|
|
585
|
+
var FileWatcher = class {
|
|
586
|
+
watcher = null;
|
|
587
|
+
watchPaths;
|
|
588
|
+
constructor(watchPaths) {
|
|
589
|
+
this.watchPaths = watchPaths;
|
|
590
|
+
}
|
|
591
|
+
start(events) {
|
|
592
|
+
this.watcher = chokidar.watch(this.watchPaths, {
|
|
593
|
+
ignored: /(^|[\/\\])\..|node_modules|\.velix|dist/,
|
|
594
|
+
persistent: true,
|
|
595
|
+
ignoreInitial: true
|
|
596
|
+
});
|
|
597
|
+
this.watcher.on("change", (filePath) => events.onChange(path8.resolve(filePath)));
|
|
598
|
+
this.watcher.on("add", (filePath) => events.onAdd(path8.resolve(filePath)));
|
|
599
|
+
this.watcher.on("unlink", (filePath) => events.onUnlink(path8.resolve(filePath)));
|
|
600
|
+
}
|
|
601
|
+
close() {
|
|
602
|
+
if (this.watcher) {
|
|
603
|
+
this.watcher.close();
|
|
604
|
+
this.watcher = null;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
// ../velix-pack/src/hmr/index.ts
|
|
610
|
+
var HMRBridge = class {
|
|
611
|
+
broadcaster = null;
|
|
612
|
+
setBroadcaster(broadcaster) {
|
|
613
|
+
this.broadcaster = broadcaster;
|
|
614
|
+
}
|
|
615
|
+
notifyFileChanged(filePath, affectedModules) {
|
|
616
|
+
if (this.broadcaster) {
|
|
617
|
+
this.broadcaster({
|
|
618
|
+
type: "file-changed",
|
|
619
|
+
file: filePath,
|
|
620
|
+
affectedModules,
|
|
621
|
+
timestamp: Date.now()
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
notifyBoundaryError(error) {
|
|
626
|
+
if (this.broadcaster) {
|
|
627
|
+
this.broadcaster({
|
|
628
|
+
type: "boundary-error",
|
|
629
|
+
error,
|
|
630
|
+
timestamp: Date.now()
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
|
|
636
|
+
// ../velix-pack/src/analyzer/index.ts
|
|
637
|
+
import pc from "picocolors";
|
|
638
|
+
function formatBuildStats(stats) {
|
|
639
|
+
const lines = [];
|
|
640
|
+
lines.push(pc.bold(pc.green("VELIX PACK ANALYSIS")));
|
|
641
|
+
lines.push("");
|
|
642
|
+
lines.push(pc.bold("Build Stats"));
|
|
643
|
+
lines.push(pc.dim("\u2500\u2500\u2500\u2500\u2500"));
|
|
644
|
+
lines.push(`Time: ${pc.cyan((stats.duration / 1e3).toFixed(2) + "s")}`);
|
|
645
|
+
lines.push(`Modules: ${pc.yellow(stats.modulesCount.toString())}`);
|
|
646
|
+
lines.push(`Chunks: ${pc.cyan(stats.chunksCount.toString())}`);
|
|
647
|
+
lines.push(`Cache hit: ${pc.green(stats.cacheHits + " / " + (stats.cacheHits + stats.cacheMisses))}`);
|
|
648
|
+
lines.push("");
|
|
649
|
+
lines.push(pc.bold("Client"));
|
|
650
|
+
lines.push(pc.dim("\u2500\u2500\u2500\u2500\u2500\u2500"));
|
|
651
|
+
lines.push(`Modules: ${stats.clientModulesCount}`);
|
|
652
|
+
lines.push(`Initial JS: ${pc.cyan((stats.initialJsSize / 1024).toFixed(1) + " KB")}`);
|
|
653
|
+
lines.push(`Async JS: ${pc.cyan((stats.asyncJsSize / 1024).toFixed(1) + " KB")}`);
|
|
654
|
+
lines.push("");
|
|
655
|
+
lines.push(pc.bold("Server"));
|
|
656
|
+
lines.push(pc.dim("\u2500\u2500\u2500\u2500\u2500\u2500"));
|
|
657
|
+
lines.push(`Modules: ${stats.serverModulesCount}`);
|
|
658
|
+
return lines.join("\n");
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// ../velix-pack/src/index.ts
|
|
662
|
+
var VelixPack = class {
|
|
663
|
+
options;
|
|
664
|
+
resolver;
|
|
665
|
+
moduleGraph;
|
|
666
|
+
pipeline;
|
|
667
|
+
cache;
|
|
668
|
+
bundler;
|
|
669
|
+
watcher = null;
|
|
670
|
+
hmr = new HMRBridge();
|
|
671
|
+
stats = {
|
|
672
|
+
duration: 0,
|
|
673
|
+
modulesCount: 0,
|
|
674
|
+
chunksCount: 0,
|
|
675
|
+
cacheHits: 0,
|
|
676
|
+
cacheMisses: 0,
|
|
677
|
+
serverModulesCount: 0,
|
|
678
|
+
clientModulesCount: 0,
|
|
679
|
+
sharedModulesCount: 0,
|
|
680
|
+
initialJsSize: 0,
|
|
681
|
+
asyncJsSize: 0
|
|
682
|
+
};
|
|
683
|
+
constructor(options = {}) {
|
|
684
|
+
const projectRoot = options.projectRoot || process.cwd();
|
|
685
|
+
this.options = {
|
|
686
|
+
projectRoot,
|
|
687
|
+
appDir: options.appDir || path9.join(projectRoot, "app"),
|
|
688
|
+
outDir: options.outDir || path9.join(projectRoot, ".velix"),
|
|
689
|
+
mode: options.mode || "development",
|
|
690
|
+
minify: options.minify ?? false,
|
|
691
|
+
sourcemap: options.sourcemap ?? true
|
|
692
|
+
};
|
|
693
|
+
this.resolver = new Resolver({ projectRoot });
|
|
694
|
+
this.moduleGraph = new ModuleGraph(projectRoot);
|
|
695
|
+
this.pipeline = new TransformPipeline(this.resolver);
|
|
696
|
+
this.cache = new CacheManager(projectRoot);
|
|
697
|
+
this.bundler = new Bundler({
|
|
698
|
+
projectRoot,
|
|
699
|
+
outDir: this.options.outDir,
|
|
700
|
+
minify: this.options.minify,
|
|
701
|
+
sourcemap: this.options.sourcemap
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
async build() {
|
|
705
|
+
const startTime = Date.now();
|
|
706
|
+
const sourceFiles = this.findSourceFiles(this.options.appDir);
|
|
707
|
+
const serverFiles = fs6.existsSync(path9.join(this.options.projectRoot, "server")) ? this.findSourceFiles(path9.join(this.options.projectRoot, "server")) : [];
|
|
708
|
+
const allFiles = Array.from(/* @__PURE__ */ new Set([...sourceFiles, ...serverFiles]));
|
|
709
|
+
for (const filePath of allFiles) {
|
|
710
|
+
await this.processFile(filePath);
|
|
711
|
+
}
|
|
712
|
+
const violations = this.moduleGraph.checkBoundaries();
|
|
713
|
+
if (violations.length > 0) {
|
|
714
|
+
for (const v of violations) {
|
|
715
|
+
console.error(`ERROR [VELIX_PACK]
|
|
716
|
+
Server module imported from client module.
|
|
717
|
+
client: ${v.clientModule}
|
|
718
|
+
server: ${v.serverModule}
|
|
719
|
+
`);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
const chunks = await this.bundler.bundle(this.moduleGraph);
|
|
723
|
+
const cacheStats = this.cache.getStats();
|
|
724
|
+
const modules = Array.from(this.moduleGraph.getAllModules().values());
|
|
725
|
+
this.stats = {
|
|
726
|
+
duration: Date.now() - startTime,
|
|
727
|
+
modulesCount: modules.length,
|
|
728
|
+
chunksCount: chunks.length,
|
|
729
|
+
cacheHits: cacheStats.hits,
|
|
730
|
+
cacheMisses: cacheStats.misses,
|
|
731
|
+
serverModulesCount: modules.filter((m) => m.type === "server").length,
|
|
732
|
+
clientModulesCount: modules.filter((m) => m.type === "client").length,
|
|
733
|
+
sharedModulesCount: modules.filter((m) => m.type === "shared").length,
|
|
734
|
+
initialJsSize: chunks.filter((c) => c.isInitial).reduce((acc, c) => acc + c.size, 0),
|
|
735
|
+
asyncJsSize: chunks.filter((c) => !c.isInitial).reduce((acc, c) => acc + c.size, 0)
|
|
736
|
+
};
|
|
737
|
+
return this.stats;
|
|
738
|
+
}
|
|
739
|
+
watch(onRebuild) {
|
|
740
|
+
const serverDir = path9.join(this.options.projectRoot, "server");
|
|
741
|
+
const watchPaths = [this.options.appDir];
|
|
742
|
+
if (fs6.existsSync(serverDir)) watchPaths.push(serverDir);
|
|
743
|
+
this.watcher = new FileWatcher(watchPaths);
|
|
744
|
+
this.watcher.start({
|
|
745
|
+
onChange: async (filePath) => {
|
|
746
|
+
const affected = await this.rebuildIncremental(filePath);
|
|
747
|
+
this.hmr.notifyFileChanged(filePath, Array.from(affected));
|
|
748
|
+
if (onRebuild) onRebuild(Array.from(affected));
|
|
749
|
+
},
|
|
750
|
+
onAdd: async (filePath) => {
|
|
751
|
+
await this.processFile(filePath);
|
|
752
|
+
const affected = this.moduleGraph.getAffectedModules(filePath);
|
|
753
|
+
if (onRebuild) onRebuild(Array.from(affected));
|
|
754
|
+
},
|
|
755
|
+
onUnlink: (filePath) => {
|
|
756
|
+
const affected = this.moduleGraph.removeModule(filePath);
|
|
757
|
+
this.cache.invalidate(this.moduleGraph.toRelativeId(filePath));
|
|
758
|
+
if (onRebuild) onRebuild(Array.from(affected));
|
|
759
|
+
}
|
|
760
|
+
});
|
|
761
|
+
return this.watcher;
|
|
762
|
+
}
|
|
763
|
+
async rebuildIncremental(filePath) {
|
|
764
|
+
await this.processFile(filePath);
|
|
765
|
+
return this.moduleGraph.getAffectedModules(filePath);
|
|
766
|
+
}
|
|
767
|
+
async processFile(filePath) {
|
|
768
|
+
const relativeId = this.moduleGraph.toRelativeId(filePath);
|
|
769
|
+
const transformResult = await this.pipeline.transform(filePath);
|
|
770
|
+
let cached = this.cache.get(relativeId, transformResult.hash);
|
|
771
|
+
if (!cached) {
|
|
772
|
+
cached = {
|
|
773
|
+
hash: transformResult.hash,
|
|
774
|
+
code: transformResult.code,
|
|
775
|
+
imports: transformResult.imports,
|
|
776
|
+
type: transformResult.type,
|
|
777
|
+
timestamp: Date.now()
|
|
778
|
+
};
|
|
779
|
+
this.cache.set(relativeId, cached);
|
|
780
|
+
}
|
|
781
|
+
const mod = this.moduleGraph.addModule(filePath, transformResult.type);
|
|
782
|
+
mod.hash = transformResult.hash;
|
|
783
|
+
this.moduleGraph.updateDependencies(filePath, transformResult.imports);
|
|
784
|
+
for (const importPath of transformResult.imports) {
|
|
785
|
+
if (!this.moduleGraph.getModuleByPath(importPath)) {
|
|
786
|
+
if (fs6.existsSync(importPath)) {
|
|
787
|
+
await this.processFile(importPath);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
findSourceFiles(dir) {
|
|
793
|
+
const results = [];
|
|
794
|
+
if (!fs6.existsSync(dir)) return results;
|
|
795
|
+
const entries = fs6.readdirSync(dir, { withFileTypes: true });
|
|
796
|
+
for (const entry of entries) {
|
|
797
|
+
const fullPath = path9.join(dir, entry.name);
|
|
798
|
+
if (entry.isDirectory()) {
|
|
799
|
+
if (entry.name !== "node_modules" && entry.name !== ".velix" && entry.name !== "dist") {
|
|
800
|
+
results.push(...this.findSourceFiles(fullPath));
|
|
801
|
+
}
|
|
802
|
+
} else if (/\.(tsx?|jsx?)$/.test(entry.name)) {
|
|
803
|
+
results.push(fullPath);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
return results;
|
|
807
|
+
}
|
|
808
|
+
getHMR() {
|
|
809
|
+
return this.hmr;
|
|
810
|
+
}
|
|
811
|
+
getStats() {
|
|
812
|
+
return this.stats;
|
|
813
|
+
}
|
|
814
|
+
};
|
|
815
|
+
export {
|
|
816
|
+
CacheManager,
|
|
817
|
+
ModuleGraph,
|
|
818
|
+
Resolver,
|
|
819
|
+
VelixPack,
|
|
820
|
+
formatBuildStats
|
|
821
|
+
};
|
|
822
|
+
//# sourceMappingURL=src-BXA4CRFC.js.map
|