@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.
Files changed (66) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/LICENSE +21 -0
  3. package/README.md +241 -0
  4. package/docs/caching.md +76 -0
  5. package/docs/configuration.md +97 -0
  6. package/docs/deployment.md +74 -0
  7. package/docs/getting-started.md +82 -0
  8. package/docs/middleware.md +58 -0
  9. package/docs/releasing.md +299 -0
  10. package/docs/routing.md +103 -0
  11. package/docs/security.md +57 -0
  12. package/package.json +68 -0
  13. package/packages/bundler/src/client-islands.ts +1457 -0
  14. package/packages/bundler/src/incremental-context.ts +206 -0
  15. package/packages/bundler/src/index.ts +1991 -0
  16. package/packages/bundler/src/module-graph.ts +317 -0
  17. package/packages/bundler/src/partial-hydration.ts +414 -0
  18. package/packages/bundler/src/production.ts +974 -0
  19. package/packages/bundler/src/server-production-middleware.ts +447 -0
  20. package/packages/bundler/src/server-production.ts +1193 -0
  21. package/packages/bundler/src/special-files.ts +131 -0
  22. package/packages/cache/src/index.ts +761 -0
  23. package/packages/cli/bin/bcp.mjs +93 -0
  24. package/packages/cli/src/args.ts +305 -0
  25. package/packages/cli/src/bootstrap.ts +514 -0
  26. package/packages/cli/src/index.ts +504 -0
  27. package/packages/cli/src/version.ts +45 -0
  28. package/packages/client/src/cache.ts +11 -0
  29. package/packages/client/src/config.ts +18 -0
  30. package/packages/client/src/error-boundary.tsx +149 -0
  31. package/packages/client/src/hydration.ts +3 -0
  32. package/packages/client/src/index.tsx +57 -0
  33. package/packages/client/src/islands.tsx +315 -0
  34. package/packages/client/src/metadata.ts +281 -0
  35. package/packages/client/src/navigation-loading.ts +52 -0
  36. package/packages/client/src/navigation-state.ts +80 -0
  37. package/packages/client/src/not-found.ts +34 -0
  38. package/packages/client/src/persistent-layout-runtime.ts +273 -0
  39. package/packages/client/src/router-v2.tsx +969 -0
  40. package/packages/client/src/router.tsx +1 -0
  41. package/packages/config/src/index.ts +1038 -0
  42. package/packages/env/src/index.ts +593 -0
  43. package/packages/router/src/advanced-router.ts +1032 -0
  44. package/packages/router/src/index.ts +1 -0
  45. package/packages/server/src/compression.ts +249 -0
  46. package/packages/server/src/dev-document-metadata.ts +154 -0
  47. package/packages/server/src/dev-hmr.ts +225 -0
  48. package/packages/server/src/index.ts +2265 -0
  49. package/packages/server/src/metadata.ts +478 -0
  50. package/packages/server/src/middleware-dev-server.ts +260 -0
  51. package/packages/server/src/middleware-loader.ts +140 -0
  52. package/packages/server/src/middleware-proxy.ts +516 -0
  53. package/packages/server/src/middleware.ts +704 -0
  54. package/packages/server/src/navigation-payload.ts +471 -0
  55. package/packages/server/src/production-server.ts +1746 -0
  56. package/packages/server/src/response-cache-proxy.ts +828 -0
  57. package/packages/server/src/security-proxy.ts +406 -0
  58. package/packages/server/src/security.ts +451 -0
  59. package/packages/server/src/standalone-production-runtime-v2.ts +2047 -0
  60. package/packages/server/src/standalone-production-runtime-v3.ts +250 -0
  61. package/packages/server/src/standalone-production-runtime-v4.ts +289 -0
  62. package/packages/server/src/standalone-production-runtime-v5.ts +289 -0
  63. package/packages/server/src/standalone-production-runtime.ts +1951 -0
  64. package/packages/server/src/standalone-production-server.ts +6 -0
  65. package/packages/server/src/static-assets.ts +262 -0
  66. 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
+ }