Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/ninety-islands-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@godot-js/editor": patch
---

fix: .ts/.js files not included in game export

Exporting GodotJS games was fundamentally broken by
a Godot engine change which altered the way .skip()
behaved on exported files. Basically, we were skipping
.ts files because we don't want them in the export,
only .js files which we added as extra files. However,
the change to skip's behavior meant extra files are
also skipped. Instead .ts files are now remapped to
the .js file, not skipped. The result is as
previously intended i.e. only .js files ship.
25 changes: 12 additions & 13 deletions weaver-editor/jsb_export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ void GodotJSExportPlugin::export_raw_files(const PackedStringArray &p_paths, boo

if (!file_path.ends_with("." JSB_TYPESCRIPT_EXT))
{
export_raw_file(file_path);
export_raw_file(file_path, false);
}
else if (p_permit_typescript)
{
const String compiled_script_path = jsb::internal::PathUtil::convert_typescript_path(file_path);
export_raw_file(compiled_script_path);
export_raw_file(compiled_script_path, true);
}
}
}
Expand Down Expand Up @@ -103,7 +103,7 @@ void GodotJSExportPlugin::_export_begin(const HashSet<String>& p_features, bool
}
}

bool GodotJSExportPlugin::export_raw_file(const String& p_path)
bool GodotJSExportPlugin::export_raw_file(const String& p_path, bool p_remap)
{
if (exported_paths_.has(p_path))
{
Expand All @@ -116,14 +116,14 @@ bool GodotJSExportPlugin::export_raw_file(const String& p_path)
return false;
}
exported_paths_.insert(p_path);
add_file(p_path, content, false);
add_file(p_path, content, p_remap);
JSB_EXPORTER_LOG(Verbose, "include raw: %s", p_path);
return true;
}

bool GodotJSExportPlugin::export_module_files(const jsb::JavaScriptModule& p_module)
bool GodotJSExportPlugin::export_module_files(const jsb::JavaScriptModule& p_module, bool p_remap)
{
if (!export_raw_file(p_module.source_info.source_filepath))
if (!export_raw_file(p_module.source_info.source_filepath, p_remap))
{
JSB_EXPORTER_LOG(Error, "can't read JS source from %s, please ensure that 'tsc' has being executed properly.", p_module.source_info.source_filepath);
return false;
Expand All @@ -132,21 +132,21 @@ bool GodotJSExportPlugin::export_module_files(const jsb::JavaScriptModule& p_mod
if (jsb::internal::Settings::is_packaging_with_source_map())
{
const String source_map_path = p_module.source_info.source_filepath + ".map";
if (!export_raw_file(source_map_path))
if (!export_raw_file(source_map_path, false))
{
JSB_EXPORTER_LOG(Verbose, "can't read the sourcemap from %s, please ensure that 'tsc' has being executed properly.", source_map_path);
}
}

if (!p_module.source_info.package_filepath.is_empty() && !export_raw_file(p_module.source_info.package_filepath))
if (!p_module.source_info.package_filepath.is_empty() && !export_raw_file(p_module.source_info.package_filepath, false))
{
JSB_EXPORTER_LOG(Error, "can't read the package.json from %s", p_module.source_info.package_filepath);
return false;
}
return true;
}

bool GodotJSExportPlugin::export_compiled_script(const String& p_path)
bool GodotJSExportPlugin::export_compiled_script(const String& p_path, bool p_remap)
{
static constexpr char kNodeModulesPrefix[] = u8"res://node_modules/";

Expand Down Expand Up @@ -198,7 +198,7 @@ bool GodotJSExportPlugin::export_compiled_script(const String& p_path)
const v8::Local<v8::Context> context = env_->get_context();
v8::Context::Scope context_scope(context);

export_module_files(*module);
export_module_files(*module, p_remap);
jsb::Environment* environment = jsb::Environment::wrap(isolate);
const v8::Local<v8::Object> module_obj = module->module.Get(isolate);
if (v8::Local<v8::Value> temp; module_obj->Get(context, jsb_name(environment, children)).ToLocal(&temp) && temp->IsArray())
Expand All @@ -213,7 +213,7 @@ bool GodotJSExportPlugin::export_compiled_script(const String& p_path)
if (child->Get(context, jsb_name(environment, filename)).ToLocal(&temp))
{
const String filename = jsb::impl::Helper::to_string(isolate, temp);
if (export_compiled_script(filename))
if (export_compiled_script(filename, false))
{
JSB_EXPORTER_LOG(Verbose, "export dependent source: %s", filename);
}
Expand All @@ -236,10 +236,9 @@ void GodotJSExportPlugin::_export_file(const String& p_path, const String& p_typ
if (p_path.ends_with("." JSB_TYPESCRIPT_EXT))
{
const String compiled_script_path = jsb::internal::PathUtil::convert_typescript_path(p_path);
export_compiled_script(compiled_script_path);
export_compiled_script(compiled_script_path, true);

// always skip the typescript source from packing
skip();
JSB_EXPORTER_LOG(Verbose, "export source: %s => %s", p_path, compiled_script_path);
}
else
Expand Down
6 changes: 3 additions & 3 deletions weaver-editor/jsb_export_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class GodotJSExportPlugin: public EditorExportPlugin
private:
static HashSet<String> ignored_paths_;

bool export_compiled_script(const String& p_path);
bool export_module_files(const jsb::JavaScriptModule& p_module);
bool export_raw_file(const String& p_path);
bool export_compiled_script(const String& p_path, bool p_remap);
bool export_module_files(const jsb::JavaScriptModule& p_module, bool p_remap);
bool export_raw_file(const String& p_path, bool p_remap);
void export_raw_files(const PackedStringArray& p_paths, bool p_permit_typescript);
void get_script_resources(const String &p_dir, Vector<String> &r_list, bool p_is_node_module = false);

Expand Down
Loading