Created
March 12, 2022 09:42
-
-
Save eric-burel/543bdc809bcc62208deabdeb004db724 to your computer and use it in GitHub Desktop.
Fix apollo exports https://github.com/apollographql/apollo-feature-requests/issues/287
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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