[英]Is there a way to get npm install to install "bin" executables in the local node_modules directory (the .bin directory)?
I have a Node project, and I can npm pack
it into a tarball and install it in another directory for testing.我有一个 Node 项目,我可以
npm pack
成一个 tarball,然后安装到另一个目录中进行测试。 When I do that, the set of files in the "bin" clause of my package.json
are correctly symlinked into the node_modules/.bin
directory there.当我这样做时,我的
package.json
的“bin”子句中的文件集被正确地符号链接到那里的node_modules/.bin
目录中。 Thus I can use npx something
to run the "something" script and it works as I would expect.因此,我可以使用
npx something
来运行“something”脚本,并且它按我预期的那样工作。
From the actual project directory, however, npm install
doesn't do that.然而,在实际的项目目录中,
npm install
不会这样做。 The scripts are there in my top-level "bin" directory of course, but npx
doesn't find them.这些脚本当然在我的顶级“bin”目录中,但
npx
找不到它们。 Obviously I could just run them directly, but it would be nice if I could run the same shell commands to run them in other installation directories and in the project home directory.显然我可以直接运行它们,但如果我可以运行相同的 shell 命令以在其他安装目录和项目主目录中运行它们,那就太好了。
I don't want to install the package globally;我不想全局安装 package; I want to keep everything local, at least for now.
我想把所有东西都放在本地,至少现在是这样。 So can I get
npm
to make those symlinks for me, or should I just bite the bullet and do it myself?那么我可以获取
npm
来为我创建这些符号链接,还是我应该硬着头皮自己做?
Here's my package.json
:这是我的
package.json
:
{
"name": "@foo/plazadb",
"version": "0.1.0",
"description": "Basic database setup with upload/download from CSV",
"main": "lib/plazadb.js",
"author": "Pointy",
"license": "ISC",
"dependencies": {
"arg": "^5.0.1",
"cls-hooked": "^4.2.2",
"csv-parser": "^3.0.0",
"csv-stringify": "^6.0.5",
"neat-csv": "^7.0.0",
"pg": "^8.7.*",
"sequelize": "^6.16.*"
},
"bin": {
"conntest": "./bin/conntest.js",
"download": "./bin/download.js",
"upload": "./bin/upload.js"
}
}
The "bin" files all exist (of course, otherwise they would never work). “bin”文件都存在(当然,否则它们将永远无法工作)。 What I'm trying (out of ignorance) is a simple
npm install
from the project directory.我正在尝试(出于无知)是从项目目录进行简单的
npm install
。
One way to do is by一种方法是通过
npm config set prefix <path>
or one of these methods linked here .npm config set prefix <path>
或此处链接的其中一种方法指定本地前缀。npm link
npm link
As a word of caution, to undo npm link
executing npm unlink.
请注意,要撤消
npm link
,请执行npm unlink.
may not work .可能行不通。 Instead one may have to run
npm uninstall -g.
相反,可能必须运行
npm uninstall -g.
. .
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.