scttcper / koa2-swagger-ui

Swagger UI as Koa v2 middleware

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Typescript refactor broke the dist

oliverjam opened this issue · comments

commented

Our pipeline just caught a regression in the latest minor version. We're getting koaSwagger is not a function whenever we try to initialise the middleware. I've reproduced the issue on Glitch here by installing the latest version and pasting the instructions from the Readme. If you run the server you can see the koaSwagger is not a function errors.

It looks like there are 2 separate issues:

  1. The new TS-built version of lib/index.js exports the main koaSwagger middleware with exports.default instead of module.exports. This means our const koaSwagger = require('koa2-swagger-ui') now gives us an object like this instead of the function we want: { default: [Function: koaSwagger] }
  2. If we patch the export to fix this we then get an error because the middleware cannot find index.hbs. It looks like this is because Typescript is only copying over .ts files in the build step. I pulled this repo and built locally and this is what my dist/ directory looks like compared to lib/:
.
├── dist
│   ├── index.d.ts
│   ├── index.js
│   └── index.js.map
├── lib
│   ├── favicon-16x16.png
│   ├── favicon-32x32.png
│   ├── index.hbs
│   └── index.ts

I don't have any TS experience, but my brief investigation suggests that TS only supports copying across .ts, .js and .jsx files, so the build process might need to include some other step for copying the other files.

Oh right

🎉 This issue has been resolved in version 2.11.1 🎉

The release is available on:

Your semantic-release bot 📦🚀