Migrate from CommonJS to ESM (#6651)
This commit is contained in:
@@ -1,11 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const queryString = require('query-string')
|
||||
const request = require('request')
|
||||
const {
|
||||
userAgent,
|
||||
} = require('../../../core/base-service/legacy-request-handler')
|
||||
const log = require('../../../core/server/log')
|
||||
import queryString from 'query-string'
|
||||
import request from 'request'
|
||||
import { userAgent } from '../../../core/base-service/legacy-request-handler.js'
|
||||
import log from '../../../core/server/log.js'
|
||||
|
||||
function setRoutes({ server, authHelper, onTokenAccepted }) {
|
||||
const baseUrl = process.env.GATSBY_BASE_URL || 'https://img.shields.io'
|
||||
@@ -29,7 +25,7 @@ function setRoutes({ server, authHelper, onTokenAccepted }) {
|
||||
|
||||
server.route(/^\/github-auth\/done$/, (data, match, end, ask) => {
|
||||
if (!data.code) {
|
||||
log(`GitHub OAuth data: ${JSON.stringify(data)}`)
|
||||
log.log(`GitHub OAuth data: ${JSON.stringify(data)}`)
|
||||
return end('GitHub OAuth authentication failed to provide a code.')
|
||||
}
|
||||
|
||||
@@ -85,4 +81,4 @@ function setRoutes({ server, authHelper, onTokenAccepted }) {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { setRoutes }
|
||||
export { setRoutes }
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
'use strict'
|
||||
|
||||
const { expect } = require('chai')
|
||||
const Camp = require('@shields_io/camp')
|
||||
const FormData = require('form-data')
|
||||
const sinon = require('sinon')
|
||||
const portfinder = require('portfinder')
|
||||
const queryString = require('query-string')
|
||||
const nock = require('nock')
|
||||
const got = require('../../../core/got-test-client')
|
||||
const GithubConstellation = require('../github-constellation')
|
||||
const acceptor = require('./acceptor')
|
||||
import { expect } from 'chai'
|
||||
import Camp from '@shields_io/camp'
|
||||
import FormData from 'form-data'
|
||||
import sinon from 'sinon'
|
||||
import portfinder from 'portfinder'
|
||||
import queryString from 'query-string'
|
||||
import nock from 'nock'
|
||||
import got from '../../../core/got-test-client.js'
|
||||
import GithubConstellation from '../github-constellation.js'
|
||||
import { setRoutes } from './acceptor.js'
|
||||
|
||||
const fakeClientId = 'githubdabomb'
|
||||
|
||||
@@ -39,7 +37,7 @@ describe('Github token acceptor', function () {
|
||||
let onTokenAccepted
|
||||
beforeEach(function () {
|
||||
onTokenAccepted = sinon.stub()
|
||||
acceptor.setRoutes({
|
||||
setRoutes({
|
||||
server: camp,
|
||||
authHelper: oauthHelper,
|
||||
onTokenAccepted,
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
'use strict'
|
||||
|
||||
const { makeSecretIsValid } = require('../../../core/server/secret-is-valid')
|
||||
import { makeSecretIsValid } from '../../../core/server/secret-is-valid.js'
|
||||
|
||||
function setRoutes({ shieldsSecret }, { apiProvider, server }) {
|
||||
const secretIsValid = makeSecretIsValid(shieldsSecret)
|
||||
@@ -31,4 +29,4 @@ function setRoutes({ shieldsSecret }, { apiProvider, server }) {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { setRoutes }
|
||||
export { setRoutes }
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
'use strict'
|
||||
|
||||
const { expect } = require('chai')
|
||||
const Camp = require('@shields_io/camp')
|
||||
const portfinder = require('portfinder')
|
||||
const got = require('../../../core/got-test-client')
|
||||
const GithubApiProvider = require('../github-api-provider')
|
||||
const { setRoutes } = require('./admin')
|
||||
import { expect } from 'chai'
|
||||
import Camp from '@shields_io/camp'
|
||||
import portfinder from 'portfinder'
|
||||
import got from '../../../core/got-test-client.js'
|
||||
import GithubApiProvider from '../github-api-provider.js'
|
||||
import { setRoutes } from './admin.js'
|
||||
|
||||
describe('GitHub admin route', function () {
|
||||
const shieldsSecret = '7'.repeat(40)
|
||||
|
||||
Reference in New Issue
Block a user