const auto basename =
flatbuffers::StripPath(flatbuffers::StripExtension(file));
if (basename != file_name_) {
- const auto file_name = basename + kGeneratedFileNamePostfix;
- code += GenPrefixedImport(file, file_name);
+ code += GenPrefixedImport(file, basename);
}
}
}
return "NS" + std::to_string(HashFnv1a<uint64_t>(file.c_str()));
}
- static std::string GenPrefixedImport(const std::string &full_file_name,
- const std::string &base_file_name) {
+ std::string GenPrefixedImport(const std::string &full_file_name,
+ const std::string &base_name) {
+ // Either keep the include path as it was
+ // or use only the base_name + kGeneratedFileNamePostfix
+ std::string path;
+ if (parser_.opts.keep_include_path) {
+ auto it = parser_.included_files_.find(full_file_name);
+ FLATBUFFERS_ASSERT(it != parser_.included_files_.end());
+ path =
+ flatbuffers::StripExtension(it->second) + kGeneratedFileNamePostfix;
+ } else {
+ path = base_name + kGeneratedFileNamePostfix;
+ }
+
+ // Add the include prefix and make the path always relative
+ path = flatbuffers::ConCatPathFileName(parser_.opts.include_prefix, path);
+ path = std::string(".") + kPathSeparator + path;
+
return "import * as " + GenFileNamespacePrefix(full_file_name) +
- " from \"./" + base_file_name + "\";\n";
+ " from \"" + path + "\";\n";
}
// Adds a source-dependent prefix, for of import * statements.