jsr.io 是 Deno 官方团队开发维护的一个包仓库, 可以同时发布为 Deno 和 Node.js 的包.
如果没有 jsr.io, 如果一个包想要同时支持 Deno 和 Node.js, 那么需要维护两套代码.
如果不想维护两套代码, 则可以构建时魔改代码, 但会受到许多约束:
.ts
后缀名.jsr.io 的包可以同时支持 Deno 和 Node.js, 解决了上述痛点. 但是 jsr.io 有两大问题:
虽然 Deno 的一大核心是 V8 引擎, 但 Deno 的运行时针对浮点计算进行了特殊处理.
比如我们要做下面的浮点运算: 1.1 * 100
110
110.00000000000001
110.00000000000001
Deno 的运行时似乎在刻意避免浮点误差.
Node.js 的生态非常庞大, Deno 想要扩大运行时市场份额, 需要为在 Node.js 环境下开发的软件提供兼容性.
在 Deno 2.x 版本中, Deno 已经尽量支持了许多 Node.js 的包.
但是这种支持仍然有限:
目前 Deno 提供的 API 仍有限, 比如有下面的问题:
jsr.io is a package registry developed and maintained by the Deno official team, allowing packages to be published for both Deno and Node.js.
Without jsr.io, supporting both Deno and Node.js would require maintaining two separate codebases.
To avoid maintaining dual codebases, code could be transformed during build time, but with several constraints:
.ts
extensions when converting to Node.js packages.jsr.io packages can support both Deno and Node.js, solving these pain points. However, jsr.io has two major issues:
Although V8 engine is a core component of Deno, the runtime handles floating-point calculations differently.
For example, let’s consider this floating-point calculation: 1.1 * 100
110
110.00000000000001
110.00000000000001
Deno’s runtime appears to deliberately avoid floating-point errors.
With Node.js’s vast ecosystem, Deno needs to provide compatibility for software developed in Node.js environment to expand its runtime market share.
In Deno 2.x, many Node.js packages are supported.
However, this support is still limited:
Currently, Deno’s API offerings are still limited, with issues such as: