@idealyst/tooling 1.2.24 → 1.2.25

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,149 @@
1
+ /**
2
+ * File type classification based on file extension patterns
3
+ */
4
+ type FileType = 'shared' | 'web' | 'native' | 'styles' | 'types' | 'other';
5
+ /**
6
+ * Platform classification for imports
7
+ */
8
+ type Platform = 'react-native' | 'react-dom' | 'neutral';
9
+ /**
10
+ * Violation type describing what kind of platform mismatch occurred
11
+ */
12
+ type ViolationType = 'native-in-shared' | 'dom-in-shared' | 'native-in-web' | 'dom-in-native';
13
+ /**
14
+ * Severity level for violations
15
+ */
16
+ type Severity = 'error' | 'warning' | 'info';
17
+ /**
18
+ * Information about a single import
19
+ */
20
+ interface ImportInfo {
21
+ /** The imported identifier name */
22
+ name: string;
23
+ /** Original name if aliased (e.g., `Image as RNImage`) */
24
+ originalName?: string;
25
+ /** The module source (e.g., 'react-native', 'react-dom') */
26
+ source: string;
27
+ /** The platform this import belongs to */
28
+ platform: Platform;
29
+ /** Line number in source file */
30
+ line: number;
31
+ /** Column number in source file */
32
+ column: number;
33
+ /** Whether this is a default import */
34
+ isDefault: boolean;
35
+ /** Whether this is a namespace import (import * as X) */
36
+ isNamespace: boolean;
37
+ /** Whether this is a type-only import */
38
+ isTypeOnly: boolean;
39
+ }
40
+ /**
41
+ * A single violation found during analysis
42
+ */
43
+ interface Violation {
44
+ /** Type of violation */
45
+ type: ViolationType;
46
+ /** The primitive/component that caused the violation */
47
+ primitive: string;
48
+ /** The module source (e.g., 'react-native', 'react-dom') */
49
+ source: string;
50
+ /** Path to the file with the violation */
51
+ filePath: string;
52
+ /** Line number where violation occurred */
53
+ line: number;
54
+ /** Column number where violation occurred */
55
+ column: number;
56
+ /** Human-readable message describing the violation */
57
+ message: string;
58
+ /** Severity level of this violation */
59
+ severity: Severity;
60
+ }
61
+ /**
62
+ * Result of analyzing a single file
63
+ */
64
+ interface AnalysisResult {
65
+ /** Path to the analyzed file */
66
+ filePath: string;
67
+ /** Classified type of the file */
68
+ fileType: FileType;
69
+ /** List of violations found */
70
+ violations: Violation[];
71
+ /** All imports found in the file */
72
+ imports: ImportInfo[];
73
+ /** Whether the file passed validation (no violations) */
74
+ passed: boolean;
75
+ }
76
+ /**
77
+ * Options for configuring the platform import analyzer
78
+ */
79
+ interface AnalyzerOptions {
80
+ /**
81
+ * Default severity level for violations
82
+ * @default 'error'
83
+ */
84
+ severity?: Severity;
85
+ /**
86
+ * Additional React Native primitives to flag beyond the built-in list
87
+ * Useful for flagging custom native-only components
88
+ */
89
+ additionalNativePrimitives?: string[];
90
+ /**
91
+ * Additional React DOM primitives to flag beyond the built-in list
92
+ * Useful for flagging custom web-only components
93
+ */
94
+ additionalDomPrimitives?: string[];
95
+ /**
96
+ * Primitives to ignore/allow even if they would normally be flagged
97
+ */
98
+ ignoredPrimitives?: string[];
99
+ /**
100
+ * Glob patterns for files to skip analysis on
101
+ * @example ['**\/*.test.tsx', '**\/*.stories.tsx']
102
+ */
103
+ ignoredPatterns?: string[];
104
+ /**
105
+ * Additional module sources to treat as React Native
106
+ * @example ['react-native-gesture-handler', 'react-native-reanimated']
107
+ */
108
+ additionalNativeSources?: string[];
109
+ /**
110
+ * Additional module sources to treat as React DOM
111
+ * @example ['react-dom/client']
112
+ */
113
+ additionalDomSources?: string[];
114
+ }
115
+ /**
116
+ * Input for batch file analysis
117
+ */
118
+ interface FileInput {
119
+ /** File path */
120
+ path: string;
121
+ /** File content (source code) */
122
+ content: string;
123
+ }
124
+ /**
125
+ * Primitive rule definition
126
+ */
127
+ interface PrimitiveRule {
128
+ /** Name of the primitive/component */
129
+ name: string;
130
+ /** Module source it comes from */
131
+ source: string;
132
+ /** Platform it belongs to */
133
+ platform: Platform;
134
+ /** Optional description of why it's platform-specific */
135
+ description?: string;
136
+ }
137
+ /**
138
+ * Rule set containing primitives for a specific platform
139
+ */
140
+ interface PrimitiveRuleSet {
141
+ /** Platform these rules apply to */
142
+ platform: Platform;
143
+ /** List of primitive rules */
144
+ primitives: PrimitiveRule[];
145
+ /** Module sources that indicate this platform */
146
+ sources: string[];
147
+ }
148
+
149
+ export type { AnalysisResult as A, FileType as F, ImportInfo as I, Platform as P, Severity as S, ViolationType as V, Violation as a, AnalyzerOptions as b, FileInput as c, PrimitiveRule as d, PrimitiveRuleSet as e };
@@ -0,0 +1,94 @@
1
+ import { F as FileType, I as ImportInfo, P as Platform } from '../types-CvIlSIOV.js';
2
+
3
+ /**
4
+ * Classifies a file based on its path and extension
5
+ *
6
+ * @param filePath - The file path to classify
7
+ * @returns The file type classification
8
+ *
9
+ * @example
10
+ * classifyFile('Button.tsx') // 'shared'
11
+ * classifyFile('Button.web.tsx') // 'web'
12
+ * classifyFile('Button.native.tsx') // 'native'
13
+ * classifyFile('Button.styles.tsx') // 'styles'
14
+ * classifyFile('types.ts') // 'types'
15
+ */
16
+ declare function classifyFile(filePath: string): FileType;
17
+ /**
18
+ * Checks if a file is a component file that should be analyzed
19
+ *
20
+ * @param filePath - The file path to check
21
+ * @returns True if the file is a component file (.tsx or .jsx)
22
+ */
23
+ declare function isComponentFile(filePath: string): boolean;
24
+ /**
25
+ * Checks if a file is a shared (cross-platform) component file
26
+ * These are the files that should NOT contain platform-specific imports
27
+ *
28
+ * @param filePath - The file path to check
29
+ * @returns True if the file is a shared component file
30
+ */
31
+ declare function isSharedFile(filePath: string): boolean;
32
+ /**
33
+ * Checks if a file is platform-specific
34
+ *
35
+ * @param filePath - The file path to check
36
+ * @returns True if the file is web or native specific
37
+ */
38
+ declare function isPlatformSpecificFile(filePath: string): boolean;
39
+ /**
40
+ * Gets the expected platform for a file
41
+ *
42
+ * @param filePath - The file path to check
43
+ * @returns The expected platform, or null for shared/other files
44
+ */
45
+ declare function getExpectedPlatform(filePath: string): 'web' | 'native' | null;
46
+ /**
47
+ * Extracts the base component name from a file path
48
+ *
49
+ * @param filePath - The file path
50
+ * @returns The base component name without platform suffix or extension
51
+ *
52
+ * @example
53
+ * getBaseName('Button.web.tsx') // 'Button'
54
+ * getBaseName('Button.native.tsx') // 'Button'
55
+ * getBaseName('Button.tsx') // 'Button'
56
+ */
57
+ declare function getBaseName(filePath: string): string;
58
+
59
+ /**
60
+ * Options for import parsing
61
+ */
62
+ interface ImportParserOptions {
63
+ /** Additional sources to treat as React Native */
64
+ additionalNativeSources?: string[];
65
+ /** Additional sources to treat as React DOM */
66
+ additionalDomSources?: string[];
67
+ }
68
+ /**
69
+ * Determines the platform for a given import source
70
+ */
71
+ declare function getPlatformForSource(source: string, options?: ImportParserOptions): Platform;
72
+ /**
73
+ * Parses import statements from TypeScript/JavaScript source code
74
+ *
75
+ * @param sourceCode - The source code to parse
76
+ * @param filePath - Optional file path for better error messages
77
+ * @param options - Parser options
78
+ * @returns Array of import information
79
+ */
80
+ declare function parseImports(sourceCode: string, filePath?: string, options?: ImportParserOptions): ImportInfo[];
81
+ /**
82
+ * Filters imports to only those from platform-specific sources
83
+ */
84
+ declare function filterPlatformImports(imports: ImportInfo[], platform?: Platform): ImportInfo[];
85
+ /**
86
+ * Gets all unique import sources from a list of imports
87
+ */
88
+ declare function getUniqueSources(imports: ImportInfo[]): string[];
89
+ /**
90
+ * Groups imports by their source module
91
+ */
92
+ declare function groupImportsBySource(imports: ImportInfo[]): Map<string, ImportInfo[]>;
93
+
94
+ export { type ImportParserOptions, classifyFile, filterPlatformImports, getBaseName, getExpectedPlatform, getPlatformForSource, getUniqueSources, groupImportsBySource, isComponentFile, isPlatformSpecificFile, isSharedFile, parseImports };