Skip to content

Commit 71118ba

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

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
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

+11-1
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,19 @@ export async function getTheme(config: Config): Promise<Theme> {
153153
// as mentioned in the documentation of node-glob
154154

155155
// the path is normalised and '\' are replaced with '/' and then passed to the glob function
156-
const normalizedGlob = path
156+
let normalizedGlob = path
157157
.normalize(path.join(config.rootUri.replace(/^file:/, ''), '**/*.{liquid,json}'))
158158
.replace(/\\/g, '/');
159+
160+
// The glob is always an absoluate path, so windows paths should always
161+
// start with a drive letter (with few exceptions we can ignore).
162+
// More info: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats
163+
//
164+
// If an absoluate path starts with a slash on Windows, we strip it
165+
if (process.platform === 'win32' && normalizedGlob.match(/^\/[a-zA-Z]:/)) {
166+
normalizedGlob = normalizedGlob.slice(1);
167+
}
168+
159169
const paths = await asyncGlob(normalizedGlob).then((result) =>
160170
// Global ignored paths should not be part of the theme
161171
result.filter((filePath) => !isIgnored(filePath, config)),

packages/theme-check-node/src/test/test-helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ export async function makeTempWorkspace(structure: Tree): Promise<Workspace> {
8080

8181
await createFiles(structure, [root]);
8282

83-
const rootUri = pathUtils.normalize('file:' + root);
83+
const rootUri = pathUtils.normalize('file://' + root);
8484

8585
return {
86-
rootUri: 'file:' + root,
86+
rootUri: 'file://' + root,
8787
uri: (relativePath) => pathUtils.join(rootUri, ...relativePath.split('/')),
8888
clean: async () => fs.rm(root, { recursive: true, force: true }),
8989
};

0 commit comments

Comments
 (0)