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,21 @@
MIT License
Copyright (c) 2024 Daniel Roe
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,63 @@
# impound
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![Github Actions][github-actions-src]][github-actions-href]
[![Codecov][codecov-src]][codecov-href]
> Build plugin to restrict import patterns in certain parts of your code-base.
This package is an [unplugin](https://unplugin.unjs.io/) which provides support for a wide range of bundlers.
## Usage
Install package:
```sh
# npm
npm install impound
```
```js
// rollup.config.js
import { dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
import { ImpoundPlugin } from 'impound'
export default {
plugins: [
ImpoundPlugin.rollup({
cwd: dirname(fileURLToPath(import.meta.url)),
include: [/src\/*/],
patterns: [
[/^node:.*/], // disallows all node imports
['@nuxt/kit', 'Importing from @nuxt kit is not allowed in your src/ directory'] // custom error message
]
}),
],
}
```
## 💻 Development
- Clone this repository
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
- Install dependencies using `pnpm install`
- Run interactive tests using `pnpm dev`
## License
Made with ❤️
Published under [MIT License](./LICENCE).
<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/impound?style=flat-square
[npm-version-href]: https://npmjs.com/package/impound
[npm-downloads-src]: https://img.shields.io/npm/dm/impound?style=flat-square
[npm-downloads-href]: https://npm.chart.dev/impound
[github-actions-src]: https://img.shields.io/github/actions/workflow/status/unjs/impound/ci.yml?branch=main&style=flat-square
[github-actions-href]: https://github.com/unjs/impound/actions?query=workflow%3Aci
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/impound/main?style=flat-square
[codecov-href]: https://codecov.io/gh/unjs/impound

View File

@@ -0,0 +1,22 @@
import * as unplugin from 'unplugin';
interface ImpoundMatcherOptions {
/** An array of patterns of importers to apply the import protection rules to. */
include?: Array<string | RegExp>;
/** An array of patterns of importers where the import protection rules explicitly do not apply. */
exclude?: Array<string | RegExp>;
/** Whether to throw an error or not. if set to `false`, an error will be logged to console instead. */
error?: boolean;
/** An array of patterns to prevent being imported, along with an optional warning to display. */
patterns: [importPattern: string | RegExp | ((id: string) => boolean | string), warning?: string][];
}
interface ImpoundSharedOptions {
cwd?: string;
}
type ImpoundOptions = (ImpoundSharedOptions & ImpoundMatcherOptions) | (ImpoundSharedOptions & {
matchers: ImpoundMatcherOptions[];
});
declare const ImpoundPlugin: unplugin.UnpluginInstance<ImpoundOptions, boolean>;
export { ImpoundPlugin };
export type { ImpoundMatcherOptions, ImpoundOptions, ImpoundSharedOptions };

View File

@@ -0,0 +1,41 @@
import { resolveModulePath } from 'exsolve';
import { join, isAbsolute, relative } from 'pathe';
import { createUnplugin } from 'unplugin';
import { createFilter } from 'unplugin-utils';
const RELATIVE_IMPORT_RE = /^\.\.?\//;
const ImpoundPlugin = createUnplugin((globalOptions) => {
const matchers = "matchers" in globalOptions ? globalOptions.matchers : [globalOptions];
return matchers.map((options) => {
const filter = createFilter(options.include, options.exclude, { resolve: globalOptions.cwd });
const proxy = resolveModulePath("mocked-exports/proxy", { from: import.meta.url });
return {
name: "impound",
enforce: "pre",
resolveId(id, importer) {
if (!importer || !filter(importer)) {
return;
}
if (RELATIVE_IMPORT_RE.test(id)) {
id = join(importer, "..", id);
}
if (isAbsolute(id) && globalOptions.cwd) {
id = relative(globalOptions.cwd, id);
}
let matched = false;
const logError = options.error === false ? console.error : this.error.bind(this);
for (const [pattern, warning] of options.patterns) {
const usesImport = pattern instanceof RegExp ? pattern.test(id) : typeof pattern === "string" ? pattern === id : pattern(id);
if (usesImport) {
const relativeImporter = isAbsolute(importer) && globalOptions.cwd ? relative(globalOptions.cwd, importer) : importer;
logError(`${typeof usesImport === "string" ? usesImport : warning || "Invalid import"} [importing \`${id}\` from \`${relativeImporter}\`]`);
matched = true;
}
}
return matched ? proxy : null;
}
};
});
});
export { ImpoundPlugin };

View File

@@ -0,0 +1,59 @@
{
"name": "impound",
"type": "module",
"version": "1.0.0",
"description": "Builder-agnostic plugin to allow restricting import patterns in certain parts of your code-base.",
"license": "MIT",
"repository": "unjs/impound",
"sideEffects": false,
"exports": {
".": "./dist/index.js"
},
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"dependencies": {
"exsolve": "^1.0.5",
"mocked-exports": "^0.1.1",
"pathe": "^2.0.3",
"unplugin": "^2.3.2",
"unplugin-utils": "^0.2.4"
},
"devDependencies": {
"@antfu/eslint-config": "4.12.0",
"@types/node": "22.14.1",
"@vitest/coverage-v8": "3.1.2",
"bumpp": "10.1.0",
"eslint": "9.25.0",
"lint-staged": "15.5.1",
"rollup": "4.40.0",
"simple-git-hooks": "2.12.1",
"typescript": "5.8.3",
"unbuild": "3.5.0",
"vite": "6.3.2",
"vitest": "3.1.2"
},
"resolutions": {
"impound": "link:."
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
},
"lint-staged": {
"*.{js,ts,mjs,cjs,json,.*rc}": [
"npx eslint --fix"
]
},
"scripts": {
"build": "unbuild",
"dev": "vitest dev",
"lint": "eslint . --fix",
"release": "bumpp && pnpm publish",
"test": "pnpm test:unit && pnpm test:types",
"test:unit": "vitest",
"test:types": "tsc --noEmit"
}
}