[英]NPM Pack: Rename package directory
I have a small script that uses npm pack
to package a certain nodejs module. 我有一个小脚本,使用npm pack
打包某些nodejs模块。 When I unpack the .tgz
created by the npm pack
command the directory inside is named package
. 当我解压缩npm pack
命令创建的.tgz
,其中的目录名为package
。 My question is if there's a way to rename this package to the acutal name of the project? 我的问题是,是否有办法将此包重命名为项目的正式名称?
Package.json 的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. @Kirill Slatin是正确的。 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. npm pack
格式仅供内部使用,因此npm不能提供将名称从package
更改为其他名称的权利。
However, you can change the names while extracting if your tar
supports the -s
switch. 但是,如果您的tar
支持-s
开关,则可以在提取时更改名称。 On OSX, you can do: 在OSX上,您可以执行以下操作:
tar -xvz -s/package/foo/ -f foo-1.0.0.tgz
(Edited, thanks David G for pointing out the error.) (已编辑,感谢David G指出错误。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.