smartinject/dist/index.js

63 lines
4.8 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();
}
2017-07-28 18:44:24 +00:00
else if (cache[path + '.js']) {
return cache[path + '.js'].contents.toString();
}
2017-02-28 22:40:13 +00:00
}
});
let cache = {};
let originalLoader = Module._extensions['.js'];
Module._extensions['.js'] = function (module, filename) {
let file = cache[filename];
2017-07-28 18:44:24 +00:00
let file2 = cache[filename + '.js'];
2017-02-28 22:40:13 +00:00
if (file) {
module._compile(file.contents.toString(), filename);
}
2017-07-28 18:44:24 +00:00
else if (file2) {
module._compile(file2.contents.toString(), filename);
}
2017-02-28 22:40:13 +00:00
else {
originalLoader.apply(this, arguments);
}
};
let originalModuleResolve = Module._resolveFilename;
Module._resolveFilename = function (request, parent, isMain) {
let file = cache[request];
2017-07-28 18:44:24 +00:00
let file2 = cache[request + '.js'];
if (file || file2) {
2017-02-28 22:40:13 +00:00
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 18:44:24 +00:00
//# sourceMappingURL=data:application/json;base64,ey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