Commit d839a0c1 authored by Akari Labs's avatar Akari Labs

fix bugs in array-style webpack hook

parent 5f4c634a
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
\ No newline at end of file
......@@ -3,7 +3,7 @@ const path = require('path');
const modules = path.join(__dirname, 'modules');
module.exports = nanopack => {
nanopack.pushFile(path.join(modules, 'cascade.orchestrate.js'), {
nanopack.pushFile(path.join(modules, 'cascade.orchestra.js'), {
provides: 'conductor'
});
nanopack.pushFile(path.join(modules, 'cascade.webpack.abstraction.js'));
......
......@@ -22,8 +22,8 @@ module.exports = {
hookWebpack(pushHook, mod) {
var _webpack;
var _style;
var _webpack, _push;
var _style = style.unknown;
var _insmod_acc = 9000;
// insert a module into webpack
......@@ -34,7 +34,7 @@ module.exports = {
_webpack([++_insmod_acc], [mod], [0]);
break;
case style.array:
_webpack.push([++_insmod_acc], [mod], [[0]]);
_push.apply(_webpack, [[[++_insmod_acc], { cascade: mod }, [['cascade']]]]);
break;
default:
console.warn('cant insmod, unrecognized webpack type');
......@@ -42,56 +42,66 @@ module.exports = {
}
}
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;
}
}
Object.defineProperty(window, 'webpackJsonp', {
get: () => _webpack,
set: setIntercept
set(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;
return;
}
// 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 && webpack.push) {
_style = style.array;
if (webpack.push.hooked || webpack.push === Array.prototype.push) {
_webpack = webpack;
return;
}
_push = webpack.push;
webpack.push = (x, mod, main) => {
if (!mod) {
mod = x[1];
main = x[2];
x = x[0];
}
return _push.apply(webpack, [[x, pushHook(mod), main]]);
}
webpack.push.hooked = true;
_webpack = webpack;
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');
_webpack = webpack;
return;
}
}
});
}
......
......@@ -120,6 +120,7 @@ module.exports = {
},
instrumentation: {
cascade(j) {
const defines = j.cascade;
if (defines.replacements) defines.replacements.forEach(replacement =>
......@@ -134,6 +135,7 @@ module.exports = {
postCtor.push(callback);
});
}
}
};
\ No newline at end of file
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