Answer the question
In order to leave comments, you need to log in
Can someone explain about the dependencies in node_modules?
Hello. Not very strong with node.js and npm.
First, please advise what can be read on npm?
About the question. For example, I installed dependencies, installed a package, for example, and now I want to change something in it, add my functionality, for example, I can’t do this?
Answer the question
In order to leave comments, you need to log in
you can write patch over a module.
Each module at the time of require('some-module') gets into require.cache and then this module can be patched.
For example:
// first.js
const add = (a,b) => a +b;
module.exports.add = add
// patched.js
const MODULENAME = './first';
const moduleToPatch = require(MODULENAME); // здесь мы кешировали нужный нам модуль
require.cache[require.resolve(MODULETOPATCH)].exports.add = (a,b) => {
console.log('PATCHED ! ! ! ! ')
return a + b;
}
// second.js
require('./patched');
const { add } = require('./first');
console.log(add(10, 20))
// PATCHED ! ! ! !
// 30
You go to the author of the package and say: so and so, I need this kind of behavior, can I make a PR? If you agree on how it should look and work, then fork, make changes, send a pull request to the author.
For example, I installed dependencies, installed a package, for example, and now I want to change something in it, add my functionality, for example, I can’t do this?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question