@ts-morph/bootstrap
Advanced tools
Comparing version 0.5.1 to 0.5.2
@@ -8,14 +8,14 @@ 'use strict'; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Copyright (c) Microsoft Corporation. | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
@@ -111,3 +111,5 @@ | ||
this.documentRegistry.updateDocument(standardizedFilePath, this.compilerOptions.get(), common.ts.ScriptSnapshot.fromString(sourceFile.text), this.getSourceFileVersion(sourceFile), sourceFile["scriptKind"]); | ||
this.fileSystemWrapper.queueMkdir(common.FileUtils.getDirPath(standardizedFilePath)); | ||
const dirPath = common.FileUtils.getDirPath(standardizedFilePath); | ||
if (!this.fileSystemWrapper.directoryExistsSync(dirPath)) | ||
this.fileSystemWrapper.queueMkdir(dirPath); | ||
this.sourceFilesByFilePath.set(standardizedFilePath, sourceFile); | ||
@@ -179,234 +181,231 @@ } | ||
} | ||
let Project = (() => { | ||
class Project { | ||
constructor(objs, options) { | ||
const { tsConfigResolver } = objs; | ||
this.fileSystem = objs.fileSystem; | ||
this._fileSystemWrapper = objs.fileSystemWrapper; | ||
const tsCompilerOptions = getCompilerOptions(); | ||
this.compilerOptions = new common.CompilerOptionsContainer(); | ||
this.compilerOptions.set(tsCompilerOptions); | ||
this._sourceFileCache = new SourceFileCache(this._fileSystemWrapper, this.compilerOptions); | ||
const resolutionHost = !options.resolutionHost | ||
? undefined | ||
: options.resolutionHost(this.getModuleResolutionHost(), () => this.compilerOptions.get()); | ||
const newLineKind = "\n"; | ||
const { languageServiceHost, compilerHost } = common.createHosts({ | ||
transactionalFileSystem: this._fileSystemWrapper, | ||
sourceFileContainer: this._sourceFileCache, | ||
compilerOptions: this.compilerOptions, | ||
getNewLine: () => newLineKind, | ||
resolutionHost: resolutionHost || {}, | ||
}); | ||
this.languageServiceHost = languageServiceHost; | ||
this.compilerHost = compilerHost; | ||
function getCompilerOptions() { | ||
return Object.assign(Object.assign({}, getTsConfigCompilerOptions()), (options.compilerOptions || {})); | ||
} | ||
function getTsConfigCompilerOptions() { | ||
if (tsConfigResolver == null) | ||
return {}; | ||
return tsConfigResolver.getCompilerOptions(); | ||
} | ||
class Project { | ||
constructor(objs, options) { | ||
const { tsConfigResolver } = objs; | ||
this.fileSystem = objs.fileSystem; | ||
this._fileSystemWrapper = objs.fileSystemWrapper; | ||
const tsCompilerOptions = getCompilerOptions(); | ||
this.compilerOptions = new common.CompilerOptionsContainer(); | ||
this.compilerOptions.set(tsCompilerOptions); | ||
this._sourceFileCache = new SourceFileCache(this._fileSystemWrapper, this.compilerOptions); | ||
const resolutionHost = !options.resolutionHost | ||
? undefined | ||
: options.resolutionHost(this.getModuleResolutionHost(), () => this.compilerOptions.get()); | ||
const newLineKind = "\n"; | ||
const { languageServiceHost, compilerHost } = common.createHosts({ | ||
transactionalFileSystem: this._fileSystemWrapper, | ||
sourceFileContainer: this._sourceFileCache, | ||
compilerOptions: this.compilerOptions, | ||
getNewLine: () => newLineKind, | ||
resolutionHost: resolutionHost || {}, | ||
}); | ||
this.languageServiceHost = languageServiceHost; | ||
this.compilerHost = compilerHost; | ||
function getCompilerOptions() { | ||
return Object.assign(Object.assign({}, getTsConfigCompilerOptions()), (options.compilerOptions || {})); | ||
} | ||
addSourceFileAtPath(filePath, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const sourceFile = yield this.addSourceFileAtPathIfExists(filePath, options); | ||
if (sourceFile == null) | ||
throw new common.errors.FileNotFoundError(this._fileSystemWrapper.getStandardizedAbsolutePath(filePath)); | ||
return sourceFile; | ||
}); | ||
function getTsConfigCompilerOptions() { | ||
if (tsConfigResolver == null) | ||
return {}; | ||
return tsConfigResolver.getCompilerOptions(); | ||
} | ||
addSourceFileAtPathSync(filePath, options) { | ||
const sourceFile = this.addSourceFileAtPathIfExistsSync(filePath, options); | ||
} | ||
addSourceFileAtPath(filePath, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const sourceFile = yield this.addSourceFileAtPathIfExists(filePath, options); | ||
if (sourceFile == null) | ||
throw new common.errors.FileNotFoundError(this._fileSystemWrapper.getStandardizedAbsolutePath(filePath)); | ||
return sourceFile; | ||
} | ||
addSourceFileAtPathIfExists(filePath, options) { | ||
return this._sourceFileCache.addOrGetSourceFileFromFilePath(this._fileSystemWrapper.getStandardizedAbsolutePath(filePath), { | ||
scriptKind: options && options.scriptKind, | ||
}); | ||
} | ||
addSourceFileAtPathIfExistsSync(filePath, options) { | ||
return this._sourceFileCache.addOrGetSourceFileFromFilePathSync(this._fileSystemWrapper.getStandardizedAbsolutePath(filePath), { | ||
scriptKind: options && options.scriptKind, | ||
}); | ||
} | ||
addSourceFilesByPaths(fileGlobs) { | ||
var e_1, _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (typeof fileGlobs === "string") | ||
fileGlobs = [fileGlobs]; | ||
const sourceFilePromises = []; | ||
const sourceFiles = []; | ||
try { | ||
for (var _b = __asyncValues(this._fileSystemWrapper.glob(fileGlobs)), _c; _c = yield _b.next(), !_c.done;) { | ||
const filePath = _c.value; | ||
sourceFilePromises.push(this.addSourceFileAtPathIfExists(filePath).then(sourceFile => { | ||
if (sourceFile != null) | ||
sourceFiles.push(sourceFile); | ||
})); | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
yield Promise.all(sourceFilePromises); | ||
return sourceFiles; | ||
}); | ||
} | ||
addSourceFilesByPathsSync(fileGlobs) { | ||
}); | ||
} | ||
addSourceFileAtPathSync(filePath, options) { | ||
const sourceFile = this.addSourceFileAtPathIfExistsSync(filePath, options); | ||
if (sourceFile == null) | ||
throw new common.errors.FileNotFoundError(this._fileSystemWrapper.getStandardizedAbsolutePath(filePath)); | ||
return sourceFile; | ||
} | ||
addSourceFileAtPathIfExists(filePath, options) { | ||
return this._sourceFileCache.addOrGetSourceFileFromFilePath(this._fileSystemWrapper.getStandardizedAbsolutePath(filePath), { | ||
scriptKind: options && options.scriptKind, | ||
}); | ||
} | ||
addSourceFileAtPathIfExistsSync(filePath, options) { | ||
return this._sourceFileCache.addOrGetSourceFileFromFilePathSync(this._fileSystemWrapper.getStandardizedAbsolutePath(filePath), { | ||
scriptKind: options && options.scriptKind, | ||
}); | ||
} | ||
addSourceFilesByPaths(fileGlobs) { | ||
var e_1, _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (typeof fileGlobs === "string") | ||
fileGlobs = [fileGlobs]; | ||
const sourceFilePromises = []; | ||
const sourceFiles = []; | ||
for (const filePath of this._fileSystemWrapper.globSync(fileGlobs)) { | ||
const sourceFile = this.addSourceFileAtPathIfExistsSync(filePath); | ||
if (sourceFile != null) | ||
sourceFiles.push(sourceFile); | ||
try { | ||
for (var _b = __asyncValues(this._fileSystemWrapper.glob(fileGlobs)), _c; _c = yield _b.next(), !_c.done;) { | ||
const filePath = _c.value; | ||
sourceFilePromises.push(this.addSourceFileAtPathIfExists(filePath).then(sourceFile => { | ||
if (sourceFile != null) | ||
sourceFiles.push(sourceFile); | ||
})); | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
yield Promise.all(sourceFilePromises); | ||
return sourceFiles; | ||
}); | ||
} | ||
addSourceFilesByPathsSync(fileGlobs) { | ||
if (typeof fileGlobs === "string") | ||
fileGlobs = [fileGlobs]; | ||
const sourceFiles = []; | ||
for (const filePath of this._fileSystemWrapper.globSync(fileGlobs)) { | ||
const sourceFile = this.addSourceFileAtPathIfExistsSync(filePath); | ||
if (sourceFile != null) | ||
sourceFiles.push(sourceFile); | ||
} | ||
addSourceFilesFromTsConfig(tsConfigFilePath) { | ||
const resolver = this._getTsConfigResolover(tsConfigFilePath); | ||
return this._addSourceFilesForTsConfigResolver(resolver, resolver.getCompilerOptions()); | ||
return sourceFiles; | ||
} | ||
addSourceFilesFromTsConfig(tsConfigFilePath) { | ||
const resolver = this._getTsConfigResolover(tsConfigFilePath); | ||
return this._addSourceFilesForTsConfigResolver(resolver, resolver.getCompilerOptions()); | ||
} | ||
addSourceFilesFromTsConfigSync(tsConfigFilePath) { | ||
const resolver = this._getTsConfigResolover(tsConfigFilePath); | ||
return this._addSourceFilesForTsConfigResolverSync(resolver, resolver.getCompilerOptions()); | ||
} | ||
_getTsConfigResolover(tsConfigFilePath) { | ||
const standardizedFilePath = this._fileSystemWrapper.getStandardizedAbsolutePath(tsConfigFilePath); | ||
return new common.TsConfigResolver(this._fileSystemWrapper, standardizedFilePath, this.compilerOptions.getEncoding()); | ||
} | ||
createSourceFile(filePath, sourceFileText, options) { | ||
return this._sourceFileCache.createSourceFileFromText(this._fileSystemWrapper.getStandardizedAbsolutePath(filePath), sourceFileText || "", { scriptKind: options && options.scriptKind }); | ||
} | ||
updateSourceFile(filePathOrSourceFile, sourceFileText, options) { | ||
if (typeof filePathOrSourceFile === "string") | ||
return this.createSourceFile(filePathOrSourceFile, sourceFileText, options); | ||
incrementVersion(filePathOrSourceFile); | ||
ensureScriptSnapshot(filePathOrSourceFile); | ||
return this._sourceFileCache.setSourceFile(filePathOrSourceFile); | ||
function incrementVersion(sourceFile) { | ||
let version = sourceFile.version || "-1"; | ||
const parsedVersion = parseInt(version, 10); | ||
if (isNaN(parsedVersion)) | ||
version = "0"; | ||
else | ||
version = (parsedVersion + 1).toString(); | ||
sourceFile.version = version; | ||
} | ||
addSourceFilesFromTsConfigSync(tsConfigFilePath) { | ||
const resolver = this._getTsConfigResolover(tsConfigFilePath); | ||
return this._addSourceFilesForTsConfigResolverSync(resolver, resolver.getCompilerOptions()); | ||
function ensureScriptSnapshot(sourceFile) { | ||
if (sourceFile.scriptSnapshot == null) | ||
sourceFile.scriptSnapshot = common.ts.ScriptSnapshot.fromString(sourceFile.text); | ||
} | ||
_getTsConfigResolover(tsConfigFilePath) { | ||
const standardizedFilePath = this._fileSystemWrapper.getStandardizedAbsolutePath(tsConfigFilePath); | ||
return new common.TsConfigResolver(this._fileSystemWrapper, standardizedFilePath, this.compilerOptions.getEncoding()); | ||
} | ||
createSourceFile(filePath, sourceFileText, options) { | ||
return this._sourceFileCache.createSourceFileFromText(this._fileSystemWrapper.getStandardizedAbsolutePath(filePath), sourceFileText || "", { scriptKind: options && options.scriptKind }); | ||
} | ||
updateSourceFile(filePathOrSourceFile, sourceFileText, options) { | ||
if (typeof filePathOrSourceFile === "string") | ||
return this.createSourceFile(filePathOrSourceFile, sourceFileText, options); | ||
incrementVersion(filePathOrSourceFile); | ||
ensureScriptSnapshot(filePathOrSourceFile); | ||
return this._sourceFileCache.setSourceFile(filePathOrSourceFile); | ||
function incrementVersion(sourceFile) { | ||
let version = sourceFile.version || "-1"; | ||
const parsedVersion = parseInt(version, 10); | ||
if (isNaN(parsedVersion)) | ||
version = "0"; | ||
else | ||
version = (parsedVersion + 1).toString(); | ||
sourceFile.version = version; | ||
} | ||
removeSourceFile(filePathOrSourceFile) { | ||
this._sourceFileCache.removeSourceFile(this._fileSystemWrapper.getStandardizedAbsolutePath(typeof filePathOrSourceFile === "string" ? filePathOrSourceFile : filePathOrSourceFile.fileName)); | ||
} | ||
resolveSourceFileDependencies() { | ||
this.createProgram(); | ||
} | ||
_addSourceFilesForTsConfigResolver(tsConfigResolver, compilerOptions) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const sourceFiles = []; | ||
yield Promise.all(tsConfigResolver.getPaths(compilerOptions).filePaths | ||
.map(p => this.addSourceFileAtPath(p).then(s => sourceFiles.push(s)))); | ||
return sourceFiles; | ||
}); | ||
} | ||
_addSourceFilesForTsConfigResolverSync(tsConfigResolver, compilerOptions) { | ||
return tsConfigResolver.getPaths(compilerOptions).filePaths.map(p => this.addSourceFileAtPathSync(p)); | ||
} | ||
createProgram(options) { | ||
const oldProgram = this._oldProgram; | ||
const program = common.ts.createProgram(Object.assign({ rootNames: Array.from(this._sourceFileCache.getSourceFilePaths()), options: this.compilerOptions.get(), host: this.compilerHost, oldProgram }, options)); | ||
this._oldProgram = program; | ||
return program; | ||
} | ||
getLanguageService() { | ||
return common.ts.createLanguageService(this.languageServiceHost, this._sourceFileCache.documentRegistry); | ||
} | ||
getSourceFileOrThrow(fileNameOrSearchFunction) { | ||
const sourceFile = this.getSourceFile(fileNameOrSearchFunction); | ||
if (sourceFile != null) | ||
return sourceFile; | ||
if (typeof fileNameOrSearchFunction === "string") { | ||
const fileNameOrPath = common.FileUtils.standardizeSlashes(fileNameOrSearchFunction); | ||
if (common.FileUtils.pathIsAbsolute(fileNameOrPath) || fileNameOrPath.indexOf("/") >= 0) { | ||
const errorFileNameOrPath = this._fileSystemWrapper.getStandardizedAbsolutePath(fileNameOrPath); | ||
throw new common.errors.InvalidOperationError(`Could not find source file in project at the provided path: ${errorFileNameOrPath}`); | ||
} | ||
function ensureScriptSnapshot(sourceFile) { | ||
if (sourceFile.scriptSnapshot == null) | ||
sourceFile.scriptSnapshot = common.ts.ScriptSnapshot.fromString(sourceFile.text); | ||
else { | ||
throw new common.errors.InvalidOperationError(`Could not find source file in project with the provided file name: ${fileNameOrSearchFunction}`); | ||
} | ||
} | ||
removeSourceFile(filePathOrSourceFile) { | ||
this._sourceFileCache.removeSourceFile(this._fileSystemWrapper.getStandardizedAbsolutePath(typeof filePathOrSourceFile === "string" ? filePathOrSourceFile : filePathOrSourceFile.fileName)); | ||
else { | ||
throw new common.errors.InvalidOperationError(`Could not find source file in project based on the provided condition.`); | ||
} | ||
resolveSourceFileDependencies() { | ||
this.createProgram(); | ||
} | ||
getSourceFile(fileNameOrSearchFunction) { | ||
const filePathOrSearchFunction = getFilePathOrSearchFunction(this._fileSystemWrapper); | ||
if (isStandardizedFilePath(filePathOrSearchFunction)) { | ||
return this._sourceFileCache.getSourceFileFromCacheFromFilePath(filePathOrSearchFunction); | ||
} | ||
_addSourceFilesForTsConfigResolver(tsConfigResolver, compilerOptions) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const sourceFiles = []; | ||
yield Promise.all(tsConfigResolver.getPaths(compilerOptions).filePaths | ||
.map(p => this.addSourceFileAtPath(p).then(s => sourceFiles.push(s)))); | ||
return sourceFiles; | ||
}); | ||
} | ||
_addSourceFilesForTsConfigResolverSync(tsConfigResolver, compilerOptions) { | ||
return tsConfigResolver.getPaths(compilerOptions).filePaths.map(p => this.addSourceFileAtPathSync(p)); | ||
} | ||
createProgram(options) { | ||
const oldProgram = this._oldProgram; | ||
const program = common.ts.createProgram(Object.assign({ rootNames: Array.from(this._sourceFileCache.getSourceFilePaths()), options: this.compilerOptions.get(), host: this.compilerHost, oldProgram }, options)); | ||
this._oldProgram = program; | ||
return program; | ||
} | ||
getLanguageService() { | ||
return common.ts.createLanguageService(this.languageServiceHost, this._sourceFileCache.documentRegistry); | ||
} | ||
getSourceFileOrThrow(fileNameOrSearchFunction) { | ||
const sourceFile = this.getSourceFile(fileNameOrSearchFunction); | ||
if (sourceFile != null) | ||
return sourceFile; | ||
if (typeof fileNameOrSearchFunction === "string") { | ||
const fileNameOrPath = common.FileUtils.standardizeSlashes(fileNameOrSearchFunction); | ||
if (common.FileUtils.pathIsAbsolute(fileNameOrPath) || fileNameOrPath.indexOf("/") >= 0) { | ||
const errorFileNameOrPath = this._fileSystemWrapper.getStandardizedAbsolutePath(fileNameOrPath); | ||
throw new common.errors.InvalidOperationError(`Could not find source file in project at the provided path: ${errorFileNameOrPath}`); | ||
} | ||
else { | ||
throw new common.errors.InvalidOperationError(`Could not find source file in project with the provided file name: ${fileNameOrSearchFunction}`); | ||
} | ||
const allSoureFilesIterable = this.getSourceFiles(); | ||
return selectSmallestDirPathResult(function* () { | ||
for (const sourceFile of allSoureFilesIterable) { | ||
if (filePathOrSearchFunction(sourceFile)) | ||
yield sourceFile; | ||
} | ||
else { | ||
throw new common.errors.InvalidOperationError(`Could not find source file in project based on the provided condition.`); | ||
} | ||
}()); | ||
function getFilePathOrSearchFunction(fileSystemWrapper) { | ||
if (fileNameOrSearchFunction instanceof Function) | ||
return fileNameOrSearchFunction; | ||
const fileNameOrPath = common.FileUtils.standardizeSlashes(fileNameOrSearchFunction); | ||
if (common.FileUtils.pathIsAbsolute(fileNameOrPath) || fileNameOrPath.indexOf("/") >= 0) | ||
return fileSystemWrapper.getStandardizedAbsolutePath(fileNameOrPath); | ||
else | ||
return def => common.FileUtils.pathEndsWith(def.fileName, fileNameOrPath); | ||
} | ||
getSourceFile(fileNameOrSearchFunction) { | ||
const filePathOrSearchFunction = getFilePathOrSearchFunction(this._fileSystemWrapper); | ||
if (isStandardizedFilePath(filePathOrSearchFunction)) { | ||
return this._sourceFileCache.getSourceFileFromCacheFromFilePath(filePathOrSearchFunction); | ||
function selectSmallestDirPathResult(results) { | ||
let result; | ||
for (const sourceFile of results) { | ||
if (result == null || common.FileUtils.getDirPath(sourceFile.fileName).length < common.FileUtils.getDirPath(result.fileName).length) | ||
result = sourceFile; | ||
} | ||
const allSoureFilesIterable = this.getSourceFiles(); | ||
return selectSmallestDirPathResult(function* () { | ||
for (const sourceFile of allSoureFilesIterable) { | ||
if (filePathOrSearchFunction(sourceFile)) | ||
yield sourceFile; | ||
} | ||
}()); | ||
function getFilePathOrSearchFunction(fileSystemWrapper) { | ||
if (fileNameOrSearchFunction instanceof Function) | ||
return fileNameOrSearchFunction; | ||
const fileNameOrPath = common.FileUtils.standardizeSlashes(fileNameOrSearchFunction); | ||
if (common.FileUtils.pathIsAbsolute(fileNameOrPath) || fileNameOrPath.indexOf("/") >= 0) | ||
return fileSystemWrapper.getStandardizedAbsolutePath(fileNameOrPath); | ||
else | ||
return def => common.FileUtils.pathEndsWith(def.fileName, fileNameOrPath); | ||
} | ||
function selectSmallestDirPathResult(results) { | ||
let result; | ||
for (const sourceFile of results) { | ||
if (result == null || common.FileUtils.getDirPath(sourceFile.fileName).length < common.FileUtils.getDirPath(result.fileName).length) | ||
result = sourceFile; | ||
} | ||
return result; | ||
} | ||
function isStandardizedFilePath(obj) { | ||
return typeof obj === "string"; | ||
} | ||
return result; | ||
} | ||
getSourceFiles() { | ||
return Array.from(this._sourceFileCache.getSourceFiles()); | ||
function isStandardizedFilePath(obj) { | ||
return typeof obj === "string"; | ||
} | ||
formatDiagnosticsWithColorAndContext(diagnostics, opts = {}) { | ||
return common.ts.formatDiagnosticsWithColorAndContext(diagnostics, { | ||
getCurrentDirectory: () => this._fileSystemWrapper.getCurrentDirectory(), | ||
getCanonicalFileName: fileName => fileName, | ||
getNewLine: () => opts.newLineChar || require("os").EOL, | ||
}); | ||
} | ||
getModuleResolutionHost() { | ||
return common.createModuleResolutionHost({ | ||
transactionalFileSystem: this._fileSystemWrapper, | ||
getEncoding: () => this.compilerOptions.getEncoding(), | ||
sourceFileContainer: this._sourceFileCache, | ||
}); | ||
} | ||
} | ||
__decorate([ | ||
common.Memoize | ||
], Project.prototype, "getLanguageService", null); | ||
__decorate([ | ||
common.Memoize | ||
], Project.prototype, "getModuleResolutionHost", null); | ||
return Project; | ||
})(); | ||
getSourceFiles() { | ||
return Array.from(this._sourceFileCache.getSourceFiles()); | ||
} | ||
formatDiagnosticsWithColorAndContext(diagnostics, opts = {}) { | ||
return common.ts.formatDiagnosticsWithColorAndContext(diagnostics, { | ||
getCurrentDirectory: () => this._fileSystemWrapper.getCurrentDirectory(), | ||
getCanonicalFileName: fileName => fileName, | ||
getNewLine: () => opts.newLineChar || require("os").EOL, | ||
}); | ||
} | ||
getModuleResolutionHost() { | ||
return common.createModuleResolutionHost({ | ||
transactionalFileSystem: this._fileSystemWrapper, | ||
getEncoding: () => this.compilerOptions.getEncoding(), | ||
sourceFileContainer: this._sourceFileCache, | ||
}); | ||
} | ||
} | ||
__decorate([ | ||
common.Memoize | ||
], Project.prototype, "getLanguageService", null); | ||
__decorate([ | ||
common.Memoize | ||
], Project.prototype, "getModuleResolutionHost", null); | ||
@@ -413,0 +412,0 @@ Object.defineProperty(exports, 'CompilerOptionsContainer', { |
{ | ||
"name": "@ts-morph/bootstrap", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "API for getting quickly set up with the TypeScript Compiler API.", | ||
@@ -21,3 +21,3 @@ "keywords": ["typescript", "compiler", "bootstrap"], | ||
"dependencies": { | ||
"@ts-morph/common": "~0.5.1" | ||
"@ts-morph/common": "~0.5.2" | ||
}, | ||
@@ -24,0 +24,0 @@ "devDependencies": { |
@@ -10,3 +10,3 @@ # @ts-morph/bootstrap | ||
* [Declarations](https://github.com/dsherret/ts-morph/blob/latest/packages/bootstrap/lib/ts-morph-bootstrap.d.ts) | ||
- [Declarations](https://github.com/dsherret/ts-morph/blob/latest/packages/bootstrap/lib/ts-morph-bootstrap.d.ts) | ||
@@ -23,7 +23,7 @@ ## Example | ||
"MyClass.ts", | ||
"export class MyClass { prop: string; }" | ||
"export class MyClass { prop: string; }", | ||
); | ||
const mainFile = project.createSourceFile( | ||
"main.ts", | ||
"import { MyClass } from './MyClass'" | ||
"import { MyClass } from './MyClass'", | ||
); | ||
@@ -80,4 +80,4 @@ | ||
compilerOptions: { | ||
target: ts.ScriptTarget.ES3 | ||
} | ||
target: ts.ScriptTarget.ES3, | ||
}, | ||
}); | ||
@@ -92,3 +92,3 @@ ``` | ||
const project = await createProject({ | ||
tsConfigFilePath: "packages/my-library/tsconfig.json" | ||
tsConfigFilePath: "packages/my-library/tsconfig.json", | ||
}); | ||
@@ -100,3 +100,3 @@ | ||
*Note:* You can override any tsconfig.json options by also providing a `compilerOptions` object. | ||
_Note:_ You can override any tsconfig.json options by also providing a `compilerOptions` object. | ||
@@ -108,3 +108,3 @@ For your convenience, this will automatically add all the associated source files from the tsconfig.json. If you don't wish to do that, then you will need to explicitly set `addFilesFromTsConfig` to `false`: | ||
tsConfigFilePath: "path/to/tsconfig.json", | ||
addFilesFromTsConfig: false | ||
addFilesFromTsConfig: false, | ||
}); | ||
@@ -136,3 +136,3 @@ ``` | ||
compilerOptions, | ||
moduleResolutionHost | ||
moduleResolutionHost, | ||
); | ||
@@ -145,3 +145,3 @@ | ||
return resolvedModules; | ||
} | ||
}, | ||
}; | ||
@@ -154,3 +154,3 @@ | ||
} | ||
} | ||
}, | ||
}); | ||
@@ -163,5 +163,5 @@ ``` | ||
* `const sourceFiles = await project.addSourceFilesByPaths("**/*.ts");` or provide an array of file globs. | ||
* `const sourceFile = await project.addSourceFileAtPath("src/my-file.ts");` or use `addSourceFileAtPathIfExists(filePath)` | ||
* `const sourceFiles = await project.addSourceFilesFromTsConfig("path/to/tsconfig.json")` | ||
- `const sourceFiles = await project.addSourceFilesByPaths("**/*.ts");` or provide an array of file globs. | ||
- `const sourceFile = await project.addSourceFileAtPath("src/my-file.ts");` or use `addSourceFileAtPathIfExists(filePath)` | ||
- `const sourceFiles = await project.addSourceFilesFromTsConfig("path/to/tsconfig.json")` | ||
@@ -168,0 +168,0 @@ Or use the corresponding `-Sync` suffix methods for a synchronous API (though it will be much slower). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
0
46439
791
Updated@ts-morph/common@~0.5.2