@chidchanun/bcp 0.1.3 → 0.1.5
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/CHANGELOG.md +25 -0
- package/README.md +33 -1
- package/docs/application-modules.md +116 -0
- package/docs/development-logging.md +13 -0
- package/package.json +6 -1
- package/packages/bundler/src/application-modules.ts +771 -0
- package/packages/bundler/src/client-boundary.ts +484 -0
- package/packages/cli/src/index.ts +36 -5
- package/packages/client/src/server-only.browser.mjs +7 -0
- package/packages/client/src/server-only.d.ts +1 -0
- package/packages/client/src/server-only.mjs +1 -0
- package/packages/server/src/dev-hmr.ts +86 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
All notable framework changes are tracked here before release.
|
|
4
4
|
|
|
5
|
+
## 0.1.5 - Application module boundaries
|
|
6
|
+
|
|
7
|
+
### Developer experience
|
|
8
|
+
|
|
9
|
+
- Added the `@/` project-root alias for generated applications across TypeScript and BCP runtime resolution.
|
|
10
|
+
- Generated applications use TypeScript Bundler module resolution so extensionless application imports match BCP runtime behavior.
|
|
11
|
+
- React client hooks in hydrated application modules require an explicit `"use client"` directive.
|
|
12
|
+
- Added `bcp/server-only` to prevent server dependencies from entering hydrated client bundles.
|
|
13
|
+
- Database helpers generated by `create-bcp-app` are marked server-only automatically and are intended to be consumed from API routes.
|
|
14
|
+
- Development HTTP request logs now focus on application API traffic and suppress `/_bcp/*`, page/static requests and the legacy internal Tailwind stylesheet endpoint.
|
|
15
|
+
- Generated Tailwind projects now link `/bcp.css` directly from `public/` instead of routing CSS through `/api/bcp-styles`, shortening the initial request path and allowing normal static-asset caching/revalidation.
|
|
16
|
+
|
|
17
|
+
## 0.1.4 - Tailwind runtime fix
|
|
18
|
+
|
|
19
|
+
### create-bcp-app
|
|
20
|
+
|
|
21
|
+
- Tailwind projects now install the official `@tailwindcss/cli` package and compile CSS before starting BCP.
|
|
22
|
+
- Development runs Tailwind in watch mode alongside `bcp dev` using `concurrently`.
|
|
23
|
+
- Production builds minify Tailwind CSS before `bcp build`.
|
|
24
|
+
- Generated Tailwind CSS is served through a framework API stylesheet endpoint with cache disabled during development.
|
|
25
|
+
- Root layout automatically links the generated stylesheet.
|
|
26
|
+
- Tailwind source detection is explicitly rooted at the generated project so utility classes in `app/` and other project files are discovered.
|
|
27
|
+
- Tailwind projects include starter utility classes so a fresh app visibly confirms that Tailwind is active.
|
|
28
|
+
- Fixed source generator metadata so local generator runs target `@chidchanun/bcp` instead of the unrelated unscoped `bcp` package.
|
|
29
|
+
|
|
5
30
|
## 0.1.3 - Interactive project setup
|
|
6
31
|
|
|
7
32
|
### create-bcp-app
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
BCP Framework is a React full-stack framework with file-based routing, SSR, client navigation, API routes, middleware, metadata, client islands, cache/revalidation, security defaults and standalone production builds.
|
|
4
4
|
|
|
5
|
-
> Current
|
|
5
|
+
> Current development version: `0.1.5`. BCP is still pre-1.0 and validates each release candidate before the manual npm publish step.
|
|
6
6
|
|
|
7
7
|
## Quick start
|
|
8
8
|
|
|
@@ -40,12 +40,43 @@ app/
|
|
|
40
40
|
└─ hello/
|
|
41
41
|
└─ route.ts
|
|
42
42
|
|
|
43
|
+
lib/
|
|
43
44
|
public/
|
|
44
45
|
bcp.config.ts
|
|
45
46
|
package.json
|
|
46
47
|
tsconfig.json
|
|
47
48
|
```
|
|
48
49
|
|
|
50
|
+
## Application imports and boundaries
|
|
51
|
+
|
|
52
|
+
Generated applications include the project-root `@/` alias:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import {
|
|
56
|
+
db,
|
|
57
|
+
} from "@/lib/database";
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Modules that use React client hooks must declare `"use client"`:
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
"use client";
|
|
64
|
+
|
|
65
|
+
import {
|
|
66
|
+
useState,
|
|
67
|
+
} from "react";
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Server-only modules can declare:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import "bcp/server-only";
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Database helpers generated by `create-bcp-app` include the server-only marker automatically. A server-only helper must not be imported from a page/client graph; put database work behind an API route instead.
|
|
77
|
+
|
|
78
|
+
See [Application Modules](docs/application-modules.md) for the complete boundary model and examples.
|
|
79
|
+
|
|
49
80
|
## Commands
|
|
50
81
|
|
|
51
82
|
```bash
|
|
@@ -224,6 +255,7 @@ No real npm publish command is run automatically by the repository.
|
|
|
224
255
|
## Documentation
|
|
225
256
|
|
|
226
257
|
- [Getting Started](docs/getting-started.md)
|
|
258
|
+
- [Application Modules](docs/application-modules.md)
|
|
227
259
|
- [Routing](docs/routing.md)
|
|
228
260
|
- [Configuration](docs/configuration.md)
|
|
229
261
|
- [Caching](docs/caching.md)
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# Application Modules
|
|
2
|
+
|
|
3
|
+
BCP applications can import project files through the project-root `@/` alias.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import {
|
|
7
|
+
db,
|
|
8
|
+
} from "@/lib/database";
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The generated `tsconfig.json` maps `@/*` to the project root. BCP also installs a Node.js resolver during development so the same alias works in SSR and API route modules. Production builds resolve the alias through the application bundler.
|
|
12
|
+
|
|
13
|
+
## Client modules
|
|
14
|
+
|
|
15
|
+
A page or shared module that uses React client hooks must begin with the `"use client"` directive.
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
"use client";
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
useEffect,
|
|
22
|
+
useState,
|
|
23
|
+
} from "react";
|
|
24
|
+
|
|
25
|
+
export default function UsersPage() {
|
|
26
|
+
const [users, setUsers] =
|
|
27
|
+
useState([]);
|
|
28
|
+
|
|
29
|
+
useEffect(
|
|
30
|
+
() => {
|
|
31
|
+
void fetch("/api/users")
|
|
32
|
+
.then(
|
|
33
|
+
(response) =>
|
|
34
|
+
response.json()
|
|
35
|
+
)
|
|
36
|
+
.then(
|
|
37
|
+
setUsers
|
|
38
|
+
);
|
|
39
|
+
},
|
|
40
|
+
[]
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<pre>
|
|
45
|
+
{JSON.stringify(users, null, 2)}
|
|
46
|
+
</pre>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
BCP checks client-reachable page/layout module graphs at development startup and production build time. Using React client hooks without `"use client"` causes a boundary error.
|
|
52
|
+
|
|
53
|
+
Client island files (`*.island.ts` and `*.island.tsx`) are already explicit client entry points and keep their existing island semantics.
|
|
54
|
+
|
|
55
|
+
## Server-only modules
|
|
56
|
+
|
|
57
|
+
Use `bcp/server-only` in modules that contain database clients, secrets, filesystem access, or other code that must never enter a browser bundle.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import "bcp/server-only";
|
|
61
|
+
|
|
62
|
+
import mysql from "mysql2/promise";
|
|
63
|
+
|
|
64
|
+
export const db =
|
|
65
|
+
mysql.createPool(
|
|
66
|
+
process.env.DATABASE_URL ??
|
|
67
|
+
""
|
|
68
|
+
);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Database helpers generated by `create-bcp-app` include this marker automatically.
|
|
72
|
+
|
|
73
|
+
Do not import a server-only module directly from a page or client component:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
// Not allowed in a page/client graph
|
|
77
|
+
import {
|
|
78
|
+
db,
|
|
79
|
+
} from "@/lib/database";
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Put the database operation behind an API route instead:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
// app/api/users/route.ts
|
|
86
|
+
import {
|
|
87
|
+
db,
|
|
88
|
+
} from "@/lib/database";
|
|
89
|
+
|
|
90
|
+
export async function GET() {
|
|
91
|
+
const [rows] =
|
|
92
|
+
await db.query(
|
|
93
|
+
"SELECT * FROM users"
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
return Response.json({
|
|
97
|
+
data: rows,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Then call the API from the client:
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
const response =
|
|
106
|
+
await fetch(
|
|
107
|
+
"/api/users"
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const result =
|
|
111
|
+
await response.json();
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Current boundary model
|
|
115
|
+
|
|
116
|
+
BCP 0.1.x is not a React Server Components implementation. Pages and layouts can participate in browser hydration, so server-only dependencies must remain behind API routes or other server execution paths. The boundary checks are designed to make that rule explicit and prevent accidental database or secret-bearing code from entering client bundles.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Development request logging
|
|
2
|
+
|
|
3
|
+
BCP keeps development request output focused on application API traffic.
|
|
4
|
+
|
|
5
|
+
By default, request-style console lines are shown for application API routes such as:
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
GET /api/users 200 1.24ms
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
BCP suppresses framework and browser bootstrap traffic such as `/_bcp/*`, page/document requests, public static assets, and the generated Tailwind stylesheet endpoint `/api/bcp-styles`.
|
|
12
|
+
|
|
13
|
+
Build, SSR, Fast Refresh, watcher and error diagnostics are not affected by this filter.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chidchanun/bcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "BCP Framework - a React full-stack framework with file-based routing, SSR, APIs, middleware, islands, caching and standalone production builds.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,6 +43,11 @@
|
|
|
43
43
|
"types": "./packages/client/src/config.ts",
|
|
44
44
|
"default": "./packages/client/src/config.ts"
|
|
45
45
|
},
|
|
46
|
+
"./server-only": {
|
|
47
|
+
"types": "./packages/client/src/server-only.d.ts",
|
|
48
|
+
"browser": "./packages/client/src/server-only.browser.mjs",
|
|
49
|
+
"default": "./packages/client/src/server-only.mjs"
|
|
50
|
+
},
|
|
46
51
|
"./middleware": {
|
|
47
52
|
"types": "./packages/server/src/middleware.ts",
|
|
48
53
|
"default": "./packages/server/src/middleware.ts"
|