Skip to content

Commit

Permalink
fix: handle extension and hashbang
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 19, 2024
1 parent ab47a25 commit e4d9183
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async function getModules(path: string, prefix = ''): Promise<string[]> {
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')
Expand All @@ -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'
}
Expand Down
4 changes: 3 additions & 1 deletion src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ' {$')
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e4d9183

Please sign in to comment.