feat(pkg): Add core extensions package

This commit is contained in:
T. R. Bernstein
2025-04-21 01:46:55 +02:00
parent 7fd56d9e6c
commit 1ba1659600
6 changed files with 271 additions and 141 deletions

View File

@@ -0,0 +1,52 @@
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const srcDir = path.resolve(__dirname, '../src')
const distDir = 'dist'
const pkgPath = path.resolve(__dirname, '../package.json')
function walk(dir) {
let result = []
const entries = fs.readdirSync(dir, { withFileTypes: true })
for (const entry of entries) {
const fullPath = path.join(dir, entry.name)
if (entry.isDirectory()) {
result = result.concat(walk(fullPath))
} else if (entry.isFile() && entry.name.endsWith('.ts') && !entry.name.endsWith('.d.ts')) {
result.push(fullPath)
}
}
return result
}
function toSubpath(filePath) {
const relativePath = path.relative(srcDir, filePath).replace(/\.ts$/, '')
return relativePath.replace(/\\/g, '/') // For Windows compatibility
}
function updatePackageJson() {
const packageJson = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
const files = walk(srcDir)
const exportsMap = {}
files.forEach((file) => {
const subpath = toSubpath(file)
exportsMap[`./${subpath}`] = {
import: `./${distDir}/${subpath}.js`,
types: `./${distDir}/${subpath}.d.ts`
}
})
packageJson.exports = exportsMap
fs.writeFileSync(pkgPath, JSON.stringify(packageJson, null, 2))
console.log('✅ Modern exports updated in package.json')
}
updatePackageJson()