StefanTerdell / json-schema-to-zod

ISC License
322 stars 46 forks source link

Please remove `fs` module from the dist #80

Closed NWYLZW closed 8 months ago

NWYLZW commented 9 months ago

When I use version @2 in my project and pack it with webpack, the repository imports the fs module.

image

However, the fs module is only supported for the CLI and is not necessary for common use cases.

StefanTerdell commented 8 months ago

However, the fs module is only supported for the CLI and is not necessary for common use cases.

This is primarily a CLI, so I disagree.

What is your use-case?

NWYLZW commented 8 months ago

I have agreed with the server to use JSON Schema as the serialization format between us. When I receive a serialized string from the server, I use your tool to convert it into a code string that defines the object using Zod. Finally, I obtain an instance object of Zod.

For your tool, it seems that only one function is using it. However, if you implement it on the CLI side, your tool can easily be used as a CLI on both browsers and servers. https://github.com/StefanTerdell/json-schema-to-zod/blob/c1d47eecf14ef85ee39a04fbb8b483a4a82f8d90/src/utils/cliTools.ts#L110-L118

StefanTerdell commented 8 months ago

I will not remove the function because it is crucial for the CLI to work and the use-case is a bad idea to begin with. Please see the last section of the readme.

Your options are to:

  1. Fork the repo, remove the CLI parts, republish.
  2. Create a PR that separates out the CLI parts in a reasonable manner, preferably without breaking changes.
  3. Validate the JSON Schema you already have with a tool like AJV. This is the only reasonable option btw but you do you.

Good luck

NWYLZW commented 8 months ago

I will try the second option. Thanks for your reply.

StefanTerdell commented 8 months ago

@NWYLZW I think 2.0.14 may have solved your issue. WebPack should be able to ignore it now.

NWYLZW commented 8 months ago

Thank your work, I will try this version later