Skip to content
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

fix: Windows slash hell, controllers: [path.join(__dirname,"/api/controllers/*.ts") doesn't work on Windows #987

Closed
jcrka opened this issue Jan 9, 2023 · 2 comments · Fixed by #994
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.

Comments

@jcrka
Copy link

jcrka commented Jan 9, 2023

Description

I used routing-controllers about 2 years ago everything was fine. But today I created a new project and got strange issue.

const app = createExpressServer({
    controllers: [path.join(__dirname,"/api/controllers/*.ts")], // we specify controllers we want to use
});

doesn't find controllers on Windows

Expected behavior

const app = createExpressServer({
    controllers: [path.join(__dirname,"/api/controllers/*.ts")], // we specify controllers we want to use
});

controllers are found

Actual behavior

path.join converted to \api\controllers (windows slash) and glob failing

const app = createExpressServer({
    controllers: [path.join(__dirname,"/api/controllers/*.ts").replace(/\\/g, '/')], // we specify controllers we want to use
});

still no luck, because in /util/importClassesFromDirectories.js

const allFiles = directories.reduce((allDirs, dir) => {
        // eslint-disable-next-line @typescript-eslint/no-var-requires
        return allDirs.concat(require('glob').sync(path.normalize(dir)));
    }, []);

path.normalize again converts / to \ and glob failing again

after removing path.normalize (hardcoded in node_modules for science)

   const allFiles = directories.reduce((allDirs, dir) => {
        // eslint-disable-next-line @typescript-eslint/no-var-requires
        // return allDirs.concat(require('glob').sync(path.normalize(dir)));
        return allDirs.concat(require('glob').sync(dir));
    }, []);

controllers are finally found

Is it a bug ? Or i need some better workarounds ?

Environment

Windows 11
Node v16.13.1

"glob":"8.0.3"
"typedi": "^0.10.0",
"routing-controllers":"0.10.0"
"typescript": "^4.9.4"
"ts-node-dev": "^2.0.0" (issue reproduced in compiled js too though)

@jcrka jcrka added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels Jan 9, 2023
@attilaorosz
Copy link
Member

Seems like glob@8 introduced a change that is breaking windows paths. isaacs/node-glob#467

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.
Development

Successfully merging a pull request may close this issue.

2 participants