translate-url-to-sourcemap-paths.js 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. /*
  3. Copyright 2021 Google LLC
  4. Use of this source code is governed by an MIT-style
  5. license that can be found in the LICENSE file or at
  6. https://opensource.org/licenses/MIT.
  7. */
  8. var __importDefault = (this && this.__importDefault) || function (mod) {
  9. return (mod && mod.__esModule) ? mod : { "default": mod };
  10. };
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. exports.translateURLToSourcemapPaths = void 0;
  13. const fs_extra_1 = __importDefault(require("fs-extra"));
  14. const upath_1 = __importDefault(require("upath"));
  15. const errors_1 = require("./errors");
  16. function translateURLToSourcemapPaths(url, swSrc, swDest) {
  17. let destPath = undefined;
  18. let srcPath = undefined;
  19. let warning = undefined;
  20. if (url && !url.startsWith('data:')) {
  21. const possibleSrcPath = upath_1.default.resolve(upath_1.default.dirname(swSrc), url);
  22. if (fs_extra_1.default.existsSync(possibleSrcPath)) {
  23. srcPath = possibleSrcPath;
  24. destPath = upath_1.default.resolve(upath_1.default.dirname(swDest), url);
  25. }
  26. else {
  27. warning = `${errors_1.errors['cant-find-sourcemap']} ${possibleSrcPath}`;
  28. }
  29. }
  30. return { destPath, srcPath, warning };
  31. }
  32. exports.translateURLToSourcemapPaths = translateURLToSourcemapPaths;