Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

fix: Watch mode not working on Windows #26

Merged
merged 2 commits into from
Dec 4, 2020

Conversation

stephan-noel
Copy link
Contributor

Description

Fixes watch mode not working on windows.

Fixes #25

How Has This Been Tested?

Tried change in node_modules of the project where error was occurring and debugged the effects.

This can still be tested on a Mac to ensure nothing was broken.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have added tests to cover my changes
  • I have made corresponding changes to the documentation

Disclaimer

By sending us your contributions, you are agreeing that your contribution is made subject to the terms of our Contributor Ownership Statement

@@ -919,7 +919,7 @@ async function garmentFromWorkspace(

if (
subscription.type === 'glob' &&
event.path.startsWith(subscription.input.rootDir)
event.path.startsWith(Path.normalize(subscription.input.rootDir))
Copy link
Contributor Author

@stephan-noel stephan-noel Nov 21, 2020

Choose a reason for hiding this comment

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

@beshanoe I'm not really comfortable with this change. Though it does work, it adds extra file input-level subscriptions to allSubscriptionsCached:

Before fix:

{
    "type": "file",
    "level": "input",
    "path": "C:\\Users\\stephan.noel\\farfetch-repos\\ui-box\\babel.config.js",
    "targetPath": "C:/Users/stephan.noel/farfetch-repos/ui-box/packages/accordion/src/context/focus-provider/FocusProvider.js"
}, {
    "type": "glob",
    "level": "input",
    "input": {
        "rootDir": "C:/Users/stephan.noel/farfetch-repos/ui-box/packages/typography/src",
        "include": ["**/*.js?(x)"],
        "exclude": ["**/*.test.js", "**/__fixtures__", "**/__mocks__"]
    }
}, {
    "type": "file",
    "level": "input",
    "path": "C:\\Users\\stephan.noel\\farfetch-repos\\ui-box\\babel.config.js",
    "targetPath": "C:/Users/stephan.noel/farfetch-repos/ui-box/packages/typography/src/index.js"
}

After fix:

{
    "type": "file",
    "level": "input",
    "path": "C:\\Users\\stephan.noel\\farfetch-repos\\ui-box\\babel.config.js",
    "targetPath": "C:/Users/stephan.noel/farfetch-repos/ui-box/packages/accordion/src/context/focus-provider/FocusProvider.js"
}, {
    "type": "file",
    "level": "input",
    "path": "C:\\Users\\stephan.noel\\farfetch-repos\\ui-box\\babel.config.js",
    "targetPath": "C:\\Users\\stephan.noel\\farfetch-repos\\ui-box\\packages\\accordion\\src\\components\\AccordionButton.js"
}, {
    "type": "glob",
    "level": "input",
    "input": {
        "rootDir": "C:/Users/stephan.noel/farfetch-repos/ui-box/packages/typography/src",
        "include": ["**/*.js?(x)"],
        "exclude": ["**/*.test.js", "**/__fixtures__", "**/__mocks__"]
    }
}, {
    "type": "file",
    "level": "input",
    "path": "C:\\Users\\stephan.noel\\farfetch-repos\\ui-box\\babel.config.js",
    "targetPath": "C:/Users/stephan.noel/farfetch-repos/ui-box/packages/typography/src/index.js"
}

We could try the approach of changing what's stored in the cache itself, but this would include changing the createdInput, rootDir (probably in getActionGraph) and targetPath to be OS-specific. Not sure if the TypeScript compiler approach of dealing with only one kind of path internally is a good strategy?

image (27)

TLDR;

This "fix" should work for now, but it has some unwanted effects. Taking the approach of platform-specific paths in the cache itself may imply changes in a lot of places. Which do you think is preferable?

Copy link
Contributor

Choose a reason for hiding this comment

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

I didnt understand how does it changes allSubscriptionCached? It seems to only affect changesBySubscriptions. We can also probably normalize the path before adding it to the subscription? 🤔
Is the path unix-style inside the watcher event?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the changesBySubscription entry to normalize as suggested, but using normalizePath. It's now working without extra entries in allSubscriptionsCached.

It is failing in build due to an outdated github action. I can try looking into it and after it should be ready to merge.

Copy link
Contributor

Choose a reason for hiding this comment

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

can we use normalizePath on this line too? Just to make it look unified. Or they work differently in this case?

Copy link
Contributor Author

@stephan-noel stephan-noel Dec 3, 2020

Choose a reason for hiding this comment

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

Sure thing. They basically do the opposite, so I can just use normalize-path on event.path instead of using Path.normalize on subscription.input.rootDir. Changed, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good to me

@stephan-noel stephan-noel force-pushed the fix/watch-mode-Windows branch from 87024f2 to 9dc2ef2 Compare December 3, 2020 00:59
- v1.4.2 used the add-path command which was deprecated and disabled due to a security vulnerability
- This was causing consumer workflows to fail
@stephan-noel stephan-noel force-pushed the fix/watch-mode-Windows branch from 9dc2ef2 to 72280b4 Compare December 3, 2020 12:18
@stephan-noel stephan-noel force-pushed the fix/watch-mode-Windows branch from 72280b4 to 96c9375 Compare December 3, 2020 20:05
@beshanoe beshanoe merged commit 1967429 into Farfetch:master Dec 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Garment watch mode not working on Windows
2 participants