Skip to content

Commit f78bd64

Browse files
committed
chore: publish libpkgx to JSR as @pkgx/libpkgx
deno.land/x is read-only; new versions go to JSR. - deno.json: name, version 0.23.0, exports (mod + deep paths) - deps via import map (npm:is-what, npm:outdent, jsr:@std/*) - explicit public API return types for JSR slow-type rules - CI: publish-jsr.yml on release (OIDC, --allow-slow-types) - lint: waive no-slow-types for remaining declare global prototype extensions (follow-up) - README: JSR import example
1 parent bf926ec commit f78bd64

36 files changed

Lines changed: 219 additions & 80 deletions

.github/workflows/publish-jsr.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: publish·jsr
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
concurrency:
9+
group: publish/jsr/${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
permissions:
13+
contents: read
14+
id-token: write # OIDC for tokenless JSR publish
15+
16+
jobs:
17+
publish:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
- uses: denoland/setup-deno@v2
22+
with:
23+
deno-version: v2.x
24+
- name: dry-run
25+
run: deno publish --dry-run --allow-slow-types --no-check --unstable-fs --unstable-ffi
26+
- name: publish
27+
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
28+
run: deno publish --allow-slow-types --no-check --unstable-fs --unstable-ffi

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ $ npm install libpkgx
1616
# ^^ https://npmjs.com/libpkgx
1717
```
1818

19-
Or with [Deno]:
19+
Or with [Deno] via [JSR](https://jsr.io):
2020

2121
```ts
22-
import * as pkgx from "https://deno.land/x/libpkgx/mod.ts"
22+
import * as pkgx from "jsr:@pkgx/libpkgx"
2323
```
2424

25+
> `deno.land/x/libpkgx` is frozen (registry is read-only). Use JSR for new versions.
26+
2527
## Usage
2628

2729
```ts

deno.json

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,69 @@
11
{
2+
"name": "@pkgx/libpkgx",
3+
"version": "0.23.0",
4+
"license": "Apache-2.0",
5+
"exports": {
6+
".": "./mod.ts",
7+
"./hooks/useConfig.ts": "./src/hooks/useConfig.ts",
8+
"./hooks/usePantry.ts": "./src/hooks/usePantry.ts",
9+
"./utils/error.ts": "./src/utils/error.ts",
10+
"./utils/host.ts": "./src/utils/host.ts",
11+
"./utils/read-lines.ts": "./src/utils/read-lines.ts",
12+
"./utils/semver.ts": "./src/utils/semver.ts",
13+
"./plumbing/hydrate.ts": "./src/plumbing/hydrate.ts"
14+
},
15+
"publish": {
16+
"include": [
17+
"LICENSE.txt",
18+
"README.md",
19+
"mod.ts",
20+
"src/**/*.ts",
21+
"vendor/**"
22+
],
23+
"exclude": [
24+
"src/**/*.test.ts",
25+
"src/hooks/useTestConfig.ts",
26+
"fixtures",
27+
"examples",
28+
"scripts",
29+
"dist",
30+
".github"
31+
]
32+
},
233
"compilerOptions": {
3-
"allowJs": false,
434
"strict": true
535
},
636
"pkgx": "deno~2.0",
737
"tasks": {
838
"test": "deno test --parallel --unstable-fs --unstable-ffi --allow-all",
9-
"typecheck": "deno check ./mod.ts"
39+
"typecheck": "deno check ./mod.ts",
40+
"publish:dry": "deno publish --dry-run --allow-slow-types --no-check --allow-dirty --unstable-fs --unstable-ffi"
1041
},
1142
"lint": {
12-
"include": ["src/"],
13-
"exclude": ["**/*.test.ts"]
43+
"include": ["src/", "mod.ts"],
44+
"exclude": ["**/*.test.ts", "vendor/", "src/hooks/useTestConfig.ts"],
45+
"rules": {
46+
// Prototype extensions (Array.compact, Promise.swallow, etc.) use
47+
// `declare global`, which JSR forbids without --allow-slow-types.
48+
// Explicit public return types are fixed; globals are a larger refactor.
49+
"exclude": ["no-slow-types"]
50+
}
1451
},
1552
"test": {
1653
"include": ["src/"],
1754
"exclude": ["dist/"]
1855
},
1956
"imports": {
2057
"@std/assert": "jsr:@std/assert@^1.0.6",
58+
"@std/crypto": "jsr:@std/crypto@^1",
59+
"@std/encoding": "jsr:@std/encoding@^1",
60+
"@std/fs": "jsr:@std/fs@^1",
61+
"@std/io": "jsr:@std/io@^0.225.0",
62+
"@std/io/write-all": "jsr:@std/io@^0.225.0/write-all",
63+
"@std/path": "jsr:@std/path@^1",
2164
"@std/testing": "jsr:@std/testing@^1.0.3",
22-
"is-what": "https://deno.land/x/is_what@v4.1.15/src/index.ts",
23-
"outdent": "https://deno.land/x/outdent@v0.8.0/mod.ts"
65+
"@std/yaml": "jsr:@std/yaml@^1",
66+
"is-what": "npm:is-what@4.1.15",
67+
"outdent": "npm:outdent@0.8.0"
2468
}
2569
}

mod.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import "./src/utils/misc.ts"
22
import { flatmap, validate } from "./src/utils/misc.ts"
33

4-
import host, { SupportedArchitecture, SupportedPlatform } from "./src/utils/host.ts"
4+
import host from "./src/utils/host.ts"
5+
import type { SupportedArchitecture, SupportedPlatform } from "./src/utils/host.ts"
56
import SemVer, * as semver from "./src/utils/semver.ts"
67
import Path from "./src/utils/Path.ts"
78

src/deps.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import * as is_what from "https://deno.land/x/is_what@v4.1.15/src/index.ts"
1+
import * as is_what from "is-what"
22
export { is_what }
33

4-
import { type PlainObject } from "https://deno.land/x/is_what@v4.1.15/src/index.ts"
4+
import type { PlainObject } from "is-what"
55
export type { PlainObject }
66

7-
import * as outdent from "https://deno.land/x/outdent@v0.8.0/mod.ts"
7+
import * as outdent from "outdent"
88
export { outdent }
99

1010
// importing super specifically to reduce final npm bundle size
11-
import * as crypto from "jsr:@std/crypto@1"
12-
import { moveSync } from "jsr:@std/fs@1"
13-
import { writeAll } from "jsr:@std/io@^0.225.0"
14-
import { parse as parseYaml, parseAll as parseYamlALL } from "jsr:@std/yaml@1"
15-
import { SEPARATOR as SEP, fromFileUrl } from "jsr:@std/path@1"
11+
import * as crypto from "@std/crypto"
12+
import { moveSync } from "@std/fs"
13+
import { writeAll } from "@std/io/write-all"
14+
import { parse as parseYaml, parseAll as parseYamlALL } from "@std/yaml"
15+
import { SEPARATOR as SEP, fromFileUrl } from "@std/path"
1616

1717
const streams = { writeAll }
1818
const fs = { moveSync }

src/hooks/useCache.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { Stowage } from "../types.ts"
1+
import type { Stowage } from "../types.ts"
22
import useConfig from "./useConfig.ts"
33
import host from "../utils/host.ts"
4+
import type Path from "../utils/Path.ts"
45

5-
export default function useCache() {
6+
export default function useCache(): { path: (stowage: Stowage) => Path } {
67
return { path }
78
}
89

9-
const path = (stowage: Stowage) => {
10+
const path = (stowage: Stowage): Path => {
1011
const { pkg, type } = stowage
1112
const stem = pkg.project.replaceAll("/", "∕")
1213

src/hooks/useCellar.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Package, PackageRequirement, Installation } from "../types.ts"
1+
import type { Package, PackageRequirement, Installation } from "../types.ts"
22
import { PkgxError } from "../utils/error.ts"
33
import * as pkgutils from "../utils/pkg.ts"
44
import SemVer from "../utils/semver.ts"
@@ -14,7 +14,15 @@ export class InstallationNotFoundError extends PkgxError {
1414
}
1515
}
1616

17-
export default function useCellar() {
17+
export type UseCellar = {
18+
has: (pkg: Package | PackageRequirement | Path) => Promise<Installation | undefined>
19+
ls: (project: string) => Promise<Installation[]>
20+
keg: (pkg: Package) => Path
21+
resolve: (pkg: Package | PackageRequirement | Path | Installation) => Promise<Installation>
22+
shelf: (project: string) => Path
23+
}
24+
25+
export default function useCellar(): UseCellar {
1826
const config = useConfig()
1927

2028
/// eg. ~/.pkgx/deno.land

src/hooks/useConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function platform_data_home_default(home: Path, { LOCALAPPDATA }: { LOCALAPPDATA
4949

5050
const SEP = Deno.build.os == 'windows' ? ';' : ':'
5151

52-
export function ConfigDefault(env = Deno.env.toObject()): Config {
52+
export function ConfigDefault(env: Record<string, string> = Deno.env.toObject()): Config {
5353
const home = flatmap(env['PKGX_HOME'], x => new Path(x)) ?? Path.home()
5454
const prefix = flatmap(env['PKGX_DIR']?.trim(), x => new Path(x)) ??
5555
flatmap(env['XDG_DATA_HOME'], x => new Path(x).join("pkgx")) ??
@@ -115,7 +115,7 @@ function boolize(input: string | undefined): boolean | undefined {
115115
}
116116
}
117117

118-
function initialized() {
118+
function initialized(): boolean {
119119
return gt.sh_pkgx_config !== undefined
120120
}
121121

src/hooks/useDownload.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { deno } from "../deps.ts"
22
const { crypto: crypto_, streams: { writeAll } } = deno
33
const { crypto } = crypto_
4-
import { encodeHex } from "jsr:@std/encoding@1"
4+
import { encodeHex } from "@std/encoding"
55
import { PkgxError, panic } from "../utils/error.ts"
66
import useConfig from "./useConfig.ts"
77
import useFetch from "./useFetch.ts"
@@ -80,7 +80,10 @@ function cache({ for: url }: {for: URL}): Path {
8080
}
8181
}
8282

83-
export default function useDownload() {
83+
export default function useDownload(): {
84+
download: typeof download
85+
cache: typeof cache
86+
} {
8487
return {
8588
download,
8689
cache

src/hooks/useInventory.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Package, PackageRequirement } from "../types.ts"
1+
import type { Package, PackageRequirement } from "../types.ts"
22
import { DownloadError } from "./useDownload.ts"
33
import SemVer from "../utils/semver.ts"
44
import useFetch from "./useFetch.ts"
@@ -14,7 +14,7 @@ export interface Inventory {
1414
}
1515
}
1616

17-
const select = async (rq: PackageRequirement | Package) => {
17+
const select = async (rq: PackageRequirement | Package): Promise<SemVer | undefined> => {
1818
const versions = await _internals.get(rq)
1919

2020
if ("constraint" in rq) {
@@ -24,7 +24,7 @@ const select = async (rq: PackageRequirement | Package) => {
2424
}
2525
}
2626

27-
const get = async (rq: PackageRequirement | Package) => {
27+
const get = async (rq: PackageRequirement | Package): Promise<SemVer[]> => {
2828
const { platform, arch } = host()
2929
const url = new URL(`${useConfig().dist}/${rq.project}/${platform}/${arch}/versions.txt`)
3030
const rsp = await useFetch(url)
@@ -47,7 +47,10 @@ const get = async (rq: PackageRequirement | Package) => {
4747
return versions
4848
}
4949

50-
export default function useInventory() {
50+
export default function useInventory(): {
51+
select: typeof select
52+
get: typeof get
53+
} {
5154
return { select, get }
5255
}
5356

0 commit comments

Comments
 (0)