Our great sponsors
-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
-
node_shims
npm packages providing shims for the Deno namespace and other globals. Useful for running Deno-first programs on Node.
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
import { build, emptyDir } from "dnt"; await emptyDir("./npm"); await build({ entryPoints: ["./mod.ts"], outDir: "./npm", typeCheck: true, test: true, declaration: true, scriptModule: "umd", importMap: "./import-map.json", compilerOptions: { lib: ["es2021", "dom"], }, shims: { deno: "dev", }, package: { name: "hpke-js", version: Deno.args[0], description: "A Hybrid Public Key Encryption (HPKE) module for web browsers, Node.js and Deno", repository: { type: "git", url: "git+https://github.com/dajiaji/hpke-js.git", }, homepage: "https://github.com/dajiaji/hpke-js#readme", license: "MIT", main: "./script/mod.js", types: "./types/mod.d.ts", exports: { ".": { "import": "./esm/mod.js", "require": "./script/mod.js", }, "./package.json": "./package.json", }, keywords: [ "hpke", // ...省略 ], engines: { "node": ">=16.0.0", }, author: "Ajitomi Daisuke", bugs: { url: "https://github.com/dajiaji/hpke-js/issues", }, }, }); // post build steps Deno.copyFileSync("LICENSE", "npm/LICENSE"); Deno.copyFileSync("README.md", "npm/README.md");
Specifically, make my codebase be for Deno, use Deno built-in formatter, linter and testing, and use dnt (Deno to Node Transform) to generate an npm package containing ESM code and to test generated code. For testing in the browser, deploy the test content linked to the generated ESM code to Github Pages and use playwright/test. For Cloudflare Workers, use wrangler to set up a worker locally for testing. A schematic diagram is shown below.
A TypeScript Hybrid Public Key Encryption (HPKE) implementation build on top of Web Cryptography API This module works on web browsers, Node.js, Deno and Cloudflare Workers
Specifically, make my codebase be for Deno, use Deno built-in formatter, linter and testing, and use dnt (Deno to Node Transform) to generate an npm package containing ESM code and to test generated code. For testing in the browser, deploy the test content linked to the generated ESM code to Github Pages and use playwright/test. For Cloudflare Workers, use wrangler to set up a worker locally for testing. A schematic diagram is shown below.
Since git tags are used for versioning in deno.land, make the tag name SemVer compliant (e.g., 1.2.3). v1.2.3 is also fine, but this will cause inconsistencies in the way of specifying versions in various CDNs (sometimes with v and sometimes without). I recommend that you use 1.2.3 without v.
Basically, do not use Deno-dependent funcitons. However, if you have to use a Deno namespace feature or any other feature that affects portability, check to see if it has a shim that is injected when converting to an npm package with dnt (see node_deno_shims. For example, the implementation status of the shims is listed up here). Using shim will ensure that it works on Node.js.
eggs is a CLI tool to deploy a package to nest.land. My setting file is (hpke-js/egg.json) as follows. It's like a package.json.
# download from a CDN (esm.sh) curl -o $YOUR_PATH/hpke.js https://esm.sh/v86/[email protected]/es2022/hpke-js.js # or downlaod a minified version from a CDN curl -o $YOUR_PATH/hpke.js https://esm.sh/v86/[email protected]/es2022/hpke.min.js # or use `deno bundle` deno bundle https://deno.land/x/[email protected]/mod.ts > $YOUR_PATH/hpke.js