knip 6.25.0 → 6.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/dist/ConfigurationChief.d.ts +108 -0
  2. package/dist/DependencyDeputy.d.ts +1 -1
  3. package/dist/DependencyDeputy.js +2 -2
  4. package/dist/ProjectPrincipal.d.ts +3 -3
  5. package/dist/ProjectPrincipal.js +4 -4
  6. package/dist/binaries/fallback.js +5 -1
  7. package/dist/binaries/resolvers/bun.js +13 -5
  8. package/dist/binaries/resolvers/npm.js +4 -2
  9. package/dist/binaries/resolvers/pnpm.js +11 -1
  10. package/dist/binaries/resolvers/yarn.js +10 -4
  11. package/dist/binaries/util.d.ts +4 -0
  12. package/dist/binaries/util.js +14 -0
  13. package/dist/compilers/index.d.ts +180 -0
  14. package/dist/compilers/less.js +1 -1
  15. package/dist/compilers/scss.js +1 -1
  16. package/dist/compilers/stylus.js +1 -1
  17. package/dist/constants.js +19 -0
  18. package/dist/graph/analyze.js +1 -1
  19. package/dist/graph/build.js +24 -7
  20. package/dist/plugins/_vue/auto-import.d.ts +12 -0
  21. package/dist/plugins/_vue/auto-import.js +332 -0
  22. package/dist/plugins/_vue/types.d.ts +45 -0
  23. package/dist/plugins/_vue/types.js +1 -0
  24. package/dist/plugins/astro/index.js +2 -37
  25. package/dist/plugins/astro/resolveFromAST.d.ts +4 -4
  26. package/dist/plugins/astro/resolveFromAST.js +34 -7
  27. package/dist/plugins/electron-vite/index.d.ts +3 -0
  28. package/dist/plugins/electron-vite/index.js +51 -0
  29. package/dist/plugins/electron-vite/types.d.ts +23 -0
  30. package/dist/plugins/electron-vite/types.js +1 -0
  31. package/dist/plugins/esbuild/index.d.ts +3 -0
  32. package/dist/plugins/esbuild/index.js +17 -0
  33. package/dist/plugins/eslint/resolveFromAST.js +18 -21
  34. package/dist/plugins/index.d.ts +18 -0
  35. package/dist/plugins/index.js +36 -0
  36. package/dist/plugins/laravel-vite-plugin/index.d.ts +3 -0
  37. package/dist/plugins/laravel-vite-plugin/index.js +14 -0
  38. package/dist/plugins/laravel-vite-plugin/resolveFromAST.d.ts +2 -0
  39. package/dist/plugins/laravel-vite-plugin/resolveFromAST.js +27 -0
  40. package/dist/plugins/next/index.js +2 -2
  41. package/dist/plugins/next-mdx/index.js +2 -8
  42. package/dist/plugins/next-mdx/resolveFromAST.d.ts +3 -2
  43. package/dist/plugins/next-mdx/resolveFromAST.js +17 -21
  44. package/dist/plugins/nuxt/index.js +5 -68
  45. package/dist/plugins/nuxt/types.d.ts +0 -34
  46. package/dist/plugins/nuxtjs-i18n/index.d.ts +3 -0
  47. package/dist/plugins/nuxtjs-i18n/index.js +12 -0
  48. package/dist/plugins/oclif/index.js +10 -5
  49. package/dist/plugins/orval/index.js +1 -3
  50. package/dist/plugins/orval/resolveFromAST.d.ts +2 -2
  51. package/dist/plugins/orval/resolveFromAST.js +4 -7
  52. package/dist/plugins/oxlint/index.js +23 -2
  53. package/dist/plugins/pnpm/index.js +2 -1
  54. package/dist/plugins/pnpm/types.d.ts +2 -4
  55. package/dist/plugins/quasar/index.d.ts +3 -0
  56. package/dist/plugins/quasar/index.js +15 -0
  57. package/dist/plugins/quasar/resolveFromAST.d.ts +3 -0
  58. package/dist/plugins/quasar/resolveFromAST.js +63 -0
  59. package/dist/plugins/qwik/index.js +1 -25
  60. package/dist/plugins/qwik/resolveFromAST.d.ts +5 -3
  61. package/dist/plugins/qwik/resolveFromAST.js +28 -9
  62. package/dist/plugins/react-email/index.js +1 -0
  63. package/dist/plugins/rolldown/index.js +2 -5
  64. package/dist/plugins/rollup/index.js +2 -5
  65. package/dist/plugins/rslib/index.js +2 -5
  66. package/dist/plugins/sst/index.js +1 -5
  67. package/dist/plugins/sst/resolveFromAST.d.ts +1 -1
  68. package/dist/plugins/sst/resolveFromAST.js +1 -1
  69. package/dist/plugins/starlight/index.js +1 -19
  70. package/dist/plugins/starlight/resolveFromAST.d.ts +2 -2
  71. package/dist/plugins/starlight/resolveFromAST.js +12 -8
  72. package/dist/plugins/stencil/index.js +2 -37
  73. package/dist/plugins/stencil/resolveFromAST.d.ts +3 -0
  74. package/dist/plugins/stencil/resolveFromAST.js +36 -0
  75. package/dist/plugins/storybook/index.js +3 -0
  76. package/dist/plugins/sveltekit/index.js +1 -48
  77. package/dist/plugins/sveltekit/resolveFromAST.d.ts +2 -0
  78. package/dist/plugins/sveltekit/resolveFromAST.js +45 -0
  79. package/dist/plugins/tailwind/compiler.js +9 -4
  80. package/dist/plugins/tanstack-router/index.js +3 -1
  81. package/dist/plugins/tauri/index.d.ts +3 -0
  82. package/dist/plugins/tauri/index.js +42 -0
  83. package/dist/plugins/tauri/types.d.ts +16 -0
  84. package/dist/plugins/tauri/types.js +1 -0
  85. package/dist/plugins/temporal/index.d.ts +3 -0
  86. package/dist/plugins/temporal/index.js +12 -0
  87. package/dist/plugins/tsdown/index.js +16 -7
  88. package/dist/plugins/tsdown/types.d.ts +4 -1
  89. package/dist/plugins/tsup/index.js +2 -5
  90. package/dist/plugins/unplugin-auto-import/index.d.ts +3 -0
  91. package/dist/plugins/unplugin-auto-import/index.js +18 -0
  92. package/dist/plugins/unplugin-icons/index.d.ts +3 -0
  93. package/dist/plugins/unplugin-icons/index.js +17 -0
  94. package/dist/plugins/unplugin-vue-components/index.d.ts +3 -0
  95. package/dist/plugins/unplugin-vue-components/index.js +16 -0
  96. package/dist/plugins/unplugin-vue-i18n/index.d.ts +3 -0
  97. package/dist/plugins/unplugin-vue-i18n/index.js +10 -0
  98. package/dist/plugins/unplugin-vue-markdown/index.d.ts +3 -0
  99. package/dist/plugins/unplugin-vue-markdown/index.js +16 -0
  100. package/dist/plugins/unplugin-vue-router/index.d.ts +3 -0
  101. package/dist/plugins/unplugin-vue-router/index.js +14 -0
  102. package/dist/plugins/vite/helpers.d.ts +2 -0
  103. package/dist/plugins/vite/helpers.js +46 -31
  104. package/dist/plugins/vite/index.js +1 -1
  105. package/dist/plugins/vite-plugin-pages/index.d.ts +3 -0
  106. package/dist/plugins/vite-plugin-pages/index.js +26 -0
  107. package/dist/plugins/vite-plugin-pwa/index.d.ts +3 -0
  108. package/dist/plugins/vite-plugin-pwa/index.js +17 -0
  109. package/dist/plugins/vite-plugin-pwa/resolveFromAST.d.ts +4 -0
  110. package/dist/plugins/vite-plugin-pwa/resolveFromAST.js +37 -0
  111. package/dist/plugins/vite-plugin-vue-layouts-next/index.d.ts +3 -0
  112. package/dist/plugins/vite-plugin-vue-layouts-next/index.js +23 -0
  113. package/dist/plugins/vite-plus/index.d.ts +3 -0
  114. package/dist/plugins/vite-plus/index.js +14 -0
  115. package/dist/plugins/vite-plus/resolveFromAST.d.ts +2 -0
  116. package/dist/plugins/vite-plus/resolveFromAST.js +37 -0
  117. package/dist/plugins/vite-pwa-assets-generator/index.d.ts +3 -0
  118. package/dist/plugins/vite-pwa-assets-generator/index.js +12 -0
  119. package/dist/plugins/vitepress/index.js +5 -1
  120. package/dist/plugins/vitest/index.js +19 -0
  121. package/dist/plugins/vitest/types.d.ts +8 -0
  122. package/dist/plugins/vue/index.js +5 -3
  123. package/dist/plugins/yarn/index.js +2 -1
  124. package/dist/plugins/yarn/types.d.ts +2 -4
  125. package/dist/run.js +3 -3
  126. package/dist/schema/configuration.d.ts +270 -0
  127. package/dist/schema/plugins.d.ts +90 -0
  128. package/dist/schema/plugins.js +18 -0
  129. package/dist/types/PluginNames.d.ts +2 -2
  130. package/dist/types/PluginNames.js +18 -0
  131. package/dist/types/config.d.ts +1 -0
  132. package/dist/types/package-json.d.ts +8 -4
  133. package/dist/typescript/ast-helpers.d.ts +7 -2
  134. package/dist/typescript/ast-helpers.js +36 -8
  135. package/dist/typescript/ast-nodes.d.ts +2 -0
  136. package/dist/typescript/ast-nodes.js +8 -0
  137. package/dist/typescript/get-imports-and-exports.js +8 -5
  138. package/dist/typescript/resolve-module-names.d.ts +2 -2
  139. package/dist/typescript/resolve-module-names.js +97 -18
  140. package/dist/typescript/visitors/walk.d.ts +2 -1
  141. package/dist/typescript/visitors/walk.js +13 -2
  142. package/dist/util/cli-arguments.d.ts +1 -1
  143. package/dist/util/cli-arguments.js +1 -1
  144. package/dist/util/create-input-handler.js +8 -1
  145. package/dist/util/create-options.d.ts +180 -0
  146. package/dist/util/package-json.d.ts +7 -0
  147. package/dist/util/package-json.js +37 -0
  148. package/dist/util/resolve.d.ts +1 -0
  149. package/dist/util/resolve.js +5 -2
  150. package/dist/util/to-source-path.d.ts +4 -3
  151. package/dist/util/to-source-path.js +23 -6
  152. package/dist/version.d.ts +1 -1
  153. package/dist/version.js +1 -1
  154. package/package.json +1 -1
  155. package/schema.json +72 -0
  156. package/dist/plugins/next/resolveFromAST.d.ts +0 -2
  157. package/dist/plugins/next/resolveFromAST.js +0 -2
  158. package/dist/plugins/nuxt/helpers.d.ts +0 -15
  159. package/dist/plugins/nuxt/helpers.js +0 -133
  160. package/dist/plugins/rolldown/resolveFromAST.d.ts +0 -2
  161. package/dist/plugins/rolldown/resolveFromAST.js +0 -4
  162. package/dist/plugins/rollup/resolveFromAST.d.ts +0 -2
  163. package/dist/plugins/rollup/resolveFromAST.js +0 -4
  164. package/dist/plugins/rslib/resolveFromAST.d.ts +0 -2
  165. package/dist/plugins/rslib/resolveFromAST.js +0 -4
  166. package/dist/plugins/tsdown/resolveFromAST.d.ts +0 -2
  167. package/dist/plugins/tsdown/resolveFromAST.js +0 -4
  168. package/dist/plugins/tsup/resolveFromAST.d.ts +0 -2
  169. package/dist/plugins/tsup/resolveFromAST.js +0 -4
  170. package/dist/plugins/vue/compiler.d.ts +0 -3
  171. package/dist/plugins/vue/compiler.js +0 -10
@@ -2,11 +2,12 @@ import type { SourceMap } from '../types/config.ts';
2
2
  import type { CompilerOptions } from '../types/project.ts';
3
3
  import type { ConfigurationChief, Workspace } from '../ConfigurationChief.ts';
4
4
  export declare const augmentWorkspace: (workspace: Workspace, dir: string, compilerOptions: CompilerOptions | undefined, pluginSourceMaps?: SourceMap[]) => void;
5
- export type WorkspaceManifestHandler = (filePath: string) => {
5
+ export type WorkspacePackageTargetHandler = (specifier: string, filePath: string) => {
6
6
  dir: string;
7
- imports: unknown;
7
+ target: unknown;
8
+ patternMatch?: string;
8
9
  } | undefined;
9
- export declare const getWorkspaceManifestHandler: (chief: ConfigurationChief) => WorkspaceManifestHandler;
10
+ export declare const getWorkspacePackageTargetHandler: (chief: ConfigurationChief) => WorkspacePackageTargetHandler;
10
11
  export declare const getModuleSourcePathHandler: (chief: ConfigurationChief) => (filePath: string) => string | undefined;
11
12
  export declare const getToSourcePathsHandler: (chief: ConfigurationChief) => (specifiers: Set<string>, dir: string, extensions: string | undefined, label: string) => Promise<string[]>;
12
13
  export declare const toSourceMappedSpecifiers: (ws: Workspace | undefined, absSpecifier: string, extensions?: string) => string[];
@@ -2,6 +2,8 @@ import { DEFAULT_EXTENSIONS } from '../constants.js';
2
2
  import { debugLog, debugLogArray } from './debug.js';
3
3
  import { findFileWithExtensions, isDirectory } from './fs.js';
4
4
  import { _glob, prependDirToPattern } from './glob.js';
5
+ import { getPackageNameFromModuleSpecifier } from './modules.js';
6
+ import { getPackageMapTarget } from './package-json.js';
5
7
  import { isAbsolute, isInternal, join, toRelative } from './path.js';
6
8
  const defaultExtensions = `.{${[...DEFAULT_EXTENSIONS].map(ext => ext.slice(1)).join(',')}}`;
7
9
  const hasTSExt = /(?<!\.d)\.(m|c)?tsx?$/;
@@ -41,15 +43,30 @@ const rewritePattern = (sourceMaps, absSpecifier, extensions) => {
41
43
  return r;
42
44
  }
43
45
  };
44
- export const getWorkspaceManifestHandler = (chief) => {
45
- return (filePath) => {
46
- const workspace = chief.findWorkspaceByFilePath(filePath);
46
+ export const getWorkspacePackageTargetHandler = (chief) => {
47
+ return (specifier, filePath) => {
48
+ const isImports = specifier.startsWith('#');
49
+ let workspace;
50
+ let key = specifier;
51
+ if (isImports) {
52
+ workspace = chief.findWorkspaceByFilePath(filePath);
53
+ }
54
+ else {
55
+ const packageName = getPackageNameFromModuleSpecifier(specifier);
56
+ if (!packageName)
57
+ return;
58
+ workspace = chief.workspacesByPkgName.get(packageName);
59
+ key = packageName === specifier ? '.' : `.${specifier.slice(packageName.length)}`;
60
+ }
47
61
  if (!workspace)
48
62
  return;
49
63
  const manifest = chief.workspacePackages.get(workspace.name)?.manifest;
50
- if (!manifest?.imports)
64
+ const map = isImports ? manifest?.imports : manifest?.exports;
65
+ if (!manifest || !map)
51
66
  return;
52
- return { dir: workspace.dir, imports: manifest.imports };
67
+ const result = getPackageMapTarget(map, key);
68
+ if (result)
69
+ return { dir: workspace.dir, ...result };
53
70
  };
54
71
  };
55
72
  export const getModuleSourcePathHandler = (chief) => {
@@ -87,7 +104,7 @@ export const getToSourcePathsHandler = (chief) => {
87
104
  const mapped = ws?.sourceMaps && rewritePattern(ws.sourceMaps, absSpecifier, extensions);
88
105
  patterns.add(mapped ?? absSpecifier);
89
106
  }
90
- const filePaths = await _glob({ patterns: Array.from(patterns), cwd: dir, label });
107
+ const filePaths = await _glob({ patterns: Array.from(patterns), cwd: chief.cwd, dir, label });
91
108
  debugLogArray(toRelative(dir, chief.cwd), 'Source mapping (package.json)', filePaths);
92
109
  return filePaths;
93
110
  };
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "6.25.0";
1
+ export declare const version = "6.27.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '6.25.0';
1
+ export const version = '6.27.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "6.25.0",
3
+ "version": "6.27.0",
4
4
  "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
5
5
  "keywords": [
6
6
  "analysis",
package/schema.json CHANGED
@@ -506,10 +506,18 @@
506
506
  "title": "Drizzle plugin configuration (https://knip.dev/reference/plugins/drizzle)",
507
507
  "$ref": "#/definitions/plugin"
508
508
  },
509
+ "electron-vite": {
510
+ "title": "electron-vite plugin configuration (https://knip.dev/reference/plugins/electron-vite)",
511
+ "$ref": "#/definitions/plugin"
512
+ },
509
513
  "eleventy": {
510
514
  "title": "eleventy plugin configuration (https://knip.dev/reference/plugins/eleventy)",
511
515
  "$ref": "#/definitions/plugin"
512
516
  },
517
+ "esbuild": {
518
+ "title": "esbuild plugin configuration (https://knip.dev/reference/plugins/esbuild)",
519
+ "$ref": "#/definitions/plugin"
520
+ },
513
521
  "eslint": {
514
522
  "title": "ESLint plugin configuration (https://knip.dev/reference/plugins/eslint)",
515
523
  "$ref": "#/definitions/plugin"
@@ -582,6 +590,10 @@
582
590
  "title": "ladle plugin configuration (https://knip.dev/reference/plugins/ladle)",
583
591
  "$ref": "#/definitions/plugin"
584
592
  },
593
+ "laravel-vite-plugin": {
594
+ "title": "laravel-vite-plugin plugin configuration (https://knip.dev/reference/plugins/laravel-vite-plugin)",
595
+ "$ref": "#/definitions/plugin"
596
+ },
585
597
  "lefthook": {
586
598
  "title": "lefthook plugin configuration (https://knip.dev/reference/plugins/lefthook)",
587
599
  "$ref": "#/definitions/plugin"
@@ -694,6 +706,10 @@
694
706
  "title": "Nuxt plugin configuration (https://knip.dev/reference/plugins/nuxt)",
695
707
  "$ref": "#/definitions/plugin"
696
708
  },
709
+ "nuxtjs-i18n": {
710
+ "title": "nuxtjs-i18n plugin configuration (https://knip.dev/reference/plugins/nuxtjs-i18n)",
711
+ "$ref": "#/definitions/plugin"
712
+ },
697
713
  "nx": {
698
714
  "title": "Nx plugin configuration (https://knip.dev/reference/plugins/nx)",
699
715
  "$ref": "#/definitions/plugin"
@@ -770,6 +786,10 @@
770
786
  "title": "Prisma plugin configuration (https://knip.dev/reference/plugins/prisma)",
771
787
  "$ref": "#/definitions/plugin"
772
788
  },
789
+ "quasar": {
790
+ "title": "quasar plugin configuration (https://knip.dev/reference/plugins/quasar)",
791
+ "$ref": "#/definitions/plugin"
792
+ },
773
793
  "qwik": {
774
794
  "title": "qwik plugin configuration (https://knip.dev/reference/plugins/qwik)",
775
795
  "$ref": "#/definitions/plugin"
@@ -918,6 +938,14 @@
918
938
  "title": "taskfile plugin configuration (https://knip.dev/reference/plugins/taskfile)",
919
939
  "$ref": "#/definitions/plugin"
920
940
  },
941
+ "tauri": {
942
+ "title": "tauri plugin configuration (https://knip.dev/reference/plugins/tauri)",
943
+ "$ref": "#/definitions/plugin"
944
+ },
945
+ "temporal": {
946
+ "title": "temporal plugin configuration (https://knip.dev/reference/plugins/temporal)",
947
+ "$ref": "#/definitions/plugin"
948
+ },
921
949
  "travis": {
922
950
  "title": "travis plugin configuration (https://knip.dev/reference/plugins/travis)",
923
951
  "$ref": "#/definitions/plugin"
@@ -954,6 +982,30 @@
954
982
  "title": "unocss plugin configuration (https://knip.dev/reference/plugins/unocss)",
955
983
  "$ref": "#/definitions/plugin"
956
984
  },
985
+ "unplugin-auto-import": {
986
+ "title": "unplugin-auto-import plugin configuration (https://knip.dev/reference/plugins/unplugin-auto-import)",
987
+ "$ref": "#/definitions/plugin"
988
+ },
989
+ "unplugin-icons": {
990
+ "title": "unplugin-icons plugin configuration (https://knip.dev/reference/plugins/unplugin-icons)",
991
+ "$ref": "#/definitions/plugin"
992
+ },
993
+ "unplugin-vue-components": {
994
+ "title": "unplugin-vue-components plugin configuration (https://knip.dev/reference/plugins/unplugin-vue-components)",
995
+ "$ref": "#/definitions/plugin"
996
+ },
997
+ "unplugin-vue-i18n": {
998
+ "title": "unplugin-vue-i18n plugin configuration (https://knip.dev/reference/plugins/unplugin-vue-i18n)",
999
+ "$ref": "#/definitions/plugin"
1000
+ },
1001
+ "unplugin-vue-markdown": {
1002
+ "title": "unplugin-vue-markdown plugin configuration (https://knip.dev/reference/plugins/unplugin-vue-markdown)",
1003
+ "$ref": "#/definitions/plugin"
1004
+ },
1005
+ "unplugin-vue-router": {
1006
+ "title": "unplugin-vue-router plugin configuration (https://knip.dev/reference/plugins/unplugin-vue-router)",
1007
+ "$ref": "#/definitions/plugin"
1008
+ },
957
1009
  "vercel": {
958
1010
  "title": "vercel plugin configuration (https://knip.dev/reference/plugins/vercel)",
959
1011
  "$ref": "#/definitions/plugin"
@@ -970,6 +1022,26 @@
970
1022
  "title": "vite plugin configuration (https://knip.dev/reference/plugins/vite)",
971
1023
  "$ref": "#/definitions/plugin"
972
1024
  },
1025
+ "vite-plugin-pages": {
1026
+ "title": "vite-plugin-pages plugin configuration (https://knip.dev/reference/plugins/vite-plugin-pages)",
1027
+ "$ref": "#/definitions/plugin"
1028
+ },
1029
+ "vite-plugin-pwa": {
1030
+ "title": "vite-plugin-pwa plugin configuration (https://knip.dev/reference/plugins/vite-plugin-pwa)",
1031
+ "$ref": "#/definitions/plugin"
1032
+ },
1033
+ "vite-plugin-vue-layouts-next": {
1034
+ "title": "vite-plugin-vue-layouts-next plugin configuration (https://knip.dev/reference/plugins/vite-plugin-vue-layouts-next)",
1035
+ "$ref": "#/definitions/plugin"
1036
+ },
1037
+ "vite-plus": {
1038
+ "title": "vite-plus plugin configuration (https://knip.dev/reference/plugins/vite-plus)",
1039
+ "$ref": "#/definitions/plugin"
1040
+ },
1041
+ "vite-pwa-assets-generator": {
1042
+ "title": "vite-pwa-assets-generator plugin configuration (https://knip.dev/reference/plugins/vite-pwa-assets-generator)",
1043
+ "$ref": "#/definitions/plugin"
1044
+ },
973
1045
  "vitepress": {
974
1046
  "title": "vitepress plugin configuration (https://knip.dev/reference/plugins/vitepress)",
975
1047
  "$ref": "#/definitions/plugin"
@@ -1,2 +0,0 @@
1
- import type { Program } from 'oxc-parser';
2
- export declare const getPageExtensions: (program: Program) => string[];
@@ -1,2 +0,0 @@
1
- import { collectPropertyValues } from '../../typescript/ast-helpers.js';
2
- export const getPageExtensions = (program) => Array.from(collectPropertyValues(program, 'pageExtensions'));
@@ -1,15 +0,0 @@
1
- import { type ParseResult } from 'oxc-parser';
2
- import type { TemplateAstNode, VueSfc } from './types.ts';
3
- export declare const getVueSfc: (cwd: string) => VueSfc;
4
- export declare const readAndParseFile: (filePath: string) => ParseResult;
5
- export declare const collectIdentifiers: (source: string, fileName: string) => Set<string>;
6
- export declare const collectTemplateInfo: (tree: TemplateAstNode) => {
7
- tags: Set<string>;
8
- identifiers: Set<string>;
9
- };
10
- export declare const toKebabCase: (s: string) => string;
11
- export declare const collectLocalImportPaths: (filePath: string, result: ParseResult) => Set<string>;
12
- export declare function buildAutoImportMap(filePath: string, result: ParseResult): {
13
- importMap: Map<string, string>;
14
- componentMap: Map<string, string[]>;
15
- };
@@ -1,133 +0,0 @@
1
- import { readFileSync } from 'node:fs';
2
- import { createRequire } from 'node:module';
3
- import { Visitor } from 'oxc-parser';
4
- import { scriptBodies } from '../../compilers/compilers.js';
5
- import { _parseFile } from '../../typescript/ast-nodes.js';
6
- import { basename, dirname, isInNodeModules, join } from '../../util/path.js';
7
- export const getVueSfc = (cwd) => {
8
- try {
9
- return createRequire(join(cwd, 'package.json'))('vue/compiler-sfc');
10
- }
11
- catch { }
12
- return {
13
- parse: (source, path) => ({
14
- descriptor: { script: { content: scriptBodies(source, path) }, scriptSetup: null, template: { content: '' } },
15
- }),
16
- };
17
- };
18
- const readFile = (filePath) => {
19
- try {
20
- return readFileSync(filePath, 'utf8');
21
- }
22
- catch {
23
- return '';
24
- }
25
- };
26
- export const readAndParseFile = (filePath) => _parseFile(filePath, readFile(filePath));
27
- export const collectIdentifiers = (source, fileName) => {
28
- const identifiers = new Set();
29
- const visitor = new Visitor({
30
- Identifier(node) {
31
- identifiers.add(node.name);
32
- },
33
- });
34
- visitor.visit(_parseFile(fileName, source).program);
35
- return identifiers;
36
- };
37
- export const collectTemplateInfo = (tree) => {
38
- const tags = new Set();
39
- const identifiers = new Set();
40
- const addExprIdentifiers = (expr) => {
41
- for (const id of collectIdentifiers(expr, 'expr.ts'))
42
- identifiers.add(id);
43
- };
44
- const visit = (node) => {
45
- if (node.tag)
46
- tags.add(node.tag);
47
- if (node.type === 5 && node.content && !node.content.isStatic)
48
- addExprIdentifiers(node.content.content);
49
- if (node.props) {
50
- for (const prop of node.props) {
51
- if (prop.type === 7) {
52
- if (prop.exp && !prop.exp.isStatic)
53
- addExprIdentifiers(prop.exp.content);
54
- if (prop.arg && !prop.arg.isStatic)
55
- addExprIdentifiers(prop.arg.content);
56
- }
57
- }
58
- }
59
- if (node.children)
60
- for (const child of node.children)
61
- visit(child);
62
- };
63
- visit(tree);
64
- return { tags, identifiers };
65
- };
66
- export const toKebabCase = (s) => s.replace(/[A-Z]/g, (m, i) => (i ? '-' : '') + m.toLowerCase());
67
- const isLocalSpecifier = (specifier) => specifier.startsWith('.') && !isInNodeModules(specifier);
68
- export const collectLocalImportPaths = (filePath, result) => {
69
- const dir = dirname(filePath);
70
- const paths = new Set();
71
- const visitor = new Visitor({
72
- TSImportType(node) {
73
- const specifier = node.source.value;
74
- if (isLocalSpecifier(specifier))
75
- paths.add(join(dir, specifier));
76
- },
77
- });
78
- visitor.visit(result.program);
79
- return paths;
80
- };
81
- export function buildAutoImportMap(filePath, result) {
82
- const dir = dirname(filePath);
83
- const isComponents = basename(filePath) === 'components.d.ts';
84
- const importMap = new Map();
85
- const componentMap = new Map();
86
- const importTypes = [];
87
- const collectVisitor = new Visitor({
88
- TSImportType(node) {
89
- importTypes.push({ start: node.start, end: node.end, specifier: node.source.value });
90
- },
91
- });
92
- collectVisitor.visit(result.program);
93
- const matchVisitor = new Visitor({
94
- VariableDeclarator(node) {
95
- if (node.id?.type !== 'Identifier')
96
- return;
97
- const name = node.id.name;
98
- if (name.startsWith('Lazy'))
99
- return;
100
- const importType = importTypes.find(it => it.start >= node.start && it.end <= node.end);
101
- if (!importType)
102
- return;
103
- if (!isLocalSpecifier(importType.specifier))
104
- return;
105
- const absSpecifier = join(dir, importType.specifier);
106
- if (isComponents) {
107
- const components = componentMap.get(name);
108
- if (components)
109
- components.push(absSpecifier);
110
- else
111
- componentMap.set(name, [absSpecifier]);
112
- }
113
- else {
114
- importMap.set(name, absSpecifier);
115
- }
116
- },
117
- ExportNamedDeclaration(node) {
118
- if (!node.source)
119
- return;
120
- const specifier = node.source.value;
121
- if (!isLocalSpecifier(specifier))
122
- return;
123
- const absSpecifier = join(dir, specifier);
124
- for (const s of node.specifiers) {
125
- const name = s.exported.type === 'Identifier' ? s.exported.name : s.exported.value;
126
- if (name)
127
- importMap.set(name, absSpecifier);
128
- }
129
- },
130
- });
131
- matchVisitor.visit(result.program);
132
- return { importMap, componentMap };
133
- }
@@ -1,2 +0,0 @@
1
- import type { Program } from 'oxc-parser';
2
- export declare const getInputFromAST: (program: Program) => Set<string>;
@@ -1,4 +0,0 @@
1
- import { collectPropertyValues } from '../../typescript/ast-helpers.js';
2
- export const getInputFromAST = (program) => {
3
- return collectPropertyValues(program, 'input');
4
- };
@@ -1,2 +0,0 @@
1
- import type { Program } from 'oxc-parser';
2
- export declare const getInputFromAST: (program: Program) => Set<string>;
@@ -1,4 +0,0 @@
1
- import { collectPropertyValues } from '../../typescript/ast-helpers.js';
2
- export const getInputFromAST = (program) => {
3
- return collectPropertyValues(program, 'input');
4
- };
@@ -1,2 +0,0 @@
1
- import type { Program } from 'oxc-parser';
2
- export declare const getEntryFromAST: (program: Program) => Set<string>;
@@ -1,4 +0,0 @@
1
- import { collectPropertyValues } from '../../typescript/ast-helpers.js';
2
- export const getEntryFromAST = (program) => {
3
- return collectPropertyValues(program, 'entry');
4
- };
@@ -1,2 +0,0 @@
1
- import type { Program } from 'oxc-parser';
2
- export declare const getEntryFromAST: (program: Program) => Set<string>;
@@ -1,4 +0,0 @@
1
- import { collectPropertyValues } from '../../typescript/ast-helpers.js';
2
- export const getEntryFromAST = (program) => {
3
- return collectPropertyValues(program, 'entry');
4
- };
@@ -1,2 +0,0 @@
1
- import type { Program } from 'oxc-parser';
2
- export declare const getEntryFromAST: (program: Program) => Set<string>;
@@ -1,4 +0,0 @@
1
- import { collectPropertyValues } from '../../typescript/ast-helpers.js';
2
- export const getEntryFromAST = (program) => {
3
- return collectPropertyValues(program, 'entry');
4
- };
@@ -1,3 +0,0 @@
1
- import type { CompilerSync } from '../../compilers/types.ts';
2
- declare const compiler: CompilerSync;
3
- export default compiler;
@@ -1,10 +0,0 @@
1
- import { scriptBodies } from '../../compilers/compilers.js';
2
- import { stylePreprocessorImports } from '../../compilers/style-preprocessors.js';
3
- const compiler = (text, path) => {
4
- const scripts = scriptBodies(text, path);
5
- const styles = stylePreprocessorImports(text, path);
6
- if (!scripts)
7
- return styles;
8
- return styles ? `${scripts};\n${styles}` : scripts;
9
- };
10
- export default compiler;