保誠-保戶業務員媒合平台
HelenHuang
2022-06-09 9bdb95c9e34cef640534e5e5a1e2225a80442000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"use strict";
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = rewritePaths;
exports.getRelativeUsePath = void 0;
 
var _path = _interopRequireDefault(require("path"));
 
var _logger = _interopRequireDefault(require("./logger"));
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
 
var useRegexp = /@(import|use)\s+(?:'([^']+)'|"([^"]+)"|([^\s;]+))/g;
 
var getRelativeUsePath = function getRelativeUsePath(oldUsePath, absoluteUsePath, moduleContext) {
  // from node_modules
  if (/^~/.test(oldUsePath)) {
    return oldUsePath;
  }
 
  return _path["default"].relative(moduleContext, absoluteUsePath);
};
 
exports.getRelativeUsePath = getRelativeUsePath;
 
function rewritePaths(error, file, contents, moduleContext, callback) {
  if (error) {
    _logger["default"].debug('Resources: **not found**');
 
    return callback(error);
  }
 
  if (!/\.s[ac]ss$/i.test(file)) {
    return callback(null, contents);
  }
 
  var rewritten = contents.replace(useRegexp, function (entire, importer, single, _double, unquoted) {
    // Don't rewrite imports from built-ins
    if ([single, _double].some(function (match) {
      return match && match.indexOf('sass:') === 0;
    })) {
      return entire;
    }
 
    var oldUsePath = single || _double || unquoted;
 
    var absoluteUsePath = _path["default"].join(_path["default"].dirname(file), oldUsePath);
 
    var relUsePath = getRelativeUsePath(oldUsePath, absoluteUsePath, moduleContext);
    var newUsePath = relUsePath.split(_path["default"].sep).join('/');
 
    _logger["default"].debug("Resources: @".concat(importer, " of ").concat(oldUsePath, " changed to ").concat(newUsePath));
 
    var lastCharacter = entire[entire.length - 1];
    var quote = lastCharacter === "'" || lastCharacter === '"' ? lastCharacter : '';
    return "@".concat(importer, " ").concat(quote).concat(newUsePath).concat(quote);
  });
  callback(null, rewritten);
  return undefined;
}