我可以强制node.js要求区分大小写吗? [英] Can I force node.js require to be case sensitive?

查看:2633
本文介绍了我可以强制node.js要求区分大小写吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我的Mac有一个不区分大小写的文件系统,在本地运行测试时,相关的输入错误将不会被捕获,但是它们在运行Linux的生成服务器上失败。



例如:当在Lion上运行时, require('./ mymodule')会找到 ./ myModule.js 但不是在Linux上。

因为我想让本地测试失败,为了不破坏服务器上的构建,我正在寻找方法来使node.js需要更严格的,如果它的文件名不是确切的(即有差异),它会抛出一个错误。



有谁知道一个方法来实现这一点?

编辑



解决这个问题我创建了 valiquire

这个工具验证了整个nodejs项目中的所有需求,同时也确保框架是正确的。

由于您的hfs文件系统不区分大小写,因此在OS lib级别查找'fileName'将与'filename'匹配,因此node.js将表现相同。所以根据定义,没有解决方法。

但是在重新格式化的代价下,你可以改变你的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆