@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,131 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
export type SpecialFileName =
|
|
5
|
+
| "error"
|
|
6
|
+
| "not-found";
|
|
7
|
+
|
|
8
|
+
export function findNearestSpecialFile(
|
|
9
|
+
appDirectory: string,
|
|
10
|
+
pageFilePath: string,
|
|
11
|
+
name: SpecialFileName
|
|
12
|
+
): string | null {
|
|
13
|
+
const appRoot =
|
|
14
|
+
path.resolve(
|
|
15
|
+
appDirectory
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
let currentDirectory =
|
|
19
|
+
path.dirname(
|
|
20
|
+
path.resolve(
|
|
21
|
+
pageFilePath
|
|
22
|
+
)
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
while (true) {
|
|
26
|
+
const specialFile =
|
|
27
|
+
findSpecialFileInDirectory(
|
|
28
|
+
currentDirectory,
|
|
29
|
+
name
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
if (specialFile) {
|
|
33
|
+
return specialFile;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (
|
|
37
|
+
currentDirectory ===
|
|
38
|
+
appRoot
|
|
39
|
+
) {
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const parent =
|
|
44
|
+
path.dirname(
|
|
45
|
+
currentDirectory
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
if (
|
|
49
|
+
parent ===
|
|
50
|
+
currentDirectory ||
|
|
51
|
+
!isInsideDirectory(
|
|
52
|
+
appRoot,
|
|
53
|
+
parent
|
|
54
|
+
)
|
|
55
|
+
) {
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
currentDirectory =
|
|
60
|
+
parent;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function findSpecialFileInDirectory(
|
|
67
|
+
directory: string,
|
|
68
|
+
name: SpecialFileName
|
|
69
|
+
): string | null {
|
|
70
|
+
const tsxFile =
|
|
71
|
+
path.join(
|
|
72
|
+
directory,
|
|
73
|
+
`${name}.tsx`
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const tsFile =
|
|
77
|
+
path.join(
|
|
78
|
+
directory,
|
|
79
|
+
`${name}.ts`
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const hasTsx =
|
|
83
|
+
fs.existsSync(
|
|
84
|
+
tsxFile
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const hasTs =
|
|
88
|
+
fs.existsSync(
|
|
89
|
+
tsFile
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
if (
|
|
93
|
+
hasTsx &&
|
|
94
|
+
hasTs
|
|
95
|
+
) {
|
|
96
|
+
throw new Error(
|
|
97
|
+
`BCP Framework: both ${name}.ts and ${name}.tsx exist in "${directory}".`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (hasTsx) {
|
|
102
|
+
return tsxFile;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (hasTs) {
|
|
106
|
+
return tsFile;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function isInsideDirectory(
|
|
113
|
+
rootDirectory: string,
|
|
114
|
+
candidate: string
|
|
115
|
+
): boolean {
|
|
116
|
+
const relative =
|
|
117
|
+
path.relative(
|
|
118
|
+
rootDirectory,
|
|
119
|
+
candidate
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
relative === "" ||
|
|
124
|
+
(
|
|
125
|
+
!relative.startsWith("..") &&
|
|
126
|
+
!path.isAbsolute(
|
|
127
|
+
relative
|
|
128
|
+
)
|
|
129
|
+
)
|
|
130
|
+
);
|
|
131
|
+
}
|