replugged-org/replugged

Allow webpack module to search by props in functions

colin273 opened this issue · 4 comments

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

  • I checked if Discord and Replugged are up to date
  • I made sure this is not related to an external plugin or a theme
  • I searched the issues to make sure this bug has not been reported before.

try webpack.getBySource("parseTwoDigitYear")

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.

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

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.