Skip to content

Commit 94e6c75

Browse files
aswamyEvilGenius13
andcommitted
Fix file path handling on Windows
Co-authored-by: Josh Faigan <[email protected]>
1 parent 5005c31 commit 94e6c75

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

.changeset/khaki-hornets-care.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/theme-check-node': patch
3+
---
4+
5+
[Bug fix] Fix file URI handling for Windows platforms

packages/theme-check-node/src/index.ts

+21-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import glob = require('glob');
2626
import { autofix } from './autofix';
2727
import { findConfigPath, loadConfig as resolveConfig } from './config';
2828
import { NodeFileSystem } from './NodeFileSystem';
29+
import { fileURLToPath } from 'node:url';
2930

3031
const asyncGlob = promisify(glob);
3132

@@ -153,13 +154,29 @@ export async function getTheme(config: Config): Promise<Theme> {
153154
// as mentioned in the documentation of node-glob
154155

155156
// the path is normalised and '\' are replaced with '/' and then passed to the glob function
156-
const normalizedGlob = path
157-
.normalize(path.join(config.rootUri.replace(/^file:/, ''), '**/*.{liquid,json}'))
158-
.replace(/\\/g, '/');
159-
const paths = await asyncGlob(normalizedGlob).then((result) =>
157+
let normalizedGlob = getThemeFilesPathPattern(config.rootUri);
158+
159+
const paths = await asyncGlob(normalizedGlob, {absolute: true}).then((result) =>
160160
// Global ignored paths should not be part of the theme
161161
result.filter((filePath) => !isIgnored(filePath, config)),
162162
);
163163
const sourceCodes = await Promise.all(paths.map(toSourceCode));
164164
return sourceCodes.filter((x): x is LiquidSourceCode | JSONSourceCode => x !== undefined);
165165
}
166+
167+
function getThemeFilesPathPattern(rootUri: string) {
168+
let normalizedGlob = path
169+
.normalize(path.join(fileURLToPath(rootUri), '**/*.{liquid,json}'))
170+
.replace(/\\/g, '/');
171+
172+
// The glob is always an absoluate path, so windows paths should always
173+
// start with a drive letter (with few exceptions we can ignore).
174+
// More info: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats
175+
//
176+
// If an absoluate path starts with a slash on Windows, we strip it
177+
if (process.platform === 'win32' && normalizedGlob.match(/^\/[a-zA-Z]:/)) {
178+
normalizedGlob = normalizedGlob.slice(1);
179+
}
180+
181+
return normalizedGlob;
182+
}

0 commit comments

Comments
 (0)