@elliots/typical 0.2.0 → 0.2.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.
- package/dist/src/config.d.ts +8 -36
- package/dist/src/config.js +0 -103
- package/dist/src/config.js.map +1 -1
- package/dist/src/transformer.js +2 -1
- package/dist/src/transformer.js.map +1 -1
- package/package.json +2 -2
- package/src/config.ts +8 -131
- package/src/transformer.ts +2 -1
package/dist/src/config.d.ts
CHANGED
|
@@ -31,12 +31,6 @@ export interface TypicalConfig {
|
|
|
31
31
|
* Example: ["React.*", "Express.Request", "*.Event"]
|
|
32
32
|
*/
|
|
33
33
|
ignoreTypes?: string[];
|
|
34
|
-
/**
|
|
35
|
-
* Skip validation for DOM types (Document, Element, Node, etc.) and their subclasses.
|
|
36
|
-
* These types have complex Window intersections that typia cannot process.
|
|
37
|
-
* Default: true
|
|
38
|
-
*/
|
|
39
|
-
ignoreDOMTypes?: boolean;
|
|
40
34
|
/**
|
|
41
35
|
* Validate function parameters and return types at runtime.
|
|
42
36
|
* When enabled, typed function parameters get runtime validation calls injected.
|
|
@@ -60,38 +54,16 @@ export interface TypicalConfig {
|
|
|
60
54
|
* Controls whether and how source maps are generated for transformed code.
|
|
61
55
|
*/
|
|
62
56
|
sourceMap?: TypicalSourceMapConfig;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
/** Compiled patterns from DOM_TYPES_TO_IGNORE (when ignoreDOMTypes is true) */
|
|
72
|
-
domPatterns: RegExp[];
|
|
73
|
-
/** All patterns combined for quick checking */
|
|
74
|
-
allPatterns: RegExp[];
|
|
57
|
+
/**
|
|
58
|
+
* Maximum number of helper functions (_io0, _io1, etc.) that can be generated
|
|
59
|
+
* for a single type before erroring. Complex DOM types or library types can
|
|
60
|
+
* generate hundreds of functions which indicates a type that should be excluded.
|
|
61
|
+
* Set to 0 to disable the limit.
|
|
62
|
+
* Default: 50
|
|
63
|
+
*/
|
|
64
|
+
maxGeneratedFunctions?: number;
|
|
75
65
|
}
|
|
76
66
|
export declare const defaultConfig: TypicalConfig;
|
|
77
|
-
/**
|
|
78
|
-
* DOM types that typia cannot process due to Window global intersections.
|
|
79
|
-
* These are the base DOM types - classes extending them are checked separately.
|
|
80
|
-
*/
|
|
81
|
-
export declare const DOM_TYPES_TO_IGNORE: string[];
|
|
82
|
-
/**
|
|
83
|
-
* Convert a glob pattern to a RegExp for type matching.
|
|
84
|
-
* Supports wildcards: "React.*" -> /^React\..*$/
|
|
85
|
-
*/
|
|
86
|
-
export declare function compileIgnorePattern(pattern: string): RegExp | null;
|
|
87
|
-
/**
|
|
88
|
-
* Pre-compile all ignore patterns for efficient matching.
|
|
89
|
-
*/
|
|
90
|
-
export declare function compileIgnorePatterns(config: TypicalConfig): CompiledIgnorePatterns;
|
|
91
|
-
/**
|
|
92
|
-
* Get compiled ignore patterns, using cache if config hasn't changed.
|
|
93
|
-
*/
|
|
94
|
-
export declare function getCompiledIgnorePatterns(config: TypicalConfig): CompiledIgnorePatterns;
|
|
95
67
|
export declare function loadConfig(configPath?: string): TypicalConfig;
|
|
96
68
|
/**
|
|
97
69
|
* Validate and adjust config for consistency.
|
package/dist/src/config.js
CHANGED
|
@@ -7,7 +7,6 @@ export const defaultConfig = {
|
|
|
7
7
|
transformJSONParse: true,
|
|
8
8
|
transformJSONStringify: true,
|
|
9
9
|
hoistRegex: true,
|
|
10
|
-
ignoreDOMTypes: true,
|
|
11
10
|
debug: {
|
|
12
11
|
writeIntermediateFiles: false,
|
|
13
12
|
},
|
|
@@ -17,110 +16,8 @@ export const defaultConfig = {
|
|
|
17
16
|
inline: false,
|
|
18
17
|
},
|
|
19
18
|
};
|
|
20
|
-
// FIXME: find a better way to work out which types to ignore
|
|
21
|
-
/**
|
|
22
|
-
* DOM types that typia cannot process due to Window global intersections.
|
|
23
|
-
* These are the base DOM types - classes extending them are checked separately.
|
|
24
|
-
*/
|
|
25
|
-
export const DOM_TYPES_TO_IGNORE = [
|
|
26
|
-
// Core DOM types
|
|
27
|
-
'Document',
|
|
28
|
-
'DocumentFragment',
|
|
29
|
-
'Element',
|
|
30
|
-
'Node',
|
|
31
|
-
'ShadowRoot',
|
|
32
|
-
'Window',
|
|
33
|
-
'EventTarget',
|
|
34
|
-
// HTML Elements
|
|
35
|
-
'HTML*Element',
|
|
36
|
-
'HTMLElement',
|
|
37
|
-
'HTMLCollection',
|
|
38
|
-
// SVG Elements
|
|
39
|
-
'SVG*Element',
|
|
40
|
-
'SVGElement',
|
|
41
|
-
// Events
|
|
42
|
-
'*Event',
|
|
43
|
-
// Other common DOM types
|
|
44
|
-
'NodeList',
|
|
45
|
-
'DOMTokenList',
|
|
46
|
-
'NamedNodeMap',
|
|
47
|
-
'CSSStyleDeclaration',
|
|
48
|
-
'Selection',
|
|
49
|
-
'Range',
|
|
50
|
-
'Text',
|
|
51
|
-
'Comment',
|
|
52
|
-
'CDATASection',
|
|
53
|
-
'ProcessingInstruction',
|
|
54
|
-
'DocumentType',
|
|
55
|
-
'Attr',
|
|
56
|
-
'Table',
|
|
57
|
-
'TableRow',
|
|
58
|
-
'TableCell',
|
|
59
|
-
'StyleSheet',
|
|
60
|
-
];
|
|
61
19
|
import fs from 'fs';
|
|
62
20
|
import path from 'path';
|
|
63
|
-
/**
|
|
64
|
-
* Convert a glob pattern to a RegExp for type matching.
|
|
65
|
-
* Supports wildcards: "React.*" -> /^React\..*$/
|
|
66
|
-
*/
|
|
67
|
-
export function compileIgnorePattern(pattern) {
|
|
68
|
-
try {
|
|
69
|
-
const regexStr = '^' +
|
|
70
|
-
pattern
|
|
71
|
-
.replace(/[.+^${}()|[\]\\]/g, '\\$&') // Escape special regex chars except *
|
|
72
|
-
.replace(/\*/g, '.*') +
|
|
73
|
-
'$';
|
|
74
|
-
return new RegExp(regexStr);
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
console.warn(`TYPICAL: Invalid ignoreTypes pattern "${pattern}": ${error.message}`);
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Pre-compile all ignore patterns for efficient matching.
|
|
83
|
-
*/
|
|
84
|
-
export function compileIgnorePatterns(config) {
|
|
85
|
-
const userPatterns = [];
|
|
86
|
-
const domPatterns = [];
|
|
87
|
-
// Compile user patterns
|
|
88
|
-
for (const pattern of config.ignoreTypes ?? []) {
|
|
89
|
-
const compiled = compileIgnorePattern(pattern);
|
|
90
|
-
if (compiled) {
|
|
91
|
-
userPatterns.push(compiled);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
// Compile DOM patterns if enabled (default: true)
|
|
95
|
-
if (config.ignoreDOMTypes !== false) {
|
|
96
|
-
for (const pattern of DOM_TYPES_TO_IGNORE) {
|
|
97
|
-
const compiled = compileIgnorePattern(pattern);
|
|
98
|
-
if (compiled) {
|
|
99
|
-
domPatterns.push(compiled);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return {
|
|
104
|
-
userPatterns,
|
|
105
|
-
domPatterns,
|
|
106
|
-
allPatterns: [...userPatterns, ...domPatterns],
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
// Cache for compiled patterns, keyed by config identity
|
|
110
|
-
let cachedPatterns = null;
|
|
111
|
-
let cachedConfig = null;
|
|
112
|
-
/**
|
|
113
|
-
* Get compiled ignore patterns, using cache if config hasn't changed.
|
|
114
|
-
*/
|
|
115
|
-
export function getCompiledIgnorePatterns(config) {
|
|
116
|
-
// Simple identity check - if same config object, use cache
|
|
117
|
-
if (cachedConfig === config && cachedPatterns) {
|
|
118
|
-
return cachedPatterns;
|
|
119
|
-
}
|
|
120
|
-
cachedConfig = config;
|
|
121
|
-
cachedPatterns = compileIgnorePatterns(config);
|
|
122
|
-
return cachedPatterns;
|
|
123
|
-
}
|
|
124
21
|
export function loadConfig(configPath) {
|
|
125
22
|
const configFile = configPath || path.join(process.cwd(), 'typical.json');
|
|
126
23
|
if (fs.existsSync(configFile)) {
|
package/dist/src/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAoEA,MAAM,CAAC,MAAM,aAAa,GAAkB;IAC1C,OAAO,EAAE,CAAC,SAAS,EAAE,UAAU,CAAC;IAChC,OAAO,EAAE,CAAC,iBAAiB,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,CAAC;IAChE,kBAAkB,EAAE,KAAK,EAAE,uEAAuE;IAClG,aAAa,EAAE,KAAK;IACpB,iBAAiB,EAAE,IAAI;IACvB,kBAAkB,EAAE,IAAI;IACxB,sBAAsB,EAAE,IAAI;IAC5B,UAAU,EAAE,IAAI;IAChB,KAAK,EAAE;QACL,sBAAsB,EAAE,KAAK;KAC9B;IACD,SAAS,EAAE;QACT,OAAO,EAAE,IAAI,EAAE,4DAA4D;QAC3E,cAAc,EAAE,IAAI;QACpB,MAAM,EAAE,KAAK;KACd;CACF,CAAA;AAED,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,MAAM,UAAU,UAAU,CAAC,UAAmB;IAC5C,MAAM,UAAU,GAAG,UAAU,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAA;IAEzE,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,IAAI,CAAC;YACH,MAAM,aAAa,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;YACzD,MAAM,UAAU,GAA2B,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;YAEpE,OAAO;gBACL,GAAG,aAAa;gBAChB,GAAG,UAAU;aACd,CAAA;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,+BAA+B,UAAU,GAAG,EAAE,KAAK,CAAC,CAAA;YACjE,OAAO,aAAa,CAAA;QACtB,CAAC;IACH,CAAC;IAED,OAAO,aAAa,CAAA;AACtB,CAAC;AAED,IAAI,qBAAqB,GAAG,KAAK,CAAA;AAEjC;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,MAAqB;IAClD,IAAI,MAAM,GAAG,MAAM,CAAA;IAEnB,+EAA+E;IAC/E,gFAAgF;IAChF,mFAAmF;IACnF,sDAAsD;IACtD,MAAM,gBAAgB,GAAG,MAAM,CAAC,SAAS,EAAE,OAAO,KAAK,KAAK,CAAA;IAC5D,MAAM,yBAAyB,GAAG,MAAM,CAAC,kBAAkB,KAAK,IAAI,CAAA;IAEpE,IAAI,gBAAgB,IAAI,yBAAyB,EAAE,CAAC;QAClD,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC3B,qBAAqB,GAAG,IAAI,CAAA;YAC5B,OAAO,CAAC,IAAI,CACV,8DAA8D,GAAG,4DAA4D,GAAG,gFAAgF,CACjN,CAAA;QACH,CAAC;QACD,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,CAAA;IACnD,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/dist/src/transformer.js
CHANGED
|
@@ -45,7 +45,8 @@ export class TypicalTransformer {
|
|
|
45
45
|
}
|
|
46
46
|
await this.ensureInitialized();
|
|
47
47
|
const resolvedPath = resolve(fileName);
|
|
48
|
-
|
|
48
|
+
// Pass ignoreTypes and maxGeneratedFunctions from config to the Go compiler
|
|
49
|
+
const result = await this.compiler.transformFile(this.projectHandle, resolvedPath, this.config.ignoreTypes, this.config.maxGeneratedFunctions);
|
|
49
50
|
return {
|
|
50
51
|
code: result.code,
|
|
51
52
|
map: result.sourceMap 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AAC;QACD,MAAM,IAAI,CAAC,WAAW,CAAA;IACxB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,SAAS,CAAC,QAAgB,EAAE,OAAoB,IAAI;QACxD,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAA;QACpF,CAAC;QAED,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAA;QAE9B,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;QACtC,4EAA4E;QAC5E,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,aAAc,EAAE,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAA;QAE/I,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,GAAG,EAAE,MAAM,CAAC,SAAS,IAAI,IAAI;SAC9B,CAAA;IACH,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,aAAa,GAAG,IAAI,CAAA;QACzB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA;QACvB,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;IAC7B,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliots/typical",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Runtime safe TypeScript transformer using typia",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"runtime",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"commander": "14.0.2",
|
|
43
|
-
"@elliots/typical-compiler": "0.2.
|
|
43
|
+
"@elliots/typical-compiler": "0.2.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/node": "22",
|
package/src/config.ts
CHANGED
|
@@ -33,12 +33,6 @@ export interface TypicalConfig {
|
|
|
33
33
|
* Example: ["React.*", "Express.Request", "*.Event"]
|
|
34
34
|
*/
|
|
35
35
|
ignoreTypes?: string[]
|
|
36
|
-
/**
|
|
37
|
-
* Skip validation for DOM types (Document, Element, Node, etc.) and their subclasses.
|
|
38
|
-
* These types have complex Window intersections that typia cannot process.
|
|
39
|
-
* Default: true
|
|
40
|
-
*/
|
|
41
|
-
ignoreDOMTypes?: boolean
|
|
42
36
|
/**
|
|
43
37
|
* Validate function parameters and return types at runtime.
|
|
44
38
|
* When enabled, typed function parameters get runtime validation calls injected.
|
|
@@ -62,19 +56,14 @@ export interface TypicalConfig {
|
|
|
62
56
|
* Controls whether and how source maps are generated for transformed code.
|
|
63
57
|
*/
|
|
64
58
|
sourceMap?: TypicalSourceMapConfig
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
userPatterns: RegExp[]
|
|
74
|
-
/** Compiled patterns from DOM_TYPES_TO_IGNORE (when ignoreDOMTypes is true) */
|
|
75
|
-
domPatterns: RegExp[]
|
|
76
|
-
/** All patterns combined for quick checking */
|
|
77
|
-
allPatterns: RegExp[]
|
|
59
|
+
/**
|
|
60
|
+
* Maximum number of helper functions (_io0, _io1, etc.) that can be generated
|
|
61
|
+
* for a single type before erroring. Complex DOM types or library types can
|
|
62
|
+
* generate hundreds of functions which indicates a type that should be excluded.
|
|
63
|
+
* Set to 0 to disable the limit.
|
|
64
|
+
* Default: 50
|
|
65
|
+
*/
|
|
66
|
+
maxGeneratedFunctions?: number
|
|
78
67
|
}
|
|
79
68
|
|
|
80
69
|
export const defaultConfig: TypicalConfig = {
|
|
@@ -86,7 +75,6 @@ export const defaultConfig: TypicalConfig = {
|
|
|
86
75
|
transformJSONParse: true,
|
|
87
76
|
transformJSONStringify: true,
|
|
88
77
|
hoistRegex: true,
|
|
89
|
-
ignoreDOMTypes: true,
|
|
90
78
|
debug: {
|
|
91
79
|
writeIntermediateFiles: false,
|
|
92
80
|
},
|
|
@@ -97,120 +85,9 @@ export const defaultConfig: TypicalConfig = {
|
|
|
97
85
|
},
|
|
98
86
|
}
|
|
99
87
|
|
|
100
|
-
// FIXME: find a better way to work out which types to ignore
|
|
101
|
-
/**
|
|
102
|
-
* DOM types that typia cannot process due to Window global intersections.
|
|
103
|
-
* These are the base DOM types - classes extending them are checked separately.
|
|
104
|
-
*/
|
|
105
|
-
export const DOM_TYPES_TO_IGNORE = [
|
|
106
|
-
// Core DOM types
|
|
107
|
-
'Document',
|
|
108
|
-
'DocumentFragment',
|
|
109
|
-
'Element',
|
|
110
|
-
'Node',
|
|
111
|
-
'ShadowRoot',
|
|
112
|
-
'Window',
|
|
113
|
-
'EventTarget',
|
|
114
|
-
// HTML Elements
|
|
115
|
-
'HTML*Element',
|
|
116
|
-
'HTMLElement',
|
|
117
|
-
'HTMLCollection',
|
|
118
|
-
// SVG Elements
|
|
119
|
-
'SVG*Element',
|
|
120
|
-
'SVGElement',
|
|
121
|
-
// Events
|
|
122
|
-
'*Event',
|
|
123
|
-
// Other common DOM types
|
|
124
|
-
'NodeList',
|
|
125
|
-
'DOMTokenList',
|
|
126
|
-
'NamedNodeMap',
|
|
127
|
-
'CSSStyleDeclaration',
|
|
128
|
-
'Selection',
|
|
129
|
-
'Range',
|
|
130
|
-
'Text',
|
|
131
|
-
'Comment',
|
|
132
|
-
'CDATASection',
|
|
133
|
-
'ProcessingInstruction',
|
|
134
|
-
'DocumentType',
|
|
135
|
-
'Attr',
|
|
136
|
-
'Table',
|
|
137
|
-
'TableRow',
|
|
138
|
-
'TableCell',
|
|
139
|
-
'StyleSheet',
|
|
140
|
-
]
|
|
141
|
-
|
|
142
88
|
import fs from 'fs'
|
|
143
89
|
import path from 'path'
|
|
144
90
|
|
|
145
|
-
/**
|
|
146
|
-
* Convert a glob pattern to a RegExp for type matching.
|
|
147
|
-
* Supports wildcards: "React.*" -> /^React\..*$/
|
|
148
|
-
*/
|
|
149
|
-
export function compileIgnorePattern(pattern: string): RegExp | null {
|
|
150
|
-
try {
|
|
151
|
-
const regexStr =
|
|
152
|
-
'^' +
|
|
153
|
-
pattern
|
|
154
|
-
.replace(/[.+^${}()|[\]\\]/g, '\\$&') // Escape special regex chars except *
|
|
155
|
-
.replace(/\*/g, '.*') +
|
|
156
|
-
'$'
|
|
157
|
-
return new RegExp(regexStr)
|
|
158
|
-
} catch (error) {
|
|
159
|
-
console.warn(`TYPICAL: Invalid ignoreTypes pattern "${pattern}": ${(error as Error).message}`)
|
|
160
|
-
return null
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Pre-compile all ignore patterns for efficient matching.
|
|
166
|
-
*/
|
|
167
|
-
export function compileIgnorePatterns(config: TypicalConfig): CompiledIgnorePatterns {
|
|
168
|
-
const userPatterns: RegExp[] = []
|
|
169
|
-
const domPatterns: RegExp[] = []
|
|
170
|
-
|
|
171
|
-
// Compile user patterns
|
|
172
|
-
for (const pattern of config.ignoreTypes ?? []) {
|
|
173
|
-
const compiled = compileIgnorePattern(pattern)
|
|
174
|
-
if (compiled) {
|
|
175
|
-
userPatterns.push(compiled)
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Compile DOM patterns if enabled (default: true)
|
|
180
|
-
if (config.ignoreDOMTypes !== false) {
|
|
181
|
-
for (const pattern of DOM_TYPES_TO_IGNORE) {
|
|
182
|
-
const compiled = compileIgnorePattern(pattern)
|
|
183
|
-
if (compiled) {
|
|
184
|
-
domPatterns.push(compiled)
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return {
|
|
190
|
-
userPatterns,
|
|
191
|
-
domPatterns,
|
|
192
|
-
allPatterns: [...userPatterns, ...domPatterns],
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// Cache for compiled patterns, keyed by config identity
|
|
197
|
-
let cachedPatterns: CompiledIgnorePatterns | null = null
|
|
198
|
-
let cachedConfig: TypicalConfig | null = null
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Get compiled ignore patterns, using cache if config hasn't changed.
|
|
202
|
-
*/
|
|
203
|
-
export function getCompiledIgnorePatterns(config: TypicalConfig): CompiledIgnorePatterns {
|
|
204
|
-
// Simple identity check - if same config object, use cache
|
|
205
|
-
if (cachedConfig === config && cachedPatterns) {
|
|
206
|
-
return cachedPatterns
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
cachedConfig = config
|
|
210
|
-
cachedPatterns = compileIgnorePatterns(config)
|
|
211
|
-
return cachedPatterns
|
|
212
|
-
}
|
|
213
|
-
|
|
214
91
|
export function loadConfig(configPath?: string): TypicalConfig {
|
|
215
92
|
const configFile = configPath || path.join(process.cwd(), 'typical.json')
|
|
216
93
|
|
package/src/transformer.ts
CHANGED
|
@@ -58,7 +58,8 @@ export class TypicalTransformer {
|
|
|
58
58
|
await this.ensureInitialized()
|
|
59
59
|
|
|
60
60
|
const resolvedPath = resolve(fileName)
|
|
61
|
-
|
|
61
|
+
// Pass ignoreTypes and maxGeneratedFunctions from config to the Go compiler
|
|
62
|
+
const result = await this.compiler.transformFile(this.projectHandle!, resolvedPath, this.config.ignoreTypes, this.config.maxGeneratedFunctions)
|
|
62
63
|
|
|
63
64
|
return {
|
|
64
65
|
code: result.code,
|