GithubHelp home page GithubHelp logo

deno_emit's Introduction

emit

deno emit Twitter handle Discord Chat

Transpile and bundle JavaScript and TypeScript in Deno and Deno Deploy.

This is an unstable module, where the API is likely to change over time.

Why was Deno.emit() removed from Deno?

In Deno 1.22 the unstable API Deno.emit() was removed. This module provides similar functionality as an optional user loaded module.

Having any APIs that are platform specific (e.g. in the Deno namespace) makes code a lot less portable. We have generally avoided adding APIs to the Deno namespace if we can. While Deno.emit() and similar APIs have been part of the unstable features for an extended period of time, creating deno_emit, deno_doc and deno_cache, which expose some of the internal Deno APIs as user loadable modules has proven to be a good pattern for giving the command line power of the Deno CLI to build end-user solutions, which also then can work on edge compute like Deno Deploy.

So while taking away functionality from the Deno CLI may seem like a strange decision, by moving it to a user loadable module, it provides users more choice and flexibility.

Note: the examples below use "unpinned" version of the module. Consider using a "pinned" version (e.g. https://deno.land/x/[email protected]/mod.ts instead.)

Transpiling

Take individual modules that are JavaScript or TypeScript and emit them in a transpiled fashion. An example of taking some TypeScript and transpiling to JavaScript:

import { emit } from "https://deno.land/x/emit/mod.ts";

const url = new URL("./testdata/mod.ts", import.meta.url);
const result = await emit(url);

const code = result[url.href];
console.log(code.includes("export default function hello()"));

Bundle

Take a root module and all its dependencies and emit a single JavaScript bundle. This is similar to the functionality provided by deno bundle on the Deno command line. An example:

import { bundle } from "https://deno.land/x/emit/mod.ts";
const result = await bundle(
  new URL("https://deno.land/[email protected]/examples/chat/server.ts"),
);

const { code } = result;
console.log(code);

Type checking

Currently emit does not perform type checking, while the prior Deno.emit() could. Getting type checking to run under Deno is a complex process. While we want to provide a user loadable solution for this, it is unlikely that it will be provided as part of this module, or would exist as a separate loadable module as part of this one.


Copyright 2018-2022 the Deno authors. All rights reserved. MIT License.

deno_emit's People

Contributors

bartlomieju avatar deckchairlabs avatar denobot avatar dsherret avatar kitsonk avatar knorpelsenf avatar lucacasonato avatar marc2332 avatar ry avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.