@reliverse/build 2.2.7
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/dist/impl/assets.d.ts +28 -0
- package/dist/impl/assets.js +188 -0
- package/dist/impl/cache.d.ts +25 -0
- package/dist/impl/cache.js +209 -0
- package/dist/impl/constants.d.ts +44 -0
- package/dist/impl/constants.js +45 -0
- package/dist/impl/debug.d.ts +30 -0
- package/dist/impl/debug.js +150 -0
- package/dist/impl/dependency-tracker.d.ts +23 -0
- package/dist/impl/dependency-tracker.js +113 -0
- package/dist/impl/dev-server.d.ts +24 -0
- package/dist/impl/dev-server.js +360 -0
- package/dist/impl/dts-generator.d.ts +26 -0
- package/dist/impl/dts-generator.js +514 -0
- package/dist/impl/go-build.d.ts +10 -0
- package/dist/impl/go-build.js +350 -0
- package/dist/impl/html-processor.d.ts +21 -0
- package/dist/impl/html-processor.js +167 -0
- package/dist/impl/impl.d.ts +0 -0
- package/dist/impl/impl.js +0 -0
- package/dist/impl/plugins/asset-optimization.d.ts +2 -0
- package/dist/impl/plugins/asset-optimization.js +114 -0
- package/dist/impl/plugins/bundle-analyzer.d.ts +2 -0
- package/dist/impl/plugins/bundle-analyzer.js +156 -0
- package/dist/impl/plugins/css-modules.d.ts +2 -0
- package/dist/impl/plugins/css-modules.js +19 -0
- package/dist/impl/plugins/index.d.ts +21 -0
- package/dist/impl/plugins/index.js +65 -0
- package/dist/impl/plugins/performance.d.ts +2 -0
- package/dist/impl/plugins/performance.js +62 -0
- package/dist/impl/plugins/react-refresh.d.ts +2 -0
- package/dist/impl/plugins/react-refresh.js +33 -0
- package/dist/impl/plugins/svg-as-react.d.ts +2 -0
- package/dist/impl/plugins/svg-as-react.js +18 -0
- package/dist/impl/plugins/typescript-declarations.d.ts +2 -0
- package/dist/impl/plugins/typescript-declarations.js +48 -0
- package/dist/impl/plugins/worker.d.ts +2 -0
- package/dist/impl/plugins/worker.js +20 -0
- package/dist/impl/presets.d.ts +10 -0
- package/dist/impl/presets.js +196 -0
- package/dist/impl/providers/mkdist/loader.d.ts +4 -0
- package/dist/impl/providers/mkdist/loader.js +26 -0
- package/dist/impl/providers/mkdist/loaders/js.d.ts +2 -0
- package/dist/impl/providers/mkdist/loaders/js.js +50 -0
- package/dist/impl/providers/mkdist/loaders/loaders-mod.d.ts +9 -0
- package/dist/impl/providers/mkdist/loaders/loaders-mod.js +22 -0
- package/dist/impl/providers/mkdist/make.d.ts +11 -0
- package/dist/impl/providers/mkdist/make.js +230 -0
- package/dist/impl/providers/mkdist/utils/dts.d.ts +11 -0
- package/dist/impl/providers/mkdist/utils/dts.js +117 -0
- package/dist/impl/providers/mkdist/utils/fs.d.ts +1 -0
- package/dist/impl/providers/mkdist/utils/fs.js +15 -0
- package/dist/impl/providers/mkdist-dts.d.ts +24 -0
- package/dist/impl/providers/mkdist-dts.js +8 -0
- package/dist/impl/tsconfig-validator.d.ts +35 -0
- package/dist/impl/tsconfig-validator.js +184 -0
- package/dist/impl/type-guards.d.ts +20 -0
- package/dist/impl/type-guards.js +147 -0
- package/dist/impl/types.d.ts +322 -0
- package/dist/impl/types.js +0 -0
- package/dist/impl/utils/go-build-handler.d.ts +12 -0
- package/dist/impl/utils/go-build-handler.js +83 -0
- package/dist/impl/utils/log-extraction.d.ts +25 -0
- package/dist/impl/utils/log-extraction.js +24 -0
- package/dist/impl/utils/package-filtering.d.ts +5 -0
- package/dist/impl/utils/package-filtering.js +22 -0
- package/dist/impl/utils/rebuild-queue.d.ts +38 -0
- package/dist/impl/utils/rebuild-queue.js +110 -0
- package/dist/impl/validation.d.ts +9 -0
- package/dist/impl/validation.js +332 -0
- package/dist/impl/watch.d.ts +21 -0
- package/dist/impl/watch.js +144 -0
- package/dist/mod.d.ts +17 -0
- package/dist/mod.js +1390 -0
- package/package.json +42 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AssetOptions, PackageInfo } from "./types.js";
|
|
2
|
+
export interface AssetProcessor {
|
|
3
|
+
processAssets(pkg: PackageInfo, outputDir: string, options?: AssetOptions): Promise<void>;
|
|
4
|
+
}
|
|
5
|
+
export declare class DefaultAssetProcessor implements AssetProcessor {
|
|
6
|
+
processAssets(pkg: PackageInfo, outputDir: string, options?: AssetOptions): Promise<void>;
|
|
7
|
+
private copyPublicAssets;
|
|
8
|
+
private copyAdditionalFiles;
|
|
9
|
+
private copyDirectory;
|
|
10
|
+
private optimizeImages;
|
|
11
|
+
}
|
|
12
|
+
export declare class CSSProcessor {
|
|
13
|
+
processCSS(_pkg: PackageInfo, outputDir: string, cssChunking?: boolean): Promise<void>;
|
|
14
|
+
private createCSSChunks;
|
|
15
|
+
private extractCommonPrefix;
|
|
16
|
+
private updateCSSReferences;
|
|
17
|
+
}
|
|
18
|
+
export declare class AssetManifest {
|
|
19
|
+
private manifest;
|
|
20
|
+
private reverseManifest;
|
|
21
|
+
addAsset(originalPath: string, hashedPath: string): void;
|
|
22
|
+
getAssetPath(originalPath: string): string;
|
|
23
|
+
getOriginalPath(hashedPath: string): string;
|
|
24
|
+
writeManifest(outputDir: string): Promise<void>;
|
|
25
|
+
loadManifest(outputDir: string): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
export declare function processAssetsForPackage(pkg: PackageInfo, outputDir: string, options?: AssetOptions): Promise<void>;
|
|
28
|
+
export declare function processCSSForPackage(pkg: PackageInfo, outputDir: string, cssChunking?: boolean): Promise<void>;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import {
|
|
2
|
+
copyFileSync,
|
|
3
|
+
existsSync,
|
|
4
|
+
mkdirSync,
|
|
5
|
+
readFileSync,
|
|
6
|
+
writeFileSync
|
|
7
|
+
} from "node:fs";
|
|
8
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
9
|
+
import { relinka } from "@reliverse/relinka";
|
|
10
|
+
export class DefaultAssetProcessor {
|
|
11
|
+
async processAssets(pkg, outputDir, options = {}) {
|
|
12
|
+
const {
|
|
13
|
+
publicPath = "/",
|
|
14
|
+
copyFiles = [],
|
|
15
|
+
imageOptimization = false
|
|
16
|
+
} = options;
|
|
17
|
+
if (pkg.hasPublicDir) {
|
|
18
|
+
await this.copyPublicAssets(pkg, outputDir, publicPath);
|
|
19
|
+
}
|
|
20
|
+
if (copyFiles.length > 0) {
|
|
21
|
+
await this.copyAdditionalFiles(pkg, outputDir, copyFiles, publicPath);
|
|
22
|
+
}
|
|
23
|
+
if (imageOptimization) {
|
|
24
|
+
await this.optimizeImages(pkg, outputDir);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async copyPublicAssets(pkg, outputDir, publicPath) {
|
|
28
|
+
const publicDir = join(pkg.path, "public");
|
|
29
|
+
if (!existsSync(publicDir)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const publicOutputDir = join(outputDir, publicPath.replace(/^\//, ""));
|
|
33
|
+
await this.copyDirectory(publicDir, publicOutputDir);
|
|
34
|
+
await relinka.info(`\u{1F4C1} Copied public assets to ${publicOutputDir}`);
|
|
35
|
+
}
|
|
36
|
+
async copyAdditionalFiles(pkg, outputDir, copyFiles, publicPath) {
|
|
37
|
+
for (const filePattern of copyFiles) {
|
|
38
|
+
const sourcePath = resolve(pkg.path, filePattern);
|
|
39
|
+
if (existsSync(sourcePath)) {
|
|
40
|
+
const fileName = basename(sourcePath);
|
|
41
|
+
const destPath = join(
|
|
42
|
+
outputDir,
|
|
43
|
+
publicPath.replace(/^\//, ""),
|
|
44
|
+
fileName
|
|
45
|
+
);
|
|
46
|
+
mkdirSync(dirname(destPath), { recursive: true });
|
|
47
|
+
copyFileSync(sourcePath, destPath);
|
|
48
|
+
await relinka.info(`\u{1F4C4} Copied ${filePattern} to ${destPath}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async copyDirectory(src, dest) {
|
|
53
|
+
if (!existsSync(dest)) {
|
|
54
|
+
mkdirSync(dest, { recursive: true });
|
|
55
|
+
}
|
|
56
|
+
const glob = new Bun.Glob("**/*");
|
|
57
|
+
const files = Array.from(glob.scanSync({ cwd: src, onlyFiles: true }));
|
|
58
|
+
for (const file of files) {
|
|
59
|
+
const srcPath = join(src, file);
|
|
60
|
+
const destPath = join(dest, file);
|
|
61
|
+
mkdirSync(dirname(destPath), { recursive: true });
|
|
62
|
+
copyFileSync(srcPath, destPath);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async optimizeImages(_pkg, _outputDir) {
|
|
66
|
+
await relinka.info("\u{1F5BC}\uFE0F Image optimization is not yet implemented");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export class CSSProcessor {
|
|
70
|
+
async processCSS(_pkg, outputDir, cssChunking = false) {
|
|
71
|
+
if (!cssChunking) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const glob = new Bun.Glob("**/*.css");
|
|
75
|
+
const cssFiles = Array.from(
|
|
76
|
+
glob.scanSync({ cwd: outputDir, onlyFiles: true })
|
|
77
|
+
);
|
|
78
|
+
if (cssFiles.length === 0) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
await relinka.info(
|
|
82
|
+
`\u{1F3A8} Processing ${cssFiles.length} CSS files for chunking`
|
|
83
|
+
);
|
|
84
|
+
try {
|
|
85
|
+
const cssContents = [];
|
|
86
|
+
for (const cssFile of cssFiles) {
|
|
87
|
+
const fullPath = join(outputDir, cssFile);
|
|
88
|
+
const content = readFileSync(fullPath, "utf-8");
|
|
89
|
+
cssContents.push({ file: cssFile, content });
|
|
90
|
+
}
|
|
91
|
+
const chunks = this.createCSSChunks(cssContents);
|
|
92
|
+
for (const [chunkName, content] of Object.entries(chunks)) {
|
|
93
|
+
const chunkPath = join(outputDir, `${chunkName}.css`);
|
|
94
|
+
writeFileSync(chunkPath, content, "utf-8");
|
|
95
|
+
await relinka.info(` \u{1F4C4} Created CSS chunk: ${chunkName}.css`);
|
|
96
|
+
}
|
|
97
|
+
await this.updateCSSReferences(cssFiles, chunks, outputDir);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
await relinka.warn(`CSS chunking failed: ${error}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
createCSSChunks(cssContents) {
|
|
103
|
+
const chunks = {};
|
|
104
|
+
const commonStyles = /* @__PURE__ */ new Map();
|
|
105
|
+
for (const { content } of cssContents) {
|
|
106
|
+
const lines = content.split("\n");
|
|
107
|
+
const commonPrefix = this.extractCommonPrefix(lines);
|
|
108
|
+
if (!commonStyles.has(commonPrefix)) {
|
|
109
|
+
commonStyles.set(commonPrefix, []);
|
|
110
|
+
}
|
|
111
|
+
commonStyles.get(commonPrefix)?.push(content);
|
|
112
|
+
}
|
|
113
|
+
let chunkIndex = 0;
|
|
114
|
+
for (const [prefix, styles] of commonStyles) {
|
|
115
|
+
const chunkName = prefix ? `chunk-${prefix}` : `chunk-${chunkIndex}`;
|
|
116
|
+
chunks[chunkName] = styles.join("\n\n");
|
|
117
|
+
chunkIndex++;
|
|
118
|
+
}
|
|
119
|
+
return chunks;
|
|
120
|
+
}
|
|
121
|
+
extractCommonPrefix(lines) {
|
|
122
|
+
const selectors = lines.filter(
|
|
123
|
+
(line) => line.trim().startsWith(".") || line.trim().startsWith("#")
|
|
124
|
+
).map((line) => line.trim().split(" ")[0]).filter(Boolean);
|
|
125
|
+
if (selectors.length === 0) return "";
|
|
126
|
+
const firstSelector = selectors[0];
|
|
127
|
+
if (!firstSelector) return "";
|
|
128
|
+
let commonPrefix = "";
|
|
129
|
+
for (let i = 0; i < firstSelector.length; i++) {
|
|
130
|
+
const char = firstSelector[i];
|
|
131
|
+
if (selectors.every((selector) => selector && selector[i] === char)) {
|
|
132
|
+
commonPrefix += char;
|
|
133
|
+
} else {
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return commonPrefix.replace(/[^a-zA-Z0-9-_]/g, "");
|
|
138
|
+
}
|
|
139
|
+
async updateCSSReferences(cssFiles, _chunks, _outputDir) {
|
|
140
|
+
await relinka.info(
|
|
141
|
+
` \u{1F4DD} Would update ${cssFiles.length} CSS files to reference chunks`
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export class AssetManifest {
|
|
146
|
+
manifest = {};
|
|
147
|
+
reverseManifest = {};
|
|
148
|
+
addAsset(originalPath, hashedPath) {
|
|
149
|
+
this.manifest[originalPath] = hashedPath;
|
|
150
|
+
this.reverseManifest[hashedPath] = originalPath;
|
|
151
|
+
}
|
|
152
|
+
getAssetPath(originalPath) {
|
|
153
|
+
return this.manifest[originalPath] || originalPath;
|
|
154
|
+
}
|
|
155
|
+
getOriginalPath(hashedPath) {
|
|
156
|
+
return this.reverseManifest[hashedPath] || hashedPath;
|
|
157
|
+
}
|
|
158
|
+
async writeManifest(outputDir) {
|
|
159
|
+
const manifestPath = join(outputDir, "asset-manifest.json");
|
|
160
|
+
const manifestData = {
|
|
161
|
+
files: this.manifest,
|
|
162
|
+
reverse: this.reverseManifest,
|
|
163
|
+
timestamp: Date.now()
|
|
164
|
+
};
|
|
165
|
+
writeFileSync(manifestPath, JSON.stringify(manifestData, null, 2));
|
|
166
|
+
await relinka.info(`\u{1F4CB} Asset manifest written to ${manifestPath}`);
|
|
167
|
+
}
|
|
168
|
+
async loadManifest(outputDir) {
|
|
169
|
+
const manifestPath = join(outputDir, "asset-manifest.json");
|
|
170
|
+
if (existsSync(manifestPath)) {
|
|
171
|
+
try {
|
|
172
|
+
const manifestData = JSON.parse(readFileSync(manifestPath, "utf-8"));
|
|
173
|
+
this.manifest = manifestData.files || {};
|
|
174
|
+
this.reverseManifest = manifestData.reverse || {};
|
|
175
|
+
} catch (error) {
|
|
176
|
+
await relinka.warn(`Failed to load asset manifest: ${error}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
export async function processAssetsForPackage(pkg, outputDir, options = {}) {
|
|
182
|
+
const processor = new DefaultAssetProcessor();
|
|
183
|
+
await processor.processAssets(pkg, outputDir, options);
|
|
184
|
+
}
|
|
185
|
+
export async function processCSSForPackage(pkg, outputDir, cssChunking = false) {
|
|
186
|
+
const processor = new CSSProcessor();
|
|
187
|
+
await processor.processCSS(pkg, outputDir, cssChunking);
|
|
188
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { BuildOptions, CacheEntry, CacheOptions, PackageInfo } from "./types.js";
|
|
2
|
+
export declare class BuildCache {
|
|
3
|
+
private options;
|
|
4
|
+
private dependencyTracker;
|
|
5
|
+
private hits;
|
|
6
|
+
private misses;
|
|
7
|
+
constructor(options?: Partial<CacheOptions>);
|
|
8
|
+
ensureCacheDirectory(): void;
|
|
9
|
+
private getCacheKey;
|
|
10
|
+
private getCacheFilePath;
|
|
11
|
+
private getSourceHash;
|
|
12
|
+
get(pkg: PackageInfo, options: BuildOptions): Promise<CacheEntry | null>;
|
|
13
|
+
set(pkg: PackageInfo, options: BuildOptions, result: {
|
|
14
|
+
buildTime: number;
|
|
15
|
+
bundleSize: number;
|
|
16
|
+
outputFiles: string[];
|
|
17
|
+
}): Promise<void>;
|
|
18
|
+
delete(key: string): void;
|
|
19
|
+
clear(): void;
|
|
20
|
+
getStats(): {
|
|
21
|
+
hits: number;
|
|
22
|
+
misses: number;
|
|
23
|
+
size: number;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { DependencyTracker } from "./dependency-tracker.js";
|
|
6
|
+
const DEFAULT_CACHE_DIR = join(".reliverse", "dler", "cache", "build");
|
|
7
|
+
const DEFAULT_TTL = 24 * 60 * 60 * 1e3;
|
|
8
|
+
export class BuildCache {
|
|
9
|
+
options;
|
|
10
|
+
dependencyTracker;
|
|
11
|
+
hits = 0;
|
|
12
|
+
misses = 0;
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
const homeDir = homedir();
|
|
15
|
+
const cacheDir = options.directory ?? join(homeDir, DEFAULT_CACHE_DIR);
|
|
16
|
+
this.options = {
|
|
17
|
+
enabled: options.enabled ?? true,
|
|
18
|
+
directory: cacheDir,
|
|
19
|
+
ttl: options.ttl ?? DEFAULT_TTL
|
|
20
|
+
};
|
|
21
|
+
this.dependencyTracker = new DependencyTracker();
|
|
22
|
+
if (this.options.enabled) {
|
|
23
|
+
this.ensureCacheDirectory();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
ensureCacheDirectory() {
|
|
27
|
+
if (existsSync(this.options.directory)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
mkdirSync(this.options.directory, { recursive: true });
|
|
31
|
+
}
|
|
32
|
+
getCacheKey(pkg, options) {
|
|
33
|
+
const buildConfig = {
|
|
34
|
+
entryPoints: pkg.entryPoints,
|
|
35
|
+
outputDir: pkg.outputDir,
|
|
36
|
+
target: options.target,
|
|
37
|
+
format: options.format,
|
|
38
|
+
minify: options.minify,
|
|
39
|
+
sourcemap: options.sourcemap,
|
|
40
|
+
splitting: options.splitting,
|
|
41
|
+
external: options.external,
|
|
42
|
+
bytecode: options.bytecode,
|
|
43
|
+
drop: options.drop,
|
|
44
|
+
packages: options.packages,
|
|
45
|
+
publicPath: options.publicPath,
|
|
46
|
+
root: options.root,
|
|
47
|
+
define: options.define,
|
|
48
|
+
naming: options.naming,
|
|
49
|
+
env: options.env,
|
|
50
|
+
banner: options.banner,
|
|
51
|
+
footer: options.footer,
|
|
52
|
+
conditions: options.conditions,
|
|
53
|
+
loader: options.loader,
|
|
54
|
+
ignoreDCEAnnotations: options.ignoreDCEAnnotations,
|
|
55
|
+
emitDCEAnnotations: options.emitDCEAnnotations
|
|
56
|
+
};
|
|
57
|
+
const configString = JSON.stringify(
|
|
58
|
+
buildConfig,
|
|
59
|
+
Object.keys(buildConfig).sort()
|
|
60
|
+
);
|
|
61
|
+
const configHash = createHash("sha256").update(configString).digest("hex");
|
|
62
|
+
const projectHash = createHash("sha256").update(pkg.path).digest("hex").substring(0, 8);
|
|
63
|
+
return `${pkg.name}-${projectHash}-${configHash}`;
|
|
64
|
+
}
|
|
65
|
+
getCacheFilePath(key) {
|
|
66
|
+
return join(this.options.directory, `${key}.json`);
|
|
67
|
+
}
|
|
68
|
+
async getSourceHash(pkg) {
|
|
69
|
+
const hashes = [];
|
|
70
|
+
await this.dependencyTracker.trackDependencies(pkg.entryPoints);
|
|
71
|
+
const graph = this.dependencyTracker.getGraph();
|
|
72
|
+
for (const filePath of Object.keys(graph)) {
|
|
73
|
+
const fileHash = this.dependencyTracker.getFileHash(filePath);
|
|
74
|
+
if (fileHash) {
|
|
75
|
+
hashes.push(fileHash);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const packageJsonPath = join(pkg.path, "package.json");
|
|
79
|
+
if (existsSync(packageJsonPath)) {
|
|
80
|
+
const content = readFileSync(packageJsonPath, "utf-8");
|
|
81
|
+
const hash = createHash("sha256").update(content).digest("hex");
|
|
82
|
+
hashes.push(hash);
|
|
83
|
+
}
|
|
84
|
+
const tsconfigPath = join(pkg.path, "tsconfig.json");
|
|
85
|
+
if (existsSync(tsconfigPath)) {
|
|
86
|
+
const content = readFileSync(tsconfigPath, "utf-8");
|
|
87
|
+
const hash = createHash("sha256").update(content).digest("hex");
|
|
88
|
+
hashes.push(hash);
|
|
89
|
+
}
|
|
90
|
+
return createHash("sha256").update(hashes.join("")).digest("hex");
|
|
91
|
+
}
|
|
92
|
+
async get(pkg, options) {
|
|
93
|
+
if (!this.options.enabled) {
|
|
94
|
+
this.misses++;
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const key = this.getCacheKey(pkg, options);
|
|
99
|
+
const cacheFilePath = this.getCacheFilePath(key);
|
|
100
|
+
if (!existsSync(cacheFilePath)) {
|
|
101
|
+
this.misses++;
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
const cacheData = JSON.parse(readFileSync(cacheFilePath, "utf-8"));
|
|
105
|
+
const entry = cacheData;
|
|
106
|
+
const now = Date.now();
|
|
107
|
+
if (now - entry.timestamp > this.options.ttl) {
|
|
108
|
+
this.delete(key);
|
|
109
|
+
this.misses++;
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
const currentSourceHash = await this.getSourceHash(pkg);
|
|
113
|
+
if (entry.hash !== currentSourceHash) {
|
|
114
|
+
this.delete(key);
|
|
115
|
+
this.misses++;
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
for (const outputFile of entry.outputFiles) {
|
|
119
|
+
if (!existsSync(outputFile)) {
|
|
120
|
+
this.delete(key);
|
|
121
|
+
this.misses++;
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
this.hits++;
|
|
126
|
+
return entry;
|
|
127
|
+
} catch (_error) {
|
|
128
|
+
this.misses++;
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async set(pkg, options, result) {
|
|
133
|
+
if (!this.options.enabled) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
const key = this.getCacheKey(pkg, options);
|
|
138
|
+
const sourceHash = await this.getSourceHash(pkg);
|
|
139
|
+
const entry = {
|
|
140
|
+
hash: sourceHash,
|
|
141
|
+
timestamp: Date.now(),
|
|
142
|
+
buildTime: result.buildTime,
|
|
143
|
+
bundleSize: result.bundleSize,
|
|
144
|
+
outputFiles: result.outputFiles
|
|
145
|
+
};
|
|
146
|
+
const cacheFilePath = this.getCacheFilePath(key);
|
|
147
|
+
writeFileSync(cacheFilePath, JSON.stringify(entry, null, 2));
|
|
148
|
+
} catch (_error) {
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
delete(key) {
|
|
152
|
+
if (!this.options.enabled) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
const cacheFilePath = this.getCacheFilePath(key);
|
|
157
|
+
if (existsSync(cacheFilePath)) {
|
|
158
|
+
const fs = require("node:fs");
|
|
159
|
+
fs.unlinkSync(cacheFilePath);
|
|
160
|
+
}
|
|
161
|
+
} catch (_error) {
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
clear() {
|
|
165
|
+
if (!this.options.enabled) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
const fs = require("node:fs");
|
|
170
|
+
const path = require("node:path");
|
|
171
|
+
if (existsSync(this.options.directory)) {
|
|
172
|
+
const files = fs.readdirSync(this.options.directory);
|
|
173
|
+
for (const file of files) {
|
|
174
|
+
if (file.endsWith(".json")) {
|
|
175
|
+
fs.unlinkSync(path.join(this.options.directory, file));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
} catch (_error) {
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
getStats() {
|
|
183
|
+
if (!this.options.enabled) {
|
|
184
|
+
return { hits: 0, misses: 0, size: 0 };
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
const fs = require("node:fs");
|
|
188
|
+
const path = require("node:path");
|
|
189
|
+
if (!existsSync(this.options.directory)) {
|
|
190
|
+
return { hits: this.hits, misses: this.misses, size: 0 };
|
|
191
|
+
}
|
|
192
|
+
const files = fs.readdirSync(this.options.directory);
|
|
193
|
+
const jsonFiles = files.filter((file) => file.endsWith(".json"));
|
|
194
|
+
let totalSize = 0;
|
|
195
|
+
for (const file of jsonFiles) {
|
|
196
|
+
const filePath = path.join(this.options.directory, file);
|
|
197
|
+
const stats = fs.statSync(filePath);
|
|
198
|
+
totalSize += stats.size;
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
hits: this.hits,
|
|
202
|
+
misses: this.misses,
|
|
203
|
+
size: totalSize
|
|
204
|
+
};
|
|
205
|
+
} catch (_error) {
|
|
206
|
+
return { hits: this.hits, misses: this.misses, size: 0 };
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default debounce time for file watching rebuilds (in milliseconds)
|
|
3
|
+
*/
|
|
4
|
+
export declare const DEFAULT_DEBOUNCE_MS = 300;
|
|
5
|
+
/**
|
|
6
|
+
* Default concurrency for parallel package builds
|
|
7
|
+
*/
|
|
8
|
+
export declare const DEFAULT_CONCURRENCY = 5;
|
|
9
|
+
/**
|
|
10
|
+
* Default dev server port
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_DEV_SERVER_PORT = 3000;
|
|
13
|
+
/**
|
|
14
|
+
* Default dev server host
|
|
15
|
+
*/
|
|
16
|
+
export declare const DEFAULT_DEV_SERVER_HOST = "localhost";
|
|
17
|
+
/**
|
|
18
|
+
* Always ignored packages (regardless of user configuration)
|
|
19
|
+
*/
|
|
20
|
+
export declare const ALWAYS_IGNORED_PACKAGES: string[];
|
|
21
|
+
/**
|
|
22
|
+
* Common frontend HTML file patterns
|
|
23
|
+
*/
|
|
24
|
+
export declare const FRONTEND_HTML_PATTERNS: readonly ["index.html", "public/index.html", "src/index.html", "app.html", "public/app.html"];
|
|
25
|
+
/**
|
|
26
|
+
* Common JavaScript/TypeScript entry point patterns
|
|
27
|
+
*/
|
|
28
|
+
export declare const JS_ENTRY_PATTERNS: readonly ["src/main.ts", "src/main.js", "src/index.ts", "src/index.js", "main.ts", "main.js", "index.ts", "index.js"];
|
|
29
|
+
/**
|
|
30
|
+
* Common library entry point patterns
|
|
31
|
+
*/
|
|
32
|
+
export declare const LIBRARY_ENTRY_PATTERNS: readonly ["src/index.ts", "src/mod.ts", "index.ts", "src/index.js", "src/mod.js", "index.js"];
|
|
33
|
+
/**
|
|
34
|
+
* Common Go project directories
|
|
35
|
+
*/
|
|
36
|
+
export declare const GO_PROJECT_DIRS: readonly ["cmd", "internal", "pkg", "prompts"];
|
|
37
|
+
/**
|
|
38
|
+
* Frontend framework package names
|
|
39
|
+
*/
|
|
40
|
+
export declare const FRONTEND_FRAMEWORKS: readonly ["react", "preact", "solid-js", "lit", "alpinejs"];
|
|
41
|
+
/**
|
|
42
|
+
* Default ignore patterns for file watching
|
|
43
|
+
*/
|
|
44
|
+
export declare const DEFAULT_IGNORE_PATTERNS: readonly ["node_modules/**", "dist/**", ".git/**", "**/*.log", "**/.DS_Store"];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export const DEFAULT_DEBOUNCE_MS = 300;
|
|
2
|
+
export const DEFAULT_CONCURRENCY = 5;
|
|
3
|
+
export const DEFAULT_DEV_SERVER_PORT = 3e3;
|
|
4
|
+
export const DEFAULT_DEV_SERVER_HOST = "localhost";
|
|
5
|
+
export const ALWAYS_IGNORED_PACKAGES = ["@reliverse/dler-v1"];
|
|
6
|
+
export const FRONTEND_HTML_PATTERNS = [
|
|
7
|
+
"index.html",
|
|
8
|
+
"public/index.html",
|
|
9
|
+
"src/index.html",
|
|
10
|
+
"app.html",
|
|
11
|
+
"public/app.html"
|
|
12
|
+
];
|
|
13
|
+
export const JS_ENTRY_PATTERNS = [
|
|
14
|
+
"src/main.ts",
|
|
15
|
+
"src/main.js",
|
|
16
|
+
"src/index.ts",
|
|
17
|
+
"src/index.js",
|
|
18
|
+
"main.ts",
|
|
19
|
+
"main.js",
|
|
20
|
+
"index.ts",
|
|
21
|
+
"index.js"
|
|
22
|
+
];
|
|
23
|
+
export const LIBRARY_ENTRY_PATTERNS = [
|
|
24
|
+
"src/index.ts",
|
|
25
|
+
"src/mod.ts",
|
|
26
|
+
"index.ts",
|
|
27
|
+
"src/index.js",
|
|
28
|
+
"src/mod.js",
|
|
29
|
+
"index.js"
|
|
30
|
+
];
|
|
31
|
+
export const GO_PROJECT_DIRS = ["cmd", "internal", "pkg", "prompts"];
|
|
32
|
+
export const FRONTEND_FRAMEWORKS = [
|
|
33
|
+
"react",
|
|
34
|
+
"preact",
|
|
35
|
+
"solid-js",
|
|
36
|
+
"lit",
|
|
37
|
+
"alpinejs"
|
|
38
|
+
];
|
|
39
|
+
export const DEFAULT_IGNORE_PATTERNS = [
|
|
40
|
+
"node_modules/**",
|
|
41
|
+
"dist/**",
|
|
42
|
+
".git/**",
|
|
43
|
+
"**/*.log",
|
|
44
|
+
"**/.DS_Store"
|
|
45
|
+
];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { BuildOptions, BuildResult, BuildSummary, PackageInfo } from "./types.js";
|
|
2
|
+
export interface DebugInfo {
|
|
3
|
+
configSource: "cli" | "reliverse" | "default";
|
|
4
|
+
configPath?: string;
|
|
5
|
+
resolvedOptions: BuildOptions;
|
|
6
|
+
packageCount: number;
|
|
7
|
+
entryPoints: string[];
|
|
8
|
+
buildTime: number;
|
|
9
|
+
bundleSize: number;
|
|
10
|
+
cacheHits: number;
|
|
11
|
+
errors: string[];
|
|
12
|
+
warnings: string[];
|
|
13
|
+
}
|
|
14
|
+
export declare class DebugLogger {
|
|
15
|
+
private enabled;
|
|
16
|
+
private startTime;
|
|
17
|
+
constructor(enabled?: boolean);
|
|
18
|
+
start(): void;
|
|
19
|
+
logConfigResolution(pkg: PackageInfo, configSource: string, configPath?: string): void;
|
|
20
|
+
logBuildOptions(options: BuildOptions, pkg: PackageInfo): void;
|
|
21
|
+
logEntryPoints(pkg: PackageInfo): void;
|
|
22
|
+
logBuildStats(summary: BuildSummary): void;
|
|
23
|
+
logPackageResult(result: BuildResult): void;
|
|
24
|
+
logDependencyGraph(pkg: PackageInfo, dependencies: string[]): void;
|
|
25
|
+
logCacheInfo(pkg: PackageInfo, cacheHit: boolean, cacheKey?: string): void;
|
|
26
|
+
logFileWatching(pkg: PackageInfo, watchedFiles: string[]): void;
|
|
27
|
+
logAssetProcessing(pkg: PackageInfo, assets: string[]): void;
|
|
28
|
+
logError(error: Error, context?: string): void;
|
|
29
|
+
}
|
|
30
|
+
export declare function createDebugLogger(options: BuildOptions): DebugLogger;
|