Cleanup node_modules, update packages (#1894)

And fix new lint issues.
This commit is contained in:
Kitson Kelly 2019-03-08 00:53:56 +11:00 committed by Ryan Dahl
parent 535037b519
commit 0473d832c1
10 changed files with 140 additions and 73 deletions

38
.yarnclean Normal file
View file

@ -0,0 +1,38 @@
# test directories
__tests__
test
tests
powered-test
# examples
example
examples
# code coverage directories
coverage
.nyc_output
# build scripts
Makefile
Gulpfile.js
Gruntfile.js
# configs
appveyor.yml
circle.yml
codeship-services.yml
codeship-steps.yml
wercker.yml
.tern-project
.gitattributes
.editorconfig
.*ignore
.eslintrc
.jshintrc
.flowconfig
.documentup.json
.yarn-metadata.json
.travis.yml
# misc
*.md

View file

@ -104,7 +104,7 @@ function createIterableString<T>(
} }
function createArrayString( function createArrayString(
value: Array<unknown>, value: unknown[],
ctx: ConsoleContext, ctx: ConsoleContext,
level: number, level: number,
maxLevel: number maxLevel: number
@ -345,7 +345,7 @@ function stringifyWithQuotes(
* @internal * @internal
*/ */
export function stringifyArgs( export function stringifyArgs(
args: Array<unknown>, args: unknown[],
options: ConsoleOptions = {} options: ConsoleOptions = {}
): string { ): string {
const first = args[0]; const first = args[0];
@ -483,7 +483,7 @@ export class Console {
} }
/** Writes the arguments to stdout */ /** Writes the arguments to stdout */
log = (...args: Array<unknown>): void => { log = (...args: unknown[]): void => {
this.printFunc( this.printFunc(
stringifyArgs(args, { stringifyArgs(args, {
indentLevel: this.indentLevel, indentLevel: this.indentLevel,
@ -504,7 +504,7 @@ export class Console {
}; };
/** Writes the arguments to stdout */ /** Writes the arguments to stdout */
warn = (...args: Array<unknown>): void => { warn = (...args: unknown[]): void => {
this.printFunc( this.printFunc(
stringifyArgs(args, { stringifyArgs(args, {
indentLevel: this.indentLevel, indentLevel: this.indentLevel,
@ -522,7 +522,7 @@ export class Console {
* *
* ref: https://console.spec.whatwg.org/#assert * ref: https://console.spec.whatwg.org/#assert
*/ */
assert = (condition = false, ...args: Array<unknown>): void => { assert = (condition = false, ...args: unknown[]): void => {
if (condition) { if (condition) {
return; return;
} }
@ -661,7 +661,7 @@ export class Console {
timerMap.set(label, Date.now()); timerMap.set(label, Date.now());
}; };
timeLog = (label = "default", ...args: Array<unknown>): void => { timeLog = (label = "default", ...args: unknown[]): void => {
label = String(label); label = String(label);
if (!timerMap.has(label)) { if (!timerMap.has(label)) {
@ -690,14 +690,14 @@ export class Console {
this.info(`${label}: ${duration}ms`); this.info(`${label}: ${duration}ms`);
}; };
group = (...label: Array<unknown>): void => { group = (...label: unknown[]): void => {
if (label.length > 0) { if (label.length > 0) {
this.log(...label); this.log(...label);
} }
this.indentLevel += 2; this.indentLevel += 2;
}; };
groupCollapsed = (...label: Array<unknown>): void => { groupCollapsed = (...label: unknown[]): void => {
if (this.collapsedAt == null) { if (this.collapsedAt == null) {
this.collapsedAt = this.indentLevel; this.collapsedAt = this.indentLevel;
} }

View file

@ -1,29 +1,28 @@
{ {
"name": "deno", "name": "deno",
"devDependencies": { "devDependencies": {
"@types/base64-js": "^1.2.5", "@types/base64-js": "1.2.5",
"@types/flatbuffers": "^1.9.0", "@types/flatbuffers": "1.9.1",
"@types/prettier": "=1.15.3", "@types/prettier": "1.16.1",
"@types/text-encoding": "0.0.33", "base64-js": "1.3.0",
"base64-js": "^1.3.0", "flatbuffers": "1.9.0",
"flatbuffers": "^1.9.0", "magic-string": "0.25.2",
"magic-string": "^0.22.5", "prettier": "1.16.4",
"prettier": "=1.15.3", "rollup": "1.4.1",
"rollup": "0.67.0", "rollup-plugin-alias": "1.5.1",
"rollup-plugin-alias": "^1.4.0", "rollup-plugin-analyzer": "3.0.0",
"rollup-plugin-analyzer": "^2.1.0", "rollup-plugin-commonjs": "9.1.3",
"rollup-plugin-commonjs": "^9.1.3", "rollup-plugin-node-globals": "1.4.0",
"rollup-plugin-node-globals": "^1.2.1", "rollup-plugin-node-resolve": "4.0.1",
"rollup-plugin-node-resolve": "^3.3.0", "rollup-plugin-replace": "2.1.0",
"rollup-plugin-replace": "^2.1.0", "rollup-plugin-string": "3.0.0",
"rollup-plugin-string": "^2.0.2", "rollup-plugin-typescript2": "0.19.3",
"rollup-plugin-typescript2": "^0.16.1", "rollup-pluginutils": "2.4.1",
"rollup-pluginutils": "^2.3.0", "ts-morph": "1.3.0",
"ts-node": "^7.0.1", "ts-node": "8.0.2",
"ts-simple-ast": "17.1.0",
"tslint": "^5.10.0", "tslint": "^5.10.0",
"tslint-eslint-rules": "^5.3.1", "tslint-eslint-rules": "^5.3.1",
"tslint-no-circular-imports": "^0.5.0", "tslint-no-circular-imports": "^0.5.0",
"typescript": "3.2.1" "typescript": "3.2.2"
} }
} }

View file

@ -220,10 +220,7 @@ export default function makeConfig(commandOptions) {
resolveGenerated(), resolveGenerated(),
// Allows rollup to resolve modules based on Node.js resolution // Allows rollup to resolve modules based on Node.js resolution
nodeResolve({ nodeResolve(),
jsnext: true,
main: true
}),
// Allows rollup to import CommonJS modules // Allows rollup to import CommonJS modules
commonjs({ commonjs({

@ -1 +1 @@
Subproject commit 7e697531c16ee6713fa3d986447bbd4dc04a80bb Subproject commit 1ba775b7b8e555fdba7753ef91ac064b597dcbaf

View file

@ -18,9 +18,9 @@ The tool depends upon a couple libraries:
- [`ts-node`](https://www.npmjs.com/package/ts-node) to provide just in time - [`ts-node`](https://www.npmjs.com/package/ts-node) to provide just in time
transpiling of TypeScript for the tool itself. transpiling of TypeScript for the tool itself.
- [`ts-simple-ast`](https://www.npmjs.com/package/ts-simple-ast) which provides - [`ts-morph`](https://www.npmjs.com/package/ts-morph) which provides a more
a more rational and functional interface to the TypeScript AST to make rational and functional interface to the TypeScript AST to make manipulations
manipulations easier. easier.
- [`prettier`](https://www.npmjs.com/package/prettier) and - [`prettier`](https://www.npmjs.com/package/prettier) and
[`@types/prettier`](https://www.npmjs.com/package/@types/prettier) to format [`@types/prettier`](https://www.npmjs.com/package/@types/prettier) to format
the output. the output.

View file

@ -15,7 +15,21 @@ import {
TypeGuards, TypeGuards,
VariableStatement, VariableStatement,
VariableDeclarationKind VariableDeclarationKind
} from "ts-simple-ast"; } from "ts-morph";
let silent = false;
/** Logs a message to the console. */
export function log(message: any = "", ...args: any[]) {
if (!silent) {
console.log(message, ...args);
}
}
/** Sets the silent flag which impacts logging to the console. */
export function setSilent(value = false): void {
silent = value;
}
/** Add a property to an interface */ /** Add a property to an interface */
export function addInterfaceProperty( export function addInterfaceProperty(
@ -169,8 +183,12 @@ export function flattenNamespace({
} }
sourceFiles.add(currentSourceFile); sourceFiles.add(currentSourceFile);
const currentSourceFilePath = currentSourceFile.getFilePath(); const currentSourceFilePath = currentSourceFile
.getFilePath()
.replace(/(\.d)?\.ts$/, "");
log("Process source file:", currentSourceFilePath);
if (customSources && currentSourceFilePath in customSources) { if (customSources && currentSourceFilePath in customSources) {
log(" Using custom source.");
output += customSources[currentSourceFilePath]; output += customSources[currentSourceFilePath];
return; return;
} }

View file

@ -1,4 +1,5 @@
import { writeFileSync } from "fs"; import { writeFileSync } from "fs";
import { join } from "path";
import * as prettier from "prettier"; import * as prettier from "prettier";
import { import {
ExpressionStatement, ExpressionStatement,
@ -8,10 +9,11 @@ import {
ts, ts,
Type, Type,
TypeGuards TypeGuards
} from "ts-simple-ast"; } from "ts-morph";
import { import {
addInterfaceProperty, addInterfaceProperty,
addSourceComment, addSourceComment,
addTypeAlias,
addVariableDeclaration, addVariableDeclaration,
checkDiagnostics, checkDiagnostics,
flattenNamespace, flattenNamespace,
@ -19,10 +21,11 @@ import {
inlineFiles, inlineFiles,
loadDtsFiles, loadDtsFiles,
loadFiles, loadFiles,
log,
logDiagnostics, logDiagnostics,
namespaceSourceFile, namespaceSourceFile,
normalizeSlashes, normalizeSlashes,
addTypeAlias setSilent
} from "./ast_util"; } from "./ast_util";
export interface BuildLibraryOptions { export interface BuildLibraryOptions {
@ -47,6 +50,10 @@ export interface BuildLibraryOptions {
*/ */
inline?: string[]; 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 * The path to the output library
*/ */
@ -320,26 +327,32 @@ export function main({
basePath, basePath,
buildPath, buildPath,
inline, inline,
inputs,
debug, debug,
outFile, outFile,
silent silent
}: BuildLibraryOptions): void { }: BuildLibraryOptions): void {
if (!silent) { setSilent(silent);
console.log("-----"); log("-----");
console.log("build_lib"); log("build_lib");
console.log(); log();
console.log(`basePath: "${basePath}"`); log(`basePath: "${basePath}"`);
console.log(`buildPath: "${buildPath}"`); log(`buildPath: "${buildPath}"`);
if (inline && inline.length) { if (inline && inline.length) {
console.log(`inline:`); log("inline:");
for (const filename of inline) { for (const filename of inline) {
console.log(` "${filename}"`); log(` "${filename}"`);
}
} }
console.log(`debug: ${!!debug}`);
console.log(`outFile: "${outFile}"`);
console.log();
} }
if (inputs && inputs.length) {
log("inputs:");
for (const input of inputs) {
log(` "${input}"`);
}
}
log(`debug: ${!!debug}`);
log(`outFile: "${outFile}"`);
log();
// the inputProject will take in the TypeScript files that are internal // the inputProject will take in the TypeScript files that are internal
// to Deno to be used to generate the library // to Deno to be used to generate the library
@ -348,10 +361,9 @@ export function main({
baseUrl: basePath, baseUrl: basePath,
declaration: true, declaration: true,
emitDeclarationOnly: true, emitDeclarationOnly: true,
lib: [], module: ModuleKind.ESNext,
module: ModuleKind.AMD,
moduleResolution: ModuleResolutionKind.NodeJs, moduleResolution: ModuleResolutionKind.NodeJs,
noLib: true, // noLib: true,
paths: { paths: {
"*": ["*", `${buildPath}/*`] "*": ["*", `${buildPath}/*`]
}, },
@ -365,20 +377,23 @@ export function main({
// Add the input files we will need to generate the declarations, `globals` // 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 any modules that are importable in the runtime need to be added here
// plus the `lib.esnext` which is used as the base library // plus the `lib.esnext` which is used as the base library
inputProject.addExistingSourceFiles([ if (inputs) {
`${basePath}/node_modules/typescript/lib/lib.esnext.d.ts`, inputProject.addExistingSourceFiles(
`${basePath}/js/deno.ts`, inputs.map(input => join(basePath, input))
`${basePath}/js/globals.ts` );
]); }
// emit the project, which will be only the declaration files // emit the project, which will be only the declaration files
const inputEmitResult = inputProject.emitToMemory(); const inputEmitResult = inputProject.emitToMemory();
log("Emitted input project.");
const inputDiagnostics = inputEmitResult const inputDiagnostics = inputEmitResult
.getDiagnostics() .getDiagnostics()
.map(d => d.compilerObject); .map(d => d.compilerObject);
logDiagnostics(inputDiagnostics); logDiagnostics(inputDiagnostics);
if (inputDiagnostics.length) { if (inputDiagnostics.length) {
console.error("\nDiagnostics present during input project emit.\n");
process.exit(1); process.exit(1);
} }
@ -419,7 +434,6 @@ export function main({
compilerOptions: { compilerOptions: {
baseUrl: buildPath, baseUrl: buildPath,
moduleResolution: ModuleResolutionKind.NodeJs, moduleResolution: ModuleResolutionKind.NodeJs,
noLib: true,
strict: true, strict: true,
target: ScriptTarget.ESNext target: ScriptTarget.ESNext
}, },
@ -445,7 +459,7 @@ export function main({
// Generate a object hash of substitutions of modules to use when flattening // Generate a object hash of substitutions of modules to use when flattening
const customSources = { const customSources = {
[msgGeneratedDts.getFilePath()]: `${ [msgGeneratedDts.getFilePath().replace(/(\.d)?\.ts$/, "")]: `${
debug ? getSourceComment(msgGeneratedDts, basePath) : "" debug ? getSourceComment(msgGeneratedDts, basePath) : ""
}${msgGeneratedDtsText}\n` }${msgGeneratedDtsText}\n`
}; };
@ -462,9 +476,7 @@ export function main({
targetSourceFile: libDTs targetSourceFile: libDTs
}); });
if (!silent) { log(`Merged "globals" into global scope.`);
console.log(`Merged "globals" into global scope.`);
}
flatten({ flatten({
basePath, basePath,
@ -478,9 +490,7 @@ export function main({
targetSourceFile: libDTs targetSourceFile: libDTs
}); });
if (!silent) { log(`Created module "deno" and namespace Deno.`);
console.log(`Created module "deno" and namespace Deno.`);
}
// Inline any files that were passed in, to be used to add additional libs // Inline any files that were passed in, to be used to add additional libs
// which are not part of TypeScript. // which are not part of TypeScript.

View file

@ -42,6 +42,11 @@ buildRuntimeLib({
buildPath, buildPath,
debug, debug,
inline, inline,
inputs: [
"node_modules/typescript/lib/lib.esnext.d.ts",
"js/deno.ts",
"js/globals.ts"
],
outFile, outFile,
silent silent
}); });

View file

@ -4,7 +4,7 @@
// ./node_modules/.bin/ts-node --project tools/ts_library_builder/tsconfig.json tools/ts_library_builder/test.ts // ./node_modules/.bin/ts-node --project tools/ts_library_builder/tsconfig.json tools/ts_library_builder/test.ts
import * as assert from "assert"; import * as assert from "assert";
import { Project, ts } from "ts-simple-ast"; import { Project, ts } from "ts-morph";
import { flatten, mergeGlobal } from "./build_library"; import { flatten, mergeGlobal } from "./build_library";
import { inlineFiles, loadDtsFiles } from "./ast_util"; import { inlineFiles, loadDtsFiles } from "./ast_util";
@ -20,7 +20,7 @@ function setupFixtures() {
baseUrl: basePath, baseUrl: basePath,
declaration: true, declaration: true,
emitDeclarationOnly: true, emitDeclarationOnly: true,
module: ModuleKind.AMD, module: ModuleKind.ESNext,
moduleResolution: ModuleResolutionKind.NodeJs, moduleResolution: ModuleResolutionKind.NodeJs,
strict: true, strict: true,
stripInternal: true, stripInternal: true,