mirror of
https://github.com/modernweb-dev/rocket.git
synced 2026-03-12 08:51:20 +00:00
27 lines
980 B
JavaScript
27 lines
980 B
JavaScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import { createRequire } from 'module';
|
|
import { packages } from '../workspace-packages.mjs';
|
|
|
|
const require = createRequire(import.meta.url);
|
|
|
|
for (const pkg of packages) {
|
|
if (pkg.type === 'ts' && pkg.environment === 'node') {
|
|
const pkgPath = path.join(process.cwd(), 'packages', pkg.name);
|
|
const cjsModule = require(path.join(pkgPath, 'dist', 'index.js'));
|
|
const namedExports = Object.keys(cjsModule)
|
|
.filter(name => name !== 'default' && !name.startsWith('_'))
|
|
.join(', ');
|
|
const esmEntrypoint = `// this file is autogenerated with the update-esm-entrypoints script
|
|
import cjsEntrypoint from './dist/index.js';
|
|
|
|
const { ${namedExports} } = cjsEntrypoint;
|
|
|
|
export { ${namedExports} }`;
|
|
const esmEntrypointDts = "export * from './dist/index.js'";
|
|
|
|
fs.writeFileSync(path.join(pkgPath, 'index.mjs'), esmEntrypoint);
|
|
fs.writeFileSync(path.join(pkgPath, 'index.d.ts'), esmEntrypointDts);
|
|
}
|
|
}
|