Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit 32ecfb5

Browse files
committed
✨ generate random module key to prevent collisions
1 parent cbb42df commit 32ecfb5

4 files changed

Lines changed: 12 additions & 11 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ $ npm install moduleraid
1616
Or if you directly want to use it in the browser
1717

1818
```html
19-
<script src="https://unpkg.com/moduleraid@3.3.0/moduleraid.js"></script>
19+
<script src="https://unpkg.com/moduleraid@3.4.0/moduleraid.js"></script>
2020
<!-- minified -->
21-
<script src="https://unpkg.com/moduleraid@3.3.0/moduleraid.min.js"></script>
21+
<script src="https://unpkg.com/moduleraid@3.4.0/moduleraid.min.js"></script>
2222
```
2323

2424
Alternatively, just copy the script from `moduleraid.js` and run it in a devtool console

moduleraid.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
const moduleRaid = function (debug) {
10+
moduleRaid.mID = Math.random().toString(36).substring(7);
1011
moduleRaid.mObj = {};
1112
moduleRaid.cArr = [];
1213

@@ -32,13 +33,13 @@ const moduleRaid = function (debug) {
3233
})
3334
moduleRaid.cArr = i.m;
3435
}]],
35-
[[1e3], {'moduleraid': function(e, t, i) {
36+
[[1e3], {[moduleRaid.mID]: function(e, t, i) {
3637
mCac = i.c;
3738
Object.keys(mCac).forEach (function(mod) {
3839
moduleRaid.mObj[mod] = mCac[mod].exports;
3940
})
4041
moduleRaid.cArr = i.m;
41-
}}, [['moduleraid']]]
42+
}}, [[moduleRaid.mID]]]
4243
]
4344

4445
fillModuleArray = function() {
@@ -66,7 +67,7 @@ const moduleRaid = function (debug) {
6667
mIter = 0;
6768

6869
if (!webpackJsonp([],[],[mIter])) {
69-
throw Error("Unknown Webpack structure");
70+
throw Error('Unknown Webpack structure');
7071
}
7172

7273
while (!mEnd) {
@@ -95,7 +96,7 @@ const moduleRaid = function (debug) {
9596
mod = moduleRaid.mObj[mKey];
9697

9798
if (typeof mod !== 'undefined') {
98-
if (typeof mod.default === "object") {
99+
if (typeof mod.default === 'object') {
99100
for (key in mod.default) {
100101
if (key == query) results.push(mod);
101102
}
@@ -112,18 +113,18 @@ const moduleRaid = function (debug) {
112113

113114
findFunction = function(query) {
114115
if (moduleRaid.cArr.length == 0) {
115-
throw Error("No module constructors to search through!");
116+
throw Error('No module constructors to search through!');
116117
}
117118

118119
results = [];
119120

120-
if (typeof query === "string") {
121+
if (typeof query === 'string') {
121122
moduleRaid.cArr.forEach(function (ctor, index) {
122123
if (ctor.toString().includes(query)) {
123124
results.push(moduleRaid.mObj[index]);
124125
}
125126
})
126-
} else if (typeof query === "function") {
127+
} else if (typeof query === 'function') {
127128
modules = Object.keys(moduleRaid.mObj);
128129

129130
modules.forEach(function(mKey, index) {

moduleraid.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "moduleraid",
3-
"version": "3.3.0",
3+
"version": "3.4.0",
44
"description": "Get modules from webpackJsonp",
55
"main": "moduleraid.js",
66
"scripts": {

0 commit comments

Comments
 (0)