xxshady / altv-esbuild Goto Github PK
View Code? Open in Web Editor NEWHot reload (without reconnect and restart of the server) ✨
Home Page: https://xxshady.github.io/altv-esbuild
Hot reload (without reconnect and restart of the server) ✨
Home Page: https://xxshady.github.io/altv-esbuild
Example repro
server.toml
modules = [ "js-module" ]
resources = [
"test",
"main"
]
resource.toml
type = "js"
main = "server.js"
server.js
export const test = () => 10
import { test } from "test" // runtime nodejs error when altv-esbuild dev mode is on
TypeDoc exiting with unexpected error:
TypeError: ts.isIdentifierOrPrivateIdentifier is not a functio
Implementation of workaround for altmp/altv-issues#1046
Only when "dev: true" I get this error when setting external module :
[Error] [altv-esbuild] Top-level exception:
ReferenceError: ___altvEsbuild_externalOnTop_node_x__alt_x_altv_x_csharp_x_entity_x_sync_x_to_x_js_x_wrapper___ is not defined
at altv-esbuild:externals-on-top:alt:altv-csharp-entity-sync-to-js-wrapper (file:///xxxxxxxxx/resources/xear-3d-audio-api/dist/server/index.mjs:84:25)
at __require (file:///xxxxxxxxxx/resources/xear-3d-audio-api/dist/server/index.mjs:45:50)
at file:///E:/Dropbox/Game%20Dev/AltV/altv-server-DEV-W/resources/xear-3d-audio-api/dist/server/index.mjs:93:30
My watch-server :
import { build } from "esbuild"
import { altvEsbuild } from "altv-esbuild"
build({
watch: true,
bundle: true,
platform: "node",
logLevel: "info",
target: "esnext",
format: "esm",
external: ["alt:altv-csharp-entity-sync-to-js-wrapper"],
entryPoints: ["./resources/xear-3d-audio-api/src/server/index.mjs"],
outfile: "./resources/xear-3d-audio-api/dist/server/index.mjs",
plugins: [
altvEsbuild({
mode: "server",
dev: true, // enables hot reload automatically
altvEnums: false,
})
],
})
In "/server/index.mjs" have :
import alt from 'alt-server'
import * as EntitySyncWrap from 'alt:altv-csharp-entity-sync-to-js-wrapper'
altv-esbuild only works in v1 compatibility mode of js module v2
I wanted to deploy altv-server for local development in Docker. And I'm having trouble net connecting altv-server-inject to my esbuild server.
The problem would be solved by being able to specify the host of the esbuild server.
But I thought, why is this connection needed at all? Altv server itself can monitor resource updates and reload them on the fly.
I tested fs.watch too
import fs from "fs";
fs.watch('./resources/chat/server/index.js', (eventType, filename) => {
alt.log(filename + ' changed');
});
And it works.
You can tie a resource reloading to this.
This can even be packaged as a separate resource for reloading resources. And use it in esbuild
Improve altvEnums
feature by adding ability (it will be a separate option enhancedAltvEnums
for backward compatibility) to use enums directly from alt-* modules, as with default typescript compiler (tsc):
- import { RadioStation } from 'altv-enums'
+ import { RadioStation } from 'alt-server'
To allow such code i will add transpilation of enums to js from your own local node_modules/@altv/types-*
on initial build of code
(types-server, types-client, types-shared)
I think it would be good to add "how it works" readme section for alt:V community
Add option to display sources in stack traces of exceptions on client-side using Error.prepareStackTrace
if esbuild source-maps are enabled.
I don't know how to reproduce it with a clean script, though.
clientReady
event to server and server thinks its on same versionAdd api to the altv code to trigger the connection of already connected players during the start of the resource to connect them by user code decision.
Something like this
import { triggerPlayersConnect } from 'altv-esbuild'
function initDatabase() {
// ... some database async shit
triggerPlayersConnect()
}
Players reconnect emulation emits playerConnect, so why not emit playerDisconnect as well?
Allow users to intercept various function calls in the alt:V JS API for debugging/development purposes
Example:
altvEsbuild({
mode: "client",
dev: {
hooks: {
// "alt-client" module
alt: {
// hook function must be an arrow-function so it can be converted to a string
// caution: variables from outer scope (any variable of build script) can't be used
log: (args, originalFunc, alt) => {
originalFunc("alt.log is called")
originalFunc(...args)
alt.logWarning("calling another api function")
alt.log("since alt.log is hooked this call will cause infinite recursion")
},
},
// "natives" module (clientside only ofcourse)
natives: {
},
globalThis: {
console: { ... },
setTimeout,
// ....etc.
}
}
}
})
Plugin option dev
and bugFixes
should depend on the mode
option passed, e.g. playersReconnect
is for server
only
https://discord.com/channels/371265202378899476/576771706119520287/1094333403081486476
Temp fix:
// everywhere in your code
- import * as alt from 'alt-client'
+ import alt from 'alt-client'
// your esbuild build script
esbuild.build({
plugins: [altvEsbuild({ altDefaultImport: true })]
})
With my project in JS that use an external C# to JS wrapper I get this error :
[server] X [ERROR] Could not resolve "altv-csharp-entity-sync-to-js-wrapper"
[server]
[server] resources/altvfpvdrone-objapi-dev/src/server/index.mjs:2:32:
2 │ ...rt * as EntitySyncWrap from 'altv-csharp-entity-sync-to-js-wrapper'
[server] ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[server]
[server] You can mark the path "altv-csharp-entity-sync-to-js-wrapper" as external to exclude it from the bundle, which will remove this error.
[server]
[server] 1 error
I have added :
external: "altv-csharp-entity-sync-to-js-wrapper",
To the build({}) of watch-server.js but the error remained.
watch-server.js :
import { build } from "esbuild"
import { altvEsbuild } from "altv-esbuild"
build({
watch: true,
bundle: true,
platform: "node",
logLevel: "info",
external: "altv-csharp-entity-sync-to-js-wrapper",
entryPoints: ["./resources/altvfpvdrone-objapi-dev/src/server/index.mjs"],
outfile: "./resources/altvfpvdrone-objapi-dev/dist/server/index.mjs",
plugins: [
altvEsbuild({
mode: "server",
dev: true, // enables hot reload automatically
altvEnums: true,
})
],
})
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.