Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

address dual dts issues #60

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lovely-adults-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/build-utils": patch
---

generate proxy d.ts for cjs and esm, to address dual package hazard
patroza marked this conversation as resolved.
Show resolved Hide resolved
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 writeDtsFor = (module: string) =>
Effect.all([
fs.writeFileString(
`dist/dist/cjs/${module}.d.ts`,
`export * from "../dts/${module}"`,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

u could very well just do this to be more explicit:

Suggested change
`export * from "../dts/${module}"`,
`export * from "../dts/${module}.js"`,

the .js extension isn't forbidden in CJS-oriented .d.ts files

),
fs.writeFileString(
`dist/dist/esm/${module}.d.ts`,
`export * from "../dts/${module}.js"`,
),
])
const manageDTS = ctx.hasDts
? Effect.forEach(
ctx.hasMain ? ["index"].concat(modules) : modules,
writeDtsFor,
)
: Effect.unit

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
Loading