@chidchanun/bcp 0.1.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/CHANGELOG.md +49 -0
- package/LICENSE +21 -0
- package/README.md +241 -0
- package/docs/caching.md +76 -0
- package/docs/configuration.md +97 -0
- package/docs/deployment.md +74 -0
- package/docs/getting-started.md +82 -0
- package/docs/middleware.md +58 -0
- package/docs/releasing.md +299 -0
- package/docs/routing.md +103 -0
- package/docs/security.md +57 -0
- package/package.json +68 -0
- package/packages/bundler/src/client-islands.ts +1457 -0
- package/packages/bundler/src/incremental-context.ts +206 -0
- package/packages/bundler/src/index.ts +1991 -0
- package/packages/bundler/src/module-graph.ts +317 -0
- package/packages/bundler/src/partial-hydration.ts +414 -0
- package/packages/bundler/src/production.ts +974 -0
- package/packages/bundler/src/server-production-middleware.ts +447 -0
- package/packages/bundler/src/server-production.ts +1193 -0
- package/packages/bundler/src/special-files.ts +131 -0
- package/packages/cache/src/index.ts +761 -0
- package/packages/cli/bin/bcp.mjs +93 -0
- package/packages/cli/src/args.ts +305 -0
- package/packages/cli/src/bootstrap.ts +514 -0
- package/packages/cli/src/index.ts +504 -0
- package/packages/cli/src/version.ts +45 -0
- package/packages/client/src/cache.ts +11 -0
- package/packages/client/src/config.ts +18 -0
- package/packages/client/src/error-boundary.tsx +149 -0
- package/packages/client/src/hydration.ts +3 -0
- package/packages/client/src/index.tsx +57 -0
- package/packages/client/src/islands.tsx +315 -0
- package/packages/client/src/metadata.ts +281 -0
- package/packages/client/src/navigation-loading.ts +52 -0
- package/packages/client/src/navigation-state.ts +80 -0
- package/packages/client/src/not-found.ts +34 -0
- package/packages/client/src/persistent-layout-runtime.ts +273 -0
- package/packages/client/src/router-v2.tsx +969 -0
- package/packages/client/src/router.tsx +1 -0
- package/packages/config/src/index.ts +1038 -0
- package/packages/env/src/index.ts +593 -0
- package/packages/router/src/advanced-router.ts +1032 -0
- package/packages/router/src/index.ts +1 -0
- package/packages/server/src/compression.ts +249 -0
- package/packages/server/src/dev-document-metadata.ts +154 -0
- package/packages/server/src/dev-hmr.ts +225 -0
- package/packages/server/src/index.ts +2265 -0
- package/packages/server/src/metadata.ts +478 -0
- package/packages/server/src/middleware-dev-server.ts +260 -0
- package/packages/server/src/middleware-loader.ts +140 -0
- package/packages/server/src/middleware-proxy.ts +516 -0
- package/packages/server/src/middleware.ts +704 -0
- package/packages/server/src/navigation-payload.ts +471 -0
- package/packages/server/src/production-server.ts +1746 -0
- package/packages/server/src/response-cache-proxy.ts +828 -0
- package/packages/server/src/security-proxy.ts +406 -0
- package/packages/server/src/security.ts +451 -0
- package/packages/server/src/standalone-production-runtime-v2.ts +2047 -0
- package/packages/server/src/standalone-production-runtime-v3.ts +250 -0
- package/packages/server/src/standalone-production-runtime-v4.ts +289 -0
- package/packages/server/src/standalone-production-runtime-v5.ts +289 -0
- package/packages/server/src/standalone-production-runtime.ts +1951 -0
- package/packages/server/src/standalone-production-server.ts +6 -0
- package/packages/server/src/static-assets.ts +262 -0
- package/packages/server/src/static-dev-server.ts +854 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import * as esbuild from "esbuild";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
performance,
|
|
5
|
+
} from "node:perf_hooks";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Configuration for a long-lived esbuild context.
|
|
9
|
+
*
|
|
10
|
+
* The context is intended for development builds where the same
|
|
11
|
+
* dependency graph is rebuilt multiple times.
|
|
12
|
+
*/
|
|
13
|
+
export interface IncrementalContextOptions
|
|
14
|
+
extends esbuild.BuildOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Absolute application/project root used for path resolution.
|
|
17
|
+
*/
|
|
18
|
+
projectRoot: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Small wrapper around esbuild.context().
|
|
23
|
+
*
|
|
24
|
+
* It keeps one esbuild context alive and exposes rebuild()/dispose()
|
|
25
|
+
* methods for a development server.
|
|
26
|
+
*/
|
|
27
|
+
export class IncrementalBuildContext {
|
|
28
|
+
private readonly projectRoot: string;
|
|
29
|
+
|
|
30
|
+
private readonly options: esbuild.BuildOptions;
|
|
31
|
+
|
|
32
|
+
private context: esbuild.BuildContext | null = null;
|
|
33
|
+
|
|
34
|
+
private lastResult:
|
|
35
|
+
esbuild.BuildResult | null = null;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Rebuild calls are serialized so two file-system events cannot
|
|
39
|
+
* mutate the same esbuild context concurrently.
|
|
40
|
+
*/
|
|
41
|
+
private rebuildQueue:
|
|
42
|
+
Promise<esbuild.BuildResult> =
|
|
43
|
+
Promise.reject(
|
|
44
|
+
new Error("No rebuild has been scheduled yet.")
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
private constructor(
|
|
48
|
+
options: IncrementalContextOptions
|
|
49
|
+
) {
|
|
50
|
+
const {
|
|
51
|
+
projectRoot,
|
|
52
|
+
...buildOptions
|
|
53
|
+
} = options;
|
|
54
|
+
|
|
55
|
+
this.projectRoot = projectRoot;
|
|
56
|
+
|
|
57
|
+
this.options = {
|
|
58
|
+
...buildOptions,
|
|
59
|
+
|
|
60
|
+
absWorkingDir:
|
|
61
|
+
projectRoot,
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The module graph needs build metadata.
|
|
65
|
+
*/
|
|
66
|
+
metafile: true,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Create and initialize a persistent esbuild context.
|
|
72
|
+
*/
|
|
73
|
+
static async create(
|
|
74
|
+
options: IncrementalContextOptions
|
|
75
|
+
): Promise<IncrementalBuildContext> {
|
|
76
|
+
const instance =
|
|
77
|
+
new IncrementalBuildContext(
|
|
78
|
+
options
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
await instance.initialize();
|
|
82
|
+
|
|
83
|
+
return instance;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Initializes the underlying esbuild context and performs the
|
|
88
|
+
* first build.
|
|
89
|
+
*/
|
|
90
|
+
private async initialize(): Promise<esbuild.BuildResult> {
|
|
91
|
+
if (this.context) {
|
|
92
|
+
return this.rebuild();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const startedAt =
|
|
96
|
+
performance.now();
|
|
97
|
+
|
|
98
|
+
this.context =
|
|
99
|
+
await esbuild.context(
|
|
100
|
+
this.options
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const result =
|
|
104
|
+
await this.rebuild();
|
|
105
|
+
|
|
106
|
+
const duration =
|
|
107
|
+
performance.now() -
|
|
108
|
+
startedAt;
|
|
109
|
+
|
|
110
|
+
console.log(
|
|
111
|
+
`[BCP] Initial incremental build: ${duration.toFixed(2)}ms`,
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Incrementally rebuilds the same context.
|
|
119
|
+
*
|
|
120
|
+
* esbuild can reuse information from the previous build when the
|
|
121
|
+
* context is kept alive.
|
|
122
|
+
*/
|
|
123
|
+
async rebuild(): Promise<esbuild.BuildResult> {
|
|
124
|
+
const previous =
|
|
125
|
+
this.rebuildQueue.catch(() =>
|
|
126
|
+
undefined,
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const next =
|
|
130
|
+
previous.then(async () => {
|
|
131
|
+
if (!this.context) {
|
|
132
|
+
throw new Error(
|
|
133
|
+
"IncrementalBuildContext is not initialized.",
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const startedAt =
|
|
138
|
+
performance.now();
|
|
139
|
+
|
|
140
|
+
const result =
|
|
141
|
+
await this.context.rebuild();
|
|
142
|
+
|
|
143
|
+
this.lastResult =
|
|
144
|
+
result;
|
|
145
|
+
|
|
146
|
+
if (
|
|
147
|
+
result.errors.length ===
|
|
148
|
+
0
|
|
149
|
+
) {
|
|
150
|
+
const duration =
|
|
151
|
+
performance.now() -
|
|
152
|
+
startedAt;
|
|
153
|
+
|
|
154
|
+
console.log(
|
|
155
|
+
`[BCP] Incremental rebuild: ${duration.toFixed(2)}ms`,
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return result;
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
this.rebuildQueue =
|
|
163
|
+
next;
|
|
164
|
+
|
|
165
|
+
return next;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Returns the latest successful/attempted build result.
|
|
170
|
+
*/
|
|
171
|
+
getLastResult():
|
|
172
|
+
esbuild.BuildResult | null {
|
|
173
|
+
return this.lastResult;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Returns the project root used by the context.
|
|
178
|
+
*/
|
|
179
|
+
getProjectRoot(): string {
|
|
180
|
+
return this.projectRoot;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Indicates whether the underlying esbuild context exists.
|
|
185
|
+
*/
|
|
186
|
+
isInitialized(): boolean {
|
|
187
|
+
return this.context !== null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Dispose the long-lived esbuild context.
|
|
192
|
+
*/
|
|
193
|
+
async dispose(): Promise<void> {
|
|
194
|
+
if (!this.context) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const context =
|
|
199
|
+
this.context;
|
|
200
|
+
|
|
201
|
+
this.context = null;
|
|
202
|
+
this.lastResult = null;
|
|
203
|
+
|
|
204
|
+
await context.dispose();
|
|
205
|
+
}
|
|
206
|
+
}
|