@bscotch/config
Advanced tools
Comparing version 0.4.0 to 0.5.0
import { __decorate, __metadata } from "tslib"; | ||
import { Pathy } from '@bscotch/pathy'; | ||
import { Trace } from '@bscotch/utility'; | ||
import { Trace, clone } from '@bscotch/utility'; | ||
import { ok } from 'assert'; | ||
import { readFileSync } from 'fs'; | ||
import json5 from 'json5'; | ||
import clone from 'just-clone'; | ||
const trace = Trace('@bscotch'); | ||
@@ -41,3 +40,3 @@ /** | ||
Pathy.asInstance(options.dir).resolveTo((options.basename || options.defaultBasename)); | ||
this.path = new Pathy(this.path, { cwd: this.dir }); | ||
this.path = new Pathy(this.path, this.dir); | ||
this.defaultBasename = options.defaultBasename || this.basename; | ||
@@ -60,3 +59,3 @@ this.data = | ||
} | ||
return this.data.extends && new Pathy(this.data.extends, { cwd: this.dir }); | ||
return this.data.extends && new Pathy(this.data.extends, this.dir); | ||
} | ||
@@ -63,0 +62,0 @@ /** |
@@ -168,3 +168,3 @@ import { Pathy, PathyOrString } from '@bscotch/pathy'; | ||
* This method does nothing if the in-memory dependencies already | ||
* match the provided on. Otherwise it freshly loads the file | ||
* match the provided one. Otherwise it freshly loads the file | ||
* from disk, updates that file, and then immediately writes it | ||
@@ -272,3 +272,3 @@ * back. | ||
engineStrict: boolean; | ||
os: import("type-fest").LiteralUnion<"win32" | "aix" | "darwin" | "freebsd" | "linux" | "openbsd" | "sunos" | "!aix" | "!darwin" | "!freebsd" | "!linux" | "!openbsd" | "!sunos" | "!win32", string>[]; | ||
os: import("type-fest").LiteralUnion<"aix" | "darwin" | "freebsd" | "linux" | "openbsd" | "sunos" | "win32" | "!aix" | "!darwin" | "!freebsd" | "!linux" | "!openbsd" | "!sunos" | "!win32", string>[]; | ||
cpu: import("type-fest").LiteralUnion<"arm" | "arm64" | "ia32" | "mips" | "mipsel" | "ppc" | "ppc64" | "s390" | "s390x" | "x32" | "x64" | "!arm" | "!arm64" | "!ia32" | "!mips" | "!mipsel" | "!ppc" | "!ppc64" | "!s390" | "!s390x" | "!x32" | "!x64", string>[]; | ||
@@ -309,4 +309,4 @@ preferGlobal: boolean; | ||
*/ | ||
static findPackageJson(options?: PackageJsonFindOptions): Promise<PackageJson>; | ||
static findPackageJson<Ext = undefined>(options?: PackageJsonFindOptions): Promise<PackageJson<Ext>>; | ||
} | ||
//# sourceMappingURL=packageJson.d.ts.map |
@@ -193,3 +193,3 @@ import { __decorate, __metadata } from "tslib"; | ||
const list = await packlist({ path: this.dir.toString() }); | ||
return list.map((path) => new Pathy(path, { cwd: this.dir.absolute })); | ||
return list.map((path) => new Pathy(path, this.dir.absolute)); | ||
} | ||
@@ -246,3 +246,3 @@ /** | ||
* This method does nothing if the in-memory dependencies already | ||
* match the provided on. Otherwise it freshly loads the file | ||
* match the provided one. Otherwise it freshly loads the file | ||
* from disk, updates that file, and then immediately writes it | ||
@@ -249,0 +249,0 @@ * back. |
@@ -88,3 +88,3 @@ /** | ||
baseUrl?: string | undefined; | ||
paths?: Partial<Record<string, string[]>> | undefined; | ||
paths?: Record<string, string[]> | undefined; | ||
plugins?: TsConfigJson.CompilerOptions.Plugin[] | undefined; | ||
@@ -146,2 +146,5 @@ rootDirs?: string[] | undefined; | ||
* - An aliased path that resolves to a path included by the config | ||
* | ||
* If any of the above are true, returns the path to the | ||
* path to the included file. | ||
*/ | ||
@@ -161,3 +164,3 @@ includes(path: string, options?: { | ||
cwd?: Pathy; | ||
}): Promise<boolean>; | ||
}): Promise<Pathy | undefined>; | ||
/** | ||
@@ -164,0 +167,0 @@ * A tsconfig file can have a `references` array, which |
@@ -36,9 +36,7 @@ /** | ||
const outDir = config.compilerOptions?.outDir || this.dir; | ||
return new Pathy(outDir, { cwd: this.dir }); | ||
return new Pathy(outDir, this.dir); | ||
} | ||
async baseUrl() { | ||
const config = await this.cumulativeConfig(); | ||
const baseUrl = new Pathy(config.compilerOptions.baseUrl || this.dir, { | ||
cwd: this.dir, | ||
}); | ||
const baseUrl = new Pathy(config.compilerOptions.baseUrl || this.dir, this.dir); | ||
return baseUrl; | ||
@@ -49,3 +47,3 @@ } | ||
const srcDir = config.compilerOptions?.rootDir || this.dir; | ||
return new Pathy(srcDir, { cwd: this.dir }); | ||
return new Pathy(srcDir, this.dir); | ||
} | ||
@@ -65,3 +63,3 @@ async aliases() { | ||
const matchingPaths = await globby([...includesAbsolutePatterns, ...excludesAbsolutePatterns], { cwd: this.dir.absolute }); | ||
return matchingPaths.map((p) => new Pathy(p, { cwd: this.dir.absolute })); | ||
return matchingPaths.map((p) => new Pathy(p, this.dir.absolute)); | ||
} | ||
@@ -77,2 +75,5 @@ /** | ||
* - An aliased path that resolves to a path included by the config | ||
* | ||
* If any of the above are true, returns the path to the | ||
* path to the included file. | ||
*/ | ||
@@ -82,3 +83,3 @@ async includes(path, options) { | ||
const cwd = options?.cwd || this.dir; | ||
let resolvedPath = new Pathy(path, { cwd }); | ||
let resolvedPath = new Pathy(path, cwd); | ||
for (const [alias, paths] of Object.entries(aliases)) { | ||
@@ -93,8 +94,12 @@ const aliasPrefix = alias.replace(/\*$/, ''); | ||
} | ||
const isIncluded = !!(await this.sourceFiles()).find((f) => f.equals(resolvedPath)); | ||
let 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; | ||
isIncluded = await ref.includes(path, { | ||
cwd, | ||
searchProjectReferences: true, | ||
}); | ||
if (isIncluded) { | ||
return isIncluded; | ||
} | ||
@@ -197,2 +202,8 @@ } | ||
__decorate([ | ||
memoize, | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", []), | ||
__metadata("design:returntype", Promise) | ||
], TsConfig.prototype, "resolveProjectReferenceTree", null); | ||
__decorate([ | ||
trace, | ||
@@ -199,0 +210,0 @@ memoize, |
@@ -12,9 +12,9 @@ import { TsConfig } from './tsConfig.js'; | ||
const config = new TsConfig({ path: 'samples/tsconfig.base.json' }); | ||
expect(await config.includes('sample.ts')).to.be.true; | ||
expect(await config.includes('sample.js')).to.be.false; | ||
expect(await config.includes('sample.ts')).to.exist; | ||
expect(await config.includes('sample.js')).to.be.undefined; | ||
}); | ||
it('can check if an alias to a file is included', async function () { | ||
const config = new TsConfig({ path: 'samples/tsconfig.base.json' }); | ||
expect(await config.includes('$lib/sample.ts')).to.be.true; | ||
expect(await config.includes('$lib/sample.js')).to.be.false; | ||
expect(await config.includes('$lib/sample.ts')).to.exist; | ||
expect(await config.includes('$lib/sample.js')).to.be.undefined; | ||
}); | ||
@@ -24,15 +24,15 @@ it('can check if a file is included in referenced projects', async function () { | ||
expect(await config.includes('referenced/src/referencedSample.ts')).to.be | ||
.false; | ||
.undefined; | ||
expect(await config.includes('referenced/src/referencedSample.ts', { | ||
searchProjectReferences: true, | ||
})).to.be.true; | ||
})).to.exist; | ||
}); | ||
it('can check if an aliased file is included in referenced projects', async function () { | ||
const config = new TsConfig({ path: 'samples/tsconfig.base.json' }); | ||
expect(await config.includes('$lib/referencedSample.ts')).to.be.false; | ||
expect(await config.includes('$lib/referencedSample.ts')).to.be.undefined; | ||
expect(await config.includes('$lib/referencedSample.ts', { | ||
searchProjectReferences: true, | ||
})).to.be.true; | ||
})).to.exist; | ||
}); | ||
}); | ||
//# sourceMappingURL=tsConfig.test.js.map |
{ | ||
"name": "@bscotch/config", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"type": "module", | ||
@@ -19,4 +19,4 @@ "exports": { | ||
"dependencies": { | ||
"@bscotch/pathy": "^1.0.0", | ||
"@bscotch/utility": "^6.0.0", | ||
"@bscotch/pathy": "^2.0.0", | ||
"@bscotch/utility": "^6.1.0", | ||
"@bscotch/validation": "^0.2.0", | ||
@@ -26,3 +26,2 @@ "chai": "^4.3.6", | ||
"json5": "^2.2.1", | ||
"just-clone": "^6.0.1", | ||
"npm-packlist": "^5.1.0", | ||
@@ -37,3 +36,12 @@ "semver": "^7.3.7", | ||
"access": "public" | ||
} | ||
}, | ||
"tags": [ | ||
"config", | ||
"configuration", | ||
"tsconfig", | ||
"json", | ||
"package-json", | ||
"package.json", | ||
"package" | ||
] | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
148323
11
58
2346
1
110
+ Added@bscotch/pathy@2.12.1(transitive)
+ Added@bscotch/utility@7.2.0(transitive)
+ Addedfs-extra@11.1.1(transitive)
+ Addedyaml@2.3.2(transitive)
- Removedjust-clone@^6.0.1
- Removed@bscotch/pathy@1.0.0(transitive)
- Removedfs-extra@10.1.0(transitive)
- Removedjust-clone@6.2.0(transitive)
- Removedyaml@2.6.1(transitive)
Updated@bscotch/pathy@^2.0.0
Updated@bscotch/utility@^6.1.0