@harpy-js/core 0.4.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 (147) hide show
  1. package/README.md +326 -0
  2. package/dist/cli.d.ts +12 -0
  3. package/dist/cli.js +53 -0
  4. package/dist/client/Link.d.ts +5 -0
  5. package/dist/client/Link.js +62 -0
  6. package/dist/client/__tests__/getActiveItemId.test.d.ts +1 -0
  7. package/dist/client/__tests__/getActiveItemId.test.js +38 -0
  8. package/dist/client/getActiveItemId.d.ts +7 -0
  9. package/dist/client/getActiveItemId.js +55 -0
  10. package/dist/client/use-i18n.d.ts +7 -0
  11. package/dist/client/use-i18n.js +64 -0
  12. package/dist/core/__tests__/component-analyzer.test.d.ts +1 -0
  13. package/dist/core/__tests__/component-analyzer.test.js +151 -0
  14. package/dist/core/__tests__/hydration-manifest.test.d.ts +1 -0
  15. package/dist/core/__tests__/hydration-manifest.test.js +211 -0
  16. package/dist/core/__tests__/jsx.engine.test.d.ts +1 -0
  17. package/dist/core/__tests__/jsx.engine.test.js +118 -0
  18. package/dist/core/app-setup.d.ts +7 -0
  19. package/dist/core/app-setup.js +79 -0
  20. package/dist/core/auto-register.module.d.ts +9 -0
  21. package/dist/core/auto-register.module.js +18 -0
  22. package/dist/core/auto-wrap-middleware.d.ts +4 -0
  23. package/dist/core/auto-wrap-middleware.js +130 -0
  24. package/dist/core/client-component-wrapper.d.ts +5 -0
  25. package/dist/core/client-component-wrapper.js +37 -0
  26. package/dist/core/client-hydration.d.ts +2 -0
  27. package/dist/core/client-hydration.js +93 -0
  28. package/dist/core/client-wrapper-browser.d.ts +2 -0
  29. package/dist/core/client-wrapper-browser.js +22 -0
  30. package/dist/core/component-analyzer.d.ts +4 -0
  31. package/dist/core/component-analyzer.js +98 -0
  32. package/dist/core/component-auto-wrapper.d.ts +2 -0
  33. package/dist/core/component-auto-wrapper.js +63 -0
  34. package/dist/core/component-client-wrapper.d.ts +4 -0
  35. package/dist/core/component-client-wrapper.js +80 -0
  36. package/dist/core/hydration-generator.d.ts +2 -0
  37. package/dist/core/hydration-generator.js +98 -0
  38. package/dist/core/hydration-manifest.d.ts +7 -0
  39. package/dist/core/hydration-manifest.js +83 -0
  40. package/dist/core/hydration.d.ts +16 -0
  41. package/dist/core/hydration.js +72 -0
  42. package/dist/core/jsx.engine.d.ts +9 -0
  43. package/dist/core/jsx.engine.js +161 -0
  44. package/dist/core/live-reload-client.js +32 -0
  45. package/dist/core/live-reload.controller.d.ts +10 -0
  46. package/dist/core/live-reload.controller.js +38 -0
  47. package/dist/core/navigation.service.d.ts +18 -0
  48. package/dist/core/navigation.service.js +206 -0
  49. package/dist/core/router.module.d.ts +2 -0
  50. package/dist/core/router.module.js +21 -0
  51. package/dist/core/static-assets.controller.d.ts +4 -0
  52. package/dist/core/static-assets.controller.js +51 -0
  53. package/dist/core/types/nav.types.d.ts +22 -0
  54. package/dist/core/types/nav.types.js +2 -0
  55. package/dist/core/views/layout.d.ts +8 -0
  56. package/dist/core/views/layout.js +35 -0
  57. package/dist/decorators/jsx.decorator.d.ts +26 -0
  58. package/dist/decorators/jsx.decorator.js +10 -0
  59. package/dist/decorators/layout.decorator.d.ts +4 -0
  60. package/dist/decorators/layout.decorator.js +29 -0
  61. package/dist/i18n/__tests__/i18n.helper.test.d.ts +1 -0
  62. package/dist/i18n/__tests__/i18n.helper.test.js +105 -0
  63. package/dist/i18n/__tests__/i18n.interceptor.test.d.ts +1 -0
  64. package/dist/i18n/__tests__/i18n.interceptor.test.js +195 -0
  65. package/dist/i18n/__tests__/i18n.module.test.d.ts +1 -0
  66. package/dist/i18n/__tests__/i18n.module.test.js +83 -0
  67. package/dist/i18n/__tests__/i18n.service.test.d.ts +1 -0
  68. package/dist/i18n/__tests__/i18n.service.test.js +109 -0
  69. package/dist/i18n/__tests__/t.test.d.ts +1 -0
  70. package/dist/i18n/__tests__/t.test.js +66 -0
  71. package/dist/i18n/i18n-module.options.d.ts +10 -0
  72. package/dist/i18n/i18n-module.options.js +4 -0
  73. package/dist/i18n/i18n-switcher.controller.d.ts +12 -0
  74. package/dist/i18n/i18n-switcher.controller.js +80 -0
  75. package/dist/i18n/i18n-types.d.ts +8 -0
  76. package/dist/i18n/i18n-types.js +2 -0
  77. package/dist/i18n/i18n.helper.d.ts +14 -0
  78. package/dist/i18n/i18n.helper.js +70 -0
  79. package/dist/i18n/i18n.interceptor.d.ts +9 -0
  80. package/dist/i18n/i18n.interceptor.js +99 -0
  81. package/dist/i18n/i18n.module.d.ts +5 -0
  82. package/dist/i18n/i18n.module.js +51 -0
  83. package/dist/i18n/i18n.service.d.ts +12 -0
  84. package/dist/i18n/i18n.service.js +61 -0
  85. package/dist/i18n/index.d.ts +10 -0
  86. package/dist/i18n/index.js +20 -0
  87. package/dist/i18n/locale.decorator.d.ts +1 -0
  88. package/dist/i18n/locale.decorator.js +8 -0
  89. package/dist/i18n/t.d.ts +3 -0
  90. package/dist/i18n/t.js +16 -0
  91. package/dist/index.d.ts +19 -0
  92. package/dist/index.js +40 -0
  93. package/package.json +79 -0
  94. package/scripts/analyze-styles.ts +124 -0
  95. package/scripts/auto-wrap-exports.ts +239 -0
  96. package/scripts/build-css.ts +38 -0
  97. package/scripts/build-hydration.ts +313 -0
  98. package/scripts/build-page-styles.ts +43 -0
  99. package/scripts/copy-assets.ts +34 -0
  100. package/scripts/dev.sh +3 -0
  101. package/scripts/dev.ts +257 -0
  102. package/src/cli.ts +71 -0
  103. package/src/client/Link.tsx +62 -0
  104. package/src/client/__tests__/getActiveItemId.test.ts +49 -0
  105. package/src/client/getActiveItemId.ts +54 -0
  106. package/src/client/use-i18n.ts +111 -0
  107. package/src/core/__tests__/component-analyzer.test.ts +141 -0
  108. package/src/core/__tests__/hydration-manifest.test.ts +223 -0
  109. package/src/core/__tests__/jsx.engine.test.ts +137 -0
  110. package/src/core/app-setup.ts +114 -0
  111. package/src/core/auto-register.module.ts +30 -0
  112. package/src/core/auto-wrap-middleware.ts +165 -0
  113. package/src/core/client-component-wrapper.ts +72 -0
  114. package/src/core/client-hydration.tsx +99 -0
  115. package/src/core/client-wrapper-browser.ts +40 -0
  116. package/src/core/component-analyzer.ts +89 -0
  117. package/src/core/component-auto-wrapper.ts +68 -0
  118. package/src/core/component-client-wrapper.ts +112 -0
  119. package/src/core/hydration-generator.ts +94 -0
  120. package/src/core/hydration-manifest.ts +79 -0
  121. package/src/core/hydration.ts +70 -0
  122. package/src/core/jsx.engine.ts +205 -0
  123. package/src/core/live-reload-client.js +32 -0
  124. package/src/core/live-reload.controller.ts +55 -0
  125. package/src/core/navigation.service.ts +257 -0
  126. package/src/core/router.module.ts +9 -0
  127. package/src/core/static-assets.controller.ts +19 -0
  128. package/src/core/types/nav.types.ts +53 -0
  129. package/src/core/views/layout.tsx +61 -0
  130. package/src/decorators/jsx.decorator.ts +49 -0
  131. package/src/decorators/layout.decorator.ts +66 -0
  132. package/src/i18n/__tests__/i18n.helper.test.ts +126 -0
  133. package/src/i18n/__tests__/i18n.interceptor.test.ts +229 -0
  134. package/src/i18n/__tests__/i18n.module.test.ts +98 -0
  135. package/src/i18n/__tests__/i18n.service.test.ts +129 -0
  136. package/src/i18n/__tests__/t.test.ts +88 -0
  137. package/src/i18n/i18n-module.options.ts +53 -0
  138. package/src/i18n/i18n-switcher.controller.ts +99 -0
  139. package/src/i18n/i18n-types.ts +56 -0
  140. package/src/i18n/i18n.helper.ts +75 -0
  141. package/src/i18n/i18n.interceptor.ts +114 -0
  142. package/src/i18n/i18n.module.ts +45 -0
  143. package/src/i18n/i18n.service.ts +95 -0
  144. package/src/i18n/index.ts +37 -0
  145. package/src/i18n/locale.decorator.ts +10 -0
  146. package/src/i18n/t.ts +62 -0
  147. package/src/index.ts +31 -0
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.createAutoWrapCreateElement = void 0;
37
+ exports.autoWrapIfUsesClient = autoWrapIfUsesClient;
38
+ exports.clearComponentAnalysisCache = clearComponentAnalysisCache;
39
+ const fs = __importStar(require("fs"));
40
+ const path = __importStar(require("path"));
41
+ const client_component_wrapper_1 = require("./client-component-wrapper");
42
+ const component_analyzer_1 = require("./component-analyzer");
43
+ const componentAnalysisCache = new Map();
44
+ function findComponentSourceFile(component) {
45
+ try {
46
+ if (component.__filename) {
47
+ return component.__filename;
48
+ }
49
+ const componentName = component.displayName || component.name;
50
+ if (!componentName)
51
+ return null;
52
+ const srcRoot = path.join(process.cwd(), "src");
53
+ const viewsDirs = fs.readdirSync(srcRoot).flatMap((feature) => {
54
+ const viewsPath = path.join(srcRoot, "features", feature, "views");
55
+ if (fs.existsSync(viewsPath)) {
56
+ return fs
57
+ .readdirSync(viewsPath)
58
+ .map((file) => path.join(viewsPath, file));
59
+ }
60
+ return [];
61
+ });
62
+ const kebabName = componentName
63
+ .replace(/([A-Z])/g, "-$1")
64
+ .toLowerCase()
65
+ .substring(1);
66
+ return (viewsDirs.find((f) => path.basename(f, path.extname(f)) === kebabName ||
67
+ path.basename(f, path.extname(f)) === componentName.toLowerCase()) || null);
68
+ }
69
+ catch (error) {
70
+ return null;
71
+ }
72
+ }
73
+ function hasUseClientDirective(filePath) {
74
+ try {
75
+ const content = fs.readFileSync(filePath, "utf-8");
76
+ return /^['"]use client['"];?\s*/.test(content);
77
+ }
78
+ catch {
79
+ return false;
80
+ }
81
+ }
82
+ function autoWrapIfUsesClient(component) {
83
+ if (componentAnalysisCache.has(component)) {
84
+ const cached = componentAnalysisCache.get(component);
85
+ if (cached.isClientComponent) {
86
+ return (0, client_component_wrapper_1.autoWrapClientComponent)(component, cached.componentName);
87
+ }
88
+ return component;
89
+ }
90
+ const sourceFile = findComponentSourceFile(component);
91
+ if (!sourceFile) {
92
+ componentAnalysisCache.set(component, {
93
+ isClientComponent: false,
94
+ componentName: component.displayName || component.name || "Unknown",
95
+ });
96
+ return component;
97
+ }
98
+ if (!hasUseClientDirective(sourceFile)) {
99
+ const componentName = (0, component_analyzer_1.getComponentNameFromPath)(sourceFile);
100
+ componentAnalysisCache.set(component, {
101
+ isClientComponent: false,
102
+ componentName,
103
+ });
104
+ return component;
105
+ }
106
+ const componentName = (0, component_analyzer_1.getComponentNameFromPath)(sourceFile);
107
+ componentAnalysisCache.set(component, {
108
+ isClientComponent: true,
109
+ componentName,
110
+ });
111
+ return (0, client_component_wrapper_1.autoWrapClientComponent)(component, componentName);
112
+ }
113
+ const createAutoWrapCreateElement = (originalCreateElement) => {
114
+ return (type, props, ...children) => {
115
+ if (typeof type === "function" && !type.prototype?.isReactComponent) {
116
+ try {
117
+ const wrappedType = autoWrapIfUsesClient(type);
118
+ return originalCreateElement(wrappedType, props, ...children);
119
+ }
120
+ catch (error) {
121
+ return originalCreateElement(type, props, ...children);
122
+ }
123
+ }
124
+ return originalCreateElement(type, props, ...children);
125
+ };
126
+ };
127
+ exports.createAutoWrapCreateElement = createAutoWrapCreateElement;
128
+ function clearComponentAnalysisCache() {
129
+ componentAnalysisCache.clear();
130
+ }
@@ -0,0 +1,5 @@
1
+ import React from "react";
2
+ declare global {
3
+ var __COMPONENT_REGISTRY__: ((data: any) => void) | undefined;
4
+ }
5
+ export declare function autoWrapClientComponent<T extends React.ComponentType<any>>(Component: T, componentName: string): React.ComponentType<React.ComponentProps<T>>;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.autoWrapClientComponent = autoWrapClientComponent;
7
+ const react_1 = __importDefault(require("react"));
8
+ function generateInstanceId(prefix) {
9
+ const randomId = Math.random().toString(36).substring(2, 11);
10
+ return `${prefix}-${randomId}`;
11
+ }
12
+ function autoWrapClientComponent(Component, componentName) {
13
+ const WrappedComponent = (props) => {
14
+ const instanceId = generateInstanceId(`hydrate-${componentName}`);
15
+ console.log(`[Wrapper] Rendering ${componentName}, registry available:`, typeof global !== "undefined" && !!global.__COMPONENT_REGISTRY__);
16
+ if (typeof global !== "undefined" && global.__COMPONENT_REGISTRY__) {
17
+ console.log(`[Wrapper] Registering ${componentName} with id ${instanceId}`);
18
+ global.__COMPONENT_REGISTRY__({
19
+ componentPath: "",
20
+ componentName,
21
+ instanceId,
22
+ props: props,
23
+ });
24
+ }
25
+ const propsJson = JSON.stringify(props);
26
+ return react_1.default.createElement("div", {
27
+ id: instanceId,
28
+ suppressHydrationWarning: true,
29
+ }, react_1.default.createElement(Component, props), react_1.default.createElement("script", {
30
+ type: "application/json",
31
+ id: `${instanceId}-props`,
32
+ dangerouslySetInnerHTML: { __html: propsJson },
33
+ }));
34
+ };
35
+ WrappedComponent.displayName = `ClientComponent(${componentName})`;
36
+ return WrappedComponent;
37
+ }
@@ -0,0 +1,2 @@
1
+ import React from "react";
2
+ export declare function hydrateComponent(componentName: string, Component: React.ComponentType<any>): void;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.hydrateComponent = hydrateComponent;
40
+ const react_1 = __importDefault(require("react"));
41
+ function findHydrationMarkers() {
42
+ const markers = [];
43
+ const hydrationDivs = document.querySelectorAll('div[id^="hydrate-"]');
44
+ hydrationDivs.forEach((div) => {
45
+ const instanceId = div.id;
46
+ const match = instanceId.match(/^hydrate-([^-]+)-(.+)$/);
47
+ if (match) {
48
+ const componentName = match[1];
49
+ const propsScriptId = `${instanceId}-props`;
50
+ markers.push({
51
+ componentName,
52
+ instanceId,
53
+ propsId: propsScriptId,
54
+ });
55
+ }
56
+ });
57
+ return markers;
58
+ }
59
+ function getHydrationProps(propsId) {
60
+ const propsScript = document.getElementById(propsId);
61
+ if (!propsScript)
62
+ return {};
63
+ try {
64
+ return JSON.parse(propsScript.textContent || "{}");
65
+ }
66
+ catch (e) {
67
+ console.warn(`Failed to parse props for ${propsId}:`, e);
68
+ return {};
69
+ }
70
+ }
71
+ function hydrateComponent(componentName, Component) {
72
+ const markers = findHydrationMarkers();
73
+ const relevantMarkers = markers.filter((m) => m.componentName === componentName);
74
+ relevantMarkers.forEach((marker) => {
75
+ const container = document.getElementById(marker.instanceId);
76
+ if (!container) {
77
+ console.warn(`Hydration container not found for ${marker.instanceId}`);
78
+ return;
79
+ }
80
+ const props = getHydrationProps(marker.propsId);
81
+ Promise.all([Promise.resolve().then(() => __importStar(require("react-dom/client")))]).then(([{ hydrateRoot }]) => {
82
+ try {
83
+ hydrateRoot(container, react_1.default.createElement(Component, props));
84
+ }
85
+ catch (error) {
86
+ console.error(`Failed to hydrate component ${componentName}:`, error);
87
+ }
88
+ });
89
+ });
90
+ }
91
+ if (typeof window !== "undefined") {
92
+ window.__HYDRATION__ = { hydrateComponent };
93
+ }
@@ -0,0 +1,2 @@
1
+ import React from "react";
2
+ export declare function hydrateClientComponent<T extends React.ComponentType<any>>(Component: T, componentName: string, props: Record<string, any>): React.ReactElement;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.hydrateClientComponent = hydrateClientComponent;
7
+ const react_1 = __importDefault(require("react"));
8
+ function generateBrowserInstanceId(prefix) {
9
+ const randomId = Math.random().toString(36).substring(2, 11);
10
+ return `${prefix}-${randomId}`;
11
+ }
12
+ function hydrateClientComponent(Component, componentName, props) {
13
+ const instanceId = generateBrowserInstanceId(`hydrate-${componentName}`);
14
+ return react_1.default.createElement("div", {
15
+ id: instanceId,
16
+ suppressHydrationWarning: true,
17
+ }, react_1.default.createElement(Component, props), react_1.default.createElement("script", {
18
+ type: "application/json",
19
+ id: `${instanceId}-props`,
20
+ dangerouslySetInnerHTML: { __html: JSON.stringify(props) },
21
+ }));
22
+ }
@@ -0,0 +1,4 @@
1
+ export declare function hasUseClientDirective(filePath: string): boolean;
2
+ export declare function getComponentNameFromPath(filePath: string): string;
3
+ export declare function findComponentFiles(dir: string, exclude?: string[]): string[];
4
+ export declare function getClientComponents(srcDir: string): string[];
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.hasUseClientDirective = hasUseClientDirective;
37
+ exports.getComponentNameFromPath = getComponentNameFromPath;
38
+ exports.findComponentFiles = findComponentFiles;
39
+ exports.getClientComponents = getClientComponents;
40
+ const fs = __importStar(require("fs"));
41
+ const path = __importStar(require("path"));
42
+ function hasUseClientDirective(filePath) {
43
+ try {
44
+ const content = fs.readFileSync(filePath, "utf-8");
45
+ const useClientRegex = /^(['"]use client['"];?\s*)/m;
46
+ return useClientRegex.test(content);
47
+ }
48
+ catch (error) {
49
+ console.error(`Error reading file ${filePath}:`, error);
50
+ return false;
51
+ }
52
+ }
53
+ function getComponentNameFromPath(filePath) {
54
+ const fileName = path.basename(filePath, path.extname(filePath));
55
+ return fileName
56
+ .split("-")
57
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
58
+ .join("");
59
+ }
60
+ function findComponentFiles(dir, exclude = []) {
61
+ const components = [];
62
+ function traverse(currentPath) {
63
+ try {
64
+ const files = fs.readdirSync(currentPath);
65
+ for (const file of files) {
66
+ const fullPath = path.join(currentPath, file);
67
+ const stat = fs.statSync(fullPath);
68
+ if (exclude.some((ex) => fullPath.includes(ex))) {
69
+ continue;
70
+ }
71
+ if (stat.isDirectory()) {
72
+ traverse(fullPath);
73
+ }
74
+ else if (file.endsWith(".tsx") || file.endsWith(".ts")) {
75
+ if (fullPath.includes("/views/") ||
76
+ file.endsWith(".component.ts") ||
77
+ file.endsWith(".component.tsx")) {
78
+ components.push(fullPath);
79
+ }
80
+ }
81
+ }
82
+ }
83
+ catch (error) {
84
+ console.error(`Error traversing directory ${currentPath}:`, error);
85
+ }
86
+ }
87
+ traverse(dir);
88
+ return components;
89
+ }
90
+ function getClientComponents(srcDir) {
91
+ const components = findComponentFiles(srcDir, [
92
+ "/node_modules/",
93
+ "/dist/",
94
+ "/test/",
95
+ "/core/",
96
+ ]);
97
+ return components.filter((componentPath) => hasUseClientDirective(componentPath));
98
+ }
@@ -0,0 +1,2 @@
1
+ import React from "react";
2
+ export declare function autoWrap<T extends React.ComponentType<any>>(Component: T, fileUrl: string): T;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.autoWrap = autoWrap;
37
+ const fs = __importStar(require("fs"));
38
+ const client_component_wrapper_1 = require("./client-component-wrapper");
39
+ const component_analyzer_1 = require("./component-analyzer");
40
+ const clientComponentCache = new Map();
41
+ function hasUseClientDirective(filePath) {
42
+ if (clientComponentCache.has(filePath)) {
43
+ return clientComponentCache.get(filePath);
44
+ }
45
+ try {
46
+ const content = fs.readFileSync(filePath, "utf-8");
47
+ const hasDirective = /^(['"]use client['"];?\s*)/m.test(content);
48
+ clientComponentCache.set(filePath, hasDirective);
49
+ return hasDirective;
50
+ }
51
+ catch (error) {
52
+ clientComponentCache.set(filePath, false);
53
+ return false;
54
+ }
55
+ }
56
+ function autoWrap(Component, fileUrl) {
57
+ const filePath = fileUrl.replace("file://", "");
58
+ if (!hasUseClientDirective(filePath)) {
59
+ return Component;
60
+ }
61
+ const componentName = (0, component_analyzer_1.getComponentNameFromPath)(filePath);
62
+ return (0, client_component_wrapper_1.autoWrapClientComponent)(Component, componentName);
63
+ }
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ export declare function createClientComponent<T extends React.ComponentType<any>>(Component: T, sourceFile: string): T;
3
+ export declare function autoWrapIfClient<T extends React.ComponentType<any>>(Component: T, filename: string): T;
4
+ export declare function clearComponentCache(): void;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.createClientComponent = createClientComponent;
37
+ exports.autoWrapIfClient = autoWrapIfClient;
38
+ exports.clearComponentCache = clearComponentCache;
39
+ const fs = __importStar(require("fs"));
40
+ const path = __importStar(require("path"));
41
+ const client_component_wrapper_1 = require("./client-component-wrapper");
42
+ const component_analyzer_1 = require("./component-analyzer");
43
+ const componentCache = new Map();
44
+ function detectClientComponent(sourceFilePath) {
45
+ const normalizedPath = path.resolve(sourceFilePath);
46
+ if (componentCache.has(normalizedPath)) {
47
+ const cached = componentCache.get(normalizedPath);
48
+ return {
49
+ isClientComponent: cached.isClientComponent,
50
+ componentPath: normalizedPath,
51
+ };
52
+ }
53
+ let isClientComponent = false;
54
+ try {
55
+ const content = fs.readFileSync(normalizedPath, "utf-8");
56
+ isClientComponent = /^['"]use client['"];?\s*/.test(content);
57
+ }
58
+ catch (error) {
59
+ isClientComponent = false;
60
+ }
61
+ componentCache.set(normalizedPath, {
62
+ isClientComponent,
63
+ wrappedComponent: null,
64
+ });
65
+ return { isClientComponent, componentPath: normalizedPath };
66
+ }
67
+ function createClientComponent(Component, sourceFile) {
68
+ const { isClientComponent, componentPath } = detectClientComponent(sourceFile);
69
+ if (!isClientComponent) {
70
+ return Component;
71
+ }
72
+ const componentName = (0, component_analyzer_1.getComponentNameFromPath)(componentPath);
73
+ return (0, client_component_wrapper_1.autoWrapClientComponent)(Component, componentName);
74
+ }
75
+ function autoWrapIfClient(Component, filename) {
76
+ return createClientComponent(Component, filename);
77
+ }
78
+ function clearComponentCache() {
79
+ componentCache.clear();
80
+ }
@@ -0,0 +1,2 @@
1
+ export declare function generateHydrationEntryFiles(srcDir: string, outputDir: string): string[];
2
+ export declare function getHydrationEntryFiles(outputDir: string): string[];
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.generateHydrationEntryFiles = generateHydrationEntryFiles;
37
+ exports.getHydrationEntryFiles = getHydrationEntryFiles;
38
+ const fs = __importStar(require("fs"));
39
+ const path = __importStar(require("path"));
40
+ const component_analyzer_1 = require("./component-analyzer");
41
+ function generateHydrationEntryFiles(srcDir, outputDir) {
42
+ const clientComponentPaths = (0, component_analyzer_1.getClientComponents)(srcDir);
43
+ if (!fs.existsSync(outputDir)) {
44
+ fs.mkdirSync(outputDir, { recursive: true });
45
+ }
46
+ const entryFiles = [];
47
+ for (const componentPath of clientComponentPaths) {
48
+ const componentName = (0, component_analyzer_1.getComponentNameFromPath)(componentPath);
49
+ const relativePath = path.relative(srcDir, componentPath);
50
+ const fromAssets = path.join(outputDir, "dummy.ts");
51
+ let importPath = path.relative(path.dirname(fromAssets), componentPath);
52
+ importPath = importPath.replace(/\\/g, "/");
53
+ importPath = importPath.replace(/\.tsx?$/, "");
54
+ const entryFileName = `${componentName}.ts`;
55
+ const entryFilePath = path.join(outputDir, entryFileName);
56
+ const entryContent = `
57
+ import { hydrateRoot } from 'react-dom/client';
58
+ import * as React from 'react';
59
+
60
+ // Import the client component
61
+ import ${componentName} from '${importPath}';
62
+
63
+ /**
64
+ * Auto-generated hydration entry for ${componentName}
65
+ * This file is bundled separately to reduce the main bundle size
66
+ */
67
+
68
+ // Find all instances of this component marked with data-hydration-id
69
+ const instances = document.querySelectorAll('[data-hydration-id]');
70
+
71
+ instances.forEach((element) => {
72
+ const hydrationId = element.getAttribute('data-hydration-id');
73
+ if (hydrationId) {
74
+ try {
75
+ // Hydrate the component
76
+ hydrateRoot(element, React.createElement(${componentName}));
77
+ console.log('[Hydration] Successfully hydrated ${componentName} (id: ' + hydrationId + ')');
78
+ } catch (error) {
79
+ console.error('[Hydration] Failed to hydrate ${componentName}:', error);
80
+ }
81
+ }
82
+ });
83
+ `.trim();
84
+ fs.writeFileSync(entryFilePath, entryContent, "utf-8");
85
+ entryFiles.push(entryFilePath);
86
+ console.log(`Generated hydration entry: ${entryFileName}`);
87
+ }
88
+ return entryFiles;
89
+ }
90
+ function getHydrationEntryFiles(outputDir) {
91
+ if (!fs.existsSync(outputDir)) {
92
+ return [];
93
+ }
94
+ return fs
95
+ .readdirSync(outputDir)
96
+ .filter((file) => file.endsWith(".ts") && !file.endsWith(".spec.ts"))
97
+ .map((file) => path.join(outputDir, file));
98
+ }
@@ -0,0 +1,7 @@
1
+ export interface HydrationManifest {
2
+ [componentName: string]: string;
3
+ }
4
+ export declare function getHydrationManifest(): HydrationManifest;
5
+ export declare function getChunkFileName(componentName: string): string | null;
6
+ export declare function getChunkPath(componentName: string): string | null;
7
+ export declare function invalidateManifestCache(): void;