-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathpostcompile.mjs
31 lines (29 loc) · 1.17 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
26
27
28
29
30
31
// @ts-check
// 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';
const packages = [
{ dir: 'cache-control-types' },
{ dir: 'gateway-interface' },
{ dir: 'plugin-response-cache' },
{ dir: 'server' },
{ dir: 'usage-reporting-protobuf', outDir: 'generated' },
];
// Tell Node what kinds of files the ".js" files in these subdirectories are.
for (const { dir, outDir = 'dist' } of packages) {
writeFileSync(
path.join('packages', dir, outDir, 'esm', 'package.json'),
JSON.stringify({ type: 'module' }),
);
writeFileSync(
path.join('packages', dir, outDir, 'cjs', 'package.json'),
JSON.stringify({ type: 'commonjs' }),
);
}