@@ -14,10 +14,7 @@ export function parseForgottenExportMessage(text: string): string | null {
1414 * Resolves which @forgerock/* package a source file belongs to.
1515 * Handles both workspace source paths and node_modules paths.
1616 */
17- export function resolveSourcePackage (
18- sourceFilePath : string ,
19- workspaceRoot : string ,
20- ) : string | null {
17+ export function resolveSourcePackage ( sourceFilePath : string , workspaceRoot : string ) : string | null {
2118 // Check node_modules path: ...node_modules/@forgerock /package-name/...
2219 const nodeModulesMatch = / @ f o r g e r o c k \/ ( [ ^ / ] + ) / . exec ( sourceFilePath ) ;
2320 if ( nodeModulesMatch && sourceFilePath . includes ( 'node_modules' ) ) {
@@ -52,14 +49,13 @@ export function resolveSourcePackage(
5249 * Finds the module specifier for a symbol's import in a .d.ts file.
5350 * Given `import { ForgottenType } from '@forgerock/sdk-types'`, returns '@forgerock/sdk-types'.
5451 */
55- export function findImportModuleForSymbol (
56- fileContent : string ,
57- symbolName : string ,
58- ) : string | null {
52+ export function findImportModuleForSymbol ( fileContent : string , symbolName : string ) : string | null {
5953 // Match: import [type] { ..., symbolName, ... } from 'module'
6054 // Handle both single-line and multi-line imports, with optional 'type' keyword
6155 const regex = new RegExp (
62- "import\\s+(?:type\\s+)?\\{[^}]*\\b" + escapeRegex ( symbolName ) + "\\b[^}]*\\}\\s*from\\s*['\"]([^'\"]+)['\"]" ,
56+ 'import\\s+(?:type\\s+)?\\{[^}]*\\b' +
57+ escapeRegex ( symbolName ) +
58+ '\\b[^}]*\\}\\s*from\\s*[\'"]([^\'"]+)[\'"]' ,
6359 's' ,
6460 ) ;
6561 const match = regex . exec ( fileContent ) ;
@@ -71,10 +67,7 @@ export function findImportModuleForSymbol(
7167 * (class/enum/const/function) by scanning the source file content.
7268 * Defaults to 'type' when uncertain.
7369 */
74- export function determineExportKind (
75- sourceContent : string ,
76- symbolName : string ,
77- ) : 'type' | 'value' {
70+ export function determineExportKind ( sourceContent : string , symbolName : string ) : 'type' | 'value' {
7871 // Check for value patterns first (more specific)
7972 // Handle optional 'export' and 'declare' keywords in .d.ts files
8073 const valuePatterns = [
@@ -111,7 +104,7 @@ export function buildReExportStatement(
111104 kind : 'type' | 'value' ,
112105) : string {
113106 const keyword = kind === 'type' ? 'export type' : 'export' ;
114- return keyword + " { " + symbolName + " } from '" + sourcePackage + "';" ;
107+ return keyword + ' { ' + symbolName + " } from '" + sourcePackage + "';" ;
115108}
116109
117110function escapeRegex ( str : string ) : string {
@@ -131,12 +124,12 @@ export function insertReExport(
131124 kind : 'type' | 'value' ,
132125) : string {
133126 // Check if already exported (handle multi-line blocks where symbol and 'from' are on different lines)
134- const hasSymbolInPackageBlock = new RegExp (
135- '\\b' + escapeRegex ( symbolName ) + '\\b' ,
136- ) ;
127+ const hasSymbolInPackageBlock = new RegExp ( '\\b' + escapeRegex ( symbolName ) + '\\b' ) ;
137128 // Find all export blocks for this package and check if symbol is in any of them
138129 const blockRegex = new RegExp (
139- '(?:export(?:\\s+type)?)\\s*\\{([^}]*)\\}\\s*from\\s*[\'"]' + escapeRegex ( sourcePackage ) + '[\'"]' ,
130+ '(?:export(?:\\s+type)?)\\s*\\{([^}]*)\\}\\s*from\\s*[\'"]' +
131+ escapeRegex ( sourcePackage ) +
132+ '[\'"]' ,
140133 'gs' ,
141134 ) ;
142135 let blockMatch ;
@@ -147,14 +140,16 @@ export function insertReExport(
147140 const keyword = kind === 'type' ? 'export type' : 'export' ;
148141
149142 // For value exports, avoid matching 'export type {' blocks
150- const keywordPattern = kind === 'value'
151- ? 'export\\s+(?!type\\s)'
152- : escapeRegex ( keyword ) + '\\s*' ;
143+ const keywordPattern = kind === 'value' ? 'export\\s+(?!type\\s)' : escapeRegex ( keyword ) + '\\s*' ;
153144
154145 // Try single-line block first: export { Foo, Bar } from 'package';
155146 // (no newlines between { and })
156147 const singleLineRegex = new RegExp (
157- '(' + keywordPattern + '\\{\\s*)([^}\\n]+)(\\s*\\}\\s*from\\s*[\'"]' + escapeRegex ( sourcePackage ) + '[\'"];)' ,
148+ '(' +
149+ keywordPattern +
150+ '\\{\\s*)([^}\\n]+)(\\s*\\}\\s*from\\s*[\'"]' +
151+ escapeRegex ( sourcePackage ) +
152+ '[\'"];)' ,
158153 ) ;
159154 const singleLineMatch = singleLineRegex . exec ( content ) ;
160155 if ( singleLineMatch ) {
@@ -169,7 +164,11 @@ export function insertReExport(
169164
170165 // Try multi-line block: export type {\n Foo,\n Bar,\n} from 'package';
171166 const multiLineBlockRegex = new RegExp (
172- '(' + keywordPattern + '\\{[^}]*)(\\}\\s*from\\s*[\'"]' + escapeRegex ( sourcePackage ) + '[\'"];)' ,
167+ '(' +
168+ keywordPattern +
169+ '\\{[^}]*)(\\}\\s*from\\s*[\'"]' +
170+ escapeRegex ( sourcePackage ) +
171+ '[\'"];)' ,
173172 's' ,
174173 ) ;
175174 const multiLineMatch = multiLineBlockRegex . exec ( content ) ;
@@ -258,7 +257,13 @@ export function applyFixes(
258257
259258 // Determine type vs value from the definition file (or fall back to usage site)
260259 const definitionContent = definitionFilePath
261- ? ( ( ) => { try { return readFileSync ( definitionFilePath , 'utf-8' ) ; } catch { return usageSiteContent ; } } ) ( )
260+ ? ( ( ) => {
261+ try {
262+ return readFileSync ( definitionFilePath , 'utf-8' ) ;
263+ } catch {
264+ return usageSiteContent ;
265+ }
266+ } ) ( )
262267 : usageSiteContent ;
263268
264269 const kind = determineExportKind ( definitionContent , fe . symbolName ) ;
0 commit comments