1
0
mirror of synced 2025-12-23 11:54:18 -05:00
Files
docs/lib/patterns.js
Kevin Heis 42e785b0a8 Migrate CommonJS to ESM (#20301)
* First run of script

* Get the app running --- ish

* Get NextJS working

* Remove `node:`

* Get more tests passing in unit directory

* Update FailBot test to use nock

* Update test.yml

* Update Dockerfile

* tests/content fixes

* Update page.js

* Update build-changelog.js

* updating tests/routing

* Update orphan-tests.js

* updating tests/rendering

* Update .eslintrc.js

* Update .eslintrc.js

* Install jest/globals

* "linting" tests

* staging update to server.mjs

* Change '.github/allowed-actions.js' to a ESM export

* Lint

* Fixes for the main package.json

* Move Jest to be last in the npm test command so we can pass args

* Just use 'npm run lint' in the npm test command

* update algolia label script

* update openapi script

* update require on openapi

* Update enterprise-algolia-label.js

* forgot JSON.parse

* Update lunr-search-index.js

* Always explicitly include process.cwd() for JSON file reads pathed from project root

* update graphql/update-files.js script

* Update other npm scripts using jest to pass ESM NODE_OPTIONS

* Update check-for-enterprise-issues-by-label.js for ESM

* Update create-enterprise-issue.js for ESM

* Import jest global for browser tests

* Convert 'script/deploy' to ESM

Co-authored-by: Grace Park <gracepark@github.com>
Co-authored-by: James M. Greene <jamesmgreene@github.com>
2021-07-14 13:49:18 -07:00

77 lines
3.1 KiB
JavaScript

// This module is intended to keep our use of regular expressions DRY,
// and to reduce the overhead of instantiating new RegExp objects
// if we're looking for part of a path, like /github,
// we allow for four characters after the string: (\/|$|\?|#)
// slash (/), end of line ($), query param (?), fragment (#)
// this will ensure we capture: /github/foo, /github, /github?query=foo, /github#foo
// and not capture: /github-foo
export const githubDotcom = /\/github(\/|$|\?|#)/
// we want to capture `/enterprise` and `/enterprise/foo` but NOT `/enterprise-admin`
export const enterprise = /\/enterprise(?:\/|$|\?)(\d+\.\d+)?/
export const admin = /enterprise\/(\d+\.\d+\/)?admin\/?/
export const gheUser = /enterprise\/(\d+\.\d+\/)?user(\/|$|\?)/
export const enterpriseHomepage = /\/enterprise\/?(\d+\.\d+)?$/
export const desktop = /desktop\//
export const oldGuidesPath = /(\/admin|(^|\/)desktop)\/guides/
// need to capture 11.10.340 and 2.0+
export const getEnterpriseVersionNumber = /^.*?enterprise\/(\d+\.\d+(?:\.340)?).*?$/
export const removeEnterpriseVersion = /(enterprise\/)\d+\.\d+\//
export const guides = /guides\//
export const hasLanguageCode = /^\/[a-z]{2}(\/|$|\?)/
export const getLanguageCode = /^\/([a-z]{2})/
export const trailingSlash = /^(.+?)\/+?$/
export const searchPath = /\/search(?:\/)?(\?)/
export const ymd = /^\d{4}-\d{2}-\d{2}$/
export const hasLiquid = /[{{][{%]/
export const dataReference = /{% ?data\s(?:early-access\.)?(?:reusables|variables|ui)\..*?%}/gm
export const imagePath = /\/?assets\/images\/.*?\.(png|svg|gif|pdf|ico|jpg|jpeg)/gi
export const homepagePath = /^\/\w{2}$/ // /en, /ja /cn
export const multipleSlashes = /^\/{2,}/
export const assetPaths = /\/(?:javascripts|stylesheets|assets|node_modules|dist)\//
export const oldApiPath = /\/v[34]\/(?!guides|overview).+?\/.+/
export const staticRedirect = /<link rel="canonical" href="(.+?)">/
export const enterpriseNoVersion = /\/enterprise\/([^\d].*$)/
// a {{ currentVersion }} in internal links may inject '<new-version@release>' into old paths,
// so the oldEnterprisePath regex must match: /enterprise/private-instances@latest/user,
// /enterprise/enterprise-server@2.22/user, /enterprise/2.22/user, and /enterprise/user
export const oldEnterprisePath = /\/([a-z]{2}\/)?(enterprise\/)?(\S+?@(\S+?\/))?(\d.\d+\/)?(user[/$])?/
// new versioning format patterns
export const adminProduct = /\/admin(\/|$|\?|#)/
export const insightsProduct = /\/insights(\/|$|\?|#)/
export const enterpriseServer = /\/enterprise-server@/
export const getEnterpriseServerNumber = /enterprise-server@(\d+\.\d+)/
export default {
githubDotcom,
enterprise,
admin,
gheUser,
enterpriseHomepage,
desktop,
oldGuidesPath,
getEnterpriseVersionNumber,
removeEnterpriseVersion,
guides,
hasLanguageCode,
getLanguageCode,
trailingSlash,
searchPath,
ymd,
hasLiquid,
dataReference,
imagePath,
homepagePath,
multipleSlashes,
assetPaths,
oldApiPath,
staticRedirect,
enterpriseNoVersion,
oldEnterprisePath,
adminProduct,
insightsProduct,
enterpriseServer,
getEnterpriseServerNumber,
}