From bc22ff1517c06b7b5ba96d8a1cc9cb7acfa3a73e Mon Sep 17 00:00:00 2001 From: Chuck Jazdzewski Date: Tue, 15 Aug 2017 17:04:45 -0700 Subject: [PATCH] fix(language-service): remove tsickle dependency Removes the tsickle dependency added when tsickle was added to the transform compiler. Added a test to ensure stray dependencies are not added and no errors are introduced during module flattening. --- .../language_service_plugin/scripts/test.sh | 5 +++ .../tools/load_test.ts | 35 +++++++++++++++++++ .../tools/tsconfig.json | 3 +- .../compiler-cli/src/language_services.ts | 24 +++++++++++++ packages/compiler-cli/tsconfig-build.json | 1 + packages/language-service/src/completions.ts | 2 +- packages/language-service/src/diagnostics.ts | 2 +- packages/language-service/src/expressions.ts | 2 +- .../language-service/src/locate_symbol.ts | 2 +- .../language-service/src/reflector_host.ts | 3 +- packages/language-service/src/types.ts | 2 +- .../language-service/src/typescript_host.ts | 2 +- packages/language-service/src/utils.ts | 2 +- packages/language-service/tsconfig-build.json | 1 + 14 files changed, 77 insertions(+), 9 deletions(-) create mode 100644 integration/language_service_plugin/tools/load_test.ts create mode 100644 packages/compiler-cli/src/language_services.ts diff --git a/integration/language_service_plugin/scripts/test.sh b/integration/language_service_plugin/scripts/test.sh index 29f5d34be2..0721da0c45 100755 --- a/integration/language_service_plugin/scripts/test.sh +++ b/integration/language_service_plugin/scripts/test.sh @@ -9,6 +9,11 @@ source scripts/env.sh HOST="node tools/typescript_host.js" VALIDATE="node tools/typescript_validator.js" +# Ensure the languages service can load correctly in node before typescript loads it. +# This verifies its dependencies and emits any exceptions, both of which are only +# emitted to the typescript logs (not the validated output). +node tools/load_test.js + for TYPESCRIPT in ${TYPESCRIPTS[@]} do SERVER="node typescripts/$TYPESCRIPT/node_modules/typescript/lib/tsserver.js" diff --git a/integration/language_service_plugin/tools/load_test.ts b/integration/language_service_plugin/tools/load_test.ts new file mode 100644 index 0000000000..96638d81d2 --- /dev/null +++ b/integration/language_service_plugin/tools/load_test.ts @@ -0,0 +1,35 @@ +const ts = require('typescript'); +const Module = require('module'); + +const existingRequire = Module.prototype.require; + +const recordedRequires: string[] = []; + +function recordingRequire(path: string) { + recordedRequires.push(path); + return existingRequire.call(this, path); +} + +Module.prototype.require = recordingRequire; + +try { + const lsf = require('@angular/language-service'); + const ls = lsf({typescript: ts}); + + // Assert that the only module that should have been required are '@angular/langauge-service', 'fs', and 'path' + + const allowedLoads = new Set(["@angular/language-service", "fs", "path"]); + + const invalidModules = recordedRequires.filter(m => !allowedLoads.has(m)); + + if (invalidModules.length > 0) { + console.error(`FAILED: Loading the language service required: ${invalidModules.join(', ')}`); + process.exit(1); + } +} catch (e) { + console.error(`FAILED: Loading the language service caused the following exception: ${e.stack || e}`); + process.exit(1); +} + +console.log('SUCCESS: Loading passed') +process.exit(0); \ No newline at end of file diff --git a/integration/language_service_plugin/tools/tsconfig.json b/integration/language_service_plugin/tools/tsconfig.json index c576365a6e..fd844f194c 100644 --- a/integration/language_service_plugin/tools/tsconfig.json +++ b/integration/language_service_plugin/tools/tsconfig.json @@ -13,6 +13,7 @@ }, "files": [ "typescript_host.ts", - "typescript_validator.ts" + "typescript_validator.ts", + "load_test.ts" ] } \ No newline at end of file diff --git a/packages/compiler-cli/src/language_services.ts b/packages/compiler-cli/src/language_services.ts new file mode 100644 index 0000000000..34fd77fd23 --- /dev/null +++ b/packages/compiler-cli/src/language_services.ts @@ -0,0 +1,24 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +/* + +The API from compiler-cli that language-service can see. +It is important that none the exported modules require anything other than +Angular modules and Typescript as this will indirectly add a dependency +to the language service. + +*/ + +export {AngularCompilerOptions} from '@angular/tsc-wrapped'; +export {CompilerHost, CompilerHostContext, MetadataProvider, ModuleResolutionHostAdapter, NodeCompilerHostContext} from './compiler_host'; +export {TypeChecker} from './diagnostics/check_types'; +export {DiagnosticTemplateInfo, ExpressionDiagnostic, getExpressionDiagnostics, getExpressionScope, getTemplateExpressionDiagnostics} from './diagnostics/expression_diagnostics'; +export {AstType, DiagnosticKind, ExpressionDiagnosticsContext, TypeDiagnostic} from './diagnostics/expression_type'; +export {BuiltinType, DeclarationKind, Definition, Location, PipeInfo, Pipes, Signature, Span, Symbol, SymbolDeclaration, SymbolQuery, SymbolTable} from './diagnostics/symbols'; +export {getClassFromStaticSymbol, getClassMembers, getClassMembersFromDeclaration, getPipesTable, getSymbolQuery} from './diagnostics/typescript_symbols'; diff --git a/packages/compiler-cli/tsconfig-build.json b/packages/compiler-cli/tsconfig-build.json index 3f1d3a822c..2bbb80d3e1 100644 --- a/packages/compiler-cli/tsconfig-build.json +++ b/packages/compiler-cli/tsconfig-build.json @@ -33,6 +33,7 @@ "index.ts", "src/main.ts", "src/extract_i18n.ts", + "src/language_services.ts", "../../node_modules/@types/node/index.d.ts", "../../node_modules/@types/jasmine/index.d.ts", "../../node_modules/zone.js/dist/zone.js.d.ts" diff --git a/packages/language-service/src/completions.ts b/packages/language-service/src/completions.ts index ab78fbce8c..3412abffef 100644 --- a/packages/language-service/src/completions.ts +++ b/packages/language-service/src/completions.ts @@ -7,7 +7,7 @@ */ import {AST, AstPath, AttrAst, Attribute, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventAst, BoundTextAst, CssSelector, DirectiveAst, Element, ElementAst, EmbeddedTemplateAst, ImplicitReceiver, NAMED_ENTITIES, NgContentAst, Node as HtmlAst, NullTemplateVisitor, ParseSpan, PropertyRead, ReferenceAst, SelectorMatcher, TagContentType, TemplateAst, TemplateAstVisitor, Text, TextAst, VariableAst, findNode, getHtmlTagDefinition, splitNsName, templateVisitAll} from '@angular/compiler'; -import {DiagnosticTemplateInfo, getExpressionScope} from '@angular/compiler-cli'; +import {DiagnosticTemplateInfo, getExpressionScope} from '@angular/compiler-cli/src/language_services'; import {AstResult, AttrInfo, SelectorInfo, TemplateInfo} from './common'; import {getExpressionCompletions} from './expressions'; diff --git a/packages/language-service/src/diagnostics.ts b/packages/language-service/src/diagnostics.ts index 83a37efef3..23ec4316bf 100644 --- a/packages/language-service/src/diagnostics.ts +++ b/packages/language-service/src/diagnostics.ts @@ -7,7 +7,7 @@ */ import {NgAnalyzedModules, StaticSymbol} from '@angular/compiler'; -import {DiagnosticTemplateInfo, getTemplateExpressionDiagnostics} from '@angular/compiler-cli'; +import {DiagnosticTemplateInfo, getTemplateExpressionDiagnostics} from '@angular/compiler-cli/src/language_services'; import {AstResult} from './common'; import {Declarations, Diagnostic, DiagnosticKind, Diagnostics, Span, TemplateSource} from './types'; diff --git a/packages/language-service/src/expressions.ts b/packages/language-service/src/expressions.ts index 9af51ec457..95b0018c81 100644 --- a/packages/language-service/src/expressions.ts +++ b/packages/language-service/src/expressions.ts @@ -7,7 +7,7 @@ */ import {AST, ASTWithSource, AstPath as AstPathBase, NullAstVisitor, visitAstChildren} from '@angular/compiler'; -import {AstType} from '@angular/compiler-cli'; +import {AstType} from '@angular/compiler-cli/src/language_services'; import {BuiltinType, Span, Symbol, SymbolQuery, SymbolTable} from './types'; import {inSpan} from './utils'; diff --git a/packages/language-service/src/locate_symbol.ts b/packages/language-service/src/locate_symbol.ts index 9dd47837bf..42dce460a4 100644 --- a/packages/language-service/src/locate_symbol.ts +++ b/packages/language-service/src/locate_symbol.ts @@ -7,7 +7,7 @@ */ import {AST, Attribute, BoundDirectivePropertyAst, BoundEventAst, ElementAst, TemplateAst, TemplateAstPath, findNode, tokenReference} from '@angular/compiler'; -import {getExpressionScope} from '@angular/compiler-cli'; +import {getExpressionScope} from '@angular/compiler-cli/src/language_services'; import {TemplateInfo} from './common'; import {getExpressionSymbol} from './expressions'; diff --git a/packages/language-service/src/reflector_host.ts b/packages/language-service/src/reflector_host.ts index 9a84fb1e37..f9439f1c51 100644 --- a/packages/language-service/src/reflector_host.ts +++ b/packages/language-service/src/reflector_host.ts @@ -6,7 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ -import {AngularCompilerOptions, AotCompilerHost, CompilerHost, ModuleResolutionHostAdapter} from '@angular/compiler-cli'; +import {AotCompilerHost} from '@angular/compiler'; +import {AngularCompilerOptions, CompilerHost, ModuleResolutionHostAdapter} from '@angular/compiler-cli/src/language_services'; import * as ts from 'typescript'; class ReflectorModuleModuleResolutionHost implements ts.ModuleResolutionHost { diff --git a/packages/language-service/src/types.ts b/packages/language-service/src/types.ts index 884cf5b02e..8ea1a5c535 100644 --- a/packages/language-service/src/types.ts +++ b/packages/language-service/src/types.ts @@ -7,7 +7,7 @@ */ import {CompileDirectiveMetadata, CompileMetadataResolver, CompilePipeSummary, NgAnalyzedModules, StaticSymbol} from '@angular/compiler'; -import {BuiltinType, DeclarationKind, Definition, PipeInfo, Pipes, Signature, Span, Symbol, SymbolDeclaration, SymbolQuery, SymbolTable} from '@angular/compiler-cli'; +import {BuiltinType, DeclarationKind, Definition, PipeInfo, Pipes, Signature, Span, Symbol, SymbolDeclaration, SymbolQuery, SymbolTable} from '@angular/compiler-cli/src/language_services'; export { BuiltinType, diff --git a/packages/language-service/src/typescript_host.ts b/packages/language-service/src/typescript_host.ts index 7cdf0a840f..e91ca3f532 100644 --- a/packages/language-service/src/typescript_host.ts +++ b/packages/language-service/src/typescript_host.ts @@ -7,7 +7,7 @@ */ import {AotSummaryResolver, CompileMetadataResolver, CompilerConfig, DEFAULT_INTERPOLATION_CONFIG, DirectiveNormalizer, DirectiveResolver, DomElementSchemaRegistry, HtmlParser, InterpolationConfig, JitSummaryResolver, NgAnalyzedModules, NgModuleResolver, ParseTreeResult, PipeResolver, ResourceLoader, StaticReflector, StaticSymbol, StaticSymbolCache, StaticSymbolResolver, SummaryResolver, analyzeNgModules, createOfflineCompileUrlResolver, extractProgramSymbols} from '@angular/compiler'; -import {AngularCompilerOptions, getClassMembersFromDeclaration, getPipesTable, getSymbolQuery} from '@angular/compiler-cli'; +import {AngularCompilerOptions, getClassMembersFromDeclaration, getPipesTable, getSymbolQuery} from '@angular/compiler-cli/src/language_services'; import {ViewEncapsulation, ɵConsole as Console} from '@angular/core'; import * as fs from 'fs'; import * as path from 'path'; diff --git a/packages/language-service/src/utils.ts b/packages/language-service/src/utils.ts index 425b9fbd6d..d9914d8c7d 100644 --- a/packages/language-service/src/utils.ts +++ b/packages/language-service/src/utils.ts @@ -7,7 +7,7 @@ */ import {AstPath, CompileDirectiveSummary, CompileTypeMetadata, CssSelector, DirectiveAst, ElementAst, EmbeddedTemplateAst, HtmlAstPath, Node as HtmlNode, ParseSourceSpan, RecursiveTemplateAstVisitor, RecursiveVisitor, TemplateAst, TemplateAstPath, identifierName, templateVisitAll, visitAll} from '@angular/compiler'; -import {DiagnosticTemplateInfo} from '@angular/compiler-cli'; +import {DiagnosticTemplateInfo} from '@angular/compiler-cli/src/language_services'; import * as ts from 'typescript'; import {SelectorInfo, TemplateInfo} from './common'; diff --git a/packages/language-service/tsconfig-build.json b/packages/language-service/tsconfig-build.json index 96a8d2658a..ad419575ff 100644 --- a/packages/language-service/tsconfig-build.json +++ b/packages/language-service/tsconfig-build.json @@ -17,6 +17,7 @@ "@angular/common": ["../../dist/packages/common"], "@angular/compiler": ["../../dist/packages/compiler"], "@angular/compiler-cli": ["../../dist/packages/compiler-cli"], + "@angular/compiler-cli/*": ["../../dist/packages/compiler-cli/*"], "@angular/http": ["../../dist/packages/http"], "@angular/platform-server": ["../../dist/packages/platform-server"], "@angular/platform-browser": ["../../dist/packages/platform-browser"],