Denoify: For NPM module authors that would like to support Deno but don't want to write a port

栏目: IT技术 · 发布时间: 3年前

内容简介:WARNING: This is a pre-release that might be broken in some ways. Stay tuned.

Denoify: For NPM module authors that would like to support Deno but don't want to write a port

Support Deno and release on NPM with a single codebase.

WARNING: This is a pre-release that might be broken in some ways. Stay tuned.

What it is

This tool takes as input a TypeScript codebase that was meant to target node and/or the web and spits out a modified version of the source files that are ready to be deployed as a Deno module.

Denoify does for Deno what browserify does for the browser.

What it isn't

A way to import node modules in Deno projects. For that purpose you can try CommonJS module Loading

Motivations

  • Although it is quite easy to port a module to Deno it is a chore to maintain two codebase.
  • Wouldn't it be great to have a tool able to make all the major NPM modules available to Deno?

Example of modules using Denoify

Modules that have been made cross-runtime using Denoify:

Will it work with my module ?

At this stage of it's development, Denoify set quite restrictive requirements:

  • Does your users need to have @types/node installed to use your module ? If yes then, unfortunately, your module is not denoifiable as it is. Even if you are allowed to use (some, not all) node builtins such as fs , path or event you will need to remove all Node reference from your exposed API before you can use Denoify. You can't for example expose a class that extends EventEmitter or if you do you will have to export a type definition for EventEmitter .
  • You will need to provide a Deno polyfill for each of your project dependencies that are not known by Denoify. Here is the list of modules for which Denoify has already a polyfill for.

    Note that Denoify work recursively meaning that you can fork your dependencies repo and Denoify them yourself.

    However, depending on how deep your dependency tree goes it might not be feasible.

  • Is your module a vanilla JS project? If yes you will have to port it into TypeScript first.

Roadmap to 1.0

These are the milestone that, when achieved, will enable Denoify to work transparently on most NPM modules:

  • Supporting all node builtins, everything on this list should be checked ( help more than welcome ).
  • Supporting require() and fs ( synchronously or not ) for dynamically accessing files of the project ( files that sits in the node_modules directory in Node ). Note that fs for the most part is already functional but the problem arises when trying to access files that are not present on the disk. In Deno unlike in Node, the packages files are not present on the disk at runtime. Fetching them synchronously is not a satisfactory solution for obvious reasons. We can do it the way Browserify is doing it but this approach works only if the paths can be analyzed statically. The solution would be to provide a way for the user to define the files that are susceptible to be accessed synchronously at runtime or by default pre-loading everything in a single files if the project is using require or fs .
  • The changes are currently performed with RegExp, we need to use the TypeScript compiler API if we want the tool to be fully reliable. ts-morph seems to be a good option here.
  • Support Javascript projects and automatically bundle types from DefinitelyTyped ( also applicable for @types/node ).
  • Automatically Denoify dependencies ( require all the previous milestone ).

GUIDES

Setting up on an existing project

Check out this repo to see in practice how to set up Denoify in your project.

Starting a project from scratch

Denoify: For NPM module authors that would like to support Deno but don't want to write a port

denoify_ci is a template repo that automate the boring and tedious tasks of:

  • Filling up the package.json
  • Setting up Typescript and Denoify .
  • Writing a README.md with decent presentation and instructions on how to install/import your module.
  • Testing on multiples Node and Deno version before publishing.
  • Maintaining a CHANGELOG
  • Publishing on NPM and deno.land/x ( via GitHub releases ).

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

人人都是产品经理

人人都是产品经理

苏杰 / 电子工业出版社 / 2014-9-1 / CNY 55.00

《人人都是产品经理(纪念版)》为经典畅销书《人人都是产品经理》的内容升级版本。对于大量成长起来的优秀互联网产品经理,为数不少想投身产品工作的其他岗位从业者,以及更多有志从事这一职业的学生而言,这本书曾是他们记忆深刻的启蒙读物、思想基石和行动手册。作者以分享经历与体会为出发点,以“朋友间聊聊如何做产品”的语气,将自己数年产品工作过程中学到的思维方法与做事方式,及其它们对自己的帮助,系统性地梳理为用户......一起来看看 《人人都是产品经理》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

URL 编码/解码
URL 编码/解码

URL 编码/解码