imjuni / ctix

CLI to generate barrel file for webpack, rollup entrypoint
MIT License
82 stars 22 forks source link

Disjoint paths sets on Windows #114

Closed rplbc closed 8 months ago

rplbc commented 9 months ago

Hi,

is it possible that this fragment filters out every path on Windows? It seems like IncludeContainer paths and filePaths differ in separator (\\ and /).

imjuni commented 9 months ago

The include and exclude configurations can only accept / path seperators. This is because glob libraries such as fast-glob and node-glob do not recognize the \\ character. Please enter the path with / characters. The glob package and the typescript compiler api will work fine in window if you enter the path with / characters. Please see to this documentation

rplbc commented 9 months ago

Thanks for the reply! The code I was testing works fine on Mac (I am not using \\ at all) so I suppose the overall config is ok.

I checked values from the following fragment

const filenames = filePaths
    .filter((filename) => include.isInclude(filename))
    .filter((filename) => !exclude.isExclude(filename));

and both filePaths and include.files() are not empty, they just differ in separator.

I don't know if those tests can help in something

obraz

In general, it works when I add something like this

filePaths.filter((filename) => include.isInclude(filename.replaceAll("/", "\\")))

but I don't use \\ in configs

imjuni commented 9 months ago

It seems that node-glob is searching for the file and returning it with a \\ character in the path. The TypeScript compiler API will not be able to find the file because the windows environment also uses the / character as a path separator. Can you grab the window-glob branch and test it? I changed the node-glob package to return the / character instead of the \\ character.

rplbc commented 9 months ago

It didn't work, I think windowsPathsNoEscape applies only to a pattern. I tried like this

const normalizeFilePath = (filePath: string) => filePath.replace(/\\/g, '/');

export function getGlobFiles<T extends GlobOptions>(glob: Glob<T>): string[] {
  ...
  return Array.from(filePathSet).map(normalizeFilePath);
}

and it worked. Removing this fragment from isInclude method also worked

if (path.isAbsolute(filePath)) {
  return this.#map.get(filePath) != null;
}

But then there is an issue

export * from './comments\getCommentKind';
export * from './comments\getCommentWorkspace';
...

which I believe is because of addCurrentDirPrefix

imjuni commented 9 months ago

The TypeScript import statement has to use the posix path seperator. The addCurrentDirPrefix works fine, but the other functions that generate the import path need to be fixed.

I don't have time to work on this right now for some personal reasons. PRs are always welcome. However, it will be a while before I get around to fixing this.

Vulthil commented 9 months ago

I'm facing a similar issue, so I'm just gonna chime in.

When trying to use 'create' mode, nothing is generated on a windows machine.

If I open the same folder in WSL (Windows Subsystem for Linux) and run the same command, the output is correctly generated.

imjuni commented 8 months ago

@rplbc @Vulthil Thank you for feedback.

2.4.0 version has been released. 2.4.0 version supports the windows environment, and I've tested it in other packages I've developed and it works fine in the windows environment. Thank you for your patience during this long wait.