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"
}
});
});
There's no way to rename a package, you have to deprecate and publish a new package.
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.
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.
@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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With