hytopia 0.10.27-prerelease-2 → 0.10.27-prerelease-4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/scripts.js CHANGED
@@ -6,7 +6,6 @@ import fs from 'fs';
6
6
  import path from 'path';
7
7
  import readline from 'readline';
8
8
  import { fileURLToPath } from 'url';
9
- import * as esbuild from 'esbuild';
10
9
 
11
10
  // Store command-line flags
12
11
  const flags = {};
@@ -66,24 +65,8 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
66
65
  * @example
67
66
  */
68
67
  async function build() {
69
- console.log('🔧 Building project...');
70
-
71
- await esbuild.build({
72
- entryPoints: ['index.ts'],
73
- outfile: './index.mjs',
74
- bundle: true,
75
- format: 'esm',
76
- platform: 'node',
77
- target: 'node24',
78
- sourcemap: 'inline',
79
- mainFields: ['module', 'main'],
80
- conditions: ['import', 'node'],
81
- treeShaking: true,
82
- minify: true,
83
- banner: {
84
- js: 'import { createRequire as __cr } from "module"; import { fileURLToPath } from "url"; import { dirname as __bundlerDirname } from "path"; const require = __cr(import.meta.url); const __filename = fileURLToPath(import.meta.url); const __dirname = __bundlerDirname(__filename);'
85
- }
86
- });
68
+ console.log('🔧 Building project (bun)...');
69
+ execSync('npx --yes bun build --target=node --format=esm --outfile=index.mjs index.ts', { stdio: 'inherit' });
87
70
  }
88
71
 
89
72
  /**
@@ -94,6 +77,8 @@ function start() {
94
77
  (async () => {
95
78
  let child = null;
96
79
  let restartTimer = null;
80
+ let bunProc = null;
81
+ let watcher = null;
97
82
 
98
83
  const stopNode = () => {
99
84
  if (child && !child.killed) {
@@ -106,42 +91,45 @@ function start() {
106
91
  child = spawn(process.execPath, ['--enable-source-maps', 'index.mjs'], { stdio: 'inherit', shell: false });
107
92
  };
108
93
 
109
- const ctx = await esbuild.context({
110
- entryPoints: ['index.ts'],
111
- outfile: './index.mjs',
112
- bundle: true,
113
- format: 'esm',
114
- platform: 'node',
115
- target: 'node24',
116
- sourcemap: 'inline',
117
- external: [ 'mediasoup' ], // prevent pathing issues in dev env, prod sets the bin path so no issue bundling in prod build/package.
118
- mainFields: ['module', 'main'],
119
- conditions: ['import', 'node'],
120
- treeShaking: true,
121
- minify: true,
122
- banner: {
123
- js: 'import { createRequire as __cr } from "module"; import { fileURLToPath } from "url"; import { dirname } from "path"; const require = __cr(import.meta.url); const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename);'
124
- },
125
- plugins: [{
126
- name: 'restart-after-build',
127
- setup(build) {
128
- build.onStart(() => {
129
- if (restartTimer) { clearTimeout(restartTimer); restartTimer = null; }
130
- });
131
- build.onEnd((result) => {
132
- if (result.errors?.length) return;
133
- restartTimer = setTimeout(restartNode, 150);
134
- });
135
- }
136
- }]
137
- });
94
+ // Start bun build in watch mode. Externalize mediasoup similar to previous dev behavior.
95
+ const bunArgs = [
96
+ '--yes', 'bun', 'build',
97
+ '--target=node',
98
+ '--format=esm',
99
+ '--outfile=index.mjs',
100
+ '--external=mediasoup',
101
+ '--watch',
102
+ 'index.ts'
103
+ ];
104
+ bunProc = spawn('npx', bunArgs, { stdio: 'inherit', shell: false });
105
+
106
+ const outputFile = path.join(process.cwd(), 'index.mjs');
107
+ // If output exists, start the node process; otherwise wait for first build
108
+ if (fs.existsSync(outputFile)) {
109
+ restartNode();
110
+ }
138
111
 
139
- await ctx.watch();
112
+ // Watch for changes to the output file and restart the node process
113
+ try {
114
+ watcher = fs.watch(outputFile, { persistent: true }, () => {
115
+ if (restartTimer) { clearTimeout(restartTimer); restartTimer = null; }
116
+ restartTimer = setTimeout(restartNode, 150);
117
+ });
118
+ } catch {
119
+ // Fallback: watch the current directory for changes to index.mjs
120
+ watcher = fs.watch(process.cwd(), { persistent: true }, (eventType, filename) => {
121
+ if (filename === 'index.mjs') {
122
+ if (restartTimer) { clearTimeout(restartTimer); restartTimer = null; }
123
+ restartTimer = setTimeout(restartNode, 150);
124
+ }
125
+ });
126
+ }
140
127
 
141
128
  const cleanup = async () => {
142
129
  if (restartTimer) clearTimeout(restartTimer);
143
130
  stopNode();
144
- try { await ctx.dispose(); } catch {}
131
+ try { if (watcher) watcher.close(); } catch {}
132
+ try { if (bunProc && !bunProc.killed) bunProc.kill(); } catch {}
145
133
  process.exit(0);
146
134
  };
147
135
 
@@ -661,7 +649,7 @@ function displayHelp() {
661
649
  console.log('Commands:');
662
650
  console.log(' help, -h, --help Show this help');
663
651
  console.log(' version, -v, --version Show CLI version');
664
- console.log(' build Build the project (Generates ESM index.js)');
652
+ console.log(' build Build the project (Generates ESM index.mjs)');
665
653
  console.log(' start Start a HYTOPIA project server (Node.js & watch)');
666
654
  console.log(' init [--template NAME] Initialize a new project');
667
655
  console.log(' init-mcp Setup MCP integrations');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hytopia",
3
- "version": "0.10.27-prerelease-2",
3
+ "version": "0.10.27-prerelease-4",
4
4
  "description": "The HYTOPIA SDK makes it easy for developers to create massively multiplayer games using JavaScript or TypeScript.",
5
5
  "type": "module",
6
6
  "main": "./server.mjs",