@pnpm/installing.context 1001.1.8
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 +22 -0
- package/README.md +15 -0
- package/lib/index.d.ts +152 -0
- package/lib/index.js +188 -0
- package/lib/readLockfiles.d.ts +36 -0
- package/lib/readLockfiles.js +100 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015-2016 Rico Sta. Cruz and other contributors
|
|
4
|
+
Copyright (c) 2016-2026 Zoltan Kochan and other contributors
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @pnpm/get-context
|
|
2
|
+
|
|
3
|
+
> Gets context information about a project
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@pnpm/get-context)
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add @pnpm/get-context
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## License
|
|
14
|
+
|
|
15
|
+
MIT
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { IncludedDependencies, Modules } from '@pnpm/installing.modules-yaml';
|
|
2
|
+
import type { LockfileObject } from '@pnpm/lockfile.fs';
|
|
3
|
+
import type { WorkspacePackages } from '@pnpm/resolving.resolver-base';
|
|
4
|
+
import type { DepPath, HoistedDependencies, ProjectId, ProjectManifest, ProjectRootDir, ProjectRootDirRealPath, ReadPackageHook, Registries } from '@pnpm/types';
|
|
5
|
+
/**
|
|
6
|
+
* Note that some fields are affected by modules directory state. Such fields should be used for
|
|
7
|
+
* mutating the modules directory only or in a manner that does not influence dependency resolution.
|
|
8
|
+
*/
|
|
9
|
+
export interface PnpmContext {
|
|
10
|
+
currentLockfile: LockfileObject;
|
|
11
|
+
currentLockfileIsUpToDate: boolean;
|
|
12
|
+
existsCurrentLockfile: boolean;
|
|
13
|
+
existsWantedLockfile: boolean;
|
|
14
|
+
existsNonEmptyWantedLockfile: boolean;
|
|
15
|
+
extraBinPaths: string[];
|
|
16
|
+
/** Affected by existing modules directory, if it exists. */
|
|
17
|
+
extraNodePaths: string[];
|
|
18
|
+
lockfileHadConflicts: boolean;
|
|
19
|
+
hoistedDependencies: HoistedDependencies;
|
|
20
|
+
/** Required included dependencies or dependencies currently included by the modules directory. */
|
|
21
|
+
include: IncludedDependencies;
|
|
22
|
+
modulesFile: Modules | null;
|
|
23
|
+
pendingBuilds: string[];
|
|
24
|
+
projects: Record<string, {
|
|
25
|
+
modulesDir: string;
|
|
26
|
+
id: ProjectId;
|
|
27
|
+
} & HookOptions & Required<ProjectOptions>>;
|
|
28
|
+
rootModulesDir: string;
|
|
29
|
+
hoistPattern: string[] | undefined;
|
|
30
|
+
/** As applied to existing modules directory, if it exists. */
|
|
31
|
+
currentHoistPattern: string[] | undefined;
|
|
32
|
+
hoistedModulesDir: string;
|
|
33
|
+
publicHoistPattern: string[] | undefined;
|
|
34
|
+
/** As applied to existing modules directory, if it exists. */
|
|
35
|
+
currentPublicHoistPattern: string[] | undefined;
|
|
36
|
+
lockfileDir: string;
|
|
37
|
+
virtualStoreDir: string;
|
|
38
|
+
/** As applied to existing modules directory, otherwise options. */
|
|
39
|
+
virtualStoreDirMaxLength: number;
|
|
40
|
+
/** As applied to existing modules directory, if it exists. */
|
|
41
|
+
skipped: Set<DepPath>;
|
|
42
|
+
storeDir: string;
|
|
43
|
+
wantedLockfile: LockfileObject;
|
|
44
|
+
wantedLockfileIsModified: boolean;
|
|
45
|
+
workspacePackages: WorkspacePackages;
|
|
46
|
+
registries: Registries;
|
|
47
|
+
}
|
|
48
|
+
export interface ProjectOptions {
|
|
49
|
+
buildIndex: number;
|
|
50
|
+
binsDir?: string;
|
|
51
|
+
manifest: ProjectManifest;
|
|
52
|
+
modulesDir?: string;
|
|
53
|
+
rootDir: ProjectRootDir;
|
|
54
|
+
rootDirRealPath?: ProjectRootDirRealPath;
|
|
55
|
+
}
|
|
56
|
+
interface HookOptions {
|
|
57
|
+
originalManifest?: ProjectManifest;
|
|
58
|
+
}
|
|
59
|
+
export interface GetContextOptions {
|
|
60
|
+
autoInstallPeers: boolean;
|
|
61
|
+
ci?: boolean;
|
|
62
|
+
excludeLinksFromLockfile: boolean;
|
|
63
|
+
peersSuffixMaxLength: number;
|
|
64
|
+
allProjects: Array<ProjectOptions & HookOptions>;
|
|
65
|
+
confirmModulesPurge?: boolean;
|
|
66
|
+
force: boolean;
|
|
67
|
+
frozenLockfile?: boolean;
|
|
68
|
+
enableGlobalVirtualStore?: boolean;
|
|
69
|
+
extraBinPaths: string[];
|
|
70
|
+
extendNodePath?: boolean;
|
|
71
|
+
lockfileDir: string;
|
|
72
|
+
modulesDir?: string;
|
|
73
|
+
nodeLinker: 'isolated' | 'hoisted' | 'pnp';
|
|
74
|
+
readPackageHook?: ReadPackageHook;
|
|
75
|
+
include?: IncludedDependencies;
|
|
76
|
+
registries: Registries;
|
|
77
|
+
storeDir: string;
|
|
78
|
+
useLockfile: boolean;
|
|
79
|
+
useGitBranchLockfile?: boolean;
|
|
80
|
+
mergeGitBranchLockfiles?: boolean;
|
|
81
|
+
virtualStoreDir?: string;
|
|
82
|
+
virtualStoreDirMaxLength: number;
|
|
83
|
+
workspacePackages?: WorkspacePackages;
|
|
84
|
+
hoistPattern?: string[] | undefined;
|
|
85
|
+
forceHoistPattern?: boolean;
|
|
86
|
+
publicHoistPattern?: string[] | undefined;
|
|
87
|
+
forcePublicHoistPattern?: boolean;
|
|
88
|
+
global?: boolean;
|
|
89
|
+
}
|
|
90
|
+
export declare function getContext(opts: GetContextOptions): Promise<PnpmContext>;
|
|
91
|
+
export interface PnpmSingleContext {
|
|
92
|
+
currentLockfile: LockfileObject;
|
|
93
|
+
currentLockfileIsUpToDate: boolean;
|
|
94
|
+
existsCurrentLockfile: boolean;
|
|
95
|
+
existsWantedLockfile: boolean;
|
|
96
|
+
existsNonEmptyWantedLockfile: boolean;
|
|
97
|
+
/** Affected by existing modules directory, if it exists. */
|
|
98
|
+
extraBinPaths: string[];
|
|
99
|
+
extraNodePaths: string[];
|
|
100
|
+
lockfileHadConflicts: boolean;
|
|
101
|
+
hoistedDependencies: HoistedDependencies;
|
|
102
|
+
hoistedModulesDir: string;
|
|
103
|
+
hoistPattern: string[] | undefined;
|
|
104
|
+
manifest: ProjectManifest;
|
|
105
|
+
modulesDir: string;
|
|
106
|
+
importerId: string;
|
|
107
|
+
prefix: string;
|
|
108
|
+
/** Required included dependencies or dependencies currently included by the modules directory. */
|
|
109
|
+
include: IncludedDependencies;
|
|
110
|
+
modulesFile: Modules | null;
|
|
111
|
+
pendingBuilds: string[];
|
|
112
|
+
publicHoistPattern: string[] | undefined;
|
|
113
|
+
registries: Registries;
|
|
114
|
+
rootModulesDir: string;
|
|
115
|
+
lockfileDir: string;
|
|
116
|
+
virtualStoreDir: string;
|
|
117
|
+
/** As applied to existing modules directory, if it exists. */
|
|
118
|
+
skipped: Set<string>;
|
|
119
|
+
storeDir: string;
|
|
120
|
+
wantedLockfile: LockfileObject;
|
|
121
|
+
wantedLockfileIsModified: boolean;
|
|
122
|
+
}
|
|
123
|
+
export declare function getContextForSingleImporter(manifest: ProjectManifest, opts: {
|
|
124
|
+
autoInstallPeers: boolean;
|
|
125
|
+
ci?: boolean;
|
|
126
|
+
enableGlobalVirtualStore?: boolean;
|
|
127
|
+
excludeLinksFromLockfile: boolean;
|
|
128
|
+
peersSuffixMaxLength: number;
|
|
129
|
+
force: boolean;
|
|
130
|
+
confirmModulesPurge?: boolean;
|
|
131
|
+
extraBinPaths: string[];
|
|
132
|
+
extendNodePath?: boolean;
|
|
133
|
+
lockfileDir: string;
|
|
134
|
+
nodeLinker: 'isolated' | 'hoisted' | 'pnp';
|
|
135
|
+
modulesDir?: string;
|
|
136
|
+
readPackageHook?: ReadPackageHook;
|
|
137
|
+
include?: IncludedDependencies;
|
|
138
|
+
dir: string;
|
|
139
|
+
registries: Registries;
|
|
140
|
+
storeDir: string;
|
|
141
|
+
useLockfile: boolean;
|
|
142
|
+
useGitBranchLockfile?: boolean;
|
|
143
|
+
mergeGitBranchLockfiles?: boolean;
|
|
144
|
+
virtualStoreDir?: string;
|
|
145
|
+
virtualStoreDirMaxLength: number;
|
|
146
|
+
hoistPattern?: string[] | undefined;
|
|
147
|
+
forceHoistPattern?: boolean;
|
|
148
|
+
publicHoistPattern?: string[] | undefined;
|
|
149
|
+
forcePublicHoistPattern?: boolean;
|
|
150
|
+
}): Promise<PnpmSingleContext>;
|
|
151
|
+
export declare function arrayOfWorkspacePackagesToMap(pkgs: Array<Pick<ProjectOptions, 'manifest' | 'rootDir'>>): WorkspacePackages;
|
|
152
|
+
export {};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { contextLogger, packageManifestLogger } from '@pnpm/core-loggers';
|
|
4
|
+
import { readProjectsContext } from '@pnpm/installing.read-projects-context';
|
|
5
|
+
import { registerProject } from '@pnpm/store.controller';
|
|
6
|
+
import { pathAbsolute } from 'path-absolute';
|
|
7
|
+
import { clone } from 'ramda';
|
|
8
|
+
import { readLockfiles } from './readLockfiles.js';
|
|
9
|
+
export async function getContext(opts) {
|
|
10
|
+
const modulesDir = opts.modulesDir ?? 'node_modules';
|
|
11
|
+
const importersContext = await readProjectsContext(opts.allProjects, { lockfileDir: opts.lockfileDir, modulesDir });
|
|
12
|
+
const virtualStoreDir = pathAbsolute(opts.virtualStoreDir ?? path.join(modulesDir, '.pnpm'), opts.lockfileDir);
|
|
13
|
+
await fs.mkdir(opts.storeDir, { recursive: true });
|
|
14
|
+
// Register this project for store prune tracking
|
|
15
|
+
await registerProject(opts.storeDir, opts.lockfileDir);
|
|
16
|
+
for (const project of opts.allProjects) {
|
|
17
|
+
packageManifestLogger.debug({
|
|
18
|
+
initial: project.manifest,
|
|
19
|
+
prefix: project.rootDir,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (opts.readPackageHook != null) {
|
|
23
|
+
await Promise.all(importersContext.projects.map(async (project) => {
|
|
24
|
+
project.originalManifest = project.manifest;
|
|
25
|
+
project.manifest = await opts.readPackageHook(clone(project.manifest), project.rootDir);
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
const extraBinPaths = [
|
|
29
|
+
...opts.extraBinPaths || [],
|
|
30
|
+
];
|
|
31
|
+
const internalPnpmDir = path.join(importersContext.rootModulesDir, '.pnpm');
|
|
32
|
+
const hoistedModulesDir = path.join(opts.enableGlobalVirtualStore ? internalPnpmDir : virtualStoreDir, 'node_modules');
|
|
33
|
+
if (opts.hoistPattern?.length) {
|
|
34
|
+
extraBinPaths.unshift(path.join(hoistedModulesDir, '.bin'));
|
|
35
|
+
}
|
|
36
|
+
const ctx = {
|
|
37
|
+
extraBinPaths,
|
|
38
|
+
extraNodePaths: getExtraNodePaths({
|
|
39
|
+
extendNodePath: opts.extendNodePath,
|
|
40
|
+
nodeLinker: opts.nodeLinker,
|
|
41
|
+
hoistPattern: importersContext.currentHoistPattern ?? opts.hoistPattern,
|
|
42
|
+
hoistedModulesDir,
|
|
43
|
+
}),
|
|
44
|
+
hoistedDependencies: importersContext.hoistedDependencies,
|
|
45
|
+
hoistedModulesDir,
|
|
46
|
+
hoistPattern: opts.hoistPattern,
|
|
47
|
+
currentHoistPattern: importersContext.currentHoistPattern,
|
|
48
|
+
include: opts.include ?? importersContext.include,
|
|
49
|
+
lockfileDir: opts.lockfileDir,
|
|
50
|
+
modulesFile: importersContext.modules,
|
|
51
|
+
pendingBuilds: importersContext.pendingBuilds,
|
|
52
|
+
projects: Object.fromEntries(importersContext.projects.map((project) => [project.rootDir, project])),
|
|
53
|
+
publicHoistPattern: opts.publicHoistPattern,
|
|
54
|
+
currentPublicHoistPattern: importersContext.currentPublicHoistPattern,
|
|
55
|
+
registries: opts.registries,
|
|
56
|
+
rootModulesDir: importersContext.rootModulesDir,
|
|
57
|
+
skipped: importersContext.skipped,
|
|
58
|
+
storeDir: opts.storeDir,
|
|
59
|
+
virtualStoreDir,
|
|
60
|
+
virtualStoreDirMaxLength: importersContext.virtualStoreDirMaxLength ?? opts.virtualStoreDirMaxLength,
|
|
61
|
+
workspacePackages: opts.workspacePackages ?? arrayOfWorkspacePackagesToMap(opts.allProjects),
|
|
62
|
+
...await readLockfiles({
|
|
63
|
+
autoInstallPeers: opts.autoInstallPeers,
|
|
64
|
+
ci: opts.ci,
|
|
65
|
+
excludeLinksFromLockfile: opts.excludeLinksFromLockfile,
|
|
66
|
+
peersSuffixMaxLength: opts.peersSuffixMaxLength,
|
|
67
|
+
force: opts.force,
|
|
68
|
+
frozenLockfile: opts.frozenLockfile === true,
|
|
69
|
+
lockfileDir: opts.lockfileDir,
|
|
70
|
+
projects: importersContext.projects,
|
|
71
|
+
registry: opts.registries.default,
|
|
72
|
+
useLockfile: opts.useLockfile,
|
|
73
|
+
useGitBranchLockfile: opts.useGitBranchLockfile,
|
|
74
|
+
mergeGitBranchLockfiles: opts.mergeGitBranchLockfiles,
|
|
75
|
+
internalPnpmDir,
|
|
76
|
+
}),
|
|
77
|
+
};
|
|
78
|
+
contextLogger.debug({
|
|
79
|
+
currentLockfileExists: ctx.existsCurrentLockfile,
|
|
80
|
+
storeDir: opts.storeDir,
|
|
81
|
+
virtualStoreDir,
|
|
82
|
+
});
|
|
83
|
+
return ctx;
|
|
84
|
+
}
|
|
85
|
+
export async function getContextForSingleImporter(manifest, opts) {
|
|
86
|
+
const { currentHoistPattern, hoistedDependencies, projects, include, modules, pendingBuilds, registries, skipped, rootModulesDir, } = await readProjectsContext([
|
|
87
|
+
{
|
|
88
|
+
rootDir: opts.dir,
|
|
89
|
+
},
|
|
90
|
+
], {
|
|
91
|
+
lockfileDir: opts.lockfileDir,
|
|
92
|
+
modulesDir: opts.modulesDir,
|
|
93
|
+
});
|
|
94
|
+
const storeDir = opts.storeDir;
|
|
95
|
+
const importer = projects[0];
|
|
96
|
+
const modulesDir = importer.modulesDir;
|
|
97
|
+
const importerId = importer.id;
|
|
98
|
+
const virtualStoreDir = pathAbsolute(opts.virtualStoreDir ?? 'node_modules/.pnpm', opts.lockfileDir);
|
|
99
|
+
await fs.mkdir(storeDir, { recursive: true });
|
|
100
|
+
// Register this project for store prune tracking
|
|
101
|
+
await registerProject(storeDir, opts.lockfileDir);
|
|
102
|
+
const extraBinPaths = [
|
|
103
|
+
...opts.extraBinPaths || [],
|
|
104
|
+
];
|
|
105
|
+
const internalPnpmDir = path.join(rootModulesDir, '.pnpm');
|
|
106
|
+
const hoistedModulesDir = path.join(opts.enableGlobalVirtualStore ? internalPnpmDir : virtualStoreDir, 'node_modules');
|
|
107
|
+
if (opts.hoistPattern?.length) {
|
|
108
|
+
extraBinPaths.unshift(path.join(hoistedModulesDir, '.bin'));
|
|
109
|
+
}
|
|
110
|
+
const ctx = {
|
|
111
|
+
extraBinPaths,
|
|
112
|
+
extraNodePaths: getExtraNodePaths({
|
|
113
|
+
extendNodePath: opts.extendNodePath,
|
|
114
|
+
nodeLinker: opts.nodeLinker,
|
|
115
|
+
hoistPattern: currentHoistPattern ?? opts.hoistPattern,
|
|
116
|
+
hoistedModulesDir,
|
|
117
|
+
}),
|
|
118
|
+
hoistedDependencies,
|
|
119
|
+
hoistedModulesDir,
|
|
120
|
+
hoistPattern: opts.hoistPattern,
|
|
121
|
+
importerId,
|
|
122
|
+
include: opts.include ?? include,
|
|
123
|
+
lockfileDir: opts.lockfileDir,
|
|
124
|
+
manifest: await opts.readPackageHook?.(manifest) ?? manifest,
|
|
125
|
+
modulesDir,
|
|
126
|
+
modulesFile: modules,
|
|
127
|
+
pendingBuilds,
|
|
128
|
+
prefix: opts.dir,
|
|
129
|
+
publicHoistPattern: opts.publicHoistPattern,
|
|
130
|
+
registries: {
|
|
131
|
+
...opts.registries,
|
|
132
|
+
...registries,
|
|
133
|
+
},
|
|
134
|
+
rootModulesDir,
|
|
135
|
+
skipped,
|
|
136
|
+
storeDir,
|
|
137
|
+
virtualStoreDir,
|
|
138
|
+
...await readLockfiles({
|
|
139
|
+
autoInstallPeers: opts.autoInstallPeers,
|
|
140
|
+
ci: opts.ci,
|
|
141
|
+
excludeLinksFromLockfile: opts.excludeLinksFromLockfile,
|
|
142
|
+
peersSuffixMaxLength: opts.peersSuffixMaxLength,
|
|
143
|
+
force: opts.force,
|
|
144
|
+
frozenLockfile: false,
|
|
145
|
+
lockfileDir: opts.lockfileDir,
|
|
146
|
+
projects: [{ id: importerId, rootDir: opts.dir }],
|
|
147
|
+
registry: opts.registries.default,
|
|
148
|
+
useLockfile: opts.useLockfile,
|
|
149
|
+
useGitBranchLockfile: opts.useGitBranchLockfile,
|
|
150
|
+
mergeGitBranchLockfiles: opts.mergeGitBranchLockfiles,
|
|
151
|
+
internalPnpmDir,
|
|
152
|
+
}),
|
|
153
|
+
};
|
|
154
|
+
packageManifestLogger.debug({
|
|
155
|
+
initial: manifest,
|
|
156
|
+
prefix: opts.dir,
|
|
157
|
+
});
|
|
158
|
+
contextLogger.debug({
|
|
159
|
+
currentLockfileExists: ctx.existsCurrentLockfile,
|
|
160
|
+
storeDir: opts.storeDir,
|
|
161
|
+
virtualStoreDir,
|
|
162
|
+
});
|
|
163
|
+
return ctx;
|
|
164
|
+
}
|
|
165
|
+
function getExtraNodePaths({ extendNodePath = true, hoistPattern, nodeLinker, hoistedModulesDir }) {
|
|
166
|
+
if (extendNodePath && nodeLinker === 'isolated' && hoistPattern?.length) {
|
|
167
|
+
return [hoistedModulesDir];
|
|
168
|
+
}
|
|
169
|
+
return [];
|
|
170
|
+
}
|
|
171
|
+
export function arrayOfWorkspacePackagesToMap(pkgs) {
|
|
172
|
+
const workspacePkgs = new Map();
|
|
173
|
+
for (const { manifest, rootDir } of pkgs) {
|
|
174
|
+
if (!manifest.name)
|
|
175
|
+
continue;
|
|
176
|
+
let workspacePkgsByVersion = workspacePkgs.get(manifest.name);
|
|
177
|
+
if (!workspacePkgsByVersion) {
|
|
178
|
+
workspacePkgsByVersion = new Map();
|
|
179
|
+
workspacePkgs.set(manifest.name, workspacePkgsByVersion);
|
|
180
|
+
}
|
|
181
|
+
workspacePkgsByVersion.set(manifest.version ?? '0.0.0', {
|
|
182
|
+
manifest: manifest,
|
|
183
|
+
rootDir,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
return workspacePkgs;
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type LockfileObject } from '@pnpm/lockfile.fs';
|
|
2
|
+
import type { ProjectId, ProjectRootDir } from '@pnpm/types';
|
|
3
|
+
export interface PnpmContext {
|
|
4
|
+
currentLockfile: LockfileObject;
|
|
5
|
+
existsCurrentLockfile: boolean;
|
|
6
|
+
existsWantedLockfile: boolean;
|
|
7
|
+
existsNonEmptyWantedLockfile: boolean;
|
|
8
|
+
wantedLockfile: LockfileObject;
|
|
9
|
+
}
|
|
10
|
+
export declare function readLockfiles(opts: {
|
|
11
|
+
autoInstallPeers: boolean;
|
|
12
|
+
excludeLinksFromLockfile: boolean;
|
|
13
|
+
peersSuffixMaxLength: number;
|
|
14
|
+
ci?: boolean;
|
|
15
|
+
force: boolean;
|
|
16
|
+
frozenLockfile: boolean;
|
|
17
|
+
projects: Array<{
|
|
18
|
+
id: ProjectId;
|
|
19
|
+
rootDir: ProjectRootDir;
|
|
20
|
+
}>;
|
|
21
|
+
lockfileDir: string;
|
|
22
|
+
registry: string;
|
|
23
|
+
useLockfile: boolean;
|
|
24
|
+
useGitBranchLockfile?: boolean;
|
|
25
|
+
mergeGitBranchLockfiles?: boolean;
|
|
26
|
+
internalPnpmDir: string;
|
|
27
|
+
}): Promise<{
|
|
28
|
+
currentLockfile: LockfileObject;
|
|
29
|
+
currentLockfileIsUpToDate: boolean;
|
|
30
|
+
existsCurrentLockfile: boolean;
|
|
31
|
+
existsWantedLockfile: boolean;
|
|
32
|
+
existsNonEmptyWantedLockfile: boolean;
|
|
33
|
+
wantedLockfile: LockfileObject;
|
|
34
|
+
wantedLockfileIsModified: boolean;
|
|
35
|
+
lockfileHadConflicts: boolean;
|
|
36
|
+
}>;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { LOCKFILE_VERSION, WANTED_LOCKFILE, } from '@pnpm/constants';
|
|
2
|
+
import { createLockfileObject, existsNonEmptyWantedLockfile, isEmptyLockfile, readCurrentLockfile, readWantedLockfile, readWantedLockfileAndAutofixConflicts, } from '@pnpm/lockfile.fs';
|
|
3
|
+
import { logger } from '@pnpm/logger';
|
|
4
|
+
import { clone, equals } from 'ramda';
|
|
5
|
+
export async function readLockfiles(opts) {
|
|
6
|
+
const wantedLockfileVersion = LOCKFILE_VERSION;
|
|
7
|
+
// On CI, avoid breaking builds due to incompatible lockfiles by default.
|
|
8
|
+
// Ignore incompatible lockfiles only for non-frozen CI installs or when `force` is set;
|
|
9
|
+
// in frozen-lockfile mode, incompatible lockfiles should still fail.
|
|
10
|
+
const lockfileOpts = {
|
|
11
|
+
ignoreIncompatible: opts.force || (opts.ci === true && !opts.frozenLockfile),
|
|
12
|
+
wantedVersions: [LOCKFILE_VERSION],
|
|
13
|
+
useGitBranchLockfile: opts.useGitBranchLockfile,
|
|
14
|
+
mergeGitBranchLockfiles: opts.mergeGitBranchLockfiles,
|
|
15
|
+
};
|
|
16
|
+
const fileReads = [];
|
|
17
|
+
let lockfileHadConflicts = false;
|
|
18
|
+
if (opts.useLockfile) {
|
|
19
|
+
if (!opts.frozenLockfile) {
|
|
20
|
+
fileReads.push((async () => {
|
|
21
|
+
try {
|
|
22
|
+
const { lockfile, hadConflicts } = await readWantedLockfileAndAutofixConflicts(opts.lockfileDir, lockfileOpts);
|
|
23
|
+
lockfileHadConflicts = hadConflicts;
|
|
24
|
+
return lockfile;
|
|
25
|
+
}
|
|
26
|
+
catch (err) { // eslint-disable-line
|
|
27
|
+
logger.warn({
|
|
28
|
+
message: `Ignoring broken lockfile at ${opts.lockfileDir}: ${err.message}`,
|
|
29
|
+
prefix: opts.lockfileDir,
|
|
30
|
+
});
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
})());
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
fileReads.push(readWantedLockfile(opts.lockfileDir, lockfileOpts));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
if (await existsNonEmptyWantedLockfile(opts.lockfileDir, lockfileOpts)) {
|
|
41
|
+
logger.warn({
|
|
42
|
+
message: `A ${WANTED_LOCKFILE} file exists. The current configuration prohibits to read or write a lockfile`,
|
|
43
|
+
prefix: opts.lockfileDir,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
fileReads.push(Promise.resolve(undefined));
|
|
47
|
+
}
|
|
48
|
+
fileReads.push((async () => {
|
|
49
|
+
try {
|
|
50
|
+
return await readCurrentLockfile(opts.internalPnpmDir, lockfileOpts);
|
|
51
|
+
}
|
|
52
|
+
catch (err) { // eslint-disable-line
|
|
53
|
+
logger.warn({
|
|
54
|
+
message: `Ignoring broken lockfile at ${opts.internalPnpmDir}: ${err.message}`,
|
|
55
|
+
prefix: opts.lockfileDir,
|
|
56
|
+
});
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
})());
|
|
60
|
+
const files = await Promise.all(fileReads);
|
|
61
|
+
const sopts = {
|
|
62
|
+
autoInstallPeers: opts.autoInstallPeers,
|
|
63
|
+
excludeLinksFromLockfile: opts.excludeLinksFromLockfile,
|
|
64
|
+
lockfileVersion: wantedLockfileVersion,
|
|
65
|
+
peersSuffixMaxLength: opts.peersSuffixMaxLength,
|
|
66
|
+
};
|
|
67
|
+
const importerIds = opts.projects.map((importer) => importer.id);
|
|
68
|
+
const currentLockfile = files[1] ?? createLockfileObject(importerIds, sopts);
|
|
69
|
+
for (const importerId of importerIds) {
|
|
70
|
+
if (!currentLockfile.importers[importerId]) {
|
|
71
|
+
currentLockfile.importers[importerId] = {
|
|
72
|
+
specifiers: {},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const wantedLockfile = files[0] ??
|
|
77
|
+
(currentLockfile && clone(currentLockfile)) ??
|
|
78
|
+
createLockfileObject(importerIds, sopts);
|
|
79
|
+
let wantedLockfileIsModified = false;
|
|
80
|
+
for (const importerId of importerIds) {
|
|
81
|
+
if (!wantedLockfile.importers[importerId]) {
|
|
82
|
+
wantedLockfileIsModified = true;
|
|
83
|
+
wantedLockfile.importers[importerId] = {
|
|
84
|
+
specifiers: {},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const existsWantedLockfile = files[0] != null;
|
|
89
|
+
return {
|
|
90
|
+
currentLockfile,
|
|
91
|
+
currentLockfileIsUpToDate: equals(currentLockfile, wantedLockfile),
|
|
92
|
+
existsCurrentLockfile: files[1] != null,
|
|
93
|
+
existsWantedLockfile,
|
|
94
|
+
existsNonEmptyWantedLockfile: existsWantedLockfile && !isEmptyLockfile(wantedLockfile),
|
|
95
|
+
wantedLockfile,
|
|
96
|
+
wantedLockfileIsModified,
|
|
97
|
+
lockfileHadConflicts,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=readLockfiles.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pnpm/installing.context",
|
|
3
|
+
"version": "1001.1.8",
|
|
4
|
+
"description": "Gets context information about a project",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pnpm",
|
|
7
|
+
"pnpm11",
|
|
8
|
+
"scripts"
|
|
9
|
+
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"funding": "https://opencollective.com/pnpm",
|
|
12
|
+
"repository": "https://github.com/pnpm/pnpm/tree/main/installing/context",
|
|
13
|
+
"homepage": "https://github.com/pnpm/pnpm/tree/main/installing/context#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/pnpm/pnpm/issues"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "lib/index.js",
|
|
19
|
+
"types": "lib/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": "./lib/index.js"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"lib",
|
|
25
|
+
"!*.map"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"path-absolute": "^2.0.0",
|
|
29
|
+
"ramda": "npm:@pnpm/ramda@0.28.1",
|
|
30
|
+
"@pnpm/installing.modules-yaml": "1000.3.6",
|
|
31
|
+
"@pnpm/core-loggers": "1001.0.4",
|
|
32
|
+
"@pnpm/lockfile.fs": "1001.1.21",
|
|
33
|
+
"@pnpm/installing.read-projects-context": "1000.0.24",
|
|
34
|
+
"@pnpm/resolving.resolver-base": "1005.1.0",
|
|
35
|
+
"@pnpm/constants": "1001.3.1",
|
|
36
|
+
"@pnpm/types": "1000.9.0",
|
|
37
|
+
"@pnpm/store.controller": "1004.0.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@pnpm/logger": ">=1001.0.0 <1002.0.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/ramda": "0.29.12",
|
|
44
|
+
"@pnpm/installing.context": "1001.1.8",
|
|
45
|
+
"@pnpm/logger": "1001.0.1"
|
|
46
|
+
},
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=22.13"
|
|
49
|
+
},
|
|
50
|
+
"jest": {
|
|
51
|
+
"preset": "@pnpm/jest-config"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
55
|
+
"_test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --disable-warning=ExperimentalWarning --disable-warning=DEP0169\" jest",
|
|
56
|
+
"test": "pnpm run compile && pnpm run _test",
|
|
57
|
+
"compile": "tsgo --build && pnpm run lint --fix"
|
|
58
|
+
}
|
|
59
|
+
}
|