From 7f6a277a8e15e331b8046611b4ec12b597ef331d Mon Sep 17 00:00:00 2001 From: Grace Park Date: Fri, 18 Jun 2021 13:08:28 -0700 Subject: [PATCH] clear out dynamic require --- .eslintrc.js | 3 +- middleware/contextualizers/webhooks.js | 3 +- middleware/index.js | 73 +++++++++---------- .../remove-version-markup.js | 3 +- .../create-graphql-files.js | 8 +- 5 files changed, 45 insertions(+), 45 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index f630fa3c0d82..98b63e7f2687 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -16,7 +16,8 @@ module.exports = { }, rules: { 'import/no-extraneous-dependencies': ['error'], - 'node/global-require': ['error'] + 'node/global-require': ['error'], + 'import/no-dynamic-require': ['error'] }, overrides: [ { diff --git a/middleware/contextualizers/webhooks.js b/middleware/contextualizers/webhooks.js index 90347b36fd68..935dffe2383c 100644 --- a/middleware/contextualizers/webhooks.js +++ b/middleware/contextualizers/webhooks.js @@ -1,6 +1,5 @@ -const path = require('path') const { defaults } = require('lodash') -const webhookPayloads = require(path.join(process.cwd(), 'lib/webhooks')) +const webhookPayloads = require('../../lib/webhooks') const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version') const allVersions = require('../../lib/all-versions') diff --git a/middleware/index.js b/middleware/index.js index 16c4037060de..267fa03f3416 100644 --- a/middleware/index.js +++ b/middleware/index.js @@ -1,4 +1,3 @@ -const path = require('path') const express = require('express') const instrument = require('../lib/instrument-middleware') const haltOnDroppedConnection = require('./halt-on-dropped-connection') @@ -23,42 +22,42 @@ const reqUtils = require('./req-utils') const recordRedirect = require('./record-redirect') const connectSlashes = require('connect-slashes') const handleErrors = require('./handle-errors') -const handleInvalidPaths = require(path.resolve(process.cwd(), './middleware', './handle-invalid-paths')) -const detectLanguage = require(path.resolve(process.cwd(), './middleware', './detect-language')) -const context = require(path.resolve(process.cwd(), './middleware', './context')) -const shortVersions = require(path.resolve(process.cwd(), './middleware', './contextualizers/short-versions')) -const redirectsExternal = require(path.resolve(process.cwd(), './middleware', './redirects/external')) -const helpToDocs = require(path.resolve(process.cwd(), './middleware', './redirects/help-to-docs')) -const languageCodeRedirects = require(path.resolve(process.cwd(), './middleware', './redirects/language-code-redirects')) -const handleRedirects = require(path.resolve(process.cwd(), './middleware', './redirects/handle-redirects')) -const findPage = require(path.resolve(process.cwd(), './middleware', './find-page')) -const blockRobots = require(path.resolve(process.cwd(), './middleware', './block-robots')) -const archivedEnterpriseVersionsAssets = require(path.resolve(process.cwd(), './middleware', './archived-enterprise-versions-assets')) -const events = require(path.resolve(process.cwd(), './middleware', './events')) -const search = require(path.resolve(process.cwd(), './middleware', './search')) -const archivedEnterpriseVersions = require(path.resolve(process.cwd(), './middleware', './archived-enterprise-versions')) -const robots = require(path.resolve(process.cwd(), './middleware', './robots')) -const earlyAccessLinks = require(path.resolve(process.cwd(), './middleware', './contextualizers/early-access-links')) -const categoriesForSupport = require(path.resolve(process.cwd(), './middleware', './categories-for-support')) -const loaderio = require(path.resolve(process.cwd(), './middleware', './loaderio-verification')) -const triggerError = require(path.resolve(process.cwd(), './middleware', './trigger-error')) -const releaseNotes = require(path.resolve(process.cwd(), './middleware', './contextualizers/release-notes')) -const whatsNewChangelog = require(path.resolve(process.cwd(), './middleware', './contextualizers/whats-new-changelog')) -const graphQL = require(path.resolve(process.cwd(), './middleware', './contextualizers/graphql')) -const rest = require(path.resolve(process.cwd(), './middleware', './contextualizers/rest')) -const webhooks = require(path.resolve(process.cwd(), './middleware', './contextualizers/webhooks')) -const layout = require(path.resolve(process.cwd(), './middleware', './contextualizers/layout')) -const currentProductTree = require(path.resolve(process.cwd(), './middleware', './contextualizers/current-product-tree')) -const genericToc = require(path.resolve(process.cwd(), './middleware', './contextualizers/generic-toc')) -const breadcrumbs = require(path.resolve(process.cwd(), './middleware', './contextualizers/breadcrumbs')) -const earlyAccessBreadcrumbs = require(path.resolve(process.cwd(), './middleware', './contextualizers/early-access-breadcrumbs')) -const productExamples = require(path.resolve(process.cwd(), './middleware', './contextualizers/product-examples')) -const devToc = require(path.resolve(process.cwd(), './middleware', './dev-toc')) -const featuredLinks = require(path.resolve(process.cwd(), './middleware', './featured-links')) -const learningTrack = require(path.resolve(process.cwd(), './middleware', './learning-track')) -const isNextRequest = require(path.resolve(process.cwd(), './middleware', './is-next-request')) -const next = require(path.resolve(process.cwd(), './middleware', './next')) -const renderPage = require(path.resolve(process.cwd(), './middleware', './render-page')) +const handleInvalidPaths = require('./handle-invalid-paths') +const detectLanguage = require('./detect-language') +const context = require('./context') +const shortVersions = require('./contextualizers/short-versions') +const redirectsExternal = require('./redirects/external') +const helpToDocs = require('./redirects/help-to-docs') +const languageCodeRedirects = require('./redirects/language-code-redirects') +const handleRedirects = require('./redirects/handle-redirects') +const findPage = require('./find-page') +const blockRobots = require('./block-robots') +const archivedEnterpriseVersionsAssets = require('./archived-enterprise-versions-assets') +const events = require('./events') +const search = require('./search') +const archivedEnterpriseVersions = require('./archived-enterprise-versions') +const robots = require('./robots') +const earlyAccessLinks = require('./contextualizers/early-access-links') +const categoriesForSupport = require('./categories-for-support') +const loaderio = require('./loaderio-verification') +const triggerError = require('./trigger-error') +const releaseNotes = require('./contextualizers/release-notes') +const whatsNewChangelog = require('./contextualizers/whats-new-changelog') +const graphQL = require('./contextualizers/graphql') +const rest = require('./contextualizers/rest') +const webhooks = require('./contextualizers/webhooks') +const layout = require('./contextualizers/layout') +const currentProductTree = require('./contextualizers/current-product-tree') +const genericToc = require('./contextualizers/generic-toc') +const breadcrumbs = require('./contextualizers/breadcrumbs') +const earlyAccessBreadcrumbs = require('./contextualizers/early-access-breadcrumbs') +const productExamples = require('./contextualizers/product-examples') +const devToc = require('./dev-toc') +const featuredLinks = require('./featured-links') +const learningTrack = require('./learning-track') +const isNextRequest = require('./is-next-request') +const next = require('./next') +const renderPage = require('./render-page') const { NODE_ENV } = process.env const isDevelopment = NODE_ENV === 'development' diff --git a/script/enterprise-server-deprecations/remove-version-markup.js b/script/enterprise-server-deprecations/remove-version-markup.js index df8eda0973d3..a6c5a35f1cf5 100755 --- a/script/enterprise-server-deprecations/remove-version-markup.js +++ b/script/enterprise-server-deprecations/remove-version-markup.js @@ -12,6 +12,7 @@ const enterpriseServerReleases = require('../../lib/enterprise-server-releases') const contentPath = path.join(__dirname, '../../content') const dataPath = path.join(__dirname, '../../data') const removeUnusedAssetsScript = 'script/remove-unused-assets' +const runRemoveUnusedAssetsScript = require('../remove-unused-assets') const elseifRegex = /{-?% elsif/ // [start-readme] @@ -64,7 +65,7 @@ const allFiles = contentFiles.concat(dataFiles) main() console.log(`\nRunning ${removeUnusedAssetsScript}...`) -require(path.join(process.cwd(), removeUnusedAssetsScript)) +runRemoveUnusedAssetsScript() function printElseIfFoundWarning (location) { console.log(`${location} has an 'elsif' condition! Resolve all elsifs by hand, then rerun the script.`) diff --git a/script/enterprise-server-releases/create-graphql-files.js b/script/enterprise-server-releases/create-graphql-files.js index 42c969fe6cd7..547946088a35 100755 --- a/script/enterprise-server-releases/create-graphql-files.js +++ b/script/enterprise-server-releases/create-graphql-files.js @@ -53,10 +53,10 @@ const changesFile = path.join(graphqlStaticDir, 'upcoming-changes.json') const objectsFile = path.join(graphqlStaticDir, 'prerendered-objects.json') const inputObjectsFile = path.join(graphqlStaticDir, 'prerendered-input-objects.json') -const previews = require(previewsFile) -const changes = require(changesFile) -const objects = require(objectsFile) -const inputObjects = require(inputObjectsFile) +const previews = JSON.parse(fs.readFileSync(previewsFile)) +const changes = JSON.parse(fs.readFileSync(changesFile)) +const objects = JSON.parse(fs.readFileSync(objectsFile)) +const inputObjects = JSON.parse(fs.readFileSync(inputObjectsFile)) // The prerendered objects file for the "old version" contains hardcoded links with the old version number. // We need to update those links to include the new version to prevent a test from failing. const regexOldVersion = new RegExp(oldVersion, 'gi')