New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@bscotch/config

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bscotch/config - npm Package Compare versions

Comparing version 0.3.2 to 0.3.3

dist/lib/tsConfig.test.d.ts

8

dist/lib/packageJson.d.ts

@@ -213,3 +213,3 @@ import { Pathy, PathyOrString } from '@bscotch/pathy';

keywords: string[];
homepage: (string & Record<never, never>) | ".";
homepage: "." | (string & Record<never, never>);
bugs: string | {

@@ -232,14 +232,14 @@ url?: string | undefined;

files: string[];
type: "module" | "commonjs";
type: "commonjs" | "module";
main: string;
exports: string | string[] | {
[x: string & Record<never, never>]: PackageJsonData.Exports;
"react-native": PackageJsonData.Exports;
node: PackageJsonData.Exports;
browser: PackageJsonData.Exports;
import: PackageJsonData.Exports;
require: PackageJsonData.Exports;
node: PackageJsonData.Exports;
"node-addons": PackageJsonData.Exports;
deno: PackageJsonData.Exports;
electron: PackageJsonData.Exports;
"react-native": PackageJsonData.Exports;
default: PackageJsonData.Exports;

@@ -246,0 +246,0 @@ } | {

@@ -14,3 +14,3 @@ /**

export declare class TsConfig<Config extends TsConfigJson = TsConfigJson> extends ConfigFile<Config> {
constructor(options: ConfigFileOptions<Config>);
constructor(options: Omit<ConfigFileOptions<Config>, 'defaultBaseName'>);
/**

@@ -44,3 +44,3 @@ * The list of paths references in the config's

module?: TsConfigJson.CompilerOptions.Module | undefined;
moduleResolution?: "node" | "classic" | undefined;
moduleResolution?: "classic" | "node" | undefined;
newLine?: TsConfigJson.CompilerOptions.NewLine | undefined;

@@ -132,4 +132,33 @@ noEmit?: boolean | undefined;

outDir(): Promise<Pathy>;
baseUrl(): Promise<Pathy>;
srcDir(): Promise<Pathy>;
aliases(): Promise<{
[key: string]: string[];
}>;
sourceFiles(): Promise<Pathy[]>;
/**
* Test a path to see if it is included by the
* config. Resolves aliases specified by
* `compilerOptions.paths`. Returns `undefined` unless
* `path` is one of:
*
* - An absolute path to a file included by the config
* - A path relative to the tsconfig file, and included by the config
* - An aliased path that resolves to a path included by the config
*/
includes(path: string, options?: {
/**
* If `true` and `path` is not found in this config,
* any referenced projects will also be checked
* (recursively) for `path`.
*/
searchProjectReferences: boolean;
/**
* By default the working directory the path is relative
* to is assumed to be the tsconfig's directory.
* You can override this.
*/
cwd?: Pathy;
}): Promise<boolean>;
/**
* A tsconfig file can have a `references` array, which

@@ -136,0 +165,0 @@ * can point to other tsconfig files. This feature is

@@ -10,4 +10,5 @@ /**

import { Pathy } from '@bscotch/pathy';
import { Memoize, Trace } from '@bscotch/utility';
import { memoize, Trace } from '@bscotch/utility';
import { ConfigFile } from './configFile.js';
import { globby } from 'globby';
const trace = Trace('@bscotch');

@@ -39,2 +40,9 @@ let TsConfig = TsConfig_1 = class TsConfig extends ConfigFile {

}
async baseUrl() {
const config = await this.cumulativeConfig();
const baseUrl = new Pathy(config.compilerOptions.baseUrl, {
cwd: this.dir,
});
return baseUrl;
}
async srcDir() {

@@ -46,3 +54,51 @@ const config = await this.cumulativeConfig();

}
async aliases() {
const cumulativeConfig = await this.cumulativeConfig();
return { ...(cumulativeConfig.compilerOptions?.paths || {}) };
}
async sourceFiles() {
const config = await this.cumulativeConfig();
const includesAbsolutePatterns = [
...(config.include || []),
...(config.files || []),
].map((p) => this.dir.join(p).absolute);
const excludesAbsolutePatterns = (config.exclude || []).map((p) => `!${this.dir.join(p).absolute}`);
const matchingPaths = await globby([...includesAbsolutePatterns, ...excludesAbsolutePatterns], { cwd: this.dir.absolute });
return matchingPaths.map((p) => new Pathy(p, { cwd: this.dir.absolute }));
}
/**
* Test a path to see if it is included by the
* config. Resolves aliases specified by
* `compilerOptions.paths`. Returns `undefined` unless
* `path` is one of:
*
* - An absolute path to a file included by the config
* - A path relative to the tsconfig file, and included by the config
* - An aliased path that resolves to a path included by the config
*/
async includes(path, options) {
const aliases = await this.aliases();
const cwd = options?.cwd || this.dir;
let resolvedPath = new Pathy(path, { cwd });
for (const [alias, paths] of Object.entries(aliases)) {
const aliasPrefix = alias.replace(/\*$/, '');
if (!path.startsWith(aliasPrefix)) {
continue;
}
// Then it's an aliased path
resolvedPath = this.dir.join(await this.baseUrl(), `${paths[0].replace(/\*$/, '')}${path.substring(aliasPrefix.length)}`);
break;
}
const isIncluded = !!(await this.sourceFiles()).find((f) => f.equals(resolvedPath));
if (!isIncluded && options?.searchProjectReferences) {
const refs = await this.resolveProjectReferenceTree();
for (const ref of refs.slice(1)) {
if (await ref.includes(path, { cwd, searchProjectReferences: true })) {
return true;
}
}
}
return isIncluded;
}
/**
* A tsconfig file can have a `references` array, which

@@ -60,3 +116,3 @@ * can point to other tsconfig files. This feature is

const innerLoop = async (config) => {
const waits = config.referencePaths.map((path) => TsConfig_1.resolve(path).then((refConfig) => {
const waits = config.referencePaths.map((path) => TsConfig_1.resolve(this.dir.resolveTo(path)).then((refConfig) => {
allRefs.push(refConfig);

@@ -134,4 +190,10 @@ return innerLoop(refConfig);

__decorate([
memoize,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], TsConfig.prototype, "sourceFiles", null);
__decorate([
trace,
Memoize(),
memoize,
__metadata("design:type", Function),

@@ -138,0 +200,0 @@ __metadata("design:paramtypes", []),

{
"name": "@bscotch/config",
"version": "0.3.2",
"version": "0.3.3",
"type": "module",

@@ -19,6 +19,7 @@ "exports": {

"dependencies": {
"@bscotch/pathy": "^0.3.1",
"@bscotch/utility": "^5.0.0",
"@bscotch/pathy": "^0.4.0",
"@bscotch/utility": "^5.1.0",
"@bscotch/validation": "^0.2.0",
"chai": "^4.3.6",
"globby": "^13.1.1",
"json5": "^2.2.1",

@@ -25,0 +26,0 @@ "just-clone": "^5.0.1",

Sorry, the diff of this file is not supported yet

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