@eserstack/laroux-bundler 0.0.0-stage → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +431 -2
  3. package/dist/adapters/fonts/font-optimizer.d.ts +28 -0
  4. package/dist/adapters/fonts/font-optimizer.js +74 -0
  5. package/dist/adapters/fonts/index.d.ts +18 -0
  6. package/dist/adapters/fonts/index.js +78 -0
  7. package/dist/adapters/fonts/mod.d.ts +6 -0
  8. package/dist/adapters/fonts/mod.js +7 -0
  9. package/dist/adapters/lightningcss/css-processor.d.ts +39 -0
  10. package/dist/adapters/lightningcss/css-processor.js +103 -0
  11. package/dist/adapters/lightningcss/mod.d.ts +5 -0
  12. package/dist/adapters/lightningcss/mod.js +6 -0
  13. package/dist/adapters/mod.d.ts +13 -0
  14. package/dist/adapters/mod.js +21 -0
  15. package/dist/adapters/prebuilt-bundler/mod.d.ts +5 -0
  16. package/dist/adapters/prebuilt-bundler/mod.js +6 -0
  17. package/dist/adapters/prebuilt-bundler/prebuilt-bundler.d.ts +22 -0
  18. package/dist/adapters/prebuilt-bundler/prebuilt-bundler.js +60 -0
  19. package/dist/adapters/react/mod.d.ts +10 -0
  20. package/dist/adapters/react/mod.js +16 -0
  21. package/dist/adapters/react/plugin.d.ts +17 -0
  22. package/dist/adapters/react/plugin.js +62 -0
  23. package/dist/adapters/react/rsc-analyze.d.ts +29 -0
  24. package/dist/adapters/react/rsc-analyze.js +116 -0
  25. package/dist/adapters/react/rsc-client-entry.d.ts +26 -0
  26. package/dist/adapters/react/rsc-client-entry.js +145 -0
  27. package/dist/adapters/react/rsc-module-map.d.ts +41 -0
  28. package/dist/adapters/react/rsc-module-map.js +81 -0
  29. package/dist/adapters/react/rsc-rewrite-imports.d.ts +38 -0
  30. package/dist/adapters/react/rsc-rewrite-imports.js +409 -0
  31. package/dist/adapters/react/rsc-transform.d.ts +26 -0
  32. package/dist/adapters/react/rsc-transform.js +101 -0
  33. package/dist/adapters/runtime-bundler/mod.d.ts +6 -0
  34. package/dist/adapters/runtime-bundler/mod.js +6 -0
  35. package/dist/adapters/runtime-bundler/runtime-bundler.d.ts +85 -0
  36. package/dist/adapters/runtime-bundler/runtime-bundler.js +244 -0
  37. package/dist/adapters/sharp/image-optimizer.d.ts +52 -0
  38. package/dist/adapters/sharp/image-optimizer.js +261 -0
  39. package/dist/adapters/sharp/mod.d.ts +6 -0
  40. package/dist/adapters/sharp/mod.js +6 -0
  41. package/dist/adapters/tailwindcss/compile.d.ts +22 -0
  42. package/dist/adapters/tailwindcss/compile.js +29 -0
  43. package/dist/adapters/tailwindcss/critical-css-config.d.ts +46 -0
  44. package/dist/adapters/tailwindcss/critical-css-config.js +78 -0
  45. package/dist/adapters/tailwindcss/critical-page-css.d.ts +61 -0
  46. package/dist/adapters/tailwindcss/critical-page-css.js +431 -0
  47. package/dist/adapters/tailwindcss/critical-universal-css.d.ts +68 -0
  48. package/dist/adapters/tailwindcss/critical-universal-css.js +250 -0
  49. package/dist/adapters/tailwindcss/mod.d.ts +10 -0
  50. package/dist/adapters/tailwindcss/mod.js +11 -0
  51. package/dist/adapters/tailwindcss/plugin.d.ts +16 -0
  52. package/dist/adapters/tailwindcss/plugin.js +107 -0
  53. package/dist/adapters/tailwindcss/stylesheet-loader.d.ts +15 -0
  54. package/dist/adapters/tailwindcss/stylesheet-loader.js +83 -0
  55. package/dist/config.d.ts +27 -0
  56. package/dist/config.js +31 -0
  57. package/dist/css-modules.d.ts +49 -0
  58. package/dist/css-modules.js +146 -0
  59. package/dist/domain/build-cache.d.ts +107 -0
  60. package/dist/domain/build-cache.js +128 -0
  61. package/dist/domain/build-validator.d.ts +68 -0
  62. package/dist/domain/build-validator.js +207 -0
  63. package/dist/domain/bundler.d.ts +136 -0
  64. package/dist/domain/bundler.js +225 -0
  65. package/dist/domain/chunk-manifest.d.ts +40 -0
  66. package/dist/domain/chunk-manifest.js +188 -0
  67. package/dist/domain/client-action-stub.d.ts +30 -0
  68. package/dist/domain/client-action-stub.js +167 -0
  69. package/dist/domain/copy-path.d.ts +15 -0
  70. package/dist/domain/copy-path.js +29 -0
  71. package/dist/domain/css-plugin.d.ts +91 -0
  72. package/dist/domain/css-plugin.js +6 -0
  73. package/dist/domain/css-processor.d.ts +57 -0
  74. package/dist/domain/css-processor.js +33 -0
  75. package/dist/domain/font-optimizer.d.ts +46 -0
  76. package/dist/domain/font-optimizer.js +17 -0
  77. package/dist/domain/framework-plugin.d.ts +106 -0
  78. package/dist/domain/framework-plugin.js +20 -0
  79. package/dist/domain/image-optimizer.d.ts +74 -0
  80. package/dist/domain/image-optimizer.js +16 -0
  81. package/dist/domain/import-map.d.ts +90 -0
  82. package/dist/domain/import-map.js +187 -0
  83. package/dist/domain/mod.d.ts +32 -0
  84. package/dist/domain/mod.js +20 -0
  85. package/dist/domain/route-generator.d.ts +34 -0
  86. package/dist/domain/route-generator.js +305 -0
  87. package/dist/domain/route-scanner.d.ts +72 -0
  88. package/dist/domain/route-scanner.js +282 -0
  89. package/dist/domain/server-action-transform.d.ts +28 -0
  90. package/dist/domain/server-action-transform.js +147 -0
  91. package/dist/domain/virtual-source.d.ts +63 -0
  92. package/dist/domain/virtual-source.js +238 -0
  93. package/dist/import-map-resolver-plugin.d.ts +47 -0
  94. package/dist/import-map-resolver-plugin.js +109 -0
  95. package/dist/mod.d.ts +57 -0
  96. package/dist/mod.js +56 -0
  97. package/dist/server-externals-plugin.d.ts +29 -0
  98. package/dist/server-externals-plugin.js +63 -0
  99. package/dist/system.d.ts +157 -0
  100. package/dist/system.js +1401 -0
  101. package/dist/types.d.ts +60 -0
  102. package/dist/types.js +38 -0
  103. package/package.json +83 -3
@@ -0,0 +1,39 @@
1
+ /**
2
+ * CSS Processing with Lightning CSS
3
+ * Uses plugin hooks for framework-specific processing (Tailwind, etc.)
4
+ */
5
+ import type { CssPlugin } from "../../domain/css-plugin.ts";
6
+ import type { CssProcessor } from "../../domain/css-processor.ts";
7
+ export type CssProcessOptions = {
8
+ /** Input CSS file path */
9
+ input: string;
10
+ /** Output CSS file path */
11
+ output: string;
12
+ /** Whether to minify the output */
13
+ minify?: boolean;
14
+ /** Project root directory */
15
+ projectRoot: string;
16
+ /** CSS plugin for framework-specific processing */
17
+ plugin?: CssPlugin;
18
+ };
19
+ /**
20
+ * Process CSS file
21
+ * Uses plugin hooks for framework-specific compilation
22
+ * @param options - Processing options
23
+ * @returns Promise resolving when processing completes
24
+ */
25
+ export declare function processCss(options: CssProcessOptions): Promise<void>;
26
+ /**
27
+ * Post-process CSS with Lightning CSS
28
+ * Applies advanced optimizations, nesting support, and unused symbol removal
29
+ * @param cssContent - CSS content to process
30
+ * @param minify - Whether to minify
31
+ * @returns Processed CSS string
32
+ */
33
+ export declare function postProcessWithLightningCSS(cssContent: string, minify: boolean): string;
34
+ /**
35
+ * CSS processor that transforms stylesheets with Lightning CSS: nesting and
36
+ * other modern syntax lowered for Chrome 90, Firefox 88 and Safari 14, and
37
+ * minification when asked. Pass it to the build as `cssProcessor`.
38
+ */
39
+ export declare const lightningCssProcessor: CssProcessor;
@@ -0,0 +1,103 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ /**
3
+ * CSS Processing with Lightning CSS
4
+ * Uses plugin hooks for framework-specific processing (Tailwind, etc.)
5
+ */
6
+ import { runtime } from "@eserstack/standards/cross-runtime";
7
+ import * as logging from "@eserstack/logging";
8
+ import * as types from "../../types.js";
9
+ import * as lightningcss from "lightningcss";
10
+ import * as cssProcessor from "../../domain/css-processor.js";
11
+ const cssLogger = logging.logger.getLogger(["laroux-bundler", "css"]);
12
+ /**
13
+ * Process CSS file
14
+ * Uses plugin hooks for framework-specific compilation
15
+ * @param options - Processing options
16
+ * @returns Promise resolving when processing completes
17
+ */
18
+ export async function processCss(options) {
19
+ const { input, output, minify = false, projectRoot, plugin } = options;
20
+ // Check if input file exists
21
+ if (!(await runtime.fs.exists(input))) {
22
+ cssLogger.warn(`CSS input file not found: ${input}`);
23
+ return;
24
+ }
25
+ // Ensure output directory exists
26
+ const outputDir = runtime.path.resolve(output, "..");
27
+ await runtime.fs.ensureDir(outputDir);
28
+ // Read input CSS
29
+ let cssContent = await runtime.fs.readTextFile(input);
30
+ cssLogger.debug(`Processing CSS: ${input} → ${output}`);
31
+ const context = {
32
+ projectRoot,
33
+ cssPath: input,
34
+ isModule: false,
35
+ };
36
+ try {
37
+ // The plugin compiles the file when it claims it (Tailwind does scanning,
38
+ // compilation and minification); otherwise Lightning CSS transforms it.
39
+ cssContent = await cssProcessor.compileStylesheet(cssContent, {
40
+ plugin: plugin ?? null,
41
+ processor: lightningCssProcessor,
42
+ context,
43
+ minify,
44
+ });
45
+ // Write output
46
+ await runtime.fs.writeTextFile(output, cssContent);
47
+ cssLogger.debug(`✓ CSS processed successfully: ${output}`);
48
+ }
49
+ catch (error) {
50
+ // Not logged here: the caller that handles the error logs it once.
51
+ const message = error instanceof Error ? error.message : String(error);
52
+ throw types.buildErrors.cssError(`${input}: ${message}`, { cause: error });
53
+ }
54
+ }
55
+ /**
56
+ * Post-process CSS with Lightning CSS
57
+ * Applies advanced optimizations, nesting support, and unused symbol removal
58
+ * @param cssContent - CSS content to process
59
+ * @param minify - Whether to minify
60
+ * @returns Processed CSS string
61
+ */
62
+ export function postProcessWithLightningCSS(cssContent, minify) {
63
+ return transformWithLightningCss(cssContent, {
64
+ filename: "styles.css",
65
+ minify,
66
+ });
67
+ }
68
+ /**
69
+ * Transform one stylesheet with Lightning CSS for Chrome 90, Firefox 88 and
70
+ * Safari 14. When Lightning CSS cannot parse it, the warning names the file
71
+ * and the stylesheet is returned unchanged.
72
+ */
73
+ function transformWithLightningCss(cssContent, options) {
74
+ try {
75
+ const result = lightningcss.transform({
76
+ filename: options.filename,
77
+ code: new TextEncoder().encode(cssContent),
78
+ minify: options.minify,
79
+ targets: {
80
+ chrome: 90 << 16, // Chrome 90+
81
+ firefox: 88 << 16, // Firefox 88+
82
+ safari: 14 << 16, // Safari 14+
83
+ },
84
+ unusedSymbols: [], // Remove unused custom properties and keyframes
85
+ });
86
+ return new TextDecoder().decode(result.code);
87
+ }
88
+ catch (error) {
89
+ cssLogger
90
+ .with({ error })
91
+ .warn(`Lightning CSS could not transform ${options.filename}, keeping it unchanged`);
92
+ return cssContent;
93
+ }
94
+ }
95
+ /**
96
+ * CSS processor that transforms stylesheets with Lightning CSS: nesting and
97
+ * other modern syntax lowered for Chrome 90, Firefox 88 and Safari 14, and
98
+ * minification when asked. Pass it to the build as `cssProcessor`.
99
+ */
100
+ export const lightningCssProcessor = {
101
+ name: "lightningcss",
102
+ process: (css, options) => transformWithLightningCss(css, options),
103
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * LightningCSS Adapter
3
+ * CSS processing with Lightning CSS
4
+ */
5
+ export { type CssProcessOptions, lightningCssProcessor, postProcessWithLightningCSS, processCss, } from "./css-processor.ts";
@@ -0,0 +1,6 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ /**
3
+ * LightningCSS Adapter
4
+ * CSS processing with Lightning CSS
5
+ */
6
+ export { lightningCssProcessor, postProcessWithLightningCSS, processCss, } from "./css-processor.js";
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Adapters Layer
3
+ *
4
+ * All adapter implementations that implement domain interfaces.
5
+ * Users import adapters explicitly and pass them to bundle function.
6
+ */
7
+ export { type CssProcessOptions, lightningCssProcessor, postProcessWithLightningCSS, processCss, } from "./lightningcss/mod.ts";
8
+ export { generateSrcset, getBestVariant, type ImageManifest, type ImageOptimizationConfig, type ImageVariant, type OptimizedImage, optimizeImage, optimizeImages, scanImages, sharpImageOptimizer, } from "./sharp/mod.ts";
9
+ export { type FontDefinition, type FontDisplay, type FontFile, type FontOptimizationResult, type FontStyle, type FontWeight, generateFontVariables, generateGoogleFontsUrl, getFontFamilies, getFontUrls, googleFontOptimizer, optimizeGoogleFonts, optimizeMultipleGoogleFonts, } from "./fonts/mod.ts";
10
+ export { createRuntimeCache, type RuntimeBundle, RuntimeBundler, type RuntimeBundlerConfig, } from "./runtime-bundler/mod.ts";
11
+ export { PrebuiltBundler, type PrebuiltBundlerConfig, } from "./prebuilt-bundler/mod.ts";
12
+ export { analyzeClientComponents, type ClientComponent, createBundlerConfig, createClientComponentMap, createClientEntry, createClientManifest, createCSSModuleMap, createImportMapping, type DirectiveAnalysisOptions, type DirectiveMatch, generateModuleMap, generateTransformManifest, getAllComponents, type ImportRewriteResult, loadModuleMap, type ModuleMap as ReactModuleMap, type ModuleMapEntry as ReactModuleMapEntry, reactPlugin, rewriteAllClientComponentCSSImports, rewriteAllServerComponents, rewriteAllSrcCSSModuleImports, rewriteServerComponentImports, saveModuleMap, transformAllClientComponents, transformClientComponent, type TransformResult, } from "./react/mod.ts";
13
+ export { ABOVE_FOLD_PATTERNS, compileTailwind, createTailwindPlugin, CRITICAL_LAYERS, CRITICAL_PROPERTY_PATTERNS, type CriticalCssConfig, type CriticalPageCssOptions, type CriticalPageCssResult, type CriticalUniversalCssResult, DEFAULT_CRITICAL_UNIVERSAL_CSS, expandApplyDirectives, extractCriticalPageCss, extractCriticalUniversalCss, extractThemeLayer, generateAsyncCssLoader, generateCriticalUniversalCss, getDefaultCriticalCssConfig, loadStylesheet, type StylesheetLoadResult, type TailwindCompileOptions, type TailwindPluginOptions, } from "./tailwindcss/mod.ts";
@@ -0,0 +1,21 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ /**
3
+ * Adapters Layer
4
+ *
5
+ * All adapter implementations that implement domain interfaces.
6
+ * Users import adapters explicitly and pass them to bundle function.
7
+ */
8
+ // LightningCSS adapter
9
+ export { lightningCssProcessor, postProcessWithLightningCSS, processCss, } from "./lightningcss/mod.js";
10
+ // Sharp image optimizer adapter
11
+ export { generateSrcset, getBestVariant, optimizeImage, optimizeImages, scanImages, sharpImageOptimizer, } from "./sharp/mod.js";
12
+ // Fonts adapter
13
+ export { generateFontVariables, generateGoogleFontsUrl, getFontFamilies, getFontUrls, googleFontOptimizer, optimizeGoogleFonts, optimizeMultipleGoogleFonts, } from "./fonts/mod.js";
14
+ // Runtime bundler adapter
15
+ export { createRuntimeCache, RuntimeBundler, } from "./runtime-bundler/mod.js";
16
+ // Prebuilt bundler adapter
17
+ export { PrebuiltBundler, } from "./prebuilt-bundler/mod.js";
18
+ // React adapter
19
+ export { analyzeClientComponents, createBundlerConfig, createClientComponentMap, createClientEntry, createClientManifest, createCSSModuleMap, createImportMapping, generateModuleMap, generateTransformManifest, getAllComponents, loadModuleMap, reactPlugin, rewriteAllClientComponentCSSImports, rewriteAllServerComponents, rewriteAllSrcCSSModuleImports, rewriteServerComponentImports, saveModuleMap, transformAllClientComponents, transformClientComponent, } from "./react/mod.js";
20
+ // Tailwind CSS adapter
21
+ export { ABOVE_FOLD_PATTERNS, compileTailwind, createTailwindPlugin, CRITICAL_LAYERS, CRITICAL_PROPERTY_PATTERNS, DEFAULT_CRITICAL_UNIVERSAL_CSS, expandApplyDirectives, extractCriticalPageCss, extractCriticalUniversalCss, extractThemeLayer, generateAsyncCssLoader, generateCriticalUniversalCss, getDefaultCriticalCssConfig, loadStylesheet, } from "./tailwindcss/mod.js";
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Prebuilt Bundler Adapter
3
+ * Reads pre-built bundles from disk
4
+ */
5
+ export { PrebuiltBundler, type PrebuiltBundlerConfig, } from "./prebuilt-bundler.ts";
@@ -0,0 +1,6 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ /**
3
+ * Prebuilt Bundler Adapter
4
+ * Reads pre-built bundles from disk
5
+ */
6
+ export { PrebuiltBundler, } from "./prebuilt-bundler.js";
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Prebuilt Bundler
3
+ * Reads pre-built bundles from dist/ directory
4
+ */
5
+ import type { BundleData, Bundler } from "../../domain/bundler.ts";
6
+ export type PrebuiltBundlerConfig = {
7
+ distDir: string;
8
+ };
9
+ /**
10
+ * PrebuiltBundler reads from dist/ directory
11
+ * Used when serving pre-built bundles
12
+ */
13
+ export declare class PrebuiltBundler implements Bundler {
14
+ private config;
15
+ private cachedManifest;
16
+ constructor(config: PrebuiltBundlerConfig);
17
+ getBundle(): Promise<BundleData>;
18
+ /**
19
+ * Reload manifest (useful for watch mode)
20
+ */
21
+ reload(): Promise<void>;
22
+ }
@@ -0,0 +1,60 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ /**
3
+ * Prebuilt Bundler
4
+ * Reads pre-built bundles from dist/ directory
5
+ */
6
+ import { runtime } from "@eserstack/standards/cross-runtime";
7
+ import * as logging from "@eserstack/logging";
8
+ const prebuiltLogger = logging.logger.getLogger([
9
+ "laroux-bundler",
10
+ "prebuilt-bundler",
11
+ ]);
12
+ /**
13
+ * PrebuiltBundler reads from dist/ directory
14
+ * Used when serving pre-built bundles
15
+ */
16
+ export class PrebuiltBundler {
17
+ config;
18
+ cachedManifest = null;
19
+ constructor(config) {
20
+ this.config = config;
21
+ }
22
+ async getBundle() {
23
+ prebuiltLogger.debug("📦 Loading prebuilt bundle from disk...");
24
+ // Load chunk manifest from client directory
25
+ const manifestPath = runtime.path.resolve(this.config.distDir, "client", "manifest.json");
26
+ const manifestContent = await runtime.fs.readTextFile(manifestPath);
27
+ const chunkManifest = JSON.parse(manifestContent);
28
+ // Load module map for SSR (required for client component resolution)
29
+ const moduleMapPath = runtime.path.resolve(this.config.distDir, "client", "module-map.json");
30
+ let moduleMap = {};
31
+ try {
32
+ const moduleMapContent = await runtime.fs.readTextFile(moduleMapPath);
33
+ moduleMap = JSON.parse(moduleMapContent);
34
+ prebuiltLogger.debug(`✅ Loaded module map with ${Object.keys(moduleMap).length} entries`);
35
+ }
36
+ catch {
37
+ prebuiltLogger.warn("⚠️ Module map not found, SSR may fail for client components");
38
+ }
39
+ // Cache for next time
40
+ this.cachedManifest = chunkManifest;
41
+ // Entrypoint from manifest (served without /dist/client prefix)
42
+ const entrypoint = chunkManifest.entrypoint
43
+ ? `/${chunkManifest.entrypoint}`
44
+ : "/client.js";
45
+ prebuiltLogger.debug(`✅ Loaded manifest with entrypoint: ${entrypoint}`);
46
+ return {
47
+ clientCode: null, // Not needed for prebuilt (served as static file)
48
+ moduleMap,
49
+ chunkManifest,
50
+ entrypoint,
51
+ };
52
+ }
53
+ /**
54
+ * Reload manifest (useful for watch mode)
55
+ */
56
+ async reload() {
57
+ this.cachedManifest = null;
58
+ await this.getBundle();
59
+ }
60
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * React Framework Adapter
3
+ * React Server Components (RSC) support for Laroux bundler
4
+ */
5
+ export { reactPlugin } from "./plugin.ts";
6
+ export { analyzeClientComponents, type ClientComponent, type DirectiveAnalysisOptions, type DirectiveMatch, getAllComponents, } from "./rsc-analyze.ts";
7
+ export { type BaseModuleEntry, type BaseModuleMap, createBundlerConfig, createClientManifest, generateModuleMap, loadModuleMap, type ModuleMap, type ModuleMapEntry, saveModuleMap, } from "./rsc-module-map.ts";
8
+ export { createImportMapping, generateTransformManifest, transformAllClientComponents, transformClientComponent, type TransformResult, } from "./rsc-transform.ts";
9
+ export { createClientComponentMap, createCSSModuleMap, type ImportRewriteResult, rewriteAllClientComponentCSSImports, rewriteAllServerComponents, rewriteAllSrcCSSModuleImports, rewriteServerComponentImports, } from "./rsc-rewrite-imports.ts";
10
+ export { createClientEntry } from "./rsc-client-entry.ts";
@@ -0,0 +1,16 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ /**
3
+ * React Framework Adapter
4
+ * React Server Components (RSC) support for Laroux bundler
5
+ */
6
+ export { reactPlugin } from "./plugin.js";
7
+ // RSC analysis
8
+ export { analyzeClientComponents, getAllComponents, } from "./rsc-analyze.js";
9
+ // RSC module map
10
+ export { createBundlerConfig, createClientManifest, generateModuleMap, loadModuleMap, saveModuleMap, } from "./rsc-module-map.js";
11
+ // RSC transformation
12
+ export { createImportMapping, generateTransformManifest, transformAllClientComponents, transformClientComponent, } from "./rsc-transform.js";
13
+ // RSC import rewriting
14
+ export { createClientComponentMap, createCSSModuleMap, rewriteAllClientComponentCSSImports, rewriteAllServerComponents, rewriteAllSrcCSSModuleImports, rewriteServerComponentImports, } from "./rsc-rewrite-imports.js";
15
+ // Client entry generation
16
+ export { createClientEntry } from "./rsc-client-entry.js";
@@ -0,0 +1,17 @@
1
+ /**
2
+ * React Framework Plugin for Laroux Bundler
3
+ *
4
+ * Implements the FrameworkPlugin interface to provide React-specific
5
+ * build functionality including React Server Components (RSC) support.
6
+ */
7
+ import type { FrameworkPlugin } from "../../domain/framework-plugin.ts";
8
+ /**
9
+ * React framework plugin for Laroux bundler
10
+ *
11
+ * Provides React Server Components (RSC) support:
12
+ * - "use client" directive analysis
13
+ * - Client component proxy generation
14
+ * - Module map for client/server communication
15
+ * - Import rewriting for bundling
16
+ */
17
+ export declare const reactPlugin: FrameworkPlugin;
@@ -0,0 +1,62 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ /**
3
+ * React Framework Plugin for Laroux Bundler
4
+ *
5
+ * Implements the FrameworkPlugin interface to provide React-specific
6
+ * build functionality including React Server Components (RSC) support.
7
+ */
8
+ // Import RSC implementations
9
+ import * as rscAnalyze from "./rsc-analyze.js";
10
+ import * as rscTransform from "./rsc-transform.js";
11
+ import * as rscModuleMap from "./rsc-module-map.js";
12
+ import * as rscRewriteImports from "./rsc-rewrite-imports.js";
13
+ import * as rscClientEntry from "./rsc-client-entry.js";
14
+ /**
15
+ * React framework plugin for Laroux bundler
16
+ *
17
+ * Provides React Server Components (RSC) support:
18
+ * - "use client" directive analysis
19
+ * - Client component proxy generation
20
+ * - Module map for client/server communication
21
+ * - Import rewriting for bundling
22
+ */
23
+ export const reactPlugin = {
24
+ name: "react",
25
+ analyzeClientComponents: async (srcDir, projectRoot, cache) => {
26
+ return await rscAnalyze.analyzeClientComponents(srcDir, projectRoot, cache);
27
+ },
28
+ getAllComponents: async (srcDir) => {
29
+ return await rscAnalyze.getAllComponents(srcDir);
30
+ },
31
+ transformClientComponents: async (components, outputDir, projectRoot) => {
32
+ const results = await rscTransform.transformAllClientComponents(components, outputDir, projectRoot);
33
+ // Map RSC TransformResult to framework-plugin TransformResult
34
+ return results.map((r) => ({
35
+ originalPath: r.originalPath,
36
+ transformedPath: r.transformedPath,
37
+ }));
38
+ },
39
+ generateTransformManifest: async (transformResults, outputPath, projectRoot) => {
40
+ await rscTransform.generateTransformManifest(transformResults, outputPath, projectRoot);
41
+ },
42
+ createModuleMap: (components) => {
43
+ // RSC's generateModuleMap returns Record<string, ModuleMapEntry>
44
+ // which matches our ModuleMap type
45
+ return Promise.resolve(rscModuleMap.generateModuleMap(components));
46
+ },
47
+ saveModuleMap: async (moduleMap, outputPath) => {
48
+ await rscModuleMap.saveModuleMap(moduleMap, outputPath);
49
+ },
50
+ createClientManifest: (components) => {
51
+ return Promise.resolve(rscModuleMap.createClientManifest(components));
52
+ },
53
+ rewriteServerComponents: async (serverComponentPaths, transformResults, cssModulePaths, outputDir, projectRoot) => {
54
+ await rscRewriteImports.rewriteAllServerComponents(serverComponentPaths, transformResults, cssModulePaths, outputDir, projectRoot);
55
+ },
56
+ rewriteCssModuleImports: async (srcDir, cssModulePaths, projectRoot) => {
57
+ await rscRewriteImports.rewriteAllSrcCSSModuleImports(srcDir, cssModulePaths, projectRoot);
58
+ },
59
+ createClientEntry: async (components, projectRoot, distDir) => {
60
+ return await rscClientEntry.createClientEntry(components, projectRoot, distDir);
61
+ },
62
+ };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Module Graph Analyzer
3
+ * Scans the codebase to identify "use client" directives and build a client component registry
4
+ *
5
+ * Uses @eserstack/codebase/directive-analysis for the core analysis,
6
+ * adding caching support for incremental builds.
7
+ */
8
+ import type { DirectiveAnalysisOptions, DirectiveMatch } from "@eserstack/codebase/directive-analysis";
9
+ import type { ClientComponentCache } from "../../domain/build-cache.ts";
10
+ export type { DirectiveAnalysisOptions, DirectiveMatch };
11
+ export type ClientComponent = {
12
+ /** Absolute file path */
13
+ filePath: string;
14
+ /** Relative path from project root (ES Module path) */
15
+ relativePath: string;
16
+ /** Export names (default or named) */
17
+ exportNames: string[];
18
+ };
19
+ /**
20
+ * Analyze the codebase and identify all client components
21
+ * @param srcDir - Source directory to scan
22
+ * @param projectRoot - Project root for relative path calculation
23
+ * @param cache - Optional build cache for incremental analysis
24
+ */
25
+ export declare function analyzeClientComponents(srcDir: string, projectRoot: string, cache?: ClientComponentCache): Promise<ClientComponent[]>;
26
+ /**
27
+ * Get all component files (both server and client)
28
+ */
29
+ export declare function getAllComponents(srcDir: string): Promise<string[]>;
@@ -0,0 +1,116 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ /**
3
+ * Module Graph Analyzer
4
+ * Scans the codebase to identify "use client" directives and build a client component registry
5
+ *
6
+ * Uses @eserstack/codebase/directive-analysis for the core analysis,
7
+ * adding caching support for incremental builds.
8
+ */
9
+ import * as directiveAnalysis from "@eserstack/codebase/directive-analysis";
10
+ import { runtime } from "@eserstack/standards/cross-runtime";
11
+ import * as patterns from "@eserstack/standards/patterns";
12
+ import * as logging from "@eserstack/logging";
13
+ import * as collector from "@eserstack/collector";
14
+ const analyzeLogger = logging.logger.getLogger([
15
+ "laroux-bundler",
16
+ "rsc-analyze",
17
+ ]);
18
+ /**
19
+ * Convert DirectiveMatch to ClientComponent for backward compatibility
20
+ */
21
+ function toClientComponent(match) {
22
+ return {
23
+ filePath: match.filePath,
24
+ relativePath: match.relativePath,
25
+ exportNames: [...match.exports],
26
+ };
27
+ }
28
+ /**
29
+ * Analyze the codebase and identify all client components
30
+ * @param srcDir - Source directory to scan
31
+ * @param projectRoot - Project root for relative path calculation
32
+ * @param cache - Optional build cache for incremental analysis
33
+ */
34
+ export async function analyzeClientComponents(srcDir, projectRoot, cache) {
35
+ analyzeLogger.debug(`🔍 Analyzing client components in: ${srcDir}`);
36
+ // If no cache, use the base implementation directly
37
+ if (cache === undefined) {
38
+ const matches = await directiveAnalysis.analyzeClientComponents(srcDir, {
39
+ projectRoot,
40
+ });
41
+ const components = matches.map(toClientComponent);
42
+ analyzeLogger.debug(`📊 Total client components found: ${components.length}`);
43
+ return components;
44
+ }
45
+ // With cache - we need to do incremental analysis
46
+ // Use the base implementation but check cache for each file
47
+ const clientComponents = [];
48
+ let cacheHits = 0;
49
+ let cacheMisses = 0;
50
+ // Get all matches from base implementation (it walks files internally)
51
+ const matches = await directiveAnalysis.analyzeClientComponents(srcDir, {
52
+ projectRoot,
53
+ });
54
+ // Modification times for the cache check; null marks a file that was
55
+ // deleted after the scan
56
+ const modifiedTimes = await Promise.all(matches.map(async (match) => {
57
+ try {
58
+ const fileStat = await runtime.fs.stat(match.filePath);
59
+ return fileStat.mtime?.getTime() ?? 0;
60
+ }
61
+ catch {
62
+ return null;
63
+ }
64
+ }));
65
+ for (const [index, match] of matches.entries()) {
66
+ const fileMtime = modifiedTimes[index] ?? null;
67
+ if (fileMtime === null) {
68
+ continue;
69
+ }
70
+ // Check cache
71
+ const cached = cache.getClientComponent(match.filePath, fileMtime);
72
+ if (cached !== null) {
73
+ cacheHits++;
74
+ if (cached.isClient) {
75
+ clientComponents.push({
76
+ filePath: match.filePath,
77
+ relativePath: match.relativePath,
78
+ exportNames: cached.exportNames,
79
+ });
80
+ }
81
+ continue;
82
+ }
83
+ // Cache miss - the match already confirmed it's a client component
84
+ cacheMisses++;
85
+ const exportNames = [...match.exports];
86
+ cache.setClientComponent(match.filePath, true, exportNames, fileMtime);
87
+ clientComponents.push({
88
+ filePath: match.filePath,
89
+ relativePath: match.relativePath,
90
+ exportNames,
91
+ });
92
+ analyzeLogger.debug(` ✓ Found client component: ${match.relativePath} (exports: ${exportNames.join(", ")})`);
93
+ }
94
+ if (cacheHits > 0 || cacheMisses > 0) {
95
+ analyzeLogger.debug(`📊 Component analysis: ${cacheHits} cache hits, ${cacheMisses} analyzed`);
96
+ }
97
+ analyzeLogger.debug(`📊 Total client components found: ${clientComponents.length}`);
98
+ return clientComponents;
99
+ }
100
+ /** Extensions of the files {@link getAllComponents} returns. */
101
+ const COMPONENT_EXTENSIONS = ["tsx", "ts", "jsx", "js"];
102
+ /**
103
+ * Get all component files (both server and client)
104
+ */
105
+ export async function getAllComponents(srcDir) {
106
+ const components = [];
107
+ const IGNORE_PATTERN = /(?:node_modules|\.test\.|\.spec\.)/;
108
+ // The extension check is done here: the glob filter of walkFiles supports
109
+ // only * and **, so a "*.{tsx,ts}" list would match no file.
110
+ for await (const relPath of collector.walkFiles(srcDir, undefined, IGNORE_PATTERN)) {
111
+ if (patterns.hasExtension(relPath, COMPONENT_EXTENSIONS)) {
112
+ components.push(runtime.path.join(srcDir, relPath));
113
+ }
114
+ }
115
+ return components;
116
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Create Client Entry Point
3
+ * Generates a temporary entry file that includes:
4
+ * 1. All client components (so they're in the bundle)
5
+ * 2. The bootstrap code from @eserstack/laroux-react/client/bootstrap
6
+ * 3. A global module registry for RSC client
7
+ */
8
+ import type { ClientComponent } from "./rsc-analyze.ts";
9
+ /** Directory under distDir that holds the copied laroux-react files. */
10
+ export declare const BOOTSTRAP_COPY_DIR = "_laroux-react";
11
+ /**
12
+ * Convert a file:// URL to a filesystem path, decoding percent-escapes such
13
+ * as %20, and return any other string unchanged.
14
+ */
15
+ export declare function fileUrlToPath(urlString: string): string;
16
+ /**
17
+ * Write the client entry for a bundle: it imports every client component,
18
+ * registers it in the global module registry and runs the laroux-react
19
+ * bootstrap, whose files are copied to `<distDir>/_laroux-react/`.
20
+ *
21
+ * @param clientComponents - The app's "use client" components
22
+ * @param _projectRoot - Unused; kept for the FrameworkPlugin signature
23
+ * @param distDir - Directory that receives the entry and the bootstrap copy
24
+ * @returns Absolute path of the generated entry file
25
+ */
26
+ export declare function createClientEntry(clientComponents: ClientComponent[], _projectRoot: string, distDir: string): Promise<string>;