Symlink to file within same NPM module - github

In a GitHub module, it is possible to symlink to another file within the same module. But is it possible to have this symlink survive / work in the NPM package of same module?
I'm using a Mac and so far I've done
ln -s [filename-1.0.4.js] [filename.js]
This works great for github.io-pages, but the file disappears when published to NPM.

After some rounds with NPM support it seems that only folders can be linked with npm link
So the answer to my question is no. Here's the documentation for npm link
And here is the answer from support:
[...]
To create a symlink in a package.json, we recommend using the scripts field.
For example:
"scripts": {
"postinstall": "npm link ../somelocallib",
"postupdate": "npm link ../somelocallib"
}
[...]

Related

How do I check which babel version is on my windows 10 OS?

I need help to find which version of Babel is on my Windows Machine. I have installed it using
npm install --save-dev babel-cli babel-preset-env.
How do I check which version is on my Windows OS?
After you finish installing Babel, your package.json file should look like this:
{
"name": "my-project",
"version": "1.0.0",
"devDependencies": {
"babel-cli": "^6.0.0"
}
}
So you can find your Babel version in this configuration file.
Try this at the command line:
npm list babel-cli
You can also check the version of babel-cli by finding the babel-cli folder in node_modules and looking at the version property of the package.json that is at the base of that folder.
If babel-cli was installed globally via -g flag of npm install, you could check the version by executing command babel --version.
Hopefully the helps!
As the babel is updated to babel 7,
check using
npm list #babel/cli
or
npm list #babel/core
possibly your local ./node_modules/.bin is not in $PATH check out
this previous question for further info.
babel --version
You can figure this out by typing in the command line:
babel --help, look over the output and you can see other options that you might need.
Good luck

Ionic 1.x - from bower to npm

I used to install plugins in my ionic 1 project with bower. The new trend, especially with ionic 2, is to install packages with npm. Some core packages, such as ionic.cloud are not provided at all anymore with bower, even for ionic 1.x.
So I need to migrate some packages to npm. What is the recommended way to do so ?
My problem:
"npm install" seems to install packages in the "my_project/node_modules" folder, unlike bower which installs packages directly in my_project/www/lib/
As explained for instance in the installation guide of ionic.cloud this requires an additional step to copy the newly installed npm package in the lib folder with the command:
cp node_modules/#ionic/cloud/dist/bundle/ionic.cloud.min.js www/lib
However, when I update the package and run "npm update", this will update the node_modules folder, but not the lib folder. This is a problem as only the files from my lib folder are included in my index.html.
Running the cp-command after each npm update does not seem such an elegant solution. What is the recommended way to deal with this?
I think you can reverse this make the .bowerrc file create your packages inside the node_modules folder and use this path as default. Otherwise the node_modules is mandatory there is no way around creating it.
Even you can npm i --prefix ./bower_components/ <package> you still need to cp to folders up from bower_components folder

How to verify facebook jest is installed successfully

I followed the instructions to install Facebook jest on https://facebook.github.io/jest/docs/getting-started.html#content :
npm install --save-dev jest-cli
After the install command I typed jest in the terminal, and press enter but It popped:
bash: jest: command not found.
But when I run the getting started sample by using npm test in the terminal, it worked well.
So, how can I verify that Facebook jest is installed successfully?
Ways to install a package in npm
In node.js you have two ways to install a package: globally or locally.
The sintax is the following:
// globally
npm install -g [package_name]
// locally
npm install --save-dev [package_name]
So, now what it happens is that you run the local one which downloads the package in node_modules under your project folder.
To check you installed jest properly so you can check on your node_modules if there is a jest folder.
How to check if jest is installed
In addition to that npm is creating a shortcut in you local node_modules under the directory .bin son in there you should find a link to jest.
You can test that like that:
cd your_project_folder
./node_modules/.bin/jest
Why npm test works?
The reason why npm test works is because when you run it npm is going to look for the commands globally and locally.

How to install an npm package from GitHub directly

Trying to install modules from GitHub results in this error:
ENOENT error on package.json.
Easily reproduced using express:
npm install https://github.com/visionmedia/express throws error.
npm install express works.
Why can't I install from GitHub?
Here is the console output:
npm http GET https://github.com/visionmedia/express.git
npm http 200 https://github.com/visionmedia/express.git
npm ERR! not a package /home/guym/tmp/npm-32312/1373176518024-0.6586997057311237/tmp.tgz
npm ERR! Error: ENOENT, open '/home/guym/tmp/npm-32312/1373176518024-0.6586997057311237/package/package.json'
npm ERR! If you need help, you may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-#googlegroups.com>
npm ERR! System Linux 3.8.0-23-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "https://github.com/visionmedia/express.git"
npm ERR! cwd /home/guym/dev_env/projects_GIT/proj/somename
npm ERR! node -v v0.10.10
npm ERR! npm -v 1.2.25
npm ERR! path /home/guym/tmp/npm-32312/1373176518024-0.6586997057311237/package/package.json
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/guym/dev_env/projects_GIT/proj/somename/npm-debug.log
npm ERR! not ok code 0
Because https://github.com/visionmedia/express is the URL of a web page and not an npm module. Use this flavor: git+{url}.git
git+https://github.com/visionmedia/express.git
or this flavor if you need SSH:
git+ssh://git#github.com/visionmedia/express.git
or if you need to install a GitHub Enterprise repository:
git+https://<github enterprise url>/<org>/<repo>.git#<branch>
To install from GitHub, you can also do
npm install visionmedia/express
Or
npm install visionmedia/express#branch
There is also support for installing directly from a Gist, Bitbucket, GitLab, and a number of other specialized formats. Look at the npm install documentation for them all.
If Git is not installed, we can try:
npm install --save https://github.com/Amitesh/gulp-rev-all/tarball/master
As of September 2016, installing from vanilla HTTPS GitHub URLs now works:
npm install https://github.com/fergiemcdowall/search-index.git
You can't do this for all modules because you are reading from a source control system, which may well contain invalid/uncompiled/buggy code. So to be clear (although it should go without saying): given that the code in the repository is in an npm-usable state, you can now quite happily install directly from GitHub.
In October 2019, we are now living through "peak TypeScript/React/Babel", and therefore JavaScript compilation has become quite common. If you need to take compilation into account, look into prepare. That said, NPM modules do not need to be compiled, and it is wise to assume that compilation is not the default, especially for older node modules (and possibly also for very new, bleeding-edge "ESNext"-y ones).
The methods are covered pretty well now in npm's install documentation as well as the numerous other answers here.
npm install git+ssh://git#github.com:<githubname>/<githubrepo.git[#<commit-ish>]
npm install git+ssh://git#github.com:<githubname>/<githubrepo.git>[#semver:^x.x]
npm install git+https://git#github.com/<githubname>/<githubrepo.git>
npm install git://github.com/<githubname>/<githubrepo.git>
npm install github:<githubname>/<githubrepo>[#<commit-ish>]
However, something notable that has changed recently is npm adding the prepare script to replace the prepublish script. This fixes a long-standing problem where modules installed via Git did not run the prepublish script and thus did not complete the build steps that occur when a module is published to the npm registry. See Run prepublish for Git URL packages #3055.
Of course, the module authors will need to update their package.json file to use the new prepare directive for this to start working.
There's also npm install https://github.com/{USER}/{REPO}/tarball/{BRANCH} to use a different branch.
The current top answer by Peter Lyons is not relevant with recent NPM versions. For example, using the same command that was criticized in this answer is now fine.
npm install https://github.com/visionmedia/express
If you have continued problems it might be a problem with whatever package you were using.
The general form of the syntax is
<protocol>://[<user>[:<password>]#]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:<semver>]
which means for your case it will be
npm install git+ssh://git#github.com/visionmedia/express.git
From npmjs docs:
npm install :
Installs the package from the hosted git provider, cloning it with
git. For a full git remote url, only that URL will be attempted.
<protocol>://[<user>[:<password>]#]<hostname>[:<port>][:][/]<path>[#<commit-ish>
| #semver:] is one of git, git+ssh, git+http,
git+https, or git+file.
If # is provided, it will be used to clone exactly that
commit. If the commit-ish has the format #semver:,
can be any valid semver range or exact version, and npm will look for
any tags or refs matching that range in the remote repository, much as
it would for a registry dependency. If neither # or
semver: is specified, then master is used.
If the repository makes use of submodules, those submodules will be
cloned as well.
If the package being installed contains a prepare script, its
dependencies and devDependencies will be installed, and the prepare
script will be run, before the package is packaged and installed.
The following git environment variables are recognized by npm and will
be added to the environment when running git:
GIT_ASKPASS
GIT_EXEC_PATH
GIT_PROXY_COMMAND
GIT_SSH
GIT_SSH_COMMAND
GIT_SSL_CAINFO GIT_SSL_NO_VERIFY
See the git man page for details.
Examples:
npm install git+ssh://git#github.com:npm/npm.git#v1.0.27
npm install git+ssh://git#github.com:npm/npm#semver:^5.0
npm install git+https://isaacs#github.com/npm/npm.git
npm install git://github.com/npm/npm.git#v1.0.27
GIT_SSH_COMMAND='ssh -i ~/.ssh/custom_ident' npm install git+ssh://git#github.com:npm/npm.git npm install
You can do:
npm install git://github.com/foo/bar.git
Or in package.json:
"dependencies": {
"bar": "git://github.com/foo/bar.git"
}
This works for me and it is less typing.
npm i github:<UserName>/<RepoName>
package.json
{
"dependencies": {
"name": "github:<UserName>/<RepoName>"
}
}
Install it directly:
npm install visionmedia/express
Alternatively, you can add "express": "github:visionmedia/express" to the "dependencies" section of package.json file, then run:
npm install
You could also do
npm i alex-cory/fasthacks
or
npm i github:alex-cory/fasthacks
Basically:
npm i user_or_org/repo_name
Sometimes I need to install from a specific branch or commit.
To make things simple I just use https://gitpkg.vercel.app/
You can directly install a GitHub repository by the npm install command, like this:
npm install https://github.com/futurechallenger/npm_git_install.git --save
NOTE: In the repository which will be installed by npm command:
maybe you have to have a dist folder in you repository, according to Dan Dascalescu's comment.
You definitely have to have a package.json in your repository! Which I forget add.
Simple:
npm install *GithubUrl*.git --save
Example:
npm install https://github.com/visionmedia/express.git --save
I tried npm install git+https://github.com/visionmedia/express but that took way too long and I wasn't sure that would work.
What did work for me was - yarn add git+https://github.com/visionmedia/express.
Below piece of code worked for me to install from github repository:
npm install git+ssh://<your_repository_ssh_clone_link>#<branch_name_if_any>
You can get ssh clone link as below:
So for above screenshot repository, you may need to import as below,
npm install git+ssh://git#github.com:Siddhu2/calculator-chatbot.git#master
where master is my branch and it is optional since I have only one branch.
If you get something like this:
npm ERR! enoent undefined ls-remote -h -t https://github.com/some_repo/repo.git
Make sure you update to the latest npm and that you have permissions as well.
The only command that worked for me was npm i MY_PACKAGE_NAME:MY_REPOSITORY#BRANCH_NAME
No need to do much; this helped me:
Yarn add <git_name>:<github_name>/<Repository_name>.git
Example:
yarn add git#github.com:myGitHub/dynamic-checkbox-input.git
And if you want to add some specific commit or branch name then add #.
Example:
yarn add git#github.com:myGitHub/dynamic-checkbox-input.git#master
Example:
yarn add git#github.com:myGitHub/dynamic-checkbox-input.git#c978U57
Yarn 2 requires the package name along with the Github repository. Read the documentation of Yarn's CLI.
Example: yarn add <package_name>git#github.com:<owner_name>/<package_name>.git
Try this command:
npm install github:[Organisation]/[Repository]#[master/BranchName] -g
This command worked for me:
npm install github:BlessCSS/bless#3.x -g

How do I install package.json dependencies in the current directory using npm

I have a web app: fooapp. I have a package.json in the root. I want to install all the dependencies in a specific node_modules directory. How do I do this?
What I want
Lets say I have two widget dependencies. I want to end up with a directory structure like this:
node_modules/
widgetA
widgetB
fooapp/
package.js
lib
..
What I get
when I run npm install fooapp/ I get this:
node_modules/
fooapp/
node_modules/
widgetA
widgetB
package.js
lib/
..
fooapp/
package.js
lib/
..
npm makes a copy of my app directory in the node_modules dir and installs the packages inside another node_modules directory.
I understand this makes sense for installing a package. But I don't require() my web app inside of something else, I run it directly. I'm looking for a simple way to install my dependencies into a specific node_modules directory.
Running:
npm install
from inside your app directory (i.e. where package.json is located) will install the dependencies for your app, rather than install it as a module, as described here. These will be placed in ./node_modules relative to your package.json file (it's actually slightly more complex than this, so check the npm docs here).
You are free to move the node_modules dir to the parent dir of your app if you want, because node's 'require' mechanism understands this. However, if you want to update your app's dependencies with install/update, npm will not see the relocated 'node_modules' and will instead create a new dir, again relative to package.json.
To prevent this, just create a symlink to the relocated node_modules from your app dir:
ln -s ../node_modules node_modules
In my case I need to do
sudo npm install
my project is inside /var/www so I also need to set proper permissions.
Just execute
sudo npm i --save
That's all
npm i --force
from documention:
The -f or --force argument will force npm to fetch remote resources even if a local copy exists on disk