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

refactor: factor out SourceFileFetcher to separate module #2683

Merged
merged 6 commits into from
Jul 31, 2019

Conversation

bartlomieju
Copy link
Member

Fixes #2659

It's a prototype to further decouple responsibilities of DenoDir, namely logic for obtaining SourceFile is moved to //cli/file_fetcher.rs::FileFetcher structure.

I'll iterate on it before it's ready to land.

For now I just want to see if there's any benefit with this refactor.

cli/deno_dir.rs Outdated

use_disk_cache: bool,
no_remote_fetch: bool,
cache_map: Arc<Mutex<HashMap<String, DiskCache>>>,
Copy link
Member

@ry ry Jul 28, 2019

Choose a reason for hiding this comment

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

Can you add a comment here describing the typical keys here? I guess it's "deps" and "gen" ?

Will it ever be anything else other than "deps" and "gen"? If not, what's the benefit of having this generalized HashMap structure?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you add a comment here describing the typical keys here? I guess it's "deps" and "gen" ?

Sure

Will it ever be anything else other than "deps" and "gen"? If not, what's the benefit of having this generalized HashMap structure?

It will if we introduce other compilers - then each compiler registers cache for itself.
import { foo } from "./foo.rs is still on my roadmap and I should be able to implement it once #2686 lands.

Copy link
Member

Choose a reason for hiding this comment

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

I see, so 'gen' and 'deps' belong to the typescript compiler, but there may be others in the future...

What about using an enum instead of String for the key?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually:

  • gen belongs to TsCompiler and is used and store compiler outputs and source maps
  • deps belongs to FileFetcher and is used to store remote modules locally

Yeah it definitely makes sense to use an enum. Will update 👍

Copy link
Member Author

@bartlomieju bartlomieju Jul 28, 2019

Choose a reason for hiding this comment

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

I'm gonna bring back DenoDir.deps_cache and DenoDir.gen_cache. Keeping them in hash map is an overkill now...

@ry
Copy link
Member

ry commented Jul 31, 2019

@bartlomieju Can you draft a commit message please?

@bartlomieju
Copy link
Member Author

@ry sure:

factor out FileFetcher to separate module

* merge SourceFileFetcher trait and FileFetcher struct

* move logic related to source file fetching to //cli/file_fetcher.rs

* use Result when creating new ThreadSafeState

/// Structure representing local or remote file.
///
/// In case of remote file `url` might be different than originally requested URL, if so
/// `redirect_source_url` will contain original URL and `url` will be equal to final location.
Copy link
Member

@ry ry Jul 31, 2019

Choose a reason for hiding this comment

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

These lines are not wrapped at 80 columns. I guess we have a bug in rustfmt...
I've added an issue for it #2699

// trait and should be handled by "compiler pipeline"
pub fn js_source(&self) -> String {
if self.media_type == msg::MediaType::TypeScript {
panic!("TypeScript module has no JS source, did you forget to run it through compiler?");
Copy link
Member

Choose a reason for hiding this comment

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

Also longer than 80 columns.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

LGTM - we'll fix the long lines when we fix rustfmt config.

@ry ry merged commit 421cbd3 into denoland:master Jul 31, 2019
@bartlomieju bartlomieju deleted the refactor-file_fetcher branch July 31, 2019 11:58
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.

Consider SourceFileFetcher as separate struct
2 participants