How to convert NuGet package to npm - npm

I need to convert/repackage NuGet package to npm package. Has anyone tried this before?
Is there any automatic tool that exist? (At least for simple cases with no dependencies)

You have to maintain the package contents with a package.json file in a git repo and register the repo in npm registry to publish it to npm.
UG: publishing-npm-packages

Related

Is there a way to install an npm package locally but not affect package.json or package-lock.json?

I have a project that I'm working on for a client where I have two private packages (which I can't get access to npm install) are inside the package.json.
I do however have access to clone the repos for those said packages. If I simply run an npm install I'll get a permission denied error. Same if I run npm link to the packages.
I've been working around this by removing the packages from the package.json then running npm install ../some-package. This works but isn't a great solution because if I wanted to add a new package I'd have to deal with a bit of a mess with the package.json.
Is there a better way than this?
I have tried running npm link ../some-package but I still get access denied. The only way I've managed to complete an install is by removing the packages then installing them from a local dir.
I don't know the details of your situation, but I see at least two potential solutions to explore.
Option 1: Install the package from the repo
I do however have access to clone the repos for those said packages.
You can install from a git repo and package.json will record that git repo as the source of the package rather than the npm registry.
From the docs at https://docs.npmjs.com/cli/v8/commands/npm-install:
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.
Option 2: Install from the local file system with --no-save
If that approach doesn't work for you, you can try npm install --no-save ../some-package as a build step. The --no-save makes it so it doesn't modify package.json.

Does npm or yarn clone from VCS and run build script when install a package?

I am studying about npm and I have some questions.
Where the npm get the package from? i.e. when run npm install <package-name> or yarn add <package-name>.
When get the package, do npm get the package as raw or get then build it(like run the build script written in package.json)?
When publish the package, the repository field of package.json is required?
Can be different between the repository for publishing and the repository in pacakge.json?
To answer your questions:
npm gets them from the NPM package registry, and so does yarn, but Yarn probably has a proxy registry in front of it. In general, you can say, both tools fetch their packages from https://npmjs.com by default.
It gets the package as it was published (so, in short, the answer is "raw"). Building is up to the publisher and depends on the type of package. Often, some prepublish task builds something into dist/ (or any other location in the package), and these files are also shipped with the package others then download. Building rarely happens after installing a package (exception here are library-wrapping packages built with node-gyp).
The repository field is not required, to my knowledge, but it is good practise to include it (it will be displayed on the NPM website, for example).
Technically, yes. You can just specify any repository in repository, but it wouldn't make much sense to specify one that isn't the source of the package.
If you in general want to read up more on how npm works, check out it's documentation over at https://docs.npmjs.com/

Use of creating a package.json file in our Node project

Why do we create a package.json file using npm init and what is its use while uploading our project on git?
Your package.json is the core of npm. In this file all of your dependencies and node packages are outlined. It's important to upload to you git repository so that anyone cloning your project will have the same dependencies and packages on the same version as the project was developed in. In addition, being able to startup a project with npm start and npm install makes everyone's life easier.

How can I install npm packages without the source code

Is it possible to install an npm package without all the other artifacts. For instance install only the content of the dist folder for the jQuery npm package?
It remains to the module publisher to exclude such files as sources, docs, tests ... and only include build and binary files when they publish their npm package (via prepublish hooks, .npmignore files, etc ...).
Not all maintainers are aware / take that in account ... The only thing you can do, as a module consumer (when you npm install) is to use the --production flag, not to install devDependencies (but that's not what you're looking for)

Add README.md to published npm package

I already published a package to NPM, but forgot the README. I updated the package, tried npm publish ./ again, but it says I can't publish on top of a published package.
So, how do I send a README to a published package?
You should increment the version. Like 0.0.0 to 0.0.1.
Just open package.json in your text editor, find "version":"0.0.0" and type in the new value.
After incrementing the version. Like 0.0.0 to 0.0.1 in your package.json file
Create a README.md in the project root directory of your package. after writing up your read me. you can now publish your package by running the npm publish. that should work and should show up your readme on the npm site.