Skip to content

Commit

Permalink
README.md: update urls
Browse files Browse the repository at this point in the history
  • Loading branch information
adryd325 committed Dec 5, 2023
1 parent 9fb57b2 commit c14e1ac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Hi, while this "Works" right now, its not well documented; and a lot is subject to change.

## Installing
The runtime with an example config for twitter can be installed from https://adryd325.github.io/webpackTools/webpackTools.user.js
The runtime with an example config for twitter can be installed from https://moonlight-mod.github.io/webpackTools/webpackTools.user.js

## Updating
To update to the latest webpackTools runtime while maintaining your existing config, edit your userscript and replace the string after `const runtime = ` with https://adryd325.github.io/webpackTools/webpackTools.runtime.json.
To update to the latest webpackTools runtime while maintaining your existing config, edit your userscript and replace the string after `const runtime = ` with https://moonlight-mod.github.io/webpackTools/webpackTools.runtime.json.

## How to determine if something is Webpack 4 or Webpack 5
TODO: actually explain this
Expand All @@ -18,5 +18,9 @@ if the 3rd entry is a function it's webpack 5

rspack seems to compile to webpack 5 runtime

## Caveats

Some sites, namely Discord, will start multiple webpack runtimes running on the same webpackChunk object. Duplicate runtimes can be found in `window.wpTools.runtimes`. Injected modules will run multiple times, one for each runtime.

## Credits
A lot of this is based on research by [Mary](https://github.com/mstrodl) and [Cynthia](https://github.com/cynosphere) (HH3), and [Twilight Sparkle](https://github.com/twilight-sparkle-irl/) (webcrack, crispr)
20 changes: 14 additions & 6 deletions src/wpTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function getWpToolsFunc(chunkObject, logSuccess = false) {
// TODO: recurse in objects
function findModulesByExports(keysArg) {
if (!webpackRequire.c) {
throw new Error("webpack runtime didn't export its moduleCache")
throw new Error("webpack runtime didn't export its moduleCache");
}
const keys = keysArg instanceof Array ? keysArg : [keysArg];
return Object.entries(webpackRequire.c)
Expand All @@ -105,10 +105,18 @@ export function getWpToolsFunc(chunkObject, logSuccess = false) {
return matchModule(funcStr, search);
})
.map(([moduleId, moduleFunc]) => {
return {
id: moduleId,
exports: webpackRequire(moduleId),
};
try {
return {
id: moduleId,
exports: webpackRequire(moduleId),
};
} catch (error) {
console.error("Failed to require module: " + error);
return {
id: moduleId,
exports: {},
};
}
});
}

Expand Down Expand Up @@ -152,7 +160,7 @@ export function getWpToolsFunc(chunkObject, logSuccess = false) {
runtimesRegistry[chunkObject] = exportedRequire;
}
runtimesRegistry[chunkObject] = exportedRequire;
window["wpTools_"+chunkObject] = exportedRequire;
window["wpTools_" + chunkObject] = exportedRequire;
}

// Mark as processed as to not loose scope if somehow passed to Patcher._patchModules()
Expand Down
2 changes: 1 addition & 1 deletion userscriptTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
(() => {
// Example config
const config = {
wpToolsEverywhere: true, // not yet implemented
wpToolsEverywhere: true, // Automatically detect webpack objects and inject them with wpTools (not full patching)
siteConfigs: [
{
name: "twitter", // Required, for documentation and debug logging
Expand Down

0 comments on commit c14e1ac

Please sign in to comment.