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,111 @@
MIT License
Copyright (c) Pooya Parsa <pooya@pi0.io>
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.
---
This is a derivative work based on:
<https://github.com/unjs/mlly>.
---
This is a derivative work based on:
<https://github.com/wooorm/import-meta-resolve>.
Which is licensed:
"""
(The MIT License)
Copyright (c) 2021 Titus Wormer <mailto:tituswormer@gmail.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.
"""
---
This is a derivative work based on:
<https://github.com/nodejs/node>.
Which is licensed:
"""
Copyright Node.js contributors. All rights reserved.
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.
"""
This license applies to parts of Node.js originating from the
https://github.com/joyent/node repository:
"""
Copyright Joyent, Inc. and other Node contributors. All rights reserved.
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,213 @@
# exsolve
[![npm version](https://img.shields.io/npm/v/exsolve?color=yellow)](https://npmjs.com/package/exsolve)
[![npm downloads](https://img.shields.io/npm/dm/exsolve?color=yellow)](https://npm.chart.dev/exsolve)
[![pkg size](https://img.shields.io/npm/unpacked-size/exsolve?color=yellow)](https://packagephobia.com/result?p=exsolve)
> Module resolution utilities for Node.js (based on previous work in [unjs/mlly](https://github.com/unjs/mlly), [wooorm/import-meta-resolve](https://github.com/wooorm/import-meta-resolve), and the upstream [Node.js](https://github.com/nodejs/node) implementation).
This library exposes an API similar to [`import.meta.resolve`](https://nodejs.org/api/esm.html#importmetaresolvespecifier) based on Node.js's upstream implementation and [resolution algorithm](https://nodejs.org/api/esm.html#esm_resolution_algorithm). It supports all built-in functionalities—import maps, export maps, CJS, and ESM—with some additions:
- Pure JS with no native dependencies (only Node.js is required).
- Built-in resolve [cache](#resolve-cache).
- Throws an error (or [try](#try)) if the resolved path does not exist in the filesystem.
- Can override the default [conditions](#conditions).
- Can resolve [from](#from) one or more parent URLs.
- Can resolve with custom [suffixes](#suffixes).
- Can resolve with custom [extensions](#extensions).
## Usage
Install the package:
```sh
# ✨ Auto-detect (npm, yarn, pnpm, bun, deno)
npx nypm install exsolve
```
Import:
```ts
// ESM import
import {
resolveModuleURL,
resolveModulePath,
createResolver,
clearResolveCache,
} from "exsolve";
// Or using dynamic import
const { resolveModulePath } = await import("exsolve");
```
```ts
resolveModuleURL(id, {
/* options */
});
resolveModulePath(id, {
/* options */
});
```
Differences between `resolveModuleURL` and `resolveModulePath`:
- `resolveModuleURL` returns a URL string like `file:///app/dep.mjs`.
- `resolveModulePath` returns an absolute path like `/app/dep.mjs`.
- If the resolved URL does not use the `file://` scheme (e.g., `data:` or `node:`), it will throw an error.
## Resolver with Options
You can create a custom resolver instance with default [options](#resolve-options) using `createResolver`.
**Example:**
```ts
import { createResolver } from "exsolve";
const { resolveModuleURL, resolveModulePath } = createResolver({
suffixes: ["", "/index"],
extensions: [".mjs", ".cjs", ".js", ".mts", ".cts", ".ts", ".json"],
conditions: ["node", "import", "production"],
});
```
## Resolve Cache
To speed up resolution, resolved values (and errors) are globally cached with a unique key based on id and options.
**Example:** Invalidate all (global) cache entries (to support file-system changes).
```ts
import { clearResolveCache } from "exsolve";
clearResolveCache();
```
**Example:** Custom resolver with custom cache object.
```ts
import { createResolver } from "exsolve";
const { clearResolveCache, resolveModulePath } = createResolver({
cache: new Map(),
});
```
**Example:** Resolve without cache.
```ts
import { resolveModulePath } from "exsolve";
resolveModulePath("id", { cache: false });
```
## Resolve Options
### `try`
If set to `true` and the module cannot be resolved, the resolver returns `undefined` instead of throwing an error.
**Example:**
```ts
// undefined
const resolved = resolveModuleURL("non-existing-package", { try: true });
```
### `from`
A URL, path, or array of URLs/paths from which to resolve the module.
If not provided, resolution starts from the current working directory. Setting this option is recommended.
You can use `import.meta.url` for `from` to mimic the behavior of `import.meta.resolve()`.
> [!TIP]
> For better performance, ensure the value is a `file://` URL or at least ends with `/`.
>
> If it is set to an absolute path, the resolver must first check the filesystem to see if it is a file or directory.
> If the input is a `file://` URL or ends with `/`, the resolver can skip this check.
### `conditions`
Conditions to apply when resolving package exports (default: `["node", "import"]`).
**Example:**
```ts
// "/app/src/index.ts"
const src = resolveModuleURL("pkg-name", {
conditions: ["deno", "node", "import", "production"],
});
```
> [!NOTE]
> Conditions are applied **without order**. The order is determined by the `exports` field in `package.json`.
### `extensions`
Additional file extensions to check as fallbacks.
**Example:**
```ts
// "/app/src/index.ts"
const src = resolveModulePath("./src/index", {
extensions: [".mjs", ".cjs", ".js", ".mts", ".cts", ".ts", ".json"],
});
```
> [!TIP]
> For better performance, use explicit extensions and avoid this option.
### `suffixes`
Path suffixes to check.
**Example:**
```ts
// "/app/src/utils/index.ts"
const src = resolveModulePath("./src/utils", {
suffixes: ["", "/index"],
extensions: [".mjs", ".cjs", ".js"],
});
```
> [!TIP]
> For better performance, use explicit `/index` when needed and avoid this option.
### `cache`
Resolve cache (enabled by default with a shared global object).
Can be set to `false` to disable or a custom `Map` to bring your own cache object.
See [cache](#resolve-cache) for more info.
## Other Performance Tips
**Use explicit module extensions `.mjs` or `.cjs` instead of `.js`:**
This allows the resolution fast path to skip reading the closest `package.json` for the [`type`](https://nodejs.org/api/packages.html#type).
## Development
<details>
<summary>local development</summary>
- Clone this repository
- Install the latest LTS version of [Node.js](https://nodejs.org/en/)
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
- Install dependencies using `pnpm install`
- Run interactive tests using `pnpm dev`
</details>
## License
Published under the [MIT](https://github.com/unjs/exsolve/blob/main/LICENSE) license.
Based on previous work in [unjs/mlly](https://github.com/unjs/mlly), [wooorm/import-meta-resolve](https://github.com/wooorm/import-meta-resolve) and [Node.js](https://github.com/nodejs/node) original implementation.

View File

@@ -0,0 +1,68 @@
/**
* Options to configure module resolution.
*/
type ResolveOptions = {
/**
* A URL, path, or array of URLs/paths from which to resolve the module.
* If not provided, resolution starts from the current working directory.
* You can use `import.meta.url` to mimic the behavior of `import.meta.resolve()`.
* For better performance, use a `file://` URL or path that ends with `/`.
*/
from?: string | URL | (string | URL)[];
/**
* Resolve cache (enabled by default with a shared global object).
* Can be set to `false` to disable or a custom `Map` to bring your own cache object.
*/
cache?: boolean | Map<string, unknown>;
/**
* Additional file extensions to check.
* For better performance, use explicit extensions and avoid this option.
*/
extensions?: string[];
/**
* Conditions to apply when resolving package exports.
* Defaults to `["node", "import"]`.
* Conditions are applied without order.
*/
conditions?: string[];
/**
* Path suffixes to check.
* For better performance, use explicit paths and avoid this option.
* Example: `["", "/index"]`
*/
suffixes?: string[];
/**
* If set to `true` and the module cannot be resolved,
* the resolver returns `undefined` instead of throwing an error.
*/
try?: boolean;
};
type ResolverOptions = Omit<ResolveOptions, "try">;
type ResolveRes<Opts extends ResolveOptions> = Opts["try"] extends true ? string | undefined : string;
/**
* Synchronously resolves a module url based on the options provided.
*
* @param {string} input - The identifier or path of the module to resolve.
* @param {ResolveOptions} [options] - Options to resolve the module. See {@link ResolveOptions}.
* @returns {string} The resolved URL as a string.
*/
declare function resolveModuleURL<O extends ResolveOptions>(input: string | URL, options?: O): ResolveRes<O>;
/**
* Synchronously resolves a module then converts it to a file path
*
* (throws error if reolved path is not file:// scheme)
*
* @param {string} id - The identifier or path of the module to resolve.
* @param {ResolveOptions} [options] - Options to resolve the module. See {@link ResolveOptions}.
* @returns {string} The resolved URL as a string.
*/
declare function resolveModulePath<O extends ResolveOptions>(id: string | URL, options?: O): ResolveRes<O>;
declare function createResolver(defaults?: ResolverOptions): {
resolveModuleURL: <O extends ResolveOptions>(id: string | URL, opts: ResolveOptions) => ResolveRes<O>;
resolveModulePath: <O extends ResolveOptions>(id: string | URL, opts: ResolveOptions) => ResolveRes<O>;
clearResolveCache: () => void;
};
declare function clearResolveCache(): void;
export { clearResolveCache, createResolver, resolveModulePath, resolveModuleURL };
export type { ResolveOptions, ResolverOptions };

View File

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,43 @@
{
"name": "exsolve",
"version": "1.0.7",
"description": "Module resolution utilities based on Node.js upstream implementation.",
"repository": "unjs/exsolve",
"license": "MIT",
"sideEffects": false,
"type": "module",
"exports": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"types": "./dist/index.d.mts",
"files": [
"dist"
],
"scripts": {
"build": "unbuild",
"dev": "vitest dev",
"lint": "eslint . && prettier -c .",
"node-ts": "node --disable-warning=ExperimentalWarning --experimental-strip-types",
"lint:fix": "automd && eslint . --fix && prettier -w .",
"prepack": "pnpm build",
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
"test": "pnpm lint && pnpm test:types && vitest run --coverage",
"test:types": "tsc --noEmit --skipLibCheck"
},
"devDependencies": {
"@types/node": "^24.0.3",
"@vitest/coverage-v8": "^3.2.4",
"automd": "^0.4.0",
"changelogen": "^0.6.1",
"eslint": "^9.29.0",
"eslint-config-unjs": "^0.4.2",
"happy-dom": "^18.0.1",
"jiti": "^2.4.2",
"prettier": "^3.5.3",
"typescript": "^5.8.3",
"unbuild": "^3.5.0",
"vitest": "^3.2.4"
},
"packageManager": "pnpm@10.12.1"
}