replugged-org / replugged

A lightweight Discord client mod focused on simplicity and performance.
https://replugged.dev/
MIT License
650 stars 64 forks source link

error in plugging discord #385

Closed NotPhantomX closed 1 year ago

NotPhantomX commented 1 year ago

Describe the bug

In src/util.ts configPathFn returns /root/.config/replugged instead of /home/{username}/.config/replugged causing an error since the .config folder in /root/ does not exist. The cause seems to be process.env.XDG_CONFIG_HOME being set to /root at some point. Using bash instead of zsh or fish sets process.env.HOME to /root as well.

Reproduction steps

  1. sudo pnpm run plug --production canary

Expected behavior

expected replugged to succeed in plugging discord

Actual behavior

tries to create /root/.config/replugged and fails to create the path since /root/.config also does not exist.

Additional information

sudo pnpm plug --production canary                         

> replugged@4.0.0-beta0.27 plug /home/phantomx/.replugged
> tsx scripts/inject/index.ts inject --no-exit-codes "--production" "canary"

node:fs:1394
  handleErrorFromBinding(ctx);
  ^

Error: ENOENT: no such file or directory, mkdir '/root/.config/replugged'
    at mkdirSync (node:fs:1394:3)
    at Object.<anonymous> (/home/phantomx/.replugged/src/util.ts:22:3)
    at Module._compile (node:internal/modules/cjs/loader:1120:14)
    at Object.v (/home/phantomx/.replugged/node_modules/.pnpm/@esbuild-kit+cjs-loader@2.3.3/node_modules/@esbuild-kit/cjs-loader/dist/index.js:1:933)
    at Module.load (node:internal/modules/cjs/loader:998:32)
    at Module._load (node:internal/modules/cjs/loader:839:12)
    at Module.require (node:internal/modules/cjs/loader:1022:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/home/phantomx/.replugged/scripts/inject/injector.ts:7:30)
    at Module._compile (node:internal/modules/cjs/loader:1120:14) {
  errno: -2,
  syscall: 'mkdir',
  code: 'ENOENT',
  path: '/root/.config/replugged'
}

Node.js v18.7.0
 ELIFECYCLE  Command failed with exit code 1.

Operating System: Fedora 37 Discord Version: Canary 173897 (8aa1dde)

Please confirm the following

bop34 commented 1 year ago

Cannot reproduce on Arch

LizAinslie commented 1 year ago

Just reproduced on arch, I cannot plug due to this issue.

Repro

Here is my neofetch: neofetch

LizAinslie commented 1 year ago

bumping because i still cannot plug my client.

I'd love to see this fixed, haven't been able to use my plugins or theme in 3 days.

lexisother commented 1 year ago

Instead of waiting for three days, just make the folder yourself until we fix it...?

LizAinslie commented 1 year ago

uh, you seem to be missing the bigger issue here. when i build & install my plugins & themes they go in MY ${USER}/.config and I presume when I run Discord as my user, it's not going to read out of the /root/.config. Or, if it does, it's going to run into permission problems when it tries to load plugins. Or maybe it'd work if I ran Discord as root but to hell with that.

LizAinslie commented 1 year ago

Oh, an update on this: I got a chance to properly test your "fix" yesterday on my day off. I ended up in a perpetual loading state for hours. I let it sit and chug.

NotPhantomX commented 1 year ago

A temporary fix is to add the absolute path to src/util.ts this function is at the top of the file just replace it with the below and modify the string to be the absolute path to your .config folder

export const configPathFn = (): string => {
  switch (process.platform) {
    case "win32":
      return join(process.env.APPDATA || "", REPLUGGED_FOLDER_NAME);
    case "darwin":
      return join(process.env.HOME || "", "Library", "Application Support", REPLUGGED_FOLDER_NAME);
    default:
      return join("/home/your user directory/.config/", REPLUGGED_FOLDER_NAME);
    // if (process.env.XDG_CONFIG_HOME) {
    //   return join(process.env.XDG_CONFIG_HOME!, REPLUGGED_FOLDER_NAME);
    // }
    // return join(process.env.HOME || "", ".config", REPLUGGED_FOLDER_NAME);
  }
};
LizAinslie commented 1 year ago

Thanks, I'll give it a shot when I get home.

asportnoy commented 1 year ago

@NotPhantomX I linked #408 which should fix this issue. Feel free to try on that branch to see if it works for you. If not, let me know.

NotPhantomX commented 1 year ago

@NotPhantomX I linked #408 which should fix this issue. Feel free to try on that branch to see if it works for you. If not, let me know.

I have confirmed that that branch successfully finds the right .config directory and successfully injects.

asportnoy commented 1 year ago

Great! Will merge it now.

LizAinslie commented 1 year ago

Pog, thanks y'all :)