Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gatsby-plugin-checker): add more filters to filter out bad packages #11093

Merged
merged 3 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions scripts/gatsby-plugin-checker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# gatsby-plugin-checker

This script searches the npm API for plugins that start with either "gatsby-source", "gatsby-plugin", or "gatsby-transformer" but don't have the "gatsby-plugin" keyword in their `package.json` and thus are not included in Gatsby's keyword search. The script will then notify those repositories by creating an issue notifying them to add the keyword to their `package.json` (This functionality will be included in the next commit). Once a repo has been notified, its `notified` attribute will be changed to `true` in `plugins.json` and won't be notified. Similarly, if a repo is a false positive or doesn't want to be notified, it can be `blacklisted`.
35 changes: 35 additions & 0 deletions scripts/gatsby-plugin-checker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,37 @@ const filterNotNotified = (packages, plugins) => {
return packages.filter(pkg => notified.indexOf(pkg.name) < 0)
}

const removePackagesWithoutRepository = packages =>
packages.filter(pkg => !!pkg.links.repository)

const removeBadNameFormats = packages => packages.filter(p => hasGoodName(p))

const hasGoodName = pkg => {
const name = pkg.name
const isScopedPackage = name.startsWith(`@`)
if (!isScopedPackage) {
return startsWithAllowedPrefix(name)
}

const nameWithoutScope = name.slice(0, name.indexOf(`/`))
return startsWithAllowedPrefix(nameWithoutScope)
}

const startsWithAllowedPrefix = name =>
keywords.some(keyword => name.startsWith(keyword))

const removePackagesWithoutReadme = packages =>
packages.filter(pkg => hasReadMe(pkg))

const hasReadMe = pkg => {
if (pkg.links.homepage || pkg.readme) return true
wardpeet marked this conversation as resolved.
Show resolved Hide resolved
if (pkg.links.repository) {
return got(pkg.links.repository + `/blob/master/README.md`)
.then(response => response.statusCode === 200)
.catch(_ => false)
} else return false
}

const updatePlugins = (updates, plugins) => {
let res = plugins.map(p => Object.assign({}, p))
updates.forEach(u => {
Expand All @@ -84,11 +115,15 @@ const main = () => {
.then(transformResults)
.then(packages => filterNotBlacklisted(packages, plugins))
.then(packages => filterNotNotified(packages, plugins))
.then(packages => removePackagesWithoutRepository(packages))
.then(packages => removeBadNameFormats(packages))
.then(packages => removePackagesWithoutReadme(packages))
.then(packages =>
packages.map(p => {
// TODO: notify / comment on github
console.info(`Notify package "${p.name}"`)
// return update status
// will turn notified to true once notifications are created
return { name: p.name, blacklist: false, notified: false }
})
)
Expand Down