Skip to content

Commit

Permalink
feat: spirits system now enabled by default
Browse files Browse the repository at this point in the history
This has been put to the test for a while now and has gone various improvements. So much that it might even be more stable than the older system.

The legacy process system is still available via a new `legacyProcess` experimental flag and will be retired in the next version after this one if all goes well.
  • Loading branch information
Pkmmte committed Aug 24, 2023
1 parent be80470 commit 2a599e6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-planets-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@roboplay/robo.js': minor
---

feat: spirits system now enabled by default
22 changes: 14 additions & 8 deletions packages/robo/src/cli/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function devAction(_args: string[], options: DevCommandOptions) {
}

// Ensure worker spirits are ready
if (config.experimental?.spirits) {
if (!config.experimental?.legacyProcess) {
spirits = new Spirits()

// Stop spirits on process exit
Expand Down Expand Up @@ -123,13 +123,18 @@ async function devAction(_args: string[], options: DevCommandOptions) {
logger.debug(`State loaded in ${Date.now() - stateStart}ms`)

// Start the Robo!
if (buildSuccess && config.experimental?.spirits) {
if (buildSuccess && !config.experimental?.legacyProcess) {
roboSpirit = await spirits.newTask<string>({
event: 'start',
onExit: (exitCode: number) => {
if (exitCode !== 0) {
logger.error(
composeColors(color.bgBlack, color.redBright, color.underline, color.bold)(`Robo exited with code ${exitCode}.`),
composeColors(
color.bgBlack,
color.redBright,
color.underline,
color.bold
)(`Robo exited with code ${exitCode}.`),
`Restarting...`
)
return true
Expand Down Expand Up @@ -191,7 +196,7 @@ async function devAction(_args: string[], options: DevCommandOptions) {
}

// Rebuild and restart
if (config.experimental?.spirits) {
if (!config.experimental?.legacyProcess) {
roboSpirit = await rebuildRobo(roboSpirit, config, options.verbose, changes)
spirits.on(roboSpirit, restartCallback)
} else {
Expand Down Expand Up @@ -225,7 +230,7 @@ export async function buildAsync(command: string, config: Config, verbose: boole
const args = command.split(' ')
const start = Date.now()

if (config.experimental?.spirits) {
if (!config.experimental?.legacyProcess) {
spirits
.newTask({
event: 'build',
Expand Down Expand Up @@ -295,9 +300,10 @@ async function rebuildRobo(spiritId: string, config: Config, verbose: boolean, c
// Get state dump before restarting
const stateSaveStart = Date.now()
logger.debug('Saving state...')
const savedState = await spirits.exec<Record<string, unknown>>(roboSpirit, {
event: 'get-state'
}) ?? {}
const savedState =
(await spirits.exec<Record<string, unknown>>(roboSpirit, {
event: 'get-state'
})) ?? {}
logger.debug(`Saved state in ${Date.now() - stateSaveStart}ms:`, savedState)

// Stop the previous spirit if it's still running
Expand Down
2 changes: 1 addition & 1 deletion packages/robo/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface Config {
}
experimental?: {
incrementalBuilds?: boolean
spirits?: boolean
legacyProcess?: boolean
}
flashcore?: {
keyv?: unknown
Expand Down

1 comment on commit 2a599e6

@vercel
Copy link

@vercel vercel bot commented on 2a599e6 Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.