*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:
parent
1bfb29658d
commit
4f83c8a526
|
@ -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:
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
nodeLinker: node-modules
|
|
@ -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,
|
||||
}),
|
||||
};
|
||||
},
|
||||
};
|
18
package.json
18
package.json
|
@ -1,18 +1,28 @@
|
|||
{
|
||||
"name": "@lumeweb/relay-plugin-handshake",
|
||||
"name": "relay-plugin-handshake",
|
||||
"type": "module",
|
||||
"version": "0.1.0",
|
||||
"packageManager": "yarn@3.3.0",
|
||||
"scripts": {
|
||||
"build": "bash build.sh"
|
||||
"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"
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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],
|
||||
})
|
||||
);
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2020",
|
||||
"module": "commonjs",
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"rootDir": "src",
|
||||
"outDir": "dist",
|
||||
|
|
Loading…
Reference in New Issue