-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Other bundlers support #117
Comments
Hey, take a look at these files for reference:
Yeah the bundle format looks pretty straight-forward. I suggest you look through https://github.com/j4k0xb/webcrack/blob/master/CONTRIBUTING.md first and try debugging to get a better idea on how the existing unpacker works (only reading the code may be a bit confusing). Then start by creating the boilerplate files and use a The next easiest thing would be extracting the entry module id from Example bundle: var __BUNDLE_START_TIME__ = this.nativePerformanceNow ? nativePerformanceNow() : Date.now();
var __DEV__ = false;
var process = this.process || {};
var __METRO_GLOBAL_PREFIX__ = "";
process.env = process.env || {};
process.env.NODE_ENV = process.env.NODE_ENV || "production";
(function (global) {
// ...
})(typeof globalThis !== "undefined" ? globalThis : typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : this);
__d(function (global, _$$_REQUIRE, _$$_IMPORT_DEFAULT, _$$_IMPORT_ALL, module, exports, _dependencyMap) {
"use strict";
const lib = _$$_REQUIRE(_dependencyMap[0]);
console.log(lib.foo);
}, 0, [1]);
__d(function (global, _$$_REQUIRE, _$$_IMPORT_DEFAULT, _$$_IMPORT_ALL, module, exports, _dependencyMap) {
"use strict";
exports.foo = "bar";
}, 1, []);
__r(0); |
great. ill give it a check! |
Hey what's up. I did this notes the other day, and i was expecting to work on the implementation, but i have had little to no time, so in the mean time ill share this with you, so you can give me a sanity check. I tried to map the concepts from a post i red about the webpack require function, and i think it is pretty similar. Basically the same.
|
this is the metroRequire file. The one that contains the runtime. I tallked about other files at the end of the notes, but this is the main one. var __BUNDLE_START_TIME__ = this.nativePerformanceNow
? nativePerformanceNow()
: Date.now(),
__DEV__ = false,
process = this.process || {};
process.env = process.env || {};
process.env.NODE_ENV = process.env.NODE_ENV || "production";
!(function (e) {
"use strict";
(e.__r = i),
(e.__d = function (e, n, o) {
if (null != t[n]) return;
const i = {
dependencyMap: o,
factory: e,
hasError: !1,
importedAll: r,
importedDefault: r,
isInitialized: !1,
publicModule: { exports: {} },
};
t[n] = i;
}),
(e.__c = o),
(e.__registerSegment = function (e, r, n) {
(p[e] = r),
n &&
n.forEach((r) => {
t[r] || h.has(r) || h.set(r, e);
});
});
var t = o();
const r = {},
{ hasOwnProperty: n } = {};
function o() {
return (t = Object.create(null));
}
function i(e) {
const r = e,
n = t[r];
return n && n.isInitialized ? n.publicModule.exports : d(r, n);
}
function l(e) {
const n = e;
if (t[n] && t[n].importedDefault !== r) return t[n].importedDefault;
const o = i(n),
l = o && o.__esModule ? o.default : o;
return (t[n].importedDefault = l);
}
function u(e) {
const o = e;
if (t[o] && t[o].importedAll !== r) return t[o].importedAll;
const l = i(o);
let u;
if (l && l.__esModule) u = l;
else {
if (((u = {}), l)) for (const e in l) n.call(l, e) && (u[e] = l[e]);
u.default = l;
}
return (t[o].importedAll = u);
}
(i.importDefault = l), (i.importAll = u);
let c = !1;
function d(t, r) {
if (!c && e.ErrorUtils) {
let n;
c = !0;
try {
n = m(t, r);
} catch (t) {
e.ErrorUtils.reportFatalError(t);
}
return (c = !1), n;
}
return m(t, r);
}
const s = 16,
a = 65535;
function f(e) {
return { segmentId: e >>> s, localId: e & a };
}
(i.unpackModuleId = f),
(i.packModuleId = function (e) {
return (e.segmentId << s) + e.localId;
});
const p = [],
h = new Map();
function m(r, n) {
if (!n && p.length > 0) {
const e = h.get(r) ?? 0,
o = p[e];
null != o && (o(r), (n = t[r]), h.delete(r));
}
const o = e.nativeRequire;
if (!n && o) {
const { segmentId: e, localId: i } = f(r);
o(i, e), (n = t[r]);
}
if (!n) throw g(r);
if (n.hasError) throw w(r, n.error);
n.isInitialized = !0;
const { factory: c, dependencyMap: d } = n;
try {
const t = n.publicModule;
return (
(t.id = r),
c(e, i, l, u, t, t.exports, d),
(n.factory = void 0),
(n.dependencyMap = void 0),
t.exports
);
} catch (e) {
throw (
((n.hasError = !0),
(n.error = e),
(n.isInitialized = !1),
(n.publicModule.exports = void 0),
e)
);
}
}
function g(e) {
return Error('Requiring unknown module "' + e + '".');
}
function w(e, t) {
return Error(
'Requiring module "' + e + '", which threw an exception: ' + t,
);
}
})(
"undefined" != typeof globalThis
? globalThis
: "undefined" != typeof global
? global
: "undefined" != typeof window
? window
: this,
); |
seems right so far supporting multi-file bundles is not gonna be easy but can be added later, so for now it would be enough to focus on the example: __d(
function (g, r, i, a, m, e, d) {
"use strict";
const t = r(d[0]).default || r(d[0]);
let c;
m.exports = () => c || ((c = t("locale")), c || "en");
},
"44cd5c",
["b2dff4"],
); to "use strict";
const t = require("./b2dff4.js").default || require("./b2dff4.js");
let c;
module.exports = () => c || ((c = t("locale")), c || "en");
they are used for
yes. |
I want to contribute with support for other bundlers. Right now i am working at a website which uses metro bundler. Which files in the project should i take into consideration for doing this? and would you consider this as something feasible to implement?
The text was updated successfully, but these errors were encountered: