File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { Request , Response } from "express" ;
2- import { seconds } from "../../utils/misc.js" ;
32import { BROWSERS , DEFAULT_BROWSERS } from "./lib/constants.js" ;
43import { Data , getData } from "./lib/index.js" ;
54
@@ -11,16 +10,18 @@ export default async function route(req: IRequest, res: Response) {
1110 const { feature } = req . params ;
1211 const browsers = normalizeBrowsers ( req . query . browsers ) ;
1312
14-
1513 try {
1614 const data = await getData ( feature ) ;
1715 if ( data === null ) {
18- res . sendStatus ( 404 ) ;
16+ const hint = feature . startsWith ( "wf-" )
17+ ? ` The "wf-" prefix indicates a web-features ID. No matching caniuse data was found for "${ feature } " or "${ feature . slice ( 3 ) } ".`
18+ : "" ;
19+ res . status ( 404 ) . json ( { error : `Feature "${ feature } " not found.${ hint } ` } ) ;
1920 return ;
2021 }
2122 const result = [ ] ;
2223 for ( const browser of browsers ) {
23- result . push ( { browser, ...getBrowserData ( data ? .all [ browser ] ) } ) ;
24+ result . push ( { browser, ...getBrowserData ( data . all [ browser ] ) } ) ;
2425 }
2526 res . json ( { result } ) ;
2627 } catch ( error ) {
Original file line number Diff line number Diff line change @@ -106,6 +106,15 @@ function sanitizeBrowsersList(browsers?: string | string[]) {
106106}
107107
108108export async function getData ( feature : string ) {
109+ // Try the feature as-is first, then fall back to stripping the "wf-" prefix.
110+ // E.g., "wf-css-grid" falls back to looking up "css-grid" in caniuse data.
111+ const data = await readFeatureFile ( feature ) ;
112+ if ( data ) return data ;
113+ if ( feature . startsWith ( "wf-" ) ) return readFeatureFile ( feature . slice ( 3 ) ) ;
114+ return null ;
115+ }
116+
117+ async function readFeatureFile ( feature : string ) {
109118 if ( cache . has ( feature ) ) {
110119 return cache . get ( feature ) as Data ;
111120 }
@@ -120,7 +129,9 @@ export async function getData(feature: string) {
120129 cache . set ( feature , data ) ;
121130 return data ;
122131 } catch ( error ) {
123- console . error ( error ) ;
132+ if ( ( error as NodeJS . ErrnoException ) . code !== "ENOENT" ) {
133+ console . error ( error ) ;
134+ }
124135 return null ;
125136 }
126137}
You can’t perform that action at this time.
0 commit comments