veryfront 0.1.82 → 0.1.84

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 (93) hide show
  1. package/esm/cli/commands/knowledge/command.d.ts +10 -13
  2. package/esm/cli/commands/knowledge/command.d.ts.map +1 -1
  3. package/esm/cli/commands/knowledge/command.js +294 -110
  4. package/esm/cli/commands/knowledge/parser-source.d.ts.map +1 -1
  5. package/esm/cli/commands/knowledge/parser-source.js +52 -0
  6. package/esm/cli/commands/knowledge/result.d.ts +54 -0
  7. package/esm/cli/commands/knowledge/result.d.ts.map +1 -0
  8. package/esm/cli/commands/knowledge/result.js +22 -0
  9. package/esm/cli/commands/knowledge/source-policy.d.ts +11 -0
  10. package/esm/cli/commands/knowledge/source-policy.d.ts.map +1 -0
  11. package/esm/cli/commands/knowledge/source-policy.js +135 -0
  12. package/esm/deno.js +1 -1
  13. package/esm/src/jobs/index.d.ts +1 -1
  14. package/esm/src/jobs/index.d.ts.map +1 -1
  15. package/esm/src/jobs/index.js +1 -1
  16. package/esm/src/jobs/schemas.d.ts +1104 -185
  17. package/esm/src/jobs/schemas.d.ts.map +1 -1
  18. package/esm/src/jobs/schemas.js +81 -8
  19. package/esm/src/platform/adapters/base.d.ts +4 -1
  20. package/esm/src/platform/adapters/base.d.ts.map +1 -1
  21. package/esm/src/platform/adapters/fs/github/adapter.d.ts +2 -1
  22. package/esm/src/platform/adapters/fs/github/adapter.d.ts.map +1 -1
  23. package/esm/src/platform/adapters/fs/github/adapter.js +2 -2
  24. package/esm/src/platform/adapters/fs/github/stat-operations.d.ts +2 -1
  25. package/esm/src/platform/adapters/fs/github/stat-operations.d.ts.map +1 -1
  26. package/esm/src/platform/adapters/fs/github/stat-operations.js +2 -2
  27. package/esm/src/platform/adapters/fs/veryfront/adapter.d.ts +2 -2
  28. package/esm/src/platform/adapters/fs/veryfront/adapter.d.ts.map +1 -1
  29. package/esm/src/platform/adapters/fs/veryfront/adapter.js +17 -2
  30. package/esm/src/platform/adapters/fs/veryfront/multi-project-adapter.d.ts +2 -2
  31. package/esm/src/platform/adapters/fs/veryfront/multi-project-adapter.d.ts.map +1 -1
  32. package/esm/src/platform/adapters/fs/veryfront/multi-project-adapter.js +2 -2
  33. package/esm/src/platform/adapters/fs/veryfront/read-operations.d.ts +1 -0
  34. package/esm/src/platform/adapters/fs/veryfront/read-operations.d.ts.map +1 -1
  35. package/esm/src/platform/adapters/fs/veryfront/stat-operations.d.ts +6 -2
  36. package/esm/src/platform/adapters/fs/veryfront/stat-operations.d.ts.map +1 -1
  37. package/esm/src/platform/adapters/fs/veryfront/stat-operations.js +131 -21
  38. package/esm/src/platform/adapters/fs/veryfront/types.d.ts +2 -1
  39. package/esm/src/platform/adapters/fs/veryfront/types.d.ts.map +1 -1
  40. package/esm/src/platform/adapters/fs/wrapper.d.ts +2 -2
  41. package/esm/src/platform/adapters/fs/wrapper.d.ts.map +1 -1
  42. package/esm/src/platform/adapters/fs/wrapper.js +2 -2
  43. package/esm/src/proxy/error-response.d.ts +7 -0
  44. package/esm/src/proxy/error-response.d.ts.map +1 -0
  45. package/esm/src/proxy/error-response.js +26 -0
  46. package/esm/src/proxy/handler.d.ts.map +1 -1
  47. package/esm/src/proxy/handler.js +25 -0
  48. package/esm/src/proxy/main.js +2 -23
  49. package/esm/src/rendering/app-route-resolver.js +0 -9
  50. package/esm/src/rendering/orchestrator/file-resolver/index.d.ts.map +1 -1
  51. package/esm/src/rendering/orchestrator/file-resolver/index.js +17 -0
  52. package/esm/src/rendering/page-resolution/page-resolver.d.ts.map +1 -1
  53. package/esm/src/rendering/page-resolution/page-resolver.js +19 -6
  54. package/esm/src/rendering/router-detection.d.ts +1 -0
  55. package/esm/src/rendering/router-detection.d.ts.map +1 -1
  56. package/esm/src/rendering/router-detection.js +3 -0
  57. package/esm/src/transforms/esm/http-cache-helpers.d.ts.map +1 -1
  58. package/esm/src/transforms/esm/http-cache-helpers.js +7 -1
  59. package/esm/src/transforms/import-rewriter/strategies/bare-strategy.d.ts.map +1 -1
  60. package/esm/src/transforms/import-rewriter/strategies/bare-strategy.js +11 -8
  61. package/esm/src/transforms/shared/package-specifier.d.ts +7 -0
  62. package/esm/src/transforms/shared/package-specifier.d.ts.map +1 -0
  63. package/esm/src/transforms/shared/package-specifier.js +19 -0
  64. package/esm/src/types/entities/getEntityInfo.d.ts.map +1 -1
  65. package/esm/src/types/entities/getEntityInfo.js +59 -42
  66. package/package.json +1 -1
  67. package/src/cli/commands/knowledge/command.ts +375 -139
  68. package/src/cli/commands/knowledge/parser-source.ts +52 -0
  69. package/src/cli/commands/knowledge/result.ts +88 -0
  70. package/src/cli/commands/knowledge/source-policy.ts +164 -0
  71. package/src/deno.js +1 -1
  72. package/src/src/jobs/index.ts +16 -0
  73. package/src/src/jobs/schemas.ts +105 -8
  74. package/src/src/platform/adapters/base.ts +5 -1
  75. package/src/src/platform/adapters/fs/github/adapter.ts +3 -2
  76. package/src/src/platform/adapters/fs/github/stat-operations.ts +3 -2
  77. package/src/src/platform/adapters/fs/veryfront/adapter.ts +24 -3
  78. package/src/src/platform/adapters/fs/veryfront/multi-project-adapter.ts +6 -3
  79. package/src/src/platform/adapters/fs/veryfront/read-operations.ts +1 -0
  80. package/src/src/platform/adapters/fs/veryfront/stat-operations.ts +161 -25
  81. package/src/src/platform/adapters/fs/veryfront/types.ts +2 -1
  82. package/src/src/platform/adapters/fs/wrapper.ts +10 -3
  83. package/src/src/proxy/error-response.ts +33 -0
  84. package/src/src/proxy/handler.ts +43 -0
  85. package/src/src/proxy/main.ts +2 -27
  86. package/src/src/rendering/app-route-resolver.ts +0 -8
  87. package/src/src/rendering/orchestrator/file-resolver/index.ts +19 -0
  88. package/src/src/rendering/page-resolution/page-resolver.ts +26 -17
  89. package/src/src/rendering/router-detection.ts +7 -0
  90. package/src/src/transforms/esm/http-cache-helpers.ts +12 -1
  91. package/src/src/transforms/import-rewriter/strategies/bare-strategy.ts +11 -12
  92. package/src/src/transforms/shared/package-specifier.ts +29 -0
  93. package/src/src/types/entities/getEntityInfo.ts +78 -59
@@ -13,6 +13,7 @@ import type {
13
13
  RewriteResult,
14
14
  } from "../types.js";
15
15
  import { buildEsmShUrl, TAILWIND_VERSION } from "../url-builder.js";
16
+ import { parseBarePackageSpecifier } from "../../shared/package-specifier.js";
16
17
 
17
18
  const logger = rendererLogger.component("esm");
18
19
 
@@ -22,10 +23,6 @@ function hasVersionSpecifier(specifier: string): boolean {
22
23
  return /@[\d^~x][\d.x^~-]*(?=\/|$)/.test(specifier);
23
24
  }
24
25
 
25
- function normalizeVersionedSpecifier(specifier: string): string {
26
- return specifier.replace(/@[\d^~x][\d.x^~-]*(?=\/|$)/, "");
27
- }
28
-
29
26
  function warnUnversionedImport(specifier: string, projectId: string): void {
30
27
  const key = `${projectId}:${specifier}`;
31
28
  if (unversionedImportsWarned.has(key)) return;
@@ -73,20 +70,22 @@ export class BareStrategy implements ImportRewriteStrategy {
73
70
  rewrite(info: ImportSpecifierInfo, ctx: RewriteContext): RewriteResult {
74
71
  if (ctx.target === "ssr") return { specifier: null };
75
72
 
76
- const normalized = normalizeVersionedSpecifier(info.specifier);
73
+ const parsed = parseBarePackageSpecifier(info.specifier);
74
+ if (parsed == null) {
75
+ return { specifier: null };
76
+ }
77
77
 
78
- let finalSpecifier = normalized;
78
+ const packageName = parsed.packageName;
79
+ let version = parsed.version ?? undefined;
80
+ const subpath = parsed.subpath ?? undefined;
79
81
 
80
- if (normalized === "tailwindcss" || normalized.startsWith("tailwindcss/")) {
81
- finalSpecifier = normalized.replace(
82
- /^tailwindcss/,
83
- `tailwindcss@${TAILWIND_VERSION}`,
84
- );
82
+ if (packageName === "tailwindcss") {
83
+ version = TAILWIND_VERSION;
85
84
  } else if (!hasVersionSpecifier(info.specifier)) {
86
85
  warnUnversionedImport(info.specifier, ctx.projectId);
87
86
  }
88
87
 
89
- const url = buildEsmShUrl(finalSpecifier, undefined, undefined, {
88
+ const url = buildEsmShUrl(packageName, version, subpath, {
90
89
  external: ["react"],
91
90
  });
92
91
 
@@ -0,0 +1,29 @@
1
+ export interface ParsedBarePackageSpecifier {
2
+ packageName: string;
3
+ version: string | null;
4
+ subpath: string | null;
5
+ }
6
+
7
+ export function parseBarePackageSpecifier(
8
+ specifier: string,
9
+ ): ParsedBarePackageSpecifier | null {
10
+ const scopedMatch = specifier.match(/^(@[^/]+\/[^/@]+)(?:@([^/]+))?(\/.*)?$/);
11
+ if (scopedMatch?.[1]) {
12
+ return {
13
+ packageName: scopedMatch[1],
14
+ version: scopedMatch[2] ?? null,
15
+ subpath: scopedMatch[3] ?? null,
16
+ };
17
+ }
18
+
19
+ const unscopedMatch = specifier.match(/^([^/@][^/@]*?)(?:@([^/]+))?(\/.*)?$/);
20
+ if (unscopedMatch?.[1]) {
21
+ return {
22
+ packageName: unscopedMatch[1],
23
+ version: unscopedMatch[2] ?? null,
24
+ subpath: unscopedMatch[3] ?? null,
25
+ };
26
+ }
27
+
28
+ return null;
29
+ }
@@ -43,49 +43,55 @@ export async function getEntityInfo(
43
43
  }
44
44
 
45
45
  try {
46
+ const shouldReadDirectly = adapter
47
+ ? isExtendedFSAdapter(adapter.fs) && adapter.fs.isVeryfrontAdapter()
48
+ : false;
49
+
50
+ let content: string;
46
51
  if (adapter) {
47
- try {
48
- const stat = await withFallback(
49
- () => adapter.fs.stat(normalizedPath),
50
- async () => {
51
- const exists = await fs.exists(filePath);
52
- if (!exists) {
53
- throw toError(
54
- createError({
55
- type: "file",
56
- message: "File not found",
57
- context: { path: filePath, operation: "read" },
58
- }),
59
- );
60
- }
61
- return await fs.stat(filePath);
62
- },
63
- { operationName: "stat:getEntityInfo", logError: false },
64
- );
52
+ if (!shouldReadDirectly) {
53
+ try {
54
+ const stat = await withFallback(
55
+ () => adapter.fs.stat(normalizedPath),
56
+ async () => {
57
+ const exists = await fs.exists(filePath);
58
+ if (!exists) {
59
+ throw toError(
60
+ createError({
61
+ type: "file",
62
+ message: "File not found",
63
+ context: { path: filePath, operation: "read" },
64
+ }),
65
+ );
66
+ }
67
+ return await fs.stat(filePath);
68
+ },
69
+ { operationName: "stat:getEntityInfo", logError: false },
70
+ );
65
71
 
66
- if (!stat.isFile) return null;
67
- } catch (error) {
68
- entityInfoScope.runSync(
69
- () => {
70
- throw error;
71
- },
72
- { path: filePath, details: { reason: "stat-failed" } },
73
- undefined,
74
- );
75
- return null;
72
+ if (!stat.isFile) return null;
73
+ } catch (error) {
74
+ entityInfoScope.runSync(
75
+ () => {
76
+ throw error;
77
+ },
78
+ { path: filePath, details: { reason: "stat-failed" } },
79
+ undefined,
80
+ );
81
+ return null;
82
+ }
76
83
  }
77
- } else {
78
- const exists = await fs.exists(filePath);
79
- if (!exists) return null;
80
- }
81
84
 
82
- const content = adapter
83
- ? await withFallback(
85
+ content = await withFallback(
84
86
  () => adapter.fs.readFile(normalizedPath),
85
87
  () => fs.readTextFile(filePath),
86
88
  { operationName: "readFile:getEntityInfo", logError: false },
87
- )
88
- : await fs.readTextFile(filePath);
89
+ );
90
+ } else {
91
+ const exists = await fs.exists(filePath);
92
+ if (!exists) return null;
93
+ content = await fs.readTextFile(filePath);
94
+ }
89
95
 
90
96
  const ext = pathHelper.extname(filePath).toLowerCase();
91
97
 
@@ -171,26 +177,30 @@ export async function getEntityBySlug(
171
177
  return await withSpan(
172
178
  "types.getEntityBySlug",
173
179
  async () => {
174
- const isVeryfrontRoute = slug.startsWith(".veryfront/") || slug === ".veryfront";
180
+ const normalizedSlug = normalizeSlug(slug);
181
+ const isVeryfrontRoute = normalizedSlug.startsWith(".veryfront/") ||
182
+ normalizedSlug === ".veryfront";
175
183
  const resolveFile = adapter?.fs.resolveFile;
176
184
 
177
185
  logger.debug("START", {
178
186
  slug,
187
+ normalizedSlug,
179
188
  projectDir,
180
189
  isVeryfrontRoute,
181
190
  hasResolveFile: !!resolveFile,
182
191
  });
183
192
 
184
193
  if (resolveFile) {
185
- const basePaths = [pathHelper.join(projectDir, "pages", slug)];
194
+ const basePaths = [pathHelper.join(projectDir, "pages", normalizedSlug)];
186
195
 
187
- if (isVeryfrontRoute) basePaths.unshift(pathHelper.join(projectDir, slug));
188
- if (slug === "index" || slug === "") {
196
+ if (isVeryfrontRoute) basePaths.unshift(pathHelper.join(projectDir, normalizedSlug));
197
+ if (normalizedSlug === "index" || normalizedSlug === "") {
189
198
  basePaths.unshift(pathHelper.join(projectDir, "pages", "index"));
190
199
  }
191
200
 
192
201
  logger.debug("Checking paths (resolveFile branch)", {
193
202
  slug,
203
+ normalizedSlug,
194
204
  basePaths,
195
205
  });
196
206
 
@@ -208,13 +218,14 @@ export async function getEntityBySlug(
208
218
  if (info?.entity.isPage) {
209
219
  logger.debug("Found page via resolveFile", {
210
220
  slug,
221
+ normalizedSlug,
211
222
  path: info.entity.path,
212
223
  });
213
224
  return info;
214
225
  }
215
226
  }
216
227
 
217
- const slugParts = slug.split("/");
228
+ const slugParts = normalizedSlug === "" ? [] : normalizedSlug.split("/");
218
229
  for (let depth = slugParts.length - 1; depth >= 0; depth--) {
219
230
  const parentPath = slugParts.slice(0, depth).join("/");
220
231
  const pagesDir = parentPath
@@ -259,33 +270,33 @@ export async function getEntityBySlug(
259
270
  }
260
271
  }
261
272
 
262
- logger.debug("No page found via resolveFile branch", { slug });
273
+ logger.debug("No page found via resolveFile branch", { slug, normalizedSlug });
263
274
  return null;
264
275
  }
265
276
 
266
277
  const possiblePaths = [
267
- pathHelper.join(projectDir, "pages", `${slug}.mdx`),
268
- pathHelper.join(projectDir, "pages", `${slug}.md`),
269
- pathHelper.join(projectDir, "pages", `${slug}.tsx`),
270
- pathHelper.join(projectDir, "pages", `${slug}.jsx`),
271
- pathHelper.join(projectDir, "pages", `${slug}.ts`),
272
- pathHelper.join(projectDir, "pages", `${slug}/index.mdx`),
273
- pathHelper.join(projectDir, "pages", `${slug}/index.md`),
274
- pathHelper.join(projectDir, "pages", `${slug}/index.tsx`),
275
- pathHelper.join(projectDir, "pages", `${slug}/index.jsx`),
276
- pathHelper.join(projectDir, "pages", `${slug}/index.ts`),
278
+ pathHelper.join(projectDir, "pages", `${normalizedSlug}.mdx`),
279
+ pathHelper.join(projectDir, "pages", `${normalizedSlug}.md`),
280
+ pathHelper.join(projectDir, "pages", `${normalizedSlug}.tsx`),
281
+ pathHelper.join(projectDir, "pages", `${normalizedSlug}.jsx`),
282
+ pathHelper.join(projectDir, "pages", `${normalizedSlug}.ts`),
283
+ pathHelper.join(projectDir, "pages", `${normalizedSlug}/index.mdx`),
284
+ pathHelper.join(projectDir, "pages", `${normalizedSlug}/index.md`),
285
+ pathHelper.join(projectDir, "pages", `${normalizedSlug}/index.tsx`),
286
+ pathHelper.join(projectDir, "pages", `${normalizedSlug}/index.jsx`),
287
+ pathHelper.join(projectDir, "pages", `${normalizedSlug}/index.ts`),
277
288
  ];
278
289
 
279
290
  if (isVeryfrontRoute) {
280
291
  possiblePaths.unshift(
281
- pathHelper.join(projectDir, `${slug}.mdx`),
282
- pathHelper.join(projectDir, `${slug}.md`),
283
- pathHelper.join(projectDir, `${slug}.tsx`),
284
- pathHelper.join(projectDir, `${slug}.ts`),
292
+ pathHelper.join(projectDir, `${normalizedSlug}.mdx`),
293
+ pathHelper.join(projectDir, `${normalizedSlug}.md`),
294
+ pathHelper.join(projectDir, `${normalizedSlug}.tsx`),
295
+ pathHelper.join(projectDir, `${normalizedSlug}.ts`),
285
296
  );
286
297
  }
287
298
 
288
- if (slug === "index" || slug === "") {
299
+ if (normalizedSlug === "index" || normalizedSlug === "") {
289
300
  possiblePaths.unshift(
290
301
  pathHelper.join(projectDir, "pages", "index.mdx"),
291
302
  pathHelper.join(projectDir, "pages", "index.md"),
@@ -302,7 +313,7 @@ export async function getEntityBySlug(
302
313
  if (info?.entity.isPage) return info;
303
314
  }
304
315
 
305
- const slugParts = slug.split("/");
316
+ const slugParts = normalizedSlug === "" ? [] : normalizedSlug.split("/");
306
317
  for (let depth = slugParts.length - 1; depth >= 0; depth--) {
307
318
  const parentPath = slugParts.slice(0, depth).join("/");
308
319
  const pagesDir = parentPath
@@ -356,7 +367,11 @@ export async function getEntityBySlug(
356
367
 
357
368
  return null;
358
369
  },
359
- { "entity.slug": slug, "entity.projectDir": projectDir },
370
+ {
371
+ "entity.slug": slug,
372
+ "entity.normalized_slug": normalizeSlug(slug),
373
+ "entity.projectDir": projectDir,
374
+ },
360
375
  );
361
376
  }
362
377
 
@@ -448,3 +463,7 @@ function getSlugFromPath(filePath: string): string {
448
463
  const parentDir = parts[parts.length - 2];
449
464
  return parentDir === "pages" ? "" : parentDir ?? "";
450
465
  }
466
+
467
+ function normalizeSlug(slug: string): string {
468
+ return slug === "/" ? "" : slug.replace(/^\/+/, "").replace(/\/+$/, "");
469
+ }