Deno 1.30 released with built-in Node module

Deno is a simple, modern and secure runtime for JavaScript and TypeScript that uses V8 and is built in Rust.

Deno 1.30 has been released, notable updates include:

Support for built-in Node.js modules

In Deno, npm packages can already access built-in Node.js modules such as fs, path, process, etc. through Deno's Node.js compatibility layer.

In this version, these modules are node: specifiersexposed to Deno code via:

import { readFileSync } from "node:fs";
console.log(readFileSync("deno.json", { encoding: "utf8" }));

If you use both Deno and Node.js code, the node:solution will work on both runtimes.

deno.jsonbecomes an import map

This release brings a major update to the config file, it is now possible to directly use the config deno.jsonfile as an import map.

In previous versions, it was possible to tell Deno where to find the import map file by specifying the importMapkey and the path to the import map file.

Many users find it useful, but this approach means there are two configuration files. To be more concise, you can now specify the importsand scopeskeys in your config file, and Deno will automatically start treating the config file as an import map.

Fixes for Node/npm and LSP

This release includes over 25 bug fixes related to npm functions and Node-API. Additionally, LSP continues to be improved with over 10 bug fixes.

Changes to the DenoAPI

Changes to stable API:

  • Deno.permissions APIs gained a synchronous counterpart
Deno.permissions.querySync({ name: "read", path: "./log.txt" }) 。
Deno.permissions.revokeSync({ name: "read", path: "./log.txt" })。
Deno.permissions.requestSync({ name: "read", path: "./log.txt" });
  • Deno.writeFile()and Deno.writeTextFile()now accepts ReadableStreamas a second argument.

    const stream = new ReadableStream({
      pull(controller) {
        controller.enqueue(new Uint8Array([1]));
        controller.enqueue(new Uint8Array([2]));
        controller.close();
      },
    });
    await Deno.writeFile("/tmp/test.txt", stream);
    assertEquals(Deno.readFileSync(filename), new Uint8Array([1, 2]));
    
  • Added a new Deno.env.has(name)API

    Deno.env.set("TEST_VAR", "A");
    assert(Deno.env.has("TEST_VAR"));
    Deno.env.delete("TEST_VAR");
    assert(!Deno.env.has("TEST_VAR"));
    
  • ...

API stabilization:

Deno.Listener.ref()and Deno.Listener.unref()are now stable. The --unstableflag .

Changes to Unstable API:

  • new Deno.Command({}).spawn()In , the stdinoption's default value was changed to "inherit”mean that if you don't specifically configure this option, standard input will be inherited from the parent process.

  • Deno.dlopenAdd support for passing structs by value:

    const Rect = ["f64", "f64", "f64", "f64"];
    const dylib = Deno.dlopen("./dylib.so", {
      make_rect: {
        parameters: ["f64", "f64", "f64", "f64"],
        result: { struct: Rect },
      },
    });
    const rect_sync = dylib.symbols.make_rect(10, 20, 100, 200);
    assertInstanceOf(rect_sync, Uint8Array);
    assertEquals(rect_sync.length, 4 * 8);
    assertEquals(Array.from(new Float64Array(rect_sync.buffer)), [
      10,
      20,
      100,
      200,
    ]);
    

New unstable API:

This release adds 3 new APIs:

  • Deno.osUptime()(requires -allow-sys=osUptimepermissions )
  • Deno.Conn.ref()
  • Deno.Conn.unref()

These APIs require --unstableflags , but we plan to stabilize them in the next release.

remove internalDeno.core

This release removes Deno.corethe namespace. Deno.coreis a private API with no stability guarantees. This change should have no effect on most users.

Deno fmtSupport configuration semicolon

Deno fmtA long-repeated feature of , is the ability to format without semicolons. This is now possible by using the --options-no-semicolonsflag or specifying in the fmt config in the Deno config file "semiColons": false.

{
  "fmt": {
    "options": {
      "semiColons": false
    }
  }
}

For more details, please check: https://github.com/denoland/deno/releases/tag/v1.30.0

おすすめ

転載: www.oschina.net/news/226137/deno-1-30-released