@visulima/package 3.6.1 → 4.0.1
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 +18 -0
- package/LICENSE.md +0 -116
- package/README.md +153 -51
- package/dist/error.js +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +1 -0
- package/dist/monorepo.js +1 -0
- package/dist/package-json.d.ts +3 -1
- package/dist/package-json.js +3 -0
- package/dist/package-manager.js +13 -0
- package/dist/package.js +1 -0
- package/dist/packem_shared/PackageNotFoundError-BictYTIA.js +1 -0
- package/dist/packem_shared/json-value.d-DU4PzU4Z.d.ts +33 -0
- package/dist/packem_shared/{package-json-DoazDpIb.d.cts → package-json-k3TJ_oy7.d.ts} +10 -43
- package/dist/pnpm.d.ts +15 -0
- package/dist/pnpm.js +1 -0
- package/package.json +25 -76
- package/dist/error.cjs +0 -1
- package/dist/error.d.cts +0 -9
- package/dist/error.d.mts +0 -9
- package/dist/error.mjs +0 -1
- package/dist/index.cjs +0 -1
- package/dist/index.d.cts +0 -7
- package/dist/index.d.mts +0 -7
- package/dist/index.mjs +0 -1
- package/dist/monorepo.cjs +0 -1
- package/dist/monorepo.d.cts +0 -9
- package/dist/monorepo.d.mts +0 -9
- package/dist/monorepo.mjs +0 -1
- package/dist/package-json.cjs +0 -3
- package/dist/package-json.d.cts +0 -3
- package/dist/package-json.d.mts +0 -3
- package/dist/package-json.mjs +0 -3
- package/dist/package-manager.cjs +0 -13
- package/dist/package-manager.d.cts +0 -21
- package/dist/package-manager.d.mts +0 -21
- package/dist/package-manager.mjs +0 -13
- package/dist/package.cjs +0 -1
- package/dist/package.d.cts +0 -4
- package/dist/package.d.mts +0 -4
- package/dist/package.mjs +0 -1
- package/dist/packem_shared/PackageNotFoundError-CEETCi0X.mjs +0 -1
- package/dist/packem_shared/PackageNotFoundError-CY57YCot.cjs +0 -1
- package/dist/packem_shared/package-json-DoazDpIb.d.mts +0 -2784
- package/dist/packem_shared/package-json-DoazDpIb.d.ts +0 -2784
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## @visulima/package [4.0.1](https://github.com/visulima/visulima/compare/@visulima/package@4.0.0...@visulima/package@4.0.1) (2025-10-02)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* **package:** export additional pnpm types and functions ([f623d28](https://github.com/visulima/visulima/commit/f623d28b74d9e559995759646e51c1020b407d64))
|
|
6
|
+
|
|
7
|
+
## @visulima/package [4.0.0](https://github.com/visulima/visulima/compare/@visulima/package@3.6.1...@visulima/package@4.0.0) (2025-10-02)
|
|
8
|
+
|
|
9
|
+
### ⚠ BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* **package:** - parsePackageJson is now async and returns Promise<NormalizedPackageJson>
|
|
12
|
+
- Removed CommonJS exports - package is now ESM-only
|
|
13
|
+
- All functions must be awaited when upgrading from v3.x
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* **package:** add pnpm catalog protocol support with breaking changes ([#529](https://github.com/visulima/visulima/issues/529)) ([76e72bd](https://github.com/visulima/visulima/commit/76e72bdb40192f271837e90acca026ef1eb79907))
|
|
18
|
+
|
|
1
19
|
## @visulima/package [3.6.1](https://github.com/visulima/visulima/compare/@visulima/package@3.6.0...@visulima/package@3.6.1) (2025-10-01)
|
|
2
20
|
|
|
3
21
|
### Bug Fixes
|
package/LICENSE.md
CHANGED
|
@@ -27,35 +27,6 @@ The published @visulima/package artifact additionally contains code with the fol
|
|
|
27
27
|
MIT
|
|
28
28
|
|
|
29
29
|
# Bundled dependencies:
|
|
30
|
-
## @antfu/install-pkg
|
|
31
|
-
License: MIT
|
|
32
|
-
By: Anthony Fu
|
|
33
|
-
Repository: git+https://github.com/antfu/install-pkg.git
|
|
34
|
-
|
|
35
|
-
> MIT License
|
|
36
|
-
>
|
|
37
|
-
> Copyright (c) 2021 Anthony Fu <https://github.com/antfu>
|
|
38
|
-
>
|
|
39
|
-
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
40
|
-
> of this software and associated documentation files (the "Software"), to deal
|
|
41
|
-
> in the Software without restriction, including without limitation the rights
|
|
42
|
-
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
43
|
-
> copies of the Software, and to permit persons to whom the Software is
|
|
44
|
-
> furnished to do so, subject to the following conditions:
|
|
45
|
-
>
|
|
46
|
-
> The above copyright notice and this permission notice shall be included in all
|
|
47
|
-
> copies or substantial portions of the Software.
|
|
48
|
-
>
|
|
49
|
-
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
50
|
-
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
51
|
-
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
52
|
-
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
53
|
-
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
54
|
-
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
55
|
-
> SOFTWARE.
|
|
56
|
-
|
|
57
|
-
---------------------------------------
|
|
58
|
-
|
|
59
30
|
## dot-prop
|
|
60
31
|
License: MIT
|
|
61
32
|
By: Sindre Sorhus
|
|
@@ -71,64 +42,6 @@ Repository: sindresorhus/dot-prop
|
|
|
71
42
|
>
|
|
72
43
|
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
73
44
|
|
|
74
|
-
---------------------------------------
|
|
75
|
-
|
|
76
|
-
## package-manager-detector
|
|
77
|
-
License: MIT
|
|
78
|
-
By: Anthony Fu
|
|
79
|
-
Repository: git+https://github.com/antfu-collective/package-manager-detector.git
|
|
80
|
-
|
|
81
|
-
> MIT License
|
|
82
|
-
>
|
|
83
|
-
> Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
|
|
84
|
-
>
|
|
85
|
-
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
86
|
-
> of this software and associated documentation files (the "Software"), to deal
|
|
87
|
-
> in the Software without restriction, including without limitation the rights
|
|
88
|
-
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
89
|
-
> copies of the Software, and to permit persons to whom the Software is
|
|
90
|
-
> furnished to do so, subject to the following conditions:
|
|
91
|
-
>
|
|
92
|
-
> The above copyright notice and this permission notice shall be included in all
|
|
93
|
-
> copies or substantial portions of the Software.
|
|
94
|
-
>
|
|
95
|
-
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
96
|
-
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
97
|
-
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
98
|
-
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
99
|
-
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
100
|
-
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
101
|
-
> SOFTWARE.
|
|
102
|
-
|
|
103
|
-
---------------------------------------
|
|
104
|
-
|
|
105
|
-
## tinyexec
|
|
106
|
-
License: MIT
|
|
107
|
-
By: James Garbutt
|
|
108
|
-
Repository: git+https://github.com/tinylibs/tinyexec.git
|
|
109
|
-
|
|
110
|
-
> MIT License
|
|
111
|
-
>
|
|
112
|
-
> Copyright (c) 2024 Tinylibs
|
|
113
|
-
>
|
|
114
|
-
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
115
|
-
> of this software and associated documentation files (the "Software"), to deal
|
|
116
|
-
> in the Software without restriction, including without limitation the rights
|
|
117
|
-
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
118
|
-
> copies of the Software, and to permit persons to whom the Software is
|
|
119
|
-
> furnished to do so, subject to the following conditions:
|
|
120
|
-
>
|
|
121
|
-
> The above copyright notice and this permission notice shall be included in all
|
|
122
|
-
> copies or substantial portions of the Software.
|
|
123
|
-
>
|
|
124
|
-
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
125
|
-
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
126
|
-
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
127
|
-
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
128
|
-
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
129
|
-
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
130
|
-
> SOFTWARE.
|
|
131
|
-
|
|
132
45
|
<!-- /DEPENDENCIES -->
|
|
133
46
|
|
|
134
47
|
<!-- TYPE_DEPENDENCIES -->
|
|
@@ -138,35 +51,6 @@ The published @visulima/package artifact additionally contains code with the fol
|
|
|
138
51
|
MIT, (MIT OR CC0-1.0)
|
|
139
52
|
|
|
140
53
|
# Bundled types:
|
|
141
|
-
## @antfu/install-pkg
|
|
142
|
-
License: MIT
|
|
143
|
-
By: Anthony Fu
|
|
144
|
-
Repository: git+https://github.com/antfu/install-pkg.git
|
|
145
|
-
|
|
146
|
-
> MIT License
|
|
147
|
-
>
|
|
148
|
-
> Copyright (c) 2021 Anthony Fu <https://github.com/antfu>
|
|
149
|
-
>
|
|
150
|
-
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
151
|
-
> of this software and associated documentation files (the "Software"), to deal
|
|
152
|
-
> in the Software without restriction, including without limitation the rights
|
|
153
|
-
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
154
|
-
> copies of the Software, and to permit persons to whom the Software is
|
|
155
|
-
> furnished to do so, subject to the following conditions:
|
|
156
|
-
>
|
|
157
|
-
> The above copyright notice and this permission notice shall be included in all
|
|
158
|
-
> copies or substantial portions of the Software.
|
|
159
|
-
>
|
|
160
|
-
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
161
|
-
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
162
|
-
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
163
|
-
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
164
|
-
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
165
|
-
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
166
|
-
> SOFTWARE.
|
|
167
|
-
|
|
168
|
-
---------------------------------------
|
|
169
|
-
|
|
170
54
|
## @inquirer/core
|
|
171
55
|
License: MIT
|
|
172
56
|
By: Simon Boudrias
|
package/README.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
<h3>Visulima package</h3>
|
|
3
3
|
<p>
|
|
4
|
-
|
|
4
|
+
A comprehensive package management utility that helps you find root directories, monorepos, package managers, and parse package.json files with advanced features like catalog resolution.
|
|
5
|
+
|
|
6
|
+
Built on top of
|
|
5
7
|
|
|
6
8
|
[@visulima/fs](https://github.com/visulima/visulima/tree/main/packages/fs),
|
|
7
9
|
[@visulima/path](https://github.com/visulima/visulima/tree/main/packages/path),
|
|
8
10
|
[normalize-package-data](https://github.com/npm/normalize-package-data),
|
|
9
|
-
[pathe](https://github.com/unjs/pathe),and
|
|
11
|
+
[pathe](https://github.com/unjs/pathe), and
|
|
10
12
|
[type-fest](https://github.com/sindresorhus/type-fest)
|
|
11
13
|
|
|
12
14
|
</p>
|
|
@@ -34,109 +36,209 @@
|
|
|
34
36
|
|
|
35
37
|
## Install
|
|
36
38
|
|
|
37
|
-
```
|
|
39
|
+
```bash
|
|
38
40
|
npm install @visulima/package
|
|
39
41
|
```
|
|
40
42
|
|
|
41
|
-
```
|
|
43
|
+
```bash
|
|
42
44
|
yarn add @visulima/package
|
|
43
45
|
```
|
|
44
46
|
|
|
45
|
-
```
|
|
47
|
+
```bash
|
|
46
48
|
pnpm add @visulima/package
|
|
47
49
|
```
|
|
48
50
|
|
|
49
|
-
##
|
|
51
|
+
## API
|
|
52
|
+
|
|
53
|
+
### Monorepo Detection
|
|
50
54
|
|
|
51
|
-
|
|
55
|
+
#### findMonorepoRoot
|
|
52
56
|
|
|
53
|
-
|
|
57
|
+
Finds the root directory and strategy for a monorepo by searching for workspace configuration files.
|
|
54
58
|
|
|
55
|
-
```
|
|
59
|
+
```typescript
|
|
56
60
|
import { findMonorepoRoot } from "@visulima/package";
|
|
57
|
-
// or import { findMonorepoRoot } from '@visulima/package/monorepo';
|
|
58
61
|
|
|
59
|
-
const
|
|
62
|
+
const result = await findMonorepoRoot();
|
|
63
|
+
// => { path: '/path/to/monorepo', strategy: 'pnpm' }
|
|
60
64
|
```
|
|
61
65
|
|
|
62
|
-
|
|
66
|
+
Supports detection of:
|
|
67
|
+
|
|
68
|
+
- pnpm workspaces (pnpm-workspace.yaml)
|
|
69
|
+
- npm/yarn workspaces (package.json workspaces field)
|
|
70
|
+
- Lerna (lerna.json)
|
|
71
|
+
- Turborepo (turbo.json)
|
|
63
72
|
|
|
64
|
-
|
|
73
|
+
### Package Detection
|
|
65
74
|
|
|
66
|
-
|
|
75
|
+
#### findPackageRoot
|
|
76
|
+
|
|
77
|
+
Finds the root directory of a package by locating its package.json file.
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
67
80
|
import { findPackageRoot } from "@visulima/package";
|
|
68
|
-
// or import { findPackageRoot } from '@visulima/package/package';
|
|
69
81
|
|
|
70
|
-
const
|
|
82
|
+
const result = await findPackageRoot();
|
|
83
|
+
// => { path: '/path/to/package', strategy: 'package' }
|
|
71
84
|
```
|
|
72
85
|
|
|
73
|
-
|
|
86
|
+
#### findPackageJson
|
|
74
87
|
|
|
75
|
-
|
|
88
|
+
Finds and parses a package.json file, searching parent directories if needed.
|
|
76
89
|
|
|
77
|
-
```
|
|
90
|
+
```typescript
|
|
78
91
|
import { findPackageJson } from "@visulima/package";
|
|
79
|
-
// or import { findPackageJson } from '@visulima/package/package-json';
|
|
80
92
|
|
|
81
|
-
const
|
|
93
|
+
const result = await findPackageJson();
|
|
94
|
+
// => { packageJson: { name: 'my-package', ... }, path: '/path/to/package.json' }
|
|
82
95
|
```
|
|
83
96
|
|
|
84
|
-
###
|
|
97
|
+
### Package Manager Detection
|
|
85
98
|
|
|
86
|
-
|
|
99
|
+
#### findPackageManager
|
|
87
100
|
|
|
88
|
-
|
|
89
|
-
import { writePackageJson } from "@visulima/package";
|
|
90
|
-
// or import { writePackageJson } from '@visulima/package/package-json';
|
|
101
|
+
Detects the package manager used in a project by examining lock files and package.json.
|
|
91
102
|
|
|
92
|
-
|
|
103
|
+
```typescript
|
|
104
|
+
import { findPackageManager } from "@visulima/package";
|
|
105
|
+
|
|
106
|
+
const result = await findPackageManager();
|
|
107
|
+
// => { packageManager: 'pnpm', path: '/path/to/project' }
|
|
93
108
|
```
|
|
94
109
|
|
|
95
|
-
|
|
110
|
+
#### findLockFile
|
|
111
|
+
|
|
112
|
+
Finds the lock file for the current project.
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
import { findLockFile } from "@visulima/package";
|
|
116
|
+
|
|
117
|
+
const lockFile = await findLockFile();
|
|
118
|
+
// => '/path/to/pnpm-lock.yaml'
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
#### getPackageManagerVersion
|
|
122
|
+
|
|
123
|
+
Retrieves the version of a specific package manager.
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
import { getPackageManagerVersion } from "@visulima/package";
|
|
127
|
+
|
|
128
|
+
const version = await getPackageManagerVersion("pnpm");
|
|
129
|
+
// => '8.15.0'
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Package.json Operations
|
|
133
|
+
|
|
134
|
+
#### parsePackageJson
|
|
96
135
|
|
|
97
|
-
|
|
136
|
+
Parses and normalizes package.json data with optional catalog resolution support.
|
|
98
137
|
|
|
99
|
-
```
|
|
138
|
+
```typescript
|
|
100
139
|
import { parsePackageJson } from "@visulima/package";
|
|
101
140
|
|
|
102
|
-
|
|
141
|
+
// Basic parsing
|
|
142
|
+
const packageJson = await parsePackageJson("./package.json");
|
|
143
|
+
|
|
144
|
+
// With catalog resolution (pnpm workspaces only)
|
|
145
|
+
const packageJson = await parsePackageJson("./package.json", {
|
|
146
|
+
resolveCatalogs: true,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// Synchronous version
|
|
150
|
+
import { parsePackageJsonSync } from "@visulima/package";
|
|
151
|
+
|
|
152
|
+
const packageJson = parsePackageJsonSync("./package.json", {
|
|
153
|
+
resolveCatalogs: true,
|
|
154
|
+
});
|
|
103
155
|
```
|
|
104
156
|
|
|
105
|
-
|
|
157
|
+
**Catalog Resolution**: When `resolveCatalogs: true` is set, the function will:
|
|
106
158
|
|
|
107
|
-
|
|
159
|
+
1. Search for `pnpm-workspace.yaml` in parent directories
|
|
160
|
+
2. Verify the package.json is part of the workspace
|
|
161
|
+
3. Resolve catalog references like `"react": "catalog:"` to actual versions
|
|
108
162
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
163
|
+
Example with pnpm catalogs:
|
|
164
|
+
|
|
165
|
+
```yaml
|
|
166
|
+
# pnpm-workspace.yaml
|
|
167
|
+
catalog:
|
|
168
|
+
react: ^18.0.0
|
|
169
|
+
typescript: ^5.0.0
|
|
112
170
|
|
|
113
|
-
|
|
171
|
+
catalogs:
|
|
172
|
+
next:
|
|
173
|
+
react: ^19.0.0
|
|
174
|
+
|
|
175
|
+
packages:
|
|
176
|
+
- packages/*
|
|
114
177
|
```
|
|
115
178
|
|
|
116
|
-
|
|
179
|
+
```json
|
|
180
|
+
// package.json
|
|
181
|
+
{
|
|
182
|
+
"dependencies": {
|
|
183
|
+
"react": "catalog:",
|
|
184
|
+
"typescript": "catalog:",
|
|
185
|
+
"next": "catalog:next"
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
```
|
|
117
189
|
|
|
118
|
-
|
|
190
|
+
After resolution:
|
|
119
191
|
|
|
120
|
-
|
|
192
|
+
```json
|
|
193
|
+
{
|
|
194
|
+
"dependencies": {
|
|
195
|
+
"react": "^18.0.0",
|
|
196
|
+
"typescript": "^5.0.0",
|
|
197
|
+
"next": "^19.0.0"
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
```
|
|
121
201
|
|
|
122
|
-
|
|
202
|
+
#### writePackageJson
|
|
123
203
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
204
|
+
Writes normalized package.json data to a file.
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
import { writePackageJson } from "@visulima/package";
|
|
127
208
|
|
|
128
|
-
|
|
209
|
+
await writePackageJson({
|
|
210
|
+
name: "my-package",
|
|
211
|
+
version: "1.0.0",
|
|
212
|
+
});
|
|
129
213
|
```
|
|
130
214
|
|
|
131
|
-
|
|
215
|
+
#### Package.json Utilities
|
|
132
216
|
|
|
133
|
-
|
|
217
|
+
```typescript
|
|
218
|
+
import { getPackageJsonProperty, hasPackageJsonProperty, hasPackageJsonAnyDependency } from "@visulima/package";
|
|
134
219
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
//
|
|
220
|
+
const packageJson = await parsePackageJson("./package.json");
|
|
221
|
+
|
|
222
|
+
// Get a property value
|
|
223
|
+
const name = getPackageJsonProperty(packageJson, "name");
|
|
224
|
+
|
|
225
|
+
// Check if property exists
|
|
226
|
+
const hasScripts = hasPackageJsonProperty(packageJson, "scripts");
|
|
227
|
+
|
|
228
|
+
// Check for dependencies
|
|
229
|
+
const hasReact = hasPackageJsonAnyDependency(packageJson, ["react", "preact"]);
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Package Installation
|
|
233
|
+
|
|
234
|
+
#### ensurePackages
|
|
235
|
+
|
|
236
|
+
Ensures specified packages are installed, prompting the user if needed.
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
import { ensurePackages } from "@visulima/package";
|
|
138
240
|
|
|
139
|
-
|
|
241
|
+
await ensurePackages(packageJson, ["typescript", "@types/node"], "devDependencies");
|
|
140
242
|
```
|
|
141
243
|
|
|
142
244
|
## Supported Node.js Versions
|
package/dist/error.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{default as a}from"./packem_shared/PackageNotFoundError-BictYTIA.js";export{a as PackageNotFoundError};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export { PackageNotFoundError } from './error.js';
|
|
2
2
|
export { RootMonorepo, Strategy, findMonorepoRoot, findMonorepoRootSync } from './monorepo.js';
|
|
3
3
|
export { findPackageRoot, findPackageRootSync } from './package.js';
|
|
4
|
-
export { E as EnsurePackagesOptions, F as FindPackageJsonCache, d as NormalizedPackageJson, N as NormalizedReadResult, P as PackageJson, e as ensurePackages, f as findPackageJson, a as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, b as hasPackageJsonProperty, p as parsePackageJson, w as writePackageJson, c as writePackageJsonSync } from './packem_shared/package-json-
|
|
4
|
+
export { E as EnsurePackagesOptions, F as FindPackageJsonCache, d as NormalizedPackageJson, N as NormalizedReadResult, P as PackageJson, e as ensurePackages, f as findPackageJson, a as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, b as hasPackageJsonProperty, p as parsePackageJson, w as writePackageJson, c as writePackageJsonSync } from './packem_shared/package-json-k3TJ_oy7.js';
|
|
5
5
|
export { PackageManager, PackageManagerResult, findLockFile, findLockFileSync, findPackageManager, findPackageManagerSync, generateMissingPackagesInstallMessage, getPackageManagerVersion, identifyInitiatingPackageManager } from './package-manager.js';
|
|
6
|
+
export { PnpmCatalog, PnpmCatalogs, isPackageInWorkspace, readPnpmCatalogs, readPnpmCatalogsSync, resolveCatalogReference, resolveCatalogReferences, resolveDependenciesCatalogReferences } from './pnpm.js';
|
|
6
7
|
import '@visulima/fs';
|
|
8
|
+
import './packem_shared/json-value.d-DU4PzU4Z.js';
|
|
9
|
+
import '@antfu/install-pkg';
|
|
7
10
|
import 'normalize-package-data';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{default as n}from"./packem_shared/PackageNotFoundError-BictYTIA.js";import{findMonorepoRoot as r,findMonorepoRootSync as c}from"./monorepo.js";import{findPackageRoot as s,findPackageRootSync as t}from"./package.js";import{ensurePackages as P,findPackageJson as f,findPackageJsonSync as k,getPackageJsonProperty as d,hasPackageJsonAnyDependency as p,hasPackageJsonProperty as l,parsePackageJson as y,writePackageJson as m,writePackageJsonSync as J}from"./package-json.js";import{findLockFile as R,findLockFileSync as S,findPackageManager as x,findPackageManagerSync as C,generateMissingPackagesInstallMessage as u,getPackageManagerVersion as v,identifyInitiatingPackageManager as F}from"./package-manager.js";import{isPackageInWorkspace as h,readPnpmCatalogs as w,readPnpmCatalogsSync as D,resolveCatalogReference as L,resolveCatalogReferences as A,resolveDependenciesCatalogReferences as E}from"./pnpm.js";export{n as PackageNotFoundError,P as ensurePackages,R as findLockFile,S as findLockFileSync,r as findMonorepoRoot,c as findMonorepoRootSync,f as findPackageJson,k as findPackageJsonSync,x as findPackageManager,C as findPackageManagerSync,s as findPackageRoot,t as findPackageRootSync,u as generateMissingPackagesInstallMessage,d as getPackageJsonProperty,v as getPackageManagerVersion,p as hasPackageJsonAnyDependency,l as hasPackageJsonProperty,F as identifyInitiatingPackageManager,h as isPackageInWorkspace,y as parsePackageJson,w as readPnpmCatalogs,D as readPnpmCatalogsSync,L as resolveCatalogReference,A as resolveCatalogReferences,E as resolveDependenciesCatalogReferences,m as writePackageJson,J as writePackageJsonSync};
|
package/dist/monorepo.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var m=Object.defineProperty;var c=(n,r)=>m(n,"name",{value:r,configurable:!0});import{findUp as l,readJson as y,findUpSync as g,readJsonSync as h}from"@visulima/fs";import{NotFoundError as f}from"@visulima/fs/error";import{dirname as u,join as a}from"@visulima/path";import{findPackageManager as w,findPackageManagerSync as k}from"./package-manager.js";const{existsSync:p,readFileSync:i}=globalThis.process.getBuiltinModule("node:fs");var j=Object.defineProperty,d=c((n,r)=>j(n,"name",{value:r,configurable:!0}),"i");const v=d(async n=>{const r=await l(["lerna.json","turbo.json"],{type:"file",...n&&{cwd:n}});if(r?.endsWith("lerna.json")){const o=await y(r);if(o.useWorkspaces||o.packages)return{path:u(r),strategy:"lerna"}}const s=r?.endsWith("turbo.json");try{const{packageManager:o,path:e}=await w(n);if(["npm","yarn"].includes(o)){const t=a(e,"package.json");if(p(t)&&i(a(e,"package.json"),"utf8").includes("workspaces"))return{path:e,strategy:s?"turbo":o}}else if(o==="pnpm"){const t=a(e,"pnpm-workspace.yaml");if(p(t))return{path:e,strategy:s?"turbo":"pnpm"}}}catch(o){if(!(o instanceof f))throw o}throw new Error(`No monorepo root could be found upwards from the directory ${n} using lerna, yarn, pnpm, or npm as indicators.`)},"findMonorepoRoot"),E=d(n=>{const r=g(["lerna.json","turbo.json"],{type:"file",...n&&{cwd:n}});if(r?.endsWith("lerna.json")){const o=h(r);if(o.useWorkspaces||o.packages)return{path:u(r),strategy:"lerna"}}const s=r?.endsWith("turbo.json");try{const{packageManager:o,path:e}=k(n);if(["npm","yarn"].includes(o)){const t=a(e,"package.json");if(p(t)&&i(a(e,"package.json"),"utf8").includes("workspaces"))return{path:e,strategy:s?"turbo":o}}else if(o==="pnpm"){const t=a(e,"pnpm-workspace.yaml");if(p(t))return{path:e,strategy:s?"turbo":"pnpm"}}}catch(o){if(!(o instanceof f))throw o}throw new Error(`No monorepo root could be found upwards from the directory ${n} using lerna, yarn, pnpm, or npm as indicators.`)},"findMonorepoRootSync");export{v as findMonorepoRoot,E as findMonorepoRootSync};
|
package/dist/package-json.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import '@visulima/fs';
|
|
2
|
-
|
|
2
|
+
import './packem_shared/json-value.d-DU4PzU4Z.js';
|
|
3
|
+
export { F as FindPackageJsonCache, N as NormalizedReadResult, e as ensurePackages, f as findPackageJson, a as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, b as hasPackageJsonProperty, p as parsePackageJson, i as parsePackageJsonSync, w as writePackageJson, c as writePackageJsonSync } from './packem_shared/package-json-k3TJ_oy7.js';
|
|
4
|
+
import '@antfu/install-pkg';
|
|
3
5
|
import 'normalize-package-data';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var _=Object.defineProperty;var i=(e,n)=>_(e,"name",{value:n,configurable:!0});import{installPackage as K}from"@antfu/install-pkg";import R from"@inquirer/confirm";import{readJsonSync as I,findUp as q,readJson as S,findUpSync as F,writeJson as M,writeJsonSync as V}from"@visulima/fs";import{NotFoundError as A}from"@visulima/fs/error";import{parseJson as D,toPath as x}from"@visulima/fs/utils";import{join as N}from"@visulima/path";import{readPnpmCatalogsSync as U,resolveCatalogReferences as O,readPnpmCatalogs as Y}from"./pnpm.js";const z=globalThis.process.getBuiltinModule("module").createRequire(import.meta.url),{existsSync:m}=globalThis.process.getBuiltinModule("node:fs"),B=z("normalize-package-data");var G=Object.defineProperty,f=i((e,n)=>G(e,"name",{value:n,configurable:!0}),"f");const u=f(e=>{const n=typeof e;return e!==null&&(n==="object"||n==="function")},"isObject"),H=f(e=>u(e)&&Object.keys(e).length===0,"isEmptyObject"),b=new Set(["__proto__","prototype","constructor"]),L=new Set("0123456789");function v(e){return typeof e=="string"&&/^\d+$/.test(e)&&Number.parseInt(e,10)>=0&&(e==="0"||!e.startsWith("0"))}i(v,"h");f(v,"isValidArrayIndex");function y(e,n,r){return r>0&&typeof e=="string"&&Array.isArray(n)&&v(e)?Number.parseInt(e,10):e}i(y,"u");f(y,"normalizeKey");function w(e){const n=[];let r="",t="start",o=!1;for(const a of e)switch(a){case"\\":{if(t==="index")throw new Error("Invalid character in an index");if(t==="indexEnd")throw new Error("Invalid character after an index");o&&(r+=a),t="property",o=!o;break}case".":{if(t==="index")throw new Error("Invalid character in an index");if(t==="indexEnd"){t="property";break}if(o){o=!1,r+=a;break}if(b.has(r))return[];n.push(r),r="",t="property";break}case"[":{if(t==="index")throw new Error("Invalid character in an index");if(t==="indexEnd"){t="index";break}if(o){o=!1,r+=a;break}if(t==="property"){if(b.has(r))return[];n.push(r),r=""}t="index";break}case"]":{if(t==="index"){n.push(Number.parseInt(r,10)),r="",t="indexEnd";break}if(t==="indexEnd")throw new Error("Invalid character after an index")}default:{if(t==="index"&&!L.has(a))throw new Error("Invalid character in an index");if(t==="indexEnd")throw new Error("Invalid character after an index");t==="start"&&(t="property"),o&&(o=!1,r+="\\"),r+=a}}switch(o&&(r+="\\"),t){case"property":{if(b.has(r))return[];n.push(r);break}case"index":throw new Error("Index was not closed");case"start":{n.push("");break}}return n}i(w,"l");f(w,"getPathSegments");function k(e,n){if(!Array.isArray(e)||typeof n=="number")return!1;const r=Number.parseInt(n,10);return Number.isInteger(r)&&String(r)===n}i(k,"c$1");f(k,"isStringIndex");function E(e,n){if(k(e,n))throw new Error("Cannot use string index")}i(E,"x");f(E,"assertNotStringIndex");function g(e,n,r){if(!u(e)||typeof n!="string")return r===void 0?e:r;const t=w(n);if(t.length===0)return r;for(let o=0;o<t.length;o++){const a=t[o],s=y(a,e,o);if(s===a&&k(e,a)?e=o===t.length-1?void 0:null:e=e[s],e==null){if(o!==t.length-1)return r;break}}return e===void 0?r:e}i(g,"getProperty");f(g,"getProperty");function $(e,n,r){if(!u(e)||typeof n!="string")return e;const t=e,o=w(n);for(let a=0;a<o.length;a++){const s=o[a],p=y(s,e,a);if(p===s&&E(e,s),a===o.length-1)e[p]=r;else if(!u(e[p])){const c=o[a+1],l=typeof c=="number"||typeof c=="string"&&v(c);e[p]=l?[]:{}}e=e[p]}return t}i($,"setProperty");f($,"setProperty");function Q(e,n){if(!u(e)||typeof n!="string")return!1;const r=w(n);for(let t=0;t<r.length;t++){const o=r[t],a=y(o,e,t);if(a===o&&E(e,o),t===r.length-1)return Object.hasOwn(e,a)?(delete e[a],!0):!1;if(e=e[a],!u(e))return!1}}i(Q,"deleteProperty");f(Q,"deleteProperty");function h(e,n){if(!u(e)||typeof n!="string")return!1;const r=w(n);if(r.length===0)return!1;for(const[t,o]of r.entries()){const a=y(o,e,t),s=a===o&&k(e,o);if(!u(e)||!(a in e)||s)return!1;e=e[a]}return!0}i(h,"hasProperty");f(h,"hasProperty");function C(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replaceAll(/[\\.[]/g,String.raw`\$&`)}i(C,"escapePath");f(C,"escapePath");function J(e){const n=Object.entries(e);return Array.isArray(e)?n.map(([r,t])=>[Number(r),t]):n}i(J,"g");f(J,"entries");function T(e){let n="";for(let[r,t]of J(e))typeof t=="number"?n+=`[${t}]`:(t=C(t),n+=r===0?t:`.${t}`);return n}i(T,"A");f(T,"stringifyPath");function*j(e,n=[]){if(!u(e)||H(e)){n.length>0&&(yield T(n));return}for(const[r,t]of J(e))yield*j(t,[...n,r])}i(j,"w");f(j,"deepKeysIterator");function X(e){return[...j(e)]}i(X,"deepKeys");f(X,"deepKeys");function Z(e){const n={};if(!u(e))return n;for(const[r,t]of Object.entries(e))$(n,r,t);return n}i(Z,"unflatten");f(Z,"unflatten");const ee=typeof process.stdout<"u"&&!process.versions.deno&&!globalThis.window;var ne=Object.defineProperty,d=i((e,n)=>ne(e,"name",{value:n,configurable:!0}),"c");const W=new Map;class te extends Error{static{i(this,"W")}static{d(this,"PackageJsonValidationError")}constructor(n){super(`The following warnings were encountered while normalizing package data:
|
|
2
|
+
- ${n.join(`
|
|
3
|
+
- `)}`),this.name="PackageJsonValidationError"}}const P=d((e,n,r=[])=>{const t=[];if(B(e,o=>{t.push(o)},n),n&&t.length>0){const o=t.filter(a=>!r.some(s=>s instanceof RegExp?s.test(a):s===a));if(o.length>0)throw new te(o)}return e},"normalizeInput"),le=d(async(e,n={})=>{const r={type:"file"};e&&(r.cwd=e);const t=await q("package.json",r);if(!t)throw new A("No such file or directory, for package.json found.");const o=n.cache&&typeof n.cache!="boolean"?n.cache:W;if(n.cache&&o.has(t))return o.get(t);const a=await S(t);P(a,n.strict??!1,n.ignoreWarnings);const s={packageJson:a,path:t};return o.set(t,s),s},"findPackageJson"),de=d((e,n={})=>{const r={type:"file"};e&&(r.cwd=e);const t=F("package.json",r);if(!t)throw new A("No such file or directory, for package.json found.");const o=n.cache&&typeof n.cache!="boolean"?n.cache:W;if(n.cache&&o.has(t))return o.get(t);const a=I(t);P(a,n.strict??!1,n.ignoreWarnings);const s={packageJson:a,path:t};return o.set(t,s),s},"findPackageJsonSync"),ue=d(async(e,n={})=>{const{cwd:r,...t}=n,o=x(n.cwd??process.cwd());await M(N(o,"package.json"),e,t)},"writePackageJson"),ge=d((e,n={})=>{const{cwd:r,...t}=n,o=x(n.cwd??process.cwd());V(N(o,"package.json"),e,t)},"writePackageJsonSync"),he=d((e,n)=>{const r=e!==null&&typeof e=="object"&&!Array.isArray(e),t=typeof e=="string";if(!r&&!t)throw new TypeError("`packageFile` should be either an `object` or a `string`.");let o;if(r?o=structuredClone(e):m(e)?o=I(e):o=D(e),n?.resolveCatalogs&&t&&m(e)){const a=U(e);a&&O(o,a)}return P(o,n?.strict??!1,n?.ignoreWarnings),o},"parsePackageJsonSync"),ye=d(async(e,n)=>{const r=e!==null&&typeof e=="object"&&!Array.isArray(e),t=typeof e=="string";if(!r&&!t)throw new TypeError("`packageFile` should be either an `object` or a `string`.");let o;if(r?o=structuredClone(e):m(e)?o=await S(e):o=D(e),n?.resolveCatalogs&&t&&m(e)){const a=await Y(e);a&&O(o,a)}return P(o,n?.strict??!1,n?.ignoreWarnings),o},"parsePackageJson"),we=d((e,n,r)=>g(e,n,r),"getPackageJsonProperty"),me=d((e,n)=>h(e,n),"hasPackageJsonProperty"),ke=d((e,n,r)=>{const t=g(e,"dependencies",{}),o=g(e,"devDependencies",{}),a=g(e,"peerDependencies",{}),s={...t,...o,...r?.peerDeps===!1?{}:a};for(const p of n)if(h(s,p))return!0;return!1},"hasPackageJsonAnyDependency"),Pe=d(async(e,n,r="dependencies",t={})=>{const o=g(e,"dependencies",{}),a=g(e,"devDependencies",{}),s=g(e,"peerDependencies",{}),p=[],c={deps:!0,devDeps:!0,peerDeps:!1,...t};for(const l of n)c.deps&&h(o,l)||c.devDeps&&h(a,l)||c.peerDeps&&h(s,l)||p.push(l);if(p.length!==0){if(process.env.CI||ee&&!process.stdout?.isTTY){const l=`Skipping package installation for [${n.join(", ")}] because the process is not interactive.`;if(t.throwOnWarn)throw new Error(l);t.logger?.warn?t.logger.warn(l):console.warn(l);return}if(typeof c.confirm?.message=="function"&&(c.confirm.message=c.confirm.message(p)),c.confirm?.message===void 0){const l=`${p.length===1?"Package is":"Packages are"} required for this config: ${p.join(", ")}. Do you want to install them?`;c.confirm===void 0?c.confirm={message:l}:c.confirm.message=l}await R(c.confirm)&&await K(p,{...c.installPackage,cwd:c.cwd?x(c.cwd):void 0,dev:r==="devDependencies"})}},"ensurePackages");export{Pe as ensurePackages,le as findPackageJson,de as findPackageJsonSync,we as getPackageJsonProperty,ke as hasPackageJsonAnyDependency,me as hasPackageJsonProperty,ye as parsePackageJson,he as parsePackageJsonSync,ue as writePackageJson,ge as writePackageJsonSync};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var b=Object.defineProperty;var d=(n,a)=>b(n,"name",{value:a,configurable:!0});import{findUpSync as f,findUp as m}from"@visulima/fs";import{NotFoundError as c}from"@visulima/fs/error";import{join as p,dirname as t}from"@visulima/path";import{parsePackageJsonSync as u,parsePackageJson as j}from"./package-json.js";const{execSync:v}=globalThis.process.getBuiltinModule("node:child_process"),{existsSync:k,readFileSync:P}=globalThis.process.getBuiltinModule("node:fs");var W=Object.defineProperty,r=d((n,a)=>W(n,"name",{value:a,configurable:!0}),"t");const l=["yarn.lock","package-lock.json","pnpm-lock.yaml","npm-shrinkwrap.json","bun.lockb"],h=r(n=>{let a;if(l.forEach(i=>{!a&&k(p(n,i))&&(a=p(n,i))}),a)return a;const e=p(n,"package.json");if(k(e)&&u(P(e,"utf8")).packageManager!==void 0)return e},"packageMangerFindUpMatcher"),S=r(async n=>{if(!n)throw new c("Could not find a package manager");if(n.endsWith("package.json")){const a=await j(n);if(a.packageManager){const e=["npm","yarn","pnpm","bun"].find(i=>a.packageManager.startsWith(i));if(e)return{packageManager:e,path:t(n)}}}if(n.endsWith("yarn.lock"))return{packageManager:"yarn",path:t(n)};if(n.endsWith("package-lock.json")||n.endsWith("npm-shrinkwrap.json"))return{packageManager:"npm",path:t(n)};if(n.endsWith("pnpm-lock.yaml"))return{packageManager:"pnpm",path:t(n)};if(n.endsWith("bun.lockb"))return{packageManager:"bun",path:t(n)};throw new c("Could not find a package manager")},"findPackageManagerOnFile"),$=r(n=>{if(!n)throw new c("Could not find a package manager");if(n.endsWith("package.json")){const a=u(n);if(a.packageManager){const e=["npm","yarn","pnpm","bun"].find(i=>a.packageManager.startsWith(i));if(e)return{packageManager:e,path:t(n)}}}if(n.endsWith("yarn.lock"))return{packageManager:"yarn",path:t(n)};if(n.endsWith("package-lock.json")||n.endsWith("npm-shrinkwrap.json"))return{packageManager:"npm",path:t(n)};if(n.endsWith("pnpm-lock.yaml"))return{packageManager:"pnpm",path:t(n)};if(n.endsWith("bun.lockb"))return{packageManager:"bun",path:t(n)};throw new c("Could not find a package manager")},"findPackageManagerOnFileSync"),I=r(async n=>{const a=await m(l,{type:"file",...n&&{cwd:n}});if(!a)throw new Error("Could not find lock file");return a},"findLockFile"),L=r(n=>{const a=f(l,{type:"file",...n&&{cwd:n}});if(!a)throw new Error("Could not find lock file");return a},"findLockFileSync"),O=r(async n=>{const a=await m(h,{...n&&{cwd:n}});return S(a)},"findPackageManager"),U=r(n=>{const a=f(h,{...n&&{cwd:n}});return $(a)},"findPackageManagerSync"),N=r(n=>v(`${n} --version`).toString("utf8").trim(),"getPackageManagerVersion"),T=r(async()=>{if(!process.env.npm_config_user_agent)return;const n=process.env.npm_config_user_agent.split(" ")[0],a=n.lastIndexOf("/"),e=n.slice(0,Math.max(0,a));return{name:e==="npminstall"?"cnpm":e,version:n.slice(Math.max(0,a+1))}},"identifyInitiatingPackageManager"),B=r((n,a,e)=>{const i=a.length===1?"":"s";if(e.packageManagers===void 0&&(e.packageManagers=["npm","pnpm","yarn"]),e.packageManagers.length===0)throw new Error("No package managers provided, please provide at least one package manager");if(a.length===0)throw new Error("No missing packages provided, please provide at least one missing package");let g=`
|
|
2
|
+
${e.preMessage??""}
|
|
3
|
+
${n} could not find the following package${i}
|
|
4
|
+
|
|
5
|
+
${a.join(`
|
|
6
|
+
`)}
|
|
7
|
+
|
|
8
|
+
To install the missing package${i}, please run the following command:
|
|
9
|
+
`;const M=r(o=>o.split("@").includes("@")?o:`${o}@latest`,"atLatest"),w=e.packageManagers.map(o=>{const s=a.map(y=>M(y)).join(" ");switch(o){case"bun":return` bun add ${s} -D`;case"npm":return` npm install ${s} --save-dev`;case"pnpm":return` pnpm add ${s} -D`;case"yarn":return` yarn add ${s} --dev`;default:throw new Error("Unknown package manager")}});return g+=w.join(`
|
|
10
|
+
|
|
11
|
+
or
|
|
12
|
+
|
|
13
|
+
`),e.postMessage&&(g+=e.postMessage),g},"generateMissingPackagesInstallMessage");export{I as findLockFile,L as findLockFileSync,O as findPackageManager,U as findPackageManagerSync,B as generateMissingPackagesInstallMessage,N as getPackageManagerVersion,T as identifyInitiatingPackageManager};
|
package/dist/package.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var p=Object.defineProperty;var c=(n,o)=>p(n,"name",{value:o,configurable:!0});import{findUp as a,findUpSync as f,readJsonSync as y}from"@visulima/fs";import{dirname as e,join as d}from"@visulima/path";import{findLockFile as u,findLockFileSync as l}from"./package-manager.js";const{existsSync:g}=globalThis.process.getBuiltinModule("node:fs");var w=Object.defineProperty,i=c((n,o)=>w(n,"name",{value:o,configurable:!0}),"i");const s=i(n=>{if(g(d(n,"package.json"))){const o=y(d(n,"package.json"));if(o.name&&o.private!==!0)return"package.json"}},"packageJsonMatcher"),j=i(async n=>{try{const t=await u(n);return e(t)}catch{}const o=await a(".git/config",{...n&&{cwd:n},type:"file"});if(o)return e(e(o));const r=await a(s,{...n&&{cwd:n},type:"file"});if(r)return e(r);throw new Error("Could not find root directory")},"findPackageRoot"),P=i(n=>{try{const t=l(n);return e(t)}catch{}const o=f(".git/config",{...n&&{cwd:n},type:"file"});if(o)return e(e(o));const r=f(s,{...n&&{cwd:n},type:"file"});if(r)return e(r);throw new Error("Could not find root directory")},"findPackageRootSync");export{j as findPackageRoot,P as findPackageRootSync};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var o=Object.defineProperty;var a=(t,e)=>o(t,"name",{value:e,configurable:!0});import{findPackageManagerSync as n}from"../package-manager.js";var c=Object.defineProperty,i=a((t,e)=>c(t,"name",{value:e,configurable:!0}),"t");class g extends Error{static{a(this,"u")}static{i(this,"PackageNotFoundError")}constructor(e,r){if(typeof e=="string"&&(e=[e]),e.length===0){super("Package was not found.");return}if(r===void 0)try{r=n().packageManager}catch{}r===void 0&&(r="npm"),super(`Package '${e.join(" ")}' was not found. Please install it using '${r} install ${e.join(" ")}'`)}get code(){return"PACKAGE_NOT_FOUND"}set code(e){throw new Error("Cannot overwrite code PACKAGE_NOT_FOUND")}get name(){return"PackageNotFoundError"}set name(e){throw new Error("Cannot overwrite name of PackageNotFoundError")}}export{g as default};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Matches a JSON object.
|
|
3
|
+
|
|
4
|
+
This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from. Don't use this as a direct return type as the user would have to double-cast it: `jsonObject as unknown as CustomResponse`. Instead, you could extend your CustomResponse type from it to ensure your type only uses JSON-compatible types: `interface CustomResponse extends JsonObject { … }`.
|
|
5
|
+
|
|
6
|
+
@category JSON
|
|
7
|
+
*/
|
|
8
|
+
type JsonObject = {[Key in string]: JsonValue} & {[Key in string]?: JsonValue | undefined};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
Matches a JSON array.
|
|
12
|
+
|
|
13
|
+
@category JSON
|
|
14
|
+
*/
|
|
15
|
+
type JsonArray = JsonValue[] | readonly JsonValue[];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
Matches any valid JSON primitive value.
|
|
19
|
+
|
|
20
|
+
@category JSON
|
|
21
|
+
*/
|
|
22
|
+
type JsonPrimitive = string | number | boolean | null;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
Matches any valid JSON value.
|
|
26
|
+
|
|
27
|
+
@see `Jsonify` if you need to transform a type to one that is assignable to `JsonValue`.
|
|
28
|
+
|
|
29
|
+
@category JSON
|
|
30
|
+
*/
|
|
31
|
+
type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
|
32
|
+
|
|
33
|
+
export type { JsonObject as J, JsonValue as a };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { WriteJsonOptions } from '@visulima/fs';
|
|
2
|
+
import { a as JsonValue, J as JsonObject } from './json-value.d-DU4PzU4Z.js';
|
|
3
|
+
import { InstallPackageOptions } from '@antfu/install-pkg';
|
|
2
4
|
import { Package } from 'normalize-package-data';
|
|
3
5
|
|
|
4
6
|
/**
|
|
@@ -15,38 +17,6 @@ type Primitive =
|
|
|
15
17
|
| symbol
|
|
16
18
|
| bigint;
|
|
17
19
|
|
|
18
|
-
/**
|
|
19
|
-
Matches a JSON object.
|
|
20
|
-
|
|
21
|
-
This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from. Don't use this as a direct return type as the user would have to double-cast it: `jsonObject as unknown as CustomResponse`. Instead, you could extend your CustomResponse type from it to ensure your type only uses JSON-compatible types: `interface CustomResponse extends JsonObject { … }`.
|
|
22
|
-
|
|
23
|
-
@category JSON
|
|
24
|
-
*/
|
|
25
|
-
type JsonObject = {[Key in string]: JsonValue} & {[Key in string]?: JsonValue | undefined};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
Matches a JSON array.
|
|
29
|
-
|
|
30
|
-
@category JSON
|
|
31
|
-
*/
|
|
32
|
-
type JsonArray = JsonValue[] | readonly JsonValue[];
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
Matches any valid JSON primitive value.
|
|
36
|
-
|
|
37
|
-
@category JSON
|
|
38
|
-
*/
|
|
39
|
-
type JsonPrimitive = string | number | boolean | null;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
Matches any valid JSON value.
|
|
43
|
-
|
|
44
|
-
@see `Jsonify` if you need to transform a type to one that is assignable to `JsonValue`.
|
|
45
|
-
|
|
46
|
-
@category JSON
|
|
47
|
-
*/
|
|
48
|
-
type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
|
49
|
-
|
|
50
20
|
/**
|
|
51
21
|
Returns a boolean for whether the given type is `any`.
|
|
52
22
|
|
|
@@ -2562,15 +2532,6 @@ type PackageJson$1 =
|
|
|
2562
2532
|
PackageJson$1.YarnConfiguration &
|
|
2563
2533
|
PackageJson$1.JSPMConfiguration;
|
|
2564
2534
|
|
|
2565
|
-
interface InstallPackageOptions {
|
|
2566
|
-
cwd?: string;
|
|
2567
|
-
dev?: boolean;
|
|
2568
|
-
silent?: boolean;
|
|
2569
|
-
packageManager?: string;
|
|
2570
|
-
preferOffline?: boolean;
|
|
2571
|
-
additionalArgs?: string[] | ((agent: string, detectedAgent: string) => string[] | undefined);
|
|
2572
|
-
}
|
|
2573
|
-
|
|
2574
2535
|
type Prettify<T> = {
|
|
2575
2536
|
[K in keyof T]: T[K];
|
|
2576
2537
|
} & {};
|
|
@@ -2770,10 +2731,16 @@ declare const writePackageJson: <T = PackageJson>(data: T, options?: WriteJsonOp
|
|
|
2770
2731
|
declare const writePackageJsonSync: <T = PackageJson>(data: T, options?: WriteJsonOptions & {
|
|
2771
2732
|
cwd?: URL | string;
|
|
2772
2733
|
}) => void;
|
|
2773
|
-
declare const
|
|
2734
|
+
declare const parsePackageJsonSync: (packageFile: JsonObject | string, options?: {
|
|
2774
2735
|
ignoreWarnings?: (RegExp | string)[];
|
|
2736
|
+
resolveCatalogs?: boolean;
|
|
2775
2737
|
strict?: boolean;
|
|
2776
2738
|
}) => NormalizedPackageJson;
|
|
2739
|
+
declare const parsePackageJson: (packageFile: JsonObject | string, options?: {
|
|
2740
|
+
ignoreWarnings?: (RegExp | string)[];
|
|
2741
|
+
resolveCatalogs?: boolean;
|
|
2742
|
+
strict?: boolean;
|
|
2743
|
+
}) => Promise<NormalizedPackageJson>;
|
|
2777
2744
|
declare const getPackageJsonProperty: <T = unknown>(packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>, defaultValue?: T) => T;
|
|
2778
2745
|
declare const hasPackageJsonProperty: (packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>) => boolean;
|
|
2779
2746
|
declare const hasPackageJsonAnyDependency: (packageJson: NormalizedPackageJson, arguments_: string[], options?: {
|
|
@@ -2781,4 +2748,4 @@ declare const hasPackageJsonAnyDependency: (packageJson: NormalizedPackageJson,
|
|
|
2781
2748
|
}) => boolean;
|
|
2782
2749
|
declare const ensurePackages: (packageJson: NormalizedPackageJson, packages: string[], installKey?: "dependencies" | "devDependencies", options?: EnsurePackagesOptions) => Promise<void>;
|
|
2783
2750
|
|
|
2784
|
-
export { type EnsurePackagesOptions as E, type FindPackageJsonCache as F, type NormalizedReadResult as N, type PackageJson as P, findPackageJsonSync as a, hasPackageJsonProperty as b, writePackageJsonSync as c, type NormalizedPackageJson as d, ensurePackages as e, findPackageJson as f, getPackageJsonProperty as g, hasPackageJsonAnyDependency as h, parsePackageJson as p, writePackageJson as w };
|
|
2751
|
+
export { type EnsurePackagesOptions as E, type FindPackageJsonCache as F, type NormalizedReadResult as N, type PackageJson as P, findPackageJsonSync as a, hasPackageJsonProperty as b, writePackageJsonSync as c, type NormalizedPackageJson as d, ensurePackages as e, findPackageJson as f, getPackageJsonProperty as g, hasPackageJsonAnyDependency as h, parsePackageJsonSync as i, parsePackageJson as p, writePackageJson as w };
|