relative-to-output-path.js 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. /*
  3. Copyright 2018 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.relativeToOutputPath = void 0;
  13. const upath_1 = __importDefault(require("upath"));
  14. /**
  15. * @param {Object} compilation The webpack compilation.
  16. * @param {string} swDest The original swDest value.
  17. *
  18. * @return {string} If swDest was not absolute, the returns swDest as-is.
  19. * Otherwise, returns swDest relative to the compilation's output path.
  20. *
  21. * @private
  22. */
  23. function relativeToOutputPath(compilation, swDest) {
  24. // See https://github.com/jantimon/html-webpack-plugin/pull/266/files#diff-168726dbe96b3ce427e7fedce31bb0bcR38
  25. if (upath_1.default.resolve(swDest) === upath_1.default.normalize(swDest)) {
  26. return upath_1.default.relative(compilation.options.output.path, swDest);
  27. }
  28. // Otherwise, return swDest as-is.
  29. return swDest;
  30. }
  31. exports.relativeToOutputPath = relativeToOutputPath;