Files
discordeno/scripts/fixCjsExtension.js
Fleny 06e8ec3888 Add a negative lookahead to prevent .json to be changed (#3536)
This was breaking the REST manager as the fetch() Response object uses a .json method to get the JSON body
2024-04-18 09:06:55 +00:00

17 lines
589 B
JavaScript

import fs from 'node:fs'
const dirs = ['']
for await (const dir of dirs) {
await Promise.all(
fs.readdirSync(`dist/cjs${dir}`).map(async (file) => {
if (!file.endsWith('.js') && !file.endsWith('.map') && !file.endsWith('.ts') && !file.endsWith('.cjs')) {
dirs.push(`${dir}/${file}`)
return
}
const content = await fs.promises.readFile(`dist/cjs${dir}/${file}`, 'utf-8')
await fs.promises.rm(`dist/cjs${dir}/${file}`)
fs.promises.writeFile(`dist/cjs${dir}/${file.slice(0, -3)}.cjs`, content.replace(/\.js(?!on)/g, '.cjs'))
}),
)
}