How to use a package in Angular2 without publishing it to npm - node.js

I have a package which is published to npm and we are successfully using the package in our angular2 applications by defining the dependency in package.json as
"dependencies": {
"somesharedmodule": "^1.0.21",
}
and in our components as import {SharedService} from 'somesharedmodule'.
Now we dont want to make the library public(not interested to make private library too).My question is - i have a module in some folder of my local system.Can i use this module in my application without making the package published in npm. can somebody please guide me the alternatives to use a module in my application without publishing it?

Not clear what exactly you want to do... Bu there are lots of options:
npm link https://docs.npmjs.com/cli/link
use github private repo:
"dependencies": {
"ng2-resource": "https://github.com/{nickName}/{repoName}.git"
}
link your IDE to use local folder as node_modules
manually copy/paste library into project's node_modules

Related

NPM how to install package as it was another

want to install package com.cordova.plugin.cache and its content i need it to be also as cordova-plugin-cache..
Example package.json was like this:
"dependencies": {
// Note these two are the same but with different name
"cordova-plugin-cache": "git+git#gitlab.com:dev/library/org.git",
"com.cordova.plugin.cache": "git+git#gitlab.com:dev/library/org.git"
}
But i published a modified version both of it on a private npm repository to remove the dependency as a repository.
"dependencies": {
// Note these two are the same but with different package name
"cordova-plugin-cache": "git+git#gitlab.com:dev/library/org.git",
"com.cordova.plugin.cache": "git+git#gitlab.com:dev/library/org.git"
}
Is this even possible? do i have to save both packages as they were two different?
Actually i have one package in a private npm registry, but don't want to duplicate the project.
Any hint is appretiated.
NPM itself has no such feature, it was discussed on their GitHub repository here and it was decided not to implement such a feature.
The solution outlined in this article may prove to solve your problem:
You can utilise the link-module-alias module, add a _moduleAliases section to your package.json that describes the alias you wish to establish and then add a postinstall script that executes the aforementioned module.

Manually install modules for Angular 5 without npm

I wish to manually install npm modules for my Angular project. I am behind a proxy and instead of setting the proxy information for my npm config file, I just wish to manually download npm modules and add them to my npm-cache/node_modules folders.
I have seen this old post but haven't found anything more recent: How to install a node.js module without using npm?
One of the modules I want to install is ng2-signalr. I went to GitHub, downloaded the source for the package, and added it to my node_modules folder.
After doing this I can import the module without error:
import { SignalRConfiguration } from 'ng2-signalr';
When I add code that uses the class:
const c = new SignalRConfiguration();
I get the following error:
index.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
Am I missing a step for manually installing a node module? Should I download to my npm cache folder?
I'm aware that I have to pay mind to dependencies of these manually installed modules. Also I know that the cache folder gets overwritten when you need to reinstall and that the node_modules folder is not usually included when you check in your source due to the size, but I only wish to experiment with the library.
Any advice?
Add the directory or index file you wish to use in your Typescript config. Example in tsconfig.app.json:
"include": [
"../path/to/library"
]
Rebuild after this. This is likely due to the 3rd party not setting up the package.json correctly.

Is it possible to publish a node package by cloning other's?

I need to use a node package in React Native.
But it requires a minor fixes for React Native bundling.
So I want to do something like this.
1. Clone the node package
2. Do minor updates for React Native(dependencies, update some codes for React Native)
3. Publish
Is this possible?
Is this violation of privacy policy?
Can I publish under node package owner's license?
Thanks in advance.
If the project is on GitHub, you could fork the repo, make your changes, and in your package.json use your own copy of the project like so, without having to re-publish it to npm:
"dependencies": {
"thepackage": "git://github.com/username/thepackage.git"
}
With regards to the licensing question however, you'll have to look into the specific license of the package you're using.
You can npm install a git repo as a package, instead of publishing a minor fix copy.

npm: install dependency from local file when available, otherwise from github

I am developing a package (library) at the same time as the application that uses it (also a package) and I would like to use the local library if available as sibling of the application, and otherwise download the latest release from github.
I tried having two references in dependencies and optionalDependencies, hoping that a failure of the latter would still use the specification in the former, but that doesn't work. The package is skipped.
Is this possible at all? Or maybe there are other ways to solve the problem? Maybe some creative use of the script hooks?
Maybe what you can do is to publish it on GitHub and in your package.json you can call directly from the repository something like this:
"dependencies": {
"mongoose-cipher": "git+ssh://git#github.com:estrada9166/mongoose-
cipher.git"
}
or
"dependencies": {
"mongoose-cipher": "git+https://git#github.com:estrada9166/mongoose-
cipher.git"
}
also you can specify the release, in case your repository has one, something like:
"dependencies": {
"mongoose-cipher": "git+ssh://git#github.com:estrada9166/mongoose-
cipher.git#v0.0.7"
}
you can create a private repository with your package and by this way it is safe!
To install from GitHub: npm install <git repo url>
also you can add your package on the node_modules folder and add the dependency on your package.json but personally I prefer to publish to GitHub and install it on my project, is easier.

Shipping node.js project with custom dependencies

I fixed a couple of issues in nested dependencies of my node.js project (dependencies are managed by npm). These fixes are pending pull requests and thus aren't published. What's the best way to use them in my project?
I know that I can do npm link inside the fixed version of the library and then npm link library-name inside my project to force npm to use my fixed version. This approach works but installs my library-name globally on my machine which I don't like.
Is it possible to have it locally in main project's repo, force the project to use it and don't do npm link.
You can use a url as the dependency and point it to your own repo (fork).
https://docs.npmjs.com/files/package.json#urls-as-dependencies
for example:
"dependencies": {
"foo": "git+ssh://user#hostname:project.git#commit-ish"
}
If your pull requests are on GitHub its even easier...
As of version 1.1.65, you can refer to GitHub urls as just "foo":
"user/foo-project". Just as with git URLs, a commit-ish suffix can be
included.
https://docs.npmjs.com/files/package.json#github-urls

Resources