Files
scriptc/packages/compiler/src/frontend/program-node.ts
T
Chris Tate c08ab955ae Enforce linting and consistent source formatting
- Enforce oxlint and oxfmt for owned JavaScript and TypeScript with independent CI checks.
- Preserve compiler import boundaries and protected fixtures while cleaning up lint findings.
- Standardize source formatting and validate import, fixture, and embedded-source protections.
2026-10-05 17:51:24 -05:00

63 lines
1.8 KiB
TypeScript

/** Node convenience entry. Native callers supply FrontendServices to
* program.ts directly; each Node load owns all of its parser connections. */
import { dirname, resolve } from "node:path";
import {
loadProgram as loadWithServices,
checkPreflightTs7 as preflightWithHost,
} from "./program.js";
import { createNodeFrontendServices } from "./services-node.js";
import type { Ts7Host } from "./ts7/program-host.js";
export * from "./program.js";
export interface NodeProgramLoadOptions {
npmStatic?: Iterable<string>;
externalTypes?: ReadonlyMap<string, string> | Readonly<Record<string, string>> | undefined;
}
export function loadProgram(
entryPath: string,
options?: NodeProgramLoadOptions,
): ReturnType<typeof loadWithServices> {
const services = createNodeFrontendServices();
try {
const load = loadWithServices(entryPath, services, {
npmStatic: [...(options?.npmStatic ?? [])],
externalTypes:
options?.externalTypes instanceof Map
? [...options.externalTypes]
: Object.entries(options?.externalTypes ?? {}),
});
return {
...load,
dispose: () => {
try {
load.dispose();
} finally {
services.close();
}
},
};
} catch (error) {
services.close();
throw error;
}
}
export function checkPreflightTs7(
entryPath: string,
sharedHost?: Ts7Host,
): ReturnType<typeof preflightWithHost> {
if (sharedHost !== undefined) return preflightWithHost(entryPath, sharedHost);
const services = createNodeFrontendServices();
try {
const host = services.createProgramHost({ cwd: dirname(resolve(entryPath)) });
try {
return preflightWithHost(entryPath, host);
} finally {
host.close();
}
} finally {
services.close();
}
}