-
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathbuild-cjs.js
More file actions
16 lines (11 loc) · 731 Bytes
/
build-cjs.js
File metadata and controls
16 lines (11 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Converts the ESM library file to commonJS for backwards compatibility with older node.js versions and projects
// kind of dumb, but works better than all the "smarter" options I tried
import { readFileSync, writeFileSync } from "node:fs";
const inFile = "lib/set-cookie.js";
const outFile = "dist/set-cookie.cjs";
const header = `// Generated automatically from ${inFile}; see build-cjs.js\n\n`;
const cjsExports = `module.exports = parseSetCookie;\n`; // the other exports are properties on parseSetCookie
const input = readFileSync(inFile, { encoding: "utf8" });
const output = header + input.split("// EXPORTS")[0] + cjsExports;
writeFileSync(outFile, output);
console.log(`Wrote ${output.length} bytes to ${outFile}`);