-
Notifications
You must be signed in to change notification settings - Fork 63
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
Stricter extension name typing, changed build system and test system #80
Conversation
…to use esbuild and vite
// Cannot constraint to "^x-" but can filter them later to access to them | ||
[extensionName: string]: any; | ||
} | ||
export type IExtensionName = `x-${string}`; |
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.
With newer versions of typescript you can actually strongly type a string prefix, which is nice
build.mjs
Outdated
const entryPoints = glob | ||
.sync('src/**/*.ts', { root: path.join(__dirname, 'src') }) | ||
.filter((l) => !l.includes('spec.ts')); | ||
await esbuild.build({ |
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 is significantly faster than tsc
(~50x for this project)
@@ -0,0 +1,18 @@ | |||
import { defineConfig } from 'vitest/config'; | |||
|
|||
export default defineConfig({ |
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.
vitest
s are significantly faster than mocha
- they all complete in ~500ms
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.
Hi @jonluca:
First of all, thank you very much for your contribution & time devoted.
Looking your PR, I see it can be splitted in 3 different parts, I want to comment about them independently:
- Improving the type checking for
x-*
extensions point. - Using a new framework for tests:
vitest
instead ofmocha
. - Using a new build framework
esbuild
instead oftsc
.
My comments on them:
-
For the first one. Its a clear improvement. We can incorporate it. Now the TS type system in newer versions is more expressive for cases like this one. Thank you for the improvement.
-
Using
vitest
instead ofmocha
is more a question of taste. Gaining some seconds when running tests is only a marginal gain (compared to forcing users/maintainers to use/learn a new tool/framework). Mocha has many plugins, once I was using was mocha-teamcity-reporter that was lost on your PR. Maybe can achieve same missing funtionality with vitest-teamcity-reporter. Anyway not against the usage ofvitest
, just pondering the pros & cons as selecting development frameworks always has. -
Using a new build framework.
esbuild
. I read a bit about its documentation:esbuild
basically erase the type info with a explicit NO-TYPE-CHECKING (see https://esbuild.github.io/content-types/#typescript). And you still need to usetsc -noEmit
to check the types. Your bet here is about improving build times (x50 accordingly to your report).
My main concern here is to preserve the library as close as possible to TSC to preserve backward compatibility and do strict type checking. A great majority of openapi3-ts clients are consuming it directly from Typescript.
- So a faster build here is only marginal gain for maintainers when building the JS version (build time before publishing the lib).
- TS users will use TS files from the library (if they want to, included in the redistribution package) so they can build/bundle with any tool (tsc, esbuild or other: not opinionated here).
- Also
esbuild
does not support: "Features that need a type system are not supported" (emitDecoratorMetadata & declaration) from docs. In the roadmap for the library, having metadata and providing decorators are a feature I want to dig in.
So, for the reasons just explained, I feel keep usingtsc
is a safer and more convenient, for the moment, for long term support than jumping into theesbuild
wagon for now. I am totally OK is the price to pay here is library build speed.
Looking forward to hear your comments about it @jonluca
So far, I am ready to merge PRs for (1) and (2) and postponing (3) if we both agree on that.
Thank you!
Hi @pjmolina - that sounds very reasonable. I agree with all your points. Let me add in the I've updated the diff removing esbuild and only using One question - I can't seem to find the travis build anywhere, https://www.travis-ci.com/metadevpro/openapi3-ts just 404s |
I also created ESM and CJS versions of the package |
Excellent, thank you. |
@@ -1 +1 @@ | |||
export * from './OpenApiBuilder'; | |||
export * from './OpenApiBuilder.js'; |
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.
Do you really need the .js
extension for any use case?
I was following the TS convention of avoiding extensions on imports to refer TS/JS files depending on the context (edit time)/(build time).
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 prevents issues with module resolution in node ESM exports. It's very annoying, I agree
More context there, but for now this is the simplest fix.
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.
Thanks for the explanation. Agreed, let's keep the extensions.
"removeComments": true, | ||
"preserveConstEnums": true, | ||
"noEmitHelpers": true, | ||
"outDir": "dist", |
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.
Changing the outDir=dist
in favor of dist/mjs
and dist/cjs
is a good improvement, but also a breaking change.
We can publishing it as 3.0.0 to warn consumers and preserve SemVer semantics.
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.
If you can change the version number, please. I think we are all done and ready to merge.
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.
Sounds good!
A nice script around this is semantic-release
- you can see an example here https://github.com/jonluca/har-to-openapi/blob/main/.github/workflows/release.yml
It's nice because you never have to update package.json yourself, and it deploys automatically based on your commits. Not saying we need to include it here, but something nice to keep in mind.
Updated the diff with 3.0.0
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.
Good point, thanks!
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.
Looks great to me.
Thanks @jonluca
Merging!
Version 2.1.0
2022.08.07