-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(cli): handle patterns correctly on Windows #10430
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { getMyUser, init, isHttpError } from '@immich/sdk'; | ||
import { glob } from 'fast-glob'; | ||
import { convertPathToPattern, glob } from 'fast-glob'; | ||
import { createHash } from 'node:crypto'; | ||
import { createReadStream } from 'node:fs'; | ||
import { readFile, stat, writeFile } from 'node:fs/promises'; | ||
import { platform } from 'node:os'; | ||
import { join, resolve } from 'node:path'; | ||
import yaml from 'yaml'; | ||
|
||
|
@@ -106,6 +107,11 @@ export interface CrawlOptions { | |
exclusionPattern?: string; | ||
extensions: string[]; | ||
} | ||
|
||
const convertPathToPatternOnWin = (path: string) => { | ||
return platform() === 'win32' ? convertPathToPattern(path) : path; | ||
}; | ||
Comment on lines
+111
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be conditional to the platform, would there be any issues with just always converting? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes,
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it doesn't change the behaviour on windows? If so that sounds weird, do you know why it is like that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it doesn't change the behaviour on Windows. From my understanding, |
||
|
||
export const crawl = async (options: CrawlOptions): Promise<string[]> => { | ||
const { extensions: extensionsWithPeriod, recursive, pathsToCrawl, exclusionPattern, includeHidden } = options; | ||
const extensions = extensionsWithPeriod.map((extension) => extension.replace('.', '')); | ||
|
@@ -124,11 +130,11 @@ export const crawl = async (options: CrawlOptions): Promise<string[]> => { | |
if (stats.isFile() || stats.isSymbolicLink()) { | ||
crawledFiles.push(absolutePath); | ||
} else { | ||
patterns.push(absolutePath); | ||
patterns.push(convertPathToPatternOnWin(absolutePath)); | ||
} | ||
} catch (error: any) { | ||
if (error.code === 'ENOENT') { | ||
patterns.push(currentPath); | ||
patterns.push(convertPathToPatternOnWin(currentPath)); | ||
} else { | ||
throw error; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import { defineConfig } from 'vite'; | |
import tsconfigPaths from 'vite-tsconfig-paths'; | ||
|
||
export default defineConfig({ | ||
resolve: { alias: { src: '/src' } }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I followed
Generally speaking, I think this change will improve the compatibility of dev configs. |
||
build: { | ||
rollupOptions: { | ||
input: 'src/index.ts', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a few changes in this test that look odd to me, can you explain what's going on here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line
#265
: On the Windows platform,/
cannot be treated as expected infast-glob
. I've filed an issue here mrmlnc/fast-glob#447.Line
#286 & #294
: Comparing path strings directly will lead to some false positive cases. For example, on Windows, a path can be written asD:\Something\Like\This
while\something\like\this
on Linux. So It should be better to compare what they've actually read in the file system. To achieve this, I'm letting each file contain unique contents (their paths) so that it can be used for comparison later. A good thing to note is that we are still comparing their paths and this is friendly when debugging.