[英]Setting PATH on Makefile - Node.js
I want to use api-easy to test my REST app. 我想使用api-easy来测试我的REST应用。 I have it in the dependences inside the package.json, so when I run npm install it's installed in ./node_modules
我在package.json内部的依赖项中有它,因此当我运行npm install时,它安装在./node_modules中
I'm trying to add the api-easy to the path like this question. 我正在尝试将api-easy添加到类似此问题的路径。
Since I'm using a Makefile I have this: 由于我使用的是Makefile,因此具有以下内容:
test:
@PATH="./node_modules/api-easy/node_modules/.bin:$PATH"
@echo $PATH
vows
@node ./test/tests.js
Note: api-easy depends on vows 注意:api-easy取决于誓言
The PATH var in not being updated, when I do the echo it returns me "ATH"(not the value), and then the command vows in not found. PATH变量未更新,当我执行回显时,它返回我“ ATH”(不是值),然后命令发誓未找到。 How can I set properly the PATH in a Makefile?
如何在Makefile中正确设置PATH?
In a make
recipe, each command is executed as a separate process, so setting an environment variable in one command will not affect the others. 在
make
配方中,每个命令都是作为单独的过程执行的,因此在一个命令中设置环境变量不会影响其他命令。 To do what you want, you need to make sure all the related commands run in a single instance of the shell, where environment variables are passed as you would expect: 要执行您想要的操作,您需要确保所有相关命令都在外壳程序的单个实例中运行,在该实例中,可以按预期传递环境变量:
test:
@PATH="./node_modules/api-easy/node_modules/.bin:$$PATH"; \
echo $$PATH; \
vows; \
node ./test/tests.js
The trailing backslash tells make
to concatenate a line with the one that follows it. 后面的反斜杠告诉
make
将一行与其后的一行连接起来。 Note also that you need to quote $
characters if you want them interpreted by the shell. 还请注意,如果要由外壳程序解释
$
字符,则需要引用$
字符。 Hence the $$
. 因此,
$$
。
I think something like this should do it: 我认为应该这样做:
export PATH="./node_modules/api-easy/node_modules/.bin:$PATH"
test:
vows
@node ./test/tests.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.