Skip to content

Commit

Permalink
Fix compilation for esm and cjs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dolu89 committed May 20, 2022
1 parent 60e9991 commit 345c3ac
Show file tree
Hide file tree
Showing 6 changed files with 549 additions and 31 deletions.
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@zerologin/lnurl",
"version": "0.0.4",
"version": "0.0.5",
"description": "LNURL library written in TS",
"private": false,
"type": "module",
"scripts": {
"dev": "ts-node ./src/index.ts",
"clean": "rimraf dist",
"prepublishOnly": "npm run build",
"build": "npm run clean && tsc -d",
"build": "npm run clean && tsup src/index.ts --format esm,cjs",
"test": "node --loader=ts-node/esm bin/test.ts"
},
"author": "zerologin",
Expand All @@ -20,18 +20,19 @@
"@japa/runner": "^2.0.8",
"@japa/spec-reporter": "^1.1.12",
"@types/node": "^17.0.35",
"rimraf": "^3.0.2",
"ts-node": "^10.7.0",
"typescript": "^4.6.4",
"rimraf": "^3.0.2"
"tsup": "^5.12.8",
"typescript": "^4.6.4"
},
"repository": {
"url": "http://github.com/zerologin/lnurl",
"type": "git"
},
"main": "dist/index.js",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist/index.js",
"dist/index.d.ts"
"dist/"
]
}
}
10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { bech32 } from "bech32";
const limit = 1023;
const prefix = "lnurl";

export const decode = (lnurl: string): string => {
const decode = (lnurl: string): string => {
const decoded = bech32.decode(lnurl, limit);
return Buffer.from(bech32.fromWords(decoded.words)).toString("utf8");
}
};

export const encode = (unencoded: string): string => {
const encode = (unencoded: string): string => {
let words = bech32.toWords(Buffer.from(unencoded, "utf8"));
return bech32.encode(prefix, words, limit).toUpperCase();
}
};

export default { decode, encode };
6 changes: 3 additions & 3 deletions tests/lnurl.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { test } from "@japa/runner";
import { decode, encode } from "../src/index";
import lnurl from "../src/index.js";

test.group("LNURL", () => {
test("can encode", ({ expect }) => {
const unencoded =
"https://service.com/api?q=3fc3645b439ce8e7f2553a69e5267081d96dcd340693afabe04be7b0ccd178df";
const encoded = encode(unencoded);
const encoded = lnurl.encode(unencoded);

const expected =
"LNURL1DP68GURN8GHJ7UM9WFMXJCM99E3K7MF0V9CXJ0M385EKVCENXC6R2C35XVUKXEFCV5MKVV34X5EKZD3EV56NYD3HXQURZEPEXEJXXEPNXSCRVWFNV9NXZCN9XQ6XYEFHVGCXXCMYXYMNSERXFQ5FNS";
Expand All @@ -15,7 +15,7 @@ test.group("LNURL", () => {
test("can decode", ({ expect }) => {
const unencoded =
"LNURL1DP68GURN8GHJ7UM9WFMXJCM99E3K7MF0V9CXJ0M385EKVCENXC6R2C35XVUKXEFCV5MKVV34X5EKZD3EV56NYD3HXQURZEPEXEJXXEPNXSCRVWFNV9NXZCN9XQ6XYEFHVGCXXCMYXYMNSERXFQ5FNS";
const decoded = decode(unencoded);
const decoded = lnurl.decode(unencoded);

const expected =
"https://service.com/api?q=3fc3645b439ce8e7f2553a69e5267081d96dcd340693afabe04be7b0ccd178df";
Expand Down
17 changes: 11 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"outDir": "dist",
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"outDir": "dist",
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true,
"noImplicitAny": true,
"preserveConstEnums": true
"preserveConstEnums": true,
"allowSyntheticDefaultImports": true,
"noEmit": true,
"isolatedModules": false,
"forceConsistentCasingInFileNames": true,
"noUnusedLocals": true,
},
"exclude":[
"exclude": [
"./node_modules",
"./tests",
"./bin"
Expand Down
9 changes: 9 additions & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { Options } from "tsup";

export const tsup: Options = {
splitting: false,
dts: true,
sourcemap: true,
clean: true,
entryPoints: ["src/index.ts"],
};
Loading

0 comments on commit 345c3ac

Please sign in to comment.