Skip to content

Commit

Permalink
chore: run fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Gammon <[email protected]>
  • Loading branch information
sgammon committed Apr 26, 2024
1 parent 9ac2965 commit c6bfd2f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 42 deletions.
10 changes: 5 additions & 5 deletions tools/tsc/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@

import esbuild from "esbuild";

export const mode = 'esm'
export const mode = "esm";

async function buildTypescriptEntrypoint() {
await esbuild.build({
entryPoints: ["src/main/js/entry.mjs"],
outfile: `src/main/resources/META-INF/elide/embedded/tools/tsc/entry.${mode === 'esm' ? 'mjs' : 'cjs'}`,
outfile: `src/main/resources/META-INF/elide/embedded/tools/tsc/entry.${mode === "esm" ? "mjs" : "cjs"}`,
format: mode,
bundle: true,
platform: "neutral",
external: ["fs", "node:fs", "path", "node:path", "os", "node:os", "inspector", "node:inspector"],
mainFields: ["module", "main"]
})
mainFields: ["module", "main"],
});

console.info("TypeScript entrypoint build complete.")
console.info("TypeScript entrypoint build complete.");
}

console.info("Building TypeScript entrypoint...");
Expand Down
68 changes: 31 additions & 37 deletions tools/tsc/src/main/js/entry.mjs
Original file line number Diff line number Diff line change
@@ -1,45 +1,41 @@
import * as tsvfs from "@typescript/vfs"
import ts from "typescript"
import { readFileSync } from "fs"
import { join } from "path"
import * as tsvfs from "@typescript/vfs";
import ts from "typescript";
import { readFileSync } from "fs";
import { join } from "path";

const getLib = (name) => {
const lib = dirname(require.resolve("typescript"))
return readFileSync(join(lib, name), "utf8")
}
const lib = dirname(require.resolve("typescript"));
return readFileSync(join(lib, name), "utf8");
};

const addLib = (name, map) => {
map.set("/" + name, getLib(name))
}
map.set("/" + name, getLib(name));
};

const createDefaultMap2015 = () => {
const fsMap = new Map()
addLib("lib.es2015.d.ts", fsMap)
addLib("lib.es2015.collection.d.ts", fsMap)
addLib("lib.es2015.core.d.ts", fsMap)
addLib("lib.es2015.generator.d.ts", fsMap)
addLib("lib.es2015.iterable.d.ts", fsMap)
addLib("lib.es2015.promise.d.ts", fsMap)
addLib("lib.es2015.proxy.d.ts", fsMap)
addLib("lib.es2015.reflect.d.ts", fsMap)
addLib("lib.es2015.symbol.d.ts", fsMap)
addLib("lib.es2015.symbol.wellknown.d.ts", fsMap)
addLib("lib.es5.d.ts", fsMap)
return fsMap
}
const fsMap = new Map();
addLib("lib.es2015.d.ts", fsMap);
addLib("lib.es2015.collection.d.ts", fsMap);
addLib("lib.es2015.core.d.ts", fsMap);
addLib("lib.es2015.generator.d.ts", fsMap);
addLib("lib.es2015.iterable.d.ts", fsMap);
addLib("lib.es2015.promise.d.ts", fsMap);
addLib("lib.es2015.proxy.d.ts", fsMap);
addLib("lib.es2015.reflect.d.ts", fsMap);
addLib("lib.es2015.symbol.d.ts", fsMap);
addLib("lib.es2015.symbol.wellknown.d.ts", fsMap);
addLib("lib.es5.d.ts", fsMap);
return fsMap;
};

function compile(fsMap, compilerOptions) {
const baseMap = createDefaultMap2015()
const baseMap = createDefaultMap2015();
fsMap.keys.forEach((key) => {
baseMap.set(key, fsMap.get(key))
baseMap.set(key, fsMap.get(key));
});

const system = tsvfs.createSystem(fsMap)
const host = tsvfs.createVirtualCompilerHost(
system,
compilerOptions,
ts,
)
const system = tsvfs.createSystem(fsMap);
const host = tsvfs.createVirtualCompilerHost(system, compilerOptions, ts);

const program = ts.createProgram({
rootNames: [...fsMap.keys()],
Expand All @@ -49,11 +45,9 @@ function compile(fsMap, compilerOptions) {

const emitResult = program.emit();

const allDiagnostics = ts
.getPreEmitDiagnostics(program)
.concat(emitResult.diagnostics);
const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);

allDiagnostics.forEach(diagnostic => {
allDiagnostics.forEach((diagnostic) => {
if (diagnostic.file) {
let { line, character } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
Expand All @@ -69,10 +63,10 @@ function compile(fsMap, compilerOptions) {
}

export default function entry(args) {
console.log("Running `tsc`...", JSON.stringify({args: args[0]}));
console.log("Running `tsc`...", JSON.stringify({ args: args[0] }));
const fsMap = new Map();
const exitCode = compile(args[0], {});
console.log("Result of `tsc`:", {exitCode});
console.log("Result of `tsc`:", { exitCode });
return exitCode;
}

Expand Down

0 comments on commit c6bfd2f

Please sign in to comment.