{"id":23196241,"url":"https://github.com/wojpawlik/deno2node","last_synced_at":"2025-04-13T00:41:43.076Z","repository":{"id":39651100,"uuid":"352162398","full_name":"wojpawlik/deno2node","owner":"wojpawlik","description":"Compile your Deno project to run on Node.js.","archived":false,"fork":false,"pushed_at":"2025-03-26T15:06:22.000Z","size":170,"stargazers_count":120,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"v1","last_synced_at":"2025-04-12T00:42:44.193Z","etag":null,"topics":["deno","transpile","transpiles-deno","ts-morph","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wojpawlik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-27T19:45:05.000Z","updated_at":"2025-02-19T14:48:29.000Z","dependencies_parsed_at":"2024-11-27T14:34:24.463Z","dependency_job_id":null,"html_url":"https://github.com/wojpawlik/deno2node","commit_stats":{"total_commits":113,"total_committers":3,"mean_commits":"37.666666666666664","dds":0.08849557522123896,"last_synced_commit":"e6eb4d8206fdd6dbf34f3eab18271f0720345076"},"previous_names":["wojpawlik/deno2node"],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wojpawlik%2Fdeno2node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wojpawlik%2Fdeno2node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wojpawlik%2Fdeno2node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wojpawlik%2Fdeno2node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wojpawlik","download_url":"https://codeload.github.com/wojpawlik/deno2node/tar.gz/refs/heads/v1","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650416,"owners_count":21139672,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deno","transpile","transpiles-deno","ts-morph","typescript"],"created_at":"2024-12-18T14:17:29.385Z","updated_at":"2025-04-13T00:41:43.034Z","avatar_url":"https://github.com/wojpawlik.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# deno2node\n\n`tsc` replacement for transpiling [Deno] libraries to run on [Node.js].\n\n\u003e [!Note]\n\u003e You don't need this if you maintain a npm package Deno can already\n\u003e run: https://deno.land/manual/node\n\n![Because Deno's tooling is way simpler than\nNode's](https://pbs.twimg.com/media/FBba11IXMAQB7pX?format=jpg)\n\n## Quick Setup\n\nRun `npx deno2node --init` in an empty directory.\n\n\u003e [!Note]\n\u003e If you don't already have a `package.json`, you may find [`dnt`]\n\u003e easier to use.\n\n## CLI Usage From Node.js\n\n```sh\nnpm install -ED deno2node\nnpm pkg set scripts.prepare=deno2node\n```\n\n\u003e [!Warning]\n\u003e New features or TypeScript upgrades may change output or diagnostics\n\u003e across minor versions of `deno2node`. Use `--save-prefix='~'` or\n\u003e `--save-exact` (`-E`) to avoid unexpected failures.\n\nCreate a [`tsconfig.json`] to specify `\"compilerOptions\"` and `\"files\"` to\n`\"include\"`, if you don't have one already.\n\nYou can now invoke `deno2node` by running `npm run prepare`.\n\nIt will alse be executed automatically when you run `npm install`.\n\n## CLI Usage From Deno\n\n`deno2node` is actually a Deno project that compiles itself to run on Node.js.\n(This is a great way to test the tool, too.)\n\n```sh\ndeno run --no-prompt --allow-read=. --allow-write=. \\\n  https://deno.land/x/deno2node/src/cli.ts\n```\n\n## How It Works\n\nThere are three main steps to this.\n\n1. Transform the code base in-memory, by rewriting all import statements.\n2. Typecheck the code.\n3. Emit `.js` and `.d.ts` files. These files can directly be run by Node or\n   published on npm.\n\n`deno2node` uses [`ts-morph`] under the hood, which in turn builds on top of the\nTypeScript compiler `tsc`. Hence, you get the same behaviour as if you had\ndeveloped your code directly for Node.\n\n`deno2node` can perform more powerful transpilation steps that make it flexible\nenough for most needs.\n\n### Shimming\n\nSome things are global in Deno, but not in Node.js.\n\nTo rectify this, create a file that exports shims for the globals you need:\n\n```ts\n// @filename: src/shim.node.ts\nexport { webcrypto as crypto } from \"crypto\";\nexport { Deno } from \"@deno/shim-deno\";\nexport { alert, confirm, prompt } from \"@deno/shim-prompts\";\n```\n\n\u003e [!Note]\n\u003e `node:` APIs are well-supported on both runtimes.\n\nThen, register your shims in [`tsconfig.json`], so `deno2node` can import them\nwhere needed:\n\n```jsonc\n// @filename: tsconfig.json\n{\n  \"deno2node\": {\n    \"shim\": \"src/shim.node.ts\" // path to shim file, relative to tsconfig\n  }\n}\n```\n\n### Runtime-specific code\n\nIn same cases you may want to have two different implementations, depending on\nwhether you're running on Deno or on Node. When shimming is not enough, you can\nprovide a Node-specific `\u003canything\u003e.node.ts` and a Deno-specific\n`\u003canything\u003e.deno.ts` version of any file. They need to reside next to each other\nin the same directory.\n\n`deno2node` will ignore the Deno version and rewrite imports to use the Node.js\nversion instead. Thus, the Deno-specific file will not be part of the build\noutput.\n\nFor example, provide `greet.deno.ts` for Deno:\n\n```ts\n// @filename: src/greet.deno.ts\nexport function greet() {\n  console.log(\"Hello Deno!\");\n  // access Deno-specific APIs here\n}\n```\n\nNow, provide `greet.node.ts` for Node:\n\n```ts\n// @filename: src/greet.node.ts\nexport function greet() {\n  console.log(\"Hello Node!\");\n  // access Node-specific APIs here\n}\n```\n\nFinally, use it in `foo.ts`:\n\n```ts\nimport { greet } from \"./platform.deno.ts\";\n\n// Prints \"Hello Deno!\" on Deno,\n// and \"Hello Node!\" on Node:\ngreet();\n```\n\nThis technique has many uses. `deno2node` itself uses it to import from\nhttps://deno.land/x. The Telegram bot framework [`grammY`] uses it to abstract\naway platform-specific APIs.\n\n### Vendoring\n\nTo import a module which has no npm equivalent, first set up `vendorDir`.\n\n```jsonc\n// @filename: tsconfig.json\n{\n  \"deno2node\": {\n    \"vendorDir\": \"src/vendor/\" // path within `rootDir`\n  }\n}\n```\n\nThen, populate it: `deno vendor src/deps.vendor.ts --output src/vendor/`.\n\nVendoring is still experimental, so be welcome to open an issue if you encounter\na problem with it!\n\nAlso, consider recommending [`pnpm`] to users of your library. It might be able\nto deduplicate vendored files across packages.\n\n## API\n\nConfer the automatically generated [API Reference] if you want to use\n`deno2node` from code.\n\n## Testing\n\nRegister tests via `\"node:test\"`, and build them alongside the source.\n\nThen, test with `deno test src/` _and_ `node --test lib/`.\n\n## Contributing\n\n`npm it` to install dependencies, build, and test the project.\n\n`git config core.hooksPath scripts/hooks/` to build before each commit.\n\n[deno]: https://deno.land/\n[node.js]: https://nodejs.org/\n[`dnt`]: https://github.com/denoland/dnt\n[`grammy`]: https://github.com/grammyjs/grammY\n[`pnpm`]: https://github.com/pnpm/pnpm#background\n[`ts-morph`]: https://github.com/dsherret/ts-morph\n[`tsconfig.json`]: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html\n[api reference]: https://doc.deno.land/https/deno.land/x/deno2node/src/mod.ts\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwojpawlik%2Fdeno2node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwojpawlik%2Fdeno2node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwojpawlik%2Fdeno2node/lists"}