-
Notifications
You must be signed in to change notification settings - Fork 2k
/
postcompile.mjs
25 lines (22 loc) 路 1.03 KB
/
postcompile.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
// This script writes package.json files to the ESM and CJS generated code
// directories teaching Node that .js files in those directories use the
// corresponding module formats. It also removes all the .d.ts files from cjs
// since we only need one copy (and package.json points at the esm one). (It
// doesn't revert the packageVersion.ts update from precompile.ts; that gets
// done directly in the compile script, whether or not tsc succeeds.)
//
// This script expects to be run from the project root (as `npm run` does).
import path from 'path';
import { writeFileSync } from 'fs';
import rimraf from 'rimraf';
// Tell Node what kinds of files the ".js" files in these subdirectories are.
writeFileSync(
path.join('packages', 'server', 'dist', 'esm', 'package.json'),
JSON.stringify({ type: 'module' }),
);
writeFileSync(
path.join('packages', 'server', 'dist', 'cjs', 'package.json'),
JSON.stringify({ type: 'commonjs' }),
);
// Remove CJS .d.ts files: we don't need two copies!
rimraf.sync('packages/server/dist/cjs/**/*.d.ts');