relative-to-output-path.js 856 B

123456789101112131415161718192021222324252627282930
  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. const upath = require('upath');
  9. /**
  10. * @param {Object} compilation The webpack compilation.
  11. * @param {string} swDest The original swDest value.
  12. *
  13. * @return {string} If swDest was not absolute, the returns swDest as-is.
  14. * Otherwise, returns swDest relative to the compilation's output path.
  15. *
  16. * @private
  17. */
  18. module.exports = (compilation, swDest) => {
  19. // See https://github.com/jantimon/html-webpack-plugin/pull/266/files#diff-168726dbe96b3ce427e7fedce31bb0bcR38
  20. if (upath.resolve(swDest) === upath.normalize(swDest)) {
  21. return upath.relative(compilation.options.output.path, swDest);
  22. } // Otherwise, return swDest as-is.
  23. return swDest;
  24. };