Migrate from CommonJS to ESM (#6651)

This commit is contained in:
Pierre-Yves B
2021-07-09 12:53:55 +01:00
committed by GitHub
parent 23678fe2f5
commit 23c0406bed
1130 changed files with 4457 additions and 6711 deletions

View File

@@ -1,8 +1,6 @@
'use strict'
const Joi = require('joi')
const { BaseJsonService, NotFound } = require('..')
const { isLegacyVersion } = require('./sonar-helpers')
import Joi from 'joi'
import { BaseJsonService, NotFound } from '../index.js'
import { isLegacyVersion } from './sonar-helpers.js'
// It is possible to see HTTP 404 response codes and HTTP 200 responses
// with empty arrays of metric values, with both the legacy (pre v5.3) and modern APIs.
@@ -51,7 +49,7 @@ const legacySchema = Joi.array()
)
.required()
module.exports = class SonarBase extends BaseJsonService {
export default class SonarBase extends BaseJsonService {
static auth = { userKey: 'sonarqube_token', serviceKey: 'sonar' }
async fetch({ sonarVersion, server, component, metricName }) {

View File

@@ -1,10 +1,8 @@
'use strict'
import { coveragePercentage } from '../color-formatters.js'
import SonarBase from './sonar-base.js'
import { documentation, keywords, queryParamSchema } from './sonar-helpers.js'
const { coveragePercentage } = require('../color-formatters')
const SonarBase = require('./sonar-base')
const { documentation, keywords, queryParamSchema } = require('./sonar-helpers')
module.exports = class SonarCoverage extends SonarBase {
export default class SonarCoverage extends SonarBase {
static category = 'coverage'
static route = {

View File

@@ -1,7 +1,6 @@
'use strict'
const t = (module.exports = require('../tester').createServiceTester())
const { isIntegerPercentage } = require('../test-validators')
import { createServiceTester } from '../tester.js'
import { isIntegerPercentage } from '../test-validators.js'
export const t = await createServiceTester()
// The service tests targeting the legacy SonarQube API are mocked
// because of the lack of publicly accessible, self-hosted, legacy SonarQube instances

View File

@@ -1,17 +1,15 @@
'use strict'
const SonarBase = require('./sonar-base')
const {
import SonarBase from './sonar-base.js'
import {
queryParamSchema,
getLabel,
positiveMetricColorScale,
keywords,
documentation,
} = require('./sonar-helpers')
} from './sonar-helpers.js'
const metric = 'public_documented_api_density'
module.exports = class SonarDocumentedApiDensity extends SonarBase {
export default class SonarDocumentedApiDensity extends SonarBase {
static category = 'analysis'
static route = {

View File

@@ -1,7 +1,5 @@
'use strict'
const { test, given } = require('sazerac')
const SonarDocumentedApiDensity = require('./sonar-documented-api-density.service')
import { test, given } from 'sazerac'
import SonarDocumentedApiDensity from './sonar-documented-api-density.service.js'
describe('SonarDocumentedApiDensity', function () {
test(SonarDocumentedApiDensity.render, () => {

View File

@@ -1,6 +1,5 @@
'use strict'
const t = (module.exports = require('../tester').createServiceTester())
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()
// The service tests targeting the legacy SonarQube API are mocked
// because of the lack of publicly accessible, self-hosted, legacy SonarQube instances

View File

@@ -1,7 +1,5 @@
'use strict'
const SonarBase = require('./sonar-base')
const { queryParamSchema, keywords, documentation } = require('./sonar-helpers')
import SonarBase from './sonar-base.js'
import { queryParamSchema, keywords, documentation } from './sonar-helpers.js'
const colorMap = {
0: 'red',
@@ -12,7 +10,7 @@ const colorMap = {
5: 'brightgreen',
}
module.exports = class SonarFortifyRating extends SonarBase {
export default class SonarFortifyRating extends SonarBase {
static category = 'analysis'
static route = {

View File

@@ -1,9 +1,7 @@
'use strict'
const { expect } = require('chai')
const nock = require('nock')
const { cleanUpNockAfterEach, defaultContext } = require('../test-helpers')
const SonarFortifyRating = require('./sonar-fortify-rating.service')
import { expect } from 'chai'
import nock from 'nock'
import { cleanUpNockAfterEach, defaultContext } from '../test-helpers.js'
import SonarFortifyRating from './sonar-fortify-rating.service.js'
const token = 'abc123def456'
const config = {

View File

@@ -1,6 +1,5 @@
'use strict'
const t = (module.exports = require('../tester').createServiceTester())
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()
// The service tests targeting the legacy SonarQube API are mocked
// because of the lack of publicly accessible, self-hosted, legacy SonarQube instances

View File

@@ -1,8 +1,6 @@
'use strict'
const { metric } = require('../text-formatters')
const SonarBase = require('./sonar-base')
const { queryParamSchema, getLabel } = require('./sonar-helpers')
import { metric } from '../text-formatters.js'
import SonarBase from './sonar-base.js'
import { queryParamSchema, getLabel } from './sonar-helpers.js'
// This service is intended to be a temporary solution to avoid breaking
// any existing users/badges that were utilizing the "other" Sonar metrics
@@ -106,7 +104,7 @@ const metricNames = [
]
const metricNameRouteParam = metricNames.join('|')
module.exports = class SonarGeneric extends SonarBase {
export default class SonarGeneric extends SonarBase {
static category = 'analysis'
static route = {

View File

@@ -1,7 +1,6 @@
'use strict'
const { isMetric } = require('../test-validators')
const t = (module.exports = require('../tester').createServiceTester())
import { isMetric } from '../test-validators.js'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()
t.create('Security Rating')
.timeout(10000)

View File

@@ -1,8 +1,6 @@
'use strict'
const Joi = require('joi')
const { colorScale } = require('../color-formatters')
const { optionalUrl } = require('../validators')
import Joi from 'joi'
import { colorScale } from '../color-formatters.js'
import { optionalUrl } from '../validators.js'
const ratingPercentageScaleSteps = [10, 20, 50, 100]
const ratingScaleColors = [
@@ -60,7 +58,7 @@ const documentation = `
</p
`
module.exports = {
export {
getLabel,
isLegacyVersion,
queryParamSchema,

View File

@@ -1,9 +1,7 @@
'use strict'
import SonarBase from './sonar-base.js'
import { documentation, keywords, queryParamSchema } from './sonar-helpers.js'
const SonarBase = require('./sonar-base')
const { documentation, keywords, queryParamSchema } = require('./sonar-helpers')
module.exports = class SonarQualityGate extends SonarBase {
export default class SonarQualityGate extends SonarBase {
static category = 'analysis'
static route = {

View File

@@ -1,7 +1,5 @@
'use strict'
const { test, given } = require('sazerac')
const SonarQualityGate = require('./sonar-quality-gate.service')
import { test, given } from 'sazerac'
import SonarQualityGate from './sonar-quality-gate.service.js'
describe('SonarQualityGate', function () {
test(SonarQualityGate.render, () => {

View File

@@ -1,7 +1,6 @@
'use strict'
const Joi = require('joi')
const t = (module.exports = require('../tester').createServiceTester())
import Joi from 'joi'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()
const isQualityGateStatus = Joi.allow('passed', 'failed')

View File

@@ -1,8 +1,6 @@
'use strict'
import { redirector } from '../index.js'
const { redirector } = require('..')
module.exports = [
export default [
redirector({
name: 'SonarVersionPrefixRedirector',
category: 'analysis',

View File

@@ -1,13 +1,11 @@
'use strict'
import queryString from 'querystring'
import { ServiceTester } from '../tester.js'
const queryString = require('querystring')
const { ServiceTester } = require('../tester')
const t = (module.exports = new ServiceTester({
export const t = new ServiceTester({
id: 'SonarRedirect',
title: 'SonarRedirect',
pathPrefix: '/sonar',
}))
})
t.create('sonar version')
.get(

View File

@@ -1,15 +1,13 @@
'use strict'
const SonarBase = require('./sonar-base')
const {
import SonarBase from './sonar-base.js'
import {
negativeMetricColorScale,
getLabel,
documentation,
keywords,
queryParamSchema,
} = require('./sonar-helpers')
} from './sonar-helpers.js'
module.exports = class SonarTechDebt extends SonarBase {
export default class SonarTechDebt extends SonarBase {
static category = 'analysis'
static route = {

View File

@@ -1,7 +1,5 @@
'use strict'
const { test, given } = require('sazerac')
const SonarTechDebt = require('./sonar-tech-debt.service')
import { test, given } from 'sazerac'
import SonarTechDebt from './sonar-tech-debt.service.js'
describe('SonarTechDebt', function () {
test(SonarTechDebt.render, () => {

View File

@@ -1,7 +1,6 @@
'use strict'
const { isPercentage } = require('../test-validators')
const t = (module.exports = require('../tester').createServiceTester())
import { isPercentage } from '../test-validators.js'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()
// The service tests targeting the legacy SonarQube API are mocked
// because of the lack of publicly accessible, self-hosted, legacy SonarQube instances

View File

@@ -1,18 +1,16 @@
'use strict'
const {
import {
testResultQueryParamSchema,
renderTestResultBadge,
documentation: testResultsDocumentation,
} = require('../test-results')
const { metric: metricCount } = require('../text-formatters')
const SonarBase = require('./sonar-base')
const {
documentation as testResultsDocumentation,
} from '../test-results.js'
import { metric as metricCount } from '../text-formatters.js'
import SonarBase from './sonar-base.js'
import {
documentation,
keywords,
queryParamSchema,
getLabel,
} = require('./sonar-helpers')
} from './sonar-helpers.js'
class SonarTestsSummary extends SonarBase {
static category = 'build'
@@ -241,4 +239,4 @@ class SonarTests extends SonarBase {
}
}
module.exports = [SonarTestsSummary, SonarTests]
export { SonarTestsSummary, SonarTests }

View File

@@ -1,7 +1,5 @@
'use strict'
const { test, given } = require('sazerac')
const SonarTests = require('./sonar-tests.service')[1]
import { test, given } from 'sazerac'
import { SonarTests } from './sonar-tests.service.js'
describe('SonarTests', function () {
test(SonarTests.render, () => {

View File

@@ -1,19 +1,18 @@
'use strict'
const Joi = require('joi')
const { ServiceTester } = require('../tester')
const t = (module.exports = new ServiceTester({
id: 'SonarTests',
title: 'SonarTests',
pathPrefix: '/sonar',
}))
const {
import Joi from 'joi'
import { ServiceTester } from '../tester.js'
import {
isDefaultTestTotals,
isDefaultCompactTestTotals,
isCustomTestTotals,
isCustomCompactTestTotals,
} = require('../test-validators')
const { isIntegerPercentage, isMetric } = require('../test-validators')
isIntegerPercentage,
isMetric,
} from '../test-validators.js'
export const t = new ServiceTester({
id: 'SonarTests',
title: 'SonarTests',
pathPrefix: '/sonar',
})
const isMetricAllowZero = Joi.alternatives(
isMetric,
Joi.number().valid(0).required()

View File

@@ -1,14 +1,12 @@
'use strict'
const { colorScale } = require('../color-formatters')
const { metric } = require('../text-formatters')
const SonarBase = require('./sonar-base')
const {
import { colorScale } from '../color-formatters.js'
import { metric } from '../text-formatters.js'
import SonarBase from './sonar-base.js'
import {
getLabel,
documentation,
keywords,
queryParamWithFormatSchema,
} = require('./sonar-helpers')
} from './sonar-helpers.js'
const violationsColorScale = colorScale(
[1, 2, 3, 5],
@@ -23,7 +21,7 @@ const violationCategoryColorMap = {
info_violations: 'green',
}
module.exports = class SonarViolations extends SonarBase {
export default class SonarViolations extends SonarBase {
static category = 'analysis'
static route = {

View File

@@ -1,8 +1,6 @@
'use strict'
const { test, given } = require('sazerac')
const { metric } = require('../text-formatters')
const SonarViolations = require('./sonar-violations.service')
import { test, given } from 'sazerac'
import { metric } from '../text-formatters.js'
import SonarViolations from './sonar-violations.service.js'
describe('SonarViolations', function () {
test(SonarViolations.render, () => {

View File

@@ -1,8 +1,7 @@
'use strict'
const Joi = require('joi')
const { isMetric, withRegex } = require('../test-validators')
const t = (module.exports = require('../tester').createServiceTester())
import Joi from 'joi'
import { isMetric, withRegex } from '../test-validators.js'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()
const isViolationsLongFormMetric = Joi.alternatives(
Joi.allow(0),
withRegex(