kogosoftwarellc / open-api

A Monorepo of various packages to power OpenAPI in node
MIT License
895 stars 237 forks source link

fs-routes: Fixes backslash issue on Windows #877

Open renkei opened 1 year ago

renkei commented 1 year ago

Fixes #868 and #871. It fixes the issue at an early stage of the scan-path-for-routes-procedure. Because fs-routes is responsible for resolving routes it should take care that routes are well-formed. This ensures that consuming packages don't need to care about this.

renkei commented 1 year ago

I've found out that downgrading glob from version 10 to 7 also fixes the issue. Currently, package express-openapi comes with a "glob": "*" dependency, changing this into "glob": "7" would also solve the issue. Anyway, I still prefer this PR to be independent of the format returned by glob.

renkei commented 1 year ago

I've updated my PR because I've probably found a more elegant solution. Instead of calling replace(/\\/, '/') to get rid of backslashes for routes on Windows, we can use the glob option posix: true that was introduced with glob 10.1.0, this I've found in the glob changelog

Add posix: true option to return / delimited paths, even on Windows.

I've also updated package.json and package-lock.json to request the latest glob version >= 10.2.7

alex77h commented 11 months ago

would love to see this merged. hope this project isnt abandoned - long time no update...

anthonyloukinas commented 10 months ago

Would also love this merged. I tested this on Windows and it fixes the issues I was having using {id}.js file formatting (Using the curly braces).

.sync(options.glob, { cwd: dir, posix: true })

Setting that posix: true works.

mystiker commented 1 month ago

Please merge this!

mystiker commented 1 month ago

I've found out that downgrading glob from version 10 to 7 also fixes the issue. Currently, package express-openapi comes with a "glob": "*" dependency, changing this into "glob": "7" would also solve the issue. Anyway, I still prefer this PR to be independent of the format returned by glob.

Can you please elaborate how you done this? I tried to set the following in my package.json in a project referencing express-openapi:

  "overrides": {
    "express-openapi": {
      "glob": "7"
    }
  },

But to no avail. Might be because I am using a somewhat complex monorepo with npm modules and maybe the resolution does not work as I expect.