diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5a35944..e235e00 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -71,8 +71,6 @@ jobs: run: ${{ matrix.install-cmd }} - name: Install Dependencies run: pnpm install - - name: Download Playwright binaries - run: pnpm exec playwright install chromium - name: Build run: pnpm build - name: Test diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 808d51e..fa49b81 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -25,8 +25,6 @@ jobs: run: pnpm build - name: Lint run: pnpm lint - - name: Download Playwright binaries - run: pnpm exec playwright install chromium - name: Test run: xvfb-run -a pnpm test diff --git a/README.md b/README.md index 6a9f12b..7aee25a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ # tinyclip 📋 -A tiny cross-platform clipboard library. Uses native OS clipboard functionality on Node.js, and the [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API) in browsers. +A tiny cross-platform clipboard library. Uses native OS clipboard functionality on Node.js. + +> [!NOTE] +> In the browser, you can use the native [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API) instead of a dependency. ## Install diff --git a/package.json b/package.json index 56fc86d..b05fe01 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,6 @@ "main": "./dist/index.js", "exports": { ".": { - "browser": "./dist/browser.js", "default": "./dist/index.js" } }, @@ -39,9 +38,7 @@ "devDependencies": { "@types/node": "^25.3.3", "@typescript/native-preview": "^7.0.0-dev.20260228.1", - "@vitest/browser-playwright": "^4.0.18", "@vitest/coverage-v8": "^4.0.18", - "playwright": "^1.58.2", "prettier": "^3.7.4", "vitest": "^4.0.18" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f5a512a..cdd33fb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,15 +14,9 @@ importers: '@typescript/native-preview': specifier: ^7.0.0-dev.20260228.1 version: 7.0.0-dev.20260228.1 - '@vitest/browser-playwright': - specifier: ^4.0.18 - version: 4.0.18(playwright@1.58.2)(vite@7.3.1(@types/node@25.3.3))(vitest@4.0.18) '@vitest/coverage-v8': specifier: ^4.0.18 version: 4.0.18(@vitest/browser@4.0.18(vite@7.3.1(@types/node@25.3.3))(vitest@4.0.18))(vitest@4.0.18) - playwright: - specifier: ^1.58.2 - version: 1.58.2 prettier: specifier: ^3.7.4 version: 3.8.1 @@ -837,7 +831,8 @@ snapshots: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.5.5 - '@polka/url@1.0.0-next.29': {} + '@polka/url@1.0.0-next.29': + optional: true '@rollup/rollup-android-arm-eabi@4.59.0': optional: true @@ -972,6 +967,7 @@ snapshots: - msw - utf-8-validate - vite + optional: true '@vitest/browser@4.0.18(vite@7.3.1(@types/node@25.3.3))(vitest@4.0.18)': dependencies: @@ -989,6 +985,7 @@ snapshots: - msw - utf-8-validate - vite + optional: true '@vitest/coverage-v8@4.0.18(@vitest/browser@4.0.18(vite@7.3.1(@types/node@25.3.3))(vitest@4.0.18))(vitest@4.0.18)': dependencies: @@ -1135,7 +1132,8 @@ snapshots: dependencies: semver: 7.7.4 - mrmime@2.0.1: {} + mrmime@2.0.1: + optional: true nanoid@3.3.11: {} @@ -1150,16 +1148,20 @@ snapshots: pixelmatch@7.1.0: dependencies: pngjs: 7.0.0 + optional: true - playwright-core@1.58.2: {} + playwright-core@1.58.2: + optional: true playwright@1.58.2: dependencies: playwright-core: 1.58.2 optionalDependencies: fsevents: 2.3.2 + optional: true - pngjs@7.0.0: {} + pngjs@7.0.0: + optional: true postcss@8.5.6: dependencies: @@ -1209,6 +1211,7 @@ snapshots: '@polka/url': 1.0.0-next.29 mrmime: 2.0.1 totalist: 3.0.1 + optional: true source-map-js@1.2.1: {} @@ -1231,7 +1234,8 @@ snapshots: tinyrainbow@3.0.3: {} - totalist@3.0.1: {} + totalist@3.0.1: + optional: true undici-types@7.18.2: {} @@ -1290,4 +1294,5 @@ snapshots: siginfo: 2.0.0 stackback: 0.0.2 - ws@8.19.0: {} + ws@8.19.0: + optional: true diff --git a/src/browser.ts b/src/browser.ts deleted file mode 100644 index c4f0d04..0000000 --- a/src/browser.ts +++ /dev/null @@ -1,7 +0,0 @@ -export function readText(): Promise { - return navigator.clipboard.readText(); -} - -export function writeText(text: string): Promise { - return navigator.clipboard.writeText(text); -} diff --git a/tests/browser.test.ts b/tests/browser.test.ts deleted file mode 100644 index 1a212ae..0000000 --- a/tests/browser.test.ts +++ /dev/null @@ -1,21 +0,0 @@ -import {describe, expect, it, beforeEach} from 'vitest'; -import {userEvent} from 'vitest/browser'; -import * as clipboard from '../src/browser.js'; - -describe('clipboard', () => { - beforeEach(async () => { - // Simulate user interaction to satisfy clipboard API security requirements - await userEvent.click(document.body); - }); - - it('should export correct API', () => { - expect(clipboard).toHaveProperty('readText'); - expect(clipboard).toHaveProperty('writeText'); - }); - - it('should copy then read successfully', async () => { - const text = Math.random().toString(); - await clipboard.writeText(text); - expect(await clipboard.readText()).toEqual(text); - }); -}); diff --git a/vitest.config.ts b/vitest.config.ts index e250652..a836dd9 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,38 +1,10 @@ import {defineConfig} from 'vitest/config'; -import {playwright} from '@vitest/browser-playwright'; export default defineConfig({ test: { + include: ['tests/*.test.ts'], coverage: { provider: 'v8' - }, - projects: [ - { - extends: './vitest.config.ts', - test: { - include: ['tests/index.test.ts'], - environment: 'node', - name: 'node' - } - }, - { - extends: './vitest.config.ts', - test: { - include: ['tests/browser.test.ts'], - name: 'browser', - browser: { - enabled: true, - provider: playwright({ - contextOptions: { - permissions: ['clipboard-read', 'clipboard-write'] - } - }), - headless: true, - instances: [{browser: 'chromium'}], - screenshotFailures: false - } - } - } - ] + } } });