From c8851097debe68899578118328c8cd7cdc18d607 Mon Sep 17 00:00:00 2001 From: David Evans Date: Wed, 11 Nov 2020 21:04:59 +0000 Subject: [PATCH] Automatically resolve directory index files for declaration generation [#8] --- generateDeclaration.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/generateDeclaration.js b/generateDeclaration.js index cc65966..14b914e 100644 --- a/generateDeclaration.js +++ b/generateDeclaration.js @@ -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,