-
-
Notifications
You must be signed in to change notification settings - Fork 287
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
feat: add types support to esm bundle for lightclient #6685
Changes from all commits
8f6ff50
3d129b7
bf45779
85680ef
0623e1a
5322591
5117caa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
import path from "node:path"; | ||
import fs from "node:fs/promises"; | ||
import {defineConfig, mergeConfig} from "vite"; | ||
import dts from "vite-plugin-dts"; | ||
import {getBaseViteConfig} from "../../vite.base.config.js"; | ||
|
||
import pkgJSON from "./package.json"; | ||
|
||
export default mergeConfig( | ||
getBaseViteConfig(pkgJSON, {libName: "LightClient", entry: "src/index.ts"}), | ||
defineConfig({ | ||
plugins: [ | ||
dts({ | ||
rollupTypes: true, | ||
bundledPackages: ["@lodestar/*", "@chainsafe/persistent-merkle-tree", "@chainsafe/bls", "@chainsafe/ssz"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do you come up with this list? Is there no way to automate this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By building the types buyndle and investigating the types import in it. The ideal scenario we want is there should not be any thirdparty types import in types bundle. |
||
async afterBuild() { | ||
await fs.rename( | ||
path.join(import.meta.dirname, "dist", "index.d.ts"), | ||
path.join(import.meta.dirname, "dist", "lightclient.min.d.mts") | ||
); | ||
}, | ||
}), | ||
], | ||
build: { | ||
rollupOptions: { | ||
output: { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
export * from "./types.js"; | ||
export * as ts from "./types.js"; | ||
export * as ssz from "./sszTypes.js"; | ||
|
||
// We have to use import->export because of the limitation in `@microsoft/api-extractor` | ||
// which is used to bundle the package types | ||
import * as ts from "./types.js"; | ||
import * as ssz from "./sszTypes.js"; | ||
export {ts, ssz}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./types.js"; | ||
export * as ts from "./types.js"; | ||
export * as ssz from "./sszTypes.js"; | ||
import * as ts from "./types.js"; | ||
import * as ssz from "./sszTypes.js"; | ||
export {ts, ssz}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./types.js"; | ||
export * as ts from "./types.js"; | ||
export * as ssz from "./sszTypes.js"; | ||
import * as ts from "./types.js"; | ||
import * as ssz from "./sszTypes.js"; | ||
export {ts, ssz}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./types.js"; | ||
export * as ts from "./types.js"; | ||
export * as ssz from "./sszTypes.js"; | ||
import * as ts from "./types.js"; | ||
import * as ssz from "./sszTypes.js"; | ||
export {ts, ssz}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./types.js"; | ||
export * as ts from "./types.js"; | ||
export * as ssz from "./sszTypes.js"; | ||
import * as ts from "./types.js"; | ||
import * as ssz from "./sszTypes.js"; | ||
export {ts, ssz}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./types.js"; | ||
export * as ts from "./types.js"; | ||
export * as ssz from "./sszTypes.js"; | ||
import * as ts from "./types.js"; | ||
import * as ssz from "./sszTypes.js"; | ||
export {ts, ssz}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * as ts from "./types.js"; | ||
export * as ssz from "./sszTypes.js"; | ||
import * as ts from "./types.js"; | ||
import * as ssz from "./sszTypes.js"; | ||
export {ts, ssz}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This checks the tests file as well and one test file is using the types imported from the bundle. So we have to build it before running types check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we solve this differently? Having this build run as part of check-types is really annoying during local development. check-types is supposed to be fast and not create a bundle for production
This takes more time than all other check-types across all packages combined
It also creates a untracked file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it also randomly fails, see CI https://github.com/ChainSafe/lodestar/actions/runs/8911114728/job/24471848781#step:4:124