Skip to content

Commit

Permalink
address dual dts issues
Browse files Browse the repository at this point in the history
  • Loading branch information
patroza committed Mar 27, 2024
1 parent b6b14f3 commit 16a43c1
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/PackV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const run = Effect.gen(function*(_) {
}

if (ctx.hasMain && ctx.hasDts) {
out.types = "./dist/dts/index.d.ts"
out.types = "./dist/cjs/index.d.ts"
}

out.exports = {
Expand All @@ -80,7 +80,6 @@ export const run = Effect.gen(function*(_) {

if (ctx.hasMain) {
out.exports["."] = {
...(ctx.hasDts && { types: "./dist/dts/index.d.ts" }),
...(ctx.hasMainEsm && { import: "./dist/esm/index.js" }),
...(ctx.hasMainCjs && { default: "./dist/cjs/index.js" }),
}
Expand All @@ -91,7 +90,6 @@ export const run = Effect.gen(function*(_) {
...out.exports,
...ReadonlyRecord.fromEntries(modules.map(_ => {
const conditions = {
...(ctx.hasDts && { types: `./dist/dts/${_}.d.ts` }),
...(ctx.hasEsm && { import: `./dist/esm/${_}.js` }),
...(ctx.hasCjs && { default: `./dist/cjs/${_}.js` }),
}
Expand All @@ -110,14 +108,31 @@ export const run = Effect.gen(function*(_) {
return out
})

const manageDTS = Effect.gen(function*($) {
const writeFor = (module: string) =>
Effect.all([
fs.writeFileString(
`dist/dist/cjs/${module}.d.ts`,
`export * from "../dts/${module}"`,
),
fs.writeFileString(
`dist/dist/esm/${module}.d.ts`,
`export * from "../dts/${module}.js"`,
),
])
if (ctx.hasDts) {
yield* $(writeFor("index"))
yield* $(Effect.forEach(modules, writeFor))
}
})

const createProxies = Effect.forEach(
modules,
_ =>
fsUtils.mkdirCached(`dist/${_}`).pipe(
Effect.zipRight(fsUtils.writeJson(`dist/${_}/package.json`, {
main: path.relative(`dist/${_}`, `dist/dist/cjs/${_}.js`),
module: path.relative(`dist/${_}`, `dist/dist/esm/${_}.js`),
types: path.relative(`dist/${_}`, `dist/dist/dts/${_}.d.ts`),
sideEffects: [],
})),
),
Expand Down Expand Up @@ -177,6 +192,7 @@ export const run = Effect.gen(function*(_) {
], { concurrency: "inherit", discard: true }),
Effect.withConcurrency(10),
)
yield* _(manageDTS)
}).pipe(
Effect.provide(
Layer.mergeAll(
Expand Down

0 comments on commit 16a43c1

Please sign in to comment.