Skip to content

Commit d5e183c

Browse files
fix: .ts/.js files not included in game export
1 parent 88c3060 commit d5e183c

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"@godot-js/editor": patch
3+
---
4+
5+
fix: .ts/.js files not included in game export
6+
7+
Exporting GodotJS games was fundamentally broken by
8+
a Godot engine change which altered the way .skip()
9+
behaved on exported files. Basically, we were skipping
10+
.ts files because we don't want them in the export,
11+
only .js files which we added as extra files. However,
12+
the change to skip's behavior meant extra files are
13+
also skipped. Instead .ts files are now remapped to
14+
the .js file, not skipped. The result is as
15+
previously intended i.e. only .js files ship.

weaver-editor/jsb_export_plugin.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ void GodotJSExportPlugin::export_raw_files(const PackedStringArray &p_paths, boo
3535

3636
if (!file_path.ends_with("." JSB_TYPESCRIPT_EXT))
3737
{
38-
export_raw_file(file_path);
38+
export_raw_file(file_path, false);
3939
}
4040
else if (p_permit_typescript)
4141
{
4242
const String compiled_script_path = jsb::internal::PathUtil::convert_typescript_path(file_path);
43-
export_raw_file(compiled_script_path);
43+
export_raw_file(compiled_script_path, true);
4444
}
4545
}
4646
}
@@ -103,7 +103,7 @@ void GodotJSExportPlugin::_export_begin(const HashSet<String>& p_features, bool
103103
}
104104
}
105105

106-
bool GodotJSExportPlugin::export_raw_file(const String& p_path)
106+
bool GodotJSExportPlugin::export_raw_file(const String& p_path, bool p_remap)
107107
{
108108
if (exported_paths_.has(p_path))
109109
{
@@ -116,14 +116,14 @@ bool GodotJSExportPlugin::export_raw_file(const String& p_path)
116116
return false;
117117
}
118118
exported_paths_.insert(p_path);
119-
add_file(p_path, content, false);
119+
add_file(p_path, content, p_remap);
120120
JSB_EXPORTER_LOG(Verbose, "include raw: %s", p_path);
121121
return true;
122122
}
123123

124-
bool GodotJSExportPlugin::export_module_files(const jsb::JavaScriptModule& p_module)
124+
bool GodotJSExportPlugin::export_module_files(const jsb::JavaScriptModule& p_module, bool p_remap)
125125
{
126-
if (!export_raw_file(p_module.source_info.source_filepath))
126+
if (!export_raw_file(p_module.source_info.source_filepath, p_remap))
127127
{
128128
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);
129129
return false;
@@ -132,21 +132,21 @@ bool GodotJSExportPlugin::export_module_files(const jsb::JavaScriptModule& p_mod
132132
if (jsb::internal::Settings::is_packaging_with_source_map())
133133
{
134134
const String source_map_path = p_module.source_info.source_filepath + ".map";
135-
if (!export_raw_file(source_map_path))
135+
if (!export_raw_file(source_map_path, false))
136136
{
137137
JSB_EXPORTER_LOG(Verbose, "can't read the sourcemap from %s, please ensure that 'tsc' has being executed properly.", source_map_path);
138138
}
139139
}
140140

141-
if (!p_module.source_info.package_filepath.is_empty() && !export_raw_file(p_module.source_info.package_filepath))
141+
if (!p_module.source_info.package_filepath.is_empty() && !export_raw_file(p_module.source_info.package_filepath, false))
142142
{
143143
JSB_EXPORTER_LOG(Error, "can't read the package.json from %s", p_module.source_info.package_filepath);
144144
return false;
145145
}
146146
return true;
147147
}
148148

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

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

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

241241
// always skip the typescript source from packing
242-
skip();
243242
JSB_EXPORTER_LOG(Verbose, "export source: %s => %s", p_path, compiled_script_path);
244243
}
245244
else

weaver-editor/jsb_export_plugin.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class GodotJSExportPlugin: public EditorExportPlugin
3030
private:
3131
static HashSet<String> ignored_paths_;
3232

33-
bool export_compiled_script(const String& p_path);
34-
bool export_module_files(const jsb::JavaScriptModule& p_module);
35-
bool export_raw_file(const String& p_path);
33+
bool export_compiled_script(const String& p_path, bool p_remap);
34+
bool export_module_files(const jsb::JavaScriptModule& p_module, bool p_remap);
35+
bool export_raw_file(const String& p_path, bool p_remap);
3636
void export_raw_files(const PackedStringArray& p_paths, bool p_permit_typescript);
3737
void get_script_resources(const String &p_dir, Vector<String> &r_list, bool p_is_node_module = false);
3838

0 commit comments

Comments
 (0)