a zip code crypto-currency system good for red ONLY

loader-impl.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var path_1 = require("path");
  4. var helpers_1 = require("../util/helpers");
  5. var logger_1 = require("../logger/logger");
  6. function webpackLoader(source, map, webpackContex) {
  7. webpackContex.cacheable();
  8. var callback = webpackContex.async();
  9. var context = helpers_1.getContext();
  10. var absolutePath = path_1.resolve(path_1.normalize(webpackContex.resourcePath));
  11. logger_1.Logger.debug("[Webpack] webpackLoader: processing the following file: " + absolutePath);
  12. var javascriptPath = helpers_1.changeExtension(absolutePath, '.js');
  13. var sourceMapPath = javascriptPath + '.map';
  14. Promise.all([
  15. readFile(context.fileCache, javascriptPath),
  16. readFile(context.fileCache, sourceMapPath)
  17. ]).then(function (_a) {
  18. var javascriptFile = _a[0], mapFile = _a[1];
  19. var sourceMapObject = map;
  20. if (mapFile) {
  21. try {
  22. sourceMapObject = JSON.parse(mapFile.content);
  23. }
  24. catch (ex) {
  25. logger_1.Logger.debug("[Webpack] loader: Attempted to parse the JSON sourcemap for " + mapFile.path + " and failed -\n using the original, webpack provided source map");
  26. }
  27. if (sourceMapObject) {
  28. sourceMapObject.sources = [absolutePath];
  29. if (!sourceMapObject.sourcesContent || sourceMapObject.sourcesContent.length === 0) {
  30. sourceMapObject.sourcesContent = [source];
  31. }
  32. }
  33. }
  34. callback(null, javascriptFile.content, sourceMapObject);
  35. }).catch(function (err) {
  36. logger_1.Logger.debug("[Webpack] loader: Encountered an unexpected error: " + err.message);
  37. callback(err);
  38. });
  39. }
  40. exports.webpackLoader = webpackLoader;
  41. function readFile(fileCache, filePath) {
  42. return helpers_1.readAndCacheFile(filePath).then(function (fileContent) {
  43. logger_1.Logger.debug("[Webpack] loader: Loaded " + filePath + " successfully from disk");
  44. return fileCache.get(filePath);
  45. }).catch(function (err) {
  46. logger_1.Logger.debug("[Webpack] loader: Failed to load " + filePath + " from disk");
  47. throw err;
  48. });
  49. }