Skip to content

Instantly share code, notes, and snippets.

@eric-burel
Created March 12, 2022 09:42
Show Gist options
  • Save eric-burel/543bdc809bcc62208deabdeb004db724 to your computer and use it in GitHub Desktop.
Save eric-burel/543bdc809bcc62208deabdeb004db724 to your computer and use it in GitHub Desktop.
const edits = [
[
"node_modules/ts-invariant/package.json",
{
type: "module",
exports: {
".": "./lib/invariant.esm.js",
"./process/index.js": "./process/index.js",
},
},
],
[
"node_modules/ts-invariant/process/package.json",
{
type: "module",
},
],
[
"node_modules/@apollo/client/package.json",
{
exports: {
".": "./index.js",
"./link/error": "./link/error/index.js",
},
},
],
,
[
"node_modules/@apollo/client/link/error/package.json",
{
exports: {
".": "./index.js",
},
},
],
];
const fs = require("fs");
const path = require("path");
edits.forEach(([packageJsonPath, fieldsToAdd]) => {
// adapt according to the path of node_modules (here my script is nested in 2 folders)
const fullPath = path.resolve(__dirname, "../../", packageJsonPath);
console.log("Add fields", fieldsToAdd, "to", fullPath);
console.log("Edited");
const currentPackage = JSON.parse(fs.readFileSync(fullPath));
const editedPackage = { ...currentPackage, ...fieldsToAdd };
fs.writeFileSync(fullPath, JSON.stringify(editedPackage));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment