Skip to content

Commit

Permalink
fix: search parent directories for tsconfig.json
Browse files Browse the repository at this point in the history
Also switches `cli.ts` from `Deno` to `process` (#39)
  • Loading branch information
wojpawlik committed Sep 28, 2023
1 parent 16eb7da commit bd444ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
19 changes: 11 additions & 8 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
#!/usr/bin/env -S deno run --no-prompt --allow-read=. --allow-write=lib/
import { existsSync } from "node:fs";
import * as process from "node:process";
import { ts } from "./deps.deno.ts";
import { getHelpText } from "./help.ts";
import { getVersion, initializeProject } from "./init.ts";
import { Context, deno2node, emit } from "./mod.ts";

const { options, fileNames, errors } = ts.parseCommandLine(Deno.args);
const tsConfigFilePath = options.project ?? ts.findConfigFile(".", existsSync);
const args = process.argv.slice(2);
const { options, fileNames, errors } = ts.parseCommandLine(args);
const tsConfigFilePath = options.project ??
ts.findConfigFile(process.cwd(), existsSync);

if (errors.length) {
for (const error of errors) {
console.error(error.messageText);
}
Deno.exit(2);
process.exit(2);
}

if (options.help) {
console.log(getHelpText(await getVersion()));
Deno.exit(0);
process.exit(0);
}

if (options.version) {
console.log("deno2node", await getVersion());
console.log("typescript", ts.version);
Deno.exit(0);
process.exit(0);
}

if (options.init) {
await initializeProject();
Deno.exit(0);
process.exit(0);
}

const ctx = new Context({
Expand All @@ -44,7 +47,7 @@ if (fileNames.length) {
ctx.project.addSourceFilesFromTsConfig(tsConfigFilePath);
} else {
console.error("Specify entry points.");
Deno.exit(2);
process.exit(2);
}
ctx.project.resolveSourceFileDependencies();
console.timeEnd("Loading source files");
Expand All @@ -58,5 +61,5 @@ if (diagnostics.length !== 0) {
console.info(ctx.project.formatDiagnosticsWithColorAndContext(diagnostics));
console.info("TypeScript", ts.version);
console.info(`Found ${diagnostics.length} errors.`);
Deno.exit(1);
process.exit(1);
}
10 changes: 2 additions & 8 deletions src/shim.node.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
// Node-only, see https://github.com/fromdeno/deno2node#shimming
import { test } from "@deno/shim-deno-test";
import { chmod, readFile } from "node:fs/promises";
import process from "node:process";
import * as process from "node:process";
import { isatty } from "node:tty";

const os = process.platform === "win32" ? "windows" : process.platform;

export const Deno = {
// please keep sorted
args: process.argv.slice(2),
build: { os },
chmod,
exit: process.exit,
isatty,
noColor: process.env.NO_COLOR !== undefined,
stdout: { rid: process.stdout.fd },
test,
};

export async function fetch(fileUrl: URL) {
const data = await readFile(fileUrl, { encoding: "utf-8" });
return {
json: () => JSON.parse(data),
text: () => data,
};
return new Response(await readFile(fileUrl));
}

0 comments on commit bd444ad

Please sign in to comment.