Skip to content

Commit 8154d3b

Browse files
committed
adding mostly readfilesync of path updates to require
1 parent 0762734 commit 8154d3b

File tree

8 files changed

+17
-11
lines changed

8 files changed

+17
-11
lines changed

lib/rest/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const operations = {}
66
fs.readdirSync(schemasPath)
77
.forEach(filename => {
88
const key = filename.replace('.json', '')
9-
const value = require(path.join(schemasPath, filename))
9+
const value = JSON.parse(fs.readFileSync(path.join(schemasPath, filename)))
1010
operations[key] = value
1111
})
1212
const allVersions = require('../all-versions')

lib/webhooks/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ versions.forEach(version => {
1919
// payload file: /path/to/check_run.completed.payload.json
2020
// payload path: check_run.completed
2121
const payloadPath = path.basename(payloadFile).replace('.payload.json', '')
22-
set(payloadsPerVersion, payloadPath, formatAsJsonCodeBlock(require(payloadFile)))
22+
set(payloadsPerVersion, payloadPath, formatAsJsonCodeBlock(JSON.parse(fs.readFileSync(payloadFile))))
2323
})
2424

2525
payloads[version] = payloadsPerVersion

middleware/contextualizers/graphql.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const fs = require('fs')
2+
const path = require('path')
13
const previews = require('../../lib/graphql/static/previews')
24
const upcomingChanges = require('../../lib/graphql/static/upcoming-changes')
35
const changelog = require('../../lib/graphql/static/changelog')
@@ -23,7 +25,7 @@ module.exports = function graphqlContext (req, res, next) {
2325
const graphqlVersion = currentVersionObj.miscVersionName
2426

2527
req.context.graphql = {
26-
schemaForCurrentVersion: require(`../../lib/graphql/static/schema-${graphqlVersion}`),
28+
schemaForCurrentVersion: JSON.parse(fs.readFileSync(path.join(process.cwd(), '/lib/graphql/static/schema-' + graphqlVersion + '.json'))),
2729
previewsForCurrentVersion: previews[graphqlVersion],
2830
upcomingChangesForCurrentVersion: upcomingChanges[graphqlVersion],
2931
prerenderedObjectsForCurrentVersion: prerenderedObjects[graphqlVersion],

script/enterprise-server-releases/create-rest-files.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async function main () {
6363
fs.writeFileSync(newDereferencedFile, newDereferenceContent)
6464
console.log(`Created ${newDereferencedFile}.`)
6565

66-
const dereferencedSchema = require(path.join(process.cwd(), newDereferencedFile))
66+
const dereferencedSchema = JSON.parse(fs.readFileSync(path.join(process.cwd(), newDereferencedFile)))
6767

6868
// Store all operations in an array of operation objects
6969
const operations = await getOperations(dereferencedSchema)

script/rest/openapi-check.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env node
2-
2+
const fs = require('fs')
3+
const path = require('path')
34
const glob = require('glob')
45
const program = require('commander')
56
const getOperations = require('./utils/get-operations')
@@ -28,8 +29,8 @@ if (filesToCheck.length) {
2829

2930
async function check (files) {
3031
console.log('Verifying OpenAPI files are valid with decorator')
31-
32-
const documents = files.map(filename => [filename, require(filename)])
32+
// Check this one to make sure it's reading the right files
33+
const documents = files.map(filename => [filename, JSON.parse(fs.readFileSync(path.join(process.cwd(), filename)))])
3334

3435
for (const [filename, schema] of documents) {
3536
try {

script/rest/update-files.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async function getDereferencedFiles () {
7575
// name of the `github/github` checkout. A CI test
7676
// checks the version and fails if it's not a semantic version.
7777
schemas.forEach(filename => {
78-
const schema = require(path.join(dereferencedPath, filename))
78+
const schema = JSON.parse(fs.readFileSync(path.join(dereferencedPath, filename)))
7979
schema.info.version = `${githubBranch} !!DEVELOPMENT MODE - DO NOT MERGE!!`
8080
fs.writeFileSync(path.join(dereferencedPath, filename), JSON.stringify(schema, null, 2))
8181
})
@@ -85,7 +85,7 @@ async function decorate () {
8585
console.log('\n🎄 Decorating the OpenAPI schema files in lib/rest/static/dereferenced.\n')
8686

8787
const dereferencedSchemas = schemas.reduce((acc, filename) => {
88-
const schema = require(path.join(dereferencedPath, filename))
88+
const schema = JSON.parse(fs.readFileSync(path.join(dereferencedPath, filename)))
8989
const key = filename.replace('.deref.json', '')
9090
return { ...acc, [key]: schema }
9191
}, {})

script/rest/utils/operation.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const httpStatusCodes = require('http-status-code')
66
const renderContent = require('../../../lib/render-content')
77
const createCodeSamples = require('./create-code-samples')
88
const Ajv = require('ajv')
9+
const operationSchema = require('./operation-schema')
910

1011
// titles that can't be derived by sentence-casing the ID
1112
const categoryTitles = { scim: 'SCIM' }
@@ -40,7 +41,7 @@ module.exports = class Operation {
4041
}
4142

4243
get schema () {
43-
return require('./operation-schema')
44+
return operationSchema
4445
}
4546

4647
async process () {

tests/content/graphql.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const fs = require('fs')
2+
const path = require('path')
13
const previewsJson = require('../../lib/graphql/static/previews')
24
const upcomingChangesJson = require('../../lib/graphql/static/upcoming-changes')
35
const prerenderedObjectsJson = require('../../lib/graphql/static/prerendered-objects')
@@ -20,7 +22,7 @@ describe('graphql json files', () => {
2022

2123
test('schemas object validation', () => {
2224
graphqlVersions.forEach(version => {
23-
const schemaJsonPerVersion = require(`../../lib/graphql/static/schema-${version}`)
25+
const schemaJsonPerVersion = JSON.parse(fs.readFileSync(path.join(process.cwd(), '/lib/graphql/static/schema-' + version + '.json')))
2426
// all graphql types are arrays except for queries
2527
graphqlTypes
2628
.filter(type => type !== 'queries')

0 commit comments

Comments
 (0)