resolve-import-url.js 1005 B

12345678910111213141516171819202122
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.resolveImportUrl = void 0;
  4. const tslib_1 = require("tslib");
  5. const path_1 = (0, tslib_1.__importDefault)(require("path"));
  6. const regex = /@(?:import|require)\s+(?:\([a-z,\s]+\)\s*)?['"]?([^'"\s;]+)['"]?;?/gu;
  7. const resolveImportUrl = (ctx, { file, content }) => ({
  8. file,
  9. content: content.replace(regex, (match, pathToResource) => {
  10. if (!pathToResource || /^[~/]/u.test(pathToResource)) {
  11. return match;
  12. }
  13. const absolutePathToResource = path_1.default.resolve(path_1.default.dirname(file), pathToResource);
  14. const relativePathFromContextToResource = path_1.default
  15. .relative(ctx.context, absolutePathToResource)
  16. .split(path_1.default.sep)
  17. .join('/');
  18. return match.replace(pathToResource, relativePathFromContextToResource);
  19. }),
  20. });
  21. exports.resolveImportUrl = resolveImportUrl;
  22. //# sourceMappingURL=resolve-import-url.js.map