版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

56 строки
1.6 KiB

  1. import { promises } from 'fs';
  2. import { createUnplugin } from 'unplugin';
  3. import { createFilter } from '@rollup/pluginutils';
  4. import MagicString from 'magic-string';
  5. import { e as createUnimport } from './shared/unimport.7daee659.mjs';
  6. import 'mlly';
  7. import './shared/unimport.5c780d40.mjs';
  8. import 'pathe';
  9. import 'strip-literal';
  10. import 'local-pkg';
  11. import 'os';
  12. import 'pkg-types';
  13. import 'fs/promises';
  14. import 'fast-glob';
  15. import 'scule';
  16. const defaultIncludes = [/\.[jt]sx?$/, /\.vue$/, /\.vue\?vue/, /\.svelte$/];
  17. const defaultExcludes = [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/];
  18. function toArray(x) {
  19. return x == null ? [] : Array.isArray(x) ? x : [x];
  20. }
  21. const unplugin = createUnplugin((options = {}) => {
  22. const ctx = createUnimport(options);
  23. const filter = createFilter(
  24. toArray(options.include || []).length ? options.include : defaultIncludes,
  25. options.exclude || defaultExcludes
  26. );
  27. const dts = options.dts === true ? "unimport.d.ts" : options.dts;
  28. return {
  29. name: "unimport",
  30. enforce: "post",
  31. transformInclude(id) {
  32. return filter(id);
  33. },
  34. async transform(code, id) {
  35. const s = new MagicString(code);
  36. await ctx.injectImports(s, id);
  37. if (!s.hasChanged()) {
  38. return;
  39. }
  40. return {
  41. code: s.toString(),
  42. map: s.generateMap()
  43. };
  44. },
  45. async buildStart() {
  46. await ctx.init();
  47. if (dts) {
  48. return promises.writeFile(dts, await ctx.generateTypeDeclarations(), "utf-8");
  49. }
  50. }
  51. };
  52. });
  53. export { unplugin as default, defaultExcludes, defaultIncludes };