Skip to content

Commit

Permalink
Automatically resolve directory index files for declaration generation [
Browse files Browse the repository at this point in the history
  • Loading branch information
davidje13 committed Nov 11, 2020
1 parent 603b287 commit c885109
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions generateDeclaration.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
const typescript = require('typescript');
const { statSync } = require('fs');
const { join } = require('path');

module.exports = function(neutrino, declarationMap) {
const rawOptions = typescript.getDefaultCompilerOptions();
const sources = Object.values(neutrino.options.mains).map((entry) => {
if (typeof entry === 'object') {
return entry.entry;
}
return entry;
});
const sources = Object.values(neutrino.options.mains)
.map((entry) => {
if (typeof entry === 'object') {
return entry.entry;
}
return entry;
})
.map((source) => {
try {
const sourceStat = statSync(source);
if (sourceStat.isDirectory()) {
return join(source, 'index');
}
} catch (ignore) {
// filenames without extensions are allowed
}
return source;
});

const options = {
...rawOptions,
Expand Down

0 comments on commit c885109

Please sign in to comment.