2020-01-22 14:18:01 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
2020-03-11 05:53:06 -04:00
|
|
|
import { CompilerHostTarget, Host } from "./host.ts";
|
|
|
|
import { ASSETS } from "./sourcefile.ts";
|
|
|
|
import { getAsset } from "./util.ts";
|
2020-01-22 14:18:01 -05:00
|
|
|
|
2020-01-27 21:12:25 -05:00
|
|
|
// NOTE: target doesn't really matter here,
|
|
|
|
// this is in fact a mock host created just to
|
|
|
|
// load all type definitions and snapshot them.
|
2020-01-24 14:15:01 -05:00
|
|
|
const host = new Host({
|
|
|
|
target: CompilerHostTarget.Main,
|
2020-03-28 13:03:49 -04:00
|
|
|
writeFile(): void {},
|
2020-01-24 14:15:01 -05:00
|
|
|
});
|
2020-01-22 14:18:01 -05:00
|
|
|
const options = host.getCompilationSettings();
|
|
|
|
|
2020-01-24 14:15:01 -05:00
|
|
|
// This is a hacky way of adding our libs to the libs available in TypeScript()
|
|
|
|
// as these are internal APIs of TypeScript which maintain valid libs
|
2020-02-19 00:34:11 -05:00
|
|
|
ts.libs.push("deno.ns", "deno.window", "deno.worker", "deno.shared_globals");
|
|
|
|
ts.libMap.set("deno.ns", "lib.deno.ns.d.ts");
|
|
|
|
ts.libMap.set("deno.window", "lib.deno.window.d.ts");
|
|
|
|
ts.libMap.set("deno.worker", "lib.deno.worker.d.ts");
|
|
|
|
ts.libMap.set("deno.shared_globals", "lib.deno.shared_globals.d.ts");
|
2020-01-24 14:15:01 -05:00
|
|
|
|
|
|
|
// this pre-populates the cache at snapshot time of our library files, so they
|
|
|
|
// are available in the future when needed.
|
2020-01-29 12:54:23 -05:00
|
|
|
host.getSourceFile(`${ASSETS}/lib.deno.ns.d.ts`, ts.ScriptTarget.ESNext);
|
|
|
|
host.getSourceFile(`${ASSETS}/lib.deno.window.d.ts`, ts.ScriptTarget.ESNext);
|
|
|
|
host.getSourceFile(`${ASSETS}/lib.deno.worker.d.ts`, ts.ScriptTarget.ESNext);
|
|
|
|
host.getSourceFile(
|
|
|
|
`${ASSETS}/lib.deno.shared_globals.d.ts`,
|
|
|
|
ts.ScriptTarget.ESNext
|
|
|
|
);
|
2020-01-24 14:15:01 -05:00
|
|
|
|
2020-01-27 21:12:25 -05:00
|
|
|
export const TS_SNAPSHOT_PROGRAM = ts.createProgram({
|
2020-01-22 14:18:01 -05:00
|
|
|
rootNames: [`${ASSETS}/bootstrap.ts`],
|
|
|
|
options,
|
2020-03-28 13:03:49 -04:00
|
|
|
host,
|
2020-01-22 14:18:01 -05:00
|
|
|
});
|
|
|
|
|
2020-02-12 16:41:51 -05:00
|
|
|
export const SYSTEM_LOADER = getAsset("system_loader.js");
|