2024-08-13 04:53:07 +03:00
|
|
|
import * as fs from 'node:fs'
|
|
|
|
import { join } from 'node:path'
|
|
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
|
2024-04-28 22:41:28 +03:00
|
|
|
import { globSync } from 'glob'
|
|
|
|
|
|
|
|
// for whatever reason, jsr's npm compatibility jayer doesn't remove
|
|
|
|
// original typescript source files, which results in type errors when
|
|
|
|
// trying to build the project. this script removes all source files from @jsr/*
|
|
|
|
// https://discord.com/channels/684898665143206084/1203185670508515399/1234222204044967967
|
|
|
|
|
|
|
|
const nodeModules = fileURLToPath(new URL('../node_modules', import.meta.url))
|
|
|
|
|
|
|
|
let count = 0
|
|
|
|
|
|
|
|
for (const file of globSync(join(nodeModules, '.pnpm/**/node_modules/@jsr/**/*.ts'))) {
|
|
|
|
if (file.endsWith('.d.ts')) continue
|
|
|
|
if (!fs.existsSync(file)) continue
|
|
|
|
|
|
|
|
fs.unlinkSync(file)
|
|
|
|
count++
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(`[jsr] removed ${count} source files`)
|