diff --git a/packages/@dcl/playground-assets/package.json b/packages/@dcl/playground-assets/package.json index 7bfb01be1..84fe7e6ea 100644 --- a/packages/@dcl/playground-assets/package.json +++ b/packages/@dcl/playground-assets/package.json @@ -25,7 +25,7 @@ "scripts": { "build": "npm run build-playground && node_modules/.bin/api-extractor run", "build-local": "npm run build-playground && node_modules/.bin/api-extractor run --local --verbose --diagnostics", - "build-playground": "./../sdk-commands/dist/index.js build --production --emitDeclaration" + "build-playground": "./../sdk-commands/dist/index.js build --production --emitDeclaration --customEntryPoint" }, "tsdoc": { "tsdocFlavor": "AEDoc" diff --git a/packages/@dcl/sdk-commands/src/commands/build/index.ts b/packages/@dcl/sdk-commands/src/commands/build/index.ts index 7d5ac1aab..9e0641c09 100644 --- a/packages/@dcl/sdk-commands/src/commands/build/index.ts +++ b/packages/@dcl/sdk-commands/src/commands/build/index.ts @@ -65,7 +65,7 @@ export async function buildScene(options: Options, project: SceneProject) { const watch = !!options.args['--watch'] - const { sceneJson } = await bundleProject( + const { sceneJson, inputs } = await bundleProject( options.components, { workingDirectory: project.workingDirectory, @@ -84,6 +84,6 @@ export async function buildScene(options: Options, project: SceneProject) { options.components.analytics.track('Build scene', { projectHash: await b64HashingFunction(project.workingDirectory), coords, - isWorkspace: false + isWorkspace: inputs.length > 1 }) } diff --git a/packages/@dcl/sdk-commands/src/logic/bundle.ts b/packages/@dcl/sdk-commands/src/logic/bundle.ts index ffcb3a248..6049a00b8 100644 --- a/packages/@dcl/sdk-commands/src/logic/bundle.ts +++ b/packages/@dcl/sdk-commands/src/logic/bundle.ts @@ -40,6 +40,38 @@ export type CompileOptions = { const MAX_STEP = 2 +/** + * Generate the entry-point code for a given original entry-point + * @param entrypointPath - file to be imported as original entry point + * @param forceCustomExport + * @returns the Typescript code + */ + +function getEntrypointCode(entrypointPath: string, forceCustomExport: boolean) { + if (forceCustomExport) return `;"use strict";export * from '${entrypointPath}'` + + return `// BEGIN AUTO GENERATED CODE "~sdk/scene-entrypoint" +"use strict"; +import * as entrypoint from '${entrypointPath}' +import { engine } from '@dcl/sdk/ecs' +import * as sdk from '@dcl/sdk' + +if ((entrypoint as any).main !== undefined) { + function _INTERNAL_startup_system() { + const maybePromise = (entrypoint as any).main() + if (maybePromise && typeof maybePromise === 'object' && typeof (maybePromise as unknown as Promise).then === 'function') { + maybePromise.catch(console.error) + } + engine.removeSystem(_INTERNAL_startup_system) + } + engine.addSystem(_INTERNAL_startup_system, Infinity) +} + +export * from '@dcl/sdk' +export * from '${entrypointPath}' +` +} + export async function bundleProject(components: BundleComponents, options: CompileOptions, sceneJson: Scene) { const tsconfig = path.join(options.workingDirectory, 'tsconfig.json') @@ -58,24 +90,44 @@ export async function bundleProject(components: BundleComponents, options: Compi throw new CliError(`File ${tsconfig} must exist to compile the Typescript project`) } - const input = globSync(options.single ?? 'src/index.ts', { cwd: options.workingDirectory, absolute: true }) // entryPoints.map((item) => item.dest) + const entrypointSource = options.single ?? 'src/index.ts' + const entrypoints = globSync(entrypointSource, { cwd: options.workingDirectory, absolute: true }) /* istanbul ignore if */ - if (!input.length) throw new CliError(`There are no input files to build: ${options.single ?? 'src/index.ts'}`) + if (!entrypoints.length) throw new CliError(`There are no input files to build: ${entrypointSource}`) + + // const output = !options.single ? sceneJson.main : options.single.replace(/\.ts$/, '.js') + // const outfile = path.join(options.workingDirectory, output) + const inputs: { entrypoint: string; outputFile: string }[] = options.single + ? entrypoints.map((entrypoint) => ({ entrypoint, outputFile: entrypoint.replace(/\.ts$/, '.js') })) + : [{ entrypoint: entrypoints[0], outputFile: sceneJson.main }] + + for (const input of inputs) { + await bundleSingleProject(components, { + ...options, + tsconfig, + ...input + }) + } - const output = !options.single ? sceneJson.main : options.single.replace(/\.ts$/, '.js') - const outfile = path.join(options.workingDirectory, output) + return { sceneJson, inputs } +} - printProgressStep(components.logger, `Bundling file ${colors.bold(input.join(','))}`, 1, MAX_STEP) +type SingleProjectOptions = CompileOptions & { + tsconfig: string + entrypoint: string + outputFile: string +} + +export async function bundleSingleProject(components: BundleComponents, options: SingleProjectOptions) { + printProgressStep(components.logger, `Bundling file ${colors.bold(options.entrypoint)}`, 1, MAX_STEP) const context = await esbuild.context({ - entryPoints: input, bundle: true, platform: 'browser', format: 'cjs', preserveSymlinks: false, - outfile: input.length > 1 ? undefined : outfile, - outdir: input.length > 1 ? path.dirname(outfile) : undefined, + outfile: options.outputFile, allowOverwrite: false, sourcemap: options.production ? 'external' : 'inline', minify: options.production, @@ -88,7 +140,7 @@ export async function bundleProject(components: BundleComponents, options: Compi target: 'es2020', external: ['~system/*', '@dcl/inspector', '@dcl/inspector/*' /* ban importing the inspector from the SDK */], // convert filesystem paths into file:// to enable VSCode debugger - sourceRoot: pathToFileURL(path.dirname(outfile)).toString(), + sourceRoot: pathToFileURL(path.dirname(options.outputFile)).toString(), define: { document: 'undefined', window: 'undefined', @@ -96,32 +148,34 @@ export async function bundleProject(components: BundleComponents, options: Compi 'globalThis.DEBUG': options.production ? 'false' : 'true', 'process.env.NODE_ENV': JSON.stringify(options.production ? 'production' : 'development') }, - tsconfig: path.join(options.workingDirectory, 'tsconfig.json'), + tsconfig: options.tsconfig, supported: { 'import-assertions': false, 'import-meta': false, 'dynamic-import': false, hashbang: false }, - plugins: [entryPointLoader(components, input, options), compositeLoader(components, options)] + logOverride: { + 'import-is-undefined': 'silent' + }, + plugins: [compositeLoader(components, options)], + stdin: { + contents: getEntrypointCode(options.entrypoint, options.customEntryPoint), + resolveDir: path.dirname(options.entrypoint), + sourcefile: path.basename(options.entrypoint) + '.entry-point.ts', + loader: 'ts' + } }) /* istanbul ignore if */ if (options.watch) { await context.watch({}) - printProgressInfo(components.logger, `Bundle saved ${colors.bold(output)}`) + printProgressInfo(components.logger, `Bundle saved ${colors.bold(options.outputFile)}`) } else { try { - const ctx = await context.rebuild() - printProgressInfo( - components.logger, - `Bundle saved ${colors.bold( - Object.keys(ctx.metafile.outputs) - .filter((_) => _.endsWith('.js')) - .join(',') || outfile - )}` - ) + await context.rebuild() + printProgressInfo(components.logger, `Bundle saved ${colors.bold(options.outputFile)}`) } catch (err: any) { /* istanbul ignore next */ throw new CliError(err.toString()) @@ -133,8 +187,6 @@ export async function bundleProject(components: BundleComponents, options: Compi if (options.watch) printProgressInfo(components.logger, `The compiler is watching for changes`) await runTypeChecker(components, options) - - return { context, sceneJson } } function runTypeChecker(components: BundleComponents, options: CompileOptions) { @@ -176,10 +228,11 @@ function runTypeChecker(components: BundleComponents, options: CompileOptions) { return typeCheckerFuture } -function compositeLoader(components: BundleComponents, options: CompileOptions): esbuild.Plugin { +function compositeLoader(components: BundleComponents, options: SingleProjectOptions): esbuild.Plugin { let shouldReload = true let contents = `export const compositeFromLoader = {}` // default exports nothing let watchFiles: string[] = [] // no files to watch + let lastBuiltSuccessful = false return { name: 'composite-loader', @@ -210,7 +263,10 @@ function compositeLoader(components: BundleComponents, options: CompileOptions): components.logger, 'Some composites are not included because of errors while compiling them. There can be unexpected behavior in the scene, check the errors and try to fix them.' ) + } else if (!lastBuiltSuccessful) { + components.logger.log('Composites built without errors.') } + lastBuiltSuccessful = !data.withErrors } shouldReload = false } @@ -224,21 +280,3 @@ function compositeLoader(components: BundleComponents, options: CompileOptions): } } } - -function entryPointLoader(components: BundleComponents, inputs: string[], options: CompileOptions): esbuild.Plugin { - const escapedInputs = inputs.map(($) => $.replace(/\\/g, '\\\\')) - const filter = new RegExp(`(${escapedInputs.join('|')})`) - return { - name: 'entry-point-loader', - setup(build) { - build.onLoad({ filter }, async (args) => { - const exportSdk = options.customEntryPoint ? '' : `;export * from '@dcl/sdk';` - const contents = exportSdk + (await components.fs.readFile(args.path)) - return { - loader: 'ts', - contents - } - }) - } - } -} diff --git a/packages/@dcl/sdk/src/composite-provider.ts b/packages/@dcl/sdk/src/composite-provider.ts index 8eba93070..b44b3daae 100644 --- a/packages/@dcl/sdk/src/composite-provider.ts +++ b/packages/@dcl/sdk/src/composite-provider.ts @@ -11,12 +11,15 @@ export const compositeProvider: Composite.Provider = { const fromLoader = compositeFromLoader[src] if (fromLoader) { try { - if (src.endsWith('.bin') && fromLoader instanceof Uint8Array) { + if (fromLoader instanceof Uint8Array) { const composite = Composite.fromBinary(fromLoader) composites.push({ src, composite }) } else if (typeof fromLoader === 'string') { const composite = Composite.fromJson(JSON.parse(fromLoader)) composites.push({ src, composite }) + } else if (typeof fromLoader === 'object') { + const composite = Composite.fromJson(fromLoader) + composites.push({ src, composite }) } } catch (err) { console.error(err) diff --git a/test/build-ecs/sourcemaps.ts b/test/build-ecs/sourcemaps.ts index 9fd3f4f8e..7c8a2f39d 100644 --- a/test/build-ecs/sourcemaps.ts +++ b/test/build-ecs/sourcemaps.ts @@ -33,6 +33,7 @@ export function assertFilesExist(map: BasicSourceMapConsumer) { // TODO: what should we do with virtual files? if (file.endsWith('sdk-composite:all-composites')) continue + if (file.endsWith('entry-point.ts')) continue const fileExist = existsSync(fileURLToPath(file)) ? file : 'does not exit' expect(fileExist).toBe(file) diff --git a/test/sdk-commands/commands/build/index.spec.ts b/test/sdk-commands/commands/build/index.spec.ts index 9a5fa393e..2f42fcd65 100644 --- a/test/sdk-commands/commands/build/index.spec.ts +++ b/test/sdk-commands/commands/build/index.spec.ts @@ -66,7 +66,7 @@ describe('build command', () => { .mockResolvedValue({ kind: 'scene', scene: {} as any, workingDirectory: process.cwd() }) jest.spyOn(projectValidation, 'needsDependencies').mockResolvedValue(false) const sceneJson = { scene: { base: '0,0' } } as any - const tsBuildSpy = jest.spyOn(dclCompiler, 'bundleProject').mockResolvedValue({ sceneJson, context: null as any }) + const tsBuildSpy = jest.spyOn(dclCompiler, 'bundleProject').mockResolvedValue({ sceneJson, inputs: [] }) await build.main({ args: { _: [], '--watch': false, '--production': true }, diff --git a/test/snapshots.spec.ts b/test/snapshots.spec.ts index 29e671581..c3a60943d 100644 --- a/test/snapshots.spec.ts +++ b/test/snapshots.spec.ts @@ -29,6 +29,11 @@ describe('Runs the snapshots', () => { path.resolve('test/snapshots'), ENV ) + itExecutes( + `npm run build -- --production --ignoreComposite "--single=production-bundles/with-main-function.ts"`, + path.resolve('test/snapshots'), + ENV + ) itExecutes( `npm run build -- --customEntryPoint --ignoreComposite "--single=development-bundles/*.ts"`, path.resolve('test/snapshots'), diff --git a/test/snapshots/development-bundles/static-scene.test.ts.crdt b/test/snapshots/development-bundles/static-scene.test.ts.crdt index a86c4906e..49370ce57 100644 --- a/test/snapshots/development-bundles/static-scene.test.ts.crdt +++ b/test/snapshots/development-bundles/static-scene.test.ts.crdt @@ -1,4 +1,4 @@ -SCENE_COMPILED_JS_SIZE_PROD=374.2k bytes +SCENE_COMPILED_JS_SIZE_PROD=374.4k bytes THE BUNDLE HAS SOURCEMAPS (start empty vm 0.21.0-3680274614.commit-1808aa1) OPCODES ~= 0k @@ -10,8 +10,8 @@ EVAL test/snapshots/development-bundles/static-scene.test.js REQUIRE: ~system/Testing REQUIRE: ~system/EngineApi REQUIRE: ~system/EngineApi - OPCODES ~= 32k - MALLOC_COUNT = 9961 + OPCODES ~= 31k + MALLOC_COUNT = 9960 ALIVE_OBJS_DELTA ~= 1.84k CALL onStart() main.crdt: PUT_COMPONENT e=0x200 c=1 t=0 data={"position":{"x":5.880000114440918,"y":2.7916901111602783,"z":7.380000114440918},"rotation":{"x":0,"y":0,"z":0,"w":1},"scale":{"x":1,"y":1,"z":1},"parent":0} @@ -56,4 +56,4 @@ CALL onUpdate(0.1) OPCODES ~= 2k MALLOC_COUNT = -3 ALIVE_OBJS_DELTA ~= 0.00k - MEMORY_USAGE_COUNT ~= 982.42k bytes \ No newline at end of file + MEMORY_USAGE_COUNT ~= 982.62k bytes \ No newline at end of file diff --git a/test/snapshots/development-bundles/testing-fw.test.ts b/test/snapshots/development-bundles/testing-fw.test.ts index 4a24826a5..d93bbad63 100644 --- a/test/snapshots/development-bundles/testing-fw.test.ts +++ b/test/snapshots/development-bundles/testing-fw.test.ts @@ -5,7 +5,7 @@ import { withRenderer } from '../helpers/with-renderer' import { assert } from '../helpers/assertions' export * from '@dcl/sdk' -withRenderer((engine) => { +export const onServerUpdate = withRenderer((engine) => { // this helper creates a second engine and prints all the messages to emulate // the renderer counterpart of the CRDT const Transform = components.Transform(engine) diff --git a/test/snapshots/development-bundles/testing-fw.test.ts.crdt b/test/snapshots/development-bundles/testing-fw.test.ts.crdt index fc36b4467..28d4355a8 100644 --- a/test/snapshots/development-bundles/testing-fw.test.ts.crdt +++ b/test/snapshots/development-bundles/testing-fw.test.ts.crdt @@ -1,4 +1,4 @@ -SCENE_COMPILED_JS_SIZE_PROD=374.7k bytes +SCENE_COMPILED_JS_SIZE_PROD=374.9k bytes THE BUNDLE HAS SOURCEMAPS (start empty vm 0.21.0-3680274614.commit-1808aa1) OPCODES ~= 0k @@ -11,7 +11,7 @@ EVAL test/snapshots/development-bundles/testing-fw.test.js REQUIRE: ~system/EngineApi REQUIRE: ~system/EngineApi OPCODES ~= 32k - MALLOC_COUNT = 10061 + MALLOC_COUNT = 10068 ALIVE_OBJS_DELTA ~= 1.88k CALL onStart() LOG: ["Adding one to position.y=0"] @@ -64,4 +64,4 @@ CALL onUpdate(0.1) OPCODES ~= 4k MALLOC_COUNT = -40 ALIVE_OBJS_DELTA ~= -0.01k - MEMORY_USAGE_COUNT ~= 982.16k bytes \ No newline at end of file + MEMORY_USAGE_COUNT ~= 982.57k bytes \ No newline at end of file diff --git a/test/snapshots/development-bundles/two-way-crdt.test.ts b/test/snapshots/development-bundles/two-way-crdt.test.ts index 4a24826a5..d93bbad63 100644 --- a/test/snapshots/development-bundles/two-way-crdt.test.ts +++ b/test/snapshots/development-bundles/two-way-crdt.test.ts @@ -5,7 +5,7 @@ import { withRenderer } from '../helpers/with-renderer' import { assert } from '../helpers/assertions' export * from '@dcl/sdk' -withRenderer((engine) => { +export const onServerUpdate = withRenderer((engine) => { // this helper creates a second engine and prints all the messages to emulate // the renderer counterpart of the CRDT const Transform = components.Transform(engine) diff --git a/test/snapshots/development-bundles/two-way-crdt.test.ts.crdt b/test/snapshots/development-bundles/two-way-crdt.test.ts.crdt index 86be60fe7..cdf5bd4c0 100644 --- a/test/snapshots/development-bundles/two-way-crdt.test.ts.crdt +++ b/test/snapshots/development-bundles/two-way-crdt.test.ts.crdt @@ -1,4 +1,4 @@ -SCENE_COMPILED_JS_SIZE_PROD=374.7k bytes +SCENE_COMPILED_JS_SIZE_PROD=374.9k bytes THE BUNDLE HAS SOURCEMAPS (start empty vm 0.21.0-3680274614.commit-1808aa1) OPCODES ~= 0k @@ -11,7 +11,7 @@ EVAL test/snapshots/development-bundles/two-way-crdt.test.js REQUIRE: ~system/EngineApi REQUIRE: ~system/EngineApi OPCODES ~= 32k - MALLOC_COUNT = 10061 + MALLOC_COUNT = 10068 ALIVE_OBJS_DELTA ~= 1.88k CALL onStart() LOG: ["Adding one to position.y=0"] @@ -64,4 +64,4 @@ CALL onUpdate(0.1) OPCODES ~= 4k MALLOC_COUNT = -40 ALIVE_OBJS_DELTA ~= -0.01k - MEMORY_USAGE_COUNT ~= 982.16k bytes \ No newline at end of file + MEMORY_USAGE_COUNT ~= 982.58k bytes \ No newline at end of file diff --git a/test/snapshots/helpers/with-renderer.ts b/test/snapshots/helpers/with-renderer.ts index 5e51dfc56..9833173c9 100644 --- a/test/snapshots/helpers/with-renderer.ts +++ b/test/snapshots/helpers/with-renderer.ts @@ -4,7 +4,6 @@ import { Transport } from '@dcl/ecs' import { IEngine, Engine } from '@dcl/ecs/dist/engine' let called = false -declare const module: any export function withRenderer(cb: (engine: IEngine) => void) { if (called) throw new Error('Only call withRenderer once') @@ -26,7 +25,7 @@ export function withRenderer(cb: (engine: IEngine) => void) { engine.addTransport(rendererTransport) cb(engine) - ;(module as any).exports.onServerUpdate = async function (data: Uint8Array) { + return async function (data: Uint8Array) { if (rendererTransport.onmessage) { rendererTransport.onmessage(data) diff --git a/test/snapshots/production-bundles/append-value-crdt.ts b/test/snapshots/production-bundles/append-value-crdt.ts index eaadafba0..862329269 100644 --- a/test/snapshots/production-bundles/append-value-crdt.ts +++ b/test/snapshots/production-bundles/append-value-crdt.ts @@ -15,7 +15,7 @@ export * from '@dcl/sdk' const entity = 512 as Entity -withRenderer((engine) => { +export const onServerUpdate = withRenderer((engine) => { const PointerEventsResult = components.PointerEventsResult(engine) let count = 0 diff --git a/test/snapshots/production-bundles/append-value-crdt.ts.crdt b/test/snapshots/production-bundles/append-value-crdt.ts.crdt index 03cf9f92c..8c9f55407 100644 --- a/test/snapshots/production-bundles/append-value-crdt.ts.crdt +++ b/test/snapshots/production-bundles/append-value-crdt.ts.crdt @@ -9,7 +9,7 @@ EVAL test/snapshots/production-bundles/append-value-crdt.js REQUIRE: ~system/EngineApi REQUIRE: ~system/EngineApi OPCODES ~= 33k - MALLOC_COUNT = 8869 + MALLOC_COUNT = 8877 ALIVE_OBJS_DELTA ~= 1.90k CALL onStart() Renderer: APPEND_VALUE e=0x200 c=1063 t=0 data={"button":0,"hit":{"position":{"x":1,"y":2,"z":3},"globalOrigin":{"x":1,"y":2,"z":3},"direction":{"x":1,"y":2,"z":3},"normalHit":{"x":1,"y":2,"z":3},"length":10,"meshName":"mesh","entityId":512},"state":1,"timestamp":1,"analog":5,"tickNumber":0} @@ -55,4 +55,4 @@ CALL onUpdate(0.1) OPCODES ~= 13k MALLOC_COUNT = 31 ALIVE_OBJS_DELTA ~= 0.01k - MEMORY_USAGE_COUNT ~= 725.82k bytes \ No newline at end of file + MEMORY_USAGE_COUNT ~= 726.14k bytes \ No newline at end of file diff --git a/test/snapshots/production-bundles/billboard.ts.crdt b/test/snapshots/production-bundles/billboard.ts.crdt index ad3de6151..7891ecad0 100644 --- a/test/snapshots/production-bundles/billboard.ts.crdt +++ b/test/snapshots/production-bundles/billboard.ts.crdt @@ -9,7 +9,7 @@ EVAL test/snapshots/production-bundles/billboard.js REQUIRE: ~system/EngineApi REQUIRE: ~system/EngineApi OPCODES ~= 43k - MALLOC_COUNT = 11185 + MALLOC_COUNT = 11184 ALIVE_OBJS_DELTA ~= 2.35k CALL onStart() OPCODES ~= 0k @@ -77,4 +77,4 @@ CALL onUpdate(0.1) OPCODES ~= 8k MALLOC_COUNT = 0 ALIVE_OBJS_DELTA ~= 0.00k - MEMORY_USAGE_COUNT ~= 877.13k bytes \ No newline at end of file + MEMORY_USAGE_COUNT ~= 877.24k bytes \ No newline at end of file diff --git a/test/snapshots/production-bundles/composite.ts b/test/snapshots/production-bundles/composite.ts deleted file mode 100644 index c2fcc3bbe..000000000 --- a/test/snapshots/production-bundles/composite.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { engine, MeshRenderer, Transform } from '@dcl/sdk/ecs' - -const cube = engine.addEntity() -Transform.create(cube) -MeshRenderer.setBox(cube) diff --git a/test/snapshots/production-bundles/cube-deleted.ts.crdt b/test/snapshots/production-bundles/cube-deleted.ts.crdt index 1790c969d..eebc0690a 100644 --- a/test/snapshots/production-bundles/cube-deleted.ts.crdt +++ b/test/snapshots/production-bundles/cube-deleted.ts.crdt @@ -1,4 +1,4 @@ -SCENE_COMPILED_JS_SIZE_PROD=162.8k bytes +SCENE_COMPILED_JS_SIZE_PROD=162.9k bytes (start empty vm 0.21.0-3680274614.commit-1808aa1) OPCODES ~= 0k MALLOC_COUNT = 1005 @@ -8,8 +8,8 @@ EVAL test/snapshots/production-bundles/cube-deleted.js REQUIRE: long REQUIRE: ~system/EngineApi REQUIRE: ~system/EngineApi - OPCODES ~= 33k - MALLOC_COUNT = 8416 + OPCODES ~= 32k + MALLOC_COUNT = 8415 ALIVE_OBJS_DELTA ~= 1.77k CALL onStart() OPCODES ~= 0k @@ -42,4 +42,4 @@ CALL onUpdate(0.1) OPCODES ~= 3k MALLOC_COUNT = 1 ALIVE_OBJS_DELTA ~= 0.00k - MEMORY_USAGE_COUNT ~= 699.58k bytes \ No newline at end of file + MEMORY_USAGE_COUNT ~= 699.68k bytes \ No newline at end of file diff --git a/test/snapshots/production-bundles/cube.ts.crdt b/test/snapshots/production-bundles/cube.ts.crdt index 395ab7d05..eb1ad4c54 100644 --- a/test/snapshots/production-bundles/cube.ts.crdt +++ b/test/snapshots/production-bundles/cube.ts.crdt @@ -9,7 +9,7 @@ EVAL test/snapshots/production-bundles/cube.js REQUIRE: ~system/EngineApi REQUIRE: ~system/EngineApi OPCODES ~= 32k - MALLOC_COUNT = 8255 + MALLOC_COUNT = 8254 ALIVE_OBJS_DELTA ~= 1.74k CALL onStart() OPCODES ~= 0k @@ -32,4 +32,4 @@ CALL onUpdate(0.1) OPCODES ~= 1k MALLOC_COUNT = 0 ALIVE_OBJS_DELTA ~= 0.00k - MEMORY_USAGE_COUNT ~= 684.08k bytes \ No newline at end of file + MEMORY_USAGE_COUNT ~= 684.18k bytes \ No newline at end of file diff --git a/test/snapshots/production-bundles/cubes.ts.crdt b/test/snapshots/production-bundles/cubes.ts.crdt index 411090ad3..a755e8624 100644 --- a/test/snapshots/production-bundles/cubes.ts.crdt +++ b/test/snapshots/production-bundles/cubes.ts.crdt @@ -8,8 +8,8 @@ EVAL test/snapshots/production-bundles/cubes.js REQUIRE: long REQUIRE: ~system/EngineApi REQUIRE: ~system/EngineApi - OPCODES ~= 83k - MALLOC_COUNT = 14635 + OPCODES ~= 82k + MALLOC_COUNT = 14634 ALIVE_OBJS_DELTA ~= 3.66k CALL onStart() OPCODES ~= 0k @@ -1652,4 +1652,4 @@ CALL onUpdate(0.1) OPCODES ~= 636k MALLOC_COUNT = 0 ALIVE_OBJS_DELTA ~= 0.00k - MEMORY_USAGE_COUNT ~= 1015.28k bytes \ No newline at end of file + MEMORY_USAGE_COUNT ~= 1015.37k bytes \ No newline at end of file diff --git a/test/snapshots/production-bundles/pointer-events.ts.crdt b/test/snapshots/production-bundles/pointer-events.ts.crdt index 5f7f98b48..b13128911 100644 --- a/test/snapshots/production-bundles/pointer-events.ts.crdt +++ b/test/snapshots/production-bundles/pointer-events.ts.crdt @@ -8,8 +8,8 @@ EVAL test/snapshots/production-bundles/pointer-events.js REQUIRE: long REQUIRE: ~system/EngineApi REQUIRE: ~system/EngineApi - OPCODES ~= 34k - MALLOC_COUNT = 8757 + OPCODES ~= 33k + MALLOC_COUNT = 8756 ALIVE_OBJS_DELTA ~= 1.87k CALL onStart() OPCODES ~= 0k @@ -43,4 +43,4 @@ CALL onUpdate(0.1) OPCODES ~= 1k MALLOC_COUNT = 0 ALIVE_OBJS_DELTA ~= 0.00k - MEMORY_USAGE_COUNT ~= 708.61k bytes \ No newline at end of file + MEMORY_USAGE_COUNT ~= 708.72k bytes \ No newline at end of file diff --git a/test/snapshots/production-bundles/schema-components.ts.crdt b/test/snapshots/production-bundles/schema-components.ts.crdt index e15c47899..f07315d7e 100644 --- a/test/snapshots/production-bundles/schema-components.ts.crdt +++ b/test/snapshots/production-bundles/schema-components.ts.crdt @@ -9,7 +9,7 @@ EVAL test/snapshots/production-bundles/schema-components.js REQUIRE: ~system/EngineApi REQUIRE: ~system/EngineApi OPCODES ~= 36k - MALLOC_COUNT = 8374 + MALLOC_COUNT = 8373 ALIVE_OBJS_DELTA ~= 1.77k CALL onStart() OPCODES ~= 0k @@ -31,4 +31,4 @@ CALL onUpdate(0.1) OPCODES ~= 1k MALLOC_COUNT = 0 ALIVE_OBJS_DELTA ~= 0.00k - MEMORY_USAGE_COUNT ~= 686.44k bytes \ No newline at end of file + MEMORY_USAGE_COUNT ~= 686.55k bytes \ No newline at end of file diff --git a/test/snapshots/production-bundles/ui.ts.crdt b/test/snapshots/production-bundles/ui.ts.crdt index f5e754a9d..f31e5b6ae 100644 --- a/test/snapshots/production-bundles/ui.ts.crdt +++ b/test/snapshots/production-bundles/ui.ts.crdt @@ -9,7 +9,7 @@ EVAL test/snapshots/production-bundles/ui.js REQUIRE: ~system/EngineApi REQUIRE: ~system/EngineApi OPCODES ~= 42k - MALLOC_COUNT = 16007 + MALLOC_COUNT = 16006 ALIVE_OBJS_DELTA ~= 3.03k CALL onStart() OPCODES ~= 0k @@ -65,4 +65,4 @@ CALL onUpdate(0.1) OPCODES ~= 61k MALLOC_COUNT = 0 ALIVE_OBJS_DELTA ~= 0.00k - MEMORY_USAGE_COUNT ~= 1506.17k bytes \ No newline at end of file + MEMORY_USAGE_COUNT ~= 1506.28k bytes \ No newline at end of file diff --git a/test/snapshots/production-bundles/with-main-function.ts b/test/snapshots/production-bundles/with-main-function.ts new file mode 100644 index 000000000..82c888282 --- /dev/null +++ b/test/snapshots/production-bundles/with-main-function.ts @@ -0,0 +1,12 @@ +import { engine, GltfContainer, MeshRenderer, Transform } from '@dcl/sdk/ecs' + +export function main() { + const cube = engine.addEntity() + Transform.create(cube) + MeshRenderer.setBox(cube) + + engine.addSystem(() => { + const newEntity = engine.addEntity() + GltfContainer.create(newEntity, { src: 'test.glb' }) + }) +} diff --git a/test/snapshots/production-bundles/with-main-function.ts.crdt b/test/snapshots/production-bundles/with-main-function.ts.crdt index a5e14e9b5..3a96ab477 100644 --- a/test/snapshots/production-bundles/with-main-function.ts.crdt +++ b/test/snapshots/production-bundles/with-main-function.ts.crdt @@ -1,4 +1,4 @@ -SCENE_COMPILED_JS_SIZE_PROD=156k bytes +SCENE_COMPILED_JS_SIZE_PROD=162.9k bytes (start empty vm 0.21.0-3680274614.commit-1808aa1) OPCODES ~= 0k MALLOC_COUNT = 1005 @@ -8,33 +8,32 @@ EVAL test/snapshots/production-bundles/with-main-function.js REQUIRE: long REQUIRE: ~system/EngineApi REQUIRE: ~system/EngineApi - OPCODES ~= 31k - MALLOC_COUNT = 8444 - ALIVE_OBJS_DELTA ~= 1.78k + OPCODES ~= 33k + MALLOC_COUNT = 8507 + ALIVE_OBJS_DELTA ~= 1.80k CALL onStart() OPCODES ~= 0k MALLOC_COUNT = 6 ALIVE_OBJS_DELTA ~= 0.00k CALL onUpdate(0) Scene: PUT_COMPONENT e=0x200 c=1 t=1 data={"position":{"x":0,"y":0,"z":0},"rotation":{"x":0,"y":0,"z":0,"w":1},"scale":{"x":1,"y":1,"z":1},"parent":0} - Scene: PUT_COMPONENT e=0x201 c=1041 t=1 data={"src":"test.glb"} Scene: PUT_COMPONENT e=0x200 c=1018 t=1 data={"mesh":{"$case":"box","box":{"uvs":[]}}} - OPCODES ~= 5k - MALLOC_COUNT = 75 + OPCODES ~= 3k + MALLOC_COUNT = 69 ALIVE_OBJS_DELTA ~= 0.03k CALL onUpdate(0.1) - Scene: PUT_COMPONENT e=0x202 c=1041 t=1 data={"src":"test.glb"} + Scene: PUT_COMPONENT e=0x201 c=1041 t=1 data={"src":"test.glb"} OPCODES ~= 2k - MALLOC_COUNT = 5 + MALLOC_COUNT = 6 ALIVE_OBJS_DELTA ~= 0.00k CALL onUpdate(0.1) - Scene: PUT_COMPONENT e=0x203 c=1041 t=1 data={"src":"test.glb"} + Scene: PUT_COMPONENT e=0x202 c=1041 t=1 data={"src":"test.glb"} OPCODES ~= 2k MALLOC_COUNT = 5 ALIVE_OBJS_DELTA ~= 0.00k CALL onUpdate(0.1) - Scene: PUT_COMPONENT e=0x204 c=1041 t=1 data={"src":"test.glb"} + Scene: PUT_COMPONENT e=0x203 c=1041 t=1 data={"src":"test.glb"} OPCODES ~= 2k MALLOC_COUNT = 5 ALIVE_OBJS_DELTA ~= 0.00k - MEMORY_USAGE_COUNT ~= 692.12k bytes \ No newline at end of file + MEMORY_USAGE_COUNT ~= 702.02k bytes \ No newline at end of file