-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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(unstable): ability to resolve specifiers with no extension, specifiers for a directory, and TS files from JS extensions #21464
Conversation
cli/args/flags.rs
Outdated
@@ -447,6 +447,7 @@ pub struct Flags { | |||
pub unstable: bool, | |||
pub unstable_bare_node_builtins: bool, | |||
pub unstable_byonm: bool, | |||
pub unstable_loose_imports: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternative name to further discourage use: --unstable-sloppy-imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like sloppy imports.
unstable-chaotic-imports?
unstable-messy-imports?
unstable-reckless-imports ?
unstable-naughty-imports?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also like --unstable-sloppy-imports
better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
This should be good to go now. I'll add the functionality for the informative error messages when not using this flag in a separate PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FAN-TA-STIC
fn specifier_text_for_redirected( | ||
redirect: &lsp::Url, | ||
referrer: &lsp::Url, | ||
) -> String { | ||
if redirect.scheme() == "file" && referrer.scheme() == "file" { | ||
// use a relative specifier when it's going to a file url | ||
match referrer.make_relative(redirect) { | ||
Some(relative) => { | ||
if relative.starts_with('.') { | ||
relative | ||
} else { | ||
format!("./{}", relative) | ||
} | ||
} | ||
None => redirect.to_string(), | ||
} | ||
} else { | ||
redirect.to_string() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool 👍
This PR adds an
--unstable-sloppy-imports
flag which supports the following forfile:
specifiers:./mod
in a specifier to do extension probing.import { Example } from "./example"
instead ofimport { Example } from "./example.ts"
./routes
to do directory extension probing for files like./routes/index.ts
./mod.js
for mod.ts files.This functionality is NOT RECOMMENDED for general use with Deno:
This is instead only recommended to help with migrating existing projects to Deno. For example, it's very useful for getting CJS projects written with import/export declaration working in Deno without modifying module specifiers and for supporting TS ESM projects written with
./mod.js
specifiers.This feature will output warnings to guide the user towards correcting their specifiers. Additionally, Quick fixes are provided in the LSP to update these specifiers: