Socket
Socket
Sign inDemoInstall

ts-lib-utils

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-lib-utils - npm Package Compare versions

Comparing version 2.7.2 to 2.8.4

41

dist/tsconfig.js

@@ -14,3 +14,3 @@ "use strict";

const { configFilePath, dirname } = getTsConfigFilePath(project);
const config = getTsConfig(configFilePath, dirname);
const config = await getTsConfig(configFilePath, dirname);
const { options: compilerOptions, errors } = typescript_1.default.convertCompilerOptionsFromJson(config.compilerOptions, config.basePath || dirname);

@@ -33,4 +33,12 @@ if (errors && errors.length > 0) {

if (fallbackProject) {
project = fallbackProject;
projectStats = fs.statSync(project);
while (fallbackProject.length > 0) {
try {
project = fallbackProject[0];
projectStats = fs.statSync(project);
break;
}
catch {
fallbackProject.shift();
}
}
}

@@ -41,7 +49,7 @@ else {

}
if (projectStats.isDirectory()) {
if (projectStats && projectStats.isDirectory()) {
configFilePath = path.resolve(project, 'tsconfig.json');
dirname = project;
}
else if (projectStats.isFile()) {
else if (projectStats && projectStats.isFile()) {
configFilePath = project;

@@ -55,3 +63,3 @@ dirname = path.dirname(project);

}
function getTsConfig(configFilePath, dirname) {
async function getTsConfig(configFilePath, dirname) {
const configResult = typescript_1.default.readConfigFile(configFilePath, p => fs.readFileSync(p).toString());

@@ -73,3 +81,3 @@ const config = configResult.error ? {

let project;
let fallbackProject;
let fallbackProjects = [];
if (path.isAbsolute(config.extends)) {

@@ -88,6 +96,7 @@ project = config.extends;

project = path.resolve(dirname, 'node_modules', config.extends);
fallbackProject = path.resolve(process.cwd(), 'node_modules', config.extends);
const paths = await findParentsWithNodeModules(dirname);
fallbackProjects = paths.map(p => path.resolve(p, 'node_modules', config.extends || ''));
}
const { configFilePath, dirname: extendsBasename } = getTsConfigFilePath(project, fallbackProject);
const extendsConfig = getTsConfig(configFilePath, extendsBasename);
const { configFilePath, dirname: extendsBasename } = getTsConfigFilePath(project, fallbackProjects);
const extendsConfig = await getTsConfig(configFilePath, extendsBasename);
config.compilerOptions = { ...extendsConfig.compilerOptions, ...config.compilerOptions };

@@ -148,1 +157,13 @@ config.basePath = extendsBasename;

}
async function findParentsWithNodeModules(dir) {
const result = [process.cwd()];
dir = path.resolve(dir);
for (let i = 0; i < 3; i++) {
dir = path.dirname(dir);
const stats = await statAsync(path.resolve(dir, 'node_modules'));
if (stats && stats.isDirectory() && !result.includes(dir)) {
result.push(dir);
}
}
return result;
}

@@ -16,3 +16,5 @@ import { __assign, __awaiter, __generator, __values } from "tslib";

_a = getTsConfigFilePath(project), configFilePath = _a.configFilePath, dirname = _a.dirname;
config = getTsConfig(configFilePath, dirname);
return [4 /*yield*/, getTsConfig(configFilePath, dirname)];
case 1:
config = _c.sent();
_b = ts.convertCompilerOptionsFromJson(config.compilerOptions, config.basePath || dirname), compilerOptions = _b.options, errors = _b.errors;

@@ -23,3 +25,3 @@ if (errors && errors.length > 0) {

return [4 /*yield*/, getRootNames(config, dirname)];
case 1:
case 2:
rootNames = _c.sent();

@@ -40,4 +42,12 @@ return [2 /*return*/, { rootNames: rootNames, compilerOptions: compilerOptions }];

if (fallbackProject) {
project = fallbackProject;
projectStats = fs.statSync(project);
while (fallbackProject.length > 0) {
try {
project = fallbackProject[0];
projectStats = fs.statSync(project);
break;
}
catch (_a) {
fallbackProject.shift();
}
}
}

@@ -48,7 +58,7 @@ else {

}
if (projectStats.isDirectory()) {
if (projectStats && projectStats.isDirectory()) {
configFilePath = path.resolve(project, 'tsconfig.json');
dirname = project;
}
else if (projectStats.isFile()) {
else if (projectStats && projectStats.isFile()) {
configFilePath = project;

@@ -63,40 +73,55 @@ dirname = path.dirname(project);

function getTsConfig(configFilePath, dirname) {
var configResult = ts.readConfigFile(configFilePath, function (p) { return fs.readFileSync(p).toString(); });
var config = configResult.error ? {
extends: undefined,
compilerOptions: {
lib: [
'dom',
'es5',
'es2015',
'es2016',
'es2017'
],
allowSyntheticDefaultImports: true
}
} : configResult.config;
if (config.extends) {
var project = void 0;
var fallbackProject = void 0;
if (path.isAbsolute(config.extends)) {
project = config.extends;
}
else if (config.extends === '.'
|| config.extends === '..'
|| config.extends.startsWith("." + path.sep)
|| config.extends.startsWith(".." + path.sep)
|| config.extends.startsWith('./')
|| config.extends.startsWith('../')) {
project = path.resolve(dirname, config.extends);
}
else {
project = path.resolve(dirname, 'node_modules', config.extends);
fallbackProject = path.resolve(process.cwd(), 'node_modules', config.extends);
}
var _a = getTsConfigFilePath(project, fallbackProject), configFilePath_1 = _a.configFilePath, extendsBasename = _a.dirname;
var extendsConfig = getTsConfig(configFilePath_1, extendsBasename);
config.compilerOptions = __assign(__assign({}, extendsConfig.compilerOptions), config.compilerOptions);
config.basePath = extendsBasename;
}
return config;
return __awaiter(this, void 0, void 0, function () {
var configResult, config, project, fallbackProjects, paths, _a, configFilePath_1, extendsBasename, extendsConfig;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
configResult = ts.readConfigFile(configFilePath, function (p) { return fs.readFileSync(p).toString(); });
config = configResult.error ? {
extends: undefined,
compilerOptions: {
lib: [
'dom',
'es5',
'es2015',
'es2016',
'es2017'
],
allowSyntheticDefaultImports: true
}
} : configResult.config;
if (!config.extends) return [3 /*break*/, 6];
project = void 0;
fallbackProjects = [];
if (!path.isAbsolute(config.extends)) return [3 /*break*/, 1];
project = config.extends;
return [3 /*break*/, 4];
case 1:
if (!(config.extends === '.'
|| config.extends === '..'
|| config.extends.startsWith("." + path.sep)
|| config.extends.startsWith(".." + path.sep)
|| config.extends.startsWith('./')
|| config.extends.startsWith('../'))) return [3 /*break*/, 2];
project = path.resolve(dirname, config.extends);
return [3 /*break*/, 4];
case 2:
project = path.resolve(dirname, 'node_modules', config.extends);
return [4 /*yield*/, findParentsWithNodeModules(dirname)];
case 3:
paths = _b.sent();
fallbackProjects = paths.map(function (p) { return path.resolve(p, 'node_modules', config.extends || ''); });
_b.label = 4;
case 4:
_a = getTsConfigFilePath(project, fallbackProjects), configFilePath_1 = _a.configFilePath, extendsBasename = _a.dirname;
return [4 /*yield*/, getTsConfig(configFilePath_1, extendsBasename)];
case 5:
extendsConfig = _b.sent();
config.compilerOptions = __assign(__assign({}, extendsConfig.compilerOptions), config.compilerOptions);
config.basePath = extendsBasename;
_b.label = 6;
case 6: return [2 /*return*/, config];
}
});
});
}

@@ -186,1 +211,29 @@ function getRootNames(config, dirname) {

}
function findParentsWithNodeModules(dir) {
return __awaiter(this, void 0, void 0, function () {
var result, i, stats;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
result = [process.cwd()];
dir = path.resolve(dir);
i = 0;
_a.label = 1;
case 1:
if (!(i < 3)) return [3 /*break*/, 4];
dir = path.dirname(dir);
return [4 /*yield*/, statAsync(path.resolve(dir, 'node_modules'))];
case 2:
stats = _a.sent();
if (stats && stats.isDirectory() && !result.includes(dir)) {
result.push(dir);
}
_a.label = 3;
case 3:
i++;
return [3 /*break*/, 1];
case 4: return [2 /*return*/, result];
}
});
});
}
{
"name": "ts-lib-utils",
"version": "2.7.2",
"version": "2.8.4",
"description": "Utils to develop library using typescript",

@@ -22,3 +22,3 @@ "main": "dist/index.js",

},
"gitHead": "528551434b44abc1e5c0356d3a2e1471a3882bb9"
"gitHead": "a8001fa4f2281fcbed36419f0aa9a9047f336cba"
}
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