#nodejs #js #module #node

js-resolve

Node.js 模块解析器

4 个版本

0.1.3 2022年1月30日
0.1.2 2022年1月30日
0.1.1 2020年1月6日
0.1.0 2019年11月28日

#2 in #modules

MIT 许可证

9KB
110 代码行数(不含注释)

js-resolve

Rust 中的简单 Node.js 模块解析器。

它基于 Node.js 解析算法

用法

只需调用 resolve。第一个参数是模块(例如:包名或路径),第二个参数是参考路径。

参考路径应该是请求模块的文件的目录。

第一个参数是一个字符串,引用模块、相对路径、绝对路径或空字符串。

如果第一个参数是空字符串,则检查 package.json 并尝试解析到 index.js/index.mjs/index.json

如果是一个引用模块的字符串,它将在您的 node_module 目录中查找,并按照原始解析算法递归查找,直到找到您的包或到达根目录。

use js_resolve;

js_resolve::resolve("express", PathBuf::from("/var/apps/server/"));
js_resolve::resolve("./index.js", PathBuf::from("/var/apps/server/"));
js_resolve::resolve("/app/index.js", PathBuf::from("/var/apps/server/"));

许可证

Copyright (c) 2019 Silvio Henrique Ferreira

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

依赖关系

~145KB