UNPKG

@jpapini/unplugin-deepkit-type

Version:
89 lines (83 loc) 2.69 kB
'use strict'; var path = require('node:path'); var typeCompiler = require('@deepkit/type-compiler'); var ts = require('typescript'); var unplugin$1 = require('unplugin'); var unpluginUtils = require('unplugin-utils'); function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } function _interopNamespace(e) { if (e && e.__esModule) return e; var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n.default = e; return Object.freeze(n); } var path__default = /*#__PURE__*/_interopDefault(path); var ts__namespace = /*#__PURE__*/_interopNamespace(ts); // src/unplugin.ts var unpluginFactory = (options = {}) => { const filter = unpluginUtils.createFilter( options.include ?? /\.(?:m|c)?tsx?$/u, options.exclude ?? "node_modules/**" ); const transformers = options.transformers ?? { before: [typeCompiler.transformer], after: [typeCompiler.declarationTransformer] }; const configFilePath = options.tsConfig ?? path__default.default.resolve("tsconfig.json"); const tsConfig = ts__namespace.readConfigFile( configFilePath, options.readFile ?? ((p) => ts__namespace.sys.readFile(p)) ); if (tsConfig.error) { throw new Error( ts__namespace.formatDiagnostic(tsConfig.error, { getCanonicalFileName: (fileName) => fileName, getCurrentDirectory: () => ts__namespace.sys.getCurrentDirectory(), getNewLine: () => ts__namespace.sys.newLine }) ); } const compilerOptions = { target: ts__namespace.ScriptTarget.ESNext, module: ts__namespace.ModuleKind.ESNext, configFilePath, ...tsConfig.config, ...options.compilerOptions ?? {} }; return { name: "unplugin-deepkit-type", enforce: "pre", transformInclude: (id) => filter(id), transform: (code, fileName) => { const transformed = ts__namespace.transpileModule(code, { compilerOptions, fileName, transformers }); return { code: transformed.outputText, ...transformed.sourceMapText ? { map: transformed.sourceMapText } : {} }; } }; }; var unplugin = /* @__PURE__ */ unplugin$1.createUnplugin(unpluginFactory); var unplugin_default = unplugin; exports.unplugin = unplugin; exports.unpluginFactory = unpluginFactory; exports.unplugin_default = unplugin_default; //# sourceMappingURL=chunk-DQIB3NT6.cjs.map //# sourceMappingURL=chunk-DQIB3NT6.cjs.map