October 27, 2020
Bartek Iwańczuk, Luca Casonato, Ryan Dahl
Today we are releasing Deno 1.5.0. This release contains a few new features, many feature stabilizations, and a ton of bug fixes. Here are some highlights:
deno bundle
now
has tree shaking, and is up to 15x faster than 1.4alert
, confirm
, and prompt
added:
web compatible prompt APIs to interact with a userIf you already have Deno installed you can upgrade to 1.5 by running
deno upgrade
. If you are installing Deno for the first time, you can use one
of the methods listed below:
# Using Shell (macOS and Linux):curl -fsSL https://deno.land/x/install/install.sh | sh
# Using PowerShell (Windows):iwr https://deno.land/x/install/install.ps1 -useb | iex
# Using Homebrew (macOS):brew install deno
# Using Scoop (Windows):scoop install deno
# Using Chocolatey (Windows):choco install deno
Since the last release we have been hard at work to refactor our entire TypeScript compiler infrastructure. Because of this we were able to replace our aging bundling infrastructure with a new bundler based on swc.
This has led to a 3x performance improvement when we type-check your code,
and up to a 15x improvement if you use the --no-check
flag.
In addition to the performance improvements the bundler is now capable of tree shaking your code. This means it will remove code from the bundle that you are not actually using. This leads to a major size reductions in bundles. For example a bundle of the file_server example is 35% smaller in 1.5 when comparing to 1.4.
Bundles are now also emitted as a standard ES module, which means that dynamic
import will work correctly now, and import.meta.url
is also set correctly. If
you were using Deno to bundle code for the browser, make sure to load the bundle
as an ES module now (type="module"
attribute on your <script>
tag).
alert
, confirm
, and prompt
added
This release adds the web platform APIs alert
, confirm
, and prompt
. These
have the same functions as they do in the browser:
alert
logs a message to the terminal, and then synchronously blocks until
you confirm (with [Enter]
).confirm
prompts the user with a message, and then synchronously blocks until
the user responds with either y
or n
(to signal yes
or no
).prompt
requests some input from the user, and blocks synchronously until the
user has entered the text and pressed [Enter]
.Here is a little demo of these functions in action. You can try it out by
running deno run https://deno.land/posts/v1.5/alert_confirm_prompt.js
.
let name = "";
while (true) { name = prompt("What is your name?");
if (confirm(`Are you sure ${name} is your name?`)) { break; }}
alert(`Hello ${name}!`);
The REPL has had a major refactor enabling several new features. Here are some of the highlights:
Tab
to cycle through the list of properties and methods.NO_COLOR
environment variable.await
promises in the REPL
without having to wrap your call in an async IIFE.This release enables the isolatedModules
TypeScript compiler option for all
users by default. In the 1.4 release this flag was enabled for users using
--unstable
. This option enables some stricter checks in the TypeScript
compiler that will likely lead to some new errors you have not seen before:
ERROR TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
These errors occur when interfaces or type aliases are re-exported. To fix the
error, change your re-exports to use export type
. Example:
// Badexport { MyType } from "./mod.ts";
// Goodexport type { MyType } from "./mod.ts";
For now you can override this option in a tsconfig.json
.
Deno
API additions and stabilizations
We have stabilized Deno.fsync()
, Deno.fdatasync()
, and their synchronous
counterparts. These low-level methods are for ensuring modified file data is
written to the disk drive.
There are also two new unstable APIs introduced to --unstable
:
Deno.sleepSync()
- This function can be used to synchronously sleep. This
will block the event loop, blocking all async operations, and JavaScript
execution. In most cases you will want to use setTimeout
to sleep as this
does not block the event loop.Deno.systemCpuInfo()
- This function can be used to get information about
number of cores available in the machine as well as the speed of the CPU.deno lint
updates
deno lint
has gotten some new rules this release. The main one is camelcase
:
it checks that all of your variable declarations use camelCase
formatting. We
are hoping to stabilize deno lint
for Deno 1.6.
In addition to the new rules, we have introduced hints for lint diagnostics. These hints will suggest how the lint errors can be fixed.
Finally deno lint
has a website now that you can use to view documentation and
explanations for the rules. You can find it at https://lint.deno.land.
deno fmt --ignore
now stable
The deno fmt --ignore
flag is now available without the --unstable
flag.
This flag can be used to ignore some files or folders from being formatted or
checked by the formatter.
std
The assertStringContains
and assertArrayContains
methods in
std/testing/asserts.ts
have been renamed to assertStringIncludes
and
assertArrayIncludes
respectively, to match the the naming of the includes
method on strings and arrays. To update your code, simply rename the imported
methods:
- import { assertStringContains, assertArrayContains } from "https://deno.land/std@0.74.0/testing/asserts.ts";-- assertStringContains("denosaur", "deno")- assertArrayContains(["deno", "new", "release"], "new")+ import { assertStringIncludes, assertArrayIncludes } from "https://deno.land/std@0.75.0/testing/asserts.ts";++ assertStringIncludes("denosaur", "deno")+ assertArrayIncludes(["deno", "new", "release"], "new")
In addition to this renaming, a assertExists
and assertObjectMatch
assertion
have been added to std/testing/asserts.ts
:
assertExists
asserts that the passed value is not null
or undefined
.assertExists("foo"); // passesassertExists(""); // passesassertExists(0); // passesassertExists(null); // throwsassertExists(undefined); // throws
assertObjectMatch
asserts that the expected
value is a subset of the
actual
value.assertObjectMatch({ a: "b", c: "d" }, { a: "b", c: "d" }); // passesassertObjectMatch({ a: "b", c: "d" }, { a: "b" }); // passesassertObjectMatch({ a: "b", c: "d" }, { a: "b", c: "f" }); // throwsassertObjectMatch({ a: "b" }, { a: "b", c: "d" }); // throws
The full release notes, including bug fixes, can be found at https://github.com/denoland/deno/releases/tag/v1.5.0.