Menu

582 TypeScript files, 11 import cycles, and nine of them disappear when you delete the word type
📰

582 TypeScript files, 11 import cycles, and nine of them disappear when you delete the word type

DEV Community: nextjs·Daniel Pertu·2 days ago
#EZO3NYTv
#devtonextjs#devto#dev#schema#import
Reading 0:00
15s threshold

Every bundler builds a module graph and almost none of them will show you one. I wanted to know the shape of the code behind Nakodo rather than its weight: which file everything depends on, which files depend on nothing, and whether the dependency arrows ever go in a circle.

That took about forty lines of Python and no tooling, and the interesting results were all in the places my first version got wrong.

Resolving the edges

Two kinds of specifier matter in this codebase: @/ for the project root alias and ./ for relatives. Everything else is a package.

def resolve ( spec , src ) : if spec . startswith ( "@/" ) : base = Path ( "src" ) / spec [ 2 : ] elif spec . startswith ( "." ) : base = ( src . parent / spec ) . resolve ( ) else : return None # a package, not our code for c in ( base , base . with_suffix ( ".ts" ) , base . with_suffix ( ".tsx" ) , base / "index.ts" , base / "index.tsx" ) : if c .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.