Skip to content

jsonOutput doesn't play well with watchify + symlinks #105

Open
@chiel

Description

@chiel

Hi there, I'm having an issue with css modules when used in combination with watchify.

The problem seems to be that on the first run, symlinks don't get resolved properly, but they do on subsequent runs triggered by watchify. This leads to paths varying between runs and the styles.json not being output correctly.

Example

Let's say I have the file ./dist/app/styles/app.css, which is also symlinked as ./node_modules/app/styles/app.css, with the following contents:

.container {
    min-height: 100vh;
}

Running this through watchify + css-modulesify with the rootDir set to process.cwd() + '/node_modules' will generate a json file that looks like this (prettified for convenience):

{
    "app/styles/app.css": {
        "container":"_app_styles_app__container"
    }
}

Perfect, this is exactly what you'd expect. However, saving app.css will trigger a rebuild in watchify so a new json file is generated with the following contents:

{
    "app/styles/app.css": {
        "container":"_app_styles_app__container"
    },
    "es/app.css": {
        "container":"_dist_app_styles_app__container"
    }
}

As you can see there are two issues here:

  1. The file path is wrong, and looks very odd, being clipped off like that (this is actually due to how the normalised file paths are being generated, based on the rootDir option).
  2. The generated class name is different, and contains the extra _dist part at the start of it.

I am not sure why the results vary between runs, nor am I sure why the _dist gets added, but my gut feeling is that this issue can potentially be solved by always using something like fs.realpath() to resolve any symlinks that might be in place.

I have been looking into the code and started debugging things a bit, so I can hopefully come up with a solution and open a pull request but I just wanted to create this issue to see if anyone else is running into a similar issue, or if there is an easy fix for it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions