JetBrains / web-types

JSON standard for documenting web component libraries for IDEs, documentation generators and other tools
Apache License 2.0
285 stars 25 forks source link

When running vue-docgen-web-types in watch mode on Windows, file changes do not take effect #73

Closed anyesu closed 1 year ago

anyesu commented 1 year ago

Describe the bug

Run on Windows.

filePath from glob is POSIX style :

src/components/HelloWorld.vue

changedFilePath from chokidar is Windows style :

src\components\HelloWorld.vue

So when calling cachedContent[filePath] = ... , new content will be added instead of replace, because the key is different.

https://github.com/JetBrains/web-types/blob/8b566c3bb87b2a45dd6bbc19c7106e689453e125/gen/vue-docgen-web-types/src/build.ts#L76-L79

Reproduction

https://stackblitz.com/edit/vitejs-vite-eqvcdt?file=src%2Fcomponents%2FHelloWorld.vue&terminal=dev

Steps to reproduce

Download Project and run on Windows .

npm i && npm run dev

You can see the web-types.json file in the root directory:

{
  "framework": "vue",
  "name": "vite-vue-starter",
  "version": "0.0.0",
  "contributions": {
    "html": {
      "description-markup": "markdown",
      "types-syntax": "typescript",
      "tags": [
        {
          "name": "HelloWorld",
          "description": "",
          "attributes": [
            {
              "name": "msg",
              "description": "This is msg.",
              "value": {
                "kind": "expression",
                "type": "string"
              }
            }
          ],
          "source": {
            "module": "./src/components/HelloWorld.vue",
            "symbol": "default"
          }
        }
      ]
    }
  }
}

Then modify the JSDoc in src\components\HelloWorld.vue , the web-types.json will be auto updated:

  {
    "framework": "vue",
    "name": "vite-vue-starter",
    "version": "0.0.0",
    "contributions": {
      "html": {
        "description-markup": "markdown",
        "types-syntax": "typescript",
        "tags": [
          {
            "name": "HelloWorld",
            "description": "",
            "attributes": [
              {
                "name": "msg",
-               "description": "This is msg.",
                "value": {
                  "kind": "expression",
                  "type": "string"
                }
              }
            ],
            "source": {
              "module": "./src/components/HelloWorld.vue",
              "symbol": "default"
            }
          },
          {
            "name": "HelloWorld",
            "description": "",
            "attributes": [
              {
                "name": "msg",
+               "description": "This is a msg.",
                "value": {
                  "kind": "expression",
                  "type": "string"
                }
              }
            ],
            "source": {
              "module": "./src/components/HelloWorld.vue",
              "symbol": "default"
            }
          }
        ]
      }
    }
  }

You can see that there are two tags with the same name HelloWorld , but with different description attribute.

So the old content will be matched when IDEA load the web-types.json file, because it is written in the front.

piotrtomiak commented 1 year ago

Thanks for the PR!