@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,93 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
spawn,
|
|
5
|
+
} from "node:child_process";
|
|
6
|
+
import {
|
|
7
|
+
fileURLToPath,
|
|
8
|
+
} from "node:url";
|
|
9
|
+
|
|
10
|
+
const bootstrapFile =
|
|
11
|
+
fileURLToPath(
|
|
12
|
+
new URL(
|
|
13
|
+
"../src/bootstrap.ts",
|
|
14
|
+
import.meta.url
|
|
15
|
+
)
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const tsxImport =
|
|
19
|
+
import.meta.resolve(
|
|
20
|
+
"tsx"
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const child =
|
|
24
|
+
spawn(
|
|
25
|
+
process.execPath,
|
|
26
|
+
[
|
|
27
|
+
"--import",
|
|
28
|
+
tsxImport,
|
|
29
|
+
bootstrapFile,
|
|
30
|
+
...process.argv.slice(2),
|
|
31
|
+
],
|
|
32
|
+
{
|
|
33
|
+
cwd:
|
|
34
|
+
process.cwd(),
|
|
35
|
+
env:
|
|
36
|
+
process.env,
|
|
37
|
+
stdio:
|
|
38
|
+
"inherit",
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
for (
|
|
43
|
+
const signal
|
|
44
|
+
of [
|
|
45
|
+
"SIGINT",
|
|
46
|
+
"SIGTERM",
|
|
47
|
+
]
|
|
48
|
+
) {
|
|
49
|
+
process.once(
|
|
50
|
+
signal,
|
|
51
|
+
() => {
|
|
52
|
+
if (
|
|
53
|
+
child.exitCode === null &&
|
|
54
|
+
child.signalCode === null
|
|
55
|
+
) {
|
|
56
|
+
child.kill(
|
|
57
|
+
signal
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
child.once(
|
|
65
|
+
"error",
|
|
66
|
+
(error) => {
|
|
67
|
+
console.error(
|
|
68
|
+
"BCP Framework CLI failed to start:",
|
|
69
|
+
error
|
|
70
|
+
);
|
|
71
|
+
process.exitCode =
|
|
72
|
+
1;
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
child.once(
|
|
77
|
+
"exit",
|
|
78
|
+
(
|
|
79
|
+
code,
|
|
80
|
+
signal
|
|
81
|
+
) => {
|
|
82
|
+
if (signal) {
|
|
83
|
+
process.kill(
|
|
84
|
+
process.pid,
|
|
85
|
+
signal
|
|
86
|
+
);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
process.exitCode =
|
|
91
|
+
code ?? 1;
|
|
92
|
+
}
|
|
93
|
+
);
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
export type CliCommand =
|
|
5
|
+
| "dev"
|
|
6
|
+
| "build"
|
|
7
|
+
| "start"
|
|
8
|
+
| "routes"
|
|
9
|
+
| "help"
|
|
10
|
+
| "version";
|
|
11
|
+
|
|
12
|
+
export interface CliOptions {
|
|
13
|
+
command: CliCommand;
|
|
14
|
+
|
|
15
|
+
rootDirectory?: string;
|
|
16
|
+
|
|
17
|
+
port?: number;
|
|
18
|
+
|
|
19
|
+
hostname?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function parseCliArgs(
|
|
23
|
+
argv: string[]
|
|
24
|
+
): CliOptions {
|
|
25
|
+
let command: CliCommand = "dev";
|
|
26
|
+
|
|
27
|
+
let rootDirectory:
|
|
28
|
+
string | undefined;
|
|
29
|
+
|
|
30
|
+
let port:
|
|
31
|
+
number | undefined;
|
|
32
|
+
|
|
33
|
+
let hostname:
|
|
34
|
+
string | undefined;
|
|
35
|
+
|
|
36
|
+
let commandSet = false;
|
|
37
|
+
|
|
38
|
+
for (
|
|
39
|
+
let index = 0;
|
|
40
|
+
index < argv.length;
|
|
41
|
+
index++
|
|
42
|
+
) {
|
|
43
|
+
const argument = argv[index];
|
|
44
|
+
|
|
45
|
+
if (
|
|
46
|
+
argument === "-h" ||
|
|
47
|
+
argument === "--help"
|
|
48
|
+
) {
|
|
49
|
+
command = "help";
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (
|
|
54
|
+
argument === "-v" ||
|
|
55
|
+
argument === "--version"
|
|
56
|
+
) {
|
|
57
|
+
command = "version";
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (
|
|
62
|
+
argument === "--root"
|
|
63
|
+
) {
|
|
64
|
+
rootDirectory =
|
|
65
|
+
requireValue(
|
|
66
|
+
argv,
|
|
67
|
+
++index,
|
|
68
|
+
"--root"
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (
|
|
75
|
+
argument.startsWith(
|
|
76
|
+
"--root="
|
|
77
|
+
)
|
|
78
|
+
) {
|
|
79
|
+
rootDirectory =
|
|
80
|
+
argument.slice(
|
|
81
|
+
"--root=".length
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (
|
|
88
|
+
argument === "--port"
|
|
89
|
+
) {
|
|
90
|
+
port = parsePort(
|
|
91
|
+
requireValue(
|
|
92
|
+
argv,
|
|
93
|
+
++index,
|
|
94
|
+
"--port"
|
|
95
|
+
)
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (
|
|
102
|
+
argument.startsWith(
|
|
103
|
+
"--port="
|
|
104
|
+
)
|
|
105
|
+
) {
|
|
106
|
+
port = parsePort(
|
|
107
|
+
argument.slice(
|
|
108
|
+
"--port=".length
|
|
109
|
+
)
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (
|
|
116
|
+
argument === "--hostname" ||
|
|
117
|
+
argument === "--host"
|
|
118
|
+
) {
|
|
119
|
+
hostname =
|
|
120
|
+
requireValue(
|
|
121
|
+
argv,
|
|
122
|
+
++index,
|
|
123
|
+
argument
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (
|
|
130
|
+
argument.startsWith(
|
|
131
|
+
"--hostname="
|
|
132
|
+
)
|
|
133
|
+
) {
|
|
134
|
+
hostname =
|
|
135
|
+
argument.slice(
|
|
136
|
+
"--hostname=".length
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (
|
|
143
|
+
argument.startsWith(
|
|
144
|
+
"--host="
|
|
145
|
+
)
|
|
146
|
+
) {
|
|
147
|
+
hostname =
|
|
148
|
+
argument.slice(
|
|
149
|
+
"--host=".length
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (
|
|
156
|
+
argument.startsWith("-")
|
|
157
|
+
) {
|
|
158
|
+
throw new Error(
|
|
159
|
+
`Unknown option: ${argument}`
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* npm compatibility
|
|
165
|
+
*
|
|
166
|
+
* Some npm environments may consume an unknown script
|
|
167
|
+
* option such as --port and leave only its numeric value
|
|
168
|
+
* in argv. Accept a bare number for dev/start servers.
|
|
169
|
+
*/
|
|
170
|
+
if (
|
|
171
|
+
isPortShortcut(argument) &&
|
|
172
|
+
(
|
|
173
|
+
!commandSet ||
|
|
174
|
+
command === "dev" ||
|
|
175
|
+
command === "start"
|
|
176
|
+
)
|
|
177
|
+
) {
|
|
178
|
+
port = parsePort(argument);
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (commandSet) {
|
|
183
|
+
throw new Error(
|
|
184
|
+
`Unexpected argument: ${argument}`
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (
|
|
189
|
+
argument === "dev" ||
|
|
190
|
+
argument === "build" ||
|
|
191
|
+
argument === "start" ||
|
|
192
|
+
argument === "routes" ||
|
|
193
|
+
argument === "help" ||
|
|
194
|
+
argument === "version"
|
|
195
|
+
) {
|
|
196
|
+
command = argument;
|
|
197
|
+
commandSet = true;
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
throw new Error(
|
|
202
|
+
`Unknown command: ${argument}`
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
command,
|
|
208
|
+
rootDirectory,
|
|
209
|
+
port,
|
|
210
|
+
hostname,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function resolveProjectRoot(
|
|
215
|
+
rootDirectory?: string
|
|
216
|
+
): string {
|
|
217
|
+
if (rootDirectory) {
|
|
218
|
+
return path.resolve(
|
|
219
|
+
process.cwd(),
|
|
220
|
+
rootDirectory
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const currentDirectory =
|
|
225
|
+
process.cwd();
|
|
226
|
+
|
|
227
|
+
if (
|
|
228
|
+
hasAppDirectory(
|
|
229
|
+
currentDirectory
|
|
230
|
+
)
|
|
231
|
+
) {
|
|
232
|
+
return currentDirectory;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const exampleDirectory =
|
|
236
|
+
path.join(
|
|
237
|
+
currentDirectory,
|
|
238
|
+
"examples",
|
|
239
|
+
"basic-app"
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
if (
|
|
243
|
+
hasAppDirectory(
|
|
244
|
+
exampleDirectory
|
|
245
|
+
)
|
|
246
|
+
) {
|
|
247
|
+
return exampleDirectory;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return currentDirectory;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function hasAppDirectory(
|
|
254
|
+
directory: string
|
|
255
|
+
): boolean {
|
|
256
|
+
return fs.existsSync(
|
|
257
|
+
path.join(
|
|
258
|
+
directory,
|
|
259
|
+
"app"
|
|
260
|
+
)
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function requireValue(
|
|
265
|
+
argv: string[],
|
|
266
|
+
index: number,
|
|
267
|
+
option: string
|
|
268
|
+
): string {
|
|
269
|
+
const value = argv[index];
|
|
270
|
+
|
|
271
|
+
if (
|
|
272
|
+
!value ||
|
|
273
|
+
value.startsWith("-")
|
|
274
|
+
) {
|
|
275
|
+
throw new Error(
|
|
276
|
+
`Option ${option} requires a value.`
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return value;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function parsePort(
|
|
284
|
+
value: string
|
|
285
|
+
): number {
|
|
286
|
+
const port = Number(value);
|
|
287
|
+
|
|
288
|
+
if (
|
|
289
|
+
!Number.isInteger(port) ||
|
|
290
|
+
port < 1 ||
|
|
291
|
+
port > 65535
|
|
292
|
+
) {
|
|
293
|
+
throw new Error(
|
|
294
|
+
`Invalid port: ${value}. Port must be an integer between 1 and 65535.`
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return port;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function isPortShortcut(
|
|
302
|
+
value: string
|
|
303
|
+
): boolean {
|
|
304
|
+
return /^\d+$/.test(value);
|
|
305
|
+
}
|