Skip to content

Commit

Permalink
feat: more JSR exports
Browse files Browse the repository at this point in the history
  • Loading branch information
eliassjogreen committed Mar 3, 2024
1 parent 3bbeef3 commit bca8336
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 90 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -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
40 changes: 0 additions & 40 deletions .github/workflows/deno.yml

This file was deleted.

21 changes: 0 additions & 21 deletions .github/workflows/depsbot.yml

This file was deleted.

17 changes: 17 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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.
12 changes: 8 additions & 4 deletions deno.json
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 4 additions & 4 deletions deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
5 changes: 0 additions & 5 deletions import_map.json

This file was deleted.

10 changes: 5 additions & 5 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -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
Expand Down Expand Up @@ -122,7 +122,7 @@ type Const<T> = 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
Expand Down
4 changes: 2 additions & 2 deletions test_deps.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "https://deno.land/[email protected].0/assert/mod.ts";
export * from "https://deno.land/[email protected].0/path/mod.ts";
export * from "jsr:@std/assert@0.214";
export * from "jsr:@std/path@0.214";
9 changes: 9 additions & 0 deletions test_import_map.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
5 changes: 2 additions & 3 deletions util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit bca8336

Please sign in to comment.