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

remove namespace and use namepace import instead for tree-shaking #35

Open
ryoppippi opened this issue Jul 16, 2024 · 3 comments
Open
Assignees
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@ryoppippi
Copy link
Contributor

As we worked on typia, I'll do this

@ryoppippi ryoppippi changed the title remove namespace for tree-shaking remove namespace and use namepace import instead for tree-shaking Jul 16, 2024
@ryoppippi
Copy link
Contributor Author

ryoppippi commented Sep 9, 2024

@samchon
After merged typia.llm.application<App>() functions in typia, I want to use this library.
However, this library has an issue of treeshaking because of use of namespace.

The reason for the emphasis on tree-shaking is that the smaller the bundle size, the better, not only for frontend but also for lambda and cloudflare workers.

That is why I'd like you to stop using namespace...

@samchon
Copy link
Owner

samchon commented Sep 10, 2024

I know that avoiding namespace is proper for downsizing disk space. As namespace is recommended style in the C++ language due to efficient grouping and managing code, and I've developed C++ language for a long time, it's not easy to change my coding style in a day.

One thing fortunate is, current typia.llm.application<App>() is importing LlmTypeChecker and LlmSeparator modules, and their disk size is very small. Also, as they are strongly dependent to each other, no significant merit by tree shaking would be. The other modules like HttpLlm and HttpMigration have the same story.

However, I also considering about the OpenApi module. People who use @samchon/openapi may utilize OpenApi.convert() function a lot, but OpenApi.downgrade() may not. So tree-shaking by escaping namespace may read significant disk space downsizing. However, I don't have proper solution to here yet.

In this v1 major update, I one time considered to escape namespaces and keeping ESM tree shaking by entirely refactoring the @samchon/openapi, however, I cound't do it due to below reason. It was possible to entirely break the namespace structure in the typia (maybe v7 major update), but could not in @samchon/openapi. I hope to keep current namespace structure at least for the interface types.

In the namespace. Is it possible to add utility functions in the namespace with keeping ESM tree-shaking?

If you have any good idea, please help me.

  • Hope to gather same categorized interfaces into a namespace.
    • Good for reading and comparing
    • When learning OpenAPI specification, it needs to be read entirely
  • Considering not to using namespace, I have to define individual interface files, and re-export them. However, as there're many OpenAPI versions in this @samchon/openapi library, the re-exporting interface types may lead users to confusing. At least, I hope to keep current namespace defined interface types.
    • Confusing
      • IOpenApiOperation (@samchon/openapi emended v3.1 spec)
      • IOpenApiV3_1IOperation
      • IOpenApiV3_IOperation
      • IOpenApiDocument
      • IOpenApiV3_0JsonSchema
    • Clear
      • OpenApi.IDocument
      • OpenApiV3.IJsonSchema
  • In the namespace, is it possible to add convert() and downgrade() functions with keeping ESM tree-shaking?

@samchon samchon added help wanted Extra attention is needed good first issue Good for newcomers labels Sep 10, 2024
@ryoppippi
Copy link
Contributor Author

@samchon
Thank you for your reply as always.

I think using export field is one solution

for example

import { convert } from '@samchon/openai/i-open-api-v31'

like so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants