@dual-bundle/import-meta-resolve
一个叉子 import-meta-resolve
同时提供共同js +无害环境管理支持,AKA双包.
它会重新定位并试图释放出来,以便每天与上游同步, 见 .github/工作流量/再基.yml 详细情况.
安装
# npm
npm install @dual-bundle/import-meta-resolve
# yarn
yarn add @dual-bundle/import-meta-resolve
导入元解析
解决像Node.js这样的问题.
目录
这是什么?
这个包是用来填马的 import.meta.resolve。 。 。 .
它支持所有你需要解决的文件,就像现代节点所做的:
导入地图,导出地图,装入CJS和无害环境管理项目,所有这一切!
什么时候用这个?
截至20.0号节点, import.meta.resolve 还在实验旗后.
这个包可以用来做它在"节点16–20"中所做的.
安装
这个软件包是 仅限无害环境管理。 。 。 . 在Node.js(第16版+)中,安装为 无数字 :
npm install import-meta-resolve
使用
import {resolve} from 'import-meta-resolve'
// A file:
console.log(resolve('./index.js', import.meta.url))
//=> file:///Users/tilde/Projects/oss/import-meta-resolve/index.js
// A CJS package:
console.log(resolve('builtins', import.meta.url))
//=> file:///Users/tilde/Projects/oss/import-meta-resolve/node_modules/builtins/index.js
// A scoped CJS package:
console.log(resolve('@eslint/eslintrc', import.meta.url))
//=> file:///Users/tilde/Projects/oss/import-meta-resolve/node_modules/@eslint/eslintrc/lib/index.js
// A package with an export map:
console.log(resolve('micromark/lib/parse', import.meta.url))
//=> file:///Users/tilde/Projects/oss/import-meta-resolve/node_modules/micromark/lib/parse.js
// A node builtin:
console.log(resolve('fs', import.meta.url))
//=> node:fs
API 密码
此软件包导出标识符 moduleResolve 财务报告和审定财务报表
resolve。 。 。 .
没有默认导出 .
resolve(specifier, parent)
匹配 import.meta.resolve 不过 parent 需要( 您可以通过)
import.meta.url) (中文(简体) ).
参数
specifier(单位:千美元)string(中文(简体) ) – 模块指定符,用于解决相对于母体的问题 (单位:千美元)/example.js, (中文(简体) ),./example.js, (中文(简体) ),../example.js, (中文(简体) ),some-package, (中文(简体) ),fs页:1parent(单位:千美元)string,例如:import.meta.url(中文(简体) ) —— 要解决的绝对母模块 URL; 您必须通过import.meta.url或别的东西
回返
满 file:, (中文(简体) ), data:,或 node: URL (中文(简体) )string对发现的东西
掷出
丢出一个 ErrnoException。 。 。 .
moduleResolve(specifier, parent, conditions, preserveSymlinks)
这个 “溶解算法规格” 如节点文件所详述
(比 resolve) (中文(简体) ).
参数
specifier(单位:千美元)string(中文(简体) ) —— 说/example.js, (中文(简体) ),./example.js, (中文(简体) ),../example.js, (中文(简体) ),some-package, (中文(简体) ),fs类parent(单位:千美元)URL,例如:import.meta.url(中文(简体) ) —— 完整 URL( 到文件)specifier解析相对conditions(单位:千美元)Set<string>,默认值 :new Set(['node', 'import'])(中文(简体) ) 条件preserveSymlinks(单位:千美元)boolean,默认值 :false(中文(简体) ) ——保持并联而不是解决
回返
URL 对象 (URL对发现的东西.
掷出
丢出一个 ErrnoException。 。 。 .
ErrnoException
解析时发生的许多不同错误之一(TypeScript类型).
类型
type ErrnoExceptionFields = Error & {
errnode?: number | undefined
code?: string | undefined
path?: string | undefined
syscall?: string | undefined
url?: string | undefined
}
这个 code 字段上的错误是以下字符串之一:
'ERR_INVALID_MODULE_SPECIFIER'何时specifier无效( 例如:'#'(中文(简体) )'ERR_INVALID_PACKAGE_CONFIG'当package.json无效( 例如: 无效的 JSON)'ERR_INVALID_PACKAGE_TARGET'当package.jsonexports或者说imports无效( 例如: 当 不从'./'(中文(简体) )'ERR_MODULE_NOT_FOUND'何时specifier无法在parent(例:'some-missing-package'(中文(简体) )'ERR_NETWORK_IMPORT_DISALLOWED'——在试图解决本地文件或从远程文件内建时抛出 (单位:千美元)node:fs相对于'https://example.com'(中文(简体) )'ERR_PACKAGE_IMPORT_NOT_DEFINED'——当导入图中没有定义本地导入时(例如:'#local'未定义时)'ERR_PACKAGE_PATH_NOT_EXPORTED'当导出在导出图中未定义时(例如:'tape/index.js', (中文(简体) ), 在其导出图中未显示)'ERR_UNSUPPORTED_DIR_IMPORT'—— 当尝试导入目录时( 例如 :'./lib/'(中文(简体) )'ERR_UNKNOWN_FILE_EXTENSION'——不知何故读取一个带有出乎意料的扩展名的文件('./readme.md'(中文(简体) )'ERR_INVALID_ARG_VALUE'何时conditions错误
算法
用于 resolve 匹配节点处理方式 import.meta.resolve,与
几相差别相.
用于 moduleResolve 与 解析器算法
规格 如节点文档所详述(同步和略微)
低于 resolve) (中文(简体) ).
与节点的差异
parent默认为import.meta.url无法填充: 您必须 明确通过- 不支持加载器(这意味着执行所有加载器)
- 不支持 CLI 旗帜 :
--conditions, (中文(简体) ),--experimental-default-type, (中文(简体) ),--experimental-json-modules, (中文(简体) ),--experimental-network-imports, (中文(简体) ),--experimental-policy, (中文(简体) ),--experimental-wasm-modules, (中文(简体) ),--input-type, (中文(简体) ),--no-addons, (中文(简体) ),--preserve-symlinks,则--preserve-symlinks-main工作 - 没有支持
WATCH_REPORT_DEPENDENCIESenv 变量 - 没有试图根据过去的工作方式增加一项建议 CJS 在未找到错误之前
- 原生方法没有保护:例如,节点保护
String#slice可能不会被篡改
类型
此软件包已全部输入 类型脚本。 。 。 .
它输出额外类型 ErrnoException。 。 。 .
兼容性
这个软件包至少可以兼容所有已维护的Node.js版本. 从现在起,那是Node.js 16 以及后来.
贡献
是的,请! 见 如何为开放源码做出贡献。 。 。 .