summaryrefslogtreecommitdiff
path: root/tools/ts_library_builder/build_library.ts
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2019-03-08 00:53:56 +1100
committerRyan Dahl <ry@tinyclouds.org>2019-03-07 08:53:56 -0500
commit0473d832c138a7acc25372441cfa01848e6b9915 (patch)
tree94c920433911fd05772fc85cd1efb06d3da894d0 /tools/ts_library_builder/build_library.ts
parent535037b519711d238dc0bfa2c4d2ffb4b17dec53 (diff)
Cleanup node_modules, update packages (#1894)
And fix new lint issues.
Diffstat (limited to 'tools/ts_library_builder/build_library.ts')
-rw-r--r--tools/ts_library_builder/build_library.ts74
1 files changed, 42 insertions, 32 deletions
diff --git a/tools/ts_library_builder/build_library.ts b/tools/ts_library_builder/build_library.ts
index 98a51f63f..abfb430d1 100644
--- a/tools/ts_library_builder/build_library.ts
+++ b/tools/ts_library_builder/build_library.ts
@@ -1,4 +1,5 @@
import { writeFileSync } from "fs";
+import { join } from "path";
import * as prettier from "prettier";
import {
ExpressionStatement,
@@ -8,10 +9,11 @@ import {
ts,
Type,
TypeGuards
-} from "ts-simple-ast";
+} from "ts-morph";
import {
addInterfaceProperty,
addSourceComment,
+ addTypeAlias,
addVariableDeclaration,
checkDiagnostics,
flattenNamespace,
@@ -19,10 +21,11 @@ import {
inlineFiles,
loadDtsFiles,
loadFiles,
+ log,
logDiagnostics,
namespaceSourceFile,
normalizeSlashes,
- addTypeAlias
+ setSilent
} from "./ast_util";
export interface BuildLibraryOptions {
@@ -47,6 +50,10 @@ export interface BuildLibraryOptions {
*/
inline?: string[];
+ /** An array of input files to be provided to the input project, relative to
+ * the basePath. */
+ inputs?: string[];
+
/**
* The path to the output library
*/
@@ -320,26 +327,32 @@ export function main({
basePath,
buildPath,
inline,
+ inputs,
debug,
outFile,
silent
}: BuildLibraryOptions): void {
- if (!silent) {
- console.log("-----");
- console.log("build_lib");
- console.log();
- console.log(`basePath: "${basePath}"`);
- console.log(`buildPath: "${buildPath}"`);
- if (inline && inline.length) {
- console.log(`inline:`);
- for (const filename of inline) {
- console.log(` "${filename}"`);
- }
+ setSilent(silent);
+ log("-----");
+ log("build_lib");
+ log();
+ log(`basePath: "${basePath}"`);
+ log(`buildPath: "${buildPath}"`);
+ if (inline && inline.length) {
+ log("inline:");
+ for (const filename of inline) {
+ log(` "${filename}"`);
+ }
+ }
+ if (inputs && inputs.length) {
+ log("inputs:");
+ for (const input of inputs) {
+ log(` "${input}"`);
}
- console.log(`debug: ${!!debug}`);
- console.log(`outFile: "${outFile}"`);
- console.log();
}
+ log(`debug: ${!!debug}`);
+ log(`outFile: "${outFile}"`);
+ log();
// the inputProject will take in the TypeScript files that are internal
// to Deno to be used to generate the library
@@ -348,10 +361,9 @@ export function main({
baseUrl: basePath,
declaration: true,
emitDeclarationOnly: true,
- lib: [],
- module: ModuleKind.AMD,
+ module: ModuleKind.ESNext,
moduleResolution: ModuleResolutionKind.NodeJs,
- noLib: true,
+ // noLib: true,
paths: {
"*": ["*", `${buildPath}/*`]
},
@@ -365,20 +377,23 @@ export function main({
// Add the input files we will need to generate the declarations, `globals`
// plus any modules that are importable in the runtime need to be added here
// plus the `lib.esnext` which is used as the base library
- inputProject.addExistingSourceFiles([
- `${basePath}/node_modules/typescript/lib/lib.esnext.d.ts`,
- `${basePath}/js/deno.ts`,
- `${basePath}/js/globals.ts`
- ]);
+ if (inputs) {
+ inputProject.addExistingSourceFiles(
+ inputs.map(input => join(basePath, input))
+ );
+ }
// emit the project, which will be only the declaration files
const inputEmitResult = inputProject.emitToMemory();
+ log("Emitted input project.");
+
const inputDiagnostics = inputEmitResult
.getDiagnostics()
.map(d => d.compilerObject);
logDiagnostics(inputDiagnostics);
if (inputDiagnostics.length) {
+ console.error("\nDiagnostics present during input project emit.\n");
process.exit(1);
}
@@ -419,7 +434,6 @@ export function main({
compilerOptions: {
baseUrl: buildPath,
moduleResolution: ModuleResolutionKind.NodeJs,
- noLib: true,
strict: true,
target: ScriptTarget.ESNext
},
@@ -445,7 +459,7 @@ export function main({
// Generate a object hash of substitutions of modules to use when flattening
const customSources = {
- [msgGeneratedDts.getFilePath()]: `${
+ [msgGeneratedDts.getFilePath().replace(/(\.d)?\.ts$/, "")]: `${
debug ? getSourceComment(msgGeneratedDts, basePath) : ""
}${msgGeneratedDtsText}\n`
};
@@ -462,9 +476,7 @@ export function main({
targetSourceFile: libDTs
});
- if (!silent) {
- console.log(`Merged "globals" into global scope.`);
- }
+ log(`Merged "globals" into global scope.`);
flatten({
basePath,
@@ -478,9 +490,7 @@ export function main({
targetSourceFile: libDTs
});
- if (!silent) {
- console.log(`Created module "deno" and namespace Deno.`);
- }
+ log(`Created module "deno" and namespace Deno.`);
// Inline any files that were passed in, to be used to add additional libs
// which are not part of TypeScript.