Skip to content

Commit

Permalink
updates for deno v2: add task and script for distributable; testing f…
Browse files Browse the repository at this point in the history
…or distributable; use jsr with comments for possible other environments aiming to use current versions in deno 2, with testing working; though it's unclear why prior attempts were reverted;
  • Loading branch information
jimmont committed Nov 18, 2024
1 parent 9b1bf0d commit ee2d8f7
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 15 deletions.
4 changes: 3 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"tasks": {
"test": "deno test --check --unstable --allow-all"
"test": "deno test --check --unstable --allow-all ./tests/test.ts",
"dist": "deno run -A ./dist.js",
"testdist": "deno test --no-check ./dist/test.js"
},
"compilerOptions": {
"verbatimModuleSyntax": true,
Expand Down
3 changes: 2 additions & 1 deletion deps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export {
decodeBase64Url,
encodeBase64Url,
} from "https://deno.land/[email protected]/encoding/base64url.ts";
} from "jsr:@std/[email protected]";
//} from "https://jsr.io/@std/encoding/1.0.5/mod.ts";
21 changes: 21 additions & 0 deletions dist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as esbuild from "npm:esbuild";
import { denoPlugins } from "jsr:@luca/esbuild-deno-loader";

const result = await esbuild.build({
plugins: [...denoPlugins()],
entryPoints: ["./mod.ts"],
outfile: `./dist/mod.js`,
bundle: true,
format: "esm",
});

const testing = await esbuild.build({
plugins: [...denoPlugins()],
entryPoints: ["./tests/test.ts"],
outfile: `./dist/test.js`,
bundle: true,
format: "esm",
});


esbuild.stop();
14 changes: 13 additions & 1 deletion examples/deps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
export {
decodeBase64Url,
encodeBase64Url,
} from "https://deno.land/[email protected]/encoding/base64url.ts";
} from "https://deno.land/[email protected]/encoding/base64url.ts";
/*
browsers:
} from "https://deno.land/[email protected]/encoding/base64url.ts";
middleware, including deno test:
} from "jsr:@std/encoding";
untested:
} from "https://jsr.io/@std/encoding/1.0.5/mod.ts";
*/
18 changes: 9 additions & 9 deletions tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const keyHS512 = await crypto.subtle.importKey(
["sign", "verify"],
);

const keyRS256 = await window.crypto.subtle.generateKey(
const keyRS256 = await globalThis.crypto.subtle.generateKey(
{
name: "RSASSA-PKCS1-v1_5",
modulusLength: 4096,
Expand All @@ -56,7 +56,7 @@ const keyRS256 = await window.crypto.subtle.generateKey(
true,
["verify", "sign"],
);
const keyRS384 = await window.crypto.subtle.generateKey(
const keyRS384 = await globalThis.crypto.subtle.generateKey(
{
name: "RSASSA-PKCS1-v1_5",
modulusLength: 4096,
Expand All @@ -66,7 +66,7 @@ const keyRS384 = await window.crypto.subtle.generateKey(
true,
["verify", "sign"],
);
const keyRS512 = await window.crypto.subtle.generateKey(
const keyRS512 = await globalThis.crypto.subtle.generateKey(
{
name: "RSASSA-PKCS1-v1_5",
modulusLength: 4096,
Expand All @@ -77,7 +77,7 @@ const keyRS512 = await window.crypto.subtle.generateKey(
["verify", "sign"],
);

const keyPS256 = await window.crypto.subtle.generateKey(
const keyPS256 = await globalThis.crypto.subtle.generateKey(
{
name: "RSA-PSS",
// Consider using a 4096-bit key for systems that require long-term security
Expand All @@ -89,7 +89,7 @@ const keyPS256 = await window.crypto.subtle.generateKey(
["sign", "verify"],
);

const keyPS384 = await window.crypto.subtle.generateKey(
const keyPS384 = await globalThis.crypto.subtle.generateKey(
{
name: "RSA-PSS",
// Consider using a 4096-bit key for systems that require long-term security
Expand All @@ -101,7 +101,7 @@ const keyPS384 = await window.crypto.subtle.generateKey(
["sign", "verify"],
);

const keyPS512 = await window.crypto.subtle.generateKey(
const keyPS512 = await globalThis.crypto.subtle.generateKey(
{
name: "RSA-PSS",
// Consider using a 4096-bit key for systems that require long-term security
Expand All @@ -113,7 +113,7 @@ const keyPS512 = await window.crypto.subtle.generateKey(
["sign", "verify"],
);

const keyES256 = await window.crypto.subtle.generateKey(
const keyES256 = await globalThis.crypto.subtle.generateKey(
{
name: "ECDSA",
namedCurve: "P-256",
Expand All @@ -122,7 +122,7 @@ const keyES256 = await window.crypto.subtle.generateKey(
["sign", "verify"],
);

const keyES384 = await window.crypto.subtle.generateKey(
const keyES384 = await globalThis.crypto.subtle.generateKey(
{
name: "ECDSA",
namedCurve: "P-384",
Expand All @@ -132,7 +132,7 @@ const keyES384 = await window.crypto.subtle.generateKey(
);

// P-521 is not yet supported.
// const keyES512 = await window.crypto.subtle.generateKey(
// const keyES512 = await globalThis.crypto.subtle.generateKey(
// {
// name: "ECDSA",
// namedCurve: "P-521",
Expand Down
8 changes: 5 additions & 3 deletions tests/test_deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export {
assertEquals,
assertRejects,
assertThrows,
} from "https://deno.land/[email protected]/testing/asserts.ts";

export { decodeHex } from "https://deno.land/[email protected]/encoding/hex.ts";
} from "jsr:@std/assert";
// see ../examples/depts.ts
// with v2 of deno test seems jsr preferred
export { decodeHex } from "jsr:@std/[email protected]";
//export { decodeHex } from "https://deno.land/[email protected]/encoding/hex.ts";

0 comments on commit ee2d8f7

Please sign in to comment.