@athenna/http 5.10.0 → 5.12.0
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/package.json +2 -2
- package/src/types/vite/PluginOptions.d.ts +33 -0
- package/src/types/vite/PluginOptions.js +9 -0
- package/src/vite/config.d.ts +22 -0
- package/src/vite/config.js +57 -0
- package/src/vite/plugin.d.ts +11 -0
- package/src/vite/plugin.js +25 -0
- package/src/vite/index.d.ts +0 -2
- package/src/vite/index.js +0 -34
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/http",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.12.0",
|
|
4
4
|
"description": "The Athenna Http server. Built on top of fastify.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "João Lenon <lenon@athenna.io>",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"./types": "./src/types/index.js",
|
|
52
52
|
"./package": "./package.json",
|
|
53
53
|
"./package.json": "./package.json",
|
|
54
|
-
"./vite": "./src/vite/
|
|
54
|
+
"./vite/plugin": "./src/vite/plugin.js",
|
|
55
55
|
"./testing/plugins": "./src/testing/plugins/index.js",
|
|
56
56
|
"./kernels/HttpKernel": "./src/kernels/HttpKernel.js",
|
|
57
57
|
"./handlers/HttpExceptionHandler": "./src/handlers/HttpExceptionHandler.js",
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @athenna/http
|
|
3
|
+
*
|
|
4
|
+
* (c) João Lenon <lenon@athenna.io>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
export interface PluginOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The URL where the assets will be served. This is particularly
|
|
12
|
+
* useful if you are using a CDN to deploy your assets.
|
|
13
|
+
*
|
|
14
|
+
* @default ''
|
|
15
|
+
*/
|
|
16
|
+
assetsUrl?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Files that should trigger a page reload when changed.
|
|
19
|
+
*
|
|
20
|
+
* @default ['./src/resources/views/** /*.edge']
|
|
21
|
+
*/
|
|
22
|
+
reload?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* Paths to the entrypoints files
|
|
25
|
+
*/
|
|
26
|
+
entrypoints: string[];
|
|
27
|
+
/**
|
|
28
|
+
* Public directory where the assets will be compiled.
|
|
29
|
+
*
|
|
30
|
+
* @default 'public/assets'
|
|
31
|
+
*/
|
|
32
|
+
buildDirectory?: string;
|
|
33
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @athenna/http
|
|
3
|
+
*
|
|
4
|
+
* (c) João Lenon <lenon@athenna.io>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
import type { ConfigEnv, Plugin, UserConfig } from 'vite';
|
|
10
|
+
import type { PluginOptions } from '#src/types/vite/PluginOptions';
|
|
11
|
+
/**
|
|
12
|
+
* Resolve the `config.base` value
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveBase(config: UserConfig, options: Required<PluginOptions>, command: 'build' | 'serve'): string;
|
|
15
|
+
/**
|
|
16
|
+
* Vite config hook
|
|
17
|
+
*/
|
|
18
|
+
export declare function configHook(options: Required<PluginOptions>, userConfig: UserConfig, { command }: ConfigEnv): UserConfig;
|
|
19
|
+
/**
|
|
20
|
+
* Update the user vite config to match Athenna requirements.
|
|
21
|
+
*/
|
|
22
|
+
export declare const config: (options: Required<PluginOptions>) => Plugin;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @athenna/http
|
|
3
|
+
*
|
|
4
|
+
* (c) João Lenon <lenon@athenna.io>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
import { join } from 'node:path';
|
|
10
|
+
/**
|
|
11
|
+
* Resolve the `config.base` value
|
|
12
|
+
*/
|
|
13
|
+
export function resolveBase(config, options, command) {
|
|
14
|
+
if (config.base)
|
|
15
|
+
return config.base;
|
|
16
|
+
if (command === 'build') {
|
|
17
|
+
return options.assetsUrl.endsWith('/')
|
|
18
|
+
? options.assetsUrl
|
|
19
|
+
: options.assetsUrl + '/';
|
|
20
|
+
}
|
|
21
|
+
return '/';
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Vite config hook
|
|
25
|
+
*/
|
|
26
|
+
export function configHook(options, userConfig, { command }) {
|
|
27
|
+
const config = {
|
|
28
|
+
publicDir: userConfig.publicDir ?? false,
|
|
29
|
+
base: resolveBase(userConfig, options, command),
|
|
30
|
+
/**
|
|
31
|
+
* Disable the vite dev server cors handling. Otherwise, it will
|
|
32
|
+
* override the cors settings defined by @fastify/cors.
|
|
33
|
+
*/
|
|
34
|
+
server: { cors: userConfig.server?.cors ?? false },
|
|
35
|
+
build: {
|
|
36
|
+
assetsDir: '',
|
|
37
|
+
emptyOutDir: true,
|
|
38
|
+
manifest: userConfig.build?.manifest ?? true,
|
|
39
|
+
outDir: userConfig.build?.outDir ?? options.buildDirectory,
|
|
40
|
+
assetsInlineLimit: userConfig.build?.assetsInlineLimit ?? 0,
|
|
41
|
+
rollupOptions: {
|
|
42
|
+
input: options.entrypoints.map(entrypoint => join(userConfig.root || '', entrypoint))
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
return config;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Update the user vite config to match Athenna requirements.
|
|
50
|
+
*/
|
|
51
|
+
export const config = (options) => {
|
|
52
|
+
return {
|
|
53
|
+
name: 'vite-plugin-athenna:config',
|
|
54
|
+
enforce: 'post',
|
|
55
|
+
config: configHook.bind(null, options)
|
|
56
|
+
};
|
|
57
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @athenna/http
|
|
3
|
+
*
|
|
4
|
+
* (c) João Lenon <lenon@athenna.io>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
import type { PluginOption } from 'vite';
|
|
10
|
+
import type { PluginOptions } from '#src/types/vite/PluginOptions';
|
|
11
|
+
export declare function athenna(options: PluginOptions): PluginOption[];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @athenna/http
|
|
3
|
+
*
|
|
4
|
+
* (c) João Lenon <lenon@athenna.io>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
import PluginRestart from 'vite-plugin-restart';
|
|
10
|
+
import { config } from '#src/vite/config';
|
|
11
|
+
export function athenna(options) {
|
|
12
|
+
const fullOptions = Object.assign({
|
|
13
|
+
assetsUrl: '/assets',
|
|
14
|
+
buildDirectory: 'public/assets',
|
|
15
|
+
reload: ['./src/resources/views/**/*.edge'],
|
|
16
|
+
css: {
|
|
17
|
+
preprocessorOptions: {
|
|
18
|
+
scss: {
|
|
19
|
+
api: 'modern'
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}, options);
|
|
24
|
+
return [PluginRestart({ reload: fullOptions.reload }), config(fullOptions)];
|
|
25
|
+
}
|
package/src/vite/index.d.ts
DELETED
package/src/vite/index.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import PluginRestart from 'vite-plugin-restart';
|
|
2
|
-
import { Path } from '@athenna/common';
|
|
3
|
-
import { mergeConfig, defineConfig } from 'vite';
|
|
4
|
-
export function defineAthennaConfig(config) {
|
|
5
|
-
const defaultConfig = {
|
|
6
|
-
root: Path.pwd(),
|
|
7
|
-
assetsUrl: '/assets',
|
|
8
|
-
buildDirectory: 'public/assets',
|
|
9
|
-
css: {
|
|
10
|
-
preprocessorOptions: {
|
|
11
|
-
scss: {
|
|
12
|
-
api: 'modern'
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
build: {
|
|
17
|
-
assetsDir: '',
|
|
18
|
-
manifest: true,
|
|
19
|
-
emptyOutDir: true,
|
|
20
|
-
outDir: 'public/assets',
|
|
21
|
-
assetsInlineLimit: 0,
|
|
22
|
-
rollupOptions: {
|
|
23
|
-
output: {
|
|
24
|
-
entryFileNames: '[name].js',
|
|
25
|
-
chunkFileNames: '[name].js',
|
|
26
|
-
assetFileNames: '[name].[ext]'
|
|
27
|
-
},
|
|
28
|
-
input: [Path.resources('css/app.scss'), Path.resources('js/app.js')]
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
plugins: [PluginRestart({ reload: [Path.views('**/*.edge')] })]
|
|
32
|
-
};
|
|
33
|
-
return defineConfig(mergeConfig(defaultConfig, config));
|
|
34
|
-
}
|