penambahan web socket

This commit is contained in:
2025-09-18 19:01:22 +07:00
parent 1d053646a9
commit d7bb2eb5bb
15070 changed files with 2402916 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
export type GlobalDirectory = {
/**
The directory with globally installed packages.
Equivalent to `npm root --global`.
*/
readonly packages: string;
/**
The directory with globally installed binaries.
Equivalent to `npm bin --global`.
*/
readonly binaries: string;
/**
The directory with directories for packages and binaries. You probably want either of the above.
Equivalent to `npm prefix --global`.
*/
readonly prefix: string;
};
declare const globalDirectory: {
/**
Get the directory of globally installed packages and binaries.
@example
```
import globalDirectory from 'global-directory';
console.log(globalDirectory.npm.prefix);
//=> '/usr/local'
console.log(globalDirectory.npm.packages);
//=> '/usr/local/lib/node_modules'
```
*/
readonly npm: GlobalDirectory;
/**
Get the directory of globally installed packages and binaries.
@example
```
import globalDirectory from 'global-directory';
console.log(globalDirectory.npm.binaries);
//=> '/usr/local/bin'
console.log(globalDirectory.yarn.packages);
//=> '/Users/sindresorhus/.config/yarn/global/node_modules'
```
*/
readonly yarn: GlobalDirectory;
};
export default globalDirectory;

View File

@@ -0,0 +1,121 @@
import process from 'node:process';
import path from 'node:path';
import os from 'node:os';
import fs from 'node:fs';
import ini from 'ini';
const isWindows = process.platform === 'win32';
const readRc = filePath => {
try {
return ini.parse(fs.readFileSync(filePath, 'utf8')).prefix;
} catch {}
};
// TODO: Remove the `.reduce` call.
// eslint-disable-next-line unicorn/no-array-reduce
const getEnvNpmPrefix = () => Object.keys(process.env).reduce((prefix, name) => /^npm_config_prefix$/i.test(name) ? process.env[name] : prefix, undefined);
const getGlobalNpmrc = () => {
if (isWindows && process.env.APPDATA) {
// Hardcoded contents of `c:\Program Files\nodejs\node_modules\npm\npmrc`
return path.join(process.env.APPDATA, '/npm/etc/npmrc');
}
// Homebrew special case: `$(brew --prefix)/lib/node_modules/npm/npmrc`
if (process.execPath.includes('/Cellar/node')) {
const homebrewPrefix = process.execPath.slice(0, process.execPath.indexOf('/Cellar/node'));
return path.join(homebrewPrefix, '/lib/node_modules/npm/npmrc');
}
if (process.execPath.endsWith('/bin/node')) {
const installDir = path.dirname(path.dirname(process.execPath));
return path.join(installDir, '/etc/npmrc');
}
};
const getDefaultNpmPrefix = () => {
if (isWindows) {
const {APPDATA} = process.env;
// `c:\node\node.exe` → `prefix=c:\node\`
return APPDATA ? path.join(APPDATA, 'npm') : path.dirname(process.execPath);
}
// `/usr/local/bin/node` → `prefix=/usr/local`
return path.dirname(path.dirname(process.execPath));
};
const getNpmPrefix = () => {
const envPrefix = getEnvNpmPrefix();
if (envPrefix) {
return envPrefix;
}
const homePrefix = readRc(path.join(os.homedir(), '.npmrc'));
if (homePrefix) {
return homePrefix;
}
if (process.env.PREFIX) {
return process.env.PREFIX;
}
const globalPrefix = readRc(getGlobalNpmrc());
if (globalPrefix) {
return globalPrefix;
}
return getDefaultNpmPrefix();
};
const npmPrefix = path.resolve(getNpmPrefix());
const getYarnWindowsDirectory = () => {
if (isWindows && process.env.LOCALAPPDATA) {
const dir = path.join(process.env.LOCALAPPDATA, 'Yarn');
if (fs.existsSync(dir)) {
return dir;
}
}
return false;
};
const getYarnPrefix = () => {
if (process.env.PREFIX) {
return process.env.PREFIX;
}
const windowsPrefix = getYarnWindowsDirectory();
if (windowsPrefix) {
return windowsPrefix;
}
const configPrefix = path.join(os.homedir(), '.config/yarn');
if (fs.existsSync(configPrefix)) {
return configPrefix;
}
const homePrefix = path.join(os.homedir(), '.yarn-config');
if (fs.existsSync(homePrefix)) {
return homePrefix;
}
// Yarn supports the npm conventions but the inverse is not true
return npmPrefix;
};
const globalDirectory = {};
globalDirectory.npm = {};
globalDirectory.npm.prefix = npmPrefix;
globalDirectory.npm.packages = path.join(npmPrefix, isWindows ? 'node_modules' : 'lib/node_modules');
globalDirectory.npm.binaries = isWindows ? npmPrefix : path.join(npmPrefix, 'bin');
const yarnPrefix = path.resolve(getYarnPrefix());
globalDirectory.yarn = {};
globalDirectory.yarn.prefix = yarnPrefix;
globalDirectory.yarn.packages = path.join(yarnPrefix, getYarnWindowsDirectory() ? 'Data/global/node_modules' : 'global/node_modules');
globalDirectory.yarn.binaries = path.join(globalDirectory.yarn.packages, '.bin');
export default globalDirectory;

View File

@@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
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:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
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.

View File

@@ -0,0 +1,61 @@
{
"name": "global-directory",
"version": "4.0.1",
"description": "Get the directory of globally installed packages and binaries",
"license": "MIT",
"repository": "sindresorhus/global-directory",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"sideEffects": false,
"engines": {
"node": ">=18"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"global",
"prefix",
"path",
"paths",
"npm",
"yarn",
"node",
"modules",
"node-modules",
"package",
"packages",
"binary",
"binaries",
"bin",
"directory",
"directories",
"npmrc",
"rc",
"config",
"root",
"resolve"
],
"dependencies": {
"ini": "4.1.1"
},
"devDependencies": {
"ava": "^5.3.1",
"execa": "^8.0.1",
"tsd": "^0.29.0",
"xo": "^0.56.0"
}
}

View File

@@ -0,0 +1,60 @@
# global-directory
> Get the directory of globally installed packages and binaries
Uses the same resolution logic as `npm` and `yarn`.
## Install
```sh
npm install global-directory
```
## Usage
```js
import globalDirectory from 'global-directory';
console.log(globalDirectory.npm.prefix);
//=> '/usr/local'
console.log(globalDirectory.npm.packages);
//=> '/usr/local/lib/node_modules'
console.log(globalDirectory.npm.binaries);
//=> '/usr/local/bin'
console.log(globalDirectory.yarn.packages);
//=> '/Users/sindresorhus/.config/yarn/global/node_modules'
```
## API
### globalDirectory
#### npm
#### yarn
##### packages
The directory with globally installed packages.
Equivalent to `npm root --global`.
##### binaries
The directory with globally installed binaries.
Equivalent to `npm bin --global`.
##### prefix
The directory with directories for packages and binaries. You probably want either of the above.
Equivalent to `npm prefix --global`.
## Related
- [import-global](https://github.com/sindresorhus/import-global) - Import a globally installed module
- [resolve-global](https://github.com/sindresorhus/resolve-global) - Resolve the path of a globally installed module
- [is-installed-globally](https://github.com/sindresorhus/is-installed-globally) - Check if your package was installed globally