-
Notifications
You must be signed in to change notification settings - Fork 0
/
postbuild.mjs
36 lines (30 loc) · 1.19 KB
/
postbuild.mjs
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
import fs from 'node:fs/promises';
import glob from 'fast-glob';
for (const entry of await glob('packages/**/dist/cjs/**/*.js')) {
const contents = await fs.readFile(entry, 'utf-8');
await fs.writeFile(
entry.replace(/\.js$/u, '.cjs'),
contents.replaceAll(/require\("(?<file>.+)\.js"\)/gu, `require("$1.cjs")`),
);
await fs.rm(entry);
}
for (const entry of await glob('packages/**/dist/cjs/**/*.js.map')) {
const contents = await fs.readFile(entry, 'utf-8');
await fs.writeFile(entry, contents.replaceAll(/\.js"/gu, `.cjs"`));
}
for (const entry of await glob('packages/enum/dist/**/enum.d.ts')) {
const contents = await fs.readFile(entry, 'utf-8');
await fs.writeFile(entry, contents.replace('#private;', '#brand: Brand;'));
}
for (const entry of await glob('packages/**/dist/cjs/**/*.d.ts')) {
const contents = await fs.readFile(entry, 'utf-8');
await fs.writeFile(
entry.replace(/\.ts$/u, '.cts'),
contents.replaceAll(/from '(?<file>.+)\.js';/gu, `from '$1.cjs';`),
);
await fs.rm(entry);
}
for (const entry of await glob('packages/**/dist/cjs/**/*.d.ts.map')) {
const contents = await fs.readFile(entry, 'utf-8');
await fs.writeFile(entry, contents.replaceAll(/\.d\.ts"/gu, `.d.cts"`));
}