WK 8c2613713a
refactor: migrate eslint to v9 (#5267)
* refactor: migrate eslint to v9

* chore: lint

* chore: update eslint command

* chore: fix lint warnings

* chore: separate lint and lint:fix

* chore: exclude contentlayer generated code

* fix(scripts): add missing await
2025-06-01 13:51:30 -03:00

42 lines
1003 B
JavaScript

const path = require('path')
const fs = require('fs')
function tryRequirePkg(pkg) {
try {
return require(pkg);
} catch {
return null;
}
}
function copyDemiDir(dir) {
const src = path.join(__dirname, '..', 'dist', 'demi', dir)
const dest = path.join(__dirname, '..', 'dist')
fs.cpSync(src, dest, { recursive: true })
}
function modifyDts(path) {
const dts = fs.readFileSync(path, 'utf8')
const modifiedDts = dts.replace(/\.\.\/\.\.\/common/g, './common')
fs.writeFileSync(path, modifiedDts, 'utf8')
}
function postinstall() {
const nextjs = tryRequirePkg('next/package.json')
const react = tryRequirePkg('react/package.json')
const nextjsVersion = Number((nextjs?.version || '').split('.')[0])
const reactVersion = Number((react?.version || '').split('.')[0])
if (reactVersion === 18 && nextjsVersion < 15) {
copyDemiDir('react18')
} else {
copyDemiDir('react19')
}
modifyDts(path.join(__dirname, '..', 'dist', 'index.d.ts'))
}
postinstall();