Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

make-deno-edition

bevry949Artistic-2.02.3.0TypeScript support: included

Automatically makes package.json projects (such as npm packages and node.js modules) compatible with Deno.

denoify, edition, editions, es2022, node, npm, transpile, typed, types, typescript, unpkg

readme

make-deno-edition

Status of the GitHub Workflow: bevry NPM version NPM downloads
GitHub Sponsors donate button ThanksDev donate button Patreon donate button Liberapay donate button Buy Me A Coffee donate button Open Collective donate button crypto donate button PayPal donate button
Discord server badge Twitch community badge

Automatically makes package.json projects (such as npm packages and node.js modules) compatible with Deno.

Overview

Examples

Here is the growing list of all the packages that make-deno-edition has made compatible with Deno.

The Need

Node.js and TypeScript support unresolved paths, e.g. import thing from './file' and import thing from './'. Deno however, only supports resolved paths, e.g. import thing from './file.ts' and import thing from 'https://unpkg.com/badges@^4.13.0/edition-deno/index.ts'. This means that anything imported into Deno must be directly resolvable and must use ECMAScript Modules (ESM).

Node.js and TypeScript support package.json files to specify dependency versions, which enables code like import dep from 'dep'. Deno however, has no conception of package.json, so all dependencies must be imported via a directly resolvable CDN URL, e.g. import dep from 'https://unpkg.com/dep@^1.0.0/file.ts'.

Deno and Node.js different on their APIs. Node.js builtins can be converted to Deno's std/node builtins, however several things such as __filename, __dirname require a polyfill, and other things have no direct compatibility so require different entries.

In the end, you must hope your dependencies are also compatible with Deno.

The Solution

make-deno-edition is a CLI tool that takes your source edition (whichever directory contains your package's typescript source files) and creates a compatible deno edition in a edition-deno directory.

It provides this compatibility by providing the following transformations:

  1. bultin imports (e.g. fs) are mapped to their corresponding deno node:* polyfill

  2. certain globals (e.g. __filename and __dirname) are mapped to their corresponding deno userland polyfilll

  3. internal imports (any relative path to another file inside your source edition) are mapped to their typescript file, e.g. import thing from './file' and import thing from './file.js' becomes import thing from './file.ts

  4. remote imports (e.g. any URL) are assumed to be compatible, as node.js doesn't support them, so it is assumed they are already deno compatible

  5. dependency imports (e.g. any package you install into node_modules) are supported by:

    1. If they have a deno field in their package.json, which will denote where to look for the deno compatible entry file, then it's direct unpkg URL will be used.

      The more dependencies that make-deno-edition is run on, then the more dependencies will automatically have a deno entry field, and thus the more dependencies will be automatically compatible with Deno, enabling more dependents to be automatically compatible with Deno.

    2. If they are an installed dependency, their esm.sh URL will be used.

    3. If they are an uninstalled dependency, the npm: prefix will be used.

make-deno-edition will also intelligently ignore compatibility for files that are not essential, such as your test and utility files, but fail if compatibility for an essential file, such as an entry file and its required modules fail

Finally, make-deno-edition will also update your package.json file with the details for the deno entry file, as well as the deno edition metadata, such that other packages and toolchains can make use of your deno compatibility.

Usage

Complete API Documentation.

Preparation

If you are using boundation to automatically generate deno compatibility for your npm package, then you can skip this step.

If you haven't already done so, add the following editions metadata to your package.json file:

  "editions": [
    {
      "description": "TypeScript source code with Import for modules",
      "directory": "source",
      "entry": "index.ts",
      "tags": [
        "typescript",
        "import"
      ],
      "engines": false
    }
  ]

Make sure that the directory is where the source files are located, in the above example, they are located in a source directory, as it is with this repository.

Make sure that the entry is where the entry file is located within the edition directory, in the above example, the entry is index.ts, as it is with this repository.

Executable

If you are using boundation to automatically generate deno compatibility for your npm package, then you can skip this step.

Install make-deno-edition to your development dependencies using:

npm install --save-dev make-deno-edition

Then add a compile npm script to your package.json containing:

make-deno-edition --attempt

Alternatively, you can run it directly on your project via:

npx make-deno-edition --attempt

The --attempt flag will not emit a failure exit code if the deno edition generation was not successful. If you require a deno edition to be published, remove the --attempt flag.

Publishing

If you are using boundation to automatically generate compatible editions (web browsers, deno, multiple node.js versions) for your npm package, then you can skip this step.

If you are using projectz to automatically generate your README.md content, then you can skip this step.

If a deno edition was successfully created, it will be located in the edition-deno directory with the metadata added to the editions array in your package.json and a deno entry field also added to your package.json.

Consumers of your package who use make-deno-edition on their own package, will now be able to use your package's deno edition to further their own deno compatibility.

You can also instruct consumers of your package to directly use your deno edition, by informing them of its presence in your README.md file. You can use projectz to automatically insert this information for them, or you can use the following template:

<a href="https://deno.land" title="Deno is a secure runtime for JavaScript and TypeScript, it is an alternative for Node.js"><h3>Deno</h3></a>

``` typescript
import pkg from 'https://unpkg.com/YOURPACKAGENAME@^VERSION/edition-deno/ENTRY.ts'
```

Install

npm

Install Globally

  • Install: npm install --global make-deno-edition
  • Executable: make-deno-edition

Install Locally

  • Install: npm install --save make-deno-edition
  • Executable: npx make-deno-edition
  • Import: import * as pkg from ('make-deno-edition')
  • Require: const pkg = require('make-deno-edition')

Editions

This package is published with the following editions:

  • make-deno-edition/source/index.ts is TypeScript source code with Import for modules
  • make-deno-edition aliases make-deno-edition/edition-es2022/index.js
  • make-deno-edition/edition-es2022/index.js is TypeScript compiled against ES2022 for Node.js 18 || 20 || 21 with Require for modules
  • make-deno-edition/edition-es2022-esm/index.js is TypeScript compiled against ES2022 for Node.js 18 || 20 || 21 with Import for modules
  • make-deno-edition/edition-types/index.d.ts is TypeScript compiled Types with Import for modules

History

Discover the release history by heading on over to the HISTORY.md file.

Backers

Code

Discover how to contribute via the CONTRIBUTING.md file.

Authors

Maintainers

Contributors

Finances

GitHub Sponsors donate button ThanksDev donate button Patreon donate button Liberapay donate button Buy Me A Coffee donate button Open Collective donate button crypto donate button PayPal donate button

Sponsors

  • Andrew Nesbitt — Software engineer and researcher
  • Balsa — We're Balsa, and we're building tools for builders.
  • Codecov — Empower developers with tools to improve code quality and testing.
  • Poonacha Medappa
  • Rob Morris
  • Sentry — Real-time crash reporting for your web apps, mobile apps, and games.
  • Syntax — Syntax Podcast

Donors

License

Unless stated otherwise all works are:

and licensed under:

changelog

History

v2.3.0 2023 December 30

v2.2.0 2023 December 28

v2.1.0 2023 December 6

v2.0.1 2023 December 5

  • Add Windows compatibility

v2.0.0 2023 November 24

  • It's been 2 years, 5 months and 8 days (total 891 days) since the last update to make-deno-edition and a lot has changed! This release incorporates all of it! Expect a lot more successful Deno editions being made. Shoutout to my GitHub Sponsors for affording me the time to make this happen.
  • Updated builtin compatibility table
  • Use esh.sh where appropriate
  • Use and understand node: and npm: prefixes where appropriate
  • Update filedirname fallback to use node:filedirname instead of a fragile URL
  • Update internals to make use of the @bevry/fs-* and @bevry/json utilities instead
  • Updated dependencies, base files, and editions using boundation

v1.3.0 2021 June 14

v1.2.0 2020 October 29

  • Use the --unstable flag when testing compatibility, as some of the std/node polyfills require it as they are still unstable
  • Updated dependencies, base files, and editions using boundation

v1.1.1 2020 September 4

  • Removed a left over debug log

v1.1.0 2020 September 3

  • Updated for filedirname v2
  • Targets Deno >= 1.3.2
  • Fixed regression from v1.0.3 where export statements could incorrectly continue onto import comments

v1.0.3 2020 August 19

v1.0.2 2020 August 18

  • Fixed __dirname detection (regression in v1.0.1)

v1.0.1 2020 August 18

  • Add support for the deno std/node/url polyfill
  • Refresh the deno cache when attempting to run our conversions
  • Use Bevry's __dirname and __filename ponyfill as the community one disappeared
  • Do not use the __dirname and __filename ponyfill if they are manually set

v1.0.0 2020 August 17

v0.15.0 2020 June 25

v0.14.0 2020 June 25

v0.13.0 2020 June 25

  • Don't verify files work with deno on Travis CI (unless the new --run flag is provided) as it is likely Deno is not present on Travis CI

v0.12.0 2020 June 25

  • Improvements to the stdout messages
  • Failed attempts will now output which files failed, and if --verbose is provided (or if it is running on Travis CI) then the complete details are also provided.

v0.11.1 2020 June 25

  • Make binary have executable permissions which is reuqired for yarn environments

v0.11.0 2020 June 25

v0.10.0 2020 June 22

v0.9.1 2020 June 21

  • Fix devDeps being merged into deps

v0.9.0 2020 June 20

v0.8.1 2020 June 20

  • Support export * from 'module' statements

v0.8.0 2020 June 20

  • Trim various fetch polyfills

v0.7.0 2020 June 20

  • Allow required deno permissions to be specified via package.json keywords
  • Deno run commands are now outputted, and indentation is corrected
  • Changed written to passed to reflect v0.6.0 changes
  • If there is a deno.ts file inside the source edition, that is used as the deno entry instead

v0.6.1 2020 June 20

  • Fix non-functional typo

v0.6.0 2020 June 20

  • Now each made deno edition file is run against deno

v0.5.1 2020 June 20

  • Fixed imports of the name as the package being mangled (regression since v0.4.0)

v0.5.0 2020 June 20

  • Support buffer imports

v0.4.2 2020 June 20

  • Fix non-functional typo

v0.4.1 2020 June 20

  • Fix thrown errors not being caught in v0.4.0

v0.4.0 2020 June 20

  • Add or remove the package.json keywords deno, denoland, deno-entry, and deno-edition based on successful deno compatibility
  • Cleaner and more detailed and useful output
  • Updated dependencies, base files, and editions using boundation

v0.3.0 2020 June 11

v0.2.2 2020 June 10

  • Fixed package imports that have a deno entry

v0.2.1 2020 June 10

  • Now supports nested files
  • Now supports circular imports

v0.2.0 2020 June 10

v0.1.2 2020 June 10

  • Use https:// instead of //, as // fails with error: File URL contains invalid path

v0.1.1 2020 June 10

  • Fixed deno-edition being generated instead of edition-deno

v0.1.0 2020 June 10

  • Initial working release