mh-two-thousand-and-two
2024-04-12 7fc6dbf547b8899d949b67cdec36b96a7d1701c7
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
63
64
65
66
67
68
69
70
71
"use strict";
 
const {
  addHook
} = require("pirates");
const sourceMapSupport = require("source-map-support");
let piratesRevert;
const maps = Object.create(null);
function installSourceMapSupport() {
  installSourceMapSupport = () => {};
  sourceMapSupport.install({
    handleUncaughtExceptions: false,
    environment: "node",
    retrieveSourceMap(filename) {
      const map = maps == null ? void 0 : maps[filename];
      if (map) {
        return {
          url: null,
          map: map
        };
      } else {
        return null;
      }
    }
  });
}
{
  const Module = require("module");
  let compiling = false;
  const internalModuleCache = Module._cache;
  var compileBabel7 = function compileBabel7(client, code, filename) {
    if (!client.isLocalClient) return compile(client, code, filename);
    if (compiling) return code;
    const globalModuleCache = Module._cache;
    try {
      compiling = true;
      Module._cache = internalModuleCache;
      return compile(client, code, filename);
    } finally {
      compiling = false;
      Module._cache = globalModuleCache;
    }
  };
}
function compile(client, inputCode, filename) {
  const result = client.transform(inputCode, filename);
  if (result === null) return inputCode;
  const {
    code,
    map
  } = result;
  if (map) {
    maps[filename] = map;
    installSourceMapSupport();
  }
  return code;
}
exports.register = function register(client, opts = {}) {
  var _opts$extensions;
  if (piratesRevert) piratesRevert();
  piratesRevert = addHook(compileBabel7.bind(null, client), {
    exts: (_opts$extensions = opts.extensions) != null ? _opts$extensions : client.getDefaultExtensions(),
    ignoreNodeModules: false
  });
  client.setOptions(opts);
};
exports.revert = function revert() {
  if (piratesRevert) piratesRevert();
};
 
//# sourceMappingURL=hook.js.map