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,13 +1,16 @@
'use strict'
const fs = require('fs')
const path = require('path')
const { svg2base64 } = require('./svg-helpers')
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import { svg2base64 } from './svg-helpers.js'
function loadLogos() {
// Cache svg logos from disk in base64 string
const logos = {}
const logoDir = path.join(__dirname, '..', 'logo')
const logoDir = path.join(
path.dirname(fileURLToPath(import.meta.url)),
'..',
'logo'
)
const logoFiles = fs.readdirSync(logoDir)
logoFiles.forEach(filename => {
if (filename[0] === '.') {
@@ -30,4 +33,4 @@ function loadLogos() {
return logos
}
module.exports = loadLogos
export default loadLogos

View File

@@ -1,7 +1,5 @@
'use strict'
const originalSimpleIcons = require('simple-icons')
const { svg2base64 } = require('./svg-helpers')
import originalSimpleIcons from 'simple-icons'
import { svg2base64 } from './svg-helpers.js'
function loadSimpleIcons() {
const simpleIcons = {}
@@ -40,4 +38,4 @@ function loadSimpleIcons() {
return simpleIcons
}
module.exports = loadSimpleIcons
export default loadSimpleIcons

View File

@@ -1,7 +1,5 @@
'use strict'
const { expect } = require('chai')
const loadSimpleIcons = require('./load-simple-icons')
import { expect } from 'chai'
import loadSimpleIcons from './load-simple-icons.js'
describe('loadSimpleIcons', function () {
let simpleIcons

View File

@@ -1,15 +1,15 @@
'use strict'
const Joi = require('joi')
const {
import Joi from 'joi'
import {
toSvgColor,
brightness,
normalizeColor,
} = require('../badge-maker/lib/color')
const coalesce = require('../core/base-service/coalesce')
const { svg2base64 } = require('./svg-helpers')
const logos = require('./load-logos')()
const simpleIcons = require('./load-simple-icons')()
} from '../badge-maker/lib/color.js'
import coalesce from '../core/base-service/coalesce.js'
import { svg2base64 } from './svg-helpers.js'
import loadLogos from './load-logos.js'
import loadSimpleIcons from './load-simple-icons.js'
const logos = loadLogos()
const simpleIcons = loadSimpleIcons()
// for backwards-compatibility with deleted logos
const logoAliases = {
@@ -131,7 +131,7 @@ function makeLogo(defaultNamedLogo, overrides) {
}
}
module.exports = {
export {
prependPrefix,
isDataUrl,
decodeDataUrlFromQueryParam,

View File

@@ -1,14 +1,12 @@
'use strict'
const { expect } = require('chai')
const { test, given, forCases } = require('sazerac')
const {
import { expect } from 'chai'
import { test, given, forCases } from 'sazerac'
import {
prependPrefix,
isDataUrl,
prepareNamedLogo,
getSimpleIcon,
makeLogo,
} = require('./logos')
} from './logos.js'
describe('Logo helpers', function () {
test(prependPrefix, () => {

View File

@@ -1,7 +1,5 @@
'use strict'
function svg2base64(svg) {
return `data:image/svg+xml;base64,${Buffer.from(svg).toString('base64')}`
}
module.exports = { svg2base64 }
export { svg2base64 }

View File

@@ -1,7 +1,5 @@
'use strict'
const { test, given } = require('sazerac')
const { svg2base64 } = require('./svg-helpers')
import { test, given } from 'sazerac'
import { svg2base64 } from './svg-helpers.js'
describe('SVG helpers', function () {
test(svg2base64, () => {