Skip to content

Commit c111c76

Browse files
authored
Merge pull request #241 from AthennaIO/develop
chore(npm): update dependencies
2 parents d996a27 + 65a520e commit c111c76

File tree

8 files changed

+118
-292
lines changed

8 files changed

+118
-292
lines changed

package-lock.json

+106-117
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@athenna/core",
3-
"version": "5.6.0",
3+
"version": "5.7.0",
44
"description": "One foundation for multiple applications.",
55
"license": "MIT",
66
"author": "João Lenon <lenon@athenna.io>",
@@ -82,10 +82,10 @@
8282
},
8383
"devDependencies": {
8484
"@athenna/artisan": "^5.3.0",
85-
"@athenna/common": "^5.3.0",
85+
"@athenna/common": "^5.5.0",
8686
"@athenna/config": "^5.1.0",
8787
"@athenna/cron": "^5.4.0",
88-
"@athenna/http": "^5.6.0",
88+
"@athenna/http": "^5.10.0",
8989
"@athenna/ioc": "^5.0.0",
9090
"@athenna/logger": "^5.1.0",
9191
"@athenna/test": "^5.2.0",

src/applications/Http.ts

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ export class Http {
3434

3535
ioc.safeUse('Athenna/Core/HttpRoute').register()
3636

37+
if (process.argv.includes('--vite')) {
38+
await server.viteReady()
39+
}
40+
3741
await server.listen({ host: options.host, port: options.port })
3842

3943
if (Config.notExists('rc.bootLogs') || Config.is('rc.bootLogs', false)) {
@@ -79,6 +83,7 @@ export class Http {
7983
await kernel.registerHelmet()
8084
await kernel.registerStatic()
8185
await kernel.registerSwagger()
86+
await kernel.registerVite()
8287
await kernel.registerRateLimit()
8388
await kernel.registerRTracer(options.trace)
8489
await kernel.registerLoggerTerminator()

src/commands/BuildCommand.ts

+2-33
Original file line numberDiff line numberDiff line change
@@ -110,46 +110,15 @@ export class BuildCommand extends BaseCommand {
110110
}
111111

112112
public async getViteConfig(vite: any) {
113-
const defaultConfig = {
114-
root: Path.pwd(),
115-
assetsUrl: '/assets',
116-
buildDirectory: 'public/assets',
117-
logLevel: 'silent',
118-
css: {
119-
preprocessorOptions: {
120-
scss: {
121-
api: 'modern'
122-
}
123-
}
124-
},
125-
build: {
126-
assetsDir: '',
127-
manifest: true,
128-
emptyOutDir: true,
129-
outDir: 'public/assets',
130-
assetsInlineLimit: 0,
131-
rollupOptions: {
132-
output: {
133-
entryFileNames: '[name].js',
134-
chunkFileNames: '[name].js',
135-
assetFileNames: '[name].[ext]'
136-
}
137-
}
138-
}
139-
}
140-
141-
const { config: fileConfig } = await vite.loadConfigFromFile(
113+
const { config } = await vite.loadConfigFromFile(
142114
{
143115
command: 'build',
144-
mode: 'development'
116+
mode: 'production'
145117
},
146118
undefined,
147119
Path.pwd()
148120
)
149121

150-
const config = vite.mergeConfig(defaultConfig, fileConfig)
151-
await vite.build(config)
152-
153122
return config
154123
}
155124
}

src/commands/ServeCommand.ts

+2-85
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export class ServeCommand extends BaseCommand {
2222

2323
@Option({
2424
signature: '-v, --vite',
25-
description: 'Use vite to build your application static files.',
25+
description:
26+
'Turn on vite dev server for HMR and static files compilation.',
2627
default: false
2728
})
2829
public vite: boolean
@@ -41,24 +42,6 @@ export class ServeCommand extends BaseCommand {
4142
Path.bin(`main.${Path.ext()}`)
4243
)
4344

44-
if (this.vite) {
45-
const formerNodeEnv = Env('NODE_ENV')
46-
47-
const vite = await this.getVite()
48-
const config = await this.getViteConfig(vite)
49-
50-
await vite.build(config)
51-
52-
Log.channelOrVanilla('application').success(
53-
'Static files successfully compiled with ({yellow} vite)'
54-
)
55-
56-
/**
57-
* Vite changes NODE_ENV when building which we need to avoid.
58-
*/
59-
process.env.NODE_ENV = formerNodeEnv
60-
}
61-
6245
if (this.watch) {
6346
const nodemon = this.getNodemon()
6447

@@ -98,24 +81,6 @@ export class ServeCommand extends BaseCommand {
9881

9982
console.clear()
10083

101-
if (this.vite) {
102-
const formerNodeEnv = Env('NODE_ENV')
103-
104-
const vite = await this.getVite()
105-
const config = await this.getViteConfig(vite)
106-
107-
await vite.build(config)
108-
109-
Log.channelOrVanilla('application').success(
110-
'Static files successfully recompiled with ({yellow} vite)'
111-
)
112-
113-
/**
114-
* Vite changes NODE_ENV when building which we need to avoid.
115-
*/
116-
process.env.NODE_ENV = formerNodeEnv
117-
}
118-
11984
Log.channelOrVanilla('application').success(
12085
'Application successfully restarted'
12186
)
@@ -135,52 +100,4 @@ export class ServeCommand extends BaseCommand {
135100

136101
return require('nodemon')
137102
}
138-
139-
public async getVite() {
140-
return import('vite')
141-
}
142-
143-
public async getViteConfig(vite: any) {
144-
const defaultConfig = {
145-
root: Path.pwd(),
146-
assetsUrl: '/assets',
147-
buildDirectory: 'public/assets',
148-
logLevel: 'silent',
149-
css: {
150-
preprocessorOptions: {
151-
scss: {
152-
api: 'modern'
153-
}
154-
}
155-
},
156-
build: {
157-
assetsDir: '',
158-
manifest: true,
159-
emptyOutDir: true,
160-
outDir: 'public/assets',
161-
assetsInlineLimit: 0,
162-
rollupOptions: {
163-
output: {
164-
entryFileNames: '[name].js',
165-
chunkFileNames: '[name].js',
166-
assetFileNames: '[name].[ext]'
167-
}
168-
}
169-
}
170-
}
171-
172-
const { config: fileConfig } = await vite.loadConfigFromFile(
173-
{
174-
command: 'build',
175-
mode: 'development'
176-
},
177-
undefined,
178-
Path.pwd()
179-
)
180-
181-
const config = vite.mergeConfig(defaultConfig, fileConfig)
182-
await vite.build(config)
183-
184-
return config
185-
}
186103
}

tests/fixtures/consoles/build-vite.ts

-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ vite.loadConfigFromFile = function () {
3535
return { config: {} }
3636
}
3737

38-
vite.mergeConfig = function () {
39-
return {}
40-
}
41-
4238
vite.build = function () {
4339
return this
4440
}

tests/fixtures/consoles/serve-vite-with-logs.ts

-25
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
* file that was distributed with this source code.
88
*/
99

10-
import { Mock } from '@athenna/test'
1110
import { Path } from '@athenna/common'
1211
import { ViewProvider } from '@athenna/view'
1312
import { Rc, Config } from '@athenna/config'
1413
import { LoggerProvider } from '@athenna/logger'
15-
import { ServeCommand } from '#src/commands/ServeCommand'
1614
import { Artisan, ConsoleKernel, ArtisanProvider } from '@athenna/artisan'
1715

1816
new ViewProvider().register()
@@ -27,29 +25,6 @@ Path.mergeDirs(Config.get('rc.directories', {}))
2725

2826
await new ConsoleKernel().registerCommands()
2927

30-
const vite = function () {
31-
return Mock.fake()
32-
}
33-
34-
vite.loadConfigFromFile = function () {
35-
return { config: {} }
36-
}
37-
38-
vite.mergeConfig = function () {
39-
return {}
40-
}
41-
42-
vite.build = function () {
43-
return this
44-
}
45-
46-
const vitePluginRestart = function () {
47-
return Mock.fake()
48-
}
49-
5028
Config.set('rc.bootLogs', true)
5129

52-
Mock.when(ServeCommand.prototype, 'getVite').return(vite)
53-
Mock.when(ServeCommand.prototype, 'getVitePluginRestart').return(vitePluginRestart)
54-
5530
await Artisan.parse(process.argv)

tests/fixtures/consoles/serve-vite.ts

-25
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
* file that was distributed with this source code.
88
*/
99

10-
import { Mock } from '@athenna/test'
1110
import { Path } from '@athenna/common'
1211
import { ViewProvider } from '@athenna/view'
1312
import { Rc, Config } from '@athenna/config'
1413
import { LoggerProvider } from '@athenna/logger'
15-
import { ServeCommand } from '#src/commands/ServeCommand'
1614
import { Artisan, ConsoleKernel, ArtisanProvider } from '@athenna/artisan'
1715

1816
new ViewProvider().register()
@@ -27,27 +25,4 @@ Path.mergeDirs(Config.get('rc.directories', {}))
2725

2826
await new ConsoleKernel().registerCommands()
2927

30-
const vite = function () {
31-
return Mock.fake()
32-
}
33-
34-
vite.loadConfigFromFile = function () {
35-
return { config: {} }
36-
}
37-
38-
vite.mergeConfig = function () {
39-
return {}
40-
}
41-
42-
vite.build = function () {
43-
return this
44-
}
45-
46-
const vitePluginRestart = function () {
47-
return Mock.fake()
48-
}
49-
50-
Mock.when(ServeCommand.prototype, 'getVite').return(vite)
51-
Mock.when(ServeCommand.prototype, 'getVitePluginRestart').return(vitePluginRestart)
52-
5328
await Artisan.parse(process.argv)

0 commit comments

Comments
 (0)