@@ -18,7 +18,7 @@ export interface JsValue {
1818// A JS runtime context.
1919export interface JsIsolate {
2020 // Execute `js` within this `JsIsolate`, returning the value.
21- execute ( js : string | ExecutableJs ) : JsValue ;
21+ execute ( js : string | JsScript ) : JsValue ;
2222}
2323
2424// A `JsRuntime` can host several `JsIsolate`s, capable
@@ -48,57 +48,35 @@ export interface TypeDefSource extends Source {
4848 contents : string ;
4949}
5050
51- // A map of filename to typescript source.
52- export interface TsArtifact {
53- entry : string ;
54- files : Source [ ] ;
51+ export interface Compiler < T > {
52+ compile ( input : Program | ProgramResolver , options : T ) : JsScript ;
5553}
5654
57- // A transformed (TypeScript) module.
58- export interface JsModule {
59- // The generated JS from the source TS.
60- contents : string ;
61- // Input source filename.
62- originalFilename : string ;
63- // The generated source map definition.
64- sourceMap : SourceMap ;
65- // The generated .d.ts source.
66- // Not currently generated, but typechecked
67- typesSrc ?: string ;
55+ // A program's entry point with a resolver to
56+ // resolve other sources used in the program.
57+ export interface ProgramResolver {
58+ entry ( ) : Source ;
59+ resolveSource ( identifier : string ) : Source | undefined ;
6860}
6961
70- export const isJsModule = ( value : unknown ) : value is JsModule =>
71- ! ! ( typeof value === "object" && value &&
72- "originalFilename" in value &&
73- typeof value . originalFilename === "string" &&
74- "contents" in value && typeof value . contents === "string" &&
75- "sourceMap" in value && typeof value . sourceMap === "object" &&
76- value . sourceMap &&
77- "typesSrc" in value
78- ? typeof value . typesSrc === "string"
79- : true ) ;
80-
81- // A collection of JS modules with an entry point.
82- export interface JsArtifact {
62+ // An entry point and its sources for a program.
63+ export interface Program {
8364 entry : string ;
84- modules : Record < string , JsModule > ;
65+ files : Source [ ] ;
66+ }
67+
68+ export function isProgram ( value : unknown ) : value is Program {
69+ return ! ! value && typeof value === "object" && "entry" in value &&
70+ typeof value . entry === "string" && "files" in value &&
71+ Array . isArray ( value . files ) ;
8572}
8673
8774// A ready-to-execute string of JavaScript,
8875// with optional metadata.
89- export interface ExecutableJs {
76+ export interface JsScript {
9077 js : string ;
9178 sourceMap ?: SourceMap ;
9279 filename ?: string ;
9380}
9481
9582export interface SourceMap extends RawSourceMap { }
96-
97- export const isSourceMap = ( value : unknown ) : value is SourceMap =>
98- ! ! ( value && typeof value === "object" &&
99- "version" in value && value . version === "3" &&
100- "file" in value && typeof value . file === "string" &&
101- "sourceRoot" in value && typeof value . sourceRoot === "string" &&
102- "sources" in value && Array . isArray ( value . sources ) &&
103- "names" in value && Array . isArray ( value . names ) &&
104- "mappings" in value && typeof value . mappings === "string" ) ;
0 commit comments