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

Cache busting config reloading by using virtual files #204

Merged
merged 10 commits into from
Sep 18, 2024

Conversation

phryneas
Copy link
Member

@phryneas phryneas commented Sep 13, 2024

We needed a way to get around node's import cache, so this seems to be the best way to do that. Setting a module-path query parameter doesn't seem to have any effect.

On a positive sidenote, we also don't have to write any files to disk for TS transpilation anymore.

@phryneas phryneas changed the base branch from main to pr/fix-ts-loading September 13, 2024 17:16
@phryneas phryneas marked this pull request as draft September 13, 2024 17:16
Copy link
Contributor

github-actions bot commented Sep 13, 2024

You can download the latest build of the extension for this PR here:
vscode-apollo-0.0.0-build-1726589871.pr-204.commit-a5c9f80.zip.

To install the extension, download the file, unzip it and install it in VS Code by selecting "Install from VSIX..." in the Extensions view.

Alternatively, run

code --install-extension vscode-apollo-0.0.0-build-1726589871.pr-204.commit-a5c9f80.vsix --force

from the command line.

For older builds, please see the edit history of this comment.

@phryneas phryneas changed the title [WIP] Cache busting config reloading by usiung virtual files [WIP] Cache busting config reloading by using virtual files Sep 16, 2024
@phryneas phryneas force-pushed the pr/config-cachebusting branch from e66e5e3 to 39115aa Compare September 16, 2024 12:45
Comment on lines -195 to -197
if (uri.match(/vscode-extension-ignore.[mc]?js$/)) {
continue;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This is no longer required since we don't create files on disk anymore

Comment on lines +67 to +72
{
with: {
as: "cachebust",
contents: transpiledContent,
format: type,
} satisfies ImportAttributes,
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This will be passed to our custom resolver, the file path will be largely ignored.

@phryneas phryneas marked this pull request as ready for review September 16, 2024 12:48
@phryneas phryneas changed the title [WIP] Cache busting config reloading by using virtual files Cache busting config reloading by using virtual files Sep 16, 2024
Comment on lines +1 to +8
module.exports = {
client: {
service: {
name: "localSchema",
localSchemaFile: "./starwarsSchema.graphql",
},
},
};
Copy link
Member Author

Choose a reason for hiding this comment

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

We need one "TypeScript, but CommonJS" config for testing, and the rover config seemed like a better candidate for yaml anyways

Base automatically changed from pr/fix-ts-loading to main September 17, 2024 16:15
An error occurred while trying to automatically change base from pr/fix-ts-loading to main September 17, 2024 16:15
@phryneas phryneas force-pushed the pr/config-cachebusting branch from 605eb83 to e4ae818 Compare September 17, 2024 16:17
Copy link
Member

@jerelmiller jerelmiller left a comment

Choose a reason for hiding this comment

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

💯

@phryneas phryneas merged commit c2351d2 into main Sep 18, 2024
8 checks passed
@phryneas phryneas deleted the pr/config-cachebusting branch September 18, 2024 07:33
@github-actions github-actions bot mentioned this pull request Sep 17, 2024
* @returns {Promise<ResolutionResult>}
*/
async function resolve(specifier, context, nextResolve) {
if (context.importAttributes.as !== "cachebust") {
Copy link

@weiatresvu weiatresvu Oct 11, 2024

Choose a reason for hiding this comment

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

It was ⁠context.importAssertions. So, in some older versions of Node.js, context.importAttributes will be undefined. Unfortunately, Cursor is using Node.js 20.9.0 in their latest version.

See, https://nodejs.org/api/module.html#hooks:~:text=v21.0.0%2C%20v20.10.0%2C%20v18.19.0

filepath,
//@ts-ignore
{
with: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

As these are object keys, what happens if you pass this in as an object with both the with and assert property?

Copy link
Contributor

@yesmeck yesmeck Oct 13, 2024

Choose a reason for hiding this comment

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

It seems fine to pass both with and assert to the import function. But I found we won't be able to access the format key from importAssertions. importAssertions only includes two fields despite we setting other keys on the assert object.
CleanShot 2024-10-13 at 15 12 01@2x

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm :/
Maybe we need to switch to as: 'cachebust:module' and as: 'cachebust:commonjs' then - or does it maybe work with a different key name than format? Maybe that is in some way reserved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants