@visulima/tsconfig 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/LICENSE.md +38 -0
- package/README.md +110 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +1343 -0
- package/dist/index.d.mts +1343 -0
- package/dist/index.d.ts +1343 -0
- package/dist/index.mjs +1 -0
- package/package.json +138 -0
package/CHANGELOG.md
ADDED
package/LICENSE.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 visulima
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
<!-- DEPENDENCIES -->
|
|
24
|
+
<!-- DEPENDENCIES -->
|
|
25
|
+
|
|
26
|
+
<!-- TYPE_DEPENDENCIES -->
|
|
27
|
+
|
|
28
|
+
# Licenses of bundled types
|
|
29
|
+
The published @visulima/tsconfig artifact additionally contains code with the following licenses:
|
|
30
|
+
(MIT OR CC0-1.0)
|
|
31
|
+
|
|
32
|
+
# Bundled types:
|
|
33
|
+
## type-fest
|
|
34
|
+
License: (MIT OR CC0-1.0)
|
|
35
|
+
By: Sindre Sorhus
|
|
36
|
+
Repository: sindresorhus/type-fest
|
|
37
|
+
|
|
38
|
+
<!-- TYPE_DEPENDENCIES -->
|
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h3>visulima tsconfig</h3>
|
|
3
|
+
<p>
|
|
4
|
+
Find and / or parse the tsconfig.json file from a directory path, this package is built on top of
|
|
5
|
+
|
|
6
|
+
[@visulima/fs](https://github.com/visulima/visulima/tree/main/packages/fs),
|
|
7
|
+
[@visulima/path](https://github.com/visulima/visulima/tree/main/packages/path),
|
|
8
|
+
[jsonc-parser](https://github.com/microsoft/node-jsonc-parser) and
|
|
9
|
+
[resolve-pkg-maps](https://github.com/privatenumber/resolve-pkg-maps)
|
|
10
|
+
</p>
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
<br />
|
|
14
|
+
|
|
15
|
+
<div align="center">
|
|
16
|
+
|
|
17
|
+
[![typescript-image]][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url]
|
|
18
|
+
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
<div align="center">
|
|
24
|
+
<p>
|
|
25
|
+
<sup>
|
|
26
|
+
Daniel Bannert's open source work is supported by the community on <a href="https://github.com/sponsors/prisis">GitHub Sponsors</a>
|
|
27
|
+
</sup>
|
|
28
|
+
</p>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
npm install @visulima/tsconfig
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
yarn add @visulima/tsconfig
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
pnpm add @visulima/tsconfig
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
### findTsConfig
|
|
50
|
+
|
|
51
|
+
Retrieves the TsConfig by searching for the "tsconfig.json" file from a given current working directory.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { findTsConfig } from "@visulima/tsconfig";
|
|
55
|
+
|
|
56
|
+
const tsconfig = await findTsConfig(); // => { path: "/Users/../Projects/visulima/packages/tsconfig/tsconfig.json", config: { compilerOptions: { ... } } }
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### writeTsConfig
|
|
60
|
+
|
|
61
|
+
Writes the provided TypeScript configuration object to a tsconfig.json file.
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { writeTsConfig } from '@visulima/package';
|
|
65
|
+
|
|
66
|
+
writeTsConfig({ compilerOptions: { ... } }/* ,{ cwd: "./" }*/);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### readTsConfig
|
|
70
|
+
|
|
71
|
+
Reads the TypeScript configuration from a tsconfig.json file.
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { readTsConfig } from '@visulima/package';
|
|
75
|
+
|
|
76
|
+
const tsconfig = await readTsConfig("/Users/../Projects/visulima/packages/tsconfig.json", /* { tscCompatible: false } */);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
> tscCompatible: If true, the configuration will be parsed in a way that is compatible with the TypeScript compiler.
|
|
80
|
+
|
|
81
|
+
## Related
|
|
82
|
+
|
|
83
|
+
- [get-tsconfig](https://github.com/privatenumber/get-tsconfig) - Get the TypeScript configuration from a project.
|
|
84
|
+
|
|
85
|
+
## Supported Node.js Versions
|
|
86
|
+
|
|
87
|
+
Libraries in this ecosystem make the best effort to track [Node.js’ release schedule](https://github.com/nodejs/release#release-schedule).
|
|
88
|
+
Here’s [a post on why we think this is important](https://medium.com/the-node-js-collection/maintainers-should-consider-following-node-js-release-schedule-ab08ed4de71a).
|
|
89
|
+
|
|
90
|
+
## Contributing
|
|
91
|
+
|
|
92
|
+
If you would like to help take a look at the [list of issues](https://github.com/visulima/visulima/issues) and check our [Contributing](.github/CONTRIBUTING.md) guidelines.
|
|
93
|
+
|
|
94
|
+
> **Note:** please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
|
|
95
|
+
|
|
96
|
+
## Credits
|
|
97
|
+
|
|
98
|
+
- [Daniel Bannert](https://github.com/prisis)
|
|
99
|
+
- [All Contributors](https://github.com/visulima/visulima/graphs/contributors)
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
The visulima tsconfig is open-sourced software licensed under the [MIT][license-url]
|
|
104
|
+
|
|
105
|
+
[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
|
|
106
|
+
[typescript-url]: "typescript"
|
|
107
|
+
[license-image]: https://img.shields.io/npm/l/@visulima/tsconfig?color=blueviolet&style=for-the-badge
|
|
108
|
+
[license-url]: LICENSE.md "license"
|
|
109
|
+
[npm-image]: https://img.shields.io/npm/v/@visulima/tsconfig/latest.svg?style=for-the-badge&logo=npm
|
|
110
|
+
[npm-url]: https://www.npmjs.com/package/@visulima/tsconfig/v/latest "npm"
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var N=Object.defineProperty;var w=(n,s)=>N(n,"name",{value:s,configurable:!0});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("@visulima/fs"),F=require("@visulima/fs/error"),r=require("@visulima/path"),T=require("jsonc-parser"),u=require("node:fs"),q=require("node:module"),k=require("resolve-pkg-maps"),D=require("@visulima/fs/utils"),J=w(n=>n&&typeof n=="object"&&"default"in n?n.default:n,"_interopDefaultCompat"),M=J(q);var _=Object.defineProperty,S=w((n,s)=>_(n,"name",{value:s,configurable:!0}),"d");const B=S(n=>T.parse(h.readFileSync(n)),"readJsonc"),z=S(()=>{const{findPnpApi:n}=M;return n?.(process.cwd())},"getPnpApi"),C=S((n,s,c,t)=>{const o=`resolveFromPackageJsonPath:${n}:${s}:${c}`;if(t?.has(o))return t.get(o);const e=B(n);if(!e)return;let i=s||"tsconfig.json";if(!c&&e.exports)try{const[a]=k.resolveExports(e.exports,s,["require","types"]);i=a}catch{return!1}else!s&&e.tsconfig&&(i=e.tsconfig);return i=r.join(n,"..",i),t?.set(o,i),i},"resolveFromPackageJsonPath"),x="package.json",v="tsconfig.json",W=S((n,s,c)=>{let t=n;if(n===".."&&(t=r.join(t,v)),n.startsWith(".")&&(t=r.resolve(s,t)),r.isAbsolute(t)){if(u.existsSync(t)){if(u.statSync(t).isFile())return t}else if(!t.endsWith(".json")){const l=`${t}.json`;if(u.existsSync(l))return l}return}const[o,...e]=n.split("/"),i=o.startsWith("@")?`${o}/${e.shift()}`:o,a=e.join("/"),f=z();if(f){const{resolveRequest:l}=f;try{if(i===n){const d=l(r.join(i,x),s);if(d){const g=C(d,a,!1,c);if(g&&u.existsSync(g))return g}}else{let d;try{d=l(n,s,{extensions:[".json"]})}catch{d=l(r.join(n,v),s)}if(d)return d}}catch{}}const p=h.findUpSync(l=>{const d=r.join(l,"node_modules",i);if(u.existsSync(d))return r.join("node_modules",i)},{cwd:s,type:"directory"});if(!p||!u.statSync(p).isDirectory())return;const m=r.join(p,x);if(u.existsSync(m)){const l=C(m,a,!1,c);if(l===!1)return;if(l&&u.existsSync(l)&&u.statSync(l).isFile())return l}const y=r.join(p,a),P=y.endsWith(".json");if(!P){const l=`${y}.json`;if(u.existsSync(l))return l}if(u.existsSync(y)){if(u.statSync(y).isDirectory()){const l=r.join(y,x);if(u.existsSync(l)){const g=C(l,"",!0,c);if(g&&u.existsSync(g))return g}const d=r.join(y,v);if(u.existsSync(d))return d}else if(P)return y}},"resolveExtendsPath");var R=Object.defineProperty,j=w((n,s)=>R(n,"name",{value:s,configurable:!0}),"c");const V=j(n=>T.parse(h.readFileSync(n)),"readJsonc"),b=j(n=>r.toNamespacedPath(/^\.{1,2}(?:\/.*)?$/.test(n)?n:`./${n}`),"normalizePath"),G=j((n,s,c,t)=>{const o=W(n,s);if(!o)throw new F.NotFoundError(`No such file or directory, for '${n}' found.`);if(c.has(o))throw new Error(`Circularity detected while resolving configuration: ${o}`);c.add(o);const e=r.dirname(o),i=$(o,t,c);delete i.references;const{compilerOptions:a}=i;if(a){const f=["baseUrl","outDir"];for(const p of f){const m=a[p];m&&(a[p]=r.relative(s,r.join(e,m)).replaceAll("\\","/")||"./")}}return i.files&&(i.files=i.files.map(f=>r.relative(s,r.join(e,f)))),i.include&&(i.include=i.include.map(f=>r.relative(s,r.join(e,f)))),i.exclude&&(i.exclude=i.exclude.map(f=>r.relative(s,r.join(e,f)))),i},"resolveExtends"),$=j((n,s,c=new Set)=>{let t;try{t=V(n)||{}}catch{throw new Error(`Cannot resolve tsconfig at path: ${n}`)}if(typeof t!="object")throw new SyntaxError(`Failed to parse tsconfig at: ${n}`);const o=r.dirname(n);if(t.compilerOptions){const{compilerOptions:e}=t;e.paths&&!e.baseUrl&&(e[I]=o)}if(t.extends){const e=Array.isArray(t.extends)?t.extends:[t.extends];delete t.extends;for(const i of e.reverse()){const a=G(i,o,new Set(c),s),f={...a,...t,compilerOptions:{...a.compilerOptions,...t.compilerOptions}};a.watchOptions&&(f.watchOptions={...a.watchOptions,...t.watchOptions}),t=f}}if(t.compilerOptions){const{compilerOptions:e}=t,i=["baseUrl","rootDir"];for(const f of i){const p=e[f];if(p){const m=r.resolve(o,p),y=r.relative(o,m);e[f]=b(y)}}const{outDir:a}=e;a&&(Array.isArray(t.exclude)||(t.exclude=[]),t.exclude.includes(a)||t.exclude.push(a),e.outDir=b(a)),s?.tscCompatible&&e.module==="node16"&&(e.allowSyntheticDefaultImports=e.allowSyntheticDefaultImports??!0,e.esModuleInterop=e.esModuleInterop??!0,e.moduleDetection=e.moduleDetection??"force",e.moduleResolution=e.moduleResolution??"node16",e.target=e.target??"es2022",e.useDefineForClassFields=e.useDefineForClassFields??!0),s?.tscCompatible&&e.strict&&(e.noImplicitAny=e.noImplicitAny??!0,e.noImplicitThis=e.noImplicitThis??!0,e.strictNullChecks=e.strictNullChecks??!0,e.strictFunctionTypes=e.strictFunctionTypes??!0,e.strictBindCallApply=e.strictBindCallApply??!0,e.strictPropertyInitialization=e.strictPropertyInitialization??!0,e.alwaysStrict=e.alwaysStrict??!0,e.useUnknownInCatchVariables=e.useUnknownInCatchVariables??!0),s?.tscCompatible&&e.isolatedModules&&(e.preserveConstEnums=e.preserveConstEnums??!0),s?.tscCompatible&&e.esModuleInterop&&(e.allowSyntheticDefaultImports=e.allowSyntheticDefaultImports??!0),s?.tscCompatible&&e.target==="esnext"&&(e.useDefineForClassFields=e.useDefineForClassFields??!0)}else t.compilerOptions={};if(t.files&&(t.files=t.files.map(e=>b(e))),t.include&&(t.include=t.include.map(e=>r.normalize(e))),t.watchOptions){const{watchOptions:e}=t;e.excludeDirectories&&(e.excludeDirectories=e.excludeDirectories.map(i=>r.resolve(o,i)))}return t},"internalParseTsConfig"),I=Symbol("implicitBaseUrl"),O=j((n,s)=>$(n,s),"readTsConfig");var H=Object.defineProperty,U=w((n,s)=>H(n,"name",{value:s,configurable:!0}),"s");const A=new Map,K=U(async(n,s={})=>{const c=s.configFileName??"tsconfig.json";let t=await h.findUp(c,{...n&&{cwd:n},type:"file"});if(t||(t=await h.findUp("jsconfig.json",{...n&&{cwd:n},type:"file"})),!t)throw new F.NotFoundError(`No such file or directory, for ${c} or jsconfig.json found.`);const o=s.cache&&typeof s.cache!="boolean"?s.cache:A;if(s.cache&&o.has(t))return o.get(t);const e={config:O(t),path:t};return s.cache&&o.set(t,e),e},"findTsConfig"),L=U((n,s={})=>{const c=s.configFileName??"tsconfig.json";let t=h.findUpSync(c,{...n&&{cwd:n},type:"file"});if(t||(t=h.findUpSync("jsconfig.json",{...n&&{cwd:n},type:"file"})),!t)throw new F.NotFoundError(`No such file or directory, for ${c} or jsconfig.json found.`);const o=s.cache&&typeof s.cache!="boolean"?s.cache:A;if(s.cache&&o.has(t))return o.get(t);const e={config:O(t),path:t};return s.cache&&o.set(t,e),e},"findTsConfigSync");var Q=Object.defineProperty,E=w((n,s)=>Q(n,"name",{value:s,configurable:!0}),"r");const X=E(async(n,s={})=>{const{cwd:c,...t}=s,o=D.toPath(c??process.cwd());await h.writeJson(r.join(o,"tsconfig.json"),n,t)},"writeTsConfig"),Y=E((n,s={})=>{const{cwd:c,...t}=s,o=D.toPath(c??process.cwd());h.writeJsonSync(r.join(o,"tsconfig.json"),n,t)},"writeTsConfigSync");exports.findTsConfig=K;exports.findTsConfigSync=L;exports.implicitBaseUrlSymbol=I;exports.readTsConfig=O;exports.writeTsConfig=X;exports.writeTsConfigSync=Y;
|