@visulima/package 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 +6 -0
- package/LICENSE.md +21 -0
- package/README.md +189 -0
- package/dist/chunk-7TF75EA4.js +13 -0
- package/dist/chunk-7TF75EA4.js.map +1 -0
- package/dist/chunk-C7FQQQI6.js +14 -0
- package/dist/chunk-C7FQQQI6.js.map +1 -0
- package/dist/chunk-HN5TULBQ.js +10 -0
- package/dist/chunk-HN5TULBQ.js.map +1 -0
- package/dist/chunk-HSXXY5E3.js +11 -0
- package/dist/chunk-HSXXY5E3.js.map +1 -0
- package/dist/chunk-KWZ4YGPC.js +11 -0
- package/dist/chunk-KWZ4YGPC.js.map +1 -0
- package/dist/chunk-MYRZ7SEG.js +9 -0
- package/dist/chunk-MYRZ7SEG.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/monorepo.d.ts +10 -0
- package/dist/monorepo.js +4 -0
- package/dist/monorepo.js.map +1 -0
- package/dist/package-json.d.ts +15 -0
- package/dist/package-json.js +4 -0
- package/dist/package-json.js.map +1 -0
- package/dist/package-manager.d.ts +12 -0
- package/dist/package-manager.js +3 -0
- package/dist/package-manager.js.map +1 -0
- package/dist/package.d.ts +5 -0
- package/dist/package.js +4 -0
- package/dist/package.js.map +1 -0
- package/dist/tsconfig.d.ts +10 -0
- package/dist/tsconfig.js +4 -0
- package/dist/tsconfig.js.map +1 -0
- package/dist/write-json-7d6e6751.d.ts +6 -0
- package/package.json +170 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
## @visulima/package 1.0.0 (2023-10-15)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* added new package with helper for package.json, monorepo and ts-config ([#217](https://github.com/visulima/visulima/issues/217)) ([c7946c8](https://github.com/visulima/visulima/commit/c7946c8a23c0dd715cea396251ba3d88211ce0f3))
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 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.
|
package/README.md
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h3>Visulima package</h3>
|
|
3
|
+
<p>
|
|
4
|
+
One Package to rule them all, finds your root-dir, monorepo, package manager or tsconfig.json is built on top of
|
|
5
|
+
|
|
6
|
+
[read-pkg](https://github.com/sindresorhus/read-pkg),
|
|
7
|
+
[detect-indent](https://github.com/sindresorhus/detect-indent),
|
|
8
|
+
[strip-json-comments](https://github.com/sindresorhus/strip-json-comments),
|
|
9
|
+
[find-up](https://github.com/sindresorhus/find-up) and
|
|
10
|
+
[get-tsconfig](https://www.npmjs.com/package/get-tsconfig)
|
|
11
|
+
|
|
12
|
+
</p>
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
<br />
|
|
16
|
+
|
|
17
|
+
<div align="center">
|
|
18
|
+
|
|
19
|
+
[![typescript-image]][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url]
|
|
20
|
+
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
<div align="center">
|
|
26
|
+
<p>
|
|
27
|
+
<sup>
|
|
28
|
+
Daniel Bannert's open source work is supported by the community on <a href="https://github.com/sponsors/prisis">GitHub Sponsors</a>
|
|
29
|
+
</sup>
|
|
30
|
+
</p>
|
|
31
|
+
</div>
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
npm install @visulima/package
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
yarn add @visulima/package
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
pnpm add @visulima/package
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
### findMonorepoRoot
|
|
52
|
+
|
|
53
|
+
Find the root directory path and strategy for a monorepo based on the given current working directory (cwd).
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { findMonorepoRoot } from "@visulima/package";
|
|
57
|
+
// or import { findMonorepoRoot } from '@visulima/package/monorepo';
|
|
58
|
+
|
|
59
|
+
const root = findMonorepoRoot(); // => /Users/../Projects/visulima
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### findPackageRoot
|
|
63
|
+
|
|
64
|
+
Find the root directory path and strategy for a package based on the given current working directory (cwd).
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { findPackageRoot } from "@visulima/package";
|
|
68
|
+
// or import { findPackageRoot } from '@visulima/package/package';
|
|
69
|
+
|
|
70
|
+
const root = findPackageRoot(); // => /Users/../Projects/visulima/packages/package
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### findPackageJson
|
|
74
|
+
|
|
75
|
+
Find the package.json file in the specified directory or its parent directories.
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { findPackageJson } from "@visulima/package";
|
|
79
|
+
// or import { findPackageJson } from '@visulima/package/package-json';
|
|
80
|
+
|
|
81
|
+
const root = findPackageJson(); // => /Users/../Projects/visulima/packages/package/package.json
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### writePackageJson
|
|
85
|
+
|
|
86
|
+
Writes the package.json file with the given data.
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import { writePackageJson } from "@visulima/package";
|
|
90
|
+
// or import { writePackageJson } from '@visulima/package/package-json';
|
|
91
|
+
|
|
92
|
+
writePackageJson({ name: "visulima" } /* ,{ cwd: "./" }*/);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### parsePackageJson
|
|
96
|
+
|
|
97
|
+
Parse the package.json file.
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import { parsePackageJson } from "@visulima/package";
|
|
101
|
+
|
|
102
|
+
const packageJson = parsePackageJson(/* object or package.json as string */);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### findLockFile
|
|
106
|
+
|
|
107
|
+
Asynchronously finds a lock file in the specified directory or any of its parent directories.
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { findLockFile } from "@visulima/package";
|
|
111
|
+
// or import { findLockFile } from '@visulima/package/package-manager';
|
|
112
|
+
|
|
113
|
+
const lockFile = await findLockFile(); // => /Users/../Projects/visulima/packages/package/package-lock.json
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### findPackageManager
|
|
117
|
+
|
|
118
|
+
Finds the package manager used in a project based on the presence of lock files or package.json configuration.
|
|
119
|
+
|
|
120
|
+
If found, returns the package manager and the path to the lock file or package.json.
|
|
121
|
+
|
|
122
|
+
Throws an error if no lock file or package.json is found.
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import { findPackageManager } from "@visulima/package";
|
|
126
|
+
// or import { findPackageManager } from '@visulima/package/package-manager';
|
|
127
|
+
|
|
128
|
+
const { packageManager, path } = findPackageManager(); // => { packageManager: 'npm', path: '/Users/../Projects/visulima/packages/package' }
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### getPackageManagerVersion
|
|
132
|
+
|
|
133
|
+
Retrieves the version of the specified package manager.
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import { getPackageManagerVersion } from "@visulima/package";
|
|
137
|
+
// or import { getPackageManagerVersion } from '@visulima/package/package-manager';
|
|
138
|
+
|
|
139
|
+
const version = await getPackageManagerVersion("npm"); // => 7.5.4
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### findTSConfig
|
|
143
|
+
|
|
144
|
+
Retrieves the TSConfig by searching for the "tsconfig.json" file from a given current working directory.
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
import { findTSConfig } from "@visulima/package";
|
|
148
|
+
// or import { findTSConfig } from '@visulima/package/tsconfig';
|
|
149
|
+
|
|
150
|
+
const tsconfig = await findTSConfig(); // => { path: "/Users/../Projects/visulima/packages/package/tsconfig.json", config: { compilerOptions: { ... } } }
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### writeTSConfig
|
|
154
|
+
|
|
155
|
+
Writes the provided TypeScript configuration object to a tsconfig.json file.
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
import { writeTSConfig } from '@visulima/package';
|
|
159
|
+
// or import { writeTSConfig } from '@visulima/package/tsconfig';
|
|
160
|
+
|
|
161
|
+
writeTSConfig({ compilerOptions: { ... } }/* ,{ cwd: "./" }*/);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Supported Node.js Versions
|
|
165
|
+
|
|
166
|
+
Libraries in this ecosystem make the best effort to track [Node.js’ release schedule](https://github.com/nodejs/release#release-schedule).
|
|
167
|
+
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).
|
|
168
|
+
|
|
169
|
+
## Contributing
|
|
170
|
+
|
|
171
|
+
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) guild.
|
|
172
|
+
|
|
173
|
+
> **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.
|
|
174
|
+
|
|
175
|
+
## Credits
|
|
176
|
+
|
|
177
|
+
- [Daniel Bannert](https://github.com/prisis)
|
|
178
|
+
- [All Contributors](https://github.com/visulima/visulima/graphs/contributors)
|
|
179
|
+
|
|
180
|
+
## License
|
|
181
|
+
|
|
182
|
+
The visulima package is open-sourced software licensed under the [MIT][license-url]
|
|
183
|
+
|
|
184
|
+
[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
|
|
185
|
+
[typescript-url]: "typescript"
|
|
186
|
+
[license-image]: https://img.shields.io/npm/l/@visulima/package?color=blueviolet&style=for-the-badge
|
|
187
|
+
[license-url]: LICENSE.md "license"
|
|
188
|
+
[npm-image]: https://img.shields.io/npm/v/@visulima/package/latest.svg?style=for-the-badge&logo=npm
|
|
189
|
+
[npm-url]: https://www.npmjs.com/package/@visulima/package/v/latest "npm"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { a, b } from './chunk-C7FQQQI6.js';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
3
|
+
import { mkdir } from 'fs/promises';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
import { findUp } from 'find-up';
|
|
6
|
+
import { parsePackage } from 'read-pkg';
|
|
7
|
+
export { parsePackage as c } from 'read-pkg';
|
|
8
|
+
|
|
9
|
+
var J=async(e=void 0)=>{let o=await findUp("package.json",{...e&&{cwd:e},allowSymlinks:!1,type:"file"});if(!o)throw new Error("Could not find package.json");return {packageJson:parsePackage(readFileSync(o,"utf8"),{normalize:!0}),path:o}},h=async(e,o={})=>{let r=a(o.cwd??process.cwd()),i=join(r,"package.json");await mkdir(r,{recursive:!0}),await b(i,e,o);};
|
|
10
|
+
|
|
11
|
+
export { J as a, h as b };
|
|
12
|
+
//# sourceMappingURL=out.js.map
|
|
13
|
+
//# sourceMappingURL=chunk-7TF75EA4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/package-json.ts"],"names":["readFileSync","mkdir","join","findUp","parsePackage","findPackageJson","cwd","filePath","writePackageJson","data","options","directory","to_path_default","path","writeJsonFile"],"mappings":"0CAAA,OAAS,gBAAAA,MAAoB,KAC7B,OAAS,SAAAC,MAAa,cACtB,OAAS,QAAAC,MAAY,OAGrB,OAAS,UAAAC,MAAc,UAEvB,OAAS,gBAAAC,MAAoB,WA2D7B,OAAyB,gBAAhBA,MAAwC,WAtC1C,IAAMC,EAAkB,MAAOC,EAAsB,SAA6C,CACrG,IAAMC,EAAW,MAAMJ,EAAO,eAAgB,CAC1C,GAAIG,GAAO,CAAE,IAAAA,CAAI,EACjB,cAAe,GACf,KAAM,MACV,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAI,MAAM,6BAA6B,EAGjD,MAAO,CAEH,YAAaH,EAAaJ,EAAaO,EAAU,MAAM,EAAG,CAAE,UAAW,EAAK,CAAC,EAC7E,KAAMA,CACV,CACJ,EAYaC,EAAmB,MAAOC,EAAyCC,EAAmD,CAAC,IAAqB,CACrJ,IAAMC,EAAYC,EAAOF,EAAQ,KAAO,QAAQ,IAAI,CAAC,EAC/CG,EAAOX,EAAKS,EAAW,cAAc,EAG3C,MAAMV,EAAMU,EAAW,CAAE,UAAW,EAAK,CAAC,EAE1C,MAAMG,EAAcD,EAAMJ,EAAMC,CAAO,CAC3C","sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { mkdir } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\nimport type { Options } from \"find-up\";\nimport { findUp } from \"find-up\";\nimport type { NormalizedPackageJson, PackageJson } from \"read-pkg\";\nimport { parsePackage } from \"read-pkg\";\n\nimport toPath from \"./utils/to-path\";\nimport type { WriteOptions } from \"./utils/write-json\";\nimport { writeJsonFile } from \"./utils/write-json\";\n\nexport type { NormalizedPackageJson } from \"read-pkg\";\n\nexport type NormalizedReadResult = {\n packageJson: NormalizedPackageJson;\n path: string;\n};\n\n/**\n * An asynchronous function to find the package.json file in the specified directory or its parent directories.\n *\n * @param cwd - The current working directory. The type of `cwd` is part of an `Options` type, specifically `Options[\"cwd\"]`.\n * @returns A `Promise` that resolves to an object containing the parsed package.json data and the file path.\n * The type of the returned promise is `Promise<NormalizedReadResult>`.\n * @throws An `Error` if the package.json file cannot be found.\n */\nexport const findPackageJson = async (cwd: Options[\"cwd\"] = undefined): Promise<NormalizedReadResult> => {\n const filePath = await findUp(\"package.json\", {\n ...(cwd && { cwd }),\n allowSymlinks: false,\n type: \"file\",\n });\n\n if (!filePath) {\n throw new Error(\"Could not find package.json\");\n }\n\n return {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n packageJson: parsePackage(readFileSync(filePath, \"utf8\"), { normalize: true }),\n path: filePath,\n };\n};\n\n/**\n * An asynchronous function to write the package.json file with the given data.\n *\n * @param data - The package.json data to write. The data is an intersection type of `PackageJson` and a record where keys are `string` and values can be any type.\n * @param options - Optional. The options for writing the package.json. If not provided, an empty object will be used `{}`.\n * This is an intersection type of `WriteOptions` and a record with an optional `cwd` key which type is `Options[\"cwd\"]`.\n * `cwd` represents the current working directory. If not specified, the default working directory will be used.\n * @returns A `Promise` that resolves once the package.json file has been written. The type of the returned promise is `Promise<void>`.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const writePackageJson = async (data: PackageJson & Record<string, any>, options: WriteOptions & { cwd?: Options[\"cwd\"] } = {}): Promise<void> => {\n const directory = toPath(options.cwd ?? process.cwd());\n const path = join(directory, \"package.json\");\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n await mkdir(directory, { recursive: true });\n\n await writeJsonFile(path, data, options);\n};\n\nexport { parsePackage as parsePackageJson } from \"read-pkg\";\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
2
|
+
import { existsSync } from 'fs';
|
|
3
|
+
import { writeFile, readFile } from 'fs/promises';
|
|
4
|
+
import m from 'detect-indent';
|
|
5
|
+
|
|
6
|
+
var l=e=>e instanceof URL?fileURLToPath(e):e,w=l;var p=async(e,n)=>{let t=existsSync(e)?await readFile(e,"utf8"):void 0,i=n.indent??(t?m(t).indent:2),r=n.newline===!0?`
|
|
7
|
+
`:n.newline===!1?"":n.newline??(t?t.endsWith(`
|
|
8
|
+
`)?`
|
|
9
|
+
`:"":`
|
|
10
|
+
`);return {indent:i,newline:r}},v=async(e,n,t={})=>{let i=await p(e,t),r=JSON.stringify(n,void 0,i.indent);r+=i.newline,await writeFile(e,r);};
|
|
11
|
+
|
|
12
|
+
export { w as a, v as b };
|
|
13
|
+
//# sourceMappingURL=out.js.map
|
|
14
|
+
//# sourceMappingURL=chunk-C7FQQQI6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/to-path.ts","../src/utils/write-json.ts"],"names":["fileURLToPath","toPath","urlOrPath","to_path_default","existsSync","readFile","writeFile","detectIndent","resolveWriteOptions","path","options","file","indent","newline","writeJsonFile","data","resolvedOptions","content"],"mappings":"AAAA,OAAS,iBAAAA,MAAqB,MAE9B,IAAMC,EAAUC,GAAqCA,aAAqB,IAAMF,EAAcE,CAAS,EAAIA,EAEpGC,EAAQF,ECJf,OAAS,cAAAG,MAAkB,KAC3B,OAAS,YAAAC,EAAU,aAAAC,MAAiB,cAEpC,OAAOC,MAAkB,gBAQzB,IAAMC,EAAsB,MAAOC,EAAcC,IAAyD,CAEtG,IAAMC,EAAOP,EAAWK,CAAI,EAAI,MAAMJ,EAASI,EAAM,MAAM,EAAI,OACzDG,EAASF,EAAQ,SAAWC,EAAOJ,EAAaI,CAAI,EAAE,OAAS,GAC/DE,EAAUH,EAAQ,UAAY,GAAO;AAAA,EAAOA,EAAQ,UAAY,GAAQ,GAAKA,EAAQ,UAAYC,EAAQA,EAAK,SAAS;AAAA,CAAI,EAAI;AAAA,EAAO,GAAM;AAAA,GAElJ,MAAO,CACH,OAAAC,EACA,QAAAC,CACJ,CACJ,EAQaC,EAAgB,MAAOL,EAAcM,EAAyCL,EAAwB,CAAC,IAAqB,CACrI,IAAMM,EAAkB,MAAMR,EAAoBC,EAAMC,CAAO,EAE3DO,EAAU,KAAK,UAAUF,EAAM,OAAWC,EAAgB,MAAM,EACpEC,GAAWD,EAAgB,QAG3B,MAAMV,EAAUG,EAAMQ,CAAO,CACjC","sourcesContent":["import { fileURLToPath } from \"node:url\";\n\nconst toPath = (urlOrPath: URL | string): string => (urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath);\n\nexport default toPath;\n","import { existsSync } from \"node:fs\";\nimport { readFile, writeFile } from \"node:fs/promises\";\n\nimport detectIndent from \"detect-indent\";\nimport type { PackageJson } from \"read-pkg\";\n\ntype ResolvedWriteOptions = {\n indent: number | string;\n newline: string;\n};\n\nconst resolveWriteOptions = async (path: string, options: WriteOptions): Promise<ResolvedWriteOptions> => {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n const file = existsSync(path) ? await readFile(path, \"utf8\") : undefined;\n const indent = options.indent ?? (file ? detectIndent(file).indent : 2);\n const newline = options.newline === true ? \"\\n\" : options.newline === false ? \"\" : options.newline ?? (file ? (file.endsWith(\"\\n\") ? \"\\n\" : \"\") : \"\\n\");\n\n return {\n indent,\n newline,\n };\n};\n\nexport type WriteOptions = {\n indent?: number | string;\n newline?: boolean | string;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const writeJsonFile = async (path: string, data: PackageJson & Record<string, any>, options: WriteOptions = {}): Promise<void> => {\n const resolvedOptions = await resolveWriteOptions(path, options);\n\n let content = JSON.stringify(data, undefined, resolvedOptions.indent);\n content += resolvedOptions.newline;\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n await writeFile(path, content);\n};\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { a, b } from './chunk-C7FQQQI6.js';
|
|
2
|
+
import { mkdir } from 'fs/promises';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { getTsconfig } from 'get-tsconfig';
|
|
5
|
+
|
|
6
|
+
var C=async t=>{let o=await getTsconfig(t===void 0?void 0:a(t),"tsconfig.json");if(o===null)throw new Error("Could not find tsconfig.json");return o},T=async(t,o={})=>{let n=a(o.cwd??process.cwd()),s=join(n,"tsconfig.json");await mkdir(n,{recursive:!0}),await b(s,t,o);};
|
|
7
|
+
|
|
8
|
+
export { C as a, T as b };
|
|
9
|
+
//# sourceMappingURL=out.js.map
|
|
10
|
+
//# sourceMappingURL=chunk-HN5TULBQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tsconfig.ts"],"names":["mkdir","join","getTsconfig","findTSConfig","cwd","config","to_path_default","writeTSConfig","tsConfig","options","directory","path","writeJsonFile"],"mappings":"+CAAA,OAAS,SAAAA,MAAa,cACtB,OAAS,QAAAC,MAAY,OAGrB,OAAS,eAAAC,MAAmB,eAgBrB,IAAMC,EAAe,MAAOC,GAAgD,CAG/E,IAAMC,EAAS,MAAMH,EAAYE,IAAQ,OAAY,OAAYE,EAAOF,CAAG,EAAG,eAAe,EAE7F,GAAIC,IAAW,KACX,MAAM,IAAI,MAAM,8BAA8B,EAGlD,OAAOA,CACX,EAWaE,EAAgB,MAAOC,EAAwBC,EAAiD,CAAC,IAAqB,CAC/H,IAAMC,EAAYJ,EAAOG,EAAQ,KAAO,QAAQ,IAAI,CAAC,EAC/CE,EAAOV,EAAKS,EAAW,eAAe,EAG5C,MAAMV,EAAMU,EAAW,CAAE,UAAW,EAAK,CAAC,EAE1C,MAAME,EAAcD,EAAMH,EAAUC,CAAO,CAC/C","sourcesContent":["import { mkdir } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\nimport type { TsConfigJson, TsConfigResult } from \"get-tsconfig\";\nimport { getTsconfig } from \"get-tsconfig\";\n\nimport toPath from \"./utils/to-path\";\nimport type { WriteOptions } from \"./utils/write-json\";\nimport { writeJsonFile } from \"./utils/write-json\";\n\n/**\n * An asynchronous function that retrieves the TSConfig by searching for the \"tsconfig.json\" file from a given\n * current working directory.\n *\n * @param cwd - Optional. The current working directory from which to search for the \"tsconfig.json\" file.\n * The type of `cwd` is `string`.\n * @returns A `Promise` that resolves to the TSConfig result object.\n * The return type of the function is `Promise<TsConfigResult>`.\n * @throws An `Error` when the \"tsconfig.json\" file is not found.\n */\nexport const findTSConfig = async (cwd?: URL | string): Promise<TsConfigResult> => {\n // wrong typing in get-tsconfig\n // eslint-disable-next-line @typescript-eslint/await-thenable\n const config = await getTsconfig(cwd === undefined ? undefined : toPath(cwd), \"tsconfig.json\");\n\n if (config === null) {\n throw new Error(\"Could not find tsconfig.json\");\n }\n\n return config;\n};\n\n/**\n * An asynchronous function that writes the provided TypeScript configuration object to a tsconfig.json file.\n *\n * @param tsConfig - The TypeScript configuration object to write. The type of `tsConfig` is `TsConfigJson`.\n * @param options - Optional. The write options and the current working directory. The type of `options` is an\n * intersection type of `WriteOptions` and a Record type with an optional `cwd` key of type `string`.\n * @returns A `Promise` that resolves when the tsconfig.json file has been written.\n * The return type of function is `Promise<void>`.\n */\nexport const writeTSConfig = async (tsConfig: TsConfigJson, options: WriteOptions & { cwd?: URL | string } = {}): Promise<void> => {\n const directory = toPath(options.cwd ?? process.cwd());\n const path = join(directory, \"tsconfig.json\");\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n await mkdir(directory, { recursive: true });\n\n await writeJsonFile(path, tsConfig, options);\n};\n\nexport type { TsConfigJson, TsConfigJsonResolved } from \"get-tsconfig\";\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { b } from './chunk-KWZ4YGPC.js';
|
|
2
|
+
import { readFileSync, existsSync } from 'fs';
|
|
3
|
+
import { dirname, join } from 'path';
|
|
4
|
+
import { findUp } from 'find-up';
|
|
5
|
+
import l from 'strip-json-comments';
|
|
6
|
+
|
|
7
|
+
var j=async e=>{let r=await findUp(["lerna.json","turbo.json"],{allowSymlinks:!1,type:"file",...e&&{cwd:e}});if(r&&r.endsWith("lerna.json")){let o=JSON.parse(l(readFileSync(r,"utf8")));if(o.useWorkspaces||o.packages)return {path:dirname(r),strategy:"lerna"}}let s=r&&r.endsWith("turbo.json");try{let{packageManager:o,path:n}=await b(e);if(["npm","yarn"].includes(o)){let t=join(n,"package.json");if(existsSync(t)&&readFileSync(join(n,"package.json"),"utf8").includes("workspaces"))return {path:n,strategy:s?"turbo":o}}else if(o==="pnpm"){let t=join(n,"pnpm-workspace.yaml");if(existsSync(t))return {path:n,strategy:s?"turbo":"pnpm"}}}catch(o){if(!o.message.includes("Could not find lock file"))throw o}throw new Error(`No monorepo root could be found upwards from the directory ${e} using lerna, yarn, pnpm, or npm as indicators.`)};
|
|
8
|
+
|
|
9
|
+
export { j as a };
|
|
10
|
+
//# sourceMappingURL=out.js.map
|
|
11
|
+
//# sourceMappingURL=chunk-HSXXY5E3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/monorepo.ts"],"names":["existsSync","readFileSync","dirname","join","findUp","stripJsonComments","findMonorepoRoot","cwd","workspaceFilePath","lerna","isTurbo","packageManager","path","findPackageManager","packageJsonFilePath","pnpmWorkspacesFilePath","error"],"mappings":"wCAAA,OAAS,cAAAA,EAAY,gBAAAC,MAAoB,KACzC,OAAS,WAAAC,EAAS,QAAAC,MAAY,OAG9B,OAAS,UAAAC,MAAc,UACvB,OAAOC,MAAuB,sBAsBvB,IAAMC,EAAmB,MAAOC,GAAgD,CACnF,IAAMC,EAAoB,MAAMJ,EAAO,CAAC,aAAc,YAAY,EAAG,CACjE,cAAe,GACf,KAAM,OACN,GAAIG,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAIC,GAAqBA,EAAkB,SAAS,YAAY,EAAG,CAE/D,IAAMC,EAAQ,KAAK,MAAMJ,EAAkBJ,EAAaO,EAAmB,MAAM,CAAC,CAAC,EAEnF,GAAIC,EAAM,eAAiBA,EAAM,SAC7B,MAAO,CACH,KAAMP,EAAQM,CAAiB,EAC/B,SAAU,OACd,CAER,CAEA,IAAME,EAAUF,GAAqBA,EAAkB,SAAS,YAAY,EAE5E,GAAI,CACA,GAAM,CAAE,eAAAG,EAAgB,KAAAC,CAAK,EAAI,MAAMC,EAAmBN,CAAG,EAE7D,GAAI,CAAC,MAAO,MAAM,EAAE,SAASI,CAAc,EAAG,CAC1C,IAAMG,EAAsBX,EAAKS,EAAM,cAAc,EAGrD,GAAIZ,EAAWc,CAAmB,GAEVb,EAAaE,EAAKS,EAAM,cAAc,EAAG,MAAM,EAEnD,SAAS,YAAY,EACjC,MAAO,CACH,KAAAA,EACA,SAAUF,EAAU,QAAWC,CACnC,CAGZ,SAAWA,IAAmB,OAAQ,CAClC,IAAMI,EAAyBZ,EAAKS,EAAM,qBAAqB,EAG/D,GAAIZ,EAAWe,CAAsB,EACjC,MAAO,CACH,KAAAH,EACA,SAAUF,EAAU,QAAU,MAClC,CAER,CAEJ,OAASM,EAAY,CAGjB,GAAI,CAACA,EAAM,QAAQ,SAAS,0BAA0B,EAClD,MAAMA,CAEd,CAEA,MAAM,IAAI,MAAM,8DAA8DT,CAAa,iDAAiD,CAChJ","sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\n\nimport type { Options } from \"find-up\";\nimport { findUp } from \"find-up\";\nimport stripJsonComments from \"strip-json-comments\";\n\nimport { findPackageManager } from \"./package-manager\";\n\nexport type Strategy = \"lerna\" | \"npm\" | \"pnpm\" | \"turbo\" | \"yarn\";\n\nexport interface RootMonorepo<T extends Strategy = Strategy> {\n path: string;\n strategy: T;\n}\n\n/**\n * An asynchronous function to find the root directory path and strategy for a monorepo based on\n * the given current working directory (cwd).\n *\n * @param cwd - The current working directory. The type of `cwd` is part of an `Options` type, specifically `Options[\"cwd\"]`.\n * Default is undefined.\n * @returns A `Promise` that resolves to the root directory path and strategy for the monorepo.\n * The type of the returned promise is `Promise<RootMonorepo>`.\n * @throws An `Error` if no monorepo root can be found using lerna, yarn, pnpm, or npm as indicators.\n */\n// eslint-disable-next-line sonarjs/cognitive-complexity\nexport const findMonorepoRoot = async (cwd?: Options[\"cwd\"]): Promise<RootMonorepo> => {\n const workspaceFilePath = await findUp([\"lerna.json\", \"turbo.json\"], {\n allowSymlinks: false,\n type: \"file\",\n ...(cwd && { cwd }),\n });\n\n if (workspaceFilePath && workspaceFilePath.endsWith(\"lerna.json\")) {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n const lerna = JSON.parse(stripJsonComments(readFileSync(workspaceFilePath, \"utf8\"))) as { packages?: string[]; useWorkspaces?: boolean };\n\n if (lerna.useWorkspaces || lerna.packages) {\n return {\n path: dirname(workspaceFilePath),\n strategy: \"lerna\",\n };\n }\n }\n\n const isTurbo = workspaceFilePath && workspaceFilePath.endsWith(\"turbo.json\");\n\n try {\n const { packageManager, path } = await findPackageManager(cwd);\n\n if ([\"npm\", \"yarn\"].includes(packageManager)) {\n const packageJsonFilePath = join(path, \"package.json\");\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(packageJsonFilePath)) {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n const packageJson = readFileSync(join(path, \"package.json\"), \"utf8\");\n\n if (packageJson.includes(\"workspaces\")) {\n return {\n path,\n strategy: isTurbo ? \"turbo\" : (packageManager as \"npm\" | \"yarn\"),\n };\n }\n }\n } else if (packageManager === \"pnpm\") {\n const pnpmWorkspacesFilePath = join(path, \"pnpm-workspace.yaml\");\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(pnpmWorkspacesFilePath)) {\n return {\n path,\n strategy: isTurbo ? \"turbo\" : \"pnpm\",\n };\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n // Skip this error to show the error message from the next block\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\n if (!error.message.includes(\"Could not find lock file\")) {\n throw error;\n }\n }\n\n throw new Error(`No monorepo root could be found upwards from the directory ${cwd as string} using lerna, yarn, pnpm, or npm as indicators.`);\n};\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import { existsSync, readFileSync } from 'fs';
|
|
3
|
+
import { join, dirname } from 'path';
|
|
4
|
+
import { findUp } from 'find-up';
|
|
5
|
+
import { parsePackage, readPackage } from 'read-pkg';
|
|
6
|
+
|
|
7
|
+
var g=["yarn.lock","package-lock.json","pnpm-lock.yaml","npm-shrinkwrap.json","bun.lockb"],b=async n=>{let a=await findUp(g,{allowSymlinks:!1,type:"file",...n&&{cwd:n}});if(!a)throw new Error("Could not find lock file");return a},j=async n=>{let a=await findUp(e=>{let o;if(g.forEach(i=>{!o&&existsSync(join(e,i))&&(o=join(e,i));}),o)return o;let r=join(e,"package.json");if(existsSync(r)&&parsePackage(readFileSync(r,"utf8")).packageManager!==void 0)return r},{...n&&{cwd:n},allowSymlinks:!1});if(!a)throw new Error("Could not find lock file");if(a.endsWith("package.json")){let e=await readPackage({cwd:dirname(a),normalize:!0});if(e.packageManager){let r=["npm","yarn","pnpm","bun"].find(i=>e.packageManager.startsWith(i));if(r)return {packageManager:r,path:dirname(a)}}}if(a.endsWith("yarn.lock"))return {packageManager:"yarn",path:dirname(a)};if(a.endsWith("package-lock.json")||a.endsWith("npm-shrinkwrap.json"))return {packageManager:"npm",path:dirname(a)};if(a.endsWith("pnpm-lock.yaml"))return {packageManager:"pnpm",path:dirname(a)};if(a.endsWith("bun.lockb"))return {packageManager:"bun",path:dirname(a)};throw new Error("Could not find lock file")},x=n=>execSync(`${n} --version`).toString("utf8").trim();
|
|
8
|
+
|
|
9
|
+
export { b as a, j as b, x as c };
|
|
10
|
+
//# sourceMappingURL=out.js.map
|
|
11
|
+
//# sourceMappingURL=chunk-KWZ4YGPC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/package-manager.ts"],"names":["execSync","existsSync","readFileSync","dirname","join","findUp","parsePackage","readPackage","lockFileNames","findLockFile","cwd","filePath","findPackageManager","foundFile","directory","lockFile","lockFileName","packageJsonFilePath","packageJson","foundPackageManager","prefix","getPackageManagerVersion","name"],"mappings":"AAAA,OAAS,YAAAA,MAAgB,gBACzB,OAAS,cAAAC,EAAY,gBAAAC,MAAoB,KACzC,OAAS,WAAAC,EAAS,QAAAC,MAAY,OAG9B,OAAS,UAAAC,MAAc,UACvB,OAAS,gBAAAC,EAAc,eAAAC,MAAmB,WAE1C,IAAMC,EAAgB,CAAC,YAAa,oBAAqB,iBAAkB,sBAAuB,WAAW,EAWhGC,EAAe,MAAOC,GAA0C,CACzE,IAAMC,EAAW,MAAMN,EAAOG,EAAe,CACzC,cAAe,GACf,KAAM,OACN,GAAIE,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,OAAOA,CACX,EAqBaC,EAAqB,MAAOF,GAAwD,CAC7F,IAAMG,EAAY,MAAMR,EACnBS,GAAc,CACX,IAAIC,EASJ,GAPAP,EAAc,QAASQ,GAAiB,CAEhC,CAACD,GAAYd,EAAWG,EAAKU,EAAWE,CAAY,CAAC,IACrDD,EAAWX,EAAKU,EAAWE,CAAY,EAE/C,CAAC,EAEGD,EACA,OAAOA,EAGX,IAAME,EAAsBb,EAAKU,EAAW,cAAc,EAE1D,GAAIb,EAAWgB,CAAmB,GAEVX,EAAaJ,EAAae,EAAqB,MAAM,CAAC,EAE1D,iBAAmB,OAC/B,OAAOA,CAKnB,EACA,CACI,GAAIP,GAAO,CAAE,IAAAA,CAAI,EACjB,cAAe,EACnB,CACJ,EAEA,GAAI,CAACG,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,GAAIA,EAAU,SAAS,cAAc,EAAG,CACpC,IAAMK,EAAc,MAAMX,EAAY,CAAE,IAAKJ,EAAQU,CAAS,EAAG,UAAW,EAAK,CAAC,EAElF,GAAIK,EAAY,eAAgB,CAE5B,IAAMC,EADsB,CAAC,MAAO,OAAQ,OAAQ,KAAK,EACT,KAAMC,GAAYF,EAAY,eAA0B,WAAWE,CAAM,CAAC,EAE1H,GAAID,EACA,MAAO,CACH,eAAgBA,EAChB,KAAMhB,EAAQU,CAAS,CAC3B,CAER,CACJ,CAEA,GAAIA,EAAU,SAAS,WAAW,EAC9B,MAAO,CACH,eAAgB,OAChB,KAAMV,EAAQU,CAAS,CAC3B,EAGJ,GAAIA,EAAU,SAAS,mBAAmB,GAAKA,EAAU,SAAS,qBAAqB,EACnF,MAAO,CACH,eAAgB,MAChB,KAAMV,EAAQU,CAAS,CAC3B,EAGJ,GAAIA,EAAU,SAAS,gBAAgB,EACnC,MAAO,CACH,eAAgB,OAChB,KAAMV,EAAQU,CAAS,CAC3B,EAGJ,GAAIA,EAAU,SAAS,WAAW,EAC9B,MAAO,CACH,eAAgB,MAChB,KAAMV,EAAQU,CAAS,CAC3B,EAGJ,MAAM,IAAI,MAAM,0BAA0B,CAC9C,EAQaQ,EAA4BC,GAAyBtB,EAAS,GAAGsB,CAAI,YAAY,EAAE,SAAS,MAAM,EAAE,KAAK","sourcesContent":["import { execSync } from \"node:child_process\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\n\nimport type { Options } from \"find-up\";\nimport { findUp } from \"find-up\";\nimport { parsePackage, readPackage } from \"read-pkg\";\n\nconst lockFileNames = [\"yarn.lock\", \"package-lock.json\", \"pnpm-lock.yaml\", \"npm-shrinkwrap.json\", \"bun.lockb\"] as const;\n\n/**\n * An asynchronous function that finds a lock file in the specified directory or any of its parent directories.\n *\n * @param cwd - Optional. The directory path to start the search from. The type of `cwd` is part of an `Options` type,\n * specifically `Options[\"cwd\"]`. Defaults to the current working directory.\n * @returns A `Promise` that resolves with the path of the found lock file.\n * The type of the returned promise is `Promise<string>`.\n * @throws An `Error` if no lock file is found.\n */\nexport const findLockFile = async (cwd?: Options[\"cwd\"]): Promise<string> => {\n const filePath = await findUp(lockFileNames, {\n allowSymlinks: false,\n type: \"file\",\n ...(cwd && { cwd }),\n });\n\n if (!filePath) {\n throw new Error(\"Could not find lock file\");\n }\n\n return filePath;\n};\n\nexport type PackageManager = \"bun\" | \"npm\" | \"pnpm\" | \"yarn\";\n\nexport type PackageManagerResult = {\n packageManager: PackageManager;\n path: string;\n};\n\n/**\n * An asynchronous function that finds the package manager used in a project based on the presence of lock files\n * or package.json configuration. If found, it returns the package manager and the path to the lock file or package.json.\n * Throws an error if no lock file or package.json is found.\n *\n * @param cwd - Optional. The current working directory to start the search from. The type of `cwd` is part of an `Options`\n * type, specifically `Options[\"cwd\"]`.\n * @returns A `Promise` that resolves to an object containing the package manager and path.\n * The return type of the function is `Promise<PackageManagerResult>`.\n * @throws An `Error` if no lock file or package.json is found.\n */\n// eslint-disable-next-line sonarjs/cognitive-complexity\nexport const findPackageManager = async (cwd?: Options[\"cwd\"]): Promise<PackageManagerResult> => {\n const foundFile = await findUp(\n (directory) => {\n let lockFile: string | undefined;\n\n lockFileNames.forEach((lockFileName) => {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (!lockFile && existsSync(join(directory, lockFileName))) {\n lockFile = join(directory, lockFileName);\n }\n });\n\n if (lockFile) {\n return lockFile;\n }\n\n const packageJsonFilePath = join(directory, \"package.json\");\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(packageJsonFilePath)) {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n const packageJson = parsePackage(readFileSync(packageJsonFilePath, \"utf8\"));\n\n if (packageJson.packageManager !== undefined) {\n return packageJsonFilePath;\n }\n }\n\n return undefined;\n },\n {\n ...(cwd && { cwd }),\n allowSymlinks: false,\n },\n );\n\n if (!foundFile) {\n throw new Error(\"Could not find lock file\");\n }\n\n if (foundFile.endsWith(\"package.json\")) {\n const packageJson = await readPackage({ cwd: dirname(foundFile), normalize: true });\n\n if (packageJson.packageManager) {\n const packageManagerNames = [\"npm\", \"yarn\", \"pnpm\", \"bun\"] as const;\n const foundPackageManager = packageManagerNames.find((prefix) => (packageJson.packageManager as string).startsWith(prefix));\n\n if (foundPackageManager) {\n return {\n packageManager: foundPackageManager,\n path: dirname(foundFile),\n };\n }\n }\n }\n\n if (foundFile.endsWith(\"yarn.lock\")) {\n return {\n packageManager: \"yarn\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"package-lock.json\") || foundFile.endsWith(\"npm-shrinkwrap.json\")) {\n return {\n packageManager: \"npm\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"pnpm-lock.yaml\")) {\n return {\n packageManager: \"pnpm\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"bun.lockb\")) {\n return {\n packageManager: \"bun\",\n path: dirname(foundFile),\n };\n }\n\n throw new Error(\"Could not find lock file\");\n};\n\n/**\n * Function that retrieves the version of the specified package manager.\n *\n * @param name - The name of the package manager. The type of `name` is `string`.\n * @returns The version of the package manager. The return type of the function is `string`.\n */\nexport const getPackageManagerVersion = (name: string): string => execSync(`${name} --version`).toString(\"utf8\").trim();\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { a } from './chunk-KWZ4YGPC.js';
|
|
2
|
+
import { dirname } from 'path';
|
|
3
|
+
import { findUp } from 'find-up';
|
|
4
|
+
|
|
5
|
+
var c=async o=>{try{let a$1=await a(o);return dirname(a$1)}catch{}let t=await findUp(".git/config",{...o&&{cwd:o},allowSymlinks:!1,type:"file"});if(t)return dirname(dirname(t));let r=await findUp("package.json",{...o&&{cwd:o},allowSymlinks:!1,type:"file"});if(r)return dirname(r);throw new Error("Could not find root directory")};
|
|
6
|
+
|
|
7
|
+
export { c as a };
|
|
8
|
+
//# sourceMappingURL=out.js.map
|
|
9
|
+
//# sourceMappingURL=chunk-MYRZ7SEG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/package.ts"],"names":["dirname","findUp","findPackageRoot","cwd","lockFile","findLockFile","gitConfig","filePath"],"mappings":"wCAAA,OAAS,WAAAA,MAAe,OAGxB,OAAS,UAAAC,MAAc,UAgBhB,IAAMC,EAAkB,MAAOC,GAA0C,CAE5E,GAAI,CACA,IAAMC,EAAW,MAAMC,EAAaF,CAAG,EAEvC,OAAOH,EAAQI,CAAQ,CAC3B,MAAQ,CAER,CAGA,IAAME,EAAY,MAAML,EAAO,cAAe,CAC1C,GAAIE,GAAO,CAAE,IAAAA,CAAI,EACjB,cAAe,GACf,KAAM,MACV,CAAC,EAED,GAAIG,EACA,OAAON,EAAQA,EAAQM,CAAS,CAAC,EAIrC,IAAMC,EAAW,MAAMN,EAAO,eAAgB,CAC1C,GAAIE,GAAO,CAAE,IAAAA,CAAI,EACjB,cAAe,GACf,KAAM,MACV,CAAC,EAED,GAAII,EACA,OAAOP,EAAQO,CAAQ,EAG3B,MAAM,IAAI,MAAM,+BAA+B,CACnD","sourcesContent":["import { dirname } from \"node:path\";\n\nimport type { Options } from \"find-up\";\nimport { findUp } from \"find-up\";\n\nimport { findLockFile } from \"./package-manager\";\n\n/**\n * An asynchronous function that finds the root directory of a project based on certain lookup criteria.\n *\n * @param cwd - Optional. The current working directory to start the search from. The type of `cwd` is `string`.\n * @returns A `Promise` that resolves to the path of the root directory. The type of the returned promise is `Promise<string>`.\n * @throws An `Error` if the root directory could not be found.\n *\n * @example\n * const rootDirectory = await findPackageRoot();\n * console.log(rootDirectory); // '/path/to/project'\n */\n// eslint-disable-next-line import/prefer-default-export\nexport const findPackageRoot = async (cwd?: Options[\"cwd\"]): Promise<string> => {\n // Lookdown for lockfile\n try {\n const lockFile = await findLockFile(cwd);\n\n return dirname(lockFile);\n } catch {\n /* empty */\n }\n\n // Lookup for .git/config\n const gitConfig = await findUp(\".git/config\", {\n ...(cwd && { cwd }),\n allowSymlinks: false,\n type: \"file\",\n });\n\n if (gitConfig) {\n return dirname(dirname(gitConfig));\n }\n\n // Lookdown for package.json\n const filePath = await findUp(\"package.json\", {\n ...(cwd && { cwd }),\n allowSymlinks: false,\n type: \"file\",\n });\n\n if (filePath) {\n return dirname(filePath);\n }\n\n throw new Error(\"Could not find root directory\");\n};\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { RootMonorepo, Strategy, findMonorepoRoot } from './monorepo.js';
|
|
2
|
+
export { findPackageRoot } from './package.js';
|
|
3
|
+
export { NormalizedReadResult, findPackageJson, writePackageJson } from './package-json.js';
|
|
4
|
+
export { PackageManager, PackageManagerResult, findLockFile, findPackageManager, getPackageManagerVersion } from './package-manager.js';
|
|
5
|
+
export { findTSConfig, writeTSConfig } from './tsconfig.js';
|
|
6
|
+
export { NormalizedPackageJson, parsePackage as parsePackageJson } from 'read-pkg';
|
|
7
|
+
export { TsConfigJson, TsConfigJsonResolved } from 'get-tsconfig';
|
|
8
|
+
import 'find-up';
|
|
9
|
+
import './write-json-7d6e6751.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { a as findMonorepoRoot } from './chunk-HSXXY5E3.js';
|
|
2
|
+
export { a as findPackageRoot } from './chunk-MYRZ7SEG.js';
|
|
3
|
+
export { a as findPackageJson, c as parsePackageJson, b as writePackageJson } from './chunk-7TF75EA4.js';
|
|
4
|
+
export { a as findLockFile, b as findPackageManager, c as getPackageManagerVersion } from './chunk-KWZ4YGPC.js';
|
|
5
|
+
export { a as findTSConfig, b as writeTSConfig } from './chunk-HN5TULBQ.js';
|
|
6
|
+
import './chunk-C7FQQQI6.js';
|
|
7
|
+
//# sourceMappingURL=out.js.map
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Options } from 'find-up';
|
|
2
|
+
|
|
3
|
+
type Strategy = "lerna" | "npm" | "pnpm" | "turbo" | "yarn";
|
|
4
|
+
interface RootMonorepo<T extends Strategy = Strategy> {
|
|
5
|
+
path: string;
|
|
6
|
+
strategy: T;
|
|
7
|
+
}
|
|
8
|
+
declare const findMonorepoRoot: (cwd?: Options["cwd"]) => Promise<RootMonorepo>;
|
|
9
|
+
|
|
10
|
+
export { RootMonorepo, Strategy, findMonorepoRoot };
|
package/dist/monorepo.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Options } from 'find-up';
|
|
2
|
+
import { NormalizedPackageJson, PackageJson } from 'read-pkg';
|
|
3
|
+
export { NormalizedPackageJson, parsePackage as parsePackageJson } from 'read-pkg';
|
|
4
|
+
import { W as WriteOptions } from './write-json-7d6e6751.js';
|
|
5
|
+
|
|
6
|
+
type NormalizedReadResult = {
|
|
7
|
+
packageJson: NormalizedPackageJson;
|
|
8
|
+
path: string;
|
|
9
|
+
};
|
|
10
|
+
declare const findPackageJson: (cwd?: Options["cwd"]) => Promise<NormalizedReadResult>;
|
|
11
|
+
declare const writePackageJson: (data: PackageJson & Record<string, any>, options?: WriteOptions & {
|
|
12
|
+
cwd?: Options["cwd"];
|
|
13
|
+
}) => Promise<void>;
|
|
14
|
+
|
|
15
|
+
export { NormalizedReadResult, findPackageJson, writePackageJson };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Options } from 'find-up';
|
|
2
|
+
|
|
3
|
+
declare const findLockFile: (cwd?: Options["cwd"]) => Promise<string>;
|
|
4
|
+
type PackageManager = "bun" | "npm" | "pnpm" | "yarn";
|
|
5
|
+
type PackageManagerResult = {
|
|
6
|
+
packageManager: PackageManager;
|
|
7
|
+
path: string;
|
|
8
|
+
};
|
|
9
|
+
declare const findPackageManager: (cwd?: Options["cwd"]) => Promise<PackageManagerResult>;
|
|
10
|
+
declare const getPackageManagerVersion: (name: string) => string;
|
|
11
|
+
|
|
12
|
+
export { PackageManager, PackageManagerResult, findLockFile, findPackageManager, getPackageManagerVersion };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/package.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TsConfigResult, TsConfigJson } from 'get-tsconfig';
|
|
2
|
+
export { TsConfigJson, TsConfigJsonResolved } from 'get-tsconfig';
|
|
3
|
+
import { W as WriteOptions } from './write-json-7d6e6751.js';
|
|
4
|
+
|
|
5
|
+
declare const findTSConfig: (cwd?: URL | string) => Promise<TsConfigResult>;
|
|
6
|
+
declare const writeTSConfig: (tsConfig: TsConfigJson, options?: WriteOptions & {
|
|
7
|
+
cwd?: URL | string;
|
|
8
|
+
}) => Promise<void>;
|
|
9
|
+
|
|
10
|
+
export { findTSConfig, writeTSConfig };
|
package/dist/tsconfig.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@visulima/package",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "One Package to rule them all, finds your root-dir, monorepo, package manager or tsconfig.json",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"anolilab",
|
|
7
|
+
"package",
|
|
8
|
+
"pkg-types",
|
|
9
|
+
"find-up-pkg",
|
|
10
|
+
"read-pkg",
|
|
11
|
+
"read-pkg-up",
|
|
12
|
+
"read-tsconfig",
|
|
13
|
+
"tsconfig",
|
|
14
|
+
"get-tsconfig",
|
|
15
|
+
"find-monorepo-root",
|
|
16
|
+
"pkg-up",
|
|
17
|
+
"pkg-dir",
|
|
18
|
+
"package-json",
|
|
19
|
+
"package.json",
|
|
20
|
+
"tsconfig.json",
|
|
21
|
+
"packages",
|
|
22
|
+
"monorepo",
|
|
23
|
+
"pkg-manager",
|
|
24
|
+
"package-manager",
|
|
25
|
+
"find",
|
|
26
|
+
"root"
|
|
27
|
+
],
|
|
28
|
+
"homepage": "https://visulima.com/packages/package",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/visulima/visulima.git",
|
|
32
|
+
"directory": "packages/package"
|
|
33
|
+
},
|
|
34
|
+
"funding": [
|
|
35
|
+
{
|
|
36
|
+
"type": "github",
|
|
37
|
+
"url": "https://github.com/sponsors/prisis"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"type": "consulting",
|
|
41
|
+
"url": "https://anolilab.com/support"
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"author": {
|
|
46
|
+
"name": "Daniel Bannert",
|
|
47
|
+
"email": "d.bannert@anolilab.de"
|
|
48
|
+
},
|
|
49
|
+
"sideEffects": false,
|
|
50
|
+
"type": "module",
|
|
51
|
+
"exports": {
|
|
52
|
+
".": {
|
|
53
|
+
"import": {
|
|
54
|
+
"types": "./dist/index.d.ts",
|
|
55
|
+
"default": "./dist/index.js"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"./monorepo": {
|
|
59
|
+
"import": {
|
|
60
|
+
"types": "./dist/monorepo.d.ts",
|
|
61
|
+
"default": "./dist/monorepo.js"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"./package": {
|
|
65
|
+
"import": {
|
|
66
|
+
"types": "./dist/package.d.ts",
|
|
67
|
+
"default": "./dist/package.js"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"./package-json": {
|
|
71
|
+
"import": {
|
|
72
|
+
"types": "./dist/package-json.d.ts",
|
|
73
|
+
"default": "./dist/package-json.js"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"./package-manager": {
|
|
77
|
+
"import": {
|
|
78
|
+
"types": "./dist/package-manager.d.ts",
|
|
79
|
+
"default": "./dist/package-manager.js"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"./tsconfig": {
|
|
83
|
+
"import": {
|
|
84
|
+
"types": "./dist/tsconfig.d.ts",
|
|
85
|
+
"default": "./dist/tsconfig.js"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"./package.json": "./package.json"
|
|
89
|
+
},
|
|
90
|
+
"module": "dist/index.js",
|
|
91
|
+
"types": "dist/index.d.ts",
|
|
92
|
+
"files": [
|
|
93
|
+
"dist/**",
|
|
94
|
+
"README.md",
|
|
95
|
+
"CHANGELOG.md",
|
|
96
|
+
"LICENSE.md"
|
|
97
|
+
],
|
|
98
|
+
"scripts": {
|
|
99
|
+
"build": "cross-env NODE_ENV=development tsup",
|
|
100
|
+
"build:prod": "cross-env NODE_ENV=production tsup",
|
|
101
|
+
"clean": "rimraf node_modules dist .eslintcache",
|
|
102
|
+
"coverage": "vitest run --coverage",
|
|
103
|
+
"dev": "pnpm run build --watch",
|
|
104
|
+
"lint:eslint": "eslint . --ext js,cjs,mjs,jsx,ts,tsx,json,yaml,yml,md,mdx --max-warnings=0 --config .eslintrc.cjs",
|
|
105
|
+
"lint:eslint:fix": "pnpm run lint:eslint --fix",
|
|
106
|
+
"lint:packagejson": "publint --strict",
|
|
107
|
+
"lint:prettier": "prettier --config=.prettierrc.cjs --check .",
|
|
108
|
+
"lint:prettier:fix": "prettier --config=.prettierrc.cjs --write .",
|
|
109
|
+
"lint:types": "tsc --noEmit",
|
|
110
|
+
"test": "vitest run",
|
|
111
|
+
"test:watch": "vitest"
|
|
112
|
+
},
|
|
113
|
+
"dependencies": {
|
|
114
|
+
"detect-indent": "^7.0.1",
|
|
115
|
+
"find-up": "^6.3.0",
|
|
116
|
+
"get-tsconfig": "^4.7.2",
|
|
117
|
+
"read-pkg": "^8.1.0",
|
|
118
|
+
"strip-json-comments": "^5.0.1"
|
|
119
|
+
},
|
|
120
|
+
"devDependencies": {
|
|
121
|
+
"@anolilab/eslint-config": "^14.0.24",
|
|
122
|
+
"@anolilab/prettier-config": "^5.0.11",
|
|
123
|
+
"@anolilab/semantic-release-preset": "^8.0.0",
|
|
124
|
+
"@babel/core": "^7.23.2",
|
|
125
|
+
"@rushstack/eslint-plugin-security": "^0.7.1",
|
|
126
|
+
"@total-typescript/ts-reset": "^0.5.1",
|
|
127
|
+
"@types/node": "18.17.12",
|
|
128
|
+
"@vitest/coverage-v8": "^0.34.6",
|
|
129
|
+
"cross-env": "^7.0.3",
|
|
130
|
+
"eslint": "^8.51.0",
|
|
131
|
+
"eslint-plugin-deprecation": "^2.0.0",
|
|
132
|
+
"eslint-plugin-etc": "^2.0.3",
|
|
133
|
+
"eslint-plugin-import": "npm:eslint-plugin-i@^2.28.1",
|
|
134
|
+
"eslint-plugin-mdx": "^2.2.0",
|
|
135
|
+
"eslint-plugin-tsdoc": "^0.2.17",
|
|
136
|
+
"eslint-plugin-vitest": "^0.3.2",
|
|
137
|
+
"eslint-plugin-vitest-globals": "^1.4.0",
|
|
138
|
+
"prettier": "^3.0.3",
|
|
139
|
+
"rimraf": "^5.0.5",
|
|
140
|
+
"semantic-release": "^22.0.5",
|
|
141
|
+
"sort-package-json": "^2.6.0",
|
|
142
|
+
"tsup": "^7.2.0",
|
|
143
|
+
"typescript": "^5.2.2",
|
|
144
|
+
"vitest": "^0.34.6"
|
|
145
|
+
},
|
|
146
|
+
"engines": {
|
|
147
|
+
"node": ">=18.* <=20.*"
|
|
148
|
+
},
|
|
149
|
+
"publishConfig": {
|
|
150
|
+
"access": "public",
|
|
151
|
+
"provenance": true
|
|
152
|
+
},
|
|
153
|
+
"anolilab": {
|
|
154
|
+
"eslint-config": {
|
|
155
|
+
"warn_on_unsupported_typescript_version": false,
|
|
156
|
+
"info_on_disabling_jsx_react_rule": false,
|
|
157
|
+
"info_on_disabling_prettier_conflict_rule": false,
|
|
158
|
+
"info_on_disabling_jsonc_sort_keys_rule": false,
|
|
159
|
+
"info_on_disabling_etc_no_deprecated": false
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
"sources": [
|
|
163
|
+
"src/index.ts",
|
|
164
|
+
"src/monorepo.ts",
|
|
165
|
+
"src/package.ts",
|
|
166
|
+
"src/package-json.ts",
|
|
167
|
+
"src/package-manager.ts",
|
|
168
|
+
"src/tsconfig.ts"
|
|
169
|
+
]
|
|
170
|
+
}
|