git: 7ba7ca77add0 - main - textproc/logseq: Repackage native better-sqlite module.

From: Gleb Popov <arrowd_at_FreeBSD.org>
Date: Tue, 14 Nov 2023 18:37:28 UTC
The branch main has been updated by arrowd:

URL: https://cgit.FreeBSD.org/ports/commit/?id=7ba7ca77add02ed6d344c1bf131f3d714a3b125b

commit 7ba7ca77add02ed6d344c1bf131f3d714a3b125b
Author:     Gleb Popov <arrowd@FreeBSD.org>
AuthorDate: 2023-11-14 18:36:23 +0000
Commit:     Gleb Popov <arrowd@FreeBSD.org>
CommitDate: 2023-11-14 18:37:23 +0000

    textproc/logseq: Repackage native better-sqlite module.
    
    Sponsored by:   Serenity Cybersecurity, LLC
---
 textproc/logseq/Makefile  | 50 +++++++++++++++++++++++++++++++++++++++++++++--
 textproc/logseq/distinfo  |  8 +++++---
 textproc/logseq/pkg-plist | 28 +-------------------------
 3 files changed, 54 insertions(+), 32 deletions(-)

diff --git a/textproc/logseq/Makefile b/textproc/logseq/Makefile
index 2ee927c03186..d38a7445adeb 100644
--- a/textproc/logseq/Makefile
+++ b/textproc/logseq/Makefile
@@ -1,10 +1,12 @@
 PORTNAME=	logseq
 PORTVERSION=	0.9.20
+PORTREVISION=	1
 CATEGORIES=	textproc
 MASTER_SITES=	https://github.com/logseq/logseq/releases/download/${PORTVERSION}/ \
-		LOCAL/arrowd/:rsapi
+		LOCAL/arrowd/:node_modules
 DISTFILES=	Logseq-linux-x64-${PORTVERSION}${EXTRACT_SUFX} \
-		logseq/rsapi.freebsd-x64.node${EXTRACT_SUFX}:rsapi
+		logseq/rsapi-${RSAPI_HASH}.freebsd-x64.node${EXTRACT_SUFX}:node_modules \
+		logseq/better-sqlite-${BETTER_SQLITE_VERSION}.node${EXTRACT_SUFX}:node_modules
 
 MAINTAINER=	arrowd@FreeBSD.org
 COMMENT=	Open-source platform for knowledge management and collaboration
@@ -20,6 +22,9 @@ SUB_FILES=	Logseq
 NO_BUILD=	yes
 WRKSRC=		${WRKDIR}/Logseq-linux-x64
 
+RSAPI_HASH=	18bd98cfc4d084182b534c1c72a6e473a7174b45
+BETTER_SQLITE_VERSION=	9.1.1
+
 post-patch:
 	${RM} ${WRKSRC}/resources/app/node_modules/@logseq/rsapi-linux-x64-gnu/package.json.orig
 
@@ -31,6 +36,47 @@ do-install:
 	${FIND} ${STAGEDIR}${DATADIR} -type d -empty -delete
 	${MV} ${STAGEDIR}${DATADIR}/resources/app/node_modules/@logseq/rsapi-linux-x64-gnu \
 		${STAGEDIR}${DATADIR}/resources/app/node_modules/@logseq/rsapi-freebsd-x64
+	${RM} ${STAGEDIR}${DATADIR}/resources/app/node_modules/@logseq/rsapi-freebsd-x64/rsapi.linux-x64-gnu.node
 	${INSTALL_PROGRAM} ${WRKDIR}/rsapi.freebsd-x64.node ${STAGEDIR}${DATADIR}/resources/app/node_modules/@logseq/rsapi-freebsd-x64
+	${RM} -r ${STAGEDIR}${DATADIR}/resources/app/node_modules/better-sqlite3/bin
+	${RM} -r ${STAGEDIR}${DATADIR}/resources/app/node_modules/better-sqlite3/build/Release
+	${INSTALL_PROGRAM} ${WRKDIR}/better_sqlite3.node ${STAGEDIR}${DATADIR}/resources/app/node_modules/better-sqlite3/build
+
+repackage-node-modules:
+	pkg info curl git yarn npm zip > /dev/null
+	${MKDIR} /tmp/logseq/
+	curl https://sh.rustup.rs -sSf --output ${WRKDIR}/rustup.sh
+	${SETENV} HOME=${WRKDIR}/home \
+		sh ${WRKDIR}/rustup.sh -y --profile minimal --default-toolchain stable
+
+	git clone https://github.com/logseq/rsapi.git ${WRKDIR}/rsapi-git
+	cd ${WRKDIR}/rsapi-git && git checkout ${RSAPI_HASH}
+	cd ${WRKDIR}/rsapi-git && ${SETENV} HOME=${WRKDIR}/home PATH=${PATH}:${WRKDIR}/home/.cargo/bin \
+		yarn install --immutable --mode=skip-build
+	cd ${WRKDIR}/rsapi-git && ${SETENV} HOME=${WRKDIR}/home PATH=${PATH}:${WRKDIR}/home/.cargo/bin \
+		yarn build
+	${STRIP_CMD} ${WRKDIR}/rsapi-git/packages/rsapi/rsapi.freebsd-x64.node
+	cd ${WRKDIR}/rsapi-git/packages/rsapi && zip /tmp/logseq/rsapi-${RSAPI_HASH}.freebsd-x64.node.zip rsapi.freebsd-x64.node
+
+	git clone https://github.com/WiseLibs/better-sqlite3.git ${WRKDIR}/better-sqlite
+	cd ${WRKDIR}/better-sqlite && git checkout v${BETTER_SQLITE_VERSION}
+	${SED} -i.bak -e 's|node-gyp rebuild|node-gyp rebuild --arch=x64 --dist-url=https://electronjs.org/headers --target=${ELECTRON_VER}|g' \
+		${WRKDIR}/better-sqlite/package.json
+	cd ${WRKDIR}/better-sqlite && ${SETENV} HOME=${WRKDIR}/home \
+		npm install --ignore-scripts
+	cd ${WRKDIR}/better-sqlite && ${SETENV} HOME=${WRKDIR}/home \
+		npm run build-release
+	${STRIP_CMD} ${WRKDIR}/better-sqlite/build/Release/better_sqlite3.node
+	cd ${WRKDIR}/better-sqlite/build/Release && zip /tmp/logseq/better-sqlite-${BETTER_SQLITE_VERSION}.node.zip better_sqlite3.node
+
+	@cd /tmp \
+		&& sha256 logseq/rsapi-${RSAPI_HASH}.freebsd-x64.node.zip \
+		&& ${ECHO_CMD} -n "SIZE (logseq/rsapi-${RSAPI_HASH}.freebsd-x64.node.zip) = " \
+		&& ${STAT} -f %z /tmp/logseq/rsapi-${RSAPI_HASH}.freebsd-x64.node.zip \
+		&& sha256 logseq/better-sqlite-${BETTER_SQLITE_VERSION}.node.zip \
+		&& ${ECHO_CMD} -n "SIZE (logseq/better-sqlite-${BETTER_SQLITE_VERSION}.node.zip) = " \
+		&& ${STAT} -f %z /tmp/logseq/better-sqlite-${BETTER_SQLITE_VERSION}.node.zip
+	@${ECHO_CMD}
+
 
 .include <bsd.port.mk>
diff --git a/textproc/logseq/distinfo b/textproc/logseq/distinfo
index 59266d922918..d905ebbd5f7a 100644
--- a/textproc/logseq/distinfo
+++ b/textproc/logseq/distinfo
@@ -1,5 +1,7 @@
-TIMESTAMP = 1699189271
+TIMESTAMP = 1699702116
 SHA256 (Logseq-linux-x64-0.9.20.zip) = fb9002a317063fd8473c3d08b8ffd0546bc30fbef257747cfafe2bf17e88c3d4
 SIZE (Logseq-linux-x64-0.9.20.zip) = 191060640
-SHA256 (logseq/rsapi.freebsd-x64.node.zip) = 104ac8d27cbbbbdb0034e08326f043bd12a790b296d09511a37367d9c184d08c
-SIZE (logseq/rsapi.freebsd-x64.node.zip) = 3190039
+SHA256 (logseq/rsapi-18bd98cfc4d084182b534c1c72a6e473a7174b45.freebsd-x64.node.zip) = 08fede53b6b6ff5914c896279844e664b67809c7f5b2b7401493400c1ba8af1f
+SIZE (logseq/rsapi-18bd98cfc4d084182b534c1c72a6e473a7174b45.freebsd-x64.node.zip) = 2361021
+SHA256 (logseq/better-sqlite-9.1.1.node.zip) = 77437d9ac7629ffdc03d47234b0b9b123cf7caf895a63de30273ce90de3fca42
+SIZE (logseq/better-sqlite-9.1.1.node.zip) = 955517
diff --git a/textproc/logseq/pkg-plist b/textproc/logseq/pkg-plist
index 25414d01a860..47914933bd55 100644
--- a/textproc/logseq/pkg-plist
+++ b/textproc/logseq/pkg-plist
@@ -1210,7 +1210,6 @@ share/applications/Logseq.desktop
 %%DATADIR%%/resources/app/node_modules/@logseq/rsapi-freebsd-x64/README.md
 %%DATADIR%%/resources/app/node_modules/@logseq/rsapi-freebsd-x64/package.json
 %%DATADIR%%/resources/app/node_modules/@logseq/rsapi-freebsd-x64/rsapi.freebsd-x64.node
-%%DATADIR%%/resources/app/node_modules/@logseq/rsapi-freebsd-x64/rsapi.linux-x64-gnu.node
 %%DATADIR%%/resources/app/node_modules/@logseq/rsapi/LICENSE
 %%DATADIR%%/resources/app/node_modules/@logseq/rsapi/index.d.ts
 %%DATADIR%%/resources/app/node_modules/@logseq/rsapi/index.js
@@ -2852,34 +2851,9 @@ share/applications/Logseq.desktop
 %%DATADIR%%/resources/app/node_modules/base64-js/package.json
 %%DATADIR%%/resources/app/node_modules/better-sqlite3/LICENSE
 %%DATADIR%%/resources/app/node_modules/better-sqlite3/README.md
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/bin/linux-x64-116/better-sqlite3.node
 %%DATADIR%%/resources/app/node_modules/better-sqlite3/binding.gyp
 %%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Makefile
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/.deps/Release/better_sqlite3.node.d
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/.deps/Release/obj.target/better_sqlite3.node.d
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/.deps/Release/obj.target/better_sqlite3/src/better_sqlite3.o.d
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/.deps/Release/obj.target/deps/locate_sqlite3.stamp.d
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/.deps/Release/obj.target/deps/sqlite3.a.d
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/.deps/Release/obj.target/sqlite3/gen/sqlite3/sqlite3.o.d
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/.deps/Release/obj.target/test_extension.node.d
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/.deps/Release/obj.target/test_extension/deps/test_extension.o.d
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/.deps/Release/sqlite3.a.d
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/.deps/Release/test_extension.node.d
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/.deps/ba23eeee118cd63e16015df367567cb043fed872.intermediate.d
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/.forge-meta
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/better_sqlite3.node
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/obj.target/better_sqlite3.node
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/obj.target/better_sqlite3/src/better_sqlite3.o
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/obj.target/deps/locate_sqlite3.stamp
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/obj.target/deps/sqlite3.a
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/obj.target/sqlite3/gen/sqlite3/sqlite3.o
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/obj.target/test_extension.node
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/obj.target/test_extension/deps/test_extension.o
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/obj/gen/sqlite3/sqlite3.c
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/obj/gen/sqlite3/sqlite3.h
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/obj/gen/sqlite3/sqlite3ext.h
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/sqlite3.a
-%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/Release/test_extension.node
+%%DATADIR%%/resources/app/node_modules/better-sqlite3/build/better_sqlite3.node
 %%DATADIR%%/resources/app/node_modules/better-sqlite3/build/better_sqlite3.target.mk
 %%DATADIR%%/resources/app/node_modules/better-sqlite3/build/binding.Makefile
 %%DATADIR%%/resources/app/node_modules/better-sqlite3/build/config.gypi