diff --git a/scripts/identify-web-features.js b/scripts/identify-web-features.js index bab0f55..92f4077 100644 --- a/scripts/identify-web-features.js +++ b/scripts/identify-web-features.js @@ -24,6 +24,15 @@ const argv = yargs(process.argv) const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN }); +function getFeature(id) { + const feature = features[id]; + if (!feature || feature.kind !== "feature") { + return null; + } + + return feature; +} + function escapeFeatureName(feature) { // Escape the feature name for use in HTML. return feature.name.replace(//g, ">"); @@ -45,8 +54,12 @@ function gatherFeaturesFromSpecUrls(urls) { for (const url of urls) { for (const id in features) { - const feature = features[id]; - const specUrls = (Array.isArray(feature.spec) ? feature.spec : [feature.spec]).map(url => new URL(url)); + const feature = getFeature(id); + if (!feature) { + continue; + } + + const specUrls = feature.spec.map(url => new URL(url)); if (specUrls.some(specUrl => { return specUrl.hostname === url.hostname && @@ -71,7 +84,7 @@ function gatherFeaturesFromExplorerUrls(urls) { } const candidateId = url.pathname.substring(url.pathname.indexOf("features/") + 9).replace("/", "").replace(".json", ""); - if (features[candidateId]) { + if (getFeature(candidateId)) { gatheredFeatures.add(candidateId); } } @@ -90,7 +103,7 @@ function gatherFeaturesFromWPTUrls(urls) { const query = url.searchParams.get("q"); const match = query.match(/feature:([a-z0-9-]+)/); - if (match && match[1] && features[match[1]]) { + if (match && match[1] && getFeature(match[1])) { gatheredFeatures.add(match[1]); } } @@ -107,7 +120,7 @@ function gatherFeaturesFromExplicitMentions(issueBody) { const explicitMentions = issueBody.match(/web-features?:\s*([a-z0-9-]+)/gi) || []; for (const mention of explicitMentions) { const match = mention.match(/web-features?:\s*([a-z0-9-]+)/i); - if (match && match[1] && features[match[1]]) { + if (match && match[1] && getFeature(match[1])) { gatheredFeatures.add(match[1]); } } @@ -120,7 +133,7 @@ function gatherFeaturesFromExplicitMentions(issueBody) { for (const section of sectionMentions) { const lines = section.split(/[\r\n]+/).map(line => line.trim()).filter(line => line && !line.startsWith("###")); for (const line of lines) { - if (features[line]) { + if (getFeature(line)) { gatheredFeatures.add(line); } } @@ -185,27 +198,24 @@ function getDocsAsMarkdown(feature) { } function getStandardPositionsAsMarkdown(feature) { - if (!feature.standardPositions.mozilla.url && !feature.standardPositions.webkit.url) { + if (!feature.standardPositions.length) { return ""; } const positions = []; - if (feature.standardPositions.mozilla.url) { - positions.push(`[Mozilla](${feature.standardPositions.mozilla.url})`); - } - if (feature.standardPositions.webkit.url) { - positions.push(`[WebKit](${feature.standardPositions.webkit.url})`); + for (const position of feature.standardPositions) { + positions.push(`[${position.vendor}](${position.url})`); } return "* **Standard positions:** " + positions.join(", ") + "\n"; } function getUseCounterAsMarkdown(feature) { - if (!feature.useCounters.chromeStatusUrl) { + if (!feature.chromeUseCounters || !feature.chromeUseCounters.url) { return ""; } - return `* **Chrome use counter:** [chromestatus.com](${feature.useCounters.chromeStatusUrl})\n`; + return `* **Chrome use counter:** [chromestatus.com](${feature.chromeUseCounters.url})\n`; } function getSurveysAsMarkdown(feature) { @@ -214,7 +224,7 @@ function getSurveysAsMarkdown(feature) { } const surveys = feature.stateOfSurveys.map(survey => { - return `[${survey.name} (${survey.question} question)](${survey.link})`; + return `[${survey.name} (${survey.question} question)](${survey.url})`; }).join(", "); return `* **State of CSS/JS/HTML surveys:** ${surveys}\n`; diff --git a/scripts/package-lock.json b/scripts/package-lock.json index 0d7b036..489128d 100644 --- a/scripts/package-lock.json +++ b/scripts/package-lock.json @@ -7,7 +7,7 @@ "name": "interop-scripts", "devDependencies": { "octokit": "^5.0.3", - "web-features": "^2.48.0", + "web-features": "^3.6.0", "yargs": "^18.0.0" } }, @@ -578,9 +578,9 @@ "license": "ISC" }, "node_modules/web-features": { - "version": "2.48.0", - "resolved": "https://registry.npmjs.org/web-features/-/web-features-2.48.0.tgz", - "integrity": "sha512-Qv/yRQP/gIQiMXF7XNCblDQDRQJ814PFArrjDvjXJnkVh80CulDMCIRaC4dB4Ex1ClE71xMwgjiBDdO8kcc48Q==", + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/web-features/-/web-features-3.6.0.tgz", + "integrity": "sha512-XuxKJvAvdTXDw3U3jcabcWNOFmQHWhTa69O0+crQDjpe5s0Odc4NNASImW1n77Gye7leBzKchVswGfO86ZbNPA==", "dev": true, "license": "Apache-2.0" }, diff --git a/scripts/package.json b/scripts/package.json index ef36b6f..0ed194b 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -3,7 +3,7 @@ "type": "module", "devDependencies": { "octokit": "^5.0.3", - "web-features": "^2.48.0", + "web-features": "^3.6.0", "yargs": "^18.0.0" } }