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(xsnap): Accommodate spaces in installation path #10082

Merged
merged 1 commit into from
Sep 12, 2024

Conversation

kriskowal
Copy link
Member

Description

When installed on a Mac via npm in nvm, the path to the xsnap binary inevitably includes a space as in Application Support. The pattern new URL(location).pathname does not account for URL encoded spaces in the input URL, as will occur based on import.meta.url. This pivots xsnap to use url.fileURLToPath instead which does take these into account as well as Windows drive letters.

Security Considerations

None.

Scaling Considerations

None.

Documentation Considerations

None.

Testing Considerations

I created a git worktree named agoric sdk for the development of this branch. The xsnap tests failed under that directory name before this change, and worked afterward.

Upgrade Considerations

None.

Copy link

cloudflare-workers-and-pages bot commented Sep 12, 2024

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: e1b2a28
Status: ✅  Deploy successful!
Preview URL: https://2d452e27.agoric-sdk.pages.dev
Branch Preview URL: https://kriskowal-xsnap-spaces-in-in.agoric-sdk.pages.dev

View logs

Copy link
Member

@dckc dckc left a comment

Choose a reason for hiding this comment

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

it's a little surprising that we didn't get bit by this sooner

@@ -21,7 +22,7 @@ const avaHandler = `./avaHandler.cjs`;

/** @type { (ref: string, readFile: typeof import('fs').promises.readFile ) => Promise<string> } */
const asset = (ref, readFile) =>
readFile(new URL(ref, import.meta.url).pathname, 'utf8');
readFile(fileURLToPath(new URL(ref, import.meta.url)), 'utf8');
Copy link
Member

Choose a reason for hiding this comment

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

asset() is about reading stuff out of the package. I wonder about using the node:module API here.

After thinking it over, I suppose it's more of a change than is necessary to fix this.

But I'll leave my thinking-out-loud here for comparison...

Suggested change
readFile(fileURLToPath(new URL(ref, import.meta.url)), 'utf8');
readFile(nodeRequire.resolve(ref), 'utf8');

presuming:

import { createRequire } from 'node:module';

const nodeRequire = createRequire(import.meta.url);

Copy link
Member Author

Choose a reason for hiding this comment

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

It occurred to me, and would be useful especially for reaching for assets in other packages.

Copy link
Member

Choose a reason for hiding this comment

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

I like it!

Not a blocker, of course. I suppose it'll come up again when we fully expunge .pathname

@kriskowal kriskowal added the automerge:rebase Automatically rebase updates, then merge label Sep 12, 2024
@kriskowal kriskowal force-pushed the kriskowal-xsnap-spaces-in-install-path branch from 1768df2 to e1b2a28 Compare September 12, 2024 21:58
@@ -21,7 +22,7 @@ const avaHandler = `./avaHandler.cjs`;

/** @type { (ref: string, readFile: typeof import('fs').promises.readFile ) => Promise<string> } */
const asset = (ref, readFile) =>
readFile(new URL(ref, import.meta.url).pathname, 'utf8');
readFile(fileURLToPath(new URL(ref, import.meta.url)), 'utf8');
Copy link
Member

Choose a reason for hiding this comment

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

I like it!

Not a blocker, of course. I suppose it'll come up again when we fully expunge .pathname

@mergify mergify bot merged commit c068d08 into master Sep 12, 2024
80 checks passed
@mergify mergify bot deleted the kriskowal-xsnap-spaces-in-install-path branch September 12, 2024 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:rebase Automatically rebase updates, then merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants