Coder Social home page Coder Social logo

dnt's Introduction

dnt - Deno to Node Transform

deno doc

Prototype for a Deno to Node/canonical TypeScript transform.

CLI Example

# install
deno install --allow-read --allow-write --allow-net -n dnt https://deno.land/x/dnt/cli.ts

# clone a Deno-first repo
git clone https://github.com/dsherret/code-block-writer.git
cd code-block-writer

# run tool and output to ./code-block-writer/npm/dist (uses tsc CLI flags)
dnt mod.ts --target ES6 --outDir ./npm/dist --declaration

# go to output directory, run tsc, and publish
cd npm
npm publish

JS API Example

To emit the Deno-first sources to code that can be consumed in Node.js, use the emit function:

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

const emitResult = await emit({
  compilerOptions: {
    outDir: "./dist",
  },
  entryPoint: "./mod.ts",
  shimPackageName: "deno-shim-package-name",
  typeCheck: false,
});

For only the Deno to canonical TypeScript transform which can be useful for bundlers, use the following:

// docs: https://doc.deno.land/https/deno.land/x/dnt/transform.ts
import { transform } from "https://deno.land/x/dnt/transform.ts";

const outputFiles = await transform({
  entryPoint: "./mod.ts",
  shimPackageName: "deno-shim-package-name",
  keepExtensions: false, // transforms to not have extensions
});

Rust API Example

When using TypeScript, the Rust API only transforms from Deno to canonical TypeScript. You will need to use the TypeScript compiler to do the rest.

use std::path::PathBuf;

use deno_node_transform::ModuleSpecifier;
use deno_node_transform::transform;
use deno_node_transform::TransformOptions;

let output_files = transform(TransformOptions {
  entry_point: ModuleSpecifier::from_file_path(PathBuf::from("./mod.ts")).unwrap(),
  keep_extensions: false,
  loader: None, // use the default loader
}).await?;

for output_file in output_files {
  // use these properties on output_file
  output_file.file_path;
  output_file.file_text;
}

dnt's People

Contributors

dsherret 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.