caffeine-mc
Version:
Select, configure and extend your to-JavaScript compiler, with arbitrary code, on a per file bases from within the file.
1,348 lines (1,156 loc) • 89.3 kB
JavaScript
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/*!**********************!*\
!*** ./index.coffee ***!
\**********************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(/*! ./source */ 1);
/***/ }),
/* 1 */
/*!*************************!*\
!*** ./source/index.js ***!
\*************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(/*! ./CaffeineMc */ 2);
/***/ }),
/* 2 */
/*!************************************!*\
!*** ./source/CaffeineMc/index.js ***!
\************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
// generated by Neptune Namespaces v4.x.x
// file: CaffeineMc/index.js
(module.exports = __webpack_require__(/*! ./namespace */ 3))
.includeInNamespace(__webpack_require__(/*! ./CaffeineMc */ 7))
.addModules({
CaffeineMcParser: __webpack_require__(/*! ./CaffeineMcParser */ 12),
CafRepl: __webpack_require__(/*! ./CafRepl */ 35),
CompileCache: __webpack_require__(/*! ./CompileCache */ 15),
DirReader: __webpack_require__(/*! ./DirReader */ 21),
FileCompiler: __webpack_require__(/*! ./FileCompiler */ 30),
Highlight: __webpack_require__(/*! ./Highlight */ 38),
Metacompiler: __webpack_require__(/*! ./Metacompiler */ 8),
ModuleResolver: __webpack_require__(/*! ./ModuleResolver */ 20),
Register: __webpack_require__(/*! ./Register */ 34),
Run: __webpack_require__(/*! ./Run */ 33),
SourceRoots: __webpack_require__(/*! ./SourceRoots */ 17),
Tools: __webpack_require__(/*! ./Tools */ 31),
WorkingCache: __webpack_require__(/*! ./WorkingCache */ 22)
});
__webpack_require__(/*! ./Compilers */ 9);
/***/ }),
/* 3 */
/*!****************************************!*\
!*** ./source/CaffeineMc/namespace.js ***!
\****************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
// generated by Neptune Namespaces v4.x.x
// file: CaffeineMc/namespace.js
module.exports = __webpack_require__(/*! neptune-namespaces */ 4).addNamespace(
'CaffeineMc',
(class CaffeineMc extends Neptune.PackageNamespace {})
._configureNamespace(__webpack_require__(/*! ../../package.json */ 5))
);
__webpack_require__(/*! ./Compilers/namespace */ 6);
/***/ }),
/* 4 */
/*!*************************************************************************************!*\
!*** external "require('neptune-namespaces' /* ABC - not inlining fellow NPM *_/)" ***!
\*************************************************************************************/
/*! no static exports found */
/***/ (function(module, exports) {
module.exports = require('neptune-namespaces' /* ABC - not inlining fellow NPM */);
/***/ }),
/* 5 */
/*!**********************!*\
!*** ./package.json ***!
\**********************/
/*! exports provided: author, bin, dependencies, description, devDependencies, license, name, scripts, version, default */
/***/ (function(module) {
module.exports = {"author":"Shane Brinkman-Davis Delamore, Imikimi LLC","bin":{"caf":"./caf"},"dependencies":{"art-build-configurator":"*","babel-core":"^6.26.3","babel-loader":"^8.0.4","babel-preset-env":"^1.7.0","caffeine-eight":"*","cardinal":"^1.0.0","chalk":"^1.1.3","colors":"^1.1.2","commander":"^2.9.0","fs-extra":"^3.0.0","glob":"^7.0.3","glob-promise":"^3.1.0","mock-fs":"^4.5.0","prettier":"^1.17.1"},"description":"Select, configure and extend your to-JavaScript compiler, with arbitrary code, on a per file bases from within the file.","devDependencies":{"art-testbench":"*","case-sensitive-paths-webpack-plugin":"^2.1.2","chai":"^4.2.0","mocha":"^5.2.0","mock-fs":"^4.10.0","webpack":"^4.32.2","webpack-cli":"*","webpack-dev-server":"^3.4.1","webpack-merge":"^4.2.1","webpack-node-externals":"^1.7.2","webpack-stylish":"^0.1.8"},"license":"ISC","name":"caffeine-mc","scripts":{"build":"webpack --progress","start":"webpack-dev-server --hot --inline --progress --env.devServer","test":"nn -s;mocha -u tdd","testInBrowser":"webpack-dev-server --progress --env.devServer"},"version":"2.12.11"};
/***/ }),
/* 6 */
/*!**************************************************!*\
!*** ./source/CaffeineMc/Compilers/namespace.js ***!
\**************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
// generated by Neptune Namespaces v4.x.x
// file: CaffeineMc/Compilers/namespace.js
module.exports = __webpack_require__(/*! ../namespace */ 3).addNamespace(
'Compilers',
class Compilers extends Neptune.PackageNamespace {}
);
/***/ }),
/* 7 */
/*!*********************************************!*\
!*** ./source/CaffeineMc/CaffeineMc.coffee ***!
\*********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
module.exports = [__webpack_require__(/*! ./Metacompiler */ 8), __webpack_require__(/*! ./FileCompiler */ 30), __webpack_require__(/*! ./ModuleResolver */ 20), __webpack_require__(/*! ./Tools */ 31), __webpack_require__(/*! ./Run */ 33), __webpack_require__(/*! ./Register */ 34)];
/***/ }),
/* 8 */
/*!***********************************************!*\
!*** ./source/CaffeineMc/Metacompiler.coffee ***!
\***********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
var BaseClass, CaffeineMc, CaffeineMcParser, CompileCache, Compilers, Metacompiler, checkWorkingCacheExpiration, dashCase, formattedInspect, isArray, isFunction, isObject, isString, log, lowerCamelCase, merge, objectWithout, present, realRequire, ref, upperCamelCase,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Compilers = __webpack_require__(/*! ./Compilers */ 9);
CaffeineMcParser = __webpack_require__(/*! ./CaffeineMcParser */ 12);
CaffeineMc = __webpack_require__(/*! ./namespace */ 3);
CompileCache = __webpack_require__(/*! ./CompileCache */ 15);
realRequire = eval('require');
ref = __webpack_require__(/*! art-standard-lib */ 13), dashCase = ref.dashCase, formattedInspect = ref.formattedInspect, present = ref.present, isFunction = ref.isFunction, log = ref.log, isString = ref.isString, lowerCamelCase = ref.lowerCamelCase, upperCamelCase = ref.upperCamelCase, merge = ref.merge, objectWithout = ref.objectWithout, isArray = ref.isArray, isObject = ref.isObject;
BaseClass = __webpack_require__(/*! art-class-system */ 11).BaseClass;
checkWorkingCacheExpiration = __webpack_require__(/*! ./WorkingCache */ 22).checkWorkingCacheExpiration;
module.exports = Metacompiler = (function(superClass) {
extend(Metacompiler, superClass);
Metacompiler.compile = function(code, options) {
if (options == null) {
options = {};
}
return new Metacompiler().compile(code, options);
};
Metacompiler.getter("compiler lastMetacompilerResult", {
current: function() {
return this.compiler;
}
});
Metacompiler.setter({
/*
IN:
string: configure to use one of the CaffeineCompiler classes
function: compileFunction
object:
compiler: custom compiler instance. Must implement:
compile: compileFunction
compileFunction: (sourceCode, options) ->
IN:
sourceCode: string
options: {}
ERROR: throw errors
OUT:
evalable-js-string
OR
object with at least:
compiled: js: evalable-js-string
*/
compiler: function(arg, options) {
return this._compiler = (function() {
if (isString(arg)) {
return this.getCompiler(arg, options);
} else if (isFunction(arg.compile)) {
return arg;
} else if (isFunction(arg)) {
return {
compile: arg
};
} else {
log.error({
InavlidCompiler: arg
});
throw new Error("CaffeineMc: @compiler must be a function or be an object with a .compile method.");
}
}).call(this);
}
});
function Metacompiler() {
Metacompiler.__super__.constructor.apply(this, arguments);
this._metaParser = new CaffeineMcParser;
this._metaCompiler = this;
this._compiler = __webpack_require__(/*! caffeine-script */ 27);
this.compilers = {};
}
Metacompiler.prototype.normalizeCompilerResult = function(result) {
var ref1;
if (isString(result)) {
return {
compiled: {
js: result
}
};
} else if (isString(result != null ? result.code : void 0)) {
return {
compiled: {
js: result.code
}
};
} else if (isString(result != null ? result.js : void 0)) {
return {
compiled: result
};
} else if (isString(result != null ? (ref1 = result.compiled) != null ? ref1.js : void 0 : void 0)) {
return result;
} else {
log.error({
normalizeCompilerResult: {
result: result,
compiler: this.compiler
}
});
throw new Error("CaffeineMc: expected @compiler result to be: (string), {js: string}, or {compiled: {js: string}}. Was: " + (formattedInspect(result)));
}
};
/*
IN:
code: string
options:
sourceMap: t/f
inlineMap: t/f
sourceFile:
sourceDir:
OUT: (an object)
compiled: extension => output map
extension: string, ex: "js"
output: string, ex: "alert();"
If writing to files, we might do:
for extension, output of compiled
write originalFileNameWith(extension), output
*/
Metacompiler.prototype.compile = function(code, options) {
checkWorkingCacheExpiration();
options = merge(Neptune.CaffeineMc.globalCompilerOptions, options);
if (options.prettier && (options.inlineMap || options.sourceMap)) {
throw new Error("prettier does not support sourcemaps");
}
if (options.cache && options.sourceFile) {
return this._compileWithCaching(code, options);
} else {
return this._postprocess(options, this._compileWithMetacompiler(code, options));
}
};
Metacompiler.prototype._postprocess = function(options, out) {
return this._postprocesPrettier(options, this._postprocessWithTranspiler(options, out));
};
Metacompiler.prototype._postprocessWithTranspiler = function(options, out) {
var babel, code, e, map, ref1, sourceMap, transpileOptions;
if (transpileOptions = options.transpile) {
transpileOptions = (function() {
switch (false) {
case !isArray(transpileOptions):
return {
presets: transpileOptions
};
case !isString(transpileOptions):
return {
presets: [transpileOptions]
};
case !isObject(transpileOptions):
return transpileOptions;
default:
return {
presets: ['env']
};
}
})();
try {
babel = __webpack_require__(/*! babel-core */ 28);
if (sourceMap = out.compiled.sourceMap && (transpileOptions.inputSourceMap == null)) {
transpileOptions = merge(transpileOptions, {
inputSourceMap: sourceMap
});
}
ref1 = babel.transform(out.compiled.js, transpileOptions), code = ref1.code, map = ref1.map;
if ((map != null) && (out.sourceMap != null)) {
out.compiled.sourceMap = JSON.stringify(map);
}
out.compiled.js = code;
out.transpiled = true;
} catch (error) {
e = error;
log(e.message);
throw e;
}
}
return out;
};
Metacompiler.prototype._postprocesPrettier = function(options, out) {
var e;
if (options.prettier) {
try {
if (out.compiled.js != null) {
out.compiled.js = __webpack_require__(/*! prettier */ 29).format(out.compiled.js, {
parser: "babel"
});
}
out.prettier = true;
} catch (error) {
e = error;
log(e.message);
throw e;
}
}
return out;
};
Metacompiler.prototype._compileWithCaching = function(code, options) {
var cacheInfo, cachedCompile, inlineMap, prettier, ref1, ref2, transpile;
options = objectWithout(options, "cache");
cacheInfo = {
compiler: this.compiler,
source: code,
verbose: options.verbose,
sourceFile: options.sourceFile
};
prettier = options.prettier, inlineMap = options.inlineMap, transpile = options.transpile;
if ((ref1 = (ref2 = prettier != null) != null ? ref2 : inlineMap != null) != null ? ref1 : transpile != null) {
cacheInfo.compilerOptions = {
prettier: prettier,
inlineMap: inlineMap,
transpile: transpile
};
}
if (cachedCompile = CompileCache.fetch(cacheInfo)) {
return cachedCompile;
} else {
return CompileCache.cache(merge(cacheInfo, this._postprocess(options, this._compileWithMetacompiler(code, options))));
}
};
Metacompiler.prototype._compileWithMetacompiler = function(rawCode, options) {
var code, compilerName, metaCode, ref1, result;
ref1 = this._metaParser.parse(rawCode.toString()), compilerName = ref1.compilerName, metaCode = ref1.metaCode, code = ref1.code;
if (metaCode || compilerName) {
this._lastMetacompilerResult = metaCode ? (result = this.normalizeCompilerResult(this.compiler.compile(metaCode)), CaffeineMc.evalInContext(result.compiled.js, this)) : this.setCompiler(compilerName, options);
return this._compileWithMetacompiler(code, options);
} else {
return this.normalizeCompilerResult(this.compiler.compile(code, options));
}
};
Metacompiler.getter({
compilerName: function() {
var base, base1;
return (typeof (base = this.compiler).getClassName === "function" ? base.getClassName() : void 0) || (typeof (base1 = this.compiler).getName === "function" ? base1.getName() : void 0) || this._compilerName || 'unknown-compiler';
}
});
Metacompiler.prototype.getCompiler = function(compilerName, options) {
var absolutePath, base, compiler, out, ucCompilerName;
if (compilerName.toLocaleLowerCase() === "javascript") {
compilerName = "JavaScript";
}
if (!present(compilerName)) {
return this.compiler;
}
if (compiler = Compilers[ucCompilerName = upperCamelCase(compilerName)]) {
return compiler;
}
this._compilerName = compilerName;
absolutePath = CaffeineMc.findModuleSync(compilerName, options).absolutePath;
try {
out = (base = this.compilers)[absolutePath] || (base[absolutePath] = realRequire(absolutePath));
if (!isFunction(out.compile)) {
throw new Error;
}
} catch (error) {
throw new Error("CaffeineMc: compiler not found for: " + compilerName + " (normalized: " + ucCompilerName + ", require: " + absolutePath + ")");
}
return out;
};
return Metacompiler;
})(BaseClass);
/***/ }),
/* 9 */
/*!**********************************************!*\
!*** ./source/CaffeineMc/Compilers/index.js ***!
\**********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
// generated by Neptune Namespaces v4.x.x
// file: CaffeineMc/Compilers/index.js
(module.exports = __webpack_require__(/*! ./namespace */ 6))
.addModules({
JavaScript: __webpack_require__(/*! ./JavaScript */ 10)
});
/***/ }),
/* 10 */
/*!*******************************************************!*\
!*** ./source/CaffeineMc/Compilers/JavaScript.coffee ***!
\*******************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
var JavaScript,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
module.exports = JavaScript = (function(superClass) {
extend(JavaScript, superClass);
function JavaScript() {
return JavaScript.__super__.constructor.apply(this, arguments);
}
JavaScript.compile = function(sourceCode, options) {
return {
compiled: {
js: sourceCode
}
};
};
return JavaScript;
})(__webpack_require__(/*! art-class-system */ 11).BaseClass);
/***/ }),
/* 11 */
/*!***********************************************************************************!*\
!*** external "require('art-class-system' /* ABC - not inlining fellow NPM *_/)" ***!
\***********************************************************************************/
/*! no static exports found */
/***/ (function(module, exports) {
module.exports = require('art-class-system' /* ABC - not inlining fellow NPM */);
/***/ }),
/* 12 */
/*!***************************************************!*\
!*** ./source/CaffeineMc/CaffeineMcParser.coffee ***!
\***************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
var CaffeineEight, CaffeineMcParser, isFunction, isString, log, lowerCamelCase, merge, present, ref, upperCamelCase,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
ref = __webpack_require__(/*! art-standard-lib */ 13), present = ref.present, isFunction = ref.isFunction, log = ref.log, isString = ref.isString, lowerCamelCase = ref.lowerCamelCase, upperCamelCase = ref.upperCamelCase, merge = ref.merge;
CaffeineEight = __webpack_require__(/*! caffeine-eight */ 14);
module.exports = CaffeineMcParser = (function(superClass) {
extend(CaffeineMcParser, superClass);
function CaffeineMcParser() {
return CaffeineMcParser.__super__.constructor.apply(this, arguments);
}
CaffeineMcParser.rule({
root: "!oneLinerWithoutColon meta? toEof"
}, {
getter: {
compilerName: function() {
var ref1, ref2;
return (ref1 = this.meta) != null ? (ref2 = ref1.compilerName) != null ? ref2.text : void 0 : void 0;
},
metaCode: function() {
var ref1, ref2;
return (ref1 = this.meta) != null ? (ref2 = ref1.metaCode) != null ? ref2.text : void 0 : void 0;
},
code: function() {
var ref1;
return ((ref1 = this.toEof) != null ? ref1.text : void 0) || "";
}
}
});
CaffeineMcParser.rule({
meta: ["'|' compilerName /\: */ metaCode:toEol end", "'|' / +/ metaCode:toEol end", "'|' compilerName /\: */? metaCode:block end", "'|' metaCode:block end", "'|' compilerName end", "'|'"],
oneLinerWithoutColon: "'|' compilerName / *[^:\n]/",
compilerName: /[^:\s]+/i,
toEof: /(.|\n)*$/,
toEol: /\S[^\n]*/,
end: /\n|$/,
block: CaffeineEight.Extensions.IndentBlocks.getPropsToSubparseBlock({
rule: "toEof"
})
});
return CaffeineMcParser;
})(CaffeineEight.Parser);
/***/ }),
/* 13 */
/*!***********************************************************************************!*\
!*** external "require('art-standard-lib' /* ABC - not inlining fellow NPM *_/)" ***!
\***********************************************************************************/
/*! no static exports found */
/***/ (function(module, exports) {
module.exports = require('art-standard-lib' /* ABC - not inlining fellow NPM */);
/***/ }),
/* 14 */
/*!*********************************************************************************!*\
!*** external "require('caffeine-eight' /* ABC - not inlining fellow NPM *_/)" ***!
\*********************************************************************************/
/*! no static exports found */
/***/ (function(module, exports) {
module.exports = require('caffeine-eight' /* ABC - not inlining fellow NPM */);
/***/ }),
/* 15 */
/*!***********************************************!*\
!*** ./source/CaffeineMc/CompileCache.coffee ***!
\***********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(module) {var BaseClass, CompileCache, Promise, array, consistentJsonStringify, crypto, currentSecond, defineModule, findModuleSync, findSourceRootSync, formattedInspect, fs, glob, isString, log, merge, os, path, randomBase62Character, ref, upperCamelCase,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
ref = __webpack_require__(/*! art-standard-lib */ 13), array = ref.array, merge = ref.merge, formattedInspect = ref.formattedInspect, log = ref.log, defineModule = ref.defineModule, isString = ref.isString, upperCamelCase = ref.upperCamelCase, randomBase62Character = ref.randomBase62Character, consistentJsonStringify = ref.consistentJsonStringify, Promise = ref.Promise, currentSecond = ref.currentSecond;
BaseClass = __webpack_require__(/*! art-class-system */ 11).BaseClass;
findSourceRootSync = __webpack_require__(/*! ./SourceRoots */ 17).findSourceRootSync;
findModuleSync = __webpack_require__(/*! ./ModuleResolver */ 20).findModuleSync;
__webpack_require__(/*! colors */ 23);
fs = __webpack_require__(/*! fs-extra */ 18);
glob = __webpack_require__(/*! glob-promise */ 24);
crypto = __webpack_require__(/*! crypto */ 25);
os = __webpack_require__(/*! os */ 26);
path = __webpack_require__(/*! path */ 19);
/*
cachedFileKey: (object)
compiler: (required, object) compiler
source: (required, string) source-code
sourceFile: (required, string) source file path & name
compilerOptions: (object) all options which affect the generated output
cachedFileKeyWithCompilerResults: (object)
all the cachedFileKey fields
compiled: (required, object) the compiler's results
*/
defineModule(module, CompileCache = (function(superClass) {
extend(CompileCache, superClass);
function CompileCache() {
return CompileCache.__super__.constructor.apply(this, arguments);
}
CompileCache.compileCacheFileNameRoot = "CaffineMcCompileCache";
CompileCache.classGetter({
compileCachePathRoot: function() {
return os.tmpdir();
},
compileCacheFilePathRoot: function() {
return this._compileCacheFilePathRoot || (this._compileCacheFilePathRoot = path.join(this.compileCachePathRoot, this.compileCacheFileNameRoot));
}
});
CompileCache.compilerSupportsCaching = function(compiler) {
return isString(compiler.version) && this.getCompilerName(compiler);
};
CompileCache.getCompilerName = function(compiler) {
return (typeof compiler.getName === "function" ? compiler.getName() : void 0) || compiler.name;
};
CompileCache.getCompilerSignature = function(compiler) {
return (this.getCompilerName(compiler)) + "-" + compiler.version;
};
CompileCache.makeSha256FilenameFriendly = function(sha256String) {
return sha256String.replace(/[\/+=]/g, "-");
};
CompileCache.hashSource = function(source) {
return this.makeSha256FilenameFriendly(crypto.createHmac('sha256', "no need for a real secret").update(source).digest('base64').split("=")[0]);
};
/*
IN: cachedFileKey (see above)
*/
CompileCache.getFileName = function(cachedFileKey) {
var compiler, compilerOptions, relativeSourceFile, source, sourceFile, sourceRoot;
compiler = cachedFileKey.compiler, source = cachedFileKey.source, sourceFile = cachedFileKey.sourceFile, compilerOptions = cachedFileKey.compilerOptions;
if (!(compiler && sourceFile && (source != null))) {
throw new Error("expecting compiler, source and sourceFile: " + formattedInspect({
compiler: compiler,
source: source,
sourceFile: sourceFile
}));
}
if (!this.compilerSupportsCaching(compiler)) {
return null;
}
sourceRoot = findSourceRootSync(sourceFile);
relativeSourceFile = path.relative(sourceRoot, sourceFile);
source = "# sourceFile: " + relativeSourceFile + "\n# compilerOptions: " + (consistentJsonStringify(compilerOptions != null ? compilerOptions : null)) + "\n" + source;
return [this.compileCacheFilePathRoot, path.basename(sourceRoot).replace(/\./g, "-"), path.basename(sourceFile).replace(/\./g, "-"), this.getCompilerSignature(compiler), this.hashSource(source)].join("_") + ".json";
};
/*
IN: cachedFileKey (see above), but also with {source, compiled and props}
*/
CompileCache.cache = function(cachedFileKey) {
var compiled, fileName, props, source;
if (fileName = this.getFileName(cachedFileKey)) {
source = cachedFileKey.source, compiled = cachedFileKey.compiled, props = cachedFileKey.props;
if (cachedFileKey.verbose) {
log({
caching: cachedFileKey.sourceFile
});
}
fs.writeFileSync(fileName, JSON.stringify(merge({
source: source,
compiled: compiled,
props: props
})));
}
return cachedFileKey;
};
/*
IN: cachedFileKey (see above)
*/
CompileCache.fetch = function(cachedFileKey) {
var cacheContents, fileName, start;
start = currentSecond();
if ((fileName = this.getFileName(cachedFileKey)) && fs.existsSync(fileName)) {
if ((cacheContents = (function() {
try {
return JSON.parse(fs.readFileSync(fileName));
} catch (error) {}
})()) && cacheContents.source === cachedFileKey.source && this.verifyDependencies(cachedFileKey, cacheContents.props)) {
cacheContents.fromCache = true;
if (cachedFileKey.verbose) {
log({
cached: (((currentSecond() - start) * 1000 | 0) + "ms ") + cachedFileKey.sourceFile
});
}
return cacheContents;
}
}
};
CompileCache.verifyDependencies = function(cachedFileKey, props) {
var cachedRequireString, moduleDependencies, requireString, sourceString;
if (moduleDependencies = props != null ? props.moduleDependencies : void 0) {
for (sourceString in moduleDependencies) {
cachedRequireString = moduleDependencies[sourceString];
requireString = findModuleSync(sourceString, {
sourceFile: cachedFileKey.sourceFile
}).requireString;
if (requireString !== cachedRequireString) {
log({
CompileCache: {
message: "moduleDependencies changed",
sourceString: sourceString,
sourceFile: cachedFileKey.sourceFile,
require: {
old: cachedRequireString,
"new": requireString
}
}
});
return false;
}
}
return true;
} else {
return true;
}
};
CompileCache.reset = function(verbose) {
return glob(this.compileCacheFilePathRoot + "*").then(function(list) {
return Promise.all(array(list, function(item) {
return Promise.resolve(item).then(function(item) {
return fs.unlink(item);
}).tap(function() {
if (verbose) {
return log("cache-reset: ".gray + item.green + " (deleted)".gray);
}
});
}));
});
};
return CompileCache;
})(BaseClass));
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/module.js */ 16)(module)))
/***/ }),
/* 16 */
/*!*************************************************!*\
!*** ../node_modules/webpack/buildin/module.js ***!
\*************************************************/
/*! no static exports found */
/***/ (function(module, exports) {
module.exports = function(module) {
if (!module.webpackPolyfill) {
module.deprecate = function() {};
module.paths = [];
// module.parent = undefined by default
if (!module.children) module.children = [];
Object.defineProperty(module, "loaded", {
enumerable: true,
get: function() {
return module.l;
}
});
Object.defineProperty(module, "id", {
enumerable: true,
get: function() {
return module.i;
}
});
module.webpackPolyfill = 1;
}
return module;
};
/***/ }),
/* 17 */
/*!**********************************************!*\
!*** ./source/CaffeineMc/SourceRoots.coffee ***!
\**********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(module) {var BaseClass, SourceRoots, array, defineModule, each, find, fs, log, merge, path, present, ref, w,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
ref = __webpack_require__(/*! art-standard-lib */ 13), defineModule = ref.defineModule, array = ref.array, log = ref.log, merge = ref.merge, present = ref.present, find = ref.find, each = ref.each, w = ref.w;
BaseClass = __webpack_require__(/*! art-class-system */ 11).BaseClass;
fs = __webpack_require__(/*! fs-extra */ 18);
path = __webpack_require__(/*! path */ 19);
defineModule(module, SourceRoots = (function(superClass) {
var _Metacompiler, defaultSourceRootIndicatorFiles, evalCapturingModuleExports, newMetacompiler;
extend(SourceRoots, superClass);
function SourceRoots() {
return SourceRoots.__super__.constructor.apply(this, arguments);
}
SourceRoots.classGetter("sourceRootIndicatorFiles knownSourceRoots caffeineInits", {
caffeineInitFileName: function() {
return "caffeine-mc.config.caf";
}
});
_Metacompiler = null;
newMetacompiler = function() {
return new (_Metacompiler != null ? _Metacompiler : _Metacompiler = __webpack_require__(/*! ./Metacompiler */ 8));
};
evalCapturingModuleExports = function(source) {
var e, exports;
global.__caffeineMcModule = {};
try {
eval("(function(module){ " + source + " })(__caffeineMcModule);");
} catch (error) {
e = error;
log.error({
"ERROR evalCapturingModuleExports": {
source: source,
error: e
}
});
throw e;
}
exports = (global.__caffeineMcModule || {}).exports;
global.__caffeineMcModule = null;
return exports;
};
SourceRoots.getCaffeineInit = function(sourceRoot) {
var res, sourceFile;
if (sourceRoot == null) {
sourceRoot = process.cwd();
}
if ((res = SourceRoots.caffeineInits[sourceRoot]) != null) {
return Promise.resolve(res);
} else {
return fs.exists(sourceFile = path.join(sourceRoot, SourceRoots.caffeineInitFileName)).then(function(exists) {
var contentsPromise;
contentsPromise = exists ? fs.readFile(sourceFile).then(function(contents) {
return contents = contents.toString();
}) : Promise.resolve(false);
return contentsPromise.then(function(contents) {
var metacompiler, result;
metacompiler = newMetacompiler();
return SourceRoots.caffeineInits[sourceRoot] = {
compiler: metacompiler,
config: (result = contents && metacompiler.compile(contents, {
sourceFile: sourceFile,
sourceRoot: sourceRoot
})) ? evalCapturingModuleExports(result.compiled.js) : {}
};
});
});
}
};
SourceRoots.getCaffeineInitSync = function(sourceRoot) {
var contents, metacompiler, res, result, sourceFile;
if (!sourceRoot) {
throw new Error("no sourceRoot");
}
if ((res = SourceRoots.caffeineInits[sourceRoot]) != null) {
return res;
} else {
if (fs.existsSync(sourceFile = path.join(sourceRoot, SourceRoots.caffeineInitFileName))) {
contents = fs.readFileSync(sourceFile).toString();
metacompiler = newMetacompiler();
result = metacompiler.compile(contents, {
sourceFile: sourceFile,
sourceRoot: sourceRoot
});
return SourceRoots.caffeineInits[sourceRoot] = {
compiler: metacompiler.compiler,
config: evalCapturingModuleExports(result.compiled.js)
};
} else {
return false;
}
}
};
SourceRoots.findSourceRoot = function(directory, rootFiles) {
if (rootFiles == null) {
rootFiles = SourceRoots._sourceRootIndicatorFiles;
}
directory = path.resolve(directory);
return fs.stat(directory).then(function(stat) {
var ret;
if (!stat.isDirectory()) {
directory = path.dirname(directory);
}
if ((ret = SourceRoots.knownSourceRoots[directory]) != null) {
return ret;
} else {
return SourceRoots._findRootR(directory, rootFiles).then(function(sourceRoot) {
return SourceRoots.knownSourceRoots[directory] = sourceRoot || false;
});
}
});
};
SourceRoots.findSourceRootSync = function(directory, rootFiles) {
var ret, sourceRoot, stat;
if (rootFiles == null) {
rootFiles = SourceRoots._sourceRootIndicatorFiles;
}
directory = path.resolve(directory);
stat = fs.statSync(directory);
if (!stat.isDirectory()) {
directory = path.dirname(directory);
}
if ((ret = SourceRoots.knownSourceRoots[directory]) != null) {
return ret;
} else {
sourceRoot = SourceRoots._findRootSyncR(directory, rootFiles);
return SourceRoots.knownSourceRoots[directory] = sourceRoot || false;
}
};
SourceRoots._caffeineInits = {};
SourceRoots._knownSourceRoots = {};
SourceRoots._sourceRootIndicatorFiles = defaultSourceRootIndicatorFiles = ["package.json", SourceRoots.caffeineInitFileName];
SourceRoots._resetSourceRoots = function() {
SourceRoots._caffeineInits = {};
SourceRoots._knownSourceRoots = {};
return SourceRoots._sourceRootIndicatorFiles = defaultSourceRootIndicatorFiles;
};
SourceRoots._findRootR = function(directory, rootFiles) {
return Promise.all(array(rootFiles, function(file) {
return fs.exists(path.join(directory, file));
})).then((function(_this) {
return function(rootFileExistResults) {
if (find(rootFileExistResults)) {
return directory;
} else if (directory !== "/" && present(directory)) {
return _this._findRootR(path.dirname(directory), rootFiles);
} else {
return null;
}
};
})(this));
};
SourceRoots._findRootSyncR = function(directory, rootFiles) {
var rootFileExistResults;
rootFileExistResults = array(rootFiles, function(file) {
return fs.existsSync(path.join(directory, file));
});
if (find(rootFileExistResults)) {
return directory;
} else if (directory !== "/" && present(directory)) {
return this._findRootSyncR(path.dirname(directory), rootFiles);
} else {
return null;
}
};
return SourceRoots;
})(BaseClass));
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/module.js */ 16)(module)))
/***/ }),
/* 18 */
/*!***************************************************************************!*\
!*** external "require('fs-extra' /* ABC - not inlining fellow NPM *_/)" ***!
\***************************************************************************/
/*! no static exports found */
/***/ (function(module, exports) {
module.exports = require('fs-extra' /* ABC - not inlining fellow NPM */);
/***/ }),
/* 19 */
/*!***********************************************************************!*\
!*** external "require('path' /* ABC - not inlining fellow NPM *_/)" ***!
\***********************************************************************/
/*! no static exports found */
/***/ (function(module, exports) {
module.exports = require('path' /* ABC - not inlining fellow NPM */);
/***/ }),
/* 20 */
/*!*************************************************!*\
!*** ./source/CaffeineMc/ModuleResolver.coffee ***!
\*************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(module) {var ErrorWithInfo, ModuleResolver, Path, Promise, cacheable, currentSecond, dashCase, defineModule, dirReader, each, find, findSourceRootSync, log, merge, mergeInto, normalizeName, peek, present, readdirSync, realRequire, ref, ref1, statSync, upperCamelCase, w,
slice = [].slice;
ref = __webpack_require__(/*! art-standard-lib */ 13), defineModule = ref.defineModule, peek = ref.peek, Promise = ref.Promise, dashCase = ref.dashCase, upperCamelCase = ref.upperCamelCase, ErrorWithInfo = ref.ErrorWithInfo, log = ref.log, merge = ref.merge, present = ref.present, find = ref.find, each = ref.each, w = ref.w, mergeInto = ref.mergeInto, currentSecond = ref.currentSecond;
Path = __webpack_require__(/*! path */ 19);
ref1 = __webpack_require__(/*! fs-extra */ 18), statSync = ref1.statSync, readdirSync = ref1.readdirSync;
dirReader = __webpack_require__(/*! ./DirReader */ 21);
cacheable = __webpack_require__(/*! ./WorkingCache */ 22).cacheable;
normalizeName = cacheable("normalizeName", upperCamelCase);
realRequire = eval('require');
findSourceRootSync = __webpack_require__(/*! ./SourceRoots */ 17).findSourceRootSync;
/*
2018-07-21 Optimization TODO:
I think if we simplify the semantics such that matches are defined as:
normalizeName(dirName) == normalizeName(moduleName)
AND
* this is the change:
normalizeName(fileName.split(".")[0]) == normalizeName(moduleName)
Then we can probably make much better use of caching:
Read the dir in and create a map:
normalizedName: name
(where normalizedName here means for files, we strip the extensions)
Then, we don't have to scan the dir every time!
NOTE: I think if we have >= 2 files which map to the same noramlized name
we encode that in the map somehow and can therefore raise the same
exception we already do.
*/
defineModule(module, ModuleResolver = (function() {
var getMatchingName, maybeCouldHaveCached;
function ModuleResolver() {}
/*
IN:
moduleBaseName: the string before the first '/'
modulePathArray: every other sub-string, split by '/'
This is only used to determine if there is addutional pathing
that must be resolved. It makes a difference what the
require path looks like.
*/
ModuleResolver.getNpmPackageName = function(moduleBaseName, modulePathArray) {
var absolutePath, name, normalizedModuleName, requireString;
normalizedModuleName = upperCamelCase(moduleBaseName);
try {
absolutePath = Path.dirname(realRequire.resolve(name = dashCase(moduleBaseName)));
} catch (error) {
try {
absolutePath = Path.dirname(realRequire.resolve(name = moduleBaseName));
} catch (error) {
throw new ErrorWithInfo("ModuleResolver: Could not find requested npm package: " + moduleBaseName, {
npmPackageNamesAttempted: [moduleBaseName, dashCase(moduleBaseName)]
});
}
}
requireString = (modulePathArray != null ? modulePathArray.length : void 0) > 0 ? Path.join(name, absolutePath.slice((absolutePath.lastIndexOf(name)) + name.length)) : name;
return {
requireString: requireString,
absolutePath: absolutePath
};
};
ModuleResolver.findModuleSync = function(moduleName, options) {
var absolutePath, base, denormalizedBase, j, len, matchingName, mod, modulePathArray, out, ref2, ref3, requireString, sub;
if (/\//.test(moduleName)) {
ref2 = (function() {
var j, len, ref2, ref3, results;
ref3 = (ref2 = moduleName.split("/"), denormalizedBase = ref2[0], ref2);
results = [];
for (j = 0, len = ref3.length; j < len; j++) {
mod = ref3[j];
out = normalizeName(mod);
results.push(out);
}
return results;
})(), base = ref2[0], modulePathArray = 2 <= ref2.length ? slice.call(ref2, 1) : [];
} else {
denormalizedBase = moduleName;
}
ref3 = ModuleResolver._findModuleBaseSync(denormalizedBase, modulePathArray, options), requireString = ref3.requireString, absolutePath = ref3.absolutePath;
if (modulePathArray) {
for (j = 0, len = modulePathArray.length; j < len; j++) {
sub = modulePathArray[j];
if (matchingName = ModuleResolver._matchingNameInDirectorySync(sub, absolutePath, options)) {
absolutePath = Path.join(absolutePath, matchingName);
requireString = requireString + "/" + matchingName;
} else {
throw new ErrorWithInfo("Could not find pathed submodule inside npm package.", {
npmPackage: requireString,
localNpmPackageLocation: absolutePath,
submodulePath: sub,
normalized: normalizeName(sub),
dirItems: dirReader.read(absolutePath)
});
}
}
}
return {
requireString: requireString,
absolutePath: absolutePath
};
};
ModuleResolver.findModule = function(moduleName, options) {
return Promise.then(function() {
return ModuleResolver.findModuleSync(moduleName, options);
});
};
maybeCouldHaveCached = {};
ModuleResolver._findModuleBaseSync = function(moduleBaseName, modulePathArray, options) {
var absolutePath, absoluteSourceFilePath, directory, e, matchingName, normalizedModuleName, requireString, shouldContinue, sourceDir, sourceFile, sourceFiles, sourceRoot;
normalizedModuleName = upperCamelCase(moduleBaseName);
if (options) {
sourceFile = options.sourceFile, sourceDir = options.sourceDir, sourceFiles = options.sourceFiles, sourceRoot = options.sourceRoot;
}
sourceFile || (sourceFile = sourceFiles != null ? sourceFiles[0] : void 0);
if (sourceFile || sourceDir) {
directory = sourceDir = dirReader.resolve(sourceDir || Path.dirname(sourceFile));
sourceRoot || (sourceRoot = findSourceRootSync(sourceDir));
sourceRoot = sourceRoot && dirReader.resolve(sourceRoot);
absoluteSourceFilePath = sourceFile && Path.join(sourceDir, Path.parse(sourceFile).name);
}
absolutePath = null;
shouldContinue = present(sourceRoot);
while (shouldContinue) {
if ((matchingName = ModuleResolver._matchingNameInDirectorySync(normalizedModuleName, directory, options)) && absoluteSourceFilePath !== (absolutePath = Path.join(directory, matchingName))) {
shouldContinue = false;
} else {
absolutePath = null;
if (directory === sourceRoot) {
if (normalizedModuleName === normalizeName(peek(sourceRoot.split("/")))) {
absolutePath = sourceRoot;
}
shouldContinue = false;
} else {
directory = Path.dirname(directory);
}
}
}
if (absolutePath) {
requireString = Path.relative(sourceDir, absolutePath);
switch (requireString) {
case "..":
case ".":
requireString = requireString + "/";
}
if (!requireString.match(/^\./)) {
requireString = "./" + requireString;
}
return {
requireString: requireString,
absolutePath: absolutePath
};
} else {
try {
return ModuleResolver.getNpmPackageName(moduleBaseName, modulePathArray);
} catch (error) {
e = error;
if (e.info) {
mergeInto(e.info, {
sourceDir: sourceDir,
sourceRoot: sourceRoot
});
}
throw e;
}
}
};
/*
Notes about "." names-with-dots.
Essentially, dots are treated as word-boundaries.
Files:
We need to manage extensions. Current rule:
Full match example: FooCaf matches foo.caf
PartialMatch must fully match on dot-boundaries:
Foo.BarFood.caf does NOT match FooBar, but does match FooBarFood
PartialMatch must match starting at the first character:
Foo.BarFood.caf does NOT match BarFood but does match Foo
Dirs:
Dirs must fully match:
Art.Foo.Bar matches ArtFooBar BUT NOT ArtFoo
Future:
I'd like to be able to treat "."s in dir-names as-if they were '/' (slashes)
Basically, this parallels how NeptuneNamespaces interprets them.
It should work identically to as-if there were nested dirs.
Given these files:
MyFile1.caf
Foo/Bar/MyFile2.caf
OR these files:
MyFile1.caf
Foo.Bar/MyFile2.caf
Then:
* inside MyFile1.caf
* this works:
&Foo/Bar/MyFile2
*/
ModuleResolver.getMatchingName = getMatchingName = function(normalizedModuleName, name, isDir) {
var foundLegalStop, i, j, len, normalizedTestName, offset, ref2, stop, stops;
if (normalizedModuleName === (normalizedTestName = normalizeName(name))) {
return name;
} else if (!isDir) {
if (0 === normalizedTestName.indexOf(normalizedModuleName)) {
foundLegalStop = false;
offset = 0;
ref2 = stops = name.split('.');
for (i = j = 0, len = ref2.length; j < len; i = ++j) {
stop = ref2[i];
stop = normalizeName(stop);
offset += stop.length;
if (normalizedModuleName.length === offset) {
return stops.slice(0, i + 1).join('.');
}
}
}
return false;
}
};
ModuleResolver._matchingNameInDirectorySync = function(normalizedModuleName, directory, options