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: