or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

tessl/npm-pnpm--lockfile--detect-dep-types

Detect the types of dependencies in pnpm lockfiles

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@pnpm/lockfile.detect-dep-types@1001.0.x

To install, run

npx @tessl/cli install tessl/npm-pnpm--lockfile--detect-dep-types@1001.0.0

0

# @pnpm/lockfile.detect-dep-types

1

2

Detects the types of dependencies in pnpm lockfiles by analyzing dependency paths and categorizing them as development-only, production-only, or both development and production dependencies.

3

4

## Package Information

5

6

- **Package Name**: @pnpm/lockfile.detect-dep-types

7

- **Package Type**: npm

8

- **Language**: TypeScript

9

- **Installation**: `pnpm add @pnpm/lockfile.detect-dep-types`

10

11

## Core Imports

12

13

```typescript

14

import { detectDepTypes, DepType, type DepTypes } from "@pnpm/lockfile.detect-dep-types";

15

```

16

17

For CommonJS:

18

19

```javascript

20

const { detectDepTypes, DepType } = require("@pnpm/lockfile.detect-dep-types");

21

```

22

23

## Basic Usage

24

25

```typescript

26

import { detectDepTypes, DepType } from "@pnpm/lockfile.detect-dep-types";

27

import { readWantedLockfile } from "@pnpm/lockfile.fs";

28

29

// Read an existing pnpm-lock.yaml file

30

const lockfile = await readWantedLockfile(process.cwd());

31

32

if (lockfile) {

33

// Analyze the lockfile to detect dependency types

34

const depTypes = detectDepTypes(lockfile);

35

36

// Check the type of specific dependencies

37

Object.entries(depTypes).forEach(([depPath, depType]) => {

38

switch (depType) {

39

case DepType.ProdOnly:

40

console.log(`${depPath} is used only in production`);

41

break;

42

case DepType.DevOnly:

43

console.log(`${depPath} is used only in development`);

44

break;

45

case DepType.DevAndProd:

46

console.log(`${depPath} is used in both development and production`);

47

break;

48

}

49

});

50

}

51

```

52

53

## Capabilities

54

55

### Dependency Type Detection

56

57

Analyzes a pnpm lockfile and determines the usage context of each dependency.

58

59

```typescript { .api }

60

/**

61

* Detects the types of dependencies in a pnpm lockfile

62

* @param lockfile - The pnpm lockfile object to analyze

63

* @returns Record mapping dependency paths to their classification types

64

*/

65

function detectDepTypes(lockfile: LockfileObject): DepTypes;

66

```

67

68

**Usage Example:**

69

70

```typescript

71

import { detectDepTypes } from "@pnpm/lockfile.detect-dep-types";

72

import type { LockfileObject } from "@pnpm/lockfile.types";

73

74

const lockfile: LockfileObject = {

75

lockfileVersion: '6.0',

76

importers: {

77

'.': {

78

specifiers: {

79

'lodash': '^4.17.21',

80

'typescript': '^4.5.0'

81

},

82

dependencies: {

83

'lodash': 'registry.npmjs.org/lodash/4.17.21'

84

},

85

devDependencies: {

86

'typescript': 'registry.npmjs.org/typescript/4.5.0'

87

}

88

}

89

},

90

packages: {

91

'registry.npmjs.org/lodash/4.17.21': {

92

resolution: { integrity: 'sha512-...' },

93

dependencies: {}

94

},

95

'registry.npmjs.org/typescript/4.5.0': {

96

resolution: { integrity: 'sha512-...' },

97

dependencies: {}

98

}

99

}

100

};

101

102

const depTypes = detectDepTypes(lockfile);

103

// Returns: {

104

// 'registry.npmjs.org/lodash/4.17.21': DepType.ProdOnly,

105

// 'registry.npmjs.org/typescript/4.5.0': DepType.DevOnly

106

// }

107

```

108

109

## Types

110

111

### DepType Enum

112

113

Enumeration defining the possible dependency type classifications.

114

115

```typescript { .api }

116

enum DepType {

117

/** Dependency used only in development */

118

DevOnly = 0,

119

/** Dependency used in both development and production */

120

DevAndProd = 1,

121

/** Dependency used only in production */

122

ProdOnly = 2

123

}

124

```

125

126

### DepTypes Type

127

128

Record type mapping dependency paths to their classifications.

129

130

```typescript { .api }

131

/**

132

* Record mapping dependency path strings to their corresponding DepType classification

133

*/

134

type DepTypes = Record<string, DepType>;

135

```

136

137

### External Types

138

139

The package relies on types from `@pnpm/lockfile.types` and related packages:

140

141

```typescript { .api }

142

import type { DepPath } from "@pnpm/types";

143

144

interface LockfileObject extends LockfileBase {

145

importers: Record<ProjectId, ProjectSnapshot>;

146

packages?: PackageSnapshots;

147

}

148

149

interface LockfileBase {

150

lockfileVersion: string;

151

catalogs?: CatalogSnapshots;

152

ignoredOptionalDependencies?: string[];

153

overrides?: Record<string, string>;

154

packageExtensionsChecksum?: string;

155

patchedDependencies?: Record<string, PatchFile>;

156

pnpmfileChecksum?: string;

157

settings?: LockfileSettings;

158

time?: Record<string, string>;

159

}

160

161

interface ProjectSnapshot extends ProjectSnapshotBase {

162

specifiers: ResolvedDependencies;

163

dependencies?: ResolvedDependencies;

164

optionalDependencies?: ResolvedDependencies;

165

devDependencies?: ResolvedDependencies;

166

}

167

168

interface ProjectSnapshotBase {

169

dependenciesMeta?: DependenciesMeta;

170

publishDirectory?: string;

171

}

172

173

interface PackageSnapshots {

174

[packagePath: DepPath]: PackageSnapshot;

175

}

176

177

interface PackageSnapshot extends LockfilePackageInfo {

178

optional?: true;

179

dependencies?: ResolvedDependencies;

180

optionalDependencies?: ResolvedDependencies;

181

transitivePeerDependencies?: string[];

182

}

183

184

interface LockfilePackageInfo {

185

id?: string;

186

patched?: true;

187

hasBin?: true;

188

name?: string;

189

version?: string;

190

resolution: LockfileResolution;

191

peerDependencies?: Record<string, string>;

192

peerDependenciesMeta?: Record<string, { optional: true }>;

193

bundledDependencies?: string[] | boolean;

194

engines?: Record<string, string> & { node: string };

195

os?: string[];

196

cpu?: string[];

197

libc?: string[];

198

deprecated?: string;

199

}

200

201

/** Record mapping dependency names to their resolved references */

202

type ResolvedDependencies = Record<string, string>;

203

204

interface LockfileResolution {

205

integrity?: string;

206

tarball?: string;

207

}

208

209

/** Branded string type representing dependency paths in pnpm */

210

type DepPath = string & { __brand: 'DepPath' };

211

212

type ProjectId = string & { __brand: 'ProjectId' };

213

```