jonycheung / deadsimple-less-watch-compiler

A nodejs script that allows you to watch a folder for changes and compile the less css files into another folder.
MIT License
285 stars 70 forks source link

.less extension in @import is not optional in watch mode under some file structures #117

Open filipesilva opened 3 years ago

filipesilva commented 3 years ago

Which version are you using (less-watch-compiler --version to find out)? 1.14.6

Is the issue reproducible after updating to the latest version ( npm update less-watch-compiler)? yes

Describe the bug The LESS docs say that the .less extension is optional on imports.

But less-watch-compiler will throw an exception when it encounters such imports under very specific circumstances:

To Reproduce Steps to reproduce the behavior:

  1. My folder setup is

    .
    ├── css
    │   └── site.css
    ├── less
    │   ├── bem
    │   │   └── block
    │   │       └── file.less
    │   ├── color.less
    │   └── site.less

    The less/bem/block/file.less and less/color.less files are empty. The content of less/site.less is @import "color";.

  2. The command I ran is yarn less-watch-compiler less css site.less

  3. Something went wrong... What is it?

Actual behavior less-watch-compiler throws an error:

~/s/repro (master|●7+2…) $ 
yarn less-watch-compiler less css site.less
yarn run v1.22.5
$ /home/filipesilva/sandbox/repro/node_modules/.bin/less-watch-compiler less css site.less
Watching directory for file changes.
internal/fs/utils.js:220
    throw err;
    ^

Error: ENOENT: no such file or directory, stat '/home/filipesilva/sandbox/repro/less/color'
    at Object.statSync (fs.js:915:3)
    at Object.findLessImportsInFile (/home/filipesilva/sandbox/repro/node_modules/less-watch-compiler/dist/lib/filesearch.js:13:20)
    at Object.fileWatcher (/home/filipesilva/sandbox/repro/node_modules/less-watch-compiler/dist/lib/lessWatchCompilerUtils.js:225:38)
    at /home/filipesilva/sandbox/repro/node_modules/less-watch-compiler/dist/lib/lessWatchCompilerUtils.js:86:40
    at /home/filipesilva/sandbox/repro/node_modules/less-watch-compiler/dist/lib/lessWatchCompilerUtils.js:67:27
    at FSReqCallback.oncomplete (fs.js:159:5) {
  errno: -2,
  syscall: 'stat',
  code: 'ENOENT',
  path: '/home/filipesilva/sandbox/repro/less/color'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Expected behavior Should compile less files successfully.

Desktop (please complete the following information):

Additional context Using the --run-once flag will make it compile sucessfully.

Using the @import "color.less"; will make it compile sucessfully.

Removing the less/bem/block folder and leaving behind an empty less/bem folder will also make it compile sucessfully.

mhnaeem commented 2 years ago

I have been facing the same issue and the PR attached above fixed it for me. The basis for change was this line in LESS documentation

If it does not have an extension, .less will be appended and it will be included as a imported Less file.

Link: https://lesscss.org/features/#import-atrules-feature-file-extensions

@jonycheung Let me know if it works.