22 * Module that exports a function that takes an array of specifications objects
33 * that each have at least a "url" and a "short" property. The function returns
44 * an object indexed by specification "shortname" with additional information
5- * about the specification fetched from the W3C API, Specref, or from the spec
6- * itself. Object returned for each specification contains the following
5+ * about the specification fetched from the W3C API, WHATWG, IETF or from the
6+ * spec itself. Object returned for each specification contains the following
77 * properties:
88 *
99 * - "nightly": an object that describes the nightly version. The object will
1515 * feature the URL of the TR document for W3C specs when it exists, and is not
1616 * present for specs that don't have release versions (WHATWG specs, CG drafts).
1717 * - "title": the title of the specification. Always set.
18- * - "source": one of "w3c", "specref ", "spec", depending on how the information
19- * was determined.
18+ * - "source": one of "w3c", "ietf ", "whatwg", " spec", depending on how the
19+ * information was determined.
2020 *
2121 * The function throws when something goes wrong, e.g. if the given spec object
2222 * describes a /TR/ specification but the specification has actually not been
2525 *
2626 * The function will start by querying the W3C API, using the given "shortname"
2727 * properties. For specifications where this fails, the function will query
28- * SpecRef, using the given "shortname" as well. If that too fails, the function
29- * assumes that the given "url" is the URL of the Editor's Draft, and will fetch
30- * it to determine the title.
28+ * IETF, then WHATWG, using the given "shortname" as well. If that too fails,
29+ * the function assumes that the given "url" is the URL of the Editor's Draft,
30+ * and will fetch it to determine the title.
3131 *
3232 * If the function needs to retrieve the spec itself, note that it will parse
3333 * the HTTP response body as a string, applying regular expressions to extract
3434 * the title. It will not parse it as HTML in particular. This means that the
3535 * function will fail if the title cannot easily be extracted for some reason.
36- *
37- * Note: the function operates on a list of specs and not only on one spec to
38- * bundle requests to Specref.
3936 */
4037
4138import puppeteer from "puppeteer" ;
@@ -45,17 +42,6 @@ import Octokit from "./octokit.js";
4542import ThrottledQueue from "./throttled-queue.js" ;
4643import fetchJSON from "./fetch-json.js" ;
4744
48- // Map spec statuses returned by Specref to those used in specs
49- // Note we typically won't get /TR statuses from Specref, since all /TR URLs
50- // are handled through the W3C API. Also, "Proposal for a CSS module" entries
51- // were probably manually hardcoded in Specref, they are really just Editor's
52- // Drafts in practice.
53- const specrefStatusMapping = {
54- "ED" : "Editor's Draft" ,
55- "Proposal for a CSS module" : "Editor's Draft" ,
56- "cg-draft" : "Draft Community Group Report"
57- } ;
58-
5945async function useLastInfoForDiscontinuedSpecs ( specs ) {
6046 const results = { } ;
6147 for ( const spec of specs ) {
@@ -215,97 +201,6 @@ async function fetchInfoFromWHATWG(specs, options) {
215201 return specInfo ;
216202}
217203
218- async function fetchInfoFromSpecref ( specs , options ) {
219- function chunkArray ( arr , len ) {
220- let chunks = [ ] ;
221- let i = 0 ;
222- let n = arr . length ;
223- while ( i < n ) {
224- chunks . push ( arr . slice ( i , i += len ) ) ;
225- }
226- return chunks ;
227- }
228-
229- // Browser-specs contributes specs to Specref. By definition, we cannot rely
230- // on information from Specref about these specs. Unfortunately, the Specref
231- // API does not return the "source" field, so we need to retrieve the list
232- // ourselves from Specref's GitHub repository.
233- const specrefBrowserspecsUrl = "https://raw.githubusercontent.com/tobie/specref/main/refs/browser-specs.json" ;
234- const browserSpecs = await fetchJSON ( specrefBrowserspecsUrl , options ) ;
235- specs = specs . filter ( spec => ! browserSpecs [ spec . shortname . toUpperCase ( ) ] ) ;
236-
237- // Browser-specs now acts as source for Specref for the WICG specs and W3C
238- // Editor's Drafts that have not yet been published to /TR. Let's filter out
239- // these specs to avoid a catch-22 where the info in browser-specs gets stuck
240- // to the that in Specref.
241- const filteredSpecs = specs . filter ( spec =>
242- ! spec . url . match ( / \/ \/ ( w i c g | w 3 c ) \. g i t h u b \. i o \/ / ) &&
243- ! spec . url . match ( / \/ \/ w w w \. w 3 \. o r g \/ / ) &&
244- ! spec . url . match ( / \/ \/ d r a f t s \. c s s w g \. o r g \/ / ) ) ;
245-
246- const chunks = chunkArray ( filteredSpecs , 50 ) ;
247- const chunksRes = await Promise . all ( chunks . map ( async chunk => {
248- let specrefUrl = "https://api.specref.org/bibrefs?refs=" +
249- chunk . map ( spec => spec . shortname ) . join ( ',' ) ;
250- return fetchJSON ( specrefUrl , options ) ;
251- } ) ) ;
252-
253- const results = { } ;
254- chunksRes . forEach ( chunkRes => {
255-
256- // Specref manages aliases, let's follow the chain to the final spec
257- function resolveAlias ( name , counter ) {
258- counter = counter || 0 ;
259- if ( counter > 100 ) {
260- throw "Too many aliases returned by Respec" ;
261- }
262- if ( chunkRes [ name ] . aliasOf ) {
263- return resolveAlias ( chunkRes [ name ] . aliasOf , counter + 1 ) ;
264- }
265- else {
266- return name ;
267- }
268- }
269- Object . keys ( chunkRes ) . forEach ( name => {
270- if ( specs . find ( spec => spec . shortname === name ) ) {
271- const info = chunkRes [ resolveAlias ( name ) ] ;
272- if ( info . edDraft ?. startsWith ( 'http:' ) ) {
273- console . warn ( `[warning] force HTTPS for nightly of ` +
274- `"${ spec . shortname } ", Specref returned "${ info . edDraft } "` ) ;
275- }
276- if ( info . href ?. startsWith ( 'http:' ) ) {
277- console . warn ( `[warning] force HTTPS for nightly of ` +
278- `"${ spec . shortname } ", Specref returned "${ info . href } "` ) ;
279- }
280- const nightly =
281- info . edDraft ?. replace ( / ^ h t t p : / , 'https:' ) ??
282- info . href ?. replace ( / ^ h t t p : / , 'https:' ) ??
283- null ;
284- const status =
285- specrefStatusMapping [ info . status ] ??
286- info . status ??
287- "Editor's Draft" ;
288- if ( nightly ?. startsWith ( "https://www.iso.org/" ) ) {
289- // The URL is to a page that describes the spec, not to the spec
290- // itself (ISO specs are not public).
291- results [ name ] = {
292- title : info . title
293- }
294- }
295- else {
296- results [ name ] = {
297- nightly : { url : nightly , status } ,
298- title : info . title
299- } ;
300- }
301- }
302- } ) ;
303- } ) ;
304-
305- return results ;
306- }
307-
308-
309204async function fetchInfoFromIETF ( specs , options ) {
310205 async function fetchRFCName ( docUrl ) {
311206 const body = await fetchJSON ( docUrl , options ) ;
@@ -611,7 +506,6 @@ async function fetchInfo(specs, options) {
611506 { name : 'w3c' , fn : fetchInfoFromW3CApi } ,
612507 { name : 'ietf' , fn : fetchInfoFromIETF } ,
613508 { name : 'whatwg' , fn : fetchInfoFromWHATWG } ,
614- { name : 'specref' , fn : fetchInfoFromSpecref } ,
615509 { name : 'spec' , fn : fetchInfoFromSpecs }
616510 ] ;
617511 let remainingSpecs = specs ;
0 commit comments