Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { createMatchPath } from "../../src";
import * as Tsconfig from "tsconfig";
import * as path from "path";
// Load tsconfig
const loadResult = Tsconfig.loadSync(process.cwd(), undefined);
// Create function that will match paths
const matchPath = createMatchPath(
path.join(
path.dirname(loadResult.path),
loadResult.config.compilerOptions.baseUrl
),
loadResult.config.compilerOptions.paths
);
// Match a path and log result
const result = matchPath("foo/mylib");
console.log(result);
import { createMatchPath } from "../../src";
import * as Tsconfig from "tsconfig";
import * as path from "path";
// Load tsconfig
const loadResult = Tsconfig.loadSync(process.cwd());
// Create function that will match paths
const matchPath = createMatchPath(
path.join(
path.dirname(loadResult.path),
loadResult.config.compilerOptions.baseUrl
),
loadResult.config.compilerOptions.paths
);
const iterations = 100000;
console.time(`Matching path ${iterations} times`);
for (let i = 0; i < iterations; i++) {
const result = matchPath("foo/mylib", undefined, undefined, [
".ts",
function readConfig(compilerOptions, project, cwd, ts) {
var result = tsconfig_1.loadSync(cwd, typeof project === 'string' ? project : undefined);
result.config.compilerOptions = Object.assign({}, result.config.compilerOptions, compilerOptions, {
sourceMap: true,
inlineSourceMap: false,
inlineSources: true,
declaration: false,
noEmit: false,
outDir: '$$ts-node$$'
});
var configPath = result.path && normalizeSlashes(result.path);
var basePath = configPath ? path_1.dirname(configPath) : normalizeSlashes(cwd);
if (typeof ts.parseConfigFile === 'function') {
return fixConfig(ts.parseConfigFile(result.config, ts.sys, basePath), ts);
}
if (typeof ts.parseJsonConfigFileContent === 'function') {
return fixConfig(ts.parseJsonConfigFileContent(result.config, ts.sys, basePath, undefined, configPath), ts);
}
function readConfig(compilerOptions, project, cwd, ts) {
var result = tsconfig_1.loadSync(cwd, typeof project === 'string' ? project : undefined);
result.config.compilerOptions = Object.assign({}, result.config.compilerOptions, compilerOptions, {
sourceMap: true,
inlineSourceMap: false,
inlineSources: true,
declaration: false,
noEmit: false,
outDir: '$$ts-node$$'
});
var configPath = result.path && normalizeSlashes(result.path);
var basePath = configPath ? path_1.dirname(configPath) : normalizeSlashes(cwd);
if (typeof ts.parseConfigFile === 'function') {
return fixConfig(ts.parseConfigFile(result.config, ts.sys, basePath), ts);
}
if (typeof ts.parseJsonConfigFileContent === 'function') {
return fixConfig(ts.parseJsonConfigFileContent(result.config, ts.sys, basePath, undefined, configPath), ts);
}
const find = () => {
const { path, config } = tsconfig.loadSync(process.cwd())
if (!path) {
logger.info(
'no tsconfig.json found, defaulting to default typescript options'
)
}
return path ? config : defaultTypescriptConfig
}
const cachedConfig = cache.get('typescript-config')
export function configureCompilerOptions(path: string) {
const json = tsconfig.loadSync(path).config.compilerOptions;
compilerOptions = ts.convertCompilerOptionsFromJson(json, process.cwd()).options;
}
.map(dir => ({dir, tsconfig: tsconfig.loadSync(dir)}))
.map(opt => resolveOptions(project, opt)))
private getCompilerOptions() {
if (this.compilerOptions === undefined) {
const json = tsconfig.loadSync(this.tsconfigPath).config.compilerOptions;
this.compilerOptions = ts.convertCompilerOptionsFromJson(json, process.cwd()).options;
}
return this.compilerOptions!;
}
}
const program = ts.createProgram([path], OPTIONS);
return new Result(program, program.getSourceFile(path));
}
exports.compileFile = compileFile;
class Result {
constructor(program, srcFile) {
this.program = program;
this.srcFile = srcFile;
}
isSuccessful() {
return this.program.getSyntacticDiagnostics(this.srcFile).length === 0;
}
}
exports.Result = Result;
const TEST_FILE_NAME = '__tyscan_test__.ts';
const OPTIONS = ts.convertCompilerOptionsFromJson(tsconfig.loadSync('.').config.compilerOptions, process.cwd()).options;
//# sourceMappingURL=compiler.js.map