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

node-zigbee2mqtt: NODE_PATH explicitly set & Reduced size #1093

Merged
merged 3 commits into from
Dec 6, 2021
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
113 changes: 113 additions & 0 deletions node-modclean/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NPM_NAME:=modclean
PKG_NAME:=node-$(PKG_NPM_NAME)
PKG_VERSION:=3.0.0-beta.1
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NPM_NAME)-$(PKG_VERSION).tgz
PKG_SOURCE_URL:=https://registry.npmjs.org/$(PKG_NPM_NAME)/-/
PKG_HASH:=88532b71a73c214f6d4841b13cf83f6cc03de81c181c37316b29e4e57701970d

PKG_MAINTAINER:=Hirokazu MORIKAWA <[email protected]>
PKG_LICENSE:=MIT
PKG_LICENSE_FILES:=LICENSE

HOST_BUILD_DEPENDS:=node/host
HOST_BUILD_PARALLEL:=1

PKG_BUILD_DEPENDS:=node/host
PKG_BUILD_PARALLEL:=1
PKG_USE_MIPS16:=0

include $(INCLUDE_DIR)/host-build.mk
include $(INCLUDE_DIR)/package.mk

define Package/node-modclean
SUBMENU:=Node.js
SECTION:=lang
CATEGORY:=Languages
TITLE:=Remove unwanted files and directories from your node_modules folder
URL:=https://www.npmjs.org/package/modclean
DEPENDS:=+node
endef

define Package/node-modclean/description
Remove unwanted files and directories from your node_modules folder
endef

TAR_OPTIONS+= --strip-components 1
TAR_CMD=$(HOST_TAR) -C $(1) $(TAR_OPTIONS)

NODEJS_CPU:=$(subst powerpc,ppc,$(subst aarch64,arm64,$(subst x86_64,x64,$(subst i386,ia32,$(ARCH)))))
TMPNPM:=$(shell mktemp -u XXXXXXXXXX)
HOSTTMPNPM:=$(shell mktemp -u XXXXXXXXXX)

TARGET_CFLAGS+=$(FPIC)
TARGET_CPPFLAGS+=$(FPIC)

define Build/Compile
cd $(PKG_BUILD_DIR); \
$(MAKE_VARS) \
$(MAKE_FLAGS) \
npm_config_nodedir=$(STAGING_DIR)/usr/ \
npm_config_cache=$(TMP_DIR)/npm-cache-$(TMPNPM) \
npm_config_tmp=$(TMP_DIR)/npm-tmp-$(TMPNPM) \
npm install --production --global-style --no-save --omit=dev --no-package-lock
rm -rf $(TMP_DIR)/npm-tmp-$(TMPNPM)
rm -rf $(TMP_DIR)/npm-cache-$(TMPNPM)
rm -f $(PKG_BUILD_DIR)/node_modules/.package-lock.json
find $(PKG_BUILD_DIR)/node_modules -type d -empty -print0 | xargs -0 rmdir || true
endef

define Package/node-modclean/install
$(INSTALL_DIR) $(1)/usr/lib/node/$(PKG_NPM_NAME)
$(CP) $(PKG_BUILD_DIR)/{package.json,LICENSE} \
$(1)/usr/lib/node/$(PKG_NPM_NAME)/
$(CP) $(PKG_BUILD_DIR)/{*.md,*.js} \
$(1)/usr/lib/node/$(PKG_NPM_NAME)/
$(CP) $(PKG_BUILD_DIR)/{node_modules,bin,lib} \
$(1)/usr/lib/node/$(PKG_NPM_NAME)/
$(INSTALL_DIR) $(1)/usr/bin
$(LN) ../lib/node/$(PKG_NPM_NAME)/bin/modclean.js $(1)/usr/bin/modclean
$(INSTALL_DIR) $(1)/usr/lib/node_modules
$(LN) ../node/$(PKG_NPM_NAME) $(1)/usr/lib/node_modules/$(PKG_NPM_NAME)
endef

define Package/node-modclean/postrm
#!/bin/sh
rm /usr/lib/node_modules/modclean || true
rm -rf /usr/lib/node/modclean || true
endef

define Host/Compile
cd $(HOST_BUILD_DIR); \
$(HOST_MAKE_VARS) \
npm_config_nodedir=$(STAGING_DIR)/usr/ \
npm_config_cache=$(TMP_DIR)/npm-cache-$(HOSTTMPNPM) \
npm_config_tmp=$(TMP_DIR)/npm-tmp-$(HOSTTMPNPM) \
npm install --production --global-style --no-save --omit=dev --no-package-lock
rm -rf $(TMP_DIR)/npm-tmp-$(HOSTTMPNPM)
rm -rf $(TMP_DIR)/npm-cache-$(HOSTTMPNPM)
rm -f $(HOST_BUILD_DIR)/node_modules/.package-lock.json
find $(HOST_BUILD_DIR)/node_modules -type d -empty -print0 | xargs -0 rmdir || true
endef

define Host/Install
$(INSTALL_DIR) $(1)/lib/node_modules/$(PKG_NPM_NAME)
$(CP) $(HOST_BUILD_DIR)/{package.json,LICENSE} \
$(1)/lib/node_modules/$(PKG_NPM_NAME)/
$(CP) $(HOST_BUILD_DIR)/{*.md,*.js} \
$(1)/lib/node_modules/$(PKG_NPM_NAME)/
$(CP) $(HOST_BUILD_DIR)/{node_modules,bin,lib} \
$(1)/lib/node_modules/$(PKG_NPM_NAME)/
$(INSTALL_DIR) $(1)/bin
$(LN) ../lib/node_modules/$(PKG_NPM_NAME)/bin/modclean.js $(1)/bin/modclean
endef

$(eval $(call HostBuild))
$(eval $(call BuildPackage,node-modclean))
7 changes: 5 additions & 2 deletions node-zigbee2mqtt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk
PKG_NPM_NAME:=zigbee2mqtt
PKG_NAME:=node-$(PKG_NPM_NAME)
PKG_VERSION:=1.22.1
PKG_RELEASE:=1
PKG_RELEASE:=2

PKG_SOURCE:=$(PKG_NPM_NAME)-$(PKG_VERSION).tgz
PKG_SOURCE_URL:=https://registry.npmjs.org/$(PKG_NPM_NAME)/-/
Expand All @@ -17,7 +17,7 @@ PKG_MAINTAINER:=Hirokazu MORIKAWA <[email protected]>
PKG_LICENSE:=GPL-3.0
PKG_LICENSE_FILES:=LICENSE

PKG_BUILD_DEPENDS:=node/host
PKG_BUILD_DEPENDS:=node/host node-modclean/host
PKG_BUILD_PARALLEL:=1
PKG_USE_MIPS16:=0

Expand Down Expand Up @@ -58,9 +58,12 @@ define Build/Compile
rm -f $(PKG_BUILD_DIR)/node_modules/zigbee2mqtt-frontend/dist/report.html
rm -f $(PKG_BUILD_DIR)/node_modules/zigbee2mqtt-frontend/dist/*.map
rm -f $(PKG_BUILD_DIR)/node_modules/zigbee2mqtt-frontend/dist/*/*.map
#rm -rf $(PKG_BUILD_DIR)/node_modules/zigbee-herdsman-converters/node_modules/zigbee-herdsman
rm -rf $(PKG_BUILD_DIR)/node_modules/moment/min
rm -rf $(PKG_BUILD_DIR)/node_modules/moment/src
rm -rf $(PKG_BUILD_DIR)/node_modules/moment/locale
modclean --no-progress -r --patterns="default:safe" --additional-patterns="*.d.ts" \
--path $(PKG_BUILD_DIR) --ignore="examples,example*"
rm -rf $(TMP_DIR)/npm-tmp-$(TMPNPM)
rm -rf $(TMP_DIR)/npm-cache-$(TMPNPM)
rm -f $(PKG_BUILD_DIR)/node_modules/.package-lock.json
Expand Down
1 change: 1 addition & 0 deletions node-zigbee2mqtt/files/zigbee2mqtt.init
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ USE_PROCD=1
start_service()
{
procd_open_instance
procd_set_param env NODE_PATH=/opt/zigbee2mqtt/node_modules/winston/node_modules
procd_set_param command /usr/bin/npm start --prefix /opt/zigbee2mqtt
procd_set_param stdout 1
procd_set_param stderr 1
Expand Down