activeguild / vite-plugin-sass-dts

This is a plugin that automatically creates a type file when using the CSS module type-safely.
MIT License
120 stars 19 forks source link

I am seeing this exact problem in version 1.3.16, has it re-appeared, or am I doing something wrong? #89

Closed mkholt closed 11 months ago

mkholt commented 11 months ago

This seems to be the same issue as #64

On version 1.3.16.

I have: /assets/styles/_index.scss /pages/index/main.module.scss

vite.config.ts specifies:

plugins: [react({}), ssr({}), sassDts({
    enabledMode: ['development', 'production'],
    global: {
      generate: true,
      outputFilePath: path.resolve(__dirname, "./@types/style.d.ts"),
    },
  })]

A file main.module.scss.d.ts is generated:

import globalClassNames from "....@types/style.d";
declare const classNames: typeof globalClassNames & {
  readonly hero: "hero";
  readonly headerImage: "headerImage";
};
export = classNames;

Note that ....@types/style.d should be `../../@types/style.d´

Originally posted by @mkholt in https://github.com/activeguild/vite-plugin-sass-dts/issues/64#issuecomment-1873340416

mkholt commented 11 months ago

Using path.join in another part of the project, and seeing ..\..\somefolder being replaced with ....somefolder, I suspect it might have something to do with the platform-specfic separator being an issue somewhere.

For completeness, I am working on a Windows system

mkholt commented 11 months ago

Definitely related to the path separator on Win32 vs POSIX systems.

After https://github.com/activeguild/vite-plugin-sass-dts/blob/0f6c6267477d601e5e55b68055036e8578953f9e/src/util.ts#L20 I added the following check:

if (path.sep !== "/") {
    relativePath = relativePath.replaceAll(path.sep, "/")
}