1 | "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }
|
2 | var _pirates = require('pirates'); var pirates = _interopRequireWildcard(_pirates);
|
3 |
|
4 | var _index = require('./index');
|
5 |
|
6 | function addHook(extension, options) {
|
7 | pirates.addHook(
|
8 | (code, filePath) => {
|
9 | const {code: transformedCode, sourceMap} = _index.transform.call(void 0, code, {
|
10 | ...options,
|
11 | sourceMapOptions: {compiledFilename: filePath},
|
12 | filePath,
|
13 | });
|
14 | const mapBase64 = Buffer.from(JSON.stringify(sourceMap)).toString("base64");
|
15 | const suffix = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${mapBase64}`;
|
16 | return `${transformedCode}\n${suffix}`;
|
17 | },
|
18 | {exts: [extension]},
|
19 | );
|
20 | } exports.addHook = addHook;
|
21 |
|
22 | function registerJS() {
|
23 | addHook(".js", {transforms: ["imports", "flow", "jsx"]});
|
24 | } exports.registerJS = registerJS;
|
25 |
|
26 | function registerJSX() {
|
27 | addHook(".jsx", {transforms: ["imports", "flow", "jsx"]});
|
28 | } exports.registerJSX = registerJSX;
|
29 |
|
30 | function registerTS() {
|
31 | addHook(".ts", {transforms: ["imports", "typescript"]});
|
32 | } exports.registerTS = registerTS;
|
33 |
|
34 | function registerTSX() {
|
35 | addHook(".tsx", {transforms: ["imports", "typescript", "jsx"]});
|
36 | } exports.registerTSX = registerTSX;
|
37 |
|
38 | function registerTSLegacyModuleInterop() {
|
39 | addHook(".ts", {
|
40 | transforms: ["imports", "typescript"],
|
41 | enableLegacyTypeScriptModuleInterop: true,
|
42 | });
|
43 | } exports.registerTSLegacyModuleInterop = registerTSLegacyModuleInterop;
|
44 |
|
45 | function registerTSXLegacyModuleInterop() {
|
46 | addHook(".tsx", {
|
47 | transforms: ["imports", "typescript", "jsx"],
|
48 | enableLegacyTypeScriptModuleInterop: true,
|
49 | });
|
50 | } exports.registerTSXLegacyModuleInterop = registerTSXLegacyModuleInterop;
|
51 |
|
52 | function registerAll() {
|
53 | registerJS();
|
54 | registerJSX();
|
55 | registerTS();
|
56 | registerTSX();
|
57 | } exports.registerAll = registerAll;
|