2017-09-11 15:18:19 -07:00
|
|
|
/**
|
|
|
|
|
* @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
|
|
|
|
|
*/
|
|
|
|
|
|
2017-10-17 16:51:04 -07:00
|
|
|
import * as path from 'path';
|
2017-09-12 09:40:28 -07:00
|
|
|
import * as ts from 'typescript';
|
|
|
|
|
|
2017-10-17 16:51:04 -07:00
|
|
|
import {CompilerOptions, DEFAULT_ERROR_CODE, Diagnostic, SOURCE} from './api';
|
2017-09-29 15:02:11 -07:00
|
|
|
|
2017-09-11 15:18:19 -07:00
|
|
|
export const GENERATED_FILES = /(.*?)\.(ngfactory|shim\.ngstyle|ngstyle|ngsummary)\.(js|d\.ts|ts)$/;
|
2017-10-20 09:46:41 -07:00
|
|
|
export const DTS = /\.d\.ts$/;
|
2017-09-12 09:40:28 -07:00
|
|
|
|
|
|
|
|
export const enum StructureIsReused {Not = 0, SafeModules = 1, Completely = 2}
|
|
|
|
|
|
|
|
|
|
// Note: This is an internal property in TypeScript. Use it only for assertions and tests.
|
|
|
|
|
export function tsStructureIsReused(program: ts.Program): StructureIsReused {
|
|
|
|
|
return (program as any).structureIsReused;
|
2017-09-29 15:02:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createMessageDiagnostic(messageText: string): ts.Diagnostic&Diagnostic {
|
|
|
|
|
return {
|
|
|
|
|
file: undefined,
|
|
|
|
|
start: undefined,
|
|
|
|
|
length: undefined,
|
|
|
|
|
category: ts.DiagnosticCategory.Message, messageText,
|
|
|
|
|
code: DEFAULT_ERROR_CODE,
|
|
|
|
|
source: SOURCE,
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-10-17 16:51:04 -07:00
|
|
|
|
|
|
|
|
export function isInRootDir(fileName: string, options: CompilerOptions) {
|
|
|
|
|
return !options.rootDir || pathStartsWithPrefix(options.rootDir, fileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function relativeToRootDirs(filePath: string, rootDirs: string[]): string {
|
|
|
|
|
if (!filePath) return filePath;
|
|
|
|
|
for (const dir of rootDirs || []) {
|
|
|
|
|
const rel = pathStartsWithPrefix(dir, filePath);
|
|
|
|
|
if (rel) {
|
|
|
|
|
return rel;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return filePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function pathStartsWithPrefix(prefix: string, fullPath: string): string|null {
|
|
|
|
|
const rel = path.relative(prefix, fullPath);
|
|
|
|
|
return rel.startsWith('..') ? null : rel;
|
|
|
|
|
}
|