Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

deno2node

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deno2node - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

lib/context.d.ts

1

lib/cli.d.ts
#!/usr/bin/env node
export {};
//# sourceMappingURL=cli.d.ts.map
#!/usr/bin/env node
import { Deno } from "./deno_namespace.node.js";
import { deno2node, emitAndExit } from "./mod.js";
import { Deno } from "./shim.node.js";
if (Deno.args.length !== 1 || Deno.args[0].startsWith("-")) {

@@ -5,0 +5,0 @@ console.error("Usage: deno2node <tsConfigFilePath>");

import { Project } from "./deps.node.js";
export declare function deno2node(tsConfigFilePath: string): Project;
//# sourceMappingURL=deno2node.d.ts.map
// based on https://github.com/dsherret/code-block-writer/blob/99454249cd13bd89befa45ac815b37b3e02896f5/scripts/build_npm.ts
import { Node, Project, validatePackageName } from "./deps.node.js";
import { Context } from "./context.js";
import { Node, validatePackageName } from "./deps.node.js";
function transpileExtension(moduleName) {

@@ -17,29 +18,42 @@ if (validatePackageName(moduleName).validForOldPackages)

}
function transpileImportSpecifiers(sourceFile) {
for (const statement of sourceFile.getStatements()) {
if (Node.isImportDeclaration(statement) ||
Node.isExportDeclaration(statement)) {
const modSpecifierValue = statement.getModuleSpecifierValue();
if (modSpecifierValue !== undefined) {
statement.setModuleSpecifier(transpileExtension(modSpecifierValue));
}
}
}
}
function createShimmer(ctx) {
if (ctx.config.shim === undefined) {
return () => { };
}
const shimFile = ctx.project.addSourceFileAtPath(ctx.resolve(ctx.config.shim));
const namedImports = Array.from(shimFile.getExportedDeclarations().keys());
return (sourceFile) => {
if (sourceFile === shimFile)
return;
sourceFile.addImportDeclaration({
namedImports,
moduleSpecifier: `${sourceFile.getRelativePathAsModuleSpecifierTo(shimFile)}.js`,
});
};
}
const isDenoSpecific = (sourceFile) => sourceFile.getBaseNameWithoutExtension().toLowerCase().endsWith(".deno");
export function deno2node(tsConfigFilePath) {
const project = new Project({
tsConfigFilePath,
compilerOptions: {
allowSyntheticDefaultImports: true,
noEmitOnError: true,
strict: true,
},
});
for (const sourceFile of project.getSourceFiles()) {
if (sourceFile.getBaseNameWithoutExtension().toLowerCase().endsWith(".deno")) {
project.removeSourceFile(sourceFile);
const ctx = new Context(tsConfigFilePath);
const shim = createShimmer(ctx);
for (const sourceFile of ctx.project.getSourceFiles()) {
if (isDenoSpecific(sourceFile)) {
ctx.project.removeSourceFile(sourceFile);
continue;
}
for (const statement of sourceFile.getStatements()) {
if (Node.isImportDeclaration(statement) ||
Node.isExportDeclaration(statement)) {
const modSpecifierValue = statement.getModuleSpecifierValue();
if (modSpecifierValue !== undefined) {
statement.setModuleSpecifier(transpileExtension(modSpecifierValue));
}
}
}
sourceFile.fixMissingImports();
transpileImportSpecifiers(sourceFile);
shim(sourceFile);
transpileShebang(sourceFile);
}
return project;
return ctx.project;
}

@@ -0,3 +1,4 @@

export { default as path } from "path";
export { default as validatePackageName } from "validate-npm-package-name";
export { z } from "zod";
export * from "ts-morph";
//# sourceMappingURL=deps.node.d.ts.map

@@ -0,2 +1,6 @@

// Node-only, see https://github.com/wojpawlik/deno2node/#preparing-your-project
// please keep sorted
export { default as path } from "path";
export { default as validatePackageName } from "validate-npm-package-name";
export { z } from "zod";
export * from "ts-morph";
import type { Project } from "./deps.node.js";
export declare function emitAndExit(project: Project): never;
//# sourceMappingURL=emit_and_exit.d.ts.map

@@ -1,2 +0,2 @@

import { Deno } from "./deno_namespace.node.js";
import { Deno } from "./shim.node.js";
export function emitAndExit(project) {

@@ -3,0 +3,0 @@ const result = project.emitSync();

export * from "./deno2node.js";
export { emitAndExit } from "./emit_and_exit.js";
//# sourceMappingURL=mod.d.ts.map
{
"name": "deno2node",
"version": "0.2.0",
"version": "0.3.0",
"description": "Transpiles Deno projects into `.js` and `.d.ts` for Node.js.",
"type": "module",
"bin": {
"deno2node": "bin.mjs"
"deno2node": "lib/cli.js"
},

@@ -43,3 +43,4 @@ "main": "./lib/mod.js",

"ts-morph": "^10.0.2",
"validate-npm-package-name": "^3.0.0"
"validate-npm-package-name": "^3.0.0",
"zod": "^3.0.0-alpha.39"
},

@@ -46,0 +47,0 @@ "devDependencies": {

# deno2node
<a href="https://doc.deno.land/https/raw.githubusercontent.com/wojpawlik/deno2node/v0.2.0/src/mod.ts"><img src="https://doc.deno.land/badge.svg" alt="deno doc"></a>
<a href="https://doc.deno.land/https/raw.githubusercontent.com/wojpawlik/deno2node/v0.3.0/src/mod.ts"><img src="https://doc.deno.land/badge.svg" alt="deno doc"></a>

@@ -9,4 +9,18 @@ Transpiles Deno projects into `.js` and `.d.ts` for Node.js.

Rename `deps.ts` to `deps.deno.ts`, create corresponding `deps.node.ts`.
Rename `deps.ts` to `deps.deno.ts`, create corresponding [`deps.node.ts`].
<!-- deno-fmt-ignore -->
If you're using some Deno globals not available in Node (`Deno`, `fetch`...),
export their shims from [`shim.node.ts`],
and add the following to your `tsconfig.json`:
```jsonc
// tsconfig.json
{
"deno2node": {
"shim": "src/shim.node.ts"
}
}
```
## Usage from Node.js

@@ -25,3 +39,6 @@

```sh
$ deno run --unstable --allow-read --allow-write https://raw.githubusercontent.com/wojpawlik/deno2node/v0.2.0/src/cli.ts <tsConfigFilePath>
$ deno run --unstable --allow-read --allow-write https://raw.githubusercontent.com/wojpawlik/deno2node/v0.3.0/src/cli.ts <tsConfigFilePath>
```
[`deps.node.ts`]: https://github.com/wojpawlik/deno2node/v0.3.0/main/src/deps.node.ts
[`shim.node.ts`]: https://github.com/wojpawlik/deno2node/v0.3.0/main/src/shim.node.ts
// based on https://github.com/dsherret/code-block-writer/blob/99454249cd13bd89befa45ac815b37b3e02896f5/scripts/build_npm.ts
import { Context } from "./context.ts";
import { Node, Project, SourceFile, validatePackageName } from "./deps.deno.ts";

@@ -20,33 +21,51 @@

export function deno2node(tsConfigFilePath: string): Project {
const project = new Project({
tsConfigFilePath,
compilerOptions: {
allowSyntheticDefaultImports: true,
noEmitOnError: true,
strict: true,
},
});
for (const sourceFile of project.getSourceFiles()) {
function transpileImportSpecifiers(sourceFile: SourceFile) {
for (const statement of sourceFile.getStatements()) {
if (
sourceFile.getBaseNameWithoutExtension().toLowerCase().endsWith(".deno")
Node.isImportDeclaration(statement) ||
Node.isExportDeclaration(statement)
) {
project.removeSourceFile(sourceFile);
const modSpecifierValue = statement.getModuleSpecifierValue();
if (modSpecifierValue !== undefined) {
statement.setModuleSpecifier(transpileExtension(modSpecifierValue));
}
}
}
}
function createShimmer(ctx: Context) {
if (ctx.config.shim === undefined) {
return () => {};
}
const shimFile = ctx.project.addSourceFileAtPath(
ctx.resolve(ctx.config.shim),
);
const namedImports = Array.from(shimFile.getExportedDeclarations().keys());
return (sourceFile: SourceFile) => {
if (sourceFile === shimFile) return;
sourceFile.addImportDeclaration({
namedImports,
moduleSpecifier: `${
sourceFile.getRelativePathAsModuleSpecifierTo(shimFile)
}.js`,
});
};
}
const isDenoSpecific = (sourceFile: SourceFile) =>
sourceFile.getBaseNameWithoutExtension().toLowerCase().endsWith(".deno");
export function deno2node(tsConfigFilePath: string): Project {
const ctx = new Context(tsConfigFilePath);
const shim = createShimmer(ctx);
for (const sourceFile of ctx.project.getSourceFiles()) {
if (isDenoSpecific(sourceFile)) {
ctx.project.removeSourceFile(sourceFile);
continue;
}
for (const statement of sourceFile.getStatements()) {
if (
Node.isImportDeclaration(statement) ||
Node.isExportDeclaration(statement)
) {
const modSpecifierValue = statement.getModuleSpecifierValue();
if (modSpecifierValue !== undefined) {
statement.setModuleSpecifier(transpileExtension(modSpecifierValue));
}
}
}
sourceFile.fixMissingImports();
transpileImportSpecifiers(sourceFile);
shim(sourceFile);
transpileShebang(sourceFile);
}
return project;
return ctx.project;
}

@@ -0,2 +1,5 @@

// please keep sorted
export { default as validatePackageName } from "https://esm.sh/validate-npm-package-name@3.0.0";
export { z } from "https://deno.land/x/zod@3.0.0-alpha.39/mod.ts";
export * as path from "https://deno.land/std@0.95.0/path/mod.ts";
export * from "https://deno.land/x/ts_morph@10.0.2/mod.ts";

@@ -0,2 +1,6 @@

// Node-only, see https://github.com/wojpawlik/deno2node/#preparing-your-project
// please keep sorted
export { default as path } from "path";
export { default as validatePackageName } from "validate-npm-package-name";
export { z } from "zod";
export * from "ts-morph";
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc