@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.
Files changed (75) hide show
  1. package/dist/impl/assets.d.ts +28 -0
  2. package/dist/impl/assets.js +188 -0
  3. package/dist/impl/cache.d.ts +25 -0
  4. package/dist/impl/cache.js +209 -0
  5. package/dist/impl/constants.d.ts +44 -0
  6. package/dist/impl/constants.js +45 -0
  7. package/dist/impl/debug.d.ts +30 -0
  8. package/dist/impl/debug.js +150 -0
  9. package/dist/impl/dependency-tracker.d.ts +23 -0
  10. package/dist/impl/dependency-tracker.js +113 -0
  11. package/dist/impl/dev-server.d.ts +24 -0
  12. package/dist/impl/dev-server.js +360 -0
  13. package/dist/impl/dts-generator.d.ts +26 -0
  14. package/dist/impl/dts-generator.js +514 -0
  15. package/dist/impl/go-build.d.ts +10 -0
  16. package/dist/impl/go-build.js +350 -0
  17. package/dist/impl/html-processor.d.ts +21 -0
  18. package/dist/impl/html-processor.js +167 -0
  19. package/dist/impl/impl.d.ts +0 -0
  20. package/dist/impl/impl.js +0 -0
  21. package/dist/impl/plugins/asset-optimization.d.ts +2 -0
  22. package/dist/impl/plugins/asset-optimization.js +114 -0
  23. package/dist/impl/plugins/bundle-analyzer.d.ts +2 -0
  24. package/dist/impl/plugins/bundle-analyzer.js +156 -0
  25. package/dist/impl/plugins/css-modules.d.ts +2 -0
  26. package/dist/impl/plugins/css-modules.js +19 -0
  27. package/dist/impl/plugins/index.d.ts +21 -0
  28. package/dist/impl/plugins/index.js +65 -0
  29. package/dist/impl/plugins/performance.d.ts +2 -0
  30. package/dist/impl/plugins/performance.js +62 -0
  31. package/dist/impl/plugins/react-refresh.d.ts +2 -0
  32. package/dist/impl/plugins/react-refresh.js +33 -0
  33. package/dist/impl/plugins/svg-as-react.d.ts +2 -0
  34. package/dist/impl/plugins/svg-as-react.js +18 -0
  35. package/dist/impl/plugins/typescript-declarations.d.ts +2 -0
  36. package/dist/impl/plugins/typescript-declarations.js +48 -0
  37. package/dist/impl/plugins/worker.d.ts +2 -0
  38. package/dist/impl/plugins/worker.js +20 -0
  39. package/dist/impl/presets.d.ts +10 -0
  40. package/dist/impl/presets.js +196 -0
  41. package/dist/impl/providers/mkdist/loader.d.ts +4 -0
  42. package/dist/impl/providers/mkdist/loader.js +26 -0
  43. package/dist/impl/providers/mkdist/loaders/js.d.ts +2 -0
  44. package/dist/impl/providers/mkdist/loaders/js.js +50 -0
  45. package/dist/impl/providers/mkdist/loaders/loaders-mod.d.ts +9 -0
  46. package/dist/impl/providers/mkdist/loaders/loaders-mod.js +22 -0
  47. package/dist/impl/providers/mkdist/make.d.ts +11 -0
  48. package/dist/impl/providers/mkdist/make.js +230 -0
  49. package/dist/impl/providers/mkdist/utils/dts.d.ts +11 -0
  50. package/dist/impl/providers/mkdist/utils/dts.js +117 -0
  51. package/dist/impl/providers/mkdist/utils/fs.d.ts +1 -0
  52. package/dist/impl/providers/mkdist/utils/fs.js +15 -0
  53. package/dist/impl/providers/mkdist-dts.d.ts +24 -0
  54. package/dist/impl/providers/mkdist-dts.js +8 -0
  55. package/dist/impl/tsconfig-validator.d.ts +35 -0
  56. package/dist/impl/tsconfig-validator.js +184 -0
  57. package/dist/impl/type-guards.d.ts +20 -0
  58. package/dist/impl/type-guards.js +147 -0
  59. package/dist/impl/types.d.ts +322 -0
  60. package/dist/impl/types.js +0 -0
  61. package/dist/impl/utils/go-build-handler.d.ts +12 -0
  62. package/dist/impl/utils/go-build-handler.js +83 -0
  63. package/dist/impl/utils/log-extraction.d.ts +25 -0
  64. package/dist/impl/utils/log-extraction.js +24 -0
  65. package/dist/impl/utils/package-filtering.d.ts +5 -0
  66. package/dist/impl/utils/package-filtering.js +22 -0
  67. package/dist/impl/utils/rebuild-queue.d.ts +38 -0
  68. package/dist/impl/utils/rebuild-queue.js +110 -0
  69. package/dist/impl/validation.d.ts +9 -0
  70. package/dist/impl/validation.js +332 -0
  71. package/dist/impl/watch.d.ts +21 -0
  72. package/dist/impl/watch.js +144 -0
  73. package/dist/mod.d.ts +17 -0
  74. package/dist/mod.js +1390 -0
  75. package/package.json +42 -0
@@ -0,0 +1,156 @@
1
+ import { existsSync, statSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { logger } from "@reliverse/relinka";
4
+ export const BundleAnalyzerPlugin = {
5
+ name: "bundle-analyzer",
6
+ setup: (buildConfig) => {
7
+ if (buildConfig?.verbose) {
8
+ logger.debug("Bundle analyzer plugin registered");
9
+ }
10
+ },
11
+ onBuildEnd: async (result) => {
12
+ if (!result.success || result.skipped) {
13
+ return;
14
+ }
15
+ try {
16
+ await analyzeBundle(result);
17
+ } catch (error) {
18
+ logger.warn(
19
+ `Failed to analyze bundle for ${result.package.name}: ${error}`
20
+ );
21
+ }
22
+ }
23
+ };
24
+ async function analyzeBundle(result) {
25
+ const pkg = result.package;
26
+ const outputDir = pkg.outputDir;
27
+ if (!existsSync(outputDir)) {
28
+ return;
29
+ }
30
+ const glob = new Bun.Glob("**/*");
31
+ const files = Array.from(glob.scanSync({ cwd: outputDir, onlyFiles: true }));
32
+ const analysis = {
33
+ package: pkg.name,
34
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
35
+ files: [],
36
+ totals: {
37
+ totalSize: 0,
38
+ totalFiles: 0,
39
+ jsFiles: 0,
40
+ cssFiles: 0,
41
+ assetFiles: 0
42
+ },
43
+ recommendations: []
44
+ };
45
+ for (const file of files) {
46
+ const filePath = join(outputDir, file);
47
+ const stats = statSync(filePath);
48
+ const ext = file.split(".").pop()?.toLowerCase() || "";
49
+ const fileInfo = {
50
+ name: file,
51
+ size: stats.size,
52
+ type: getFileType(ext)
53
+ };
54
+ analysis.files.push(fileInfo);
55
+ analysis.totals.totalSize += stats.size;
56
+ analysis.totals.totalFiles++;
57
+ if (ext === "js" || ext === "mjs") {
58
+ analysis.totals.jsFiles++;
59
+ } else if (ext === "css") {
60
+ analysis.totals.cssFiles++;
61
+ } else {
62
+ analysis.totals.assetFiles++;
63
+ }
64
+ }
65
+ analysis.files.sort((a, b) => b.size - a.size);
66
+ generateRecommendations(analysis);
67
+ const reportPath = join(outputDir, "bundle-analysis.json");
68
+ writeFileSync(reportPath, JSON.stringify(analysis, null, 2));
69
+ logger.info(`\u{1F4CA} Bundle analysis for ${pkg.name}:`);
70
+ logger.info(` Total size: ${formatBytes(analysis.totals.totalSize)}`);
71
+ logger.info(
72
+ ` Files: ${analysis.totals.totalFiles} (${analysis.totals.jsFiles} JS, ${analysis.totals.cssFiles} CSS, ${analysis.totals.assetFiles} assets)`
73
+ );
74
+ if (analysis.files.length > 0) {
75
+ const largestFile = analysis.files[0];
76
+ if (largestFile) {
77
+ logger.info(
78
+ ` Largest file: ${largestFile.name} (${formatBytes(largestFile.size)})`
79
+ );
80
+ }
81
+ }
82
+ if (analysis.recommendations.length > 0) {
83
+ logger.info(` Recommendations:`);
84
+ for (const rec of analysis.recommendations) {
85
+ logger.info(` \u2022 ${rec}`);
86
+ }
87
+ }
88
+ logger.info(` Report saved to: ${reportPath}`);
89
+ }
90
+ function getFileType(ext) {
91
+ const typeMap = {
92
+ js: "JavaScript",
93
+ mjs: "JavaScript (ESM)",
94
+ css: "CSS",
95
+ png: "Image (PNG)",
96
+ jpg: "Image (JPEG)",
97
+ jpeg: "Image (JPEG)",
98
+ gif: "Image (GIF)",
99
+ svg: "Image (SVG)",
100
+ webp: "Image (WebP)",
101
+ woff: "Font (WOFF)",
102
+ woff2: "Font (WOFF2)",
103
+ ttf: "Font (TTF)",
104
+ eot: "Font (EOT)",
105
+ html: "HTML",
106
+ json: "JSON",
107
+ txt: "Text"
108
+ };
109
+ return typeMap[ext] || "Unknown";
110
+ }
111
+ function generateRecommendations(analysis) {
112
+ const { totals, files } = analysis;
113
+ if (totals.totalSize > 1024 * 1024) {
114
+ analysis.recommendations.push(
115
+ "Bundle size is large (>1MB). Consider code splitting or removing unused code."
116
+ );
117
+ }
118
+ const largeFiles = files.filter((f) => f.size > 500 * 1024);
119
+ if (largeFiles.length > 0) {
120
+ analysis.recommendations.push(
121
+ `Large files detected: ${largeFiles.map((f) => f.name).join(", ")}. Consider optimizing or splitting.`
122
+ );
123
+ }
124
+ if (totals.totalFiles > 50) {
125
+ analysis.recommendations.push(
126
+ "Many files in bundle. Consider consolidating or using code splitting."
127
+ );
128
+ }
129
+ if (totals.jsFiles > 0 && totals.cssFiles > 0) {
130
+ const jsSize = files.filter((f) => f.type.includes("JavaScript")).reduce((sum, f) => sum + f.size, 0);
131
+ const cssSize = files.filter((f) => f.type.includes("CSS")).reduce((sum, f) => sum + f.size, 0);
132
+ if (cssSize > jsSize) {
133
+ analysis.recommendations.push(
134
+ "CSS is larger than JavaScript. Consider CSS optimization or purging unused styles."
135
+ );
136
+ }
137
+ }
138
+ const fileTypes = /* @__PURE__ */ new Map();
139
+ files.forEach((f) => {
140
+ fileTypes.set(f.type, (fileTypes.get(f.type) || 0) + 1);
141
+ });
142
+ for (const [type, count] of fileTypes) {
143
+ if (count > 10) {
144
+ analysis.recommendations.push(
145
+ `Many ${type} files (${count}). Consider consolidating.`
146
+ );
147
+ }
148
+ }
149
+ }
150
+ function formatBytes(bytes) {
151
+ if (bytes === 0) return "0 B";
152
+ const k = 1024;
153
+ const sizes = ["B", "KB", "MB", "GB"];
154
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
155
+ return `${parseFloat((bytes / k ** i).toFixed(1))} ${sizes[i]}`;
156
+ }
@@ -0,0 +1,2 @@
1
+ import type { DlerPlugin } from "../types.js";
2
+ export declare const CSSModulesPlugin: DlerPlugin;
@@ -0,0 +1,19 @@
1
+ import { logger } from "@reliverse/relinka";
2
+ export const CSSModulesPlugin = {
3
+ name: "css-modules",
4
+ setup: (buildConfig) => {
5
+ buildConfig.loader = {
6
+ ...buildConfig.loader,
7
+ ".module.css": "file",
8
+ ".module.less": "file",
9
+ ".module.styl": "file"
10
+ };
11
+ if (!buildConfig.define) {
12
+ buildConfig.define = {};
13
+ }
14
+ buildConfig.define.__CSS_MODULES__ = "true";
15
+ if (buildConfig.verbose) {
16
+ logger.debug("CSS modules plugin applied");
17
+ }
18
+ }
19
+ };
@@ -0,0 +1,21 @@
1
+ import type { BunBuildConfig, DlerPlugin } from "../types.js";
2
+ export declare class PluginRegistry {
3
+ private plugins;
4
+ register(plugin: DlerPlugin, verbose?: boolean): void;
5
+ getPlugin(name: string): DlerPlugin | undefined;
6
+ getAllPlugins(): DlerPlugin[];
7
+ hasPlugin(name: string): boolean;
8
+ clear(): void;
9
+ }
10
+ export declare const pluginRegistry: PluginRegistry;
11
+ export { AssetOptimizationPlugin } from "./asset-optimization.js";
12
+ export { BundleAnalyzerPlugin } from "./bundle-analyzer.js";
13
+ export { CSSModulesPlugin } from "./css-modules.js";
14
+ export { PerformancePlugin } from "./performance.js";
15
+ export { ReactRefreshPlugin } from "./react-refresh.js";
16
+ export { SVGAsReactPlugin } from "./svg-as-react.js";
17
+ export { TypeScriptDeclarationsPlugin } from "./typescript-declarations.js";
18
+ export { WorkerPlugin } from "./worker.js";
19
+ export declare function createPlugin(name: string, setup: (build: BunBuildConfig) => void): DlerPlugin;
20
+ export declare function loadPlugins(pluginNames: string[]): DlerPlugin[];
21
+ export declare function applyPlugins(plugins: DlerPlugin[], buildConfig: BunBuildConfig): void;
@@ -0,0 +1,65 @@
1
+ import { logger } from "@reliverse/relinka";
2
+ export class PluginRegistry {
3
+ plugins = /* @__PURE__ */ new Map();
4
+ register(plugin, verbose) {
5
+ if (this.plugins.has(plugin.name)) {
6
+ logger.warn(`Plugin ${plugin.name} is already registered`);
7
+ return;
8
+ }
9
+ this.plugins.set(plugin.name, plugin);
10
+ if (verbose) {
11
+ logger.debug(`Registered plugin: ${plugin.name}`);
12
+ }
13
+ }
14
+ getPlugin(name) {
15
+ return this.plugins.get(name);
16
+ }
17
+ getAllPlugins() {
18
+ return Array.from(this.plugins.values());
19
+ }
20
+ hasPlugin(name) {
21
+ return this.plugins.has(name);
22
+ }
23
+ clear() {
24
+ this.plugins.clear();
25
+ }
26
+ }
27
+ export const pluginRegistry = new PluginRegistry();
28
+ export { AssetOptimizationPlugin } from "./asset-optimization.js";
29
+ export { BundleAnalyzerPlugin } from "./bundle-analyzer.js";
30
+ export { CSSModulesPlugin } from "./css-modules.js";
31
+ export { PerformancePlugin } from "./performance.js";
32
+ export { ReactRefreshPlugin } from "./react-refresh.js";
33
+ export { SVGAsReactPlugin } from "./svg-as-react.js";
34
+ export { TypeScriptDeclarationsPlugin } from "./typescript-declarations.js";
35
+ export { WorkerPlugin } from "./worker.js";
36
+ export function createPlugin(name, setup) {
37
+ return {
38
+ name,
39
+ setup
40
+ };
41
+ }
42
+ export function loadPlugins(pluginNames) {
43
+ const plugins = [];
44
+ for (const name of pluginNames) {
45
+ const plugin = pluginRegistry.getPlugin(name);
46
+ if (plugin) {
47
+ plugins.push(plugin);
48
+ } else {
49
+ logger.warn(`Plugin ${name} not found in registry`);
50
+ }
51
+ }
52
+ return plugins;
53
+ }
54
+ export function applyPlugins(plugins, buildConfig) {
55
+ for (const plugin of plugins) {
56
+ try {
57
+ plugin.setup(buildConfig);
58
+ if (buildConfig.verbose) {
59
+ logger.debug(`Applied plugin: ${plugin.name}`);
60
+ }
61
+ } catch (error) {
62
+ logger.error(`Failed to apply plugin ${plugin.name}: ${error}`);
63
+ }
64
+ }
65
+ }
@@ -0,0 +1,2 @@
1
+ import type { DlerPlugin } from "../types.js";
2
+ export declare const PerformancePlugin: DlerPlugin;
@@ -0,0 +1,62 @@
1
+ import { logger } from "@reliverse/relinka";
2
+ export const PerformancePlugin = {
3
+ name: "performance",
4
+ setup: (buildConfig) => {
5
+ if (buildConfig?.verbose) {
6
+ logger.debug("Performance monitoring plugin registered");
7
+ }
8
+ },
9
+ onBuildEnd: async (result) => {
10
+ if (!result.success || result.skipped) {
11
+ return;
12
+ }
13
+ try {
14
+ await checkPerformanceBudgets(result);
15
+ } catch (error) {
16
+ logger.warn(
17
+ `Failed to check performance budgets for ${result.package.name}: ${error}`
18
+ );
19
+ }
20
+ }
21
+ };
22
+ async function checkPerformanceBudgets(result) {
23
+ const pkg = result.package;
24
+ const budget = pkg.buildConfig?.performanceBudget;
25
+ if (!budget) {
26
+ return;
27
+ }
28
+ const bundleSize = result.bundleSize || 0;
29
+ const warnings = [];
30
+ if (budget.maxBundleSize && bundleSize > budget.maxBundleSize) {
31
+ warnings.push(
32
+ `Bundle size ${formatBytes(bundleSize)} exceeds limit of ${formatBytes(budget.maxBundleSize)}`
33
+ );
34
+ }
35
+ if (budget.maxChunkSize && bundleSize > budget.maxChunkSize) {
36
+ warnings.push(
37
+ `Chunk size ${formatBytes(bundleSize)} exceeds limit of ${formatBytes(budget.maxChunkSize)}`
38
+ );
39
+ }
40
+ if (budget.maxAssetSize && bundleSize > budget.maxAssetSize) {
41
+ warnings.push(
42
+ `Asset size ${formatBytes(bundleSize)} exceeds limit of ${formatBytes(budget.maxAssetSize)}`
43
+ );
44
+ }
45
+ if (warnings.length > 0) {
46
+ logger.warn(`\u26A0\uFE0F Performance budget exceeded for ${pkg.name}:`);
47
+ for (const warning of warnings) {
48
+ logger.warn(` ${warning}`);
49
+ }
50
+ } else {
51
+ logger.info(
52
+ `\u2705 Performance budget met for ${pkg.name} (${formatBytes(bundleSize)})`
53
+ );
54
+ }
55
+ }
56
+ function formatBytes(bytes) {
57
+ if (bytes === 0) return "0 B";
58
+ const k = 1024;
59
+ const sizes = ["B", "KB", "MB", "GB"];
60
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
61
+ return `${parseFloat((bytes / k ** i).toFixed(1))} ${sizes[i]}`;
62
+ }
@@ -0,0 +1,2 @@
1
+ import type { DlerPlugin } from "../types.js";
2
+ export declare const ReactRefreshPlugin: DlerPlugin;
@@ -0,0 +1,33 @@
1
+ import { logger } from "@reliverse/relinka";
2
+ export const ReactRefreshPlugin = {
3
+ name: "react-refresh",
4
+ setup: (buildConfig) => {
5
+ buildConfig.reactFastRefresh = true;
6
+ const refreshRuntime = `
7
+ if (typeof window !== 'undefined' && process.env.NODE_ENV === 'development') {
8
+ const refreshRuntime = {
9
+ performReactRefresh: () => {
10
+ if (window.__REACT_DEVTOOLS_GLOBAL_HOOK__?.onCommitFiberRoot) {
11
+ window.__REACT_DEVTOOLS_GLOBAL_HOOK__.onCommitFiberRoot();
12
+ }
13
+ }
14
+ };
15
+ window.__REACT_REFRESH_RUNTIME__ = refreshRuntime;
16
+ }`;
17
+ if (buildConfig.banner) {
18
+ buildConfig.banner = `${refreshRuntime}
19
+ ${buildConfig.banner}`;
20
+ } else {
21
+ buildConfig.banner = refreshRuntime;
22
+ }
23
+ if (!buildConfig.jsx) {
24
+ buildConfig.jsx = {
25
+ runtime: "automatic",
26
+ importSource: "react"
27
+ };
28
+ }
29
+ if (buildConfig.verbose) {
30
+ logger.debug("React Fast Refresh plugin applied");
31
+ }
32
+ }
33
+ };
@@ -0,0 +1,2 @@
1
+ import type { DlerPlugin } from "../types.js";
2
+ export declare const SVGAsReactPlugin: DlerPlugin;
@@ -0,0 +1,18 @@
1
+ import { logger } from "@reliverse/relinka";
2
+ export const SVGAsReactPlugin = {
3
+ name: "svg-as-react",
4
+ setup: (buildConfig) => {
5
+ buildConfig.loader = {
6
+ ...buildConfig.loader,
7
+ ".svg": "jsx"
8
+ // Use JSX loader for SVG files
9
+ };
10
+ if (!buildConfig.define) {
11
+ buildConfig.define = {};
12
+ }
13
+ buildConfig.define.__SVG_AS_REACT__ = "true";
14
+ if (buildConfig.verbose) {
15
+ logger.debug("SVG as React plugin applied");
16
+ }
17
+ }
18
+ };
@@ -0,0 +1,2 @@
1
+ import type { DlerPlugin } from "../types.js";
2
+ export declare const TypeScriptDeclarationsPlugin: DlerPlugin;
@@ -0,0 +1,48 @@
1
+ import { logger } from "@reliverse/relinka";
2
+ import { generateDeclarations } from "../dts-generator.js";
3
+ export const TypeScriptDeclarationsPlugin = {
4
+ name: "typescript-declarations",
5
+ setup: (buildConfig) => {
6
+ if (buildConfig?.verbose) {
7
+ logger.debug("TypeScript declarations plugin registered");
8
+ }
9
+ },
10
+ onBuildEnd: async (result, buildOptions) => {
11
+ if (!result.success || result.skipped) {
12
+ return;
13
+ }
14
+ const pkg = result.package;
15
+ if (pkg.isFrontendApp) {
16
+ return;
17
+ }
18
+ try {
19
+ await generateTypeDeclarations(pkg, buildOptions);
20
+ } catch (error) {
21
+ logger.warn(`\u26A0\uFE0F Declaration generation failed for ${pkg.name}: ${error}`);
22
+ }
23
+ }
24
+ };
25
+ async function generateTypeDeclarations(pkg, buildOptions) {
26
+ const configDts = pkg.buildConfig?.dts;
27
+ const dtsConfig = typeof configDts === "boolean" ? { enable: configDts } : configDts || {};
28
+ const dtsOptions = {
29
+ enable: true,
30
+ // Already checked by plugin activation
31
+ ...dtsConfig,
32
+ // Config from dler.ts
33
+ // CLI overrides
34
+ ...buildOptions?.dtsProvider && { provider: buildOptions.dtsProvider }
35
+ };
36
+ const result = await generateDeclarations({
37
+ package: pkg,
38
+ dtsOptions,
39
+ format: pkg.buildConfig?.format || "esm",
40
+ outputDir: pkg.outputDir
41
+ });
42
+ if (!result.success) {
43
+ logger.warn(`\u26A0\uFE0F Declaration generation failed for ${pkg.name}:`);
44
+ logger.warn(
45
+ result.error || "Unknown error occurred during declaration generation"
46
+ );
47
+ }
48
+ }
@@ -0,0 +1,2 @@
1
+ import type { DlerPlugin } from "../types.js";
2
+ export declare const WorkerPlugin: DlerPlugin;
@@ -0,0 +1,20 @@
1
+ import { logger } from "@reliverse/relinka";
2
+ export const WorkerPlugin = {
3
+ name: "worker",
4
+ setup: (buildConfig) => {
5
+ buildConfig.loader = {
6
+ ...buildConfig.loader,
7
+ ".worker.js": "js",
8
+ ".worker.ts": "ts",
9
+ ".worker.jsx": "jsx",
10
+ ".worker.tsx": "tsx"
11
+ };
12
+ if (!buildConfig.define) {
13
+ buildConfig.define = {};
14
+ }
15
+ buildConfig.define.__WORKER_SUPPORT__ = "true";
16
+ if (buildConfig.verbose) {
17
+ logger.debug("Worker plugin applied");
18
+ }
19
+ }
20
+ };
@@ -0,0 +1,10 @@
1
+ import type { BuildOptions } from "./types.js";
2
+ export declare function applyProductionPreset(options: BuildOptions): BuildOptions;
3
+ export declare function applyDevelopmentPreset(options: BuildOptions): BuildOptions;
4
+ export declare function applyFrontendPreset(options: BuildOptions): BuildOptions;
5
+ export declare function applyPresets(options: BuildOptions): BuildOptions;
6
+ export declare function applyLibraryPreset(options: BuildOptions): BuildOptions;
7
+ export declare function applyReactPreset(options: BuildOptions): BuildOptions;
8
+ export declare function applyNodePreset(options: BuildOptions): BuildOptions;
9
+ export declare function applyMonorepoPreset(options: BuildOptions): BuildOptions;
10
+ export declare function getPresetDescription(preset: "production" | "development" | "library" | "react" | "node" | "monorepo"): string;
@@ -0,0 +1,196 @@
1
+ export function applyProductionPreset(options) {
2
+ const result = {
3
+ ...options,
4
+ production: true,
5
+ minify: true,
6
+ sourcemap: "none",
7
+ env: "inline",
8
+ splitting: !options.compile,
9
+ // Disable splitting for executables
10
+ dev: false,
11
+ watch: false,
12
+ verbose: false
13
+ };
14
+ if (options.compile && options.target === "bun" && options.format === "cjs") {
15
+ result.bytecode = true;
16
+ }
17
+ return result;
18
+ }
19
+ export function applyDevelopmentPreset(options) {
20
+ return {
21
+ ...options,
22
+ dev: true,
23
+ minify: false,
24
+ sourcemap: "inline",
25
+ env: "disable",
26
+ splitting: true,
27
+ watch: true,
28
+ // Override user settings for development
29
+ production: false,
30
+ bytecode: false,
31
+ compile: false
32
+ };
33
+ }
34
+ export function applyFrontendPreset(options) {
35
+ return {
36
+ ...options,
37
+ target: "browser",
38
+ format: "esm",
39
+ splitting: true,
40
+ html: true,
41
+ cssChunking: true,
42
+ minify: options.production ?? false,
43
+ sourcemap: options.production ? "linked" : "inline",
44
+ // Frontend-specific defaults
45
+ publicAssets: "public",
46
+ // Override conflicting options
47
+ bytecode: false
48
+ // Bytecode not supported for browser target
49
+ };
50
+ }
51
+ export function applyPresets(options) {
52
+ let result = { ...options };
53
+ if (options.production) {
54
+ result = applyProductionPreset(result);
55
+ }
56
+ if (options.dev) {
57
+ result = applyDevelopmentPreset(result);
58
+ }
59
+ if (options.html || options.target === "browser") {
60
+ result = applyFrontendPreset(result);
61
+ }
62
+ if (typeof result.minify === "boolean") {
63
+ result.minify = {
64
+ whitespace: result.minify,
65
+ syntax: result.minify,
66
+ identifiers: result.minify
67
+ };
68
+ } else if (result.minifyWhitespace !== void 0 || result.minifySyntax !== void 0 || result.minifyIdentifiers !== void 0) {
69
+ result.minify = {
70
+ whitespace: result.minifyWhitespace ?? true,
71
+ syntax: result.minifySyntax ?? true,
72
+ identifiers: result.minifyIdentifiers ?? true
73
+ };
74
+ }
75
+ if (result.entryNaming || result.chunkNaming || result.assetNaming) {
76
+ result.naming = {
77
+ entry: result.entryNaming,
78
+ chunk: result.chunkNaming,
79
+ asset: result.assetNaming
80
+ };
81
+ }
82
+ if (result.external && typeof result.external === "string") {
83
+ result.external = [result.external];
84
+ }
85
+ if (result.drop && typeof result.drop === "string") {
86
+ result.drop = [result.drop];
87
+ }
88
+ if (result.conditions) {
89
+ if (typeof result.conditions === "string") {
90
+ result.conditions = [result.conditions];
91
+ } else if (!Array.isArray(result.conditions)) {
92
+ result.conditions = [];
93
+ }
94
+ }
95
+ const resultWithJSX = result;
96
+ if (resultWithJSX.jsxRuntime || resultWithJSX.jsxImportSource) {
97
+ result.jsx = {
98
+ runtime: resultWithJSX.jsxRuntime || "automatic",
99
+ importSource: resultWithJSX.jsxImportSource
100
+ };
101
+ }
102
+ if (result.experimental && typeof result.experimental === "string") {
103
+ result.experimental = result.experimental.split(",").map((f) => f.trim());
104
+ }
105
+ return result;
106
+ }
107
+ export function applyLibraryPreset(options) {
108
+ return {
109
+ ...options,
110
+ target: "bun",
111
+ format: "esm",
112
+ splitting: false,
113
+ minify: false,
114
+ sourcemap: "linked",
115
+ // Library-specific defaults
116
+ packages: "external",
117
+ // Enhanced library features
118
+ generateTypes: true,
119
+ typeCheck: true,
120
+ sideEffects: false,
121
+ // Override conflicting options
122
+ html: false,
123
+ cssChunking: false,
124
+ devServer: false
125
+ };
126
+ }
127
+ export function applyReactPreset(options) {
128
+ return {
129
+ ...options,
130
+ target: "browser",
131
+ format: "esm",
132
+ splitting: true,
133
+ html: true,
134
+ cssChunking: true,
135
+ jsx: {
136
+ runtime: "automatic",
137
+ importSource: "react"
138
+ },
139
+ // React-specific defaults
140
+ minify: options.production ?? false,
141
+ sourcemap: options.production ? "linked" : "inline",
142
+ // Enhanced React features
143
+ reactFastRefresh: !options.production,
144
+ svgAsReact: true,
145
+ cssModules: true,
146
+ // Override conflicting options
147
+ bytecode: false
148
+ };
149
+ }
150
+ export function applyNodePreset(options) {
151
+ return {
152
+ ...options,
153
+ target: "node",
154
+ format: "esm",
155
+ splitting: false,
156
+ minify: options.production ?? false,
157
+ sourcemap: options.production ? "none" : "inline",
158
+ // Node.js-specific defaults
159
+ packages: "bundle",
160
+ // Override conflicting options
161
+ html: false,
162
+ cssChunking: false,
163
+ devServer: false
164
+ };
165
+ }
166
+ export function applyMonorepoPreset(options) {
167
+ return {
168
+ ...options,
169
+ // Monorepo-specific defaults
170
+ concurrency: 8,
171
+ stopOnError: false,
172
+ cache: true,
173
+ // Optimize for multiple packages
174
+ minify: options.production ?? false,
175
+ sourcemap: options.production ? "linked" : "inline",
176
+ splitting: true
177
+ };
178
+ }
179
+ export function getPresetDescription(preset) {
180
+ switch (preset) {
181
+ case "production":
182
+ return "Optimized for production: minify=true, sourcemap=none, env=inline, splitting=true";
183
+ case "development":
184
+ return "Optimized for development: minify=false, sourcemap=inline, env=disable, watch=true";
185
+ case "library":
186
+ return "Optimized for libraries: target=bun, format=esm, splitting=false, packages=external";
187
+ case "react":
188
+ return "Optimized for React apps: target=browser, format=esm, jsx=automatic, html=true";
189
+ case "node":
190
+ return "Optimized for Node.js: target=node, format=esm, splitting=false, packages=bundle";
191
+ case "monorepo":
192
+ return "Optimized for monorepos: concurrency=8, cache=true, stopOnError=false";
193
+ default:
194
+ return "";
195
+ }
196
+ }
@@ -0,0 +1,4 @@
1
+ import type { CreateLoaderOptions, LoadFile } from "../../types.js";
2
+ export declare function createLoader(loaderOptions?: CreateLoaderOptions): {
3
+ loadFile: LoadFile;
4
+ };