Skip to content

Commit

Permalink
Update Readme and init.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
wojpawlik committed Sep 6, 2023
1 parent e7e4ad2 commit c4a503b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

`tsc` replacement for transpiling [Deno] libraries to run on [Node.js].

> **Note** You don't need this if you maintain a npm package Deno can already
> [!Note]
> You don't need this if you maintain a npm package Deno can already
> run: https://deno.land/manual/node
![Because Deno's tooling is way simpler than
Expand All @@ -12,7 +13,8 @@ Node's](https://pbs.twimg.com/media/FBba11IXMAQB7pX?format=jpg)

Run `npx deno2node --init` in an empty directory.

> **Note** If you don't already have a `package.json`, you may find [`dnt`]
> [!Note]
> If you don't already have a `package.json`, you may find [`dnt`]
> easier to use.
## CLI Usage From Node.js
Expand All @@ -22,7 +24,8 @@ npm install -ED deno2node
npm pkg set scripts.prepare=deno2node
```

> **Note** New features or TypeScript upgrades may change output or diagnostics
> [!Warning]
> New features or TypeScript upgrades may change output or diagnostics
> across minor versions of `deno2node`. Use `--save-prefix='~'` or
> `--save-exact` (`-E`) to avoid unexpected failures.
Expand Down Expand Up @@ -67,14 +70,14 @@ To rectify this, create a file that exports shims for the globals you need:

```ts
// @filename: src/shim.node.ts
export { Blob } from "buffer";
export { webcrypto as crypto } from "crypto";

export { fetch, File, FormData, Headers, Request, Response } from "undici";
export { Deno } from "@deno/shim-deno";
export { alert, confirm, prompt } from "@deno/shim-prompts";
```

> [!Note]
> `node:` APIs are well-supported on both runtimes.
Then, register your shims in [`tsconfig.json`], so `deno2node` can import them
where needed:

Expand Down
11 changes: 7 additions & 4 deletions src/init.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env -S deno run --no-check --allow-read --allow-write='.'
import fs from "node:fs/promises";
#!/usr/bin/env -S deno run --allow-read --allow-write='.'
import * as fs from "node:fs/promises";

const shimFile = "// See https://github.com/fromdeno/deno2node#shimming";
const gitignore = "/lib/\n/node_modules/\n/src/vendor/";
Expand All @@ -24,13 +24,16 @@ async function createPackageJson() {
"typings": "./lib/mod.d.ts",
"files": [
"lib/",
"!lib/**/*.test.*",
"!*/vendor/**/*.ts*",
],
"scripts": {
"prepare": "deno2node --project tsconfig.json",
"clean": "git clean -fXde !node_modules/",
"fmt": "deno fmt",
"lint": "deno lint",
"test": "deno test",
"prepare": "deno2node",
"postprepare": "node --test lib/",
"clean": "git clean -fXde !node_modules/",
},
"devDependencies": {
"deno2node": `~${await getVersion()}`,
Expand Down

0 comments on commit c4a503b

Please sign in to comment.