@cjser/global-directory__v4_0_1 4.0.1-cjser.2

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.
@@ -0,0 +1,124 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // packages/@cjser/global-directory__v4_0_1.tmp-26-1778147441262/index.js
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
+ default: () => index_default
33
+ });
34
+ module.exports = __toCommonJS(index_exports);
35
+ var import_node_process = __toESM(require("node:process"), 1);
36
+ var import_node_path = __toESM(require("node:path"), 1);
37
+ var import_node_os = __toESM(require("node:os"), 1);
38
+ var import_node_fs = __toESM(require("node:fs"), 1);
39
+ var import_ini = __toESM(require("ini"), 1);
40
+ var isWindows = import_node_process.default.platform === "win32";
41
+ var readRc = (filePath) => {
42
+ try {
43
+ return import_ini.default.parse(import_node_fs.default.readFileSync(filePath, "utf8")).prefix;
44
+ } catch {
45
+ }
46
+ };
47
+ var getEnvNpmPrefix = () => Object.keys(import_node_process.default.env).reduce((prefix, name) => /^npm_config_prefix$/i.test(name) ? import_node_process.default.env[name] : prefix, void 0);
48
+ var getGlobalNpmrc = () => {
49
+ if (isWindows && import_node_process.default.env.APPDATA) {
50
+ return import_node_path.default.join(import_node_process.default.env.APPDATA, "/npm/etc/npmrc");
51
+ }
52
+ if (import_node_process.default.execPath.includes("/Cellar/node")) {
53
+ const homebrewPrefix = import_node_process.default.execPath.slice(0, import_node_process.default.execPath.indexOf("/Cellar/node"));
54
+ return import_node_path.default.join(homebrewPrefix, "/lib/node_modules/npm/npmrc");
55
+ }
56
+ if (import_node_process.default.execPath.endsWith("/bin/node")) {
57
+ const installDir = import_node_path.default.dirname(import_node_path.default.dirname(import_node_process.default.execPath));
58
+ return import_node_path.default.join(installDir, "/etc/npmrc");
59
+ }
60
+ };
61
+ var getDefaultNpmPrefix = () => {
62
+ if (isWindows) {
63
+ const { APPDATA } = import_node_process.default.env;
64
+ return APPDATA ? import_node_path.default.join(APPDATA, "npm") : import_node_path.default.dirname(import_node_process.default.execPath);
65
+ }
66
+ return import_node_path.default.dirname(import_node_path.default.dirname(import_node_process.default.execPath));
67
+ };
68
+ var getNpmPrefix = () => {
69
+ const envPrefix = getEnvNpmPrefix();
70
+ if (envPrefix) {
71
+ return envPrefix;
72
+ }
73
+ const homePrefix = readRc(import_node_path.default.join(import_node_os.default.homedir(), ".npmrc"));
74
+ if (homePrefix) {
75
+ return homePrefix;
76
+ }
77
+ if (import_node_process.default.env.PREFIX) {
78
+ return import_node_process.default.env.PREFIX;
79
+ }
80
+ const globalPrefix = readRc(getGlobalNpmrc());
81
+ if (globalPrefix) {
82
+ return globalPrefix;
83
+ }
84
+ return getDefaultNpmPrefix();
85
+ };
86
+ var npmPrefix = import_node_path.default.resolve(getNpmPrefix());
87
+ var getYarnWindowsDirectory = () => {
88
+ if (isWindows && import_node_process.default.env.LOCALAPPDATA) {
89
+ const dir = import_node_path.default.join(import_node_process.default.env.LOCALAPPDATA, "Yarn");
90
+ if (import_node_fs.default.existsSync(dir)) {
91
+ return dir;
92
+ }
93
+ }
94
+ return false;
95
+ };
96
+ var getYarnPrefix = () => {
97
+ if (import_node_process.default.env.PREFIX) {
98
+ return import_node_process.default.env.PREFIX;
99
+ }
100
+ const windowsPrefix = getYarnWindowsDirectory();
101
+ if (windowsPrefix) {
102
+ return windowsPrefix;
103
+ }
104
+ const configPrefix = import_node_path.default.join(import_node_os.default.homedir(), ".config/yarn");
105
+ if (import_node_fs.default.existsSync(configPrefix)) {
106
+ return configPrefix;
107
+ }
108
+ const homePrefix = import_node_path.default.join(import_node_os.default.homedir(), ".yarn-config");
109
+ if (import_node_fs.default.existsSync(homePrefix)) {
110
+ return homePrefix;
111
+ }
112
+ return npmPrefix;
113
+ };
114
+ var globalDirectory = {};
115
+ globalDirectory.npm = {};
116
+ globalDirectory.npm.prefix = npmPrefix;
117
+ globalDirectory.npm.packages = import_node_path.default.join(npmPrefix, isWindows ? "node_modules" : "lib/node_modules");
118
+ globalDirectory.npm.binaries = isWindows ? npmPrefix : import_node_path.default.join(npmPrefix, "bin");
119
+ var yarnPrefix = import_node_path.default.resolve(getYarnPrefix());
120
+ globalDirectory.yarn = {};
121
+ globalDirectory.yarn.prefix = yarnPrefix;
122
+ globalDirectory.yarn.packages = import_node_path.default.join(yarnPrefix, getYarnWindowsDirectory() ? "Data/global/node_modules" : "global/node_modules");
123
+ globalDirectory.yarn.binaries = import_node_path.default.join(globalDirectory.yarn.packages, ".bin");
124
+ var index_default = globalDirectory;
package/index.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ export type GlobalDirectory = {
2
+ /**
3
+ The directory with globally installed packages.
4
+
5
+ Equivalent to `npm root --global`.
6
+ */
7
+ readonly packages: string;
8
+
9
+ /**
10
+ The directory with globally installed binaries.
11
+
12
+ Equivalent to `npm bin --global`.
13
+ */
14
+ readonly binaries: string;
15
+
16
+ /**
17
+ The directory with directories for packages and binaries. You probably want either of the above.
18
+
19
+ Equivalent to `npm prefix --global`.
20
+ */
21
+ readonly prefix: string;
22
+ };
23
+
24
+ declare const globalDirectory: {
25
+ /**
26
+ Get the directory of globally installed packages and binaries.
27
+
28
+ @example
29
+ ```
30
+ import globalDirectory from '@cjser/global-directory__v4_0_1';
31
+
32
+ console.log(globalDirectory.npm.prefix);
33
+ //=> '/usr/local'
34
+
35
+ console.log(globalDirectory.npm.packages);
36
+ //=> '/usr/local/lib/node_modules'
37
+ ```
38
+ */
39
+ readonly npm: GlobalDirectory;
40
+
41
+ /**
42
+ Get the directory of globally installed packages and binaries.
43
+
44
+ @example
45
+ ```
46
+ import globalDirectory from '@cjser/global-directory__v4_0_1';
47
+
48
+ console.log(globalDirectory.npm.binaries);
49
+ //=> '/usr/local/bin'
50
+
51
+ console.log(globalDirectory.yarn.packages);
52
+ //=> '/Users/sindresorhus/.config/yarn/global/node_modules'
53
+ ```
54
+ */
55
+ readonly yarn: GlobalDirectory;
56
+ };
57
+
58
+ export default globalDirectory;
package/index.js ADDED
@@ -0,0 +1,121 @@
1
+ import process from 'node:process';
2
+ import path from 'node:path';
3
+ import os from 'node:os';
4
+ import fs from 'node:fs';
5
+ import ini from 'ini';
6
+
7
+ const isWindows = process.platform === 'win32';
8
+
9
+ const readRc = filePath => {
10
+ try {
11
+ return ini.parse(fs.readFileSync(filePath, 'utf8')).prefix;
12
+ } catch {}
13
+ };
14
+
15
+ // TODO: Remove the `.reduce` call.
16
+ // eslint-disable-next-line unicorn/no-array-reduce
17
+ const getEnvNpmPrefix = () => Object.keys(process.env).reduce((prefix, name) => /^npm_config_prefix$/i.test(name) ? process.env[name] : prefix, undefined);
18
+
19
+ const getGlobalNpmrc = () => {
20
+ if (isWindows && process.env.APPDATA) {
21
+ // Hardcoded contents of `c:\Program Files\nodejs\node_modules\npm\npmrc`
22
+ return path.join(process.env.APPDATA, '/npm/etc/npmrc');
23
+ }
24
+
25
+ // Homebrew special case: `$(brew --prefix)/lib/node_modules/npm/npmrc`
26
+ if (process.execPath.includes('/Cellar/node')) {
27
+ const homebrewPrefix = process.execPath.slice(0, process.execPath.indexOf('/Cellar/node'));
28
+ return path.join(homebrewPrefix, '/lib/node_modules/npm/npmrc');
29
+ }
30
+
31
+ if (process.execPath.endsWith('/bin/node')) {
32
+ const installDir = path.dirname(path.dirname(process.execPath));
33
+ return path.join(installDir, '/etc/npmrc');
34
+ }
35
+ };
36
+
37
+ const getDefaultNpmPrefix = () => {
38
+ if (isWindows) {
39
+ const {APPDATA} = process.env;
40
+ // `c:\node\node.exe` → `prefix=c:\node\`
41
+ return APPDATA ? path.join(APPDATA, 'npm') : path.dirname(process.execPath);
42
+ }
43
+
44
+ // `/usr/local/bin/node` → `prefix=/usr/local`
45
+ return path.dirname(path.dirname(process.execPath));
46
+ };
47
+
48
+ const getNpmPrefix = () => {
49
+ const envPrefix = getEnvNpmPrefix();
50
+ if (envPrefix) {
51
+ return envPrefix;
52
+ }
53
+
54
+ const homePrefix = readRc(path.join(os.homedir(), '.npmrc'));
55
+ if (homePrefix) {
56
+ return homePrefix;
57
+ }
58
+
59
+ if (process.env.PREFIX) {
60
+ return process.env.PREFIX;
61
+ }
62
+
63
+ const globalPrefix = readRc(getGlobalNpmrc());
64
+ if (globalPrefix) {
65
+ return globalPrefix;
66
+ }
67
+
68
+ return getDefaultNpmPrefix();
69
+ };
70
+
71
+ const npmPrefix = path.resolve(getNpmPrefix());
72
+
73
+ const getYarnWindowsDirectory = () => {
74
+ if (isWindows && process.env.LOCALAPPDATA) {
75
+ const dir = path.join(process.env.LOCALAPPDATA, 'Yarn');
76
+ if (fs.existsSync(dir)) {
77
+ return dir;
78
+ }
79
+ }
80
+
81
+ return false;
82
+ };
83
+
84
+ const getYarnPrefix = () => {
85
+ if (process.env.PREFIX) {
86
+ return process.env.PREFIX;
87
+ }
88
+
89
+ const windowsPrefix = getYarnWindowsDirectory();
90
+ if (windowsPrefix) {
91
+ return windowsPrefix;
92
+ }
93
+
94
+ const configPrefix = path.join(os.homedir(), '.config/yarn');
95
+ if (fs.existsSync(configPrefix)) {
96
+ return configPrefix;
97
+ }
98
+
99
+ const homePrefix = path.join(os.homedir(), '.yarn-config');
100
+ if (fs.existsSync(homePrefix)) {
101
+ return homePrefix;
102
+ }
103
+
104
+ // Yarn supports the npm conventions but the inverse is not true
105
+ return npmPrefix;
106
+ };
107
+
108
+ const globalDirectory = {};
109
+
110
+ globalDirectory.npm = {};
111
+ globalDirectory.npm.prefix = npmPrefix;
112
+ globalDirectory.npm.packages = path.join(npmPrefix, isWindows ? 'node_modules' : 'lib/node_modules');
113
+ globalDirectory.npm.binaries = isWindows ? npmPrefix : path.join(npmPrefix, 'bin');
114
+
115
+ const yarnPrefix = path.resolve(getYarnPrefix());
116
+ globalDirectory.yarn = {};
117
+ globalDirectory.yarn.prefix = yarnPrefix;
118
+ globalDirectory.yarn.packages = path.join(yarnPrefix, getYarnWindowsDirectory() ? 'Data/global/node_modules' : 'global/node_modules');
119
+ globalDirectory.yarn.binaries = path.join(globalDirectory.yarn.packages, '.bin');
120
+
121
+ export default globalDirectory;
package/license ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "@cjser/global-directory__v4_0_1",
3
+ "version": "4.0.1-cjser.2",
4
+ "description": "Get the directory of globally installed packages and binaries",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://code.moenext.com/3rdeye/cjser.git"
9
+ },
10
+ "funding": "https://github.com/sponsors/sindresorhus",
11
+ "author": {
12
+ "name": "Sindre Sorhus",
13
+ "email": "sindresorhus@gmail.com",
14
+ "url": "https://sindresorhus.com"
15
+ },
16
+ "type": "module",
17
+ "exports": {
18
+ "types": "./index.d.ts",
19
+ "require": "./dist-cjser/index.cjs",
20
+ "default": "./index.js"
21
+ },
22
+ "sideEffects": false,
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "scripts": {
27
+ "test": "xo && ava && tsd"
28
+ },
29
+ "files": [
30
+ "index.js",
31
+ "index.d.ts",
32
+ "dist-cjser"
33
+ ],
34
+ "keywords": [
35
+ "global",
36
+ "prefix",
37
+ "path",
38
+ "paths",
39
+ "npm",
40
+ "yarn",
41
+ "node",
42
+ "modules",
43
+ "node-modules",
44
+ "package",
45
+ "packages",
46
+ "binary",
47
+ "binaries",
48
+ "bin",
49
+ "directory",
50
+ "directories",
51
+ "npmrc",
52
+ "rc",
53
+ "config",
54
+ "root",
55
+ "resolve"
56
+ ],
57
+ "dependencies": {
58
+ "ini": "4.1.1"
59
+ },
60
+ "devDependencies": {
61
+ "ava": "^5.3.1",
62
+ "execa": "^8.0.1",
63
+ "tsd": "^0.29.0",
64
+ "xo": "^0.56.0"
65
+ },
66
+ "types": "./index.d.ts",
67
+ "main": "./dist-cjser/index.cjs",
68
+ "cjser": {
69
+ "sourceVersion": "4.0.1",
70
+ "cjserVersion": 2,
71
+ "original": {
72
+ "name": "global-directory",
73
+ "version": "4.0.1",
74
+ "exports": {
75
+ "types": "./index.d.ts",
76
+ "default": "./index.js"
77
+ },
78
+ "repository": "sindresorhus/global-directory",
79
+ "dependencies": {
80
+ "ini": "4.1.1"
81
+ },
82
+ "files": [
83
+ "index.js",
84
+ "index.d.ts"
85
+ ],
86
+ "scripts": {
87
+ "test": "xo && ava && tsd"
88
+ }
89
+ }
90
+ }
91
+ }
package/readme.md ADDED
@@ -0,0 +1,65 @@
1
+ # global-directory
2
+
3
+ > Get the directory of globally installed packages and binaries
4
+
5
+ Uses the same resolution logic as `npm` and `yarn`.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install global-directory
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```js
16
+ import globalDirectory from 'global-directory';
17
+
18
+ console.log(globalDirectory.npm.prefix);
19
+ //=> '/usr/local'
20
+
21
+ console.log(globalDirectory.npm.packages);
22
+ //=> '/usr/local/lib/node_modules'
23
+
24
+ console.log(globalDirectory.npm.binaries);
25
+ //=> '/usr/local/bin'
26
+
27
+ console.log(globalDirectory.yarn.packages);
28
+ //=> '/Users/sindresorhus/.config/yarn/global/node_modules'
29
+ ```
30
+
31
+ ## API
32
+
33
+ ### globalDirectory
34
+
35
+ #### npm
36
+ #### yarn
37
+
38
+ ##### packages
39
+
40
+ The directory with globally installed packages.
41
+
42
+ Equivalent to `npm root --global`.
43
+
44
+ ##### binaries
45
+
46
+ The directory with globally installed binaries.
47
+
48
+ Equivalent to `npm bin --global`.
49
+
50
+ ##### prefix
51
+
52
+ The directory with directories for packages and binaries. You probably want either of the above.
53
+
54
+ Equivalent to `npm prefix --global`.
55
+
56
+ ## Related
57
+
58
+ - [import-global](https://github.com/sindresorhus/import-global) - Import a globally installed module
59
+ - [resolve-global](https://github.com/sindresorhus/resolve-global) - Resolve the path of a globally installed module
60
+ - [is-installed-globally](https://github.com/sindresorhus/is-installed-globally) - Check if your package was installed globally
61
+
62
+ ## cjser
63
+
64
+ This package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
65
+ Original repository: https://github.com/sindresorhus/global-directory