UNPKG

ts-patch

Version:

Patch typescript to support custom transformers in tsconfig.json

38 lines 1.84 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getLiveTypeScriptPath = getLiveTypeScriptPath; exports.getLiveTypeScriptPackage = getLiveTypeScriptPackage; exports.getLiveModule = getLiveModule; const path_1 = __importDefault(require("path")); const ts_module_1 = require("./ts-module"); const ts_package_1 = require("../ts-package"); const get_patched_source_1 = require("../patch/get-patched-source"); const system_1 = require("../system"); // endregion /* ****************************************************************************************************************** */ // region: Utils /* ****************************************************************************************************************** */ function getLiveTypeScriptPath() { return process.env.TSP_COMPILER_TS_PATH ? path_1.default.resolve(process.env.TSP_COMPILER_TS_PATH) : require.resolve('typescript'); } function getLiveTypeScriptPackage() { return (0, ts_package_1.getTsPackage)(getLiveTypeScriptPath()); } function getLiveModule(moduleName, opts) { const skipCache = process.env.TSP_SKIP_CACHE === 'true'; const libraryName = opts?.libraryName ?? String(moduleName).replace(/\.js$/, ''); /* Open the TypeScript module */ const tsPackage = getLiveTypeScriptPackage(); (0, system_1.assertSupportedTypeScript)(tsPackage); const tsModule = (0, ts_module_1.getTsModule)(tsPackage, moduleName, { skipCache }); /* Get patched version */ const { js } = (0, get_patched_source_1.getPatchedSource)(tsModule, { skipCache, skipDts: true, libraryName }); return { js, tsModule }; } // endregion //# sourceMappingURL=get-live-module.js.map