there is this tool called patch-package which probably can help you with this.
it requires the following steps (as described in it's documentation):
- add a post install script to
package.json
"scripts": {
...
"postinstall": "patch-package"
},
install patch package npm i patch-package
go in your node_modules
folder find the package and file in it that you want to update
for example i'm setting number of retries for mongodb package default which is 5 to 10 here
class Cursor extends CoreCursor {
constructor(topology, ns, cmd, options) {
super(topology, ns, cmd, options);
if (this.operation) {
options = this.operation.options;
}
// part i modified
const numberOfRetries = options.numberOfRetries || 10;
const tailableRetryInterval = options.tailableRetryInterval || 500;
const currentNumberOfRetries = numberOfRetries;
//...
}
//
...
}
- let patch package create a patch folder with the applied changes via
npx patch-package mongodb
the output will look like this
> npx patch-package mongodb
patch-package 6.4.7
• Creating temporary folder
• Installing mongodb@3.7.3 with npm
• Diffing your files with clean files
✔ Created file patches/mongodb+3.7.3.patch
mongodb is on GitHub! To draft an issue based on your patch run
npx patch-package mongodb --create-issue
and it will create a patches
folder with a file mongodb+3.7.3.patch
with contents like this
diff --git a/node_modules/mongodb/lib/cursor.js b/node_modules/mongodb/lib/cursor.js
index 63f5fb7..4f71085 100644
--- a/node_modules/mongodb/lib/cursor.js
+++ b/node_modules/mongodb/lib/cursor.js
@@ -108,7 +108,7 @@ class Cursor extends CoreCursor {
}
// Tailable cursor options
- const numberOfRetries = options.numberOfRetries || 5;
+ const numberOfRetries = options.numberOfRetries || 10;
const tailableRetryInterval = options.tailableRetryInterval || 500;
const currentNumberOfRetries = numberOfRetries;
that should be it now when you build your code will use the package with the updates applied to it.