jscad / OpenJSCAD.org

JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.
https://openjscad.xyz/
MIT License
2.65k stars 514 forks source link

refactor(all): use named import/export for ES modules #1208

Closed platypii closed 1 year ago

platypii commented 1 year ago

This is what it would look like if we got rid of all the export default in the V3 branch, and instead use named import/exports for everything.

I think it's a good best practice. Instead of there being two ways to do something, this makes it so that we are consistent in always doing it one way. No need to think about how to import or export. This removes the need to add "export default" at the bottom of each file, so it saves hundreds of lines of code. It feels like cleaner use of ES modules.

Everything is exactly the same for users. The exported API doesn't change at all. This just simplifies how modules are imported internally in the codebase.

Let me know what you guys think.

All Submissions:

z3dev commented 1 year ago

@garyhodgson what do you think?

personally, I like simple concise code. Which makes maintenance far easier.

@platypii is there a way to configure JSLint to flag default exports?

platypii commented 1 year ago

Just pushed some last minute cleanup of the imports. I think it's good now.

There is an ESLint rule no-default-export that we could set, but eslint appears to not be setup currently?

z3dev commented 1 year ago

Just pushed some last minute cleanup of the imports. I think it's good now.

There is an ESLint rule no-default-export that we could set, but eslint appears to not be setup currently?

The basic rules are from sandardx but additional rules can be set. See package.json

platypii commented 1 year ago

Added lint check. Also made some more updates: updated import/export for packages outside of modeling, and removed default exports from typescript .d.ts files.

z3dev commented 1 year ago

reviewing... but there's a lot of file... ;)

z3dev commented 1 year ago

@platypii anything else pending? if not then i will merge.

platypii commented 1 year ago

Yup looks good!