"use strict"; /** * @license * Copyright Google LLC 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 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.createFormatDiagnosticHost = exports.createFileSystemCompilerHost = exports.FileSystemHost = void 0; const ts = require("typescript"); /** * Implementation of a TypeScript parse config host that relies fully on * a given virtual file system. */ class FileSystemHost { _fileSystem; useCaseSensitiveFileNames = ts.sys.useCaseSensitiveFileNames; constructor(_fileSystem) { this._fileSystem = _fileSystem; } fileExists(path) { return this._fileSystem.fileExists(this._fileSystem.resolve(path)); } readFile(path) { const content = this._fileSystem.read(this._fileSystem.resolve(path)); if (content === null) { return undefined; } // Strip BOM as otherwise TSC methods (e.g. "getWidth") will return an offset which // which breaks the CLI UpdateRecorder. https://github.com/angular/angular/pull/30719 return content.replace(/^\uFEFF/, ''); } readDirectory(rootDir, extensions, excludes, includes, depth) { if (ts.matchFiles === undefined) { throw Error('Unable to read directory in virtual file system host. This means that ' + 'TypeScript changed its file matching internals.\n\nPlease consider downgrading your ' + 'TypeScript version, and report an issue in the Angular Components repository.'); } return ts.matchFiles(rootDir, extensions, extensions, includes, this.useCaseSensitiveFileNames, '/', depth, p => this._getFileSystemEntries(p), p => this._fileSystem.resolve(p), p => this._fileSystem.directoryExists(this._fileSystem.resolve(p))); } _getFileSystemEntries(path) { return this._fileSystem.readDirectory(this._fileSystem.resolve(path)); } } exports.FileSystemHost = FileSystemHost; /** * Creates a TypeScript compiler host that fully relies fully on the given * virtual file system. i.e. no interactions with the working directory. */ function createFileSystemCompilerHost(options, fileSystem) { const host = ts.createCompilerHost(options, true); const virtualHost = new FileSystemHost(fileSystem); host.readFile = virtualHost.readFile.bind(virtualHost); host.readDirectory = virtualHost.readDirectory.bind(virtualHost); host.fileExists = virtualHost.fileExists.bind(virtualHost); host.directoryExists = dirPath => fileSystem.directoryExists(fileSystem.resolve(dirPath)); host.getCurrentDirectory = () => '/'; host.getCanonicalFileName = p => fileSystem.resolve(p); return host; } exports.createFileSystemCompilerHost = createFileSystemCompilerHost; /** Creates a format diagnostic host that works with the given file system. */ function createFormatDiagnosticHost(fileSystem) { return { getCanonicalFileName: p => fileSystem.resolve(p), getCurrentDirectory: () => '/', getNewLine: () => '\n', }; } exports.createFormatDiagnosticHost = createFormatDiagnosticHost; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmlydHVhbC1ob3N0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9zY2hlbWF0aWNzL3VwZGF0ZS10b29sL3V0aWxzL3ZpcnR1YWwtaG9zdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7OztHQU1HOzs7QUFFSCxpQ0FBaUM7QUFnQ2pDOzs7R0FHRztBQUNILE1BQWEsY0FBYztJQUdMO0lBRnBCLHlCQUF5QixHQUFHLEVBQUUsQ0FBQyxHQUFHLENBQUMseUJBQXlCLENBQUM7SUFFN0QsWUFBb0IsV0FBdUI7UUFBdkIsZ0JBQVcsR0FBWCxXQUFXLENBQVk7SUFBRyxDQUFDO0lBRS9DLFVBQVUsQ0FBQyxJQUFZO1FBQ3JCLE9BQU8sSUFBSSxDQUFDLFdBQVcsQ0FBQyxVQUFVLENBQUMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQztJQUNyRSxDQUFDO0lBRUQsUUFBUSxDQUFDLElBQVk7UUFDbkIsTUFBTSxPQUFPLEdBQUcsSUFBSSxDQUFDLFdBQVcsQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQztRQUN0RSxJQUFJLE9BQU8sS0FBSyxJQUFJLEVBQUU7WUFDcEIsT0FBTyxTQUFTLENBQUM7U0FDbEI7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