From bca8336c6a4f9bbbdb38920a10fced45d74988ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Sj=C3=B6green?= Date: Sun, 3 Mar 2024 14:28:35 +0100 Subject: [PATCH] feat: more JSR exports --- .github/workflows/checks.yml | 24 +++++++++++++++++++++ .github/workflows/deno.yml | 40 ----------------------------------- .github/workflows/depsbot.yml | 21 ------------------ .github/workflows/publish.yml | 17 +++++++++++++++ LICENSE | 2 +- README.md | 37 +++++++++++++++++++++++++++----- deno.json | 12 +++++++---- deps.ts | 8 +++---- import_map.json | 5 ----- mod.ts | 10 ++++----- test_deps.ts | 4 ++-- test_import_map.json | 9 ++++++++ util.ts | 5 ++--- 13 files changed, 104 insertions(+), 90 deletions(-) create mode 100644 .github/workflows/checks.yml delete mode 100644 .github/workflows/deno.yml delete mode 100644 .github/workflows/depsbot.yml create mode 100644 .github/workflows/publish.yml delete mode 100644 import_map.json create mode 100644 test_import_map.json diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 0000000..db9f3a4 --- /dev/null +++ b/.github/workflows/checks.yml @@ -0,0 +1,24 @@ +name: Checks + +on: [push, pull_request] + +jobs: + style: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: denoland/setup-deno@v1 + - run: deno fmt --check + - run: deno lint + + tests: + name: ${{ matrix.kind }} ${{ matrix.os }} + runs-on: ${{ matrix.os }} + timeout-minutes: 5 + strategy: + matrix: + os: [macOS-latest, windows-latest, ubuntu-latest] + steps: + - uses: actions/checkout@v4 + - uses: denoland/setup-deno@v1 + - run: deno test --import-map test_import_map.json -A --doc diff --git a/.github/workflows/deno.yml b/.github/workflows/deno.yml deleted file mode 100644 index 6c6d5ba..0000000 --- a/.github/workflows/deno.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: deno - -on: [push, pull_request] - -jobs: - style: - runs-on: ubuntu-latest - steps: - - name: checkout repo - uses: actions/checkout@v2 - - - name: setup latest deno version - uses: denoland/setup-deno@main - with: - deno-version: v1.x - - - name: run deno fmt - run: deno fmt --check - - - name: run deno lint - run: deno lint --unstable - - tests: - name: ${{ matrix.kind }} ${{ matrix.os }} - runs-on: ${{ matrix.os }} - timeout-minutes: 5 - strategy: - matrix: - os: [macOS-latest, windows-latest, ubuntu-latest] - steps: - - name: Checkout sources - uses: actions/checkout@v2 - - - name: Setup latest deno version - uses: denoland/setup-deno@main - with: - deno-version: v1.x - - - name: run deno test - run: deno test -A --unstable diff --git a/.github/workflows/depsbot.yml b/.github/workflows/depsbot.yml deleted file mode 100644 index 705242d..0000000 --- a/.github/workflows/depsbot.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: depsbot - -on: - push: - branches: [main] - pull_request: - branches: [main] - schedule: - - cron: "0 0 */2 * *" - -jobs: - run: - runs-on: ubuntu-latest - steps: - - name: Checkout Repository - uses: actions/checkout@v2 - - - name: Run depsbot - uses: denosaurs/depsbot@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..ebf40ee --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,17 @@ +name: Publish + +on: + push: + branches: + - main + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v4 + - uses: denoland/setup-deno@v1 + - run: deno publish diff --git a/LICENSE b/LICENSE index 41e1668..3e5e81a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020-2023 the denosaurs team +Copyright (c) 2020-2024 the denosaurs team Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 0627200..6c64c94 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,26 @@ automatically create the URL for your cross-operating-system, cross-architecture libraries if you so wish using a simple configuration which deviates from the standard URL/string path input. +## Installation + +Plug is published to [jsr.io](https://jsr.io/@denosaurs/plug) and +[deno.land](https://deno.land/x/plug). The recommended way to use it is to use +JSR: + +```bash +deno add @denosaurs/plug +``` + +or without the CLI: + +```typescript +import * as plug from "jsr:@denosaurs/plug"; +``` + ## Example using plug as an almost drop in replacement for `Deno.dlopen` ```ts -import { dlopen } from "https://deno.land/x/plug/mod.ts"; +import { dlopen } from "@denosaurs/plug"; // Drop-in replacement for `Deno.dlopen` which fetches the following depending // on operating system: @@ -31,7 +47,7 @@ library.symbols.noop(); ## Example using automatic binary name guessing ```ts -import { dlopen, FetchOptions } from "https://deno.land/x/plug/mod.ts"; +import { dlopen, FetchOptions } from "@denosaurs/plug"; // If you want plug to guess your binary names const options: FetchOptions = { @@ -53,7 +69,7 @@ library.symbols.noop(); ## Example using nested cross-platform options ```ts -import { dlopen, FetchOptions } from "https://deno.land/x/plug/mod.ts"; +import { dlopen, FetchOptions } from "@denosaurs/plug"; // Also you can specify the path for certain architecture const options: FetchOptions = { @@ -79,7 +95,7 @@ await dlopen(options, {}); ## Example using nested cross-platform options and automatic binary name guessing ```ts -import { dlopen, FetchOptions } from "https://deno.land/x/plug/mod.ts"; +import { dlopen, FetchOptions } from "@denosaurs/plug"; // Or even configure plug to automatically guess the binary names for you, // even when there are special rules for naming on specific architectures @@ -100,6 +116,17 @@ const options: FetchOptions = { await dlopen(options, {}); ``` +## Testing + +To run the plug tests, you can use the following command: + +```bash +deno test --import-map test_import_map.json -A --doc +``` + +The `test_import_map.json` file is used to map the `@denosaurs/plug` import to +the local `mod.ts` file instead of the remote one for the documentation tests. + ## Other ### Related @@ -115,4 +142,4 @@ Pull request, issues and feedback are very welcome. Code style is formatted with ### Licence -Copyright 2020-2023, the denosaurs team. All rights reserved. MIT license. +Copyright 2020-2024, the denosaurs team. All rights reserved. MIT license. diff --git a/deno.json b/deno.json index 77ee439..64e6b64 100644 --- a/deno.json +++ b/deno.json @@ -1,7 +1,11 @@ { "name": "@denosaurs/plug", - "version": "1.0.3", - "exports": "./mod.ts", - "lock": false, - "importMap": "./import_map.json" + "version": "1.0.4", + "exports": { + ".": "./mod.ts", + "./types": "./types.ts", + "./download": "./download.ts", + "./util": "./util.ts" + }, + "lock": false } diff --git a/deps.ts b/deps.ts index 9b8064c..322521d 100644 --- a/deps.ts +++ b/deps.ts @@ -7,7 +7,7 @@ export { normalize, resolve, toFileUrl, -} from "jsr:@std/path@0.213.1"; -export { ensureDir } from "jsr:@std/fs@0.213.1"; -export { encodeHex as hex } from "jsr:@std/encoding@0.213.1/hex"; -export { green } from "jsr:@std/fmt@0.213.1/colors"; +} from "jsr:@std/path@0.214"; +export { ensureDir } from "jsr:@std/fs@0.214"; +export { encodeHex as hex } from "jsr:@std/encoding@0.214/hex"; +export { green } from "jsr:@std/fmt@0.214/colors"; diff --git a/import_map.json b/import_map.json deleted file mode 100644 index a9feaa5..0000000 --- a/import_map.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "imports": { - "https://deno.land/x/plug/": "./" - } -} diff --git a/mod.ts b/mod.ts index 7df16c0..2a5219a 100644 --- a/mod.ts +++ b/mod.ts @@ -7,7 +7,7 @@ * * @example * ```ts - * import { dlopen } from "https://deno.land/x/plug/mod.ts"; + * import { dlopen } from "@denosaurs/plug"; * * // Drop-in replacement for `Deno.dlopen` which fetches the following depending * // on operating system: @@ -23,7 +23,7 @@ * * @example * ```ts - * import { dlopen, FetchOptions } from "https://deno.land/x/plug/mod.ts"; + * import { dlopen, FetchOptions } from "@denosaurs/plug"; * * // If you want plug to guess your binary names * const options: FetchOptions = { @@ -44,7 +44,7 @@ * * @example * ```ts - * import { dlopen, FetchOptions } from "https://deno.land/x/plug/mod.ts"; + * import { dlopen, FetchOptions } from "@denosaurs/plug"; * * // Also you can specify the path for certain architecture * const options: FetchOptions = { @@ -64,7 +64,7 @@ * * @example * ```ts - * import { dlopen, FetchOptions } from "https://deno.land/x/plug/mod.ts"; + * import { dlopen, FetchOptions } from "@denosaurs/plug"; * * // Or even configure plug to automatically guess the binary names for you, * // even when there are special rules for naming on specific architectures @@ -122,7 +122,7 @@ type Const = Cast< * * @example * ```ts - * import { dlopen, FetchOptions } from "https://deno.land/x/plug/mod.ts"; + * import { dlopen, FetchOptions } from "@denosaurs/plug"; * * // Configure plug to automatically guess the binary names for you, even when * // there for example are special rules for naming on specific architectures diff --git a/test_deps.ts b/test_deps.ts index 2fa4a31..5064119 100644 --- a/test_deps.ts +++ b/test_deps.ts @@ -1,2 +1,2 @@ -export * from "https://deno.land/std@0.214.0/assert/mod.ts"; -export * from "https://deno.land/std@0.214.0/path/mod.ts"; +export * from "jsr:@std/assert@0.214"; +export * from "jsr:@std/path@0.214"; diff --git a/test_import_map.json b/test_import_map.json new file mode 100644 index 0000000..94c20d3 --- /dev/null +++ b/test_import_map.json @@ -0,0 +1,9 @@ +{ + "imports": { + "https://deno.land/x/plug/": "./", + "@denosaurs/plug": "./mod.ts", + "@denosaurs/plug/types": "./types.ts", + "@denosaurs/plug/download": "./download.ts", + "@denosaurs/plug/util": "./util.ts" + } +} diff --git a/util.ts b/util.ts index 43a4ce5..32b5e58 100644 --- a/util.ts +++ b/util.ts @@ -7,8 +7,7 @@ import { toFileUrl, } from "./deps.ts"; -export const encoder = new TextEncoder(); -export const decoder = new TextDecoder(); +const encoder = new TextEncoder(); function baseUrlToFilename(url: URL): string { const out = []; @@ -112,7 +111,7 @@ export function cacheDir(): string | undefined { } } -export function denoCacheDir() { +export function denoCacheDir(): string | undefined { const dd = Deno.env.get("DENO_DIR"); let root; if (dd) {