Socket
Socket
Sign inDemoInstall

@ts-morph/bootstrap

Package Overview
Dependencies
25
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.11.1 to 0.12.0

139

dist-deno/ts-morph-bootstrap.js

@@ -26,32 +26,2 @@ import { DocumentRegistry, ts, StringUtils, FileUtils, Memoize, TransactionalFileSystem, TsConfigResolver, errors, InMemoryFileSystemHost, RealFileSystemHost, CompilerOptionsContainer, createHosts, runtime, createModuleResolutionHost } from '@ts-morph/common';

function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
}
class SourceFileCache {

@@ -86,10 +56,8 @@ constructor(fileSystemWrapper, compilerOptions) {

}
addOrGetSourceFileFromFilePath(filePath, options) {
return __awaiter(this, void 0, void 0, function* () {
let sourceFile = this.sourceFilesByFilePath.get(filePath);
if (sourceFile == null && (yield this.fileSystemWrapper.fileExists(filePath))) {
sourceFile = this.createSourceFileFromText(filePath, yield this.fileSystemWrapper.readFile(filePath, this.compilerOptions.getEncoding()), options);
}
return sourceFile;
});
async addOrGetSourceFileFromFilePath(filePath, options) {
let sourceFile = this.sourceFilesByFilePath.get(filePath);
if (sourceFile == null && await this.fileSystemWrapper.fileExists(filePath)) {
sourceFile = this.createSourceFileFromText(filePath, await this.fileSystemWrapper.readFile(filePath, this.compilerOptions.getEncoding()), options);
}
return sourceFile;
}

@@ -133,12 +101,10 @@ addOrGetSourceFileFromFilePathSync(filePath, options) {

function createProject(options = {}) {
return __awaiter(this, void 0, void 0, function* () {
const { project, tsConfigResolver } = createProjectCommon(options);
if (tsConfigResolver != null && options.skipAddingFilesFromTsConfig !== true) {
yield project._addSourceFilesForTsConfigResolver(tsConfigResolver, project.compilerOptions.get());
if (!options.skipFileDependencyResolution)
project.resolveSourceFileDependencies();
}
return project;
});
async function createProject(options = {}) {
const { project, tsConfigResolver } = createProjectCommon(options);
if (tsConfigResolver != null && options.skipAddingFilesFromTsConfig !== true) {
await project._addSourceFilesForTsConfigResolver(tsConfigResolver, project.compilerOptions.get());
if (!options.skipFileDependencyResolution)
project.resolveSourceFileDependencies();
}
return project;
}

@@ -213,3 +179,6 @@ function createProjectSync(options = {}) {

function getCompilerOptions() {
return Object.assign(Object.assign({}, getTsConfigCompilerOptions()), (options.compilerOptions || {}));
return {
...getTsConfigCompilerOptions(),
...(options.compilerOptions || {}),
};
}

@@ -222,9 +191,7 @@ function getTsConfigCompilerOptions() {

}
addSourceFileAtPath(filePath, options) {
return __awaiter(this, void 0, void 0, function* () {
const sourceFile = yield this.addSourceFileAtPathIfExists(filePath, options);
if (sourceFile == null)
throw new errors.FileNotFoundError(this._fileSystemWrapper.getStandardizedAbsolutePath(filePath));
return sourceFile;
});
async addSourceFileAtPath(filePath, options) {
const sourceFile = await this.addSourceFileAtPathIfExists(filePath, options);
if (sourceFile == null)
throw new errors.FileNotFoundError(this._fileSystemWrapper.getStandardizedAbsolutePath(filePath));
return sourceFile;
}

@@ -247,28 +214,15 @@ addSourceFileAtPathSync(filePath, options) {

}
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;
});
async addSourceFilesByPaths(fileGlobs) {
if (typeof fileGlobs === "string")
fileGlobs = [fileGlobs];
const sourceFilePromises = [];
const sourceFiles = [];
for await (const filePath of this._fileSystemWrapper.glob(fileGlobs)) {
sourceFilePromises.push(this.addSourceFileAtPathIfExists(filePath).then(sourceFile => {
if (sourceFile != null)
sourceFiles.push(sourceFile);
}));
}
await Promise.all(sourceFilePromises);
return sourceFiles;
}

@@ -327,9 +281,7 @@ addSourceFilesByPathsSync(fileGlobs) {

}
_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;
});
async _addSourceFilesForTsConfigResolver(tsConfigResolver, compilerOptions) {
const sourceFiles = [];
await Promise.all(tsConfigResolver.getPaths(compilerOptions).filePaths
.map(p => this.addSourceFileAtPath(p).then(s => sourceFiles.push(s))));
return sourceFiles;
}

@@ -341,3 +293,10 @@ _addSourceFilesForTsConfigResolverSync(tsConfigResolver, compilerOptions) {

const oldProgram = this._oldProgram;
const program = ts.createProgram(Object.assign({ rootNames: Array.from(this._sourceFileCache.getSourceFilePaths()), options: this.compilerOptions.get(), host: this.compilerHost, oldProgram, configFileParsingDiagnostics: this.configFileParsingDiagnostics }, options));
const program = ts.createProgram({
rootNames: Array.from(this._sourceFileCache.getSourceFilePaths()),
options: this.compilerOptions.get(),
host: this.compilerHost,
oldProgram,
configFileParsingDiagnostics: this.configFileParsingDiagnostics,
...options,
});
this._oldProgram = program;

@@ -344,0 +303,0 @@ return program;

@@ -29,32 +29,2 @@ 'use strict';

function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
}
class SourceFileCache {

@@ -89,10 +59,8 @@ constructor(fileSystemWrapper, compilerOptions) {

}
addOrGetSourceFileFromFilePath(filePath, options) {
return __awaiter(this, void 0, void 0, function* () {
let sourceFile = this.sourceFilesByFilePath.get(filePath);
if (sourceFile == null && (yield this.fileSystemWrapper.fileExists(filePath))) {
sourceFile = this.createSourceFileFromText(filePath, yield this.fileSystemWrapper.readFile(filePath, this.compilerOptions.getEncoding()), options);
}
return sourceFile;
});
async addOrGetSourceFileFromFilePath(filePath, options) {
let sourceFile = this.sourceFilesByFilePath.get(filePath);
if (sourceFile == null && await this.fileSystemWrapper.fileExists(filePath)) {
sourceFile = this.createSourceFileFromText(filePath, await this.fileSystemWrapper.readFile(filePath, this.compilerOptions.getEncoding()), options);
}
return sourceFile;
}

@@ -136,12 +104,10 @@ addOrGetSourceFileFromFilePathSync(filePath, options) {

function createProject(options = {}) {
return __awaiter(this, void 0, void 0, function* () {
const { project, tsConfigResolver } = createProjectCommon(options);
if (tsConfigResolver != null && options.skipAddingFilesFromTsConfig !== true) {
yield project._addSourceFilesForTsConfigResolver(tsConfigResolver, project.compilerOptions.get());
if (!options.skipFileDependencyResolution)
project.resolveSourceFileDependencies();
}
return project;
});
async function createProject(options = {}) {
const { project, tsConfigResolver } = createProjectCommon(options);
if (tsConfigResolver != null && options.skipAddingFilesFromTsConfig !== true) {
await project._addSourceFilesForTsConfigResolver(tsConfigResolver, project.compilerOptions.get());
if (!options.skipFileDependencyResolution)
project.resolveSourceFileDependencies();
}
return project;
}

@@ -216,3 +182,6 @@ function createProjectSync(options = {}) {

function getCompilerOptions() {
return Object.assign(Object.assign({}, getTsConfigCompilerOptions()), (options.compilerOptions || {}));
return {
...getTsConfigCompilerOptions(),
...(options.compilerOptions || {}),
};
}

@@ -225,9 +194,7 @@ function getTsConfigCompilerOptions() {

}
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;
});
async addSourceFileAtPath(filePath, options) {
const sourceFile = await this.addSourceFileAtPathIfExists(filePath, options);
if (sourceFile == null)
throw new common.errors.FileNotFoundError(this._fileSystemWrapper.getStandardizedAbsolutePath(filePath));
return sourceFile;
}

@@ -250,28 +217,15 @@ addSourceFileAtPathSync(filePath, options) {

}
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;
});
async addSourceFilesByPaths(fileGlobs) {
if (typeof fileGlobs === "string")
fileGlobs = [fileGlobs];
const sourceFilePromises = [];
const sourceFiles = [];
for await (const filePath of this._fileSystemWrapper.glob(fileGlobs)) {
sourceFilePromises.push(this.addSourceFileAtPathIfExists(filePath).then(sourceFile => {
if (sourceFile != null)
sourceFiles.push(sourceFile);
}));
}
await Promise.all(sourceFilePromises);
return sourceFiles;
}

@@ -330,9 +284,7 @@ addSourceFilesByPathsSync(fileGlobs) {

}
_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;
});
async _addSourceFilesForTsConfigResolver(tsConfigResolver, compilerOptions) {
const sourceFiles = [];
await Promise.all(tsConfigResolver.getPaths(compilerOptions).filePaths
.map(p => this.addSourceFileAtPath(p).then(s => sourceFiles.push(s))));
return sourceFiles;
}

@@ -344,3 +296,10 @@ _addSourceFilesForTsConfigResolverSync(tsConfigResolver, compilerOptions) {

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, configFileParsingDiagnostics: this.configFileParsingDiagnostics }, options));
const program = common.ts.createProgram({
rootNames: Array.from(this._sourceFileCache.getSourceFilePaths()),
options: this.compilerOptions.get(),
host: this.compilerHost,
oldProgram,
configFileParsingDiagnostics: this.configFileParsingDiagnostics,
...options,
});
this._oldProgram = program;

@@ -347,0 +306,0 @@ return program;

@@ -1,2 +0,2 @@

import { ts } from "@ts-morph/common";
import { RuntimeDirEntry, ts } from "@ts-morph/common";

@@ -35,3 +35,3 @@ /**

*/
readDirSync(dirPath: string): string[];
readDirSync(dirPath: string): RuntimeDirEntry[];
/** Asynchronously reads a file at the specified path. */

@@ -88,3 +88,3 @@ readFile(filePath: string, encoding?: string): Promise<string>;

/** @inheritdoc */
readDirSync(dirPath: string): string[];
readDirSync(dirPath: string): RuntimeDirEntry[];
/** @inheritdoc */

@@ -91,0 +91,0 @@ readFile(filePath: string, encoding?: string): Promise<string>;

{
"name": "@ts-morph/bootstrap",
"version": "0.11.1",
"version": "0.12.0",
"description": "API for getting quickly set up with the TypeScript Compiler API.",

@@ -14,12 +14,12 @@ "keywords": ["typescript", "compiler", "bootstrap"],

"build:node": "rimraf dist && npm run rollup",
"build:deno": "rimraf dist-deno && npm run rollup -- --environment BUILD:deno && ts-node scripts/buildDeno.ts",
"build:declarations": "ts-node --compiler ttypescript --project scripts/tsconfig.json --transpile-only scripts/buildDeclarations.ts",
"test": "cross-env TS_NODE_COMPILER=\"ttypescript\" TS_NODE_TRANSPILE_ONLY=\"true\" mocha",
"build:deno": "rimraf dist-deno && npm run rollup -- --environment BUILD:deno && deno run -A scripts/buildDeno.ts",
"build:declarations": "deno run -A scripts/buildDeclarations.ts",
"test": "cross-env TS_NODE_TRANSPILE_ONLY=\"true\" mocha",
"test:ci": "npm run test",
"test:debug": "npm run test --inspect-brk",
"test:ts-versions": "ts-node --transpile-only scripts/test/testTypeScriptVersions",
"test:ts-versions": "deno run -A scripts/test/testTypeScriptVersions.ts",
"rollup": "rollup -c"
},
"dependencies": {
"@ts-morph/common": "~0.11.1"
"@ts-morph/common": "~0.12.0"
},

@@ -29,4 +29,2 @@ "devDependencies": {

"@types/mocha": "^9.0.0",
"@types/ts-nameof": "^4.2.1",
"@ts-morph/scripts": "~0.2.0",
"chai": "^4.3.4",

@@ -36,8 +34,6 @@ "cross-env": "^7.0.3",

"rimraf": "^3.0.2",
"rollup": "^2.58.3",
"rollup-plugin-typescript2": "^0.30.0",
"ts-nameof": "^5.0.0",
"rollup": "^2.60.0",
"rollup-plugin-typescript2": "^0.31.0",
"ts-node": "^10.4.0",
"ttypescript": "^1.5.12",
"typescript": "~4.4.4"
"typescript": "~4.5.2"
},

@@ -44,0 +40,0 @@ "publishConfig": {

@@ -21,8 +21,8 @@ # @ts-morph/bootstrap

const myClassFile = project.createSourceFile(
"MyClass.ts",
"export class MyClass { prop: string; }",
"MyClass.ts",
"export class MyClass { prop: string; }",
);
const mainFile = project.createSourceFile(
"main.ts",
"import { MyClass } from './MyClass'",
"main.ts",
"import { MyClass } from './MyClass'",
);

@@ -78,5 +78,5 @@

const project = await createProject({
compilerOptions: {
target: ts.ScriptTarget.ES3,
},
compilerOptions: {
target: ts.ScriptTarget.ES3,
},
});

@@ -91,3 +91,3 @@ ```

const project = await createProject({
tsConfigFilePath: "packages/my-library/tsconfig.json",
tsConfigFilePath: "packages/my-library/tsconfig.json",
});

@@ -105,4 +105,4 @@

const project = await createProject({
tsConfigFilePath: "path/to/tsconfig.json",
skipAddingFilesFromTsConfig: true,
tsConfigFilePath: "path/to/tsconfig.json",
skipAddingFilesFromTsConfig: true,
});

@@ -123,30 +123,30 @@ ```

const project = await createProject({
resolutionHost: (moduleResolutionHost, getCompilerOptions) => {
return {
resolveModuleNames: (moduleNames, containingFile) => {
const compilerOptions = getCompilerOptions();
const resolvedModules: ts.ResolvedModule[] = [];
resolutionHost: (moduleResolutionHost, getCompilerOptions) => {
return {
resolveModuleNames: (moduleNames, containingFile) => {
const compilerOptions = getCompilerOptions();
const resolvedModules: ts.ResolvedModule[] = [];
for (const moduleName of moduleNames.map(removeTsExtension)) {
const result = ts.resolveModuleName(
moduleName,
containingFile,
compilerOptions,
moduleResolutionHost,
);
for (const moduleName of moduleNames.map(removeTsExtension)) {
const result = ts.resolveModuleName(
moduleName,
containingFile,
compilerOptions,
moduleResolutionHost,
);
if (result.resolvedModule)
resolvedModules.push(result.resolvedModule);
}
if (result.resolvedModule)
resolvedModules.push(result.resolvedModule);
}
return resolvedModules;
},
};
return resolvedModules;
},
};
function removeTsExtension(moduleName: string) {
if (moduleName.slice(-3).toLowerCase() === ".ts")
return moduleName.slice(0, -3);
return moduleName;
}
},
function removeTsExtension(moduleName: string) {
if (moduleName.slice(-3).toLowerCase() === ".ts")
return moduleName.slice(0, -3);
return moduleName;
}
},
});

@@ -153,0 +153,0 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc