isolated-deps 0.1.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/LICENSE +21 -0
- package/README.md +112 -0
- package/dist/cache-state.d.ts +6 -0
- package/dist/contract-types.d.ts +18 -0
- package/dist/index.cjs +1034 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +954 -0
- package/dist/install-root-packages.d.ts +1 -0
- package/dist/installer-engine.d.ts +11 -0
- package/dist/messages.d.ts +5 -0
- package/dist/package-manager.d.ts +31 -0
- package/dist/package-specs.d.ts +9 -0
- package/dist/runtime-context.d.ts +3 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Cezar Augusto
|
|
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,112 @@
|
|
|
1
|
+
# optional-deps-lib
|
|
2
|
+
|
|
3
|
+
> Deterministically install optional tooling dependencies into an isolated cache root instead of mutating the user's project.
|
|
4
|
+
|
|
5
|
+
`optional-deps-lib` is a small runtime helper for library authors who need to bootstrap optional packages on demand while keeping those installs reproducible and separate from the consumer's app.
|
|
6
|
+
|
|
7
|
+
## Why this exists
|
|
8
|
+
|
|
9
|
+
- Keeps optional tooling installs outside the user's project directory.
|
|
10
|
+
- Lets the client choose exact dependency specs and versions.
|
|
11
|
+
- Verifies installed packages after each install attempt instead of trusting exit codes alone.
|
|
12
|
+
- Recovers from partial installs by retrying and, if needed, recreating only the isolated cache root.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install optional-deps-lib
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## How it works
|
|
21
|
+
|
|
22
|
+
1. `optional-deps-lib` resolves an isolated cache directory for optional packages.
|
|
23
|
+
2. It writes a small manifest with the exact specs requested by the client.
|
|
24
|
+
3. It detects the active package manager (`npm`, `pnpm`, `yarn`, or `bun`).
|
|
25
|
+
4. It installs the requested packages into the cache root.
|
|
26
|
+
5. It re-checks resolution from the cache root before reporting success.
|
|
27
|
+
|
|
28
|
+
The default cache root is versioned so installs remain deterministic across library upgrades.
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
import {
|
|
34
|
+
installOptionalDependencies,
|
|
35
|
+
resolveOptionalInstallRoot,
|
|
36
|
+
hasDependency
|
|
37
|
+
} from 'optional-deps-lib'
|
|
38
|
+
|
|
39
|
+
async function ensurePostcss(projectPath) {
|
|
40
|
+
if (hasDependency(projectPath, 'postcss')) {
|
|
41
|
+
return null
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const installed = await installOptionalDependencies('PostCSS', ['postcss@8.5.6'])
|
|
45
|
+
|
|
46
|
+
if (!installed) {
|
|
47
|
+
throw new Error('Failed to install PostCSS support')
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return resolveOptionalInstallRoot()
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Supported package managers
|
|
55
|
+
|
|
56
|
+
- `npm`
|
|
57
|
+
- `pnpm`
|
|
58
|
+
- `yarn`
|
|
59
|
+
- `bun`
|
|
60
|
+
|
|
61
|
+
The installer also contains Windows and WSL-specific path handling so isolated installs can run in the same environment where the user launched the host tool.
|
|
62
|
+
|
|
63
|
+
## Deterministic package versions
|
|
64
|
+
|
|
65
|
+
This package does not ship its own dependency catalog.
|
|
66
|
+
|
|
67
|
+
Clients are expected to pass exact dependency specs such as:
|
|
68
|
+
|
|
69
|
+
- `postcss@8.5.6`
|
|
70
|
+
- `react-refresh@0.18.0`
|
|
71
|
+
- `@rspack/plugin-react-refresh@1.6.0`
|
|
72
|
+
|
|
73
|
+
That keeps version policy with the consuming tool while this library focuses on isolated installation, package-manager execution, and verification.
|
|
74
|
+
|
|
75
|
+
## API
|
|
76
|
+
|
|
77
|
+
- `installOptionalDependencies(integration, dependencySpecs, options?)`
|
|
78
|
+
- `installOptionalDependenciesBatch(plans)`
|
|
79
|
+
- `resolveOptionalInstallRoot()`
|
|
80
|
+
- `resolveDevelopInstallRoot()`
|
|
81
|
+
- `hasDependency(projectPath, dependency)`
|
|
82
|
+
|
|
83
|
+
### `installOptionalDependencies(integration, dependencySpecs, options?)`
|
|
84
|
+
|
|
85
|
+
Installs the requested exact dependency specs into the isolated cache root and verifies they can be resolved afterward.
|
|
86
|
+
|
|
87
|
+
### `installOptionalDependenciesBatch(plans)`
|
|
88
|
+
|
|
89
|
+
Installs several integration plans in sequence and stops on the first failure.
|
|
90
|
+
|
|
91
|
+
### `resolveOptionalInstallRoot()`
|
|
92
|
+
|
|
93
|
+
Returns the versioned isolated cache directory used for optional installs.
|
|
94
|
+
|
|
95
|
+
### `resolveDevelopInstallRoot()`
|
|
96
|
+
|
|
97
|
+
Resolves the host `extension-develop` installation root when this package is used inside that runtime.
|
|
98
|
+
|
|
99
|
+
### `hasDependency(projectPath, dependency)`
|
|
100
|
+
|
|
101
|
+
Checks whether the nearest project `package.json` already declares the given dependency.
|
|
102
|
+
|
|
103
|
+
## Guarantees
|
|
104
|
+
|
|
105
|
+
- Optional installs are isolated from the consumer project.
|
|
106
|
+
- User project lockfiles are not modified by bootstrap installs.
|
|
107
|
+
- Install success is verified via follow-up resolution checks.
|
|
108
|
+
- Recovery only resets the isolated optional dependency root.
|
|
109
|
+
|
|
110
|
+
## License
|
|
111
|
+
|
|
112
|
+
MIT (c) Cezar Augusto.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type OptionalDependencyVerificationRule = {
|
|
2
|
+
type: 'install-root';
|
|
3
|
+
packageId: string;
|
|
4
|
+
} | {
|
|
5
|
+
type: 'module-context-resolve';
|
|
6
|
+
fromPackage: string;
|
|
7
|
+
packageId: string;
|
|
8
|
+
} | {
|
|
9
|
+
type: 'module-context-load';
|
|
10
|
+
fromPackage: string;
|
|
11
|
+
packageId: string;
|
|
12
|
+
};
|
|
13
|
+
export type OptionalDependencyContract = {
|
|
14
|
+
id: string;
|
|
15
|
+
integration: string;
|
|
16
|
+
installPackages: string[];
|
|
17
|
+
verificationRules: OptionalDependencyVerificationRule[];
|
|
18
|
+
};
|