Skip to content

Commit b29e373

Browse files
authored
Remove import x statements (github#20594)
* Clear out most import x * Update rimraf use * Move up readme blocks in scripts
1 parent 1ed18e1 commit b29e373

File tree

84 files changed

+551
-524
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+551
-524
lines changed

lib/create-tree.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { fileURLToPath } from 'url'
22
import path from 'path'
3-
import xFs from 'fs'
3+
import fs from 'fs/promises'
44
import Page from './page.js'
55
const __dirname = path.dirname(fileURLToPath(import.meta.url))
6-
const fs = xFs.promises
76

87
export default async function createTree(originalPath, langObj) {
98
// This basePath definition is needed both here and in lib/page-data.js because this

lib/render-content/create-processor.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import slug from 'rehype-slug'
99
import autolinkHeadings from 'rehype-autolink-headings'
1010
import highlight from 'rehype-highlight'
1111
import html from 'rehype-stringify'
12-
import xHighlightjsGraphql from 'highlightjs-graphql'
12+
import HighlightjsGraphql from 'highlightjs-graphql'
1313
import remarkCodeExtra from 'remark-code-extra'
1414
import codeHeader from './plugins/code-header.js'
1515
import rewriteLocalLinks from './plugins/rewrite-local-links.js'
1616
import useEnglishHeadings from './plugins/use-english-headings.js'
1717
import rewriteLegacyAssetPaths from './plugins/rewrite-legacy-asset-paths.js'
1818
import wrapInElement from './plugins/wrap-in-element.js'
19-
const graphql = xHighlightjsGraphql.definer
19+
const graphql = HighlightjsGraphql.definer
2020

2121
export default function createProcessor(context) {
2222
return unified()

lib/render-content/index.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import GithubSlugger from 'github-slugger'
22
import renderContent from './renderContent.js'
33
import { ExtendedMarkdown, tags } from '../liquid-tags/extended-markdown.js'
4-
import xLink from '../liquid-tags/link.js'
5-
import xLinkWithIntro from '../liquid-tags/link-with-intro.js'
6-
import xLinkInList from '../liquid-tags/link-in-list.js'
7-
import xTopicLinkInList from '../liquid-tags/topic-link-in-list.js'
8-
import xIndentedDataReference from '../liquid-tags/indented-data-reference.js'
9-
import xData from '../liquid-tags/data.js'
10-
import xOcticon from '../liquid-tags/octicon.js'
11-
import xLinkAsArticleCard from '../liquid-tags/link-as-article-card.js'
12-
import xIfversion from '../liquid-tags/ifversion.js'
4+
import Link from '../liquid-tags/link.js'
5+
import LinkWithIntro from '../liquid-tags/link-with-intro.js'
6+
import LinkInList from '../liquid-tags/link-in-list.js'
7+
import TopicLinkInList from '../liquid-tags/topic-link-in-list.js'
8+
import IndentedDataReference from '../liquid-tags/indented-data-reference.js'
9+
import Data from '../liquid-tags/data.js'
10+
import Octicon from '../liquid-tags/octicon.js'
11+
import LinkAsArticleCard from '../liquid-tags/link-as-article-card.js'
12+
import Ifversion from '../liquid-tags/ifversion.js'
1313

1414
// Include custom tags like {% link_with_intro /article/foo %}
15-
renderContent.liquid.registerTag('link', xLink('link'))
16-
renderContent.liquid.registerTag('link_with_intro', xLinkWithIntro)
17-
renderContent.liquid.registerTag('link_in_list', xLinkInList)
18-
renderContent.liquid.registerTag('topic_link_in_list', xTopicLinkInList)
19-
renderContent.liquid.registerTag('indented_data_reference', xIndentedDataReference)
20-
renderContent.liquid.registerTag('data', xData)
21-
renderContent.liquid.registerTag('octicon', xOcticon)
22-
renderContent.liquid.registerTag('link_as_article_card', xLinkAsArticleCard)
23-
renderContent.liquid.registerTag('ifversion', xIfversion)
15+
renderContent.liquid.registerTag('link', Link('link'))
16+
renderContent.liquid.registerTag('link_with_intro', LinkWithIntro)
17+
renderContent.liquid.registerTag('link_in_list', LinkInList)
18+
renderContent.liquid.registerTag('topic_link_in_list', TopicLinkInList)
19+
renderContent.liquid.registerTag('indented_data_reference', IndentedDataReference)
20+
renderContent.liquid.registerTag('data', Data)
21+
renderContent.liquid.registerTag('octicon', Octicon)
22+
renderContent.liquid.registerTag('link_as_article_card', LinkAsArticleCard)
23+
renderContent.liquid.registerTag('ifversion', Ifversion)
2424

2525
for (const tag in tags) {
2626
// Register all the extended markdown tags, like {% note %} and {% warning %}

lib/render-content/plugins/use-english-headings.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import GithubSlugger from 'github-slugger'
2-
import xHtmlEntities from 'html-entities'
2+
import HtmlEntities from 'html-entities'
33
import toString from 'hast-util-to-string'
44
import { visit } from 'unist-util-visit'
5-
const Entities = xHtmlEntities.XmlEntities
65
const slugger = new GithubSlugger()
7-
const entities = new Entities()
6+
const entities = new HtmlEntities.XmlEntities()
87

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

lib/render-content/renderContent.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import liquid from './liquid.js'
22
import cheerio from 'cheerio'
3-
import xHtmlEntities from 'html-entities'
3+
import HtmlEntities from 'html-entities'
44
import stripHtmlComments from 'strip-html-comments'
55
import createProcessor from './create-processor.js'
6-
const Entities = xHtmlEntities.XmlEntities
7-
const entities = new Entities()
6+
const entities = new HtmlEntities.XmlEntities()
87

98
// used below to remove extra newlines in TOC lists
109
const endLine = '</a>\r?\n'

lib/search/lunr-search.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import { fileURLToPath } from 'url'
22
import path from 'path'
33
import lunr from 'lunr'
4-
import xLunrStemmerSupport from 'lunr-languages/lunr.stemmer.support.js'
5-
import xTinyseg from 'lunr-languages/tinyseg.js'
6-
import xLunrJa from 'lunr-languages/lunr.ja.js'
7-
import xLunrEs from 'lunr-languages/lunr.es.js'
8-
import xLunrPt from 'lunr-languages/lunr.pt.js'
9-
import xLunrDe from 'lunr-languages/lunr.de.js'
4+
import lunrStemmerSupport from 'lunr-languages/lunr.stemmer.support.js'
5+
import tinyseg from 'lunr-languages/tinyseg.js'
6+
import lunrJa from 'lunr-languages/lunr.ja.js'
7+
import lunrEs from 'lunr-languages/lunr.es.js'
8+
import lunrPt from 'lunr-languages/lunr.pt.js'
9+
import lunrDe from 'lunr-languages/lunr.de.js'
1010
import { get } from 'lodash-es'
1111
import readFileAsync from '../readfile-async.js'
1212
import { namePrefix } from './config.js'
1313
import { decompress } from './compress.js'
1414
const __dirname = path.dirname(fileURLToPath(import.meta.url))
15-
xLunrStemmerSupport(lunr)
16-
xTinyseg(lunr)
17-
xLunrJa(lunr)
18-
xLunrEs(lunr)
19-
xLunrPt(lunr)
20-
xLunrDe(lunr)
15+
lunrStemmerSupport(lunr)
16+
tinyseg(lunr)
17+
lunrJa(lunr)
18+
lunrEs(lunr)
19+
lunrPt(lunr)
20+
lunrDe(lunr)
2121

2222
const LUNR_DIR = './indexes'
2323
const lunrIndexes = new Map()

lib/use-english-headings.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import GithubSlugger from 'github-slugger'
2-
import xHtmlEntities from 'html-entities'
2+
import HtmlEntities from 'html-entities'
33
const slugger = new GithubSlugger()
4-
const Entities = xHtmlEntities.XmlEntities
5-
const entities = new Entities()
4+
const entities = new HtmlEntities.XmlEntities()
65

76
// replace translated IDs and links in headings with English
87
export default function useEnglishHeadings($, englishHeadings) {

middleware/context.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import languages from '../lib/languages.js'
22
import enterpriseServerReleases from '../lib/enterprise-server-releases.js'
33
import { allVersions } from '../lib/all-versions.js'
44
import { productMap } from '../lib/all-products.js'
5-
import xPathUtils from '../lib/path-utils.js'
5+
import pathUtils from '../lib/path-utils.js'
66
import productNames from '../lib/product-names.js'
77
import warmServer from '../lib/warm-server.js'
88
import readJsonFile from '../lib/read-json-file.js'
@@ -16,7 +16,7 @@ const {
1616
getProductStringFromPath,
1717
getCategoryStringFromPath,
1818
getPathWithoutLanguage,
19-
} = xPathUtils
19+
} = pathUtils
2020
const featureFlags = Object.keys(readJsonFile('./feature-flags.json'))
2121

2222
// Supply all route handlers with a baseline `req.context` object

middleware/cookie-parser.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import xCookieParser from 'cookie-parser'
2-
import xCookieSettings from '../lib/cookie-settings.js'
3-
export default xCookieParser(process.env.COOKIE_SECRET, xCookieSettings)
1+
import cookieParser from 'cookie-parser'
2+
import cookieSettings from '../lib/cookie-settings.js'
3+
export default cookieParser(process.env.COOKIE_SECRET, cookieSettings)

middleware/cors.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import xCors from 'cors'
2-
export default xCors({
1+
import cors from 'cors'
2+
export default cors({
33
origin: '*',
44
methods: ['GET', 'HEAD'],
55
})

middleware/csrf.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import cookieSettings from '../lib/cookie-settings.js'
2-
import xCsurf from 'csurf'
2+
import csurf from 'csurf'
33

4-
export default xCsurf({
4+
export default csurf({
55
cookie: cookieSettings,
66
ignoreMethods: ['GET', 'HEAD', 'OPTIONS'],
77
})

middleware/detect-language.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import xLanguages from '../lib/languages.js'
1+
import libLanguages from '../lib/languages.js'
22
import parser from 'accept-language-parser'
3-
const languageCodes = Object.keys(xLanguages)
3+
const languageCodes = Object.keys(libLanguages)
44

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

script/anonymize-branch.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#!/usr/bin/env node
2-
import { execSync as exec } from 'child_process'
3-
import path from 'path'
42

53
// [start-readme]
64
//
@@ -12,6 +10,9 @@ import path from 'path'
1210
//
1311
// [end-readme]
1412

13+
import { execSync as exec } from 'child_process'
14+
import path from 'path'
15+
1516
process.env.GIT_AUTHOR_NAME = process.env.GIT_COMMITTER_NAME = 'Octomerger Bot'
1617
process.env.GIT_AUTHOR_EMAIL = process.env.GIT_COMMITTER_EMAIL =
1718
+17-18
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
11
#!/usr/bin/env node
2-
import { fileURLToPath } from 'url'
3-
import path from 'path'
4-
import fs from 'fs'
5-
import walk from 'walk-sync'
6-
import xMkdirp from 'mkdirp'
7-
import languages from '../lib/languages.js'
8-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
9-
10-
const mkdirp = xMkdirp.sync
11-
12-
const dirs = ['content', 'data']
132

143
// [start-readme]
154
//
@@ -18,24 +7,34 @@ const dirs = ['content', 'data']
187
//
198
// [end-readme]
209

21-
dirs.forEach((dir) => {
10+
import { fileURLToPath } from 'url'
11+
import path from 'path'
12+
import fs from 'fs'
13+
import walk from 'walk-sync'
14+
import mkdirp from 'mkdirp'
15+
import languages from '../lib/languages.js'
16+
17+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
18+
const dirs = ['content', 'data']
19+
20+
for (const dir of dirs) {
2221
const englishPath = path.join(__dirname, `../${dir}`)
2322
const filenames = walk(englishPath).filter((filename) => {
2423
return (
2524
(filename.endsWith('.yml') || filename.endsWith('.md')) && !filename.endsWith('README.md')
2625
)
2726
})
2827

29-
filenames.forEach((filename) => {
30-
Object.values(languages).forEach((language) => {
28+
for (const filename of filenames) {
29+
for (const language of Object.values(languages)) {
3130
if (language.code === 'en') return
3231
const fullPath = path.join(__dirname, '..', language.dir, dir, filename)
3332
if (!fs.existsSync(fullPath)) {
3433
console.log('missing', fullPath)
3534
const englishFullPath = path.join(__dirname, '..', dir, filename)
36-
mkdirp(path.dirname(fullPath))
35+
await mkdirp(path.dirname(fullPath))
3736
fs.writeFileSync(fullPath, fs.readFileSync(englishFullPath))
3837
}
39-
})
40-
})
41-
})
38+
}
39+
}
40+
}

script/check-english-links.js

+17-18
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
11
#!/usr/bin/env node
2+
3+
// [start-readme]
4+
//
5+
// This script runs once per day via a scheduled GitHub Action to check all links in
6+
// English content, not including deprecated Enterprise Server content. It opens an issue
7+
// if it finds broken links. To exclude a link path, add it to `lib/excluded-links.js`.
8+
// Note that linkinator somtimes returns 429 and 503 errors for links that are not actually
9+
// broken, so this script double-checks those using `got`.
10+
//
11+
// [end-readme]
12+
213
import { fileURLToPath } from 'url'
314
import path from 'path'
415
import fs from 'fs'
516
import linkinator from 'linkinator'
617
import program from 'commander'
718
import { pull, uniq } from 'lodash-es'
8-
import xRimraf from 'rimraf'
9-
import xMkdirp from 'mkdirp'
19+
import rimraf from 'rimraf'
20+
import mkdirp from 'mkdirp'
1021
import { deprecated } from '../lib/enterprise-server-releases.js'
1122
import got from 'got'
1223
import excludedLinks from '../lib/excluded-links.js'
13-
import xLanguages from '../lib/languages.js'
24+
import libLanguages from '../lib/languages.js'
1425
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1526

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

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

25-
// [start-readme]
26-
//
27-
// This script runs once per day via a scheduled GitHub Action to check all links in
28-
// English content, not including deprecated Enterprise Server content. It opens an issue
29-
// if it finds broken links. To exclude a link path, add it to `lib/excluded-links.js`.
30-
// Note that linkinator somtimes returns 429 and 503 errors for links that are not actually
31-
// broken, so this script double-checks those using `got`.
32-
//
33-
// [end-readme]
34-
3534
program
3635
.description('Check all links in the English docs.')
3736
.option(
@@ -51,7 +50,7 @@ program
5150
// Skip excluded links defined in separate file.
5251

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

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

8180
// Update CLI output and append to logfile after each checked link.
8281
checker.on('link', (result) => {

script/check-internal-links.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
#!/usr/bin/env node
2-
import linkinator from 'linkinator'
3-
import { deprecated, latest } from '../lib/enterprise-server-releases.js'
4-
5-
const checker = new linkinator.LinkChecker()
6-
const englishRoot = 'http://localhost:4002/en'
7-
const allowedVersions = ['dotcom', 'enterprise-server', 'github-ae']
82

93
// [start-readme]
104
//
@@ -17,6 +11,13 @@ const allowedVersions = ['dotcom', 'enterprise-server', 'github-ae']
1711
//
1812
// [end-readme]
1913

14+
import linkinator from 'linkinator'
15+
import { deprecated, latest } from '../lib/enterprise-server-releases.js'
16+
17+
const checker = new linkinator.LinkChecker()
18+
const englishRoot = 'http://localhost:4002/en'
19+
const allowedVersions = ['dotcom', 'enterprise-server', 'github-ae']
20+
2021
const config = {
2122
path: englishRoot,
2223
// Use concurrency = 10 to optimize for Actions

script/content-migrations/add-tags-to-articles.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#!/usr/bin/env node
22
import fs from 'fs'
33
import path from 'path'
4-
import xXlsxPopulate from 'xlsx-populate'
4+
import XlsxPopulate from 'xlsx-populate' // this is an optional dependency, install with `npm i --include=optional`
55
import readFrontmatter from '../../lib/read-frontmatter.js'
66

7-
const XlsxPopulate = xXlsxPopulate // this is an optional dependency, install with `npm i --include=optional`
8-
97
const START_ROW = 2
108

119
// Load an existing workbook

0 commit comments

Comments
 (0)