Skip to content

Commit

Permalink
Remove import x statements (github#20594)
Browse files Browse the repository at this point in the history
* Clear out most import x

* Update rimraf use

* Move up readme blocks in scripts
  • Loading branch information
heiskr authored Jul 29, 2021
1 parent 1ed18e1 commit b29e373
Show file tree
Hide file tree
Showing 84 changed files with 551 additions and 524 deletions.
3 changes: 1 addition & 2 deletions lib/create-tree.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { fileURLToPath } from 'url'
import path from 'path'
import xFs from 'fs'
import fs from 'fs/promises'
import Page from './page.js'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const fs = xFs.promises

export default async function createTree(originalPath, langObj) {
// This basePath definition is needed both here and in lib/page-data.js because this
Expand Down
4 changes: 2 additions & 2 deletions lib/render-content/create-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import slug from 'rehype-slug'
import autolinkHeadings from 'rehype-autolink-headings'
import highlight from 'rehype-highlight'
import html from 'rehype-stringify'
import xHighlightjsGraphql from 'highlightjs-graphql'
import HighlightjsGraphql from 'highlightjs-graphql'
import remarkCodeExtra from 'remark-code-extra'
import codeHeader from './plugins/code-header.js'
import rewriteLocalLinks from './plugins/rewrite-local-links.js'
import useEnglishHeadings from './plugins/use-english-headings.js'
import rewriteLegacyAssetPaths from './plugins/rewrite-legacy-asset-paths.js'
import wrapInElement from './plugins/wrap-in-element.js'
const graphql = xHighlightjsGraphql.definer
const graphql = HighlightjsGraphql.definer

export default function createProcessor(context) {
return unified()
Expand Down
36 changes: 18 additions & 18 deletions lib/render-content/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import GithubSlugger from 'github-slugger'
import renderContent from './renderContent.js'
import { ExtendedMarkdown, tags } from '../liquid-tags/extended-markdown.js'
import xLink from '../liquid-tags/link.js'
import xLinkWithIntro from '../liquid-tags/link-with-intro.js'
import xLinkInList from '../liquid-tags/link-in-list.js'
import xTopicLinkInList from '../liquid-tags/topic-link-in-list.js'
import xIndentedDataReference from '../liquid-tags/indented-data-reference.js'
import xData from '../liquid-tags/data.js'
import xOcticon from '../liquid-tags/octicon.js'
import xLinkAsArticleCard from '../liquid-tags/link-as-article-card.js'
import xIfversion from '../liquid-tags/ifversion.js'
import Link from '../liquid-tags/link.js'
import LinkWithIntro from '../liquid-tags/link-with-intro.js'
import LinkInList from '../liquid-tags/link-in-list.js'
import TopicLinkInList from '../liquid-tags/topic-link-in-list.js'
import IndentedDataReference from '../liquid-tags/indented-data-reference.js'
import Data from '../liquid-tags/data.js'
import Octicon from '../liquid-tags/octicon.js'
import LinkAsArticleCard from '../liquid-tags/link-as-article-card.js'
import Ifversion from '../liquid-tags/ifversion.js'

// Include custom tags like {% link_with_intro /article/foo %}
renderContent.liquid.registerTag('link', xLink('link'))
renderContent.liquid.registerTag('link_with_intro', xLinkWithIntro)
renderContent.liquid.registerTag('link_in_list', xLinkInList)
renderContent.liquid.registerTag('topic_link_in_list', xTopicLinkInList)
renderContent.liquid.registerTag('indented_data_reference', xIndentedDataReference)
renderContent.liquid.registerTag('data', xData)
renderContent.liquid.registerTag('octicon', xOcticon)
renderContent.liquid.registerTag('link_as_article_card', xLinkAsArticleCard)
renderContent.liquid.registerTag('ifversion', xIfversion)
renderContent.liquid.registerTag('link', Link('link'))
renderContent.liquid.registerTag('link_with_intro', LinkWithIntro)
renderContent.liquid.registerTag('link_in_list', LinkInList)
renderContent.liquid.registerTag('topic_link_in_list', TopicLinkInList)
renderContent.liquid.registerTag('indented_data_reference', IndentedDataReference)
renderContent.liquid.registerTag('data', Data)
renderContent.liquid.registerTag('octicon', Octicon)
renderContent.liquid.registerTag('link_as_article_card', LinkAsArticleCard)
renderContent.liquid.registerTag('ifversion', Ifversion)

for (const tag in tags) {
// Register all the extended markdown tags, like {% note %} and {% warning %}
Expand Down
5 changes: 2 additions & 3 deletions lib/render-content/plugins/use-english-headings.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import GithubSlugger from 'github-slugger'
import xHtmlEntities from 'html-entities'
import HtmlEntities from 'html-entities'
import toString from 'hast-util-to-string'
import { visit } from 'unist-util-visit'
const Entities = xHtmlEntities.XmlEntities
const slugger = new GithubSlugger()
const entities = new Entities()
const entities = new HtmlEntities.XmlEntities()

const matcher = (node) => node.type === 'element' && ['h2', 'h3', 'h4'].includes(node.tagName)

Expand Down
5 changes: 2 additions & 3 deletions lib/render-content/renderContent.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import liquid from './liquid.js'
import cheerio from 'cheerio'
import xHtmlEntities from 'html-entities'
import HtmlEntities from 'html-entities'
import stripHtmlComments from 'strip-html-comments'
import createProcessor from './create-processor.js'
const Entities = xHtmlEntities.XmlEntities
const entities = new Entities()
const entities = new HtmlEntities.XmlEntities()

// used below to remove extra newlines in TOC lists
const endLine = '</a>\r?\n'
Expand Down
24 changes: 12 additions & 12 deletions lib/search/lunr-search.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { fileURLToPath } from 'url'
import path from 'path'
import lunr from 'lunr'
import xLunrStemmerSupport from 'lunr-languages/lunr.stemmer.support.js'
import xTinyseg from 'lunr-languages/tinyseg.js'
import xLunrJa from 'lunr-languages/lunr.ja.js'
import xLunrEs from 'lunr-languages/lunr.es.js'
import xLunrPt from 'lunr-languages/lunr.pt.js'
import xLunrDe from 'lunr-languages/lunr.de.js'
import lunrStemmerSupport from 'lunr-languages/lunr.stemmer.support.js'
import tinyseg from 'lunr-languages/tinyseg.js'
import lunrJa from 'lunr-languages/lunr.ja.js'
import lunrEs from 'lunr-languages/lunr.es.js'
import lunrPt from 'lunr-languages/lunr.pt.js'
import lunrDe from 'lunr-languages/lunr.de.js'
import { get } from 'lodash-es'
import readFileAsync from '../readfile-async.js'
import { namePrefix } from './config.js'
import { decompress } from './compress.js'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
xLunrStemmerSupport(lunr)
xTinyseg(lunr)
xLunrJa(lunr)
xLunrEs(lunr)
xLunrPt(lunr)
xLunrDe(lunr)
lunrStemmerSupport(lunr)
tinyseg(lunr)
lunrJa(lunr)
lunrEs(lunr)
lunrPt(lunr)
lunrDe(lunr)

const LUNR_DIR = './indexes'
const lunrIndexes = new Map()
Expand Down
5 changes: 2 additions & 3 deletions lib/use-english-headings.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import GithubSlugger from 'github-slugger'
import xHtmlEntities from 'html-entities'
import HtmlEntities from 'html-entities'
const slugger = new GithubSlugger()
const Entities = xHtmlEntities.XmlEntities
const entities = new Entities()
const entities = new HtmlEntities.XmlEntities()

// replace translated IDs and links in headings with English
export default function useEnglishHeadings($, englishHeadings) {
Expand Down
4 changes: 2 additions & 2 deletions middleware/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import languages from '../lib/languages.js'
import enterpriseServerReleases from '../lib/enterprise-server-releases.js'
import { allVersions } from '../lib/all-versions.js'
import { productMap } from '../lib/all-products.js'
import xPathUtils from '../lib/path-utils.js'
import pathUtils from '../lib/path-utils.js'
import productNames from '../lib/product-names.js'
import warmServer from '../lib/warm-server.js'
import readJsonFile from '../lib/read-json-file.js'
Expand All @@ -16,7 +16,7 @@ const {
getProductStringFromPath,
getCategoryStringFromPath,
getPathWithoutLanguage,
} = xPathUtils
} = pathUtils
const featureFlags = Object.keys(readJsonFile('./feature-flags.json'))

// Supply all route handlers with a baseline `req.context` object
Expand Down
6 changes: 3 additions & 3 deletions middleware/cookie-parser.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import xCookieParser from 'cookie-parser'
import xCookieSettings from '../lib/cookie-settings.js'
export default xCookieParser(process.env.COOKIE_SECRET, xCookieSettings)
import cookieParser from 'cookie-parser'
import cookieSettings from '../lib/cookie-settings.js'
export default cookieParser(process.env.COOKIE_SECRET, cookieSettings)
4 changes: 2 additions & 2 deletions middleware/cors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import xCors from 'cors'
export default xCors({
import cors from 'cors'
export default cors({
origin: '*',
methods: ['GET', 'HEAD'],
})
4 changes: 2 additions & 2 deletions middleware/csrf.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cookieSettings from '../lib/cookie-settings.js'
import xCsurf from 'csurf'
import csurf from 'csurf'

export default xCsurf({
export default csurf({
cookie: cookieSettings,
ignoreMethods: ['GET', 'HEAD', 'OPTIONS'],
})
4 changes: 2 additions & 2 deletions middleware/detect-language.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import xLanguages from '../lib/languages.js'
import libLanguages from '../lib/languages.js'
import parser from 'accept-language-parser'
const languageCodes = Object.keys(xLanguages)
const languageCodes = Object.keys(libLanguages)

const chineseRegions = ['CN', 'HK']

Expand Down
5 changes: 3 additions & 2 deletions script/anonymize-branch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env node
import { execSync as exec } from 'child_process'
import path from 'path'

// [start-readme]
//
Expand All @@ -12,6 +10,9 @@ import path from 'path'
//
// [end-readme]

import { execSync as exec } from 'child_process'
import path from 'path'

process.env.GIT_AUTHOR_NAME = process.env.GIT_COMMITTER_NAME = 'Octomerger Bot'
process.env.GIT_AUTHOR_EMAIL = process.env.GIT_COMMITTER_EMAIL =
'[email protected]'
Expand Down
35 changes: 17 additions & 18 deletions script/backfill-missing-localizations.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
#!/usr/bin/env node
import { fileURLToPath } from 'url'
import path from 'path'
import fs from 'fs'
import walk from 'walk-sync'
import xMkdirp from 'mkdirp'
import languages from '../lib/languages.js'
const __dirname = path.dirname(fileURLToPath(import.meta.url))

const mkdirp = xMkdirp.sync

const dirs = ['content', 'data']

// [start-readme]
//
Expand All @@ -18,24 +7,34 @@ const dirs = ['content', 'data']
//
// [end-readme]

dirs.forEach((dir) => {
import { fileURLToPath } from 'url'
import path from 'path'
import fs from 'fs'
import walk from 'walk-sync'
import mkdirp from 'mkdirp'
import languages from '../lib/languages.js'

const __dirname = path.dirname(fileURLToPath(import.meta.url))
const dirs = ['content', 'data']

for (const dir of dirs) {
const englishPath = path.join(__dirname, `../${dir}`)
const filenames = walk(englishPath).filter((filename) => {
return (
(filename.endsWith('.yml') || filename.endsWith('.md')) && !filename.endsWith('README.md')
)
})

filenames.forEach((filename) => {
Object.values(languages).forEach((language) => {
for (const filename of filenames) {
for (const language of Object.values(languages)) {
if (language.code === 'en') return
const fullPath = path.join(__dirname, '..', language.dir, dir, filename)
if (!fs.existsSync(fullPath)) {
console.log('missing', fullPath)
const englishFullPath = path.join(__dirname, '..', dir, filename)
mkdirp(path.dirname(fullPath))
await mkdirp(path.dirname(fullPath))
fs.writeFileSync(fullPath, fs.readFileSync(englishFullPath))
}
})
})
})
}
}
}
35 changes: 17 additions & 18 deletions script/check-english-links.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
#!/usr/bin/env node

// [start-readme]
//
// This script runs once per day via a scheduled GitHub Action to check all links in
// English content, not including deprecated Enterprise Server content. It opens an issue
// if it finds broken links. To exclude a link path, add it to `lib/excluded-links.js`.
// Note that linkinator somtimes returns 429 and 503 errors for links that are not actually
// broken, so this script double-checks those using `got`.
//
// [end-readme]

import { fileURLToPath } from 'url'
import path from 'path'
import fs from 'fs'
import linkinator from 'linkinator'
import program from 'commander'
import { pull, uniq } from 'lodash-es'
import xRimraf from 'rimraf'
import xMkdirp from 'mkdirp'
import rimraf from 'rimraf'
import mkdirp from 'mkdirp'
import { deprecated } from '../lib/enterprise-server-releases.js'
import got from 'got'
import excludedLinks from '../lib/excluded-links.js'
import xLanguages from '../lib/languages.js'
import libLanguages from '../lib/languages.js'
const __dirname = path.dirname(fileURLToPath(import.meta.url))

const checker = new linkinator.LinkChecker()
const rimraf = xRimraf.sync
const mkdirp = xMkdirp.sync
const root = 'https://docs.github.com'
const englishRoot = `${root}/en`

// Links with these codes may or may not really be broken.
const retryStatusCodes = [429, 503, 'Invalid']

// [start-readme]
//
// This script runs once per day via a scheduled GitHub Action to check all links in
// English content, not including deprecated Enterprise Server content. It opens an issue
// if it finds broken links. To exclude a link path, add it to `lib/excluded-links.js`.
// Note that linkinator somtimes returns 429 and 503 errors for links that are not actually
// broken, so this script double-checks those using `got`.
//
// [end-readme]

program
.description('Check all links in the English docs.')
.option(
Expand All @@ -51,7 +50,7 @@ program
// Skip excluded links defined in separate file.

// Skip non-English content.
const languagesToSkip = Object.keys(xLanguages)
const languagesToSkip = Object.keys(libLanguages)
.filter((code) => code !== 'en')
.map((code) => `${root}/${code}`)

Expand All @@ -75,8 +74,8 @@ main()
async function main() {
// Clear and recreate a directory for logs.
const logFile = path.join(__dirname, '../.linkinator/full.log')
rimraf(path.dirname(logFile))
mkdirp(path.dirname(logFile))
rimraf.sync(path.dirname(logFile))
await mkdirp(path.dirname(logFile))

// Update CLI output and append to logfile after each checked link.
checker.on('link', (result) => {
Expand Down
13 changes: 7 additions & 6 deletions script/check-internal-links.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#!/usr/bin/env node
import linkinator from 'linkinator'
import { deprecated, latest } from '../lib/enterprise-server-releases.js'

const checker = new linkinator.LinkChecker()
const englishRoot = 'http://localhost:4002/en'
const allowedVersions = ['dotcom', 'enterprise-server', 'github-ae']

// [start-readme]
//
Expand All @@ -17,6 +11,13 @@ const allowedVersions = ['dotcom', 'enterprise-server', 'github-ae']
//
// [end-readme]

import linkinator from 'linkinator'
import { deprecated, latest } from '../lib/enterprise-server-releases.js'

const checker = new linkinator.LinkChecker()
const englishRoot = 'http://localhost:4002/en'
const allowedVersions = ['dotcom', 'enterprise-server', 'github-ae']

const config = {
path: englishRoot,
// Use concurrency = 10 to optimize for Actions
Expand Down
4 changes: 1 addition & 3 deletions script/content-migrations/add-tags-to-articles.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#!/usr/bin/env node
import fs from 'fs'
import path from 'path'
import xXlsxPopulate from 'xlsx-populate'
import XlsxPopulate from 'xlsx-populate' // this is an optional dependency, install with `npm i --include=optional`
import readFrontmatter from '../../lib/read-frontmatter.js'

const XlsxPopulate = xXlsxPopulate // this is an optional dependency, install with `npm i --include=optional`

const START_ROW = 2

// Load an existing workbook
Expand Down
Loading

0 comments on commit b29e373

Please sign in to comment.