diff --git a/src/build.ts b/src/build.ts index 829ce2e..25fae59 100644 --- a/src/build.ts +++ b/src/build.ts @@ -44,7 +44,7 @@ async function getModules(path: string, prefix = ''): Promise { export async function build(cwd: string, args: string[] = []) { const require = createRequire(cwd + '/') const config = await load(cwd, args) - const outFile = config.get('outFile') + const outFile = config.get('outFile', 'lib/index.d.ts') if (!outFile) throw new Error('outFile is required') const rootDir = config.get('rootDir') if (!rootDir) throw new Error('rootDir is required') @@ -60,8 +60,8 @@ export async function build(cwd: string, args: string[] = []) { const { inline = [], exclude = [] } = config.dtsc || {} files.push(...inline) for (const extra of inline) { - const meta = require(extra + '/package.json') - const filename = join(extra, meta.typings || meta.types) + const manifest = require(extra + '/package.json') + const filename = join(extra, manifest.typings || manifest.types) const content = await fs.readFile(require.resolve(filename), 'utf8') source += [`declare module "${extra}" {`, ...content.split('\n')].join('\n ') + '\n}\n' } diff --git a/src/bundle.ts b/src/bundle.ts index 1213b4f..64315ad 100644 --- a/src/bundle.ts +++ b/src/bundle.ts @@ -9,7 +9,7 @@ export interface BundleOptions { export async function bundle(options: BundleOptions) { const { files, source, exclude = [] } = options - const moduleRE = `["'](${files.join('|')})["']` + const moduleRE = `["'](${files.join('|')})(\\.[jt]s)?["']` const internalImport = new RegExp('import\\(' + moduleRE + '\\)\\.', 'g') const internalExport = new RegExp('^ {4}export .+ from ' + moduleRE + ';$') const internalInject = new RegExp('^declare module ' + moduleRE + ' {$') @@ -73,6 +73,8 @@ export async function bundle(options: BundleOptions) { }) } else if (line.startsWith('///')) { prolog += line + EOL + } else if (line.startsWith('#!')) { + return false } else if (line.startsWith(' export default ')) { if (current === 'index') return true if (line.endsWith('{')) isExportDefault = true