From a2f3abaebda027ee6250ed15974060d6b4e4666d Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Tue, 28 Jun 2022 15:47:41 +0100 Subject: [PATCH] Remove unpacked dependencies from app --- package.json | 8 ++++++-- src/cli/nso/notify.ts | 14 +++++++++----- src/cli/nso/presence.ts | 3 ++- src/discord/rpc.ts | 17 ++++++++++++++--- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 0351bf4..01d0283 100644 --- a/package.json +++ b/package.json @@ -84,12 +84,16 @@ "files": [ "dist/app/bundle", "dist/bundle", - "!dist/app/package" + "!dist/app/package", + "!**/node_modules/**/*" ], "asar": false, "extraMetadata": { "name": "nxapi-app", - "main": "dist/bundle/app-main-bundle.cjs" + "main": "dist/bundle/app-main-bundle.cjs", + "dependencies": {}, + "optionalDependencies": {}, + "devDependencies": {} }, "directories": { "output": "dist/app/package" diff --git a/src/cli/nso/notify.ts b/src/cli/nso/notify.ts index fa004b5..2e9552a 100644 --- a/src/cli/nso/notify.ts +++ b/src/cli/nso/notify.ts @@ -1,7 +1,6 @@ import * as path from 'node:path'; import createDebug from 'debug'; import persist from 'node-persist'; -import notifier from 'node-notifier'; import type { Arguments as ParentArguments } from '../nso.js'; import { ArgumentsCamelCase, Argv, YargsArguments } from '../../util/yargs.js'; import { initStorage } from '../../util/storage.js'; @@ -105,6 +104,7 @@ export async function handler(argv: ArgumentsCamelCase) { const i = new ZncNotifications(storage, token, nso, data); + i.notifications = new TerminalNotificationManager(await import('node-notifier')); i.user_notifications = argv.userNotifications; i.friend_notifications = argv.friendNotifications; i.update_interval = argv.updateInterval; @@ -127,10 +127,14 @@ export async function handler(argv: ArgumentsCamelCase) { } export class TerminalNotificationManager extends NotificationManager { + constructor(private readonly notifier: typeof import('node-notifier')) { + super(); + } + onFriendOnline(friend: CurrentUser | Friend, prev?: CurrentUser | Friend, naid?: string, ir?: boolean) { const currenttitle = friend.presence.game as Game; - notifier.notify({ + this.notifier.notify({ title: friend.name, message: 'Playing ' + currenttitle.name + (currenttitle.sysDescription ? '\n' + currenttitle.sysDescription : ''), @@ -140,7 +144,7 @@ export class TerminalNotificationManager extends NotificationManager { } onFriendOffline(friend: CurrentUser | Friend, prev?: CurrentUser | Friend, naid?: string, ir?: boolean) { - notifier.notify({ + this.notifier.notify({ title: friend.name, message: 'Offline', icon: friend.imageUri, @@ -150,7 +154,7 @@ export class TerminalNotificationManager extends NotificationManager { onFriendPlayingChangeTitle(friend: CurrentUser | Friend, prev?: CurrentUser | Friend, naid?: string, ir?: boolean) { const currenttitle = friend.presence.game as Game; - notifier.notify({ + this.notifier.notify({ title: friend.name, message: 'Playing ' + currenttitle.name + (currenttitle.sysDescription ? '\n' + currenttitle.sysDescription : ''), @@ -162,7 +166,7 @@ export class TerminalNotificationManager extends NotificationManager { onFriendTitleStateChange(friend: CurrentUser | Friend, prev?: CurrentUser | Friend, naid?: string, ir?: boolean) { const currenttitle = friend.presence.game as Game; - notifier.notify({ + this.notifier.notify({ title: friend.name, message: 'Playing ' + currenttitle.name + (currenttitle.sysDescription ? '\n' + currenttitle.sysDescription : ''), diff --git a/src/cli/nso/presence.ts b/src/cli/nso/presence.ts index 17eb61a..e43f314 100644 --- a/src/cli/nso/presence.ts +++ b/src/cli/nso/presence.ts @@ -4,7 +4,7 @@ import { ArgumentsCamelCase, Argv, YargsArguments } from '../../util/yargs.js'; import { initStorage } from '../../util/storage.js'; import { getToken } from '../../common/auth/nso.js'; import { DiscordPresencePlayTime } from '../../discord/util.js'; -import { handleEnableSplatNet2Monitoring } from './notify.js'; +import { handleEnableSplatNet2Monitoring, TerminalNotificationManager } from './notify.js'; import { ZncDiscordPresence, ZncProxyDiscordPresence } from '../../common/presence.js'; const debug = createDebug('cli:nso:presence'); @@ -191,6 +191,7 @@ export async function handler(argv: ArgumentsCamelCase) { const i = new ZncDiscordPresence(storage, token, nso, data); + i.notifications = new TerminalNotificationManager(await import('node-notifier')); i.user_notifications = argv.userNotifications; i.friend_notifications = argv.friendNotifications; i.update_interval = argv.updateInterval; diff --git a/src/discord/rpc.ts b/src/discord/rpc.ts index 1c60909..dff2e83 100644 --- a/src/discord/rpc.ts +++ b/src/discord/rpc.ts @@ -1,15 +1,26 @@ import process from 'node:process'; import * as net from 'node:net'; -import { createRequire } from 'node:module'; +import { EventEmitter } from 'node:events'; import createDebug from 'debug'; import fetch from 'node-fetch'; import DiscordRPC from 'discord-rpc'; +// @ts-expect-error +import __BaseIpcTransport from 'discord-rpc/src/transports/ipc.js'; const debug = createDebug('nxapi:discord:rpc'); -const require = createRequire(import.meta.url); +declare class _BaseIpcTransport extends EventEmitter { + constructor(client: DiscordRPC.Client); + connect(): Promise; + onClose(e: boolean): void; + send(data: unknown, op?: OPCode): void; + close(): Promise; + ping(): void; + static encode(op: OPCode, data: unknown): Buffer; + static decode(socket: net.Socket, callback: (op: OPCode, data: unknown) => void): void; +} -const BaseIpcTransport = require('discord-rpc/src/transports/ipc.js'); +const BaseIpcTransport = __BaseIpcTransport as typeof _BaseIpcTransport; export async function getDiscordRpcClients() { const sockets = await getAllIpcSockets();