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

Add GetDependentFiles to slim service. #14

Merged
merged 1 commit into from
Oct 25, 2023

Conversation

nojaf
Copy link

@nojaf nojaf commented Oct 25, 2023

This adds a method to the slim service to find the dependent files in a project using the new Graph-based type-checking code.

What the graph-based type-checking does is detect links between files using the untyped tree.
This turned out to be very reliable and helps to answer the question of what files should be reprocessed after the current file has changed.

More of the code could improve a bit, but I'm raising this more as a conversation starter. Would you be ok with having this?

This would be a puzzle piece in the work for fable-compiler/Fable#3552.

@ncave
Copy link
Owner

ncave commented Oct 25, 2023

@nojaf Thanks, that looks useful, we can improve the current typecheck caching (see ClearStaleCache), which currently just blasts away any typechecked result for the file that was changed, and all the files below it.

If we make the change to use the graph and improve the typecheck caching, do you still need this as a separate method? I'm not opposed to adding it, I'm sure you have some use for it in your plugin, just asking to make sure you need it.

@nojaf
Copy link
Author

nojaf commented Oct 25, 2023

do you still need this as a separate method?

At first glance, I do think I will need it.

I believe the rough outline for the Vite plugin:

const { compileFSharp } = require('./some-great-compile-fsharp-module');

export default function fablePlugin() {
  return {
    name: 'fable-plugin',
    async transform(code, id) {
      // Check if the file has a .fs extension
      if (id.endsWith('.fs')) {
        // Use your compileFSharp function to transform the F# code to JavaScript
        const { compiledCode, dependencies } = await compileFSharp(code);

        // Create an array to hold the transformed dependencies
        const transformedDependencies = [];

        // Process and emit the dependencies as separate files
        for (const depId of dependencies) {
          const { compiledCode: depCode } = await compileFSharp(
            // Load the content of the dependency using Rollup's `this.emitFile` function
            this.emitFile({ type: 'chunk', id: depId }),
          );
          transformedDependencies.push(depCode);
        }

        // Return the transformed code for the current module
        return {
          code: compiledCode,
          map: null, // You may provide source maps if needed
        };
      }
    },
  };
}

I would need to call the emitFile for other changed files.

@ncave ncave merged commit ad39ec6 into ncave:service_slim Oct 25, 2023
ncave pushed a commit that referenced this pull request Dec 8, 2023
ncave pushed a commit that referenced this pull request Nov 16, 2024
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.

2 participants