Architecture of nodejs/node and denoland/deno_std/node
I contribute to denoland/deno_std as a hobby, and I've been looking at denoland/deno_std/node a lot, so I thought I'd take a quick look at the architectural differences between the nodejs/node and denoland/deno_std/node APIs at this point in time (2021/12/16).
Where to implement the API
nodejs/node
It is implemented in node/lib.
Using Query string as an example, the logic is implemented in node/lib/querystring.js and exported at here.
In addition, internal code that does not need to be exported is implemented in node/lib/internal.
In Query string, functions such as encordStr are exported, and imported at node/lib/querystring.js
.
denoland/deno_std
It is implemented in deno_std/node.
APIs that are compatible with the logic exported in nodejs/node/lib/querystring.js
in deno_std/node/querystirng.ts are exported here.
Also, in deno_std/node/internal, an implementation equivalent to nodejs/node/lib/internal
has been created.
Implementation Language
nodejs/node
It is implemented in JavaScript and C++.
Using URL as an example, some C++ code is called by the internalBinding in JavaScript implementations such as node/lib/url.js
and node/lib/internal/url.js
.
For example, the domainToASCII implementation is in node/src/node_url.cc.
Incidentally, I was wondering why it is not implemented in JavaScript, and asked Why domainToASCII is written by C++ not JS? in the help repository, and got the answer "for perf reasons".
Also, primordials are used in many places.
You can read more about primordials in the suggestions around prototype pollution and primordials.js(Japanese article).
denoland/deno_std
It is implemented in JavaScript and TypeScript.
For example, Query string is implemented in querystring.ts
, and Buffer is implemented in node/buffer.js, and node/buffer.d.ts is specified in @deno-types
of node/buffer.ts.
The equivalent of Node's internalBinding is implemented by TypeScript in node/internal_binding.
The primordials are implemented in denoland/deno, but not in denoland/deno_std.
Tests
nodejs/node
It can be found in node/test.
For example, URL testing is implemented in node/test/parallel/test-url-*.js
.
The execution method and other information is summarized in pull-requests.md.
denoland/deno_std
In node/_tools/config.json, specify the file name of the test in nodejs/node/test
, retrieve it in node/_tools/setup.ts, and place it in node/_tools/suites.
The execution method and other information is summarized in node/README.md.