-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
constants.js
133 lines (98 loc) · 4.29 KB
/
constants.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* @flow */
const os = require('os');
const path = require('path');
const userHome = require('./util/user-home-dir').default;
const {getCacheDir, getConfigDir, getDataDir} = require('./util/user-dirs');
const isWebpackBundle = require('is-webpack-bundle');
type Env = {
[key: string]: ?string,
};
export const DEPENDENCY_TYPES = ['devDependencies', 'dependencies', 'optionalDependencies', 'peerDependencies'];
export const OWNED_DEPENDENCY_TYPES = ['devDependencies', 'dependencies', 'optionalDependencies'];
export const RESOLUTIONS = 'resolutions';
export const MANIFEST_FIELDS = [RESOLUTIONS, ...DEPENDENCY_TYPES];
export const SUPPORTED_NODE_VERSIONS = '^4.8.0 || ^5.7.0 || ^6.2.2 || >=8.0.0';
export const YARN_REGISTRY = 'https://registry.yarnpkg.com';
export const NPM_REGISTRY_RE = /https?:\/\/registry\.npmjs\.org/g;
export const YARN_DOCS = 'https://yarnpkg.com/en/docs/cli/';
export const YARN_INSTALLER_SH = 'https://yarnpkg.com/install.sh';
export const YARN_INSTALLER_MSI = 'https://yarnpkg.com/latest.msi';
export const SELF_UPDATE_VERSION_URL = 'https://yarnpkg.com/latest-version';
// cache version, bump whenever we make backwards incompatible changes
export const CACHE_VERSION = 4;
// lockfile version, bump whenever we make backwards incompatible changes
export const LOCKFILE_VERSION = 1;
// max amount of network requests to perform concurrently
export const NETWORK_CONCURRENCY = 8;
// HTTP timeout used when downloading packages
export const NETWORK_TIMEOUT = 30 * 1000; // in milliseconds
// max amount of child processes to execute concurrently
export const CHILD_CONCURRENCY = 5;
export const REQUIRED_PACKAGE_KEYS = ['name', 'version', '_uid'];
function getPreferredCacheDirectories(): Array<string> {
const preferredCacheDirectories = [getCacheDir()];
if (process.getuid) {
// $FlowFixMe: process.getuid exists, dammit
preferredCacheDirectories.push(path.join(os.tmpdir(), `.yarn-cache-${process.getuid()}`));
}
preferredCacheDirectories.push(path.join(os.tmpdir(), `.yarn-cache`));
return preferredCacheDirectories;
}
export const PREFERRED_MODULE_CACHE_DIRECTORIES = getPreferredCacheDirectories();
export const CONFIG_DIRECTORY = getConfigDir();
export const DATA_DIRECTORY = getDataDir();
export const LINK_REGISTRY_DIRECTORY = path.join(DATA_DIRECTORY, 'link');
export const GLOBAL_MODULE_DIRECTORY = path.join(DATA_DIRECTORY, 'global');
export const NODE_BIN_PATH = process.execPath;
export const YARN_BIN_PATH = getYarnBinPath();
// Webpack needs to be configured with node.__dirname/__filename = false
function getYarnBinPath(): string {
if (isWebpackBundle) {
return __filename;
} else {
return path.join(__dirname, '..', 'bin', 'yarn.js');
}
}
export const NODE_MODULES_FOLDER = 'node_modules';
export const NODE_PACKAGE_JSON = 'package.json';
export const PNP_FILENAME = '.pnp.js';
export const POSIX_GLOBAL_PREFIX = `${process.env.DESTDIR || ''}/usr/local`;
export const FALLBACK_GLOBAL_PREFIX = path.join(userHome, '.yarn');
export const META_FOLDER = '.yarn-meta';
export const INTEGRITY_FILENAME = '.yarn-integrity';
export const LOCKFILE_FILENAME = 'yarn.lock';
export const METADATA_FILENAME = '.yarn-metadata.json';
export const TARBALL_FILENAME = '.yarn-tarball.tgz';
export const CLEAN_FILENAME = '.yarnclean';
export const NPM_LOCK_FILENAME = 'package-lock.json';
export const NPM_SHRINKWRAP_FILENAME = 'npm-shrinkwrap.json';
export const DEFAULT_INDENT = ' ';
export const SINGLE_INSTANCE_PORT = 31997;
export const SINGLE_INSTANCE_FILENAME = '.yarn-single-instance';
export const ENV_PATH_KEY = getPathKey(process.platform, process.env);
export function getPathKey(platform: string, env: Env): string {
let pathKey = 'PATH';
// windows calls its path "Path" usually, but this is not guaranteed.
if (platform === 'win32') {
pathKey = 'Path';
for (const key in env) {
if (key.toLowerCase() === 'path') {
pathKey = key;
}
}
}
return pathKey;
}
export const VERSION_COLOR_SCHEME: {[key: string]: VersionColor} = {
major: 'red',
premajor: 'red',
minor: 'yellow',
preminor: 'yellow',
patch: 'green',
prepatch: 'green',
prerelease: 'red',
unchanged: 'white',
unknown: 'red',
};
export type VersionColor = 'red' | 'yellow' | 'green' | 'white';
export type RequestHint = 'dev' | 'optional' | 'resolution' | 'workspaces';