Skip to content

Commit

Permalink
refactor: move to --unstable-hmr flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed Apr 13, 2024
1 parent 6c2bff9 commit cdc266a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 5 additions & 5 deletions commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class Serve extends BaseCommand {
'',
'You can also start the server with HMR support using the following command.',
'```',
'{{ binaryName }} serve --hmr',
'{{ binaryName }} serve --unstable-hmr',
'```',
'',
'The assets bundler dev server runs automatically after detecting vite config or webpack config files',
Expand All @@ -47,7 +47,7 @@ export default class Serve extends BaseCommand {
declare devServer: DevServer

@flags.boolean({ description: 'Start the server with HMR support' })
declare hmr?: boolean
declare unstableHmr?: boolean

@flags.boolean({
description: 'Watch filesystem and restart the HTTP server on file change',
Expand Down Expand Up @@ -120,14 +120,14 @@ export default class Serve extends BaseCommand {
return
}

if (this.watch && this.hmr) {
this.logger.error('Cannot use --watch and --hmr flags together. Choose one of them')
if (this.watch && this.unstableHmr) {
this.logger.error('Cannot use --watch and --unstable-hmr flags together. Choose one of them')
this.exitCode = 1
return
}

this.devServer = new assembler.DevServer(this.app.appRoot, {
hmr: this.hmr === true ? true : false,
hmr: this.unstableHmr === true ? true : false,

Check failure on line 130 in commands/serve.ts

View workflow job for this annotation

GitHub Actions / typecheck / typecheck

Object literal may only specify known properties, and 'hmr' does not exist in type 'DevServerOptions'.

Check failure on line 130 in commands/serve.ts

View workflow job for this annotation

GitHub Actions / typecheck / typecheck

Object literal may only specify known properties, and 'hmr' does not exist in type 'DevServerOptions'.
clearScreen: this.clear === false ? false : true,
nodeArgs: this.parsed.nodeArgs,
scriptArgs: [],
Expand Down
9 changes: 6 additions & 3 deletions tests/commands/serve.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ test.group('Serve command', () => {
await sleep(1200)
})

test('error if --hmr and --watch are used together', async ({ assert, fs, cleanup }) => {
test('error if --unstable-hmr and --watch are used together', async ({ assert, fs, cleanup }) => {

Check failure on line 341 in tests/commands/serve.spec.ts

View workflow job for this annotation

GitHub Actions / typecheck / typecheck

'cleanup' is declared but its value is never read.

Check failure on line 341 in tests/commands/serve.spec.ts

View workflow job for this annotation

GitHub Actions / typecheck / typecheck

'cleanup' is declared but its value is never read.
await fs.create('node_modules/ts-node/esm.js', '')

const ace = await new AceFactory().make(fs.baseUrl, {
Expand All @@ -347,12 +347,15 @@ test.group('Serve command', () => {

ace.ui.switchMode('raw')

const command = await ace.create(Serve, ['--hmr', '--watch', '--no-clear'])
const command = await ace.create(Serve, ['--unstable-hmr', '--watch', '--no-clear'])
await command.exec()

assert.equal(command.exitCode, 1)
assert.lengthOf(ace.ui.logger.getLogs(), 1)
assert.equal(ace.ui.logger.getLogs()[0].stream, 'stderr')
assert.match(ace.ui.logger.getLogs()[0].message, /Cannot use --watch and --hmr flags together/)
assert.match(
ace.ui.logger.getLogs()[0].message,
/Cannot use --watch and --unstable-hmr flags together/
)
})
})

0 comments on commit cdc266a

Please sign in to comment.