*Major refactor to use yarn v2 and switch to rollup

*Use relay-plugin-rollup-preset which uses a custom native module packer
*Create a custom packer plugin to store hsd names.db inline
This commit is contained in:
Derrick Hammer 2022-12-14 13:27:48 -05:00
parent 1bfb29658d
commit 4f83c8a526
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
8 changed files with 2318 additions and 17 deletions

View File

@ -3,6 +3,8 @@ pipeline:
image: git.lumeweb.com/lumeweb/ci-node
commands:
- apt-get update && apt-get install libunbound-dev
- corepack enable
- corepack prepare yarn@stable --activate
- yarn
- yarn build
package:

2
.yarnrc.yml Normal file
View File

@ -0,0 +1,2 @@
nodeLinker: node-modules

1
README.md Normal file
View File

@ -0,0 +1 @@
# relay-plugin-handshake

48
hsdBundlePlugin.js Normal file
View File

@ -0,0 +1,48 @@
import MagicString from "magic-string";
import astMatcher from "ast-matcher";
import path from "path";
import fs from "fs";
export default {
name: "bundle-hsd-names-db",
transform(src, id, ast) {
if (!id.includes("reserved.js")) {
return false;
}
const magicString = new MagicString(src);
astMatcher.setParser(this.parse);
if (!ast) {
try {
ast = this.parse(src);
} catch (e) {
throw e;
}
}
const findNamesDb = astMatcher("const DATA = fs.readFileSync(FILE)");
const findNamesDbMatches = findNamesDb(ast);
if (!findNamesDbMatches?.length) {
return false;
}
const dbPath = path.join(path.dirname(id), "names.db");
const dbData = fs.readFileSync(dbPath);
magicString.overwrite(
findNamesDbMatches[0].node.start,
findNamesDbMatches[0].node.end,
`const DATA = Buffer.from("${dbData.toString("base64")}","base64")`
);
return {
code: magicString.toString(),
map: magicString.generateMap({
source: src,
includeContent: true,
hires: true,
}),
};
},
};

View File

@ -1,18 +1,28 @@
{
"name": "@lumeweb/relay-plugin-handshake",
"type": "module",
"version": "0.1.0",
"scripts": {
"build": "bash build.sh"
},
"devDependencies": {
"@types/node": "^18.11.10",
"esbuild": "^0.15.5"
},
"dependencies": {
"@lumeweb/relay-types": "https://git.lumeweb.com/LumeWeb/relay-types.git",
"hs-client": "^0.0.11",
"hsd": "https://github.com/LumeWeb/hsd.git#spv-namestate",
"random-key": "^0.3.2"
}
"name": "relay-plugin-handshake",
"type": "module",
"packageManager": "yarn@3.3.0",
"scripts": {
"build": "rollup -c rollup.config.js"
},
"devDependencies": {
"@lumeweb/relay-plugin-rollup-preset": "https://git.lumeweb.com/LumeWeb/relay-plugin-rollup-preset.git",
"@rollup/plugin-commonjs": "^23.0.4",
"@rollup/plugin-json": "^5.0.2",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-typescript": "^10.0.1",
"@types/node": "^18.11.10",
"esbuild": "^0.15.5",
"prettier": "^2.8.1",
"tslib": "^2.4.1",
"typescript": "^4.9.4",
"vite": "^4.0.1"
},
"dependencies": {
"@lumeweb/relay-types": "https://git.lumeweb.com/LumeWeb/relay-types.git",
"hs-client": "^0.0.11",
"hsd": "https://github.com/LumeWeb/hsd.git#spv-namestate",
"object-merger": "^1.0.3",
"random-key": "^0.3.2"
}
}

15
rollup.config.js Normal file
View File

@ -0,0 +1,15 @@
import { defineConfig } from "rollup";
import preset from "@lumeweb/relay-plugin-rollup-preset";
import merger from "object-merger";
import hsdBundlePlugin from "./hsdBundlePlugin.js";
export default defineConfig(
merger(preset(), {
input: "src/index.ts",
output: {
file: "dist/handshake.js",
format: "cjs",
},
plugins: [hsdBundlePlugin],
})
);

View File

@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"module": "esnext",
"moduleResolution": "node",
"rootDir": "src",
"outDir": "dist",

2223
yarn.lock Normal file

File diff suppressed because it is too large Load Diff