-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: introduce tsup for bundling #25
Conversation
I have tested these changes by run the import { fromTraffic } from '@mswjs/source'
import { default as json } from './__data__/health-check.json'
it.only('should throw exception when all services are unavailable', async () => {
server.use(
...fromTraffic(json),
// rest.get('https://localhost:30001/-/health', (_req, res, _ctx) => {
// res.networkError('Network Error')
// }),
// rest.get('https://localhost:30002/-/health', (_req, res, _ctx) => {
// res.networkError('Network Error')
// }),
)
await expect(controller.check()).rejects.toThrow('Service Unavailable Exception')
}) For me, after these changes, the above unit test was passing without errors. The project is a Nest.js project using Typescript. Note I currently don't have a ESM only project ready to test if the ESM module part of the package works as expected. I will try to do make one tomorrow. |
It'd be great to have automated tests in different formats (CJS/ESM) that help us catch regressions regarding module format incompatibilities. |
508ae8e
to
48a02f4
Compare
@weyert, I'm sorry, I think I've just messed up the commit authorship after rewording the commit. Could you please |
Added the package `tsup` to assist in bundling `@mswjs/source`-package so it both supports CommonJS and ESM modules. The `package.json` file has been modified so the appropriate properties for the modern `exports`-approach of exporting, and the older `main`-`module` combination. During building and running the tests the `fromOpenApi` had issues to pass the tests or build due to the way the `SwaggerParser` utility class was exporter. The code has been updated so it refers to the `deferences`-function via `SwaggerParser.deferences()` instead of trying to instantiate the class. For this reason the `tsconfig.json` has been updated so that it enables `esModuleInterop` and `allowSyntheticDefaultImports` after this change the package build and bundled successfully with `tsup` and passed the unit tests, before errors like below were shown: src/fromOpenApi/fromOpenApi.ts:16:35 - error TS2351: This expression is not constructable. Type 'typeof SwaggerParser' has no construct signatures. 16 const specification = await new SwaggerParser().dereference(document) ~~~~~~~~~~~~~
48a02f4
to
db1b96a
Compare
I think I did now but not 100% sure |
Yeah, good idea, I am not sure what the best approach is. Maybe a simple script that |
@weyert, you've set the commit author to @tapico-weyert. If it's the expected result then everything is okay! |
Released: v0.1.0 🎉This has been released in v0.1.0! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
Added the package
tsup
to assist in bundling@mswjs/source
-package soit both supports CommonJS and ESM modules. The
package.json
file hasbeen modified so the appropriate properties for the modern
exports
-approachof exporting, and the older
main
-module
combination.During building and running the tests the
fromOpenApi
had issuesto pass the tests or build due to the way the
SwaggerParser
utilityclass was exporter. The code has been updated so it refers to
the
deferences
-function viaSwaggerParser.deferences()
instead of tryingto instantiate the class.
For this reason the
tsconfig.json
has been updated so that it enablesesModuleInterop
andallowSyntheticDefaultImports
after this changethe package build and bundled successfully with
tsup
and passed theunit tests, before errors like below were shown: