@simple-code-inspector/core 1.6.1

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.
@@ -0,0 +1,157 @@
1
+ import { CodeOptions, Condition, EscapeTags } from './type';
2
+ /**
3
+ * 将源码位置信息格式化为复制到剪贴板的文本
4
+ * @param format 模版字符串,支持 {file} / {line} / {column} / {tag} 占位符
5
+ * @param source 源码位置信息
6
+ */
7
+ export declare function formatCopyText(format: string, source: {
8
+ file: string;
9
+ line: number;
10
+ column: number;
11
+ tag: string;
12
+ }): string;
13
+ /**
14
+ * 读取 cwd 下 `.env.local` 文件中指定 key 的值
15
+ * 用于 `needEnvInspector` 配置:仅当 `.env.local` 中包含 `CODE_INSPECTOR=true` 时插件才生效
16
+ * @param key 环境变量名
17
+ * @param cwd 项目目录,默认为 process.cwd()
18
+ * @returns 对应的值;不存在时返回 undefined
19
+ */
20
+ export declare function getEnvVariable(key: string, cwd?: string): string | undefined;
21
+ export declare function getIP(ip: boolean | string): string;
22
+ export declare function isJsTypeFile(file: string): boolean;
23
+ export declare function getFilePathWithoutExt(filePath: string): string;
24
+ export declare function normalizePath(filepath: string): string;
25
+ export declare function isAstroToolbarFile(file: string): boolean;
26
+ export declare function isEscapeTags(escapeTags: EscapeTags, tag: string): boolean;
27
+ export declare function getDependenciesMap(): any;
28
+ export declare function getDependencies(): string[];
29
+ type BooleanFunction = () => boolean;
30
+ /**
31
+ * Determine if the current environment is development mode
32
+ *
33
+ * Priority: user-specified environment > system default environment
34
+ *
35
+ * @param userDev - User-specified development mode setting:
36
+ * - `true`: Force development mode
37
+ * - `false`: Force production mode
38
+ * - `function`: Dynamic function that returns boolean
39
+ * - `undefined`: Use system default
40
+ * @param systemDev - System default development mode (e.g., from NODE_ENV)
41
+ * @returns `true` if in development mode, `false` otherwise
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * // Force development mode
46
+ * isDev(true, false) // Returns: true
47
+ *
48
+ * // Force production mode
49
+ * isDev(false, true) // Returns: false
50
+ *
51
+ * // Use system default
52
+ * isDev(undefined, true) // Returns: true
53
+ *
54
+ * // Dynamic function
55
+ * isDev(() => process.env.NODE_ENV === 'development', false)
56
+ * ```
57
+ */
58
+ export declare function isDev(userDev: boolean | BooleanFunction | undefined, systemDev: boolean): boolean;
59
+ /**
60
+ * Check if a file matches the given condition
61
+ *
62
+ * Supports multiple condition types for flexible file matching:
63
+ * - String: Checks if file path contains the string
64
+ * - RegExp: Tests file path against the regular expression
65
+ * - Array: Recursively checks if file matches any condition in the array
66
+ *
67
+ * @param condition - The condition to match against:
68
+ * - `string`: File path must contain this string
69
+ * - `RegExp`: File path must match this pattern
70
+ * - `Array`: File path must match at least one condition
71
+ * @param file - The file path to check
72
+ * @returns `true` if the file matches the condition, `false` otherwise
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * // String matching
77
+ * matchCondition('node_modules', '/path/to/node_modules/pkg') // Returns: true
78
+ *
79
+ * // RegExp matching
80
+ * matchCondition(/\.test\.ts$/, 'file.test.ts') // Returns: true
81
+ *
82
+ * // Array matching (OR logic)
83
+ * matchCondition(['src', /\.tsx$/], 'src/App.tsx') // Returns: true
84
+ * ```
85
+ */
86
+ export declare function matchCondition(condition: Condition, file: string): boolean;
87
+ /**
88
+ * Get the mapped file path based on the provided mappings configuration
89
+ *
90
+ * This function resolves file paths by applying mapping rules, which is useful for:
91
+ * - Resolving module aliases (e.g., '@/components' -> 'src/components')
92
+ * - Mapping node_modules paths to local source paths
93
+ * - Handling monorepo package paths
94
+ *
95
+ * @param file - The original file path to map
96
+ * @param mappings - Path mapping configuration, can be either:
97
+ * - Object: `{ '@/': 'src/', '~': 'node_modules/' }`
98
+ * - Array: `[{ find: '@/', replacement: 'src/' }, { find: /^~/, replacement: 'node_modules/' }]`
99
+ * @returns The mapped file path if a mapping is found and the file exists, otherwise returns the original path
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * // Object mapping
104
+ * getMappingFilePath('@/components/Button.tsx', { '@/': 'src/' })
105
+ * // Returns: 'src/components/Button.tsx' (if file exists)
106
+ *
107
+ * // Array mapping with RegExp
108
+ * getMappingFilePath('~/lodash/index.js', [
109
+ * { find: /^~/, replacement: 'node_modules/' }
110
+ * ])
111
+ * // Returns: 'node_modules/lodash/index.js' (if file exists)
112
+ * ```
113
+ */
114
+ export declare function getMappingFilePath(file: string, mappings?: Record<string, string> | Array<{
115
+ find: string | RegExp;
116
+ replacement: string;
117
+ }>): string;
118
+ /**
119
+ * Check if a file should be excluded from processing
120
+ *
121
+ * Determines if a file should be excluded based on exclude/include patterns.
122
+ * Files in node_modules are always excluded unless explicitly included.
123
+ *
124
+ * Logic:
125
+ * - If file matches exclude pattern AND NOT in include pattern → excluded
126
+ * - If file matches include pattern → NOT excluded (even if in node_modules)
127
+ * - node_modules is always in the exclude list by default
128
+ *
129
+ * @param file - The file path to check
130
+ * @param options - Code inspector options containing exclude/include patterns
131
+ * @returns `true` if the file should be excluded, `false` otherwise
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * const options = {
136
+ * exclude: [/\.test\.ts$/, 'dist'],
137
+ * include: ['src']
138
+ * };
139
+ *
140
+ * isExcludedFile('src/App.test.ts', options) // Returns: true (matches exclude)
141
+ * isExcludedFile('node_modules/pkg/index.js', options) // Returns: true (node_modules)
142
+ * isExcludedFile('src/index.ts', options) // Returns: false (in include)
143
+ * ```
144
+ */
145
+ export declare function isExcludedFile(file: string, options: CodeOptions): boolean;
146
+ export declare function hasWritePermission(filePath: string): boolean;
147
+ /**
148
+ * Check if a file should be ignored based on special directives in comments
149
+ * @param content - The file content to check
150
+ * @param fileType - The type of file ('vue', 'jsx', 'svelte', 'astro', 'mdx', or unknown)
151
+ * @returns true if the file should be ignored, false otherwise
152
+ */
153
+ export declare function isIgnoredFile({ content, fileType, }: {
154
+ content: string;
155
+ fileType: 'vue' | 'jsx' | 'svelte' | 'astro' | 'mdx' | unknown;
156
+ }): boolean;
157
+ export {};