Skip to content

Commit 5fd1a1e

Browse files
committed
Add more bun/pnpm/vlt/yarn constants
1 parent fd86e61 commit 5fd1a1e

15 files changed

+306
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare const bunCachePath: string
2+
export = bunCachePath
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict'
2+
3+
const path = require('node:path')
4+
const ENV = /*@__PURE__*/ require('./env')
5+
const WIN32 = /*@__PURE__*/ require('./win32')
6+
7+
// Bun cache directory path.
8+
// Bun stores its cache in a platform-specific location.
9+
//
10+
// Default locations:
11+
// - macOS: ~/Library/Caches/bun
12+
// - Linux: ~/.bun/install/cache
13+
// - Windows: %TEMP%/bun
14+
//
15+
// Can be overridden by:
16+
// - BUN_INSTALL_CACHE_DIR environment variable
17+
// - cache.dir setting in bunfig.toml
18+
//
19+
// Documentation: https://bun.sh/docs/runtime/bunfig#cache-dir
20+
function getBunCachePath() {
21+
// Check for explicit BUN_INSTALL_CACHE_DIR environment variable.
22+
const bunCacheDir = process.env.BUN_INSTALL_CACHE_DIR
23+
if (bunCacheDir) {
24+
return bunCacheDir
25+
}
26+
27+
if (WIN32) {
28+
// On Windows, Bun uses TEMP directory.
29+
const temp = process.env.TEMP || process.env.TMP
30+
return temp ? path.join(temp, 'bun') : ''
31+
}
32+
33+
// On macOS, use Library/Caches.
34+
if (process.platform === 'darwin' && ENV.HOME) {
35+
return path.join(ENV.HOME, 'Library', 'Caches', 'bun')
36+
}
37+
38+
// On Linux/Unix, use ~/.bun/install/cache.
39+
return ENV.HOME ? path.join(ENV.HOME, '.bun', 'install', 'cache') : ''
40+
}
41+
42+
module.exports = getBunCachePath()

registry/lib/constants/index.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import abortSignal from './abort-signal'
33
import AT_LATEST from './at-latest'
44
import BIOME_JSON from './biome-json'
55
import BUN from './bun'
6+
import bunCachePath from './bun-cache-path'
67
import BUN_LOCK from './bun-lock'
78
import BUN_LOCKB from './bun-lockb'
89
import CI from './ci'
@@ -60,6 +61,7 @@ import nodeNoWarningsFlags from './node-no-warnings-flags'
6061
import NODE_VERSION from './node-version'
6162
import NPM from './npm'
6263
import npmExecPath from './npm-exec-path'
64+
import npmLifecycleEvent from './npm-lifecycle-event'
6365
import npmRealExecPath from './npm-real-exec-path'
6466
import NPM_SHRINKWRAP_JSON from './npm-shrinkwrap-json'
6567
import NPX from './npx'
@@ -70,11 +72,13 @@ import PACKAGE_DEFAULT_VERSION from './package-default-version'
7072
import packageExtensions from './package-extensions'
7173
import PACKAGE_JSON from './package-json'
7274
import PACKAGE_LOCK_JSON from './package-lock-json'
75+
import packageManagerCacheNames from './package-manager-cache-names'
7376
import packumentCache from './packument-cache'
7477
import pacoteCachePath from './pacote-cache-path'
7578
import PNPM from './pnpm'
7679
import pnpmExecPath from './pnpm-exec-path'
7780
import PNPM_LOCK_YAML from './pnpm-lock-yaml'
81+
import pnpmStorePath from './pnpm-store-path'
7882
import PRE_COMMIT from './pre-commit'
7983
import README_GLOB from './readme-glob'
8084
import README_GLOB_RECURSIVE from './readme-glob-recursive'
@@ -110,10 +114,12 @@ import UNLICENSED from './unlicensed'
110114
import UTF8 from './utf8'
111115
import VITEST from './vitest'
112116
import VLT from './vlt'
117+
import vltCachePath from './vlt-cache-path'
113118
import VLT_LOCK_JSON from './vlt-lock-json'
114119
import WIN32 from './win32'
115120
import YARN from './yarn'
116121
import YARN_BERRY from './yarn-berry'
122+
import yarnCachePath from './yarn-cache-path'
117123
import YARN_CLASSIC from './yarn-classic'
118124
import yarnExecPath from './yarn-exec-path'
119125
import YARN_LOCK from './yarn-lock'
@@ -136,6 +142,7 @@ declare const Constants: {
136142
readonly AT_LATEST: typeof AT_LATEST
137143
readonly BIOME_JSON: typeof BIOME_JSON
138144
readonly BUN: typeof BUN
145+
readonly bunCachePath: typeof bunCachePath
139146
readonly BUN_LOCK: typeof BUN_LOCK
140147
readonly BUN_LOCKB: typeof BUN_LOCKB
141148
readonly CI: typeof CI
@@ -183,6 +190,7 @@ declare const Constants: {
183190
readonly NODE_MODULES_GLOB_RECURSIVE: typeof NODE_MODULES_GLOB_RECURSIVE
184191
readonly NODE_VERSION: typeof NODE_VERSION
185192
readonly NPM: typeof NPM
193+
readonly npmLifecycleEvent: typeof npmLifecycleEvent
186194
readonly NPM_SHRINKWRAP_JSON: typeof NPM_SHRINKWRAP_JSON
187195
readonly NPX: typeof NPX
188196
readonly OVERRIDES: typeof OVERRIDES
@@ -193,6 +201,7 @@ declare const Constants: {
193201
readonly PACKAGE_LOCK_JSON: typeof PACKAGE_LOCK_JSON
194202
readonly PNPM: typeof PNPM
195203
readonly PNPM_LOCK_YAML: typeof PNPM_LOCK_YAML
204+
readonly pnpmStorePath: typeof pnpmStorePath
196205
readonly PRE_COMMIT: typeof PRE_COMMIT
197206
readonly README_GLOB: typeof README_GLOB
198207
readonly README_GLOB_RECURSIVE: typeof README_GLOB_RECURSIVE
@@ -225,10 +234,12 @@ declare const Constants: {
225234
readonly UTF8: typeof UTF8
226235
readonly VITEST: typeof VITEST
227236
readonly VLT: typeof VLT
237+
readonly vltCachePath: typeof vltCachePath
228238
readonly VLT_LOCK_JSON: typeof VLT_LOCK_JSON
229239
readonly WIN32: typeof WIN32
230240
readonly YARN: typeof YARN
231241
readonly YARN_BERRY: typeof YARN_BERRY
242+
readonly yarnCachePath: typeof yarnCachePath
232243
readonly YARN_CLASSIC: typeof YARN_CLASSIC
233244
readonly YARN_LOCK: typeof YARN_LOCK
234245
readonly abortController: typeof abortController
@@ -244,6 +255,7 @@ declare const Constants: {
244255
readonly npmExecPath: typeof npmExecPath
245256
readonly npmRealExecPath: typeof npmRealExecPath
246257
readonly packageExtensions: typeof packageExtensions
258+
readonly packageManagerCacheNames: typeof packageManagerCacheNames
247259
readonly packumentCache: typeof packumentCache
248260
readonly pacoteCachePath: typeof pacoteCachePath
249261
readonly pnpmExecPath: typeof pnpmExecPath

registry/lib/constants/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const props = {
1111
BUN: 'bun',
1212
BUN_LOCK: 'bun.lock',
1313
BUN_LOCKB: 'bun.lockb',
14+
bunCachePath: undefined,
1415
CI: 'CI',
1516
COLUMN_LIMIT: 80,
1617
DARWIN: undefined,
@@ -55,6 +56,7 @@ const props = {
5556
NODE_MODULES_GLOB_RECURSIVE: '**/node_modules',
5657
NODE_VERSION: undefined,
5758
NPM: 'npm',
59+
npmLifecycleEvent: undefined,
5860
NPM_SHRINKWRAP_JSON: 'npm-shrinkwrap.json',
5961
NPX: 'npx',
6062
OVERRIDES: 'overrides',
@@ -65,6 +67,7 @@ const props = {
6567
PACKAGE_LOCK_JSON: 'package-lock.json',
6668
PNPM: 'pnpm',
6769
PNPM_LOCK_YAML: 'pnpm-lock.yaml',
70+
pnpmStorePath: undefined,
6871
PRE_COMMIT: 'PRE_COMMIT',
6972
README_GLOB: 'README{.*,}',
7073
README_GLOB_RECURSIVE: '**/README{.*,}',
@@ -99,9 +102,11 @@ const props = {
99102
VITEST: 'VITEST',
100103
VLT: 'vlt',
101104
VLT_LOCK_JSON: 'vlt-lock.json',
105+
vltCachePath: undefined,
102106
WIN32: undefined,
103107
YARN: 'yarn',
104108
YARN_BERRY: 'yarn/berry',
109+
yarnCachePath: undefined,
105110
YARN_CLASSIC: 'yarn/classic',
106111
YARN_LOCK: 'yarn.lock',
107112
abortController: undefined,
@@ -117,6 +122,7 @@ const props = {
117122
npmExecPath: undefined,
118123
npmRealExecPath: undefined,
119124
packageExtensions: undefined,
125+
packageManagerCacheNames: undefined,
120126
pnpmExecPath: undefined,
121127
packumentCache: undefined,
122128
pacoteCachePath: undefined,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare const npmLifecycleEvent: string
2+
export = npmLifecycleEvent
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict'
2+
3+
const { envAsString } = /*@__PURE__*/ require('../env')
4+
5+
// npm_lifecycle_event is set by npm, pnpm, yarn, bun, and vlt during script execution.
6+
// This environment variable contains the name of the script being run (e.g., 'test', 'build', 'start').
7+
// It's universally supported across all major package managers:
8+
// - npm: Sets this for all lifecycle scripts since early versions
9+
// - pnpm: Fully compatible with npm's behavior
10+
// - yarn: Both Classic (v1) and Berry (v2+) set this variable
11+
// - bun: Sets this when running scripts via 'bun run'
12+
// - vlt: The new Volt package manager by npm also sets this
13+
//
14+
// Examples:
15+
// - When running 'npm test', npm_lifecycle_event = 'test'
16+
// - When running 'pnpm build', npm_lifecycle_event = 'build'
17+
// - When running 'yarn start', npm_lifecycle_event = 'start'
18+
// - When running 'bun run dev', npm_lifecycle_event = 'dev'
19+
// - When running 'vlt run lint', npm_lifecycle_event = 'lint'
20+
//
21+
// This is useful for scripts that need to know which lifecycle event triggered them,
22+
// allowing conditional behavior based on the current script context.
23+
module.exports = envAsString(process.env.npm_lifecycle_event)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
interface PackageManagerCacheNames {
2+
readonly NPM_CACHE_DIR: '.npm'
3+
readonly PNPM_STORE_DIR: 'pnpm'
4+
readonly YARN_CLASSIC_CACHE_DIR: 'yarn'
5+
readonly YARN_BERRY_CACHE_DIR: '.yarn/cache'
6+
readonly BUN_CACHE_DIR: 'bun'
7+
readonly VLT_CACHE_DIR: 'vlt'
8+
}
9+
declare const packageManagerCacheNames: PackageManagerCacheNames
10+
export = packageManagerCacheNames
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict'
2+
3+
const { freeze: ObjectFreeze } = Object
4+
5+
// Package manager cache directory names.
6+
// These are the standard directory names used by each package manager
7+
// for their cache storage. These names are consistent across platforms.
8+
//
9+
// npm: Uses .npm directory
10+
// pnpm: Uses pnpm/store directory structure
11+
// yarn classic: Uses yarn directory
12+
// yarn berry: Uses .yarn/cache directory structure
13+
// bun: Uses bun directory
14+
// vlt: Uses vlt directory
15+
//
16+
// These constants are useful for:
17+
// - Identifying cache directories in file systems
18+
// - Creating gitignore patterns
19+
// - Cleaning up cache directories
20+
// - Detecting which package manager created a cache
21+
module.exports = ObjectFreeze({
22+
__proto__: null,
23+
// npm cache directory name (usually in home directory as .npm).
24+
NPM_CACHE_DIR: '.npm',
25+
// pnpm store directory name.
26+
PNPM_STORE_DIR: 'pnpm',
27+
// Yarn Classic cache directory name.
28+
YARN_CLASSIC_CACHE_DIR: 'yarn',
29+
// Yarn Berry cache directory path relative to project.
30+
YARN_BERRY_CACHE_DIR: '.yarn/cache',
31+
// Bun cache directory name.
32+
BUN_CACHE_DIR: 'bun',
33+
// Vlt cache directory name.
34+
VLT_CACHE_DIR: 'vlt'
35+
})
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare const pnpmStorePath: string
2+
export = pnpmStorePath
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict'
2+
3+
const path = require('node:path')
4+
const ENV = /*@__PURE__*/ require('./env')
5+
const WIN32 = /*@__PURE__*/ require('./win32')
6+
7+
// PNPM store path - the global package store location.
8+
// By default:
9+
// - macOS: ~/Library/pnpm/store
10+
// - Linux: ~/.local/share/pnpm/store (or $XDG_DATA_HOME/pnpm/store if set)
11+
// - Windows: %LOCALAPPDATA%/pnpm/store
12+
//
13+
// Can be overridden by:
14+
// - PNPM_HOME environment variable
15+
// - pnpm config store-dir setting
16+
// - .npmrc store-dir setting
17+
//
18+
// Documentation: https://pnpm.io/npmrc#store-dir
19+
function getPnpmStorePath() {
20+
// Check for explicit PNPM_HOME environment variable.
21+
const pnpmHome = process.env.PNPM_HOME
22+
if (pnpmHome) {
23+
return path.join(pnpmHome, 'store')
24+
}
25+
26+
if (WIN32) {
27+
// On Windows, use LOCALAPPDATA.
28+
return ENV.LOCALAPPDATA ? path.join(ENV.LOCALAPPDATA, 'pnpm', 'store') : ''
29+
}
30+
31+
// On Unix-like systems, follow XDG Base Directory specification.
32+
if (ENV.XDG_DATA_HOME) {
33+
return path.join(ENV.XDG_DATA_HOME, 'pnpm', 'store')
34+
}
35+
36+
// macOS default location.
37+
if (process.platform === 'darwin' && ENV.HOME) {
38+
return path.join(ENV.HOME, 'Library', 'pnpm', 'store')
39+
}
40+
41+
// Linux/Unix default location.
42+
return ENV.HOME ? path.join(ENV.HOME, '.local', 'share', 'pnpm', 'store') : ''
43+
}
44+
45+
module.exports = getPnpmStorePath()

0 commit comments

Comments
 (0)