@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,144 @@
|
|
|
1
|
+
import { existsSync, statSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { relinka } from "@reliverse/relinka";
|
|
4
|
+
import { DEFAULT_DEBOUNCE_MS, DEFAULT_IGNORE_PATTERNS } from "./constants.js";
|
|
5
|
+
import { RebuildQueueProcessor } from "./utils/rebuild-queue.js";
|
|
6
|
+
export class FileWatcher {
|
|
7
|
+
watchers = /* @__PURE__ */ new Map();
|
|
8
|
+
rebuildQueue;
|
|
9
|
+
options;
|
|
10
|
+
packages;
|
|
11
|
+
constructor(packages, options) {
|
|
12
|
+
this.packages = packages;
|
|
13
|
+
this.options = {
|
|
14
|
+
debounceMs: options.debounceMs ?? DEFAULT_DEBOUNCE_MS,
|
|
15
|
+
ignorePatterns: options.ignorePatterns ?? [...DEFAULT_IGNORE_PATTERNS],
|
|
16
|
+
incremental: options.incremental ?? true,
|
|
17
|
+
...options
|
|
18
|
+
};
|
|
19
|
+
this.rebuildQueue = new RebuildQueueProcessor(packages, {
|
|
20
|
+
debounceMs: this.options.debounceMs,
|
|
21
|
+
incremental: this.options.incremental,
|
|
22
|
+
buildOptions: this.options
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async start() {
|
|
26
|
+
await relinka.info(
|
|
27
|
+
`\u{1F440} Starting file watcher for ${this.packages.length} packages...`
|
|
28
|
+
);
|
|
29
|
+
for (const pkg of this.packages) {
|
|
30
|
+
if (pkg.entryPoints.length === 0) continue;
|
|
31
|
+
await this.watchPackage(pkg);
|
|
32
|
+
}
|
|
33
|
+
await relinka.success("\u2705 File watching started");
|
|
34
|
+
}
|
|
35
|
+
async stop() {
|
|
36
|
+
for (const [path, watcher] of this.watchers) {
|
|
37
|
+
try {
|
|
38
|
+
watcher.close();
|
|
39
|
+
} catch (error) {
|
|
40
|
+
await relinka.warn(
|
|
41
|
+
`Failed to close watcher for ${path}: ${error instanceof Error ? error.message : String(error)}`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
this.watchers.clear();
|
|
46
|
+
this.rebuildQueue.clear();
|
|
47
|
+
await relinka.info("File watching stopped");
|
|
48
|
+
}
|
|
49
|
+
async watchPackage(pkg) {
|
|
50
|
+
for (const entryPoint of pkg.entryPoints) {
|
|
51
|
+
if (existsSync(entryPoint)) {
|
|
52
|
+
await this.watchFile(entryPoint, pkg);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const srcDir = join(pkg.path, "src");
|
|
56
|
+
if (existsSync(srcDir) && statSync(srcDir).isDirectory()) {
|
|
57
|
+
await this.watchDirectory(srcDir, pkg);
|
|
58
|
+
}
|
|
59
|
+
const packageJsonPath = join(pkg.path, "package.json");
|
|
60
|
+
if (existsSync(packageJsonPath)) {
|
|
61
|
+
await this.watchFile(packageJsonPath, pkg);
|
|
62
|
+
}
|
|
63
|
+
const tsconfigPath = join(pkg.path, "tsconfig.json");
|
|
64
|
+
if (existsSync(tsconfigPath)) {
|
|
65
|
+
await this.watchFile(tsconfigPath, pkg);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async watchFile(filePath, pkg) {
|
|
69
|
+
if (this.watchers.has(filePath)) return;
|
|
70
|
+
try {
|
|
71
|
+
const { watch } = await import("node:fs");
|
|
72
|
+
const watcher = watch(filePath, (eventType) => {
|
|
73
|
+
if (eventType === "change") {
|
|
74
|
+
this.handleFileChange(filePath, pkg);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
watcher.on("error", (error) => {
|
|
78
|
+
void relinka.warn(
|
|
79
|
+
`File watcher error for ${filePath}: ${error.message}`
|
|
80
|
+
);
|
|
81
|
+
this.watchers.delete(filePath);
|
|
82
|
+
});
|
|
83
|
+
this.watchers.set(filePath, watcher);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
void relinka.warn(`Failed to watch file ${filePath}: ${error}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async watchDirectory(dirPath, pkg) {
|
|
89
|
+
if (this.watchers.has(dirPath)) return;
|
|
90
|
+
try {
|
|
91
|
+
const { watch } = await import("node:fs");
|
|
92
|
+
const watcher = watch(
|
|
93
|
+
dirPath,
|
|
94
|
+
{ recursive: true },
|
|
95
|
+
(eventType, filename) => {
|
|
96
|
+
if (eventType === "change" && filename) {
|
|
97
|
+
const fullPath = join(dirPath, filename);
|
|
98
|
+
this.handleFileChange(fullPath, pkg);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
watcher.on("error", (error) => {
|
|
103
|
+
void relinka.warn(
|
|
104
|
+
`Directory watcher error for ${dirPath}: ${error.message}`
|
|
105
|
+
);
|
|
106
|
+
this.watchers.delete(dirPath);
|
|
107
|
+
});
|
|
108
|
+
this.watchers.set(dirPath, watcher);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
void relinka.warn(`Failed to watch directory ${dirPath}: ${error}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
handleFileChange(filePath, pkg) {
|
|
114
|
+
if (this.shouldIgnoreFile(filePath)) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
void relinka.info(`\u{1F4DD} File changed: ${filePath}`);
|
|
118
|
+
this.rebuildQueue.add(pkg.name);
|
|
119
|
+
}
|
|
120
|
+
shouldIgnoreFile(filePath) {
|
|
121
|
+
if (!this.options.ignorePatterns) return false;
|
|
122
|
+
for (const pattern of this.options.ignorePatterns) {
|
|
123
|
+
const regexPattern = pattern.replace(/\*\*/g, ".*").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]").replace(/\./g, "\\.");
|
|
124
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
|
125
|
+
if (regex.test(filePath) || regex.test(filePath.replace(/\\/g, "/"))) {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
export async function startWatchMode(packages, options) {
|
|
133
|
+
const watcher = new FileWatcher(packages, options);
|
|
134
|
+
const shutdown = async () => {
|
|
135
|
+
await relinka.info("\n\u{1F6D1} Shutting down watch mode...");
|
|
136
|
+
await watcher.stop();
|
|
137
|
+
process.exit(0);
|
|
138
|
+
};
|
|
139
|
+
process.on("SIGINT", shutdown);
|
|
140
|
+
process.on("SIGTERM", shutdown);
|
|
141
|
+
await watcher.start();
|
|
142
|
+
return new Promise(() => {
|
|
143
|
+
});
|
|
144
|
+
}
|
package/dist/mod.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BuildCache } from "./impl/cache.js";
|
|
2
|
+
import type { BuildOptions, BuildResult, BuildSummary, PackageInfo } from "./impl/types.js";
|
|
3
|
+
export type { GoBuildOptions } from "@reliverse/config/impl/build";
|
|
4
|
+
export type { PackageKind, RegistryType, } from "@reliverse/config/impl/publish";
|
|
5
|
+
export type { PreparePackageJsonOptions } from "@reliverse/typerso";
|
|
6
|
+
export { addBinFieldToPackageJson, extractPackageName, parseBinArgument, preparePackageJsonForPublishing, transformExportsForBuild, } from "@reliverse/typerso";
|
|
7
|
+
export type { DtsGeneratorOptions, DtsGeneratorResult, } from "./impl/dts-generator.js";
|
|
8
|
+
export { generateDeclarations } from "./impl/dts-generator.js";
|
|
9
|
+
export { buildGo } from "./impl/go-build.js";
|
|
10
|
+
export { applyPresets } from "./impl/presets.js";
|
|
11
|
+
export type { MkdistDtsOptions } from "./impl/providers/mkdist-dts.js";
|
|
12
|
+
export type { TSConfigValidationOptions, TSConfigValidationResult, } from "./impl/tsconfig-validator.js";
|
|
13
|
+
export { logValidationResults, validateAllTSConfigs, validateTSConfig, } from "./impl/tsconfig-validator.js";
|
|
14
|
+
export type { BuildOptions } from "./impl/types.js";
|
|
15
|
+
export { validateAndExit } from "./impl/validation.js";
|
|
16
|
+
export declare const buildPackage: (pkg: PackageInfo, options?: BuildOptions, cache?: BuildCache) => Promise<BuildResult>;
|
|
17
|
+
export declare const runBuildOnAllPackages: (ignore?: string | string[], cwd?: string, options?: BuildOptions) => Promise<BuildSummary>;
|