Skip to content

Commit

Permalink
feat: support nested exposures
Browse files Browse the repository at this point in the history
closed #4
  • Loading branch information
ruanyl committed Jul 25, 2021
1 parent 13e9fc0 commit 557e3db
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,23 @@ function emitFile(
) {
for (const [key, value] of Object.entries(loaderOptions.exposes)) {
if (key && value) {
const entryPath = path.resolve(cwd, value)
if (entryPath === fileName) {
const inputFilePath = path.resolve(cwd, value)
if (inputFilePath === fileName) {
const moduleFilename = `${key}.d.ts`
const modulePath = path.resolve(
cwd,
`${loaderOptions.typesOutputDir}/${loaderOptions.name}`
)
const dtsEntryPath = path.resolve(modulePath, moduleFilename)
const relativePathToOutput = path.relative(
path.dirname(dtsEntryPath),
o.name.replace('.d.ts', '')
)

fs.ensureFileSync(dtsEntryPath)
fs.writeFileSync(
path.resolve(modulePath, moduleFilename),
`export * from './${path.relative(
path.relative(cwd, modulePath),
o.name.replace('.d.ts', '')
)}';\nexport { default } from './${path.relative(
path.relative(cwd, modulePath),
o.name.replace('.d.ts', '')
)}';`
dtsEntryPath,
`export * from './${relativePathToOutput}';\nexport { default } from './${relativePathToOutput}';`
)
}
}
Expand Down

0 comments on commit 557e3db

Please sign in to comment.