Skip to content

Commit

Permalink
Remove .js and .ts from require / import (#4002)
Browse files Browse the repository at this point in the history
Summary:
Fixes #3989 (comment)

This PR updates `relay-codegen`'s printer not to include the file's extension when writing imports /  requires. This might be a naive implementation, maybe there's a better, more holistic approach.

Pull Request resolved: #4002

Reviewed By: voideanvalue

Differential Revision: D37660489

Pulled By: captbaritone

fbshipit-source-id: ea94fca0e524539b2559f0bdff27d0c39caacd7b
  • Loading branch information
tbezman authored and facebook-github-bot committed Jul 12, 2022
1 parent 02f61b8 commit c4dbd26
Show file tree
Hide file tree
Showing 78 changed files with 183 additions and 163 deletions.
20 changes: 20 additions & 0 deletions compiler/crates/relay-codegen/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use indexmap::IndexMap;
use intern::string_key::StringKey;
use std::fmt::Result as FmtResult;
use std::fmt::Write;
use std::path::Path;

pub fn print_operation(
schema: &SDLSchema,
Expand Down Expand Up @@ -470,6 +471,25 @@ impl<'b> JSONPrinter<'b> {
},
Primitive::JSModuleDependency(key) => match self.js_module_format {
JsModuleFormat::CommonJS => {
let path = Path::new(key.lookup());
let extension = path.extension();

if let Some(extension) = extension {
if extension == "ts" || extension == "js" {
let path_without_extension = path.with_extension("");

let path_without_extension = path_without_extension
.to_str()
.expect("could not convert `path_without_extension` to a str");

return self.write_js_dependency(
f,
key.to_string(),
format!("./{}", path_without_extension),
);
}
}

self.write_js_dependency(f, key.to_string(), format!("./{}", key))
}
JsModuleFormat::Haste => {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c4dbd26

Please sign in to comment.