11import { read } from '$app/server' ;
2+ import { PACKAGES_META } from '$lib/packages-meta' ;
23import type { Document , DocumentSummary } from '@sveltejs/site-kit' ;
34import { create_index } from '@sveltejs/site-kit/server/content' ;
45
@@ -17,6 +18,15 @@ const assets = import.meta.glob<string>(
1718 }
1819) ;
1920
21+ const registry_docs = import . meta. glob < string > (
22+ '../../../src/lib/server/generated/registry/*.json' ,
23+ {
24+ eager : true ,
25+ query : '?raw' ,
26+ import : 'default'
27+ }
28+ ) ;
29+
2030// https://github.com/vitejs/vite/issues/17453
2131export const index = await create_index ( documents , assets , '../../../content' , read ) ;
2232
@@ -142,3 +152,275 @@ export function create_summary(document: Document): DocumentSummary {
142152export const docs = create_docs ( ) ;
143153
144154export const examples = index . examples . children ;
155+
156+ /**
157+ * Checks if a semver range supports Svelte versions 3.x, 4.x, and 5.x
158+ */
159+ function supports_svelte_versions ( version_range : string ) : {
160+ 3 : boolean ;
161+ 4 : boolean ;
162+ 5 : boolean ;
163+ } {
164+ if ( ! version_range ) return { 3 : false , 4 : false , 5 : false } ;
165+
166+ // Initialize result object
167+ const result = { 3 : false , 4 : false , 5 : false } ;
168+
169+ // Handle version range with OR operators first before any other processing
170+ if ( version_range . includes ( '||' ) ) {
171+ const ranges = version_range . split ( '||' ) . map ( ( r ) => r . trim ( ) ) ;
172+
173+ // Check each range and combine results with OR logic
174+ for ( const range of ranges ) {
175+ const range_result = supports_svelte_versions ( range ) ;
176+ result [ 3 ] = result [ 3 ] || range_result [ 3 ] ;
177+ result [ 4 ] = result [ 4 ] || range_result [ 4 ] ;
178+ result [ 5 ] = result [ 5 ] || range_result [ 5 ] ;
179+ }
180+
181+ return result ;
182+ }
183+
184+ // Handle exact version with equals sign
185+ if ( version_range . startsWith ( '=' ) ) {
186+ const exact_version = version_range . substring ( 1 ) ;
187+ return supports_svelte_versions ( exact_version ) ;
188+ }
189+
190+ // Handle hyphen ranges directly (not part of a complex expression)
191+ if ( version_range . includes ( ' - ' ) ) {
192+ // Split by hyphen and trim whitespace
193+ const parts = version_range . split ( '-' ) . map ( ( p ) => p . trim ( ) ) ;
194+ // Handle "x - y" format correctly
195+ if ( parts . length === 2 ) {
196+ const start = parseFloat ( parts [ 0 ] ) ;
197+ const end = parseFloat ( parts [ 1 ] ) ;
198+
199+ result [ 3 ] = start <= 3 && end >= 3 ;
200+ result [ 4 ] = start <= 4 && end >= 4 ;
201+ result [ 5 ] = start <= 5 && end >= 5 ;
202+
203+ return result ;
204+ }
205+ }
206+
207+ // Handle complex version ranges with both upper and lower bounds in the same expression
208+ // Examples: ">=1.0.0 <=4.9.9", ">=3.0.0 <6.0.0", ">3.0.0-rc.1 <3.1.0"
209+ if (
210+ version_range . includes ( ' ' ) &&
211+ ( version_range . includes ( '<' ) ||
212+ version_range . includes ( '<=' ) ||
213+ version_range . includes ( '>=' ) ||
214+ version_range . includes ( '>' ) )
215+ ) {
216+ // Process for complex range with multiple constraints
217+ let includes_version_3 = true ;
218+ let includes_version_4 = true ;
219+ let includes_version_5 = true ;
220+
221+ // Split by spaces to get individual constraints
222+ const constraints = version_range
223+ . split ( ' ' )
224+ . filter (
225+ ( c ) => c . startsWith ( '<' ) || c . startsWith ( '<=' ) || c . startsWith ( '>' ) || c . startsWith ( '>=' )
226+ ) ;
227+
228+ // If we couldn't parse any valid constraints, return false
229+ if ( constraints . length === 0 ) {
230+ return { 3 : false , 4 : false , 5 : false } ;
231+ }
232+
233+ // Special case handling for pre-release specific ranges (e.g., ">3.0.0-rc.1 <3.1.0")
234+ if ( constraints . some ( ( c ) => c . includes ( '-' ) ) ) {
235+ // Identify if this is a narrow range for a specific major version
236+ let major_version = null ;
237+
238+ for ( const constraint of constraints ) {
239+ const match = constraint . match ( / [ < > = ] + \s * ( \d + ) / ) ;
240+ if ( match ) {
241+ const version = parseInt ( match [ 1 ] ) ;
242+ if ( major_version === null ) {
243+ major_version = version ;
244+ } else if ( major_version !== version ) {
245+ major_version = null ; // Different major versions, not a narrow range
246+ break ;
247+ }
248+ }
249+ }
250+
251+ // If we identified a specific major version for this pre-release constraint
252+ if ( major_version !== null ) {
253+ result [ 3 ] = major_version === 3 ;
254+ result [ 4 ] = major_version === 4 ;
255+ result [ 5 ] = major_version === 5 ;
256+ return result ;
257+ }
258+ }
259+
260+ for ( const constraint of constraints ) {
261+ if ( constraint . startsWith ( '>=' ) ) {
262+ const version_number = parseFloat ( constraint . substring ( 2 ) ) ;
263+ // Check lower bounds for each version
264+ if ( version_number > 3 ) includes_version_3 = false ;
265+ if ( version_number > 4 ) includes_version_4 = false ;
266+ if ( version_number > 5 ) includes_version_5 = false ;
267+ } else if ( constraint . startsWith ( '>' ) ) {
268+ const version_number = parseFloat ( constraint . substring ( 1 ) ) ;
269+ // Check lower bounds for each version
270+ if ( version_number >= 3 ) includes_version_3 = false ;
271+ if ( version_number >= 4 ) includes_version_4 = false ;
272+ if ( version_number >= 5 ) includes_version_5 = false ;
273+ } else if ( constraint . startsWith ( '<=' ) ) {
274+ const version_number = parseFloat ( constraint . substring ( 2 ) ) ;
275+ // Check upper bounds for each version
276+ if ( version_number < 3 ) includes_version_3 = false ;
277+ if ( version_number < 4 ) includes_version_4 = false ;
278+ if ( version_number < 5 ) includes_version_5 = false ;
279+ } else if ( constraint . startsWith ( '<' ) ) {
280+ const version_number = parseFloat ( constraint . substring ( 1 ) ) ;
281+ // Check upper bounds for each version
282+ if ( version_number <= 3 ) includes_version_3 = false ;
283+ if ( version_number <= 4 ) includes_version_4 = false ;
284+ if ( version_number <= 5 ) includes_version_5 = false ;
285+ }
286+ }
287+
288+ result [ 3 ] = includes_version_3 ;
289+ result [ 4 ] = includes_version_4 ;
290+ result [ 5 ] = includes_version_5 ;
291+
292+ return result ;
293+ }
294+
295+ // Handle exact major version format
296+ if ( / ^ [ 0 - 9 ] + $ / . test ( version_range ) ) {
297+ const version = parseInt ( version_range ) ;
298+ result [ 3 ] = version === 3 ;
299+ result [ 4 ] = version === 4 ;
300+ result [ 5 ] = version === 5 ;
301+ return result ;
302+ }
303+
304+ // Handle caret ranges
305+ if ( version_range . startsWith ( '^' ) ) {
306+ const major_version = parseInt ( version_range . substring ( 1 ) . split ( '.' ) [ 0 ] ) ;
307+ result [ 3 ] = major_version === 3 ;
308+ result [ 4 ] = major_version === 4 ;
309+ result [ 5 ] = major_version === 5 ;
310+ return result ;
311+ }
312+
313+ // Handle pre-release versions directly (e.g., 5.0.0-next.42)
314+ if ( / ^ ( [ 0 - 9 ] + ) \. ( [ 0 - 9 ] + ) \. ( [ 0 - 9 ] + ) - / . test ( version_range ) ) {
315+ const match = version_range . match ( / ^ ( [ 0 - 9 ] + ) \. / ) ;
316+ if ( match ) {
317+ // Extract major version from the pre-release
318+ const major_version = parseInt ( match [ 1 ] ) ;
319+ result [ 3 ] = major_version === 3 ;
320+ result [ 4 ] = major_version === 4 ;
321+ result [ 5 ] = major_version === 5 ;
322+ return result ;
323+ }
324+ }
325+
326+ // Handle tilde ranges
327+ if ( version_range . startsWith ( '~' ) ) {
328+ const major_version = parseInt ( version_range . substring ( 1 ) . split ( '.' ) [ 0 ] ) ;
329+ result [ 3 ] = major_version === 3 ;
330+ result [ 4 ] = major_version === 4 ;
331+ result [ 5 ] = major_version === 5 ;
332+ return result ;
333+ }
334+
335+ // Handle wildcard (*) by itself, which means any version
336+ if ( version_range === '*' ) {
337+ return { 3 : true , 4 : true , 5 : true } ;
338+ }
339+
340+ // Handle * and x ranges (e.g., "3.x", "4.*")
341+ if ( / ^ ( [ 0 - 9 ] + ) \. ( x | \* ) / . test ( version_range ) ) {
342+ const match = version_range . match ( / ^ ( [ 0 - 9 ] + ) \. / ) ;
343+ if ( match ) {
344+ const major_version = parseInt ( match [ 1 ] ) ;
345+ result [ 3 ] = major_version === 3 ;
346+ result [ 4 ] = major_version === 4 ;
347+ result [ 5 ] = major_version === 5 ;
348+ return result ;
349+ }
350+ }
351+
352+ // Handle >= ranges
353+ if ( version_range . startsWith ( '>=' ) ) {
354+ const version_number = parseFloat ( version_range . substring ( 2 ) ) ;
355+ result [ 3 ] = version_number <= 3 ;
356+ result [ 4 ] = version_number <= 4 ;
357+ result [ 5 ] = version_number <= 5 ;
358+ return result ;
359+ }
360+
361+ // Handle > ranges
362+ if ( version_range . startsWith ( '>' ) ) {
363+ const version_number = parseFloat ( version_range . substring ( 1 ) ) ;
364+ result [ 3 ] = version_number < 3 ;
365+ result [ 4 ] = version_number < 4 ;
366+ result [ 5 ] = version_number < 5 ;
367+ return result ;
368+ }
369+
370+ // Handle <= ranges
371+ if ( version_range . startsWith ( '<=' ) ) {
372+ const version_number = parseFloat ( version_range . substring ( 2 ) ) ;
373+ result [ 3 ] = version_number >= 3 ;
374+ result [ 4 ] = version_number >= 4 ;
375+ result [ 5 ] = version_number >= 5 ;
376+ return result ;
377+ }
378+
379+ // Handle < ranges
380+ if ( version_range . startsWith ( '<' ) ) {
381+ const version_number = parseFloat ( version_range . substring ( 1 ) ) ;
382+ result [ 3 ] = version_number > 3 ;
383+ result [ 4 ] = version_number > 4 ;
384+ result [ 5 ] = version_number > 5 ;
385+ return result ;
386+ }
387+
388+ // Handle exact versions (like 3.0.0, 4.1.2, etc.)
389+ if ( / ^ [ 0 - 9 ] + \. [ 0 - 9 ] + \. [ 0 - 9 ] + $ / . test ( version_range ) ) {
390+ const major_version = parseInt ( version_range . split ( '.' ) [ 0 ] ) ;
391+ result [ 3 ] = major_version === 3 ;
392+ result [ 4 ] = major_version === 4 ;
393+ result [ 5 ] = major_version === 5 ;
394+ return result ;
395+ }
396+
397+ // Handle x-ranges (3.x.x, 4.x, etc.)
398+ if ( version_range . includes ( '.x' ) || version_range . includes ( '.*' ) ) {
399+ const major_version = parseInt ( version_range . split ( '.' ) [ 0 ] ) ;
400+ result [ 3 ] = major_version === 3 ;
401+ result [ 4 ] = major_version === 4 ;
402+ result [ 5 ] = major_version === 5 ;
403+ return result ;
404+ }
405+
406+ return result ;
407+ }
408+
409+ function create_registry ( ) {
410+ let output : Package [ ] = [ ] ;
411+
412+ for ( const frontmatter of Object . values ( registry_docs ) ) {
413+ const json = JSON . parse ( frontmatter ) ;
414+ json . description = json . description ;
415+ json . outdated = + new Date ( ) - + new Date ( json . updated ) > 2 * 365 * 24 * 60 * 60 * 1000 ;
416+ json . official = json . official ?? PACKAGES_META . is_official ( json . name ) ;
417+ json . ts_support = json . typescript ?. types_source ;
418+ json . svelte = supports_svelte_versions ( json . svelte_range ) ;
419+
420+ output . push ( json as unknown as Package ) ;
421+ }
422+
423+ return output ;
424+ }
425+
426+ export const registry = create_registry ( ) ;
0 commit comments