-
-
Notifications
You must be signed in to change notification settings - Fork 87
/
posttsup.ts
73 lines (65 loc) · 2.03 KB
/
posttsup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import path from 'node:path';
import fs from 'node:fs';
import pkg from './package.json';
async function copy(...files: string[]) {
return files.map((file) => Bun.write('dist/' + file.replace('src/', ''), Bun.file(file), { createPath: true }));
}
copy(
'LICENSE',
'CHANGELOG.md',
'README.md',
'src/types/babel.d.ts',
'src/types/reactive-native.d.ts',
'src/types/reactive-web.d.ts',
);
const lsexports = pkg.lsexports;
const exports: Record<string, string | { import?: string; require?: string; types: string }> = {
'./package.json': './package.json',
'./babel': './babel.js',
'./types/babel': {
types: './types/babel.d.ts',
},
'./types/reactive-web': {
types: './types/reactive-web.d.ts',
},
'./types/reactive-native': {
types: './types/reactive-native.d.ts',
},
};
function addExport(key: string, file: string) {
exports[key] = {
import: `./${file}.mjs`,
require: `./${file}.js`,
types: `./${file}.d.ts`,
};
}
lsexports.forEach((exp) => {
if (exp.endsWith('/*')) {
const p = exp.replace('/*', '');
const files = fs.readdirSync(path.join('src', p));
files.forEach((filename) => {
const file = filename.replace(/\.[^/.]+$/, '');
if (!file.startsWith('_')) {
addExport(`${file === '.' ? '' : './'}${p}/${file}`, `${p}/${file}`);
}
});
} else {
addExport(exp === '.' ? exp : './' + exp, exp === '.' ? 'index' : exp);
}
});
const pkgOut = pkg as Record<string, any>;
pkg.private = false;
pkgOut.exports = exports;
delete pkgOut.lsexports;
delete pkgOut.devDependencies;
delete pkgOut.overrides;
delete pkgOut.scripts;
delete pkgOut.engines;
Bun.write('dist/package.json', JSON.stringify(pkg, undefined, 2));
async function fix_To$(path: string) {
const pathOld = path.replace('$', '_');
await Bun.write(path, Bun.file(pathOld));
fs.unlinkSync(pathOld);
}
fix_To$('dist/config/enable$GetSet.d.ts');
fix_To$('dist/config/enable$GetSet.d.mts');