import { copyFileSync, readFileSync, writeFileSync } from 'node:fs'; import { resolve } from 'node:path'; function copy(filename: string, from: string, to: string): void { copyFileSync(resolve(from, filename), resolve(to, filename)); } function rewrite(path: string, replacer: (from: string) => string): void { const file = readFileSync(path).toString(); const replaced = replacer(file); writeFileSync(path, replaced); } // as we publish only the dist folder, we need to copy some meta files inside (readme/license/package.json) // also changes paths inside the copied `package.json` (`dist/index.js` -> `index.js`) const root = resolve(import.meta.dirname, '..'); const target = resolve(process.cwd(), 'dist'); copy('README.md', root, target); copy('LICENSE', root, target); copy('package.json', process.cwd(), target); rewrite(resolve(target, 'package.json'), (pkg) => pkg.replace(/.\/dist\//g, './'));