Code Monkey home page Code Monkey logo

moduleraid's Introduction

moduleRaid

moduleRaid is a utility to get modules and module constructors from webpackJsonp functions (or similar endpoints) embedded on websites by Webpack. It also provides functions to search through returned modules.

Installation

You can get moduleRaid over npm

$ npm install moduleraid

Or if you directly want to use it in the browser

<script src="https://unpkg.com/moduleraid/dist/moduleraid.iife.js"></script>

Or alternatively, just copy the contents from above unpkg link into the devtools console on a website!

Usage

Preparation

Using moduleRaid as a module, simply require and execute it somewhere where it will end up as a public facing script on a page that also includes a Webpack build!

import ModuleRaid from 'moduleRaid'

const mR = new ModuleRaid()

Examples

Now, with the mR instance available and modules being fetched, you can use the two available find*() methods to search for modules!

let results = mR.findModule('coolFeature')
// => Array of fitting modules for the search query

let constRes = mR.findConstructor('_internal')
// => Array of fitting constructor/module tuples for the search query

// after moduleRaid has been set up you can now listen for new chunks being loaded
document.addEventListener('moduleraid:webpack-push', (e) => {
  // e.detail contains the arguments push() was called with

  // your code here...
})

For more in-depth documentation around what you can use of moduleRaid, you can visit the API Documentation!

Special Thanks

License

moduleRaid is licensed under the MIT License

moduleraid's People

Contributors

dependabot[bot] avatar eramdam avatar pedroslopez avatar pixeldesu avatar twilight-sparkle-irl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

moduleraid's Issues

findFunction returns array of undefined

Hello there! Thanks for the great work with this package.

I'm running into an issue using findFunction. To my understanding, when a function is passed as the query parameter, it should execute my function with the current module and if I return true from my function, it should add the module that matches to the resulting array. However, line 137 of moduleraid.js is as follows:

results.push(moduleRaid.mObj[index]);

To me, this doesn't really make sense since you're getting property index of the modules object, which would always be undefined. Instead, shouldn't it push moduleRaid.mObj[mKey] to the array, adding the module itself? In my tests this has worked...

I was going to do a PR with this, but reading the README, it states the following for what findFunction is supposed to do:

findFunction(query): Return functions that include query (query can be either a string or a function)

So is this not supposed to return the module itself? If so, how would one execute a function to custom match modules and get the result, as I suggested above?

Thanks in advance.

Interested in a maintainer / collaborator?

Howdy!

I’ve followed your work for a long time, and have built a few proprietary systems like this project.
I am working on an software architecture which allows for, among many other things, the ability for many builds to act as one.

I’ve worked and collaborated on and co authored some of the largest contrubutions to React architecture, one of my co-authors actually wrote require.resolveWeak for our work on Universal code.

I’d like to propose, could you consider adding me as a collaborator to this project? We both seem to be moving toward the same common goal and rather than waste efforts doing almost the same things, let’s combine forces and help balance up the little time we have to contribute to OSS.

This is a project I am highly interested in, and would be rolling it into my other projects as a dependency. Many of these projects have amassed hundreds of thousands of downloads a week.

We don’t know each other, but I don’t want to write another closed-source solution to a problem that has yet to be solved publicly. I am sure you are proud of your contribution, and should be!

I’d love nothing more than to help you drive this forwards for the greater good. Modularaid automation is the cornerstone of true micro frontend multi build asset loading and orchestration.

I want nothing more than to see this project soar to be used by millions and by some of the biggest companies in the world.

Let me know your thoughts, I understand it is a big ask. I’d like the original of the project to get the recognition than a fork of their hard work. I do hope my GitHub profile will reveal that even though we are strangers, I’m a trustworthy source, asking to work on a project that I believe in.

Great work! On your Webpack 4 update! I wish I could have PRd mine... but I was still in a closed source situation at the time.

With respect,
Zack

Uncaught Error: Unknown Webpack structure

Hi! I've stumbled upon this error, the webpage is https://www.seb.lv/sites/default/files/calc/public/en/kma.html

The command I run

{
    const script = document.createElement('script');
    script.setAttribute('src', 'https://unpkg.com/moduleraid/dist/moduleraid.iife.js');
    script.addEventListener('load', () => window.mR = new ModuleRaid({debug:true}));
    document.head.appendChild(script);
}

The error:

moduleraid.iife.js:1 Uncaught Error: Unknown Webpack structure
at o.fillModules (moduleraid.iife.js:1:1888)
at new e (moduleraid.iife.js:1:1001)
at HTMLScriptElement. (:4:55)

Debug info:

moduleraid.iife.js:1 [moduleRaid] Pushing moduleRaid.arrayArguments[0] into webpackJsonp failed:
TypeError: window[t.entrypoint].push is not a function
TypeError: window[t.entrypoint].push is not a function
at https://unpkg.com/moduleraid/dist/moduleraid.iife.js:1:1662
at Array.forEach ()
at o.fillModules (https://unpkg.com/moduleraid/dist/moduleraid.iife.js:1:1562)
at new e (https://unpkg.com/moduleraid/dist/moduleraid.iife.js:1:1001)
at HTMLScriptElement. (:4:55)

moduleraid.iife.js:1 [moduleRaid] Pushing moduleRaid.arrayArguments[1] into webpackJsonp failed:
TypeError: window[t.entrypoint].push is not a function
TypeError: window[t.entrypoint].push is not a function
at https://unpkg.com/moduleraid/dist/moduleraid.iife.js:1:1662
at Array.forEach ()
at o.fillModules (https://unpkg.com/moduleraid/dist/moduleraid.iife.js:1:1562)
at new e (https://unpkg.com/moduleraid/dist/moduleraid.iife.js:1:1001)
at HTMLScriptElement. (:4:55)

Maybe I'm doing something wrong with the configuration? Any suggestion?

TypeError: Cannot read properties of undefined (reading 'length')

The error occurred on https://ivan-stoychev.com/ and a couple of other sites where entrypoint starts with webpackJsonpreact-*

Debug info:

Entrypoint has been detected at window.webpackJsonpreact-tours and set for injection

[moduleRaid] Pushing moduleRaid.arrayArguments[0] into webpackJsonpreact-tours failed:
TypeError: Cannot read properties of undefined (reading 'length')
TypeError: Cannot read properties of undefined (reading 'length')
at t (https://ivan-stoychev.com/:1:1261)
at Array.r [as push] (https://ivan-stoychev.com/:1:1186)
at https://unpkg.com/moduleraid/dist/moduleraid.iife.js:1:1742
at Array.forEach ()
at n.fillModules (https://unpkg.com/moduleraid/dist/moduleraid.iife.js:1:1642)
at new e (https://unpkg.com/moduleraid/dist/moduleraid.iife.js:1:1075)
at HTMLScriptElement. (:4:55)

[moduleRaid] Pushing moduleRaid.arrayArguments[1] into webpackJsonpreact-tours failed:
TypeError: Cannot read properties of undefined (reading 'length')
TypeError: Cannot read properties of undefined (reading 'length')
at t (https://ivan-stoychev.com/:1:1261)
at Array.r [as push] (https://ivan-stoychev.com/:1:1186)
at https://unpkg.com/moduleraid/dist/moduleraid.iife.js:1:1742
at Array.forEach ()
at n.fillModules (https://unpkg.com/moduleraid/dist/moduleraid.iife.js:1:1642)
at new e (https://unpkg.com/moduleraid/dist/moduleraid.iife.js:1:1075)
at HTMLScriptElement. (:4:55)

Error:

Uncaught Error: Unknown Webpack structure
at n.fillModules (moduleraid.ts:211:15)
at new e (moduleraid.ts:148:10)
at HTMLScriptElement. (:4:55

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.