Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM Pack: Rename package directory

I have a small script that uses npm pack to package a certain nodejs module. When I unpack the .tgz created by the npm pack command the directory inside is named package. My question is if there's a way to rename this package to the acutal name of the project?

Package.json

{
   "name": "package_name",
   "version": "0.0.3",
   "description": "A description",
   "main": "server.js",
   "scripts": {
      "test": "echo \"Error: no test specified\" && exit 1"
   },
   "author": "",
   "license": "ISC",
   "dependencies": {
      "request": "2.55.0"
   },
   "devDependencies": {
      "grunt": "0.4.5",
      "grunt-contrib-concat": "0.5.1"
   }
}

Here's to code I'm using, might be helpful.

npm.load('./some/path', function (er) {
    if (er) {
       res.send("er");
    }
    npm.commands.pack(['./another/path'], function (er, data) {
    if (er) {
       res.send("error");
    }

    var fileName = __dirname+"/projectName-0.0.3.tgz";
    res.sendFile(fileName, {
         headers: {
             "Content-Type": "application/x-tar"
         }
    });
});
like image 742
cbass Avatar asked Apr 18 '15 13:04

cbass


People also ask

Can you rename an npm package?

There's no way to rename a package, you have to deprecate and publish a new package.

What is shrinkwrap npm?

NPM shrinkwrap is used to lock the dependency version in a project. After installing packages using npm install or npm install package-name and updating your node_modules folder, you should run npm shrinkwrap. It will create new npm-shrinkwrap.

What is a tarball npm?

Tarball is a compressed file format. You need to unpack it before running the npm command. From: http://www.rebol.com/docs/unpack-tar-gz.html. To unpack a tar.gz file, you can use the tar command from the shell.


1 Answers

@Kirill Slatin is correct. The npm pack format is intended for internal consumption, so npm does not provide an affordance for changing the name from package to something else.

However, you can change the names while extracting if your tar supports the -s switch. On OSX, you can do:

tar -xvz -s/package/foo/ -f foo-1.0.0.tgz

(Edited, thanks David G for pointing out the error.)

like image 156
Sam Mikes Avatar answered Sep 26 '22 00:09

Sam Mikes