Skip to content

Commit bad1034

Browse files
committed
fix: Re-export iteration process fail
1 parent 952bebc commit bad1034

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/handlers/re-export-all.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import assert from 'assert';
21
import AwaitEventEmitter from 'await-event-emitter';
32

43
import { EventArguments } from '../types';
@@ -9,32 +8,36 @@ export function reExportAll(emitter: AwaitEventEmitter) {
98

109
function beforeGenerateFiles(args: EventArguments) {
1110
const { project, output } = args;
11+
const rootDirectory = project.getDirectoryOrThrow(output);
1212

13-
for (const rootDirectory of project.getRootDirectories()) {
14-
const sourcesFiles = rootDirectory.getSourceFiles();
15-
const sourceIndexFile = rootDirectory.createSourceFile('index.ts', '', {
13+
for (const directory of project.getRootDirectories()) {
14+
if (directory === rootDirectory) {
15+
continue;
16+
}
17+
const sourcesFiles = directory.getSourceFiles();
18+
const sourceIndexFile = directory.createSourceFile('index.ts', '', {
1619
overwrite: true,
1720
});
1821
const exportDeclarations = sourcesFiles.flatMap(s => ({
1922
namedExports: s
2023
.getExportSymbols()
2124
.flatMap(s => s.getName())
2225
.map(name => ({ name })),
23-
moduleSpecifier: rootDirectory.getRelativePathAsModuleSpecifierTo(s),
26+
moduleSpecifier: directory.getRelativePathAsModuleSpecifierTo(s),
2427
}));
2528
sourceIndexFile.addExportDeclarations(exportDeclarations);
2629
}
2730

28-
const rootDirectory = project.getDirectory(output);
29-
assert(rootDirectory, 'Cannot get project output directory');
3031
const sourceIndexFile = rootDirectory.createSourceFile('index.ts', '', {
3132
overwrite: true,
3233
});
3334
const exportDeclarations = project
34-
.getRootDirectories()
35-
.map(directory => directory.getSourceFile('index.ts'))
35+
.getDirectories()
36+
.filter(d => d !== rootDirectory)
37+
.map(directory => {
38+
return directory.getSourceFileOrThrow('index.ts');
39+
})
3640
.map(sourcesFile => {
37-
assert(sourcesFile, 'Just created index source file not found');
3841
return {
3942
namedExports: sourcesFile
4043
.getExportSymbols()
@@ -44,5 +47,7 @@ function beforeGenerateFiles(args: EventArguments) {
4447
),
4548
};
4649
});
47-
sourceIndexFile.addExportDeclarations(exportDeclarations);
50+
if (exportDeclarations.length > 0) {
51+
sourceIndexFile.addExportDeclarations(exportDeclarations);
52+
}
4853
}

0 commit comments

Comments
 (0)