I am trying to update the npm dependency files, but they are not inside a project. I am using Github API to get the package.json and package-lock.json. The contents of the files are being saved as variables and I want to update few dependencies. I don't want to save them in files and use npm-update.
I also thought I would get the latest versions and simply change the versions with new one. But this also won't work. I can change the versions in package.json and it would be done, but with lockfile I need to change the versions, integrity and their dependencies.
If you can suggest any solution thanks in advance
const updatePackages = ['axios','bluebird','lodash']
let pkgfile = fetch('https://api.github.com/repos/<repo>/<owner>/package.json')
let lockfile = fetch('https://api.github.com/repos/<repo>/<owner>/package-lock.json')
//now I need to update these dependency variables
//without using cli
const ltsAxiosVersion = fetch('https://unpkg.com/axios')
pkgfile.dependencies.axios = ltsAxiosVersion
//post the updated content to the github
Related
I have a libsass-dev on my system. But npm will download its own one, which is annoying. How to let npm makes use of libsass-dev?
You can try specifying the absolute path to your module, assuming is outside the node_modules folder.
You can try first the require.resolve('/path/to/my/Module') and if it finds it will return the path to the module, then do the require function.
Or You can create your own folder inside node_modules and require the full folder, something like require('./relativeOrAbsPath/To/My/node_modules/myModule'). The default file is index.js or You can mention in the package.json file using the main property to specify another file name.
Also you can update your modules path using this npm module https://www.npmjs.com/package/app-module-path but this looks first on your node_modules folder. However on prior version 1.x is starting for the bottom of the module.paths list.
In Bulma documentation (https://bulma.io/documentation/customize/with-node-sass/) it says to do an npm init and when prompted for an entry point, enter sass/mystyles.scss. I understand from previous post (What is "entry point" in npm init) that entry point during npm init should be your main.js file.
Why does Bulma documentation recommend making the custom scss file the entry point?
I'm keeping project entry point at main.js, but unsure of implications (if any).
TL;DR
It doesn't matter as long as your project isn't meant to be installed as a dependency.
The longer answer
To clearify what you read in the post about the NPM entry point:
The entry is used when users install your package from NPM and requires it. This means that if your entry is main.js,
const package = require("yourpackage");
will be the same as writing
const package = require("./node_modules/yourpackage/main");
Because you don't need this syntax inside your project, it doesn't affect anything, like compiling Sass, inside your project.
If the package is supposed to be published and installed as a dependency, however, you have to think about your entry point. If the project is primarily a Sass/SCSS package, I'd recommend setting the value to your main Sass/SCSS file, as there are Sass/SCSS processors that make use of the entry point.
That's also why the Bulma docs recommend setting the entry point to the Sass file. But in the end, it's your decision.
I am using rn-diff to upgrade react-native version for my app. Sometimes, the project.pbxproj is updated to contain some new dependencies or updates to the existing dependencies. What is the recommended way to update this file? I don't think that I can just copy and paste the changes shown in the diff because it may create some duplicates or create some conflicting entries in the file.
For example, below link contains changes made to the project.pbxproj file while changing from version 0.54.4 to 0.55.0. There are a lot changes to the project.pbxproj file and I am not sure if I am supposed to copy them over or I should rather be updating some dependencies myself in Xcode.
https://github.com/ncuillery/rn-diff/compare/rn-0.54.4...rn-0.55.0
In such cases I'm usually sad that I need to do this terrible thing ;)
But being serious: sadly going through RN Diff is like the very best thing that you can do now (unless you have NOT detached Expo.io but then you wouldn't probably ask here). So basically you go through each change that happened between your version and version to which you want to update and copy paste the changes in these files. As rarely you can apply patches (because your project file will be so different that there is no way that it will work out correctly).
My way of doing it is:
- see what changed
- see code block next to it, that is somehow easy to find out in my code (like some block of code that has unique ID + few properties around e.g. can be some native modules that are always there like TEXT or View or whatever, something which is always in RN)
- find the same element in my code and paste the new code above / below that code that was the same
Rinse and repeat
Please take a look at Upgrading to new React Native versions for upgrading your react native version!
Also if you want to update all of your dependencies, you can:
npm i -g npm-check-updates
ncu -u
npm install
And there is a library called npm-check-updates which:
Find newer versions of package dependencies than what your package.json or bower.json allows!
I installed a package from npm, but I needed to customize it. The problem is that, when the team install or update npm packages, the customization is overwritten.
I would like to know if there is anyway to preserve this customization or if I need to upload another package with the customization...
as semanser says, you need fork the project, but the right way for include this in your package.json file is
"package-name": "<your user name>/<your package name>#<your branch>"
you can find additional information here
Create a Github fork of a package that you need to customize.
Make changes that you want in your fork (don't forget to commit and push them).
Add the link to the fork to your package.json file in the following format:
"dependencies": {
"bar": "git://github.com/foo/bar.git"
}
(optional) Create a Pull Request and wait until your changes will be approved in the original repo.
I am new, and when i first created my app based on the documentation using npm create-react-app i found it there were a lot of package included inside folder node_module when i code and i only use react and react DOM and etc from the basic.
node_modules
acorn
timer
ansi
and many more
I wonder if anyone can help my how to understand each use inside the node_module or where can i find the documentation for each use?
or how can i just reduce to what i want to use only to decrease the app size?
The answers are 2:
because you're using an automated scaffolding tool, which essentially does everything for you, and, you have just to code, it is supposed to locally deploy all the packages it needs to work (for example webpack is needed to bundle your code, babel to transpile it, ...
under node_modules you will find all the packages of the whole app. That's means you will find both your dependencies and the dependencies of your dependencies (this rule has some exceptions and you can find them in the npm documentation.
example:
// your code depends on A
var dependency = require('A');
// but then, inside your A dependency you can also find something similar to:
var b = require('B');
how can i just reduce to what i want to use only to decrease the app size?
You basically can't do it. They are all needed.
Most of the libraries that we pull from npm have dependencies. You may use only react and react-dom but there are react-scripts that require lots of stuff. I don't think that you have to worry about the size of the node_modules. That's not what you are suppose to ship in production.
If you want to see what are these all modules about you may open their folder and fine README.md file.