8000 Fix file URI handling for Windows platforms by EvilGenius13 · Pull Request #835 · Shopify/theme-tools · GitHub
[go: up one dir, main page]

Skip to content
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 file URI handling for Windows platforms #835

Open
wants to merge 1 commit into
base: main
Choose a base branch
< 8000 div role="tabpanel" id="tags-menu" data-filter-placeholder="Find a tag" tabindex="" hidden class="d-flex flex-column flex-auto">
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
< 8000 div class="file-header d-flex flex-md-row flex-column flex-md-items-center file-header--expandable js-file-header js-skip-tagsearch sticky-file-header" data-path=".changeset/khaki-hornets-care.md" data-short-path="51a655a" data-anchor="diff-51a655a61793646cceeda82183d624e2cf5dbfcb6d06bf63f00fcb159a586f43" data-file-type=".md" data-file-deleted="false" >
5 changes: 5 additions & 0 deletions .changeset/khaki-hornets-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/theme-check-node': patch
---

[Bug fix] Fix file URI handling for Windows platforms
12 changes: 11 additions & 1 deletion packages/theme-check-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,19 @@ export async function getTheme(config: Config): Promise<Theme> {
// as mentioned in the documentation of node-glob

// the path is normalised and '\' are replaced with '/' and then passed to the glob function
const normalizedGlob = path
let normalizedGlob = path
.normalize(path.join(config.rootUri.replace(/^file:/, ''), '**/*.{liquid,json}'))
.replace(/\\/g, '/');

// The glob is always an absoluate path, so windows paths should always
// start with a drive letter (with few exceptions we can ignore).
// More info: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats
//
// If an absoluate path starts with a slash on Windows, we strip it
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a test for this? Is there a reasonable way to accomplish that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a test for this?

Will do!

Is there a reasonable way to accomplish that?

We can't tophat this in a reasonable way because we have to release theme-tools FIRST then update CLI. To verify this works i installed CLI on my windows machine, then updated its source code to contain this change.

if (process.platform === 'win32' && normalizedGlob.match(/^\/[a-zA-Z]:/)) {
normalizedGlob = normalizedGlob.slice(1);
}

const paths = await asyncGlob(normalizedGlob).then((result) =>
// Global ignored paths should not be part of the theme
result.filter((filePath) => !isIgnored(filePath, config)),
Expand Down
4 changes: 2 additions & 2 deletions packages/theme-check-node/src/test/test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ export async function makeTempWorkspace(structure: Tree): Promise<Workspace> {

await createFiles(structure, [root]);

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

return {
rootUri: 'file:' + root,
rootUri: 'file://' + root,
uri: (relativePath) => pathUtils.join(rootUri, ...relativePath.split('/')),
clean: async () => fs.rm(root, { recursive: true, force: true }),
};
Expand Down
Loading
0