Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSR changes #38

Merged
merged 12 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/jwtjs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
test:
strategy:
matrix:
deno-version: [1.37.2]
deno-version: [1.44.0]
environment: CI
runs-on: ubuntu-latest
steps:
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
node-version: [20.x]
deno-version: [1.37.2]
deno-version: [1.44.0]

runs-on: ubuntu-latest
permissions:
Expand All @@ -18,7 +18,7 @@ jobs:

steps:
- name: Checkout nkeys.js
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -41,5 +41,6 @@ jobs:
- run: npm publish --provenance --access public --tag=next
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: npx jsr publish


81 changes: 6 additions & 75 deletions bin/cjs-fix-imports.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
/*
* Copyright 2020-2022 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { parse } from "https://deno.land/std@0.136.0/flags/mod.ts";
import { parseArgs } from "jsr:@std/cli@0.224.3/parse-args";
import {
basename,
extname,
join,
resolve,
} from "https://deno.land/std@0.136.0/path/mod.ts";

const argv = parse(
const argv = parseArgs(
Deno.args,
{
alias: {
Expand All @@ -34,17 +20,6 @@ const argv = parse(
},
);

const requires = new Map<string, { lib: string; arg: string }>();

requires.set(
"https://raw.githubusercontent.com/nats-io/nkeys.js",
{ lib: "nkeys.js", arg: "nkeys" },
);
requires.set(
"https://deno.land/x/nkeys.js",
{ lib: "nkeys.js", arg: "nkeys" },
);

// resolve the specified directories to fq
const dirs = (argv._ as string[]).map((n) => {
return resolve(n);
Expand Down Expand Up @@ -74,7 +49,7 @@ if (argv.debug) {

if (!dirs.length || argv.h || argv.help) {
console.log(
`deno run --allow-all cjs-fix-imports [--debug] [--out lib/] dir/ dir2/`,
`deno run --allow-all cjs-fix-imports [--debug] [--out build/] dir/ dir2/`,
);
Deno.exit(1);
}
Expand All @@ -90,54 +65,10 @@ for (const fn of files) {
const data = await Deno.readFile(fn);
const txt = new TextDecoder().decode(data);

let mod = txt.replace(/from\s+"(\S+).[t|j]s"/gim, 'from "$1"');
mod = mod.replace(/require\("(\S+).[j|t]s"\)/gim, 'require("$1")');

// some of the imports are references to external projects
// that in node we resolve with requires - if we encounter one that
// the script is not configured for, the build fails
while (true) {
// if we have an url import
const m = mod.match(/(export [\s\S]+ from\s+"(https:\/\/\S+)")/);
if (m) {
for (const k of requires.keys()) {
// and starts with one of our expected matches
if (m[2].indexOf(k) === 0) {
const entry = requires.get(k);
// replace it with the require
mod = mod.replace(
m[0],
`export const ${entry!.arg} = require("${entry!.lib}")`,
);
break;
}
}
} else {
break;
}
let mod = txt.replace(/jsr:@nats-io\/nkeys/gim, "nkeys.js");
if (!fn.endsWith("nkeys.ts") && !fn.endsWith("nuid.ts")) {
mod = mod.replace(/from\s+"(\S+).[t|j]s"/gim, 'from "$1"');
}

while (true) {
// if we have an url import
const m = mod.match(/(import [\s\S]+ from\s+"(https:\/\/\S+)")/);
if (m) {
for (const k of requires.keys()) {
// and starts with one of our expected matches
if (m[2].indexOf(k) === 0) {
const entry = requires.get(k);
// replace it with the require
mod = mod.replace(
m[0],
`const ${entry!.arg} = require("${entry!.lib}")`,
);
break;
}
}
} else {
break;
}
}

const target = join(out, basename(fn));
await Deno.writeFile(target, new TextEncoder().encode(mod));
if (txt.length !== mod.length) {
Expand Down
18 changes: 18 additions & 0 deletions bin/generate_version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import npmConfig from "../package.json" with { type: "json" };
import jsrConfig from "../deno.json" with { type: "json" };

if (npmConfig.version !== jsrConfig.version) {
throw new Error(
`unmatched versions - npm: ${npmConfig.version} jsr: ${jsrConfig.version}`,
);
}

const v = npmConfig.version;

Deno.writeTextFileSync(
"./src/version.ts",
`
// this file is autogenerated - do not edit
export const Version = "${v}";`,
{ create: true },
);
20 changes: 19 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
{
"name": "@nats-io/jwt",
"version": "0.0.10-3",
"exports": {
".": "./src/mod.ts"
},
"publish": {
"include": [
"LICENSE",
"CODE-OF-CONDUCT.md",
"MANTAINERS.md",
"README.md",
"src/**/*",
"deno.json"
]
},
"imports": {
"std/": "https://deno.land/std@0.206.0/"
"@std/assert": "jsr:@std/assert@0.225.1",
"@std/fs": "jsr:@std/fs@0.224.0",
"@std/path": "jsr:@std/path@0.224.0",
"@nats-io/nkeys": "jsr:@nats-io/nkeys@^1.2.0-4"
},
"lint": {
"exclude": ["docs/", "lib/", "esm/jwt.js", "debug/", "cjs/", "cjs_src/"]
Expand Down
Loading
Loading