'use strict'; const Unimport = require('unimport/unplugin'); const fs = require('fs'); const pkgTypes = require('pkg-types'); const consola = require('consola'); function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; } const Unimport__default = /*#__PURE__*/_interopDefaultCompat(Unimport); const fs__default = /*#__PURE__*/_interopDefaultCompat(fs); const removeEmptyDirectory = (dir) => { if (dir === "") { return; } if (fs__default.existsSync(dir)) { let files = fs__default.readdirSync(dir); if (files.length === 0) { fs__default.rmdirSync(dir); removeEmptyDirectory(dir.split("/").slice(0, -1).join("/")); } } }; const createSimpleOptions = async (options = {}) => { let defaultDirectory = "node_modules/@types/codegen/imports/import.ds.ts"; let isTS = false; let tsConfigPath = void 0; try { tsConfigPath = await pkgTypes.resolveTSConfig(); defaultDirectory = "codegen/imports/imports.d.ts"; isTS = true; } catch (e) { } const { typeDefinitions = defaultDirectory, packages = [], dirs = [], disableReactHookImport } = options; const dts_directory = typeDefinitions.split("/").slice(0, -1).join("/"); if (dts_directory) { if (fs__default.existsSync(typeDefinitions)) { fs__default.rmSync(typeDefinitions); } removeEmptyDirectory(dts_directory); fs__default.mkdirSync(dts_directory, { recursive: true }); } let defaultPresets = []; if (!disableReactHookImport) { defaultPresets = ["react"]; } if (!isTS) { consola.consola.info(`Adding type definitions file to ${typeDefinitions}. `); } else { const tsconfig = await pkgTypes.readTSConfig(); if (!tsconfig.include?.includes(typeDefinitions)) { consola.consola.warn(`You need to add the typedefinitions file to your tsconfig.json file to get editor support for the auto-imported packages.`); const resp = await consola.consola.prompt(`Do you want to add the include to your tsconfig.json file automatically?`, { type: "confirm" }); if (resp) { if (tsconfig.include !== void 0) { tsconfig.include?.push(typeDefinitions); } else { tsconfig.include = [typeDefinitions]; } pkgTypes.writeTSConfig(tsConfigPath, tsconfig); } else { consola.consola.warn(`Please add the following line to your tsconfig.json file to get editor support for the auto-imported packages: "include": ["${typeDefinitions}"] `); } } } return { dts: typeDefinitions, presets: [...defaultPresets, ...packages], dirs }; }; const createReactUnimportPlugin = async (options) => { if (!options) { options = await createSimpleOptions(); } return Unimport__default.vite(options); }; exports.createReactUnimportPlugin = createReactUnimportPlugin; exports.createSimpleOptions = createSimpleOptions;