Skip to content

Commit

Permalink
fix: use of existing types in src/@types
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-pribilinskiy committed Jul 22, 2022
1 parent c791a5c commit c5910a9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ export const FEDERATION_CONFIG_FILE = 'federation.config.json';
export const DIR_EMITTED = '@types';

export const DIR_DIST = 'dist';
export const DIR_DOWNLOADED = 'src/@types/remotes';
export const DIR_TYPES = 'src/@types';
export const DIR_DOWNLOADED = `${DIR_TYPES}/remotes`;

export const DEFAULT_SYNC_TYPES_INTERVAL_IN_SECONDS = 60;

Expand Down
7 changes: 6 additions & 1 deletion src/helpers/compileTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import ts from 'typescript';

import { getLogger } from './logger';

import { DIR_TYPES } from '../constants';
import { CompileTypesResult, FederationConfig } from '../types';
import { getAllFilePaths } from './files';

export function getTSConfigCompilerOptions(): ts.CompilerOptions {
const logger = getLogger();
Expand Down Expand Up @@ -39,7 +41,10 @@ export function compileTypes(exposedComponents: string[], outFile: string): Comp
const host = ts.createCompilerHost(compilerOptions);
host.writeFile = (_fileName: string, contents: string) => fileContent = contents;

exposedFileNames.push('./src/@types/utility.d.ts');
if (fs.existsSync(DIR_TYPES)) {
exposedFileNames.push(...getAllFilePaths(DIR_TYPES).filter(path => path.endsWith('.d.ts')));
}

const program = ts.createProgram(exposedFileNames, compilerOptions, host);
const { diagnostics, emitSkipped } = program.emit();
diagnostics.forEach(reportCompileDiagnostic);
Expand Down
16 changes: 16 additions & 0 deletions src/helpers/files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import fs from 'fs';
import path from 'path';

export function getAllFilePaths(dirPath: string, arrayOfFiles: string[] = []): string[] {
const files = fs.readdirSync(dirPath);

files.forEach(file => {
if (fs.statSync(`${dirPath}/${file}`).isDirectory()) {
arrayOfFiles = getAllFilePaths(`${dirPath}/${file}`, arrayOfFiles);
} else {
arrayOfFiles.push(path.join(__dirname, dirPath, "/", file));
}
})

return arrayOfFiles;
}

0 comments on commit c5910a9

Please sign in to comment.