replugged-org / replugged

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

Allow webpack module to search by props in functions #440

Closed colin273 closed 1 year ago

colin273 commented 1 year ago

Describe the bug

Currently, the webpack searcher only looks for props in objects, ignoring functions. This makes it needlessly verbose to search for modules such as moment.js (see #439), where useful props are on the top-level moment() function (the only export of its module) rather than an object.

Reproduction steps

  1. Try to search for moment.js using replugged.webpack.getByProps("isMoment")
  2. Fail
  3. Use replugged.webpack.getModule(m => typeof m.exports === "function" && m.exports.isMoment) to get moment.js
  4. Grumble about how relatively tedious that is

Expected behavior

getByProps should find moment.js

Actual behavior

getByProps returns undefined

Additional information

Should be fixed soon-ish in the webpack-sanity branch, whenever that makes it to the PR stage

Please confirm the following

yofukashino commented 1 year ago

try webpack.getBySource("parseTwoDigitYear")

colin273 commented 1 year ago

Searching by source is a last resort (and I mean LAST) for when the props or more reliable criteria aren't available, and in the case of moment.js they are very much available.

yofukashino commented 1 year ago

Will this be adding support for prototype of the function too?

colin273 commented 1 year ago

Searching by prototype is out of scope for #450, since that PR is aimed at cleaning up and upgrading existing APIs rather than adding new ones. New webpack filters will need to be added in a separate PR.