Skip to content

Commit

Permalink
fix: publish via JSR (#136)
Browse files Browse the repository at this point in the history
* First pass

* chore: fixes to imports etc

* chore: format

* readme

---------

Co-authored-by: ascorbic <[email protected]>
  • Loading branch information
ascorbic and ascorbic authored Oct 26, 2024
1 parent 61a8520 commit 6674473
Show file tree
Hide file tree
Showing 35 changed files with 273 additions and 83 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@ jobs:
run: deno run -A ./scripts/build_npm.ts ${{steps.get_tag_version.outputs.TAG_VERSION}}
- uses: actions/setup-node@v3
with:
node-version: "18.x"
node-version: "22.x"
registry-url: "https://registry.npmjs.org"
- name: npm publish
if: startsWith(github.ref, 'refs/tags/')
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: cd npm && npm publish --provenance --access public
- name: Update version in deno.json
run: |
VERSION=$(cat version.txt) && jq --arg v "$VERSION" '.version = $v' deno.json > deno.json.tmp
mv deno.json.tmp deno.json
deno fmt deno.json
- name: Publish to JSR
run: npx jsr publish --allow-dirty
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"./scripts",
"./mod.ts",
"./deps.ts",
"./e2e.test.ts",
"*/*.json",
"./example"
],
Expand Down
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ transform the image on the fly.

## Usage

This library is available via URL imports for Deno and via npm for Node. To use
it in Deno, import the module from deno.land:

```ts
import { transformUrl } from "https://deno.land/x/unpic/mod.ts";
```
This library is available via NPM as `unpic` and JSR as
[`@unpic/lib`](https://jsr.io/@unpic/lib).

To use it in Node, install it from npm:

Expand All @@ -41,6 +37,15 @@ Then import it in your code:
import { transformUrl } from "unpic";
```

To use it in Deno, import [the module from JSR](https://jsr.io/@unpic/lib):

```ts
import { transformUrl } from "jsr:@unpic/lib";
```

If you previously installed the library from deno.land/x, you should update to
use JSR instead as the deno.land/x version is no longer updated.

You can then use the `transformUrl` function to transform a URL:

```ts
Expand Down
33 changes: 33 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@unpic/lib",
"version": "3.18.0",
"exports": "./mod.ts",
"tasks": {
"build:npm": "deno run --allow-all scripts/build_npm.ts"
},
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "https://esm.sh/[email protected]"
},
"fmt": {
"useTabs": true
},
"imports": {
"@deno/dnt": "jsr:@deno/[email protected]",
"@std/path": "jsr:@std/[email protected]",
"@std/fs": "jsr:@std/[email protected]",
"@std/testing": "jsr:@std/[email protected]"
},
"publish": {
"include": [
"src",
"mod.ts",
"README.md",
"data"
],
"exclude": [
"**/*.test.ts"
]
},
"license": "MIT"
}
12 changes: 0 additions & 12 deletions deno.jsonc

This file was deleted.

156 changes: 156 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 5 additions & 9 deletions src/e2e.test.ts → e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import {
assertAlmostEquals,
assertEquals,
assertExists,
} from "jsr:@std/assert";
import examples from "../demo/src/examples.json" with { type: "json" };
import { getPixels } from "https://deno.land/x/[email protected]/mod.ts";
import { transformUrl } from "./transform.ts";
import type { ImageCdn } from "./types.ts";
import { assertAlmostEquals, assertExists } from "jsr:@std/assert";
import examples from "./demo/src/examples.json" with { type: "json" };
import { getPixels } from "jsr:@unpic/pixels";
import { transformUrl } from "./src/transform.ts";
import type { ImageCdn } from "./src/types.ts";

Deno.test("E2E tests", async (t) => {
for (const [cdn, example] of Object.entries(examples)) {
Expand Down
17 changes: 7 additions & 10 deletions scripts/build_npm.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { build, emptyDir } from "https://deno.land/x/dnt@0.37.0/mod.ts";
import { basename } from "https://deno.land/[email protected]/path/mod.ts";
import { walk } from "https://deno.land/[email protected]/fs/mod.ts";
import { build, emptyDir } from "jsr:@deno/dnt";
import { basename } from "jsr:@std/path";
import { walk } from "jsr:@std/fs";

await emptyDir("./npm");

const trans = await Array.fromAsync(walk("./src/transformers", {
const transformers = await Array.fromAsync(walk("./src/transformers", {
match: [/^(?!.*test\.ts$).*\.ts$/],
}));

const entry = trans.map((t) => ({
path: t.path,
name: `./transformers/${basename(t.path, ".ts")}`,
const entry = transformers.map((entry) => ({
path: entry.path,
name: `./transformers/${basename(entry.path, ".ts")}`,
}));

await build({
Expand Down Expand Up @@ -51,9 +51,6 @@ await build({
"@unpic/pixels": "latest",
},
},
mappings: {
"https://deno.land/x/[email protected]/mod.ts": "@unpic/pixels",
},
});

// post build steps
Expand Down
11 changes: 5 additions & 6 deletions src/canonical.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
assertEquals,
assertExists,
} from "https://deno.land/[email protected]/testing/asserts.ts";
import { assertEquals, assertExists } from "jsr:@std/assert";
import { getCanonicalCdnForUrl } from "./canonical.ts";

const nextImgLocal =
Expand Down Expand Up @@ -43,8 +40,10 @@ Deno.test("Canonical", async (t) => {
await t.step(
"should fall back to the default CDN for unrecognized image domains - vercel",
() => {
const result =
getCanonicalCdnForUrl("https://placekitten.com/100", "vercel") ||
const result = getCanonicalCdnForUrl(
"https://placekitten.com/100",
"vercel",
) ||
undefined;
assertExists(result);
assertEquals(
Expand Down
6 changes: 4 additions & 2 deletions src/transform.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { assertEquals } from "jsr:@std/assert";
import { getImageCdnForUrl } from "./detect.ts";
import { transformUrl } from "./transform.ts";

Expand Down Expand Up @@ -142,7 +142,9 @@ Deno.test("delegation", async (t) => {

Deno.test("detection", async (t) => {
await t.step("should detect by path with a relative URL", () => {
const cdn = getImageCdnForUrl("/_next/image?url=%2Fprofile.png&w=200&q=75");
const cdn = getImageCdnForUrl(
"/_next/image?url=%2Fprofile.png&w=200&q=75",
);
assertEquals(cdn, "nextjs");
});
});
2 changes: 1 addition & 1 deletion src/transformers/astro.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { assertEquals } from "jsr:@std/assert";

import { ParsedUrl } from "../types.ts";
import { AstroParams, parse, transform } from "./astro.ts";
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/builder.io.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { assertEquals } from "jsr:@std/assert";

import { transform } from "./builder.io.ts";

Expand Down
2 changes: 1 addition & 1 deletion src/transformers/cloudflare.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { assertEquals } from "jsr:@std/assert";
import { ParsedUrl } from "../types.ts";
import { CloudflareParams, parse, transform } from "./cloudflare.ts";

Expand Down
2 changes: 1 addition & 1 deletion src/transformers/cloudflare_images.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { assertEquals } from "jsr:@std/assert";
import { ParsedUrl } from "../types.ts";
import {
CloudflareImagesParams,
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/cloudimage.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { assertEquals } from "jsr:@std/assert";
import { ParsedUrl } from "../types.ts";
import { CloudimageParams, parse, transform } from "./cloudimage.ts";

Expand Down
2 changes: 1 addition & 1 deletion src/transformers/cloudinary.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { assertEquals } from "jsr:@std/assert";
import { ParsedUrl } from "../types.ts";
import { CloudinaryParams, parse, transform } from "./cloudinary.ts";

Expand Down
Loading

0 comments on commit 6674473

Please sign in to comment.