我可以强制node.js要求区分大小写吗? [英] Can I force node.js require to be case sensitive?
问题描述
例如:当在Lion上运行时, require('./ mymodule')
会找到 ./ myModule.js
但不是在Linux上。
因为我想让本地测试失败,为了不破坏服务器上的构建,我正在寻找方法来使node.js需要更严格的,如果它的文件名不是确切的(即有差异),它会抛出一个错误。
有谁知道一个方法来实现这一点?
编辑:
解决这个问题我创建了 valiquire 。
这个工具验证了整个nodejs项目中的所有需求,同时也确保框架是正确的。
但是在重新格式化的代价下,你可以改变你的fs格式来使用hfs区分大小写。
http://www.coriolis -systems.com/iPartition.php 在此线程中提到: https://superuser.com/questions/380330/mac-convert-from-case-sensitive-to-case-insensitive-file-system
Since my Mac has a case-insensitive filesystem case related typos will not be caught when running tests locally, however they fail on the build server which is running Linux.
For example: require('./mymodule')
will find ./myModule.js
when running on Lion, but not on Linux.
Since I'd like to have the tests fail locally as well in order to not break the build on the server, I'm looking for a way to make node.js require more strict in that it throws an error if it the filename is not exact (i.e. has a difference in casing).
Does anyone know of a way to accomplish this?
EDIT:
Since there seemed no good solution for this problem out there I created valiquire.
This tool validates all requires found in an entire nodejs project also ensuring that the casing is correct.
Since your hfs filesystem is not case sensitive, lookups for 'fileName' will match 'filename' at OS lib level, and therefore node.js will behave the same. So by definition there is no workaround.
But at the price of a reformating you can change your fs format to use hfs case sensitive.
http://www.coriolis-systems.com/iPartition.php is mentioned in this thread : https://superuser.com/questions/380330/mac-convert-from-case-sensitive-to-case-insensitive-file-system
这篇关于我可以强制node.js要求区分大小写吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!