简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM