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

feat: support crate imports in deno_typescript #3814

Merged
merged 2 commits into from
Feb 1, 2020

Conversation

afinch7
Copy link
Contributor

@afinch7 afinch7 commented Jan 28, 2020

Basic support for crate imports for deno_typescript. Syntax is like this crate:https://crate_name/path_in_crate.ts.

@afinch7 afinch7 force-pushed the crate_imports branch 2 times, most recently from b2f768c to c62cc26 Compare January 28, 2020 18:17
cli/js/deno.ts Outdated Show resolved Hide resolved
core/lib.rs Outdated Show resolved Hide resolved
@afinch7 afinch7 force-pushed the crate_imports branch 2 times, most recently from 5474367 to c25f2ef Compare January 30, 2020 18:48
Comment on lines +452 to +470
#[macro_export]
macro_rules! crate_modules {
() => {
pub const DENO_CRATE_PATH: &'static str = env!("CARGO_MANIFEST_DIR");
};
}

#[macro_export]
macro_rules! include_crate_modules {
( $( $x:ident ),* ) => {
{
let mut temp: HashMap<String, String> = HashMap::new();
$(
temp.insert(stringify!($x).to_string(), $x::DENO_CRATE_PATH.to_string());
)*
temp
}
};
}
Copy link
Member

Choose a reason for hiding this comment

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

This solution is so simple that these macros almost feel like extraneous sugar 👍

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

@ry I think once https://github.com/denoland/deno/pull/3814/files#r373159795 is resolved we could land it and try to factor out dispatch_json using this mechanism

@afinch7
Copy link
Contributor Author

afinch7 commented Jan 30, 2020

@bartlomieju I'm going to refactor #3692 to use this once it lands.

@afinch7 afinch7 changed the title [WIP] feat: support crate imports in deno_typescript feat: support crate imports in deno_typescript Jan 30, 2020
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.

It would be very cool if these files could be accessed without using include_str.

Although this patch is small I'm hesitant to introduce a new URL schema like this... I'm marking this as "request changes" because I'm not ready to land it yet. I'm not sure if this is actually possible without include _str ...

@ry ry requested a review from piscisaureus January 31, 2020 17:48
@ry
Copy link
Member

ry commented Jan 31, 2020

Sorry @afinch7 I guess the PR doesn't use include_str! ... did a previous version or am I just mistaken?

Anyway the solution looks good now that I've seen it clearly. I wonder if this works with cargo package correctly?

@ry
Copy link
Member

ry commented Jan 31, 2020

Practical example:

import { makeTempDir } from "crate:https://deno_fs/make_temp_dir.ts";

@ry
Copy link
Member

ry commented Jan 31, 2020

We should really add an explanation to the manual.

Copy link
Member

@piscisaureus piscisaureus left a comment

Choose a reason for hiding this comment

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

Yes, very elegant! +1

@ry
Copy link
Member

ry commented Jan 31, 2020

Just need some a minimal manual entry and then we can land it

@bartlomieju
Copy link
Member

@ry this is snapshot only feature, does it really need entry in manual right now? Maybe let's refactor some crates and stabilize this feature first?

@ry
Copy link
Member

ry commented Jan 31, 2020

Alright - you're right - let's land it.

@bartlomieju bartlomieju requested a review from ry February 1, 2020 08:26
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!

@bartlomieju bartlomieju merged commit 4f8a5c0 into denoland:master Feb 1, 2020
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.

None yet

4 participants