Commit 092949ed authored by Akari Labs's avatar Akari Labs

populate repo

parent a605364c
const path = require('path');
const modules = path.join(__dirname, 'modules');
module.exports = nanopack => {
nanopack.pushFile(path.join(modules, 'cascade.webpack.abstraction.js'));
nanopack.pushFile(path.join(modules, 'cascade.webpack.js'));
};
\ No newline at end of file
function createSymbols(arr) {
const r = {};
arr.forEach(k => r[k] = Symbol(k));
return r;
}
const style = createSymbols(['func', 'array', 'unknown']);
// https://stackoverflow.com/questions/1007981
// fuck you.
const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
const ARGUMENT_NAMES = /([^\s,]+)/g;
function getParams(func) {
const fnStr = func.toString().replace(STRIP_COMMENTS, '');
const result = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')')).match(ARGUMENT_NAMES);
if (result === null)
result = [];
return result;
}
module.exports = {
hookWebpack(pushHook, mod) {
var _webpack;
var _style;
var _insmod_acc = 9000;
// insert a module into webpack
function insmod(mod) {
if (mod === undefined) return;
switch (_style) {
case style.func:
_webpack([++_insmod_acc], [mod], [0]);
break;
case style.array:
_webpack.push([++_insmod_acc], [mod], [[0]]);
break;
default:
console.warn('cant insmod, unrecognized webpack type');
break;
}
}
function setIntercept(webpack) {
switch (typeof webpack) {
case 'function':
const params = getParams(webpack);
if (params.length === 3 || params.length === 2) {
// probably just a relatively normal webpack config
// we naively assume that if there are 2 parameters, it will still be ok
// pleromafe's webpack doesnt take a third parameter, but luckily javascript doesnt give a fuck
_style = style.func;
_webpack = (x, mod, main) => webpack(x, pushHook(mod), main);
}
else {
// god fucking damn it
// okay i have no fucking idea what to do with you
console.warn('cant hook webpack: unrecognized prototype for webpackJsonp');
_webpack = webpack;
}
// hacky but i dont really know how else to go about this
// pleromafe's webpack fails if we insmod before returning from webpackJsonp setter
setTimeout(() => insmod(mod), 10);
break;
case 'object':
if (webpack instanceof Array && push in webpack) {
_style = style.array;
if (webpack.push.hooked || webpack.push === Array.prototype.push)
return _webpack = webpack;
const _push = webpack.push;
webpack.push = (x) => _push.apply(webpack, [x[0], pushHook(x[1]), x[2]])
webpack.push.hooked = true;
_webpack = webpack;
this.insmod(mod);
}
else return console.warn('cant hook webpack: webpackJsonp is an object, but isnt an array');
break;
default:
console.warn('cant hook webpack: i have no idea what webpackJsonp even is');
break;
}
this.webpack = _webpack = webpack;
}
Object.defineProperty(window, 'webpackJsonp', {
get: () => _webpack,
set: setIntercept
});
}
};
\ No newline at end of file
/*
cascade!webpack 1.2
Copyright 2019 astra akari (nocebo) and caela akari (lp0)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
const abstraction = require('cascade.webpack.abstraction');
var _webpack;
const moduleInfo = [];
const replacements = [];
const preCtor = [];
const postCtor = [];
function ctorSearchToFunc(cond) {
if (typeof cond === 'function') return cond;
if (typeof cond === 'string') return info => info.ctor.toString().indexOf(cond) !== -1;
if (Array.isArray(cond)) return info => cond.filter(s => info.ctor.toString().indexOf(s) !== -1).length > 0;
if (cond instanceof RegExp) return info => info.ctor.toString().match(cond);
}
function callbackSearchToFunc(cond) {
if (typeof cond === 'function') return cond;
if (typeof cond === 'string') return info => info.module.exports && ((!!info.module.exports[cond]) || (info.module.exports.default && !!info.module.exports.default[cond]));
if (Array.isArray(cond)) return info => info.module.exports && ((cond.filter(s => info.module.exports[s]).length === cond.length) || (info.module.exports.default && cond.filter(s => info.module.exports.default[s]).length === cond.length));
}
const search = {
byCtor(search) {
const searchFunc = ctorSearchToFunc(search);
return moduleInfo.filter(searchFunc);
},
byCallback(search) {
const searchFunc = callbackSearchToFunc(search);
return moduleInfo.filter(searchFunc);
},
moduleInfo: moduleInfo
};
function cascadeModule(_self, _exports, _require) {
search.require = _require;
}
function exportHook(_self, _exports, _require, _ctor) {
const modinfo = {
ctor: _ctor,
module: _self
};
moduleInfo.push(modinfo);
preCtor.filter(c => c.condition(modinfo)).forEach(c => c.callback(modinfo));
modinfo.ctor(_self, _exports, _require);
postCtor.filter(c => c.condition(modinfo)).forEach(c => c.callback(modinfo));
}
function processModule(mod, i) {
if (!mod) return mod;
var ctorstr = mod.toString();
replacements.forEach(set => {
if (typeof set === 'function') set(ctorstr);
else {
if (
typeof set.search === 'function' ? set.search(ctorstr) :
set.search instanceof RegExp ? ctorstr.match(set.search) :
ctorstr.indexOf(set.search) != -1
) {
console.debug(`patching module ${i} (${set.search})`);
if (typeof set.search === 'function' && typeof set.replace !== 'function')
throw 'function search must have function replace';
ctorstr = typeof set.replace === 'function' ?
set.replace(ctorstr) :
ctorstr.replace(set.search, set.replace);
}
}
});
return (s, e, r) => exportHook(s, e, r, eval(`(${ctorstr})`));
}
function pushHook(mod) {
if (Array.isArray(mod)) {
console.debug(`processing ${mod.length} modules (in array)`);
for (var i in mod) mod[i] = processModule(mod[i], i);
}
else if (typeof mod === 'object') {
var keys = Object.keys(mod);
console.debug(`processing ${keys.length} modules (in object)`);
keys.forEach(i => mod[i] = processModule(mod[i], i));
}
/*else if (typeof mod === 'function') {
console.debug(`processing a module (single)`);
mod = processModule(mod);
}*/
else {
console.warn(`weird type passed to push (${typeof mod}); ignoring it`);
console.debug(mod);
}
return mod;
}
function hookWebpack() {
console.debug('hooking webpackJsonp');
var hooks = abstraction.hookWebpack(pushHook, cascadeModule);
}
module.exports = {
search, hookWebpack,
replacements, preCtor, postCtor
};
\ No newline at end of file
{
"name": "nanopack_cascade",
"version": "0.0.0",
"description": "rip apart webpack modules with ease",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://git.agiri.ninja/lp0/cascade-webpack.git"
},
"author": "nocebo and lp0",
"license": "MIT"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment