fix: generate command with running cross-device#3403
fix: generate command with running cross-device#3403petebacondarwin merged 5 commits intocloudflare:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 97ad9fa The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/5390610863/npm-package-wrangler-3403You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/3403/npm-package-wrangler-3403Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/5390610863/npm-package-wrangler-3403 dev path/to/script.jsAdditional artifacts:npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/5390610863/npm-package-cloudflare-pages-shared-3403Note that these links will no longer work once the GitHub Actions artifact expires. |
Codecov Report
@@ Coverage Diff @@
## main #3403 +/- ##
==========================================
+ Coverage 75.07% 75.11% +0.03%
==========================================
Files 183 183
Lines 11083 11091 +8
Branches 2917 2918 +1
==========================================
+ Hits 8321 8331 +10
+ Misses 2762 2760 -2
|
|
It seems like |
f06ebbc to
f406cfa
Compare
| // @ts-expect-error non standard property on Error | ||
| if (err.code !== "EXDEV") { | ||
| logger.debug(err); | ||
| throw new Error(`Failed to find "${subdirectory}" in ${remote}`); |
There was a problem hiding this comment.
Perhaps include the original err in the new Error?
There was a problem hiding this comment.
I'm happy to do this - the original code doesn't, so I assumed that was intentional, but if you think it's safe to just pass it through into the new error, can do!
There was a problem hiding this comment.
Hmm. Oh I see. OK let's leave it as-is.
(Aside, I note that subdirectory could actually be undefined that would be a weird message!)
There was a problem hiding this comment.
(Aside, I note that subdirectory could actually be undefined that would be a weird message!)
Yeah, it could for sure. The error handling here is pretty bare-bones. If you think it's worth refactoring here, let me know.
petebacondarwin
left a comment
There was a problem hiding this comment.
I note that you are skipping the two unit tests. Do they not work?
I know you said that it was hard to create a real world test for this.
I wonder if we could create a network mapped drive that points to a local folder?
https://support.microsoft.com/en-us/windows/map-a-network-drive-in-windows-29ce55d1-34e3-a7e2-4801-131475f9557d#ID0EBD=Windows_11
Yeah I attempted a very dumb test by temporarily mocking
This might work 🤔 I've never had to test anything like this in CI before. Prior libraries that have solved this seem to just handle it by naively mocking: https://github.com/andrewrk/node-mv/blob/645d8f4c783abf84204be704098fdd41f36ab195/test/test.js#L14 |
This is in use throughout other parts of the codebase, so it should be safe
packages/wrangler/src/git-client.ts
Outdated
| // likely on a different filesystem, so we need to copy instead of rename | ||
| // and then remove the original directory | ||
| try { | ||
| fs.cpSync(templatePath, targetDirectory); |
There was a problem hiding this comment.
We actually need a recursive option on this command too, which is why the tests were failing.
I have fixed this up and rebased.
7dc55c7 to
97ad9fa
Compare
petebacondarwin
left a comment
There was a problem hiding this comment.
Assuming CI is happy, I am happy.
|
Thanks Pete! 🎉 |
Fixes #2850
What this PR solves / how to test:
When using Windows (and maybe other operating systems), a
renameSynccan throw aError: EXDEV: cross-device link not permittederror when renaming across drives. This is very common on Windows installs that may have Windows onC:/, but their user files on another drive likeE:/.This PR resolves that by first trying the
renameSync(will be much faster than copying files on the same device, so worth doing first), but then catching theEXDEVerror and handling it specifically afterwards.For tests, I don't really know how to properly approach testing this cross-device behaviour if I'm honest - it'd need another filesystem (maybe mocked?) on some other virtual device - and most
generatetests appear to be skipped right now anyway. If that's something folks would like to see, I'm going to need some guidance/examples on how best to do that testing. I ran manual tests locally on my Windows 10 machine usinggenerate project-name https://github.com/cloudflare/workers-sdk/templates/experimental/worker-rust, as well as in WSL and on my Macbook just to ensure the previous behaviour wasn't impacted across a few OSes, and all worked well.Author has included the following, where applicable:
Reviewer is to perform the following, as applicable: