mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 23:34:47 -05:00
6bd846a780
Moves to using a minimal System loader for bundles generated by Deno. TypeScript in 3.8 will be able to output TLA for modules, and the loader is written to take advantage of that as soon as we update Deno to TS 3.8. System also allows us to support `import.meta` and provide more ESM aligned assignment of exports, as well as there is better handling of circular imports. The loader is also very terse versus to try to save overhead. Also, fixed an issue where abstract classes were not being re-exported. Fixes #2553 Fixes #3559 Fixes #3751 Fixes #3825 Refs #3301
58 lines
2.1 KiB
TypeScript
58 lines
2.1 KiB
TypeScript
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
import { ASSETS, CompilerHostTarget, Host } from "./compiler_host.ts";
|
|
import { getAsset } from "./compiler_util.ts";
|
|
|
|
// NOTE: target doesn't really matter here,
|
|
// this is in fact a mock host created just to
|
|
// load all type definitions and snapshot them.
|
|
const host = new Host({
|
|
target: CompilerHostTarget.Main,
|
|
writeFile(): void {}
|
|
});
|
|
const options = host.getCompilationSettings();
|
|
|
|
// 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
|
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
(ts as any).libs.push(
|
|
"deno_ns",
|
|
"deno_window",
|
|
"deno_worker",
|
|
"deno_shared_globals"
|
|
);
|
|
(ts as any).libMap.set("deno_ns", "lib.deno.ns.d.ts");
|
|
(ts as any).libMap.set("deno_window", "lib.deno.window.d.ts");
|
|
(ts as any).libMap.set("deno_worker", "lib.deno.worker.d.ts");
|
|
(ts as any).libMap.set("deno_shared_globals", "lib.deno.shared_globals.d.ts");
|
|
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
|
|
// this pre-populates the cache at snapshot time of our library files, so they
|
|
// are available in the future when needed.
|
|
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
|
|
);
|
|
|
|
/**
|
|
* This function spins up TS compiler and loads all available libraries
|
|
* into memory (including ones specified above).
|
|
*
|
|
* Used to generate the foundational AST for all other compilations, so it can
|
|
* be cached as part of the snapshot and available to speed up startup.
|
|
*/
|
|
export const TS_SNAPSHOT_PROGRAM = ts.createProgram({
|
|
rootNames: [`${ASSETS}/bootstrap.ts`],
|
|
options,
|
|
host
|
|
});
|
|
|
|
/** A module loader which is concatenated into bundle files.
|
|
*
|
|
* We read all static assets during the snapshotting process, which is
|
|
* why this is located in compiler_bootstrap.
|
|
*/
|
|
export const SYSTEM_LOADER = getAsset("system_loader.js");
|