Apos2.222.0 - Invalid RegEx path.sep missing "\"
Even though it isn't recommended to run ApostropheCMS on Windows, I've found a small bug which is worth opening a PR for.
To Reproduce
Step by step instructions to reproduce the behavior:
- Running ApostropheCMS 2 branch release-2.222.0 on Windows
npm iinstalls packages fine on Node 14,16 and 18npm startis throwing an error with an invalid regular expression
Expected behavior
Apostrophe should start as expected
Describe the bug
Getting the following error when starting Apostrophe on a Windows environment:
kiichiro-toyoda-cms\node_modules\apostrophe\index.js:58
throw err;
^
SyntaxError: Invalid regular expression: /\node_modules\mocha\/: \ at end of pattern
at new RegExp (<anonymous>)
at getRoot (C:\Users\user\WebStormProjects\kiichiro-toyoda-cms\node_modules\apostrophe\index.js:259:35)
at module.exports (C:\Users\user\WebStormProjects\kiichiro-toyoda-cms\node_modules\apostrophe\index.js:35:33)
at Object.<anonymous> (C:\Users\user\WebStormProjects\kiichiro-toyoda-cms\app.js:334:35)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47
[nodemon] app crashed - waiting for file changes before starting...
A small update is required to a specific line within the root index.js file of the apostrophe release-2.222.0 branch, the following on line 259 should be updated from:
if (m.parent.filename.match(new RegExp(`${path.sep}node_modules${path.sep}mocha${path.sep}`))) {
to:
if (m.parent.filename.match(new RegExp(`${path.sep}node_modules${path.sep}mocha\${path.sep}`))) {
Details
Windows uses
Version of Node.js: Tested on Node 14, 16 and 18
Server Operating System: Microsoft Windows
Additional context: This is specific to Microsoft Windows, after forking at testing the above fix Apostrophe starts as expected including on both Linux and Mac.
Makes sense to submit a PR, please do. But the right way to avoid this would be to use self.apos.utils.regExpQuote so that you don't wind up with an unnecessary escape character for non-Windows path characters.