Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

config-file-ts

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

config-file-ts - npm Package Compare versions

Comparing version 0.2.3 to 0.2.4

45

dist/index.js

@@ -22,9 +22,14 @@ 'use strict';

const program = ts.createProgram(fileNames, options);
const sources = program
.getSourceFiles()
.map((f) => f.fileName)
.filter((name) => !name.includes("node_modules"));
const emitResult = program.emit();
logDiagnostics(program, emitResult);
return !emitResult.emitSkipped;
return { localSources: sources, compiled: !emitResult.emitSkipped };
}
function logDiagnostics(program, emitResult) {
const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
allDiagnostics.forEach(diagnostic => {
const allDiagnostics = ts.getPreEmitDiagnostics(program)
.concat(emitResult.diagnostics);
allDiagnostics.forEach((diagnostic) => {
if (diagnostic.file) {

@@ -84,4 +89,6 @@ const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);

function compileIfNecessary(sources, outDir, strict = true) {
if (needsCompile(sources, outDir)) {
const compileResult = tsCompile(sources, {
const sourceSet = new Set([...sources, ...extendedSources(outDir)]);
const allSources = [...sourceSet];
if (needsCompile(allSources, outDir)) {
const { compiled, localSources } = tsCompile(sources, {
outDir,

@@ -95,11 +102,29 @@ rootDir: fsRoot,

target: ts__default['default'].ScriptTarget.ES2019,
noImplicitAny: false,
noEmitOnError: true,
});
if (compileResult) {
if (compiled) {
saveExtendedSources(outDir, localSources);
linkNodeModules(outDir);
}
return compileResult;
return compiled;
}
return true;
}
/** local sources used in last compilation, including imports */
function extendedSources(outDir) {
const file = sourcesFile(outDir);
if (!fs__default['default'].existsSync(file)) {
return [];
}
const lines = fs__default['default'].readFileSync(file, "utf8");
return lines.split("\n");
}
function sourcesFile(outDir) {
return path__default['default'].join(outDir, "_sources");
}
function saveExtendedSources(outDir, allSources) {
const file = sourcesFile(outDir);
fs__default['default'].writeFileSync(file, allSources.join("\n"));
}
/** Put a link in the output directory to node_modules.

@@ -164,3 +189,3 @@ */

*/
function compileConfigIfNecessary(tsFile, outDir, strict = false) {
function compileConfigIfNecessary(tsFile, outDir, strict = true) {
if (!fs__default['default'].existsSync(tsFile)) {

@@ -206,5 +231,5 @@ console.error("config file:", tsFile, " not found");

*/
function loadTsConfig(tsFile, outDir) {
function loadTsConfig(tsFile, outDir, strict = true) {
const realOutDir = outDir || defaultOutDir(tsFile, "config-file-ts");
const jsConfig = compileConfigIfNecessary(tsFile, realOutDir);
const jsConfig = compileConfigIfNecessary(tsFile, realOutDir, strict);
if (!jsConfig) {

@@ -211,0 +236,0 @@ return undefined;

@@ -8,4 +8,4 @@ /** Load a typescript configuration file.

*/
export declare function loadTsConfig<T>(tsFile: string, outDir?: string): T | undefined;
export declare function loadTsConfig<T>(tsFile: string, outDir?: string, strict?: boolean): T | undefined;
/** @return the directory that will be used to store transpilation output. */
export declare function defaultOutDir(tsFile: string, programName?: string): string;
import * as ts from "typescript";
export declare function tsCompile(fileNames: string[], options: ts.CompilerOptions): boolean;
export interface CompileResult {
localSources: string[];
compiled: boolean;
}
export declare function tsCompile(fileNames: string[], options: ts.CompilerOptions): CompileResult;
{
"name": "config-file-ts",
"version": "0.2.3",
"version": "0.2.4",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "types": "dist/index.d.ts",

@@ -58,4 +58,6 @@ import glob from "glob";

): boolean {
if (needsCompile(sources, outDir)) {
const compileResult = tsCompile(sources, {
const sourceSet = new Set([...sources, ...extendedSources(outDir)]);
const allSources = [...sourceSet];
if (needsCompile(allSources, outDir)) {
const { compiled, localSources } = tsCompile(sources, {
outDir,

@@ -69,8 +71,10 @@ rootDir: fsRoot,

target: ts.ScriptTarget.ES2019,
noImplicitAny: false,
noEmitOnError: true,
});
if (compileResult) {
if (compiled) {
saveExtendedSources(outDir, localSources);
linkNodeModules(outDir);
}
return compileResult;
return compiled;
}

@@ -80,2 +84,22 @@ return true;

/** local sources used in last compilation, including imports */
function extendedSources(outDir: string): string[] {
const file = sourcesFile(outDir);
if (!fs.existsSync(file)) {
return [];
}
const lines = fs.readFileSync(file, "utf8");
return lines.split("\n");
}
function sourcesFile(outDir: string): string {
return path.join(outDir, "_sources");
}
function saveExtendedSources(outDir: string, allSources: string[]): void {
const file = sourcesFile(outDir);
fs.writeFileSync(file, allSources.join("\n"));
}
/** Put a link in the output directory to node_modules.

@@ -82,0 +106,0 @@ */

@@ -5,15 +5,29 @@ import * as ts from "typescript";

export function tsCompile(fileNames: string[], options: ts.CompilerOptions): boolean {
export interface CompileResult {
localSources: string[];
compiled: boolean;
}
export function tsCompile(
fileNames: string[],
options: ts.CompilerOptions
): CompileResult {
console.log("compiling:", fileNames);
const program = ts.createProgram(fileNames, options);
const sources = program
.getSourceFiles()
.map((f) => f.fileName)
.filter((name) => !name.includes("node_modules"));
const emitResult = program.emit();
logDiagnostics(program, emitResult);
return !emitResult.emitSkipped;
return { localSources: sources, compiled: !emitResult.emitSkipped };
}
function logDiagnostics(program: Program, emitResult: EmitResult): void {
const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
const allDiagnostics = ts
.getPreEmitDiagnostics(program)
.concat(emitResult.diagnostics);
allDiagnostics.forEach(diagnostic => {
allDiagnostics.forEach((diagnostic) => {
if (diagnostic.file) {

@@ -23,4 +37,7 @@ const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(

);
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
const message = ts.flattenDiagnosticMessageText(
diagnostic.messageText,
"\n"
);
const filePath = path.resolve(diagnostic.file.fileName);

@@ -31,5 +48,7 @@ console.log(

} else {
console.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
console.log(
ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")
);
}
});
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc