Skip to content
Closed
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
25 changes: 24 additions & 1 deletion packages/@dcl/sdk-commands/src/logic/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export type CompileOptions = {
const MAX_STEP = 2

/**
* Generate the entry-point code for a given original entry-point
* Generate the entry-point code for a given original entry-point.
* It can be considered an "SDK Bootstrap", it runs before any scene code executes.
* @param entrypointPath - file to be imported as original entry point
* @param forceCustomExport
* @returns the Typescript code
Expand All @@ -58,6 +59,28 @@ function getEntrypointCode(entrypointPath: string, forceCustomExport: boolean, i

return `// BEGIN AUTO GENERATED CODE "~sdk/scene-entrypoint"
"use strict";

// Override console.log() to apply JSON.stringify wrapper
// To avoid "Object object" on console.log(whateverObject)
(function() {
const _originalConsoleLog = console.log;
console.log = function(...args) {
const stringifiedArgs = args.map(arg => {
if (arg === null) return 'null';
if (arg === undefined) return 'undefined';
if (typeof arg === 'string') return arg;
if (typeof arg === 'number' || typeof arg === 'boolean') return String(arg);
try {
return JSON.stringify(arg);
} catch (e) {
// Fallback for non-serializable objects
return String(arg);
}
});
_originalConsoleLog(...stringifiedArgs);
};
})();

import * as entrypoint from '${unixEntrypointPath}'
import { engine, NetworkEntity } from '@dcl/sdk/ecs'
import * as sdk from '@dcl/sdk'
Expand Down
8 changes: 4 additions & 4 deletions test/snapshots/production-bundles/with-main-function.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=204.9k bytes
SCENE_COMPILED_JS_SIZE_PROD=205.2k bytes
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
MALLOC_COUNT = 1005
Expand All @@ -9,8 +9,8 @@ EVAL test/snapshots/production-bundles/with-main-function.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 57k
MALLOC_COUNT = 12350
ALIVE_OBJS_DELTA ~= 2.72k
MALLOC_COUNT = 12358
ALIVE_OBJS_DELTA ~= 2.73k
CALL onStart()
OPCODES ~= 0k
MALLOC_COUNT = 6
Expand All @@ -37,4 +37,4 @@ CALL onUpdate(0.1)
OPCODES ~= 3k
MALLOC_COUNT = 5
ALIVE_OBJS_DELTA ~= 0.00k
MEMORY_USAGE_COUNT ~= 894.09k bytes
MEMORY_USAGE_COUNT ~= 894.98k bytes
Loading