@flexireact/core 1.0.2 → 2.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.
- package/README.md +112 -112
- package/bin/flexireact.js +23 -0
- package/cli/index.ts +9 -21
- package/core/cli/{logger.js → logger.ts} +8 -2
- package/core/client/{hydration.js → hydration.ts} +10 -0
- package/core/client/{islands.js → islands.ts} +6 -1
- package/core/client/{navigation.js → navigation.ts} +10 -2
- package/core/client/{runtime.js → runtime.ts} +16 -0
- package/core/{index.js → index.ts} +2 -1
- package/core/islands/{index.js → index.ts} +16 -4
- package/core/{logger.js → logger.ts} +1 -1
- package/core/middleware/{index.js → index.ts} +32 -9
- package/core/plugins/{index.js → index.ts} +9 -6
- package/core/render/index.ts +1069 -0
- package/core/{render.js → render.ts} +7 -5
- package/core/router/index.ts +543 -0
- package/core/rsc/{index.js → index.ts} +6 -5
- package/core/server/{index.js → index.ts} +25 -6
- package/core/{server.js → server.ts} +8 -2
- package/core/ssg/{index.js → index.ts} +30 -5
- package/core/start-dev.ts +6 -0
- package/core/start-prod.ts +6 -0
- package/core/tsconfig.json +28 -0
- package/core/types.ts +239 -0
- package/package.json +19 -14
- package/cli/index.js +0 -992
- package/core/render/index.js +0 -773
- package/core/router/index.js +0 -296
- /package/core/{api.js → api.ts} +0 -0
- /package/core/build/{index.js → index.ts} +0 -0
- /package/core/client/{index.js → index.ts} +0 -0
- /package/core/{config.js → config.ts} +0 -0
- /package/core/{context.js → context.ts} +0 -0
- /package/core/{dev.js → dev.ts} +0 -0
- /package/core/{loader.js → loader.ts} +0 -0
- /package/core/{router.js → router.ts} +0 -0
- /package/core/{utils.js → utils.ts} +0 -0
|
@@ -19,19 +19,34 @@ import { ensureDir, cleanDir } from '../utils.js';
|
|
|
19
19
|
/**
|
|
20
20
|
* SSG Build Result
|
|
21
21
|
*/
|
|
22
|
+
interface SSGPage {
|
|
23
|
+
path: string;
|
|
24
|
+
file: string;
|
|
25
|
+
size: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface SSGError {
|
|
29
|
+
path: string;
|
|
30
|
+
error: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
22
33
|
export class SSGResult {
|
|
34
|
+
pages: SSGPage[];
|
|
35
|
+
errors: SSGError[];
|
|
36
|
+
duration: number;
|
|
37
|
+
|
|
23
38
|
constructor() {
|
|
24
39
|
this.pages = [];
|
|
25
40
|
this.errors = [];
|
|
26
41
|
this.duration = 0;
|
|
27
42
|
}
|
|
28
43
|
|
|
29
|
-
addPage(
|
|
30
|
-
this.pages.push({ path, file, size });
|
|
44
|
+
addPage(pagePath: string, file: string, size: number) {
|
|
45
|
+
this.pages.push({ path: pagePath, file, size });
|
|
31
46
|
}
|
|
32
47
|
|
|
33
|
-
addError(
|
|
34
|
-
this.errors.push({ path, error: error.message });
|
|
48
|
+
addError(pagePath: string, error: Error) {
|
|
49
|
+
this.errors.push({ path: pagePath, error: error.message });
|
|
35
50
|
}
|
|
36
51
|
|
|
37
52
|
get success() {
|
|
@@ -237,8 +252,18 @@ function formatSize(bytes) {
|
|
|
237
252
|
* Incremental Static Regeneration (ISR) support
|
|
238
253
|
* Allows pages to be regenerated after a specified interval
|
|
239
254
|
*/
|
|
255
|
+
interface ISRCacheEntry {
|
|
256
|
+
html: string;
|
|
257
|
+
generatedAt: number;
|
|
258
|
+
revalidateAfter: number | null;
|
|
259
|
+
}
|
|
260
|
+
|
|
240
261
|
export class ISRManager {
|
|
241
|
-
|
|
262
|
+
cache: Map<string, ISRCacheEntry>;
|
|
263
|
+
revalidating: Set<string>;
|
|
264
|
+
defaultRevalidate: number;
|
|
265
|
+
|
|
266
|
+
constructor(options: { defaultRevalidate?: number } = {}) {
|
|
242
267
|
this.cache = new Map();
|
|
243
268
|
this.revalidating = new Set();
|
|
244
269
|
this.defaultRevalidate = options.defaultRevalidate || 60; // seconds
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"rootDir": ".",
|
|
9
|
+
"strict": false,
|
|
10
|
+
"noImplicitAny": false,
|
|
11
|
+
"strictPropertyInitialization": false,
|
|
12
|
+
"useUnknownInCatchVariables": false,
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
"forceConsistentCasingInFileNames": true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"declaration": false,
|
|
18
|
+
"sourceMap": true,
|
|
19
|
+
"allowJs": true,
|
|
20
|
+
"checkJs": false,
|
|
21
|
+
"noEmit": true
|
|
22
|
+
},
|
|
23
|
+
"include": [
|
|
24
|
+
"*.ts",
|
|
25
|
+
"**/*.ts"
|
|
26
|
+
],
|
|
27
|
+
"exclude": ["node_modules", "dist"]
|
|
28
|
+
}
|
package/core/types.ts
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FlexiReact Core Types
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { IncomingMessage, ServerResponse } from 'http';
|
|
6
|
+
import type { ReactNode, ComponentType } from 'react';
|
|
7
|
+
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Config Types
|
|
10
|
+
// ============================================================================
|
|
11
|
+
|
|
12
|
+
export interface FlexiConfig {
|
|
13
|
+
/** Stylesheets to include */
|
|
14
|
+
styles?: string[];
|
|
15
|
+
/** Favicon path */
|
|
16
|
+
favicon?: string;
|
|
17
|
+
/** Server configuration */
|
|
18
|
+
server?: {
|
|
19
|
+
port?: number;
|
|
20
|
+
host?: string;
|
|
21
|
+
};
|
|
22
|
+
/** Islands configuration */
|
|
23
|
+
islands?: {
|
|
24
|
+
enabled?: boolean;
|
|
25
|
+
};
|
|
26
|
+
/** Routing configuration */
|
|
27
|
+
routing?: {
|
|
28
|
+
type?: 'flexi' | 'app' | 'pages';
|
|
29
|
+
};
|
|
30
|
+
/** Pages directory */
|
|
31
|
+
pagesDir?: string;
|
|
32
|
+
/** Layouts directory */
|
|
33
|
+
layoutsDir?: string;
|
|
34
|
+
/** Public directory */
|
|
35
|
+
publicDir?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ============================================================================
|
|
39
|
+
// Router Types
|
|
40
|
+
// ============================================================================
|
|
41
|
+
|
|
42
|
+
export type RouteType = 'page' | 'api' | 'layout' | 'loading' | 'error' | 'not-found';
|
|
43
|
+
|
|
44
|
+
export interface Route {
|
|
45
|
+
type: RouteType;
|
|
46
|
+
path: string;
|
|
47
|
+
filePath: string;
|
|
48
|
+
pattern: RegExp;
|
|
49
|
+
segments: string[];
|
|
50
|
+
layout?: string | null;
|
|
51
|
+
loading?: string | null;
|
|
52
|
+
error?: string | null;
|
|
53
|
+
notFound?: string | null;
|
|
54
|
+
template?: string | null;
|
|
55
|
+
isAppRouter?: boolean;
|
|
56
|
+
isFlexiRouter?: boolean;
|
|
57
|
+
isServerComponent?: boolean;
|
|
58
|
+
isClientComponent?: boolean;
|
|
59
|
+
isIsland?: boolean;
|
|
60
|
+
params?: Record<string, string>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface RouteTree {
|
|
64
|
+
pages: Route[];
|
|
65
|
+
api: Route[];
|
|
66
|
+
layouts: Map<string, string>;
|
|
67
|
+
tree: Record<string, unknown>;
|
|
68
|
+
appRoutes: Route[];
|
|
69
|
+
flexiRoutes: Route[];
|
|
70
|
+
rootLayout?: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface RouteMatch {
|
|
74
|
+
route: Route;
|
|
75
|
+
params: Record<string, string>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// ============================================================================
|
|
79
|
+
// Server Types
|
|
80
|
+
// ============================================================================
|
|
81
|
+
|
|
82
|
+
export type Request = IncomingMessage & {
|
|
83
|
+
params?: Record<string, string>;
|
|
84
|
+
query?: Record<string, string>;
|
|
85
|
+
body?: unknown;
|
|
86
|
+
json?: () => Promise<unknown>;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export type Response = ServerResponse & {
|
|
90
|
+
json?: (data: unknown) => void;
|
|
91
|
+
send?: (data: string) => void;
|
|
92
|
+
status?: (code: number) => Response;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export type NextFunction = () => void | Promise<void>;
|
|
96
|
+
|
|
97
|
+
export type Middleware = (
|
|
98
|
+
req: Request,
|
|
99
|
+
res: Response,
|
|
100
|
+
next: NextFunction
|
|
101
|
+
) => void | Promise<void>;
|
|
102
|
+
|
|
103
|
+
export type ApiHandler = (
|
|
104
|
+
req: Request,
|
|
105
|
+
res: Response
|
|
106
|
+
) => void | Promise<void>;
|
|
107
|
+
|
|
108
|
+
// ============================================================================
|
|
109
|
+
// Component Types
|
|
110
|
+
// ============================================================================
|
|
111
|
+
|
|
112
|
+
export interface PageProps {
|
|
113
|
+
params?: Record<string, string>;
|
|
114
|
+
searchParams?: Record<string, string>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface LayoutProps {
|
|
118
|
+
children: ReactNode;
|
|
119
|
+
params?: Record<string, string>;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface ErrorProps {
|
|
123
|
+
error: Error;
|
|
124
|
+
reset: () => void;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface LoadingProps {}
|
|
128
|
+
|
|
129
|
+
export interface NotFoundProps {}
|
|
130
|
+
|
|
131
|
+
export type PageComponent = ComponentType<PageProps>;
|
|
132
|
+
export type LayoutComponent = ComponentType<LayoutProps>;
|
|
133
|
+
export type ErrorComponent = ComponentType<ErrorProps>;
|
|
134
|
+
export type LoadingComponent = ComponentType<LoadingProps>;
|
|
135
|
+
export type NotFoundComponent = ComponentType<NotFoundProps>;
|
|
136
|
+
|
|
137
|
+
// ============================================================================
|
|
138
|
+
// Island Types
|
|
139
|
+
// ============================================================================
|
|
140
|
+
|
|
141
|
+
export interface IslandConfig {
|
|
142
|
+
name: string;
|
|
143
|
+
component: ComponentType<unknown>;
|
|
144
|
+
props?: Record<string, unknown>;
|
|
145
|
+
hydrate?: 'load' | 'idle' | 'visible' | 'media' | 'interaction';
|
|
146
|
+
media?: string;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface IslandManifest {
|
|
150
|
+
islands: Map<string, IslandConfig>;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ============================================================================
|
|
154
|
+
// Build Types
|
|
155
|
+
// ============================================================================
|
|
156
|
+
|
|
157
|
+
export interface BuildOptions {
|
|
158
|
+
outDir?: string;
|
|
159
|
+
minify?: boolean;
|
|
160
|
+
sourcemap?: boolean;
|
|
161
|
+
target?: string;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export interface BuildResult {
|
|
165
|
+
success: boolean;
|
|
166
|
+
errors?: string[];
|
|
167
|
+
warnings?: string[];
|
|
168
|
+
duration?: number;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// ============================================================================
|
|
172
|
+
// SSG Types
|
|
173
|
+
// ============================================================================
|
|
174
|
+
|
|
175
|
+
export interface StaticPath {
|
|
176
|
+
params: Record<string, string>;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export interface StaticProps {
|
|
180
|
+
props: Record<string, unknown>;
|
|
181
|
+
revalidate?: number | false;
|
|
182
|
+
notFound?: boolean;
|
|
183
|
+
redirect?: {
|
|
184
|
+
destination: string;
|
|
185
|
+
permanent?: boolean;
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export type GetStaticPaths = () => Promise<{
|
|
190
|
+
paths: StaticPath[];
|
|
191
|
+
fallback: boolean | 'blocking';
|
|
192
|
+
}>;
|
|
193
|
+
|
|
194
|
+
export type GetStaticProps = (context: {
|
|
195
|
+
params?: Record<string, string>;
|
|
196
|
+
}) => Promise<StaticProps>;
|
|
197
|
+
|
|
198
|
+
// ============================================================================
|
|
199
|
+
// Plugin Types
|
|
200
|
+
// ============================================================================
|
|
201
|
+
|
|
202
|
+
export interface Plugin {
|
|
203
|
+
name: string;
|
|
204
|
+
setup?: (config: FlexiConfig) => void | Promise<void>;
|
|
205
|
+
transform?: (code: string, id: string) => string | null | Promise<string | null>;
|
|
206
|
+
buildStart?: () => void | Promise<void>;
|
|
207
|
+
buildEnd?: () => void | Promise<void>;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// ============================================================================
|
|
211
|
+
// Metadata Types
|
|
212
|
+
// ============================================================================
|
|
213
|
+
|
|
214
|
+
export interface Metadata {
|
|
215
|
+
title?: string;
|
|
216
|
+
description?: string;
|
|
217
|
+
keywords?: string[];
|
|
218
|
+
author?: string;
|
|
219
|
+
openGraph?: {
|
|
220
|
+
title?: string;
|
|
221
|
+
description?: string;
|
|
222
|
+
image?: string;
|
|
223
|
+
url?: string;
|
|
224
|
+
type?: string;
|
|
225
|
+
};
|
|
226
|
+
twitter?: {
|
|
227
|
+
card?: 'summary' | 'summary_large_image' | 'app' | 'player';
|
|
228
|
+
title?: string;
|
|
229
|
+
description?: string;
|
|
230
|
+
image?: string;
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// ============================================================================
|
|
235
|
+
// Re-exports
|
|
236
|
+
// ============================================================================
|
|
237
|
+
|
|
238
|
+
export type { IncomingMessage, ServerResponse } from 'http';
|
|
239
|
+
export type { ReactNode, ComponentType } from 'react';
|
package/package.json
CHANGED
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flexireact/core",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "The Modern React Framework - SSR, SSG, Islands, TypeScript, Tailwind
|
|
5
|
-
"main": "core/index.
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "The Modern React Framework v2 - SSR, SSG, Islands, App Router, TypeScript, Tailwind",
|
|
5
|
+
"main": "core/index.ts",
|
|
6
|
+
"types": "core/types.ts",
|
|
6
7
|
"type": "module",
|
|
7
8
|
"bin": {
|
|
8
|
-
"flexireact": "./
|
|
9
|
-
"flexi": "./
|
|
9
|
+
"flexireact": "./bin/flexireact.js",
|
|
10
|
+
"flexi": "./bin/flexireact.js"
|
|
10
11
|
},
|
|
11
12
|
"exports": {
|
|
12
|
-
".": "./core/index.
|
|
13
|
-
"./client": "./core/client/index.
|
|
14
|
-
"./server": "./core/server/index.
|
|
15
|
-
"./render": "./core/render/index.
|
|
16
|
-
"./config": "./core/config.
|
|
13
|
+
".": "./core/index.ts",
|
|
14
|
+
"./client": "./core/client/index.ts",
|
|
15
|
+
"./server": "./core/server/index.ts",
|
|
16
|
+
"./render": "./core/render/index.ts",
|
|
17
|
+
"./config": "./core/config.ts",
|
|
18
|
+
"./types": "./core/types.ts"
|
|
17
19
|
},
|
|
18
20
|
"files": [
|
|
21
|
+
"bin",
|
|
19
22
|
"cli",
|
|
20
23
|
"core",
|
|
21
24
|
"README.md",
|
|
22
25
|
"LICENSE"
|
|
23
26
|
],
|
|
24
27
|
"scripts": {
|
|
25
|
-
"dev": "
|
|
26
|
-
"build": "
|
|
27
|
-
"start": "
|
|
28
|
-
"typecheck": "tsc --noEmit"
|
|
28
|
+
"dev": "npx tsx cli/index.ts dev",
|
|
29
|
+
"build": "npx tsx cli/index.ts build",
|
|
30
|
+
"start": "npx tsx cli/index.ts start",
|
|
31
|
+
"typecheck": "tsc --noEmit -p core/tsconfig.json"
|
|
29
32
|
},
|
|
30
33
|
"keywords": [
|
|
31
34
|
"react",
|
|
@@ -62,8 +65,10 @@
|
|
|
62
65
|
},
|
|
63
66
|
"devDependencies": {
|
|
64
67
|
"@types/node": "^22.10.1",
|
|
68
|
+
"@types/prompts": "^2.4.9",
|
|
65
69
|
"@types/react": "^18.3.14",
|
|
66
70
|
"@types/react-dom": "^18.3.2",
|
|
71
|
+
"tsx": "^4.21.0",
|
|
67
72
|
"typescript": "^5.7.2"
|
|
68
73
|
},
|
|
69
74
|
"engines": {
|