The JavaScript and TypeScript runtime Deno has reached version 1.30. In the first release of the year, the runtime from Node.js inventor Ryan Dahl is again dedicated to use with Node.js modules. The release also adds three new APIs that are currently considered unstable: Deno.Conn.ref()
, Deno.Conn.unref()
and Deno.osUptime()
. The latter requires the --allow-sys=osUptime
-Permission. the deno.core
-Namespace is dropped in this release, which the Deno team says shouldn’t impact most users.
New specifier for Node.js modules
Deno has been offering access to modules integrated in Node.js such as File System, Path or Process since version 1.15 through a compatibility layer. New in version 1.30 is access via node:
Specifier:
import { readFileSync } from "node:fs";
console.log(readFileSync("deno.json", { encoding: "utf8" }));
However, importing using a pure specifier is not possible without an import map. For example, would import { readFileSync } from "fs";
lead to an error. If you try this and the specifier resembles a built-in Node.js module that cannot be found in an import map, Deno generates an error message. This indicates what is missing node:
-prefix to. The Language Server Protocol (LSP) also offers a quick fix to node:
to add specifiers.
Using deno.json as import map
Described by the Deno team as a major update to the configuration file, the deno.json file can now be used as an import map. Developers can now imports
– and scopes
-Specify keys in configuration. Deno then considers the configuration file as an import map.
The following code is used in deno.json
{
"imports": {
"std/": "https://deno.land/[email protected]/"
}
}
then the following script works with a pure specifier:
import { assertEquals } from "std/testing/assert.ts";
assertEquals(1, 2);
The current innovations can be followed in the Q1 roadmap on GitHub. A blog entry also takes a look back at the past year.
More details on version 1.30 can also be found on the Deno blog.
(May)