marko-js / cli

command-line tools for Marko
MIT License
94 stars 36 forks source link

@marko/serve@2.1.1 - Using directory path on Windows is broken #175

Closed ghost closed 3 years ago

ghost commented 4 years ago

@marko/serve@2.1.1

Details

Using a directory path on Windows (e.g. marko-serve ./pages) does not work.

Expected Behavior

Using a directory path works as documented.

marko-serve ./pages # serve a pages directory

Actual Behavior

When a directory path is used, the script attempts to do all kinds of naughty things like stat my pagefile. This causes my laptop to get flustered and spool up its fan. The cause of excess system load appears to be chokidar watching from the drive root (C:), not the project root.

Possible Fix

Not sure yet.

Additional Info ### Your Environment Windows Server 2016. Reproducible on any Windows OS. ### Steps to Reproduce 1. Run Node.js on Windows 2. Run a @marko/cli command using a relative path. 3. Immediately terminate the process before your hardware melts down. ### Stack Trace Key evidence: `ERROR in EPERM: operation not permitted, stat 'C:\System Volume Information' @ ../node_modules/webpack-inject-plugin/dist/webpack-inject-plugin.loader.js?id=webpack-inject-module-3 2:10-7:5 @ multi ../node_modules/webpack-inject-plugin/dist/webpack-inject-plugin.loader?id=webpack-inject-module-2 ../node_modules/webpack-inject-plugin/dist/webpack-inject-plugin.loader?id=webpack-inject-module-3 ../node_modules/webpack-inject-plugin/dist/webpack-inject-plugin.loader?id=webpack-inject-module-1 ../node_modules/@marko/build/dist/files/server.js i 「wdm」: Failed to compile. Error from chokidar (/): Error: EBUSY: resource busy or locked, lstat 'C:\pagefile.sys' Error from chokidar (\): Error: EBUSY: resource busy or locked, lstat 'C:\pagefile.sys' Error from chokidar (\Documents and Settings): Error: EBUSY: resource busy or locked, lstat 'C:\pagefile.sys'`
ghost commented 4 years ago

@marko/build works as expected with a directory path, so this appears to be isolated to @marko/serve.

Webpack docs note the following:

Windows Paths Because webpack expects absolute paths for many configuration options such as __dirname + '/app/folder' the Windows \ path separator can break some functionality.

Use the correct separators. I.e. path.resolve(dirname, 'app/folder') or path.join(dirname, 'app', 'folder'). https://webpack.js.org/configuration/watch/#windows-paths

This article has some helpful tips on cross-platform path handling: https://shapeshed.com/writing-cross-platform-node/

ghost commented 4 years ago

Unable to reproduce after one small change in build/src/util.js:60

${JSON.stringify(cwd + path.sep)}+ _