@pyreon/compiler 0.11.5 → 0.11.6

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.
@@ -2,8 +2,8 @@
2
2
  * Project scanner — extracts route, component, and island information from source files.
3
3
  */
4
4
 
5
- import * as fs from "node:fs"
6
- import * as path from "node:path"
5
+ import * as fs from 'node:fs'
6
+ import * as path from 'node:path'
7
7
 
8
8
  export interface RouteInfo {
9
9
  path: string
@@ -29,7 +29,7 @@ export interface IslandInfo {
29
29
  }
30
30
 
31
31
  export interface ProjectContext {
32
- framework: "pyreon"
32
+ framework: 'pyreon'
33
33
  version: string
34
34
  generatedAt: string
35
35
  routes: RouteInfo[]
@@ -42,7 +42,7 @@ export function generateContext(cwd: string): ProjectContext {
42
42
  const version = readVersion(cwd)
43
43
 
44
44
  return {
45
- framework: "pyreon",
45
+ framework: 'pyreon',
46
46
  version,
47
47
  generatedAt: new Date().toISOString(),
48
48
  routes: extractRoutes(files, cwd),
@@ -53,8 +53,8 @@ export function generateContext(cwd: string): ProjectContext {
53
53
 
54
54
  function collectSourceFiles(cwd: string): string[] {
55
55
  const results: string[] = []
56
- const extensions = new Set([".tsx", ".jsx", ".ts", ".js"])
57
- const ignoreDirs = new Set(["node_modules", "dist", "lib", ".pyreon", ".git", "build"])
56
+ const extensions = new Set(['.tsx', '.jsx', '.ts', '.js'])
57
+ const ignoreDirs = new Set(['node_modules', 'dist', 'lib', '.pyreon', '.git', 'build'])
58
58
 
59
59
  // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: simple recursive walker
60
60
  function walk(dir: string): void {
@@ -65,7 +65,7 @@ function collectSourceFiles(cwd: string): string[] {
65
65
  return
66
66
  }
67
67
  for (const entry of entries) {
68
- if (entry.name.startsWith(".") && entry.isDirectory()) continue
68
+ if (entry.name.startsWith('.') && entry.isDirectory()) continue
69
69
  if (ignoreDirs.has(entry.name) && entry.isDirectory()) continue
70
70
  const fullPath = path.join(dir, entry.name)
71
71
  if (entry.isDirectory()) {
@@ -86,7 +86,7 @@ function extractRoutes(files: string[], _cwd: string): RouteInfo[] {
86
86
  for (const file of files) {
87
87
  let code: string
88
88
  try {
89
- code = fs.readFileSync(file, "utf-8")
89
+ code = fs.readFileSync(file, 'utf-8')
90
90
  } catch {
91
91
  continue
92
92
  }
@@ -95,11 +95,11 @@ function extractRoutes(files: string[], _cwd: string): RouteInfo[] {
95
95
  /(?:createRouter\s*\(\s*\[|(?:const|let)\s+routes\s*(?::\s*RouteRecord\[\])?\s*=\s*\[)([\s\S]*?)\]/g
96
96
  let match: RegExpExecArray | null
97
97
  for (match = routeArrayRe.exec(code); match; match = routeArrayRe.exec(code)) {
98
- const block = match[1] ?? ""
98
+ const block = match[1] ?? ''
99
99
  const routeObjRe = /path\s*:\s*["']([^"']+)["']/g
100
100
  let routeMatch: RegExpExecArray | null
101
101
  for (routeMatch = routeObjRe.exec(block); routeMatch; routeMatch = routeObjRe.exec(block)) {
102
- const routePath = routeMatch[1] ?? ""
102
+ const routePath = routeMatch[1] ?? ''
103
103
  const surroundingStart = Math.max(0, routeMatch.index - 50)
104
104
  const surroundingEnd = Math.min(block.length, routeMatch.index + 200)
105
105
  const surrounding = block.slice(surroundingStart, surroundingEnd)
@@ -124,7 +124,7 @@ function extractComponents(files: string[], cwd: string): ComponentInfo[] {
124
124
  for (const file of files) {
125
125
  let code: string
126
126
  try {
127
- code = fs.readFileSync(file, "utf-8")
127
+ code = fs.readFileSync(file, 'utf-8')
128
128
  } catch {
129
129
  continue
130
130
  }
@@ -134,12 +134,12 @@ function extractComponents(files: string[], cwd: string): ComponentInfo[] {
134
134
  let match: RegExpExecArray | null
135
135
 
136
136
  for (match = componentRe.exec(code); match; match = componentRe.exec(code)) {
137
- const name = match[1] ?? "Unknown"
138
- const propsStr = match[2] ?? ""
137
+ const name = match[1] ?? 'Unknown'
138
+ const propsStr = match[2] ?? ''
139
139
  const props = propsStr
140
140
  .split(/[,;]/)
141
- .map((p) => p.trim().replace(/[{}]/g, "").trim().split(":")[0]?.split("=")[0]?.trim() ?? "")
142
- .filter((p) => p && p !== "props")
141
+ .map((p) => p.trim().replace(/[{}]/g, '').trim().split(':')[0]?.split('=')[0]?.trim() ?? '')
142
+ .filter((p) => p && p !== 'props')
143
143
 
144
144
  const bodyStart = match.index + match[0].length
145
145
  const body = code.slice(bodyStart, Math.min(code.length, bodyStart + 2000))
@@ -169,7 +169,7 @@ function extractIslands(files: string[], cwd: string): IslandInfo[] {
169
169
  for (const file of files) {
170
170
  let code: string
171
171
  try {
172
- code = fs.readFileSync(file, "utf-8")
172
+ code = fs.readFileSync(file, 'utf-8')
173
173
  } catch {
174
174
  continue
175
175
  }
@@ -182,7 +182,7 @@ function extractIslands(files: string[], cwd: string): IslandInfo[] {
182
182
  islands.push({
183
183
  name: match[1],
184
184
  file: path.relative(cwd, file),
185
- hydrate: match[2] ?? "load",
185
+ hydrate: match[2] ?? 'load',
186
186
  })
187
187
  }
188
188
  }
@@ -203,13 +203,13 @@ function extractParams(routePath: string): string[] {
203
203
 
204
204
  function readVersion(cwd: string): string {
205
205
  try {
206
- const pkg = JSON.parse(fs.readFileSync(path.join(cwd, "package.json"), "utf-8"))
206
+ const pkg = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf-8'))
207
207
  const deps: Record<string, unknown> = { ...pkg.dependencies, ...pkg.devDependencies }
208
208
  for (const [name, ver] of Object.entries(deps)) {
209
- if (name.startsWith("@pyreon/") && typeof ver === "string") return ver.replace(/^[\^~]/, "")
209
+ if (name.startsWith('@pyreon/') && typeof ver === 'string') return ver.replace(/^[\^~]/, '')
210
210
  }
211
- return (pkg.version as string) || "unknown"
211
+ return (pkg.version as string) || 'unknown'
212
212
  } catch {
213
- return "unknown"
213
+ return 'unknown'
214
214
  }
215
215
  }