cbass
cbass

Reputation: 2558

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"
         }
    });
});

Upvotes: 6

Views: 11739

Answers (1)

Sam Mikes
Sam Mikes

Reputation: 10848

@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.)

Upvotes: 5

Related Questions