smartinject/dist/index.js

55 lines
4.0 KiB
JavaScript
Raw Normal View History

2017-02-28 22:40:13 +00:00
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global");
let Module = require('module');
const sourceMap = require("source-map-support");
const through2 = require("through2");
sourceMap.install({
retrieveFile: function (path) {
if (cache[path]) {
return cache[path].contents.toString();
}
}
});
let cache = {};
let originalLoader = Module._extensions['.js'];
Module._extensions['.js'] = function (module, filename) {
let file = cache[filename];
if (file) {
module._compile(file.contents.toString(), filename);
}
else {
originalLoader.apply(this, arguments);
}
};
let originalModuleResolve = Module._resolveFilename;
Module._resolveFilename = function (request, parent, isMain) {
let file = cache[request];
if (file) {
return request;
}
else {
return originalModuleResolve.apply(this, arguments);
}
};
exports.gulpPipe = function () {
return through2.obj(function (file, enc, cb) {
cache[file.path] = file;
return cb(null, file);
});
};
exports.injectFileArray = (fileArray) => __awaiter(this, void 0, void 0, function* () {
for (let fileObject of fileArray) {
cache[fileObject.path] = fileObject;
}
return fileArray;
});
2017-07-28 16:19:06 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsMEJBQXVCO0FBRXZCLElBQUksTUFBTSxHQUFHLE9BQU8sQ0FBQyxRQUFRLENBQUMsQ0FBQztBQUUvQixnREFBaUQ7QUFDakQscUNBQXNDO0F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