@adonisjs/vite 2.0.2 → 3.0.0-1
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/LICENSE.md +1 -1
- package/build/index.d.ts +2 -2
- package/build/index.js +47 -12
- package/build/providers/vite_provider.d.ts +4 -10
- package/build/providers/vite_provider.js +49 -78
- package/build/providers/vite_provider.js.map +1 -0
- package/build/services/vite.d.ts +1 -1
- package/build/services/vite.js +8 -16
- package/build/services/vite.js.map +1 -0
- package/build/src/client/config.d.ts +13 -2
- package/build/src/client/main.d.ts +1 -1
- package/build/src/client/main.js +67 -22
- package/build/src/client/main.js.map +1 -0
- package/build/src/client/types.d.ts +12 -21
- package/build/src/define_config.d.ts +5 -0
- package/build/src/hooks/build_hook.d.ts +8 -0
- package/build/src/hooks/build_hook.js +16 -0
- package/build/src/hooks/build_hook.js.map +1 -0
- package/build/src/middlewares/vite_middleware.d.ts +17 -0
- package/build/src/{backend/types.d.ts → types.d.ts} +6 -22
- package/build/src/types.js +1 -0
- package/build/src/types.js.map +1 -0
- package/build/src/{backend/utils.d.ts → utils.d.ts} +4 -0
- package/build/src/{backend/vite.d.ts → vite.d.ts} +27 -9
- package/build/stubs/vite.config.stub +1 -1
- package/package.json +52 -55
- package/build/configure.js +0 -42
- package/build/src/backend/debug.d.ts +0 -3
- package/build/src/backend/debug.js +0 -10
- package/build/src/backend/define_config.d.ts +0 -5
- package/build/src/backend/define_config.js +0 -23
- package/build/src/backend/plugins/edge.js +0 -86
- package/build/src/backend/types.js +0 -9
- package/build/src/backend/utils.js +0 -36
- package/build/src/backend/vite.js +0 -259
- package/build/src/client/config.js +0 -73
- package/build/src/client/config_resolver.d.ts +0 -20
- package/build/src/client/config_resolver.js +0 -46
- package/build/src/client/helpers/inertia.d.ts +0 -4
- package/build/src/client/helpers/inertia.js +0 -22
- package/build/src/client/hot_file.d.ts +0 -14
- package/build/src/client/hot_file.js +0 -49
- package/build/src/client/types.js +0 -9
- package/build/src/client/utils.d.ts +0 -11
- package/build/src/client/utils.js +0 -44
- package/build/stubs/main.js +0 -10
- /package/build/src/{backend/plugins → plugins}/edge.d.ts +0 -0
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/vite
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
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 { defu } from 'defu';
|
|
10
|
-
import { join } from 'node:path';
|
|
11
|
-
import { HotFile } from './hot_file.js';
|
|
12
|
-
import { resolveDevServerUrl } from './utils.js';
|
|
13
|
-
import { ConfigResolver } from './config_resolver.js';
|
|
14
|
-
/**
|
|
15
|
-
* Vite config hook
|
|
16
|
-
*/
|
|
17
|
-
export const configHook = (options, userConfig, { command }) => {
|
|
18
|
-
const config = {
|
|
19
|
-
publicDir: userConfig.publicDir ?? false,
|
|
20
|
-
base: ConfigResolver.resolveBase(userConfig, options, command),
|
|
21
|
-
resolve: { alias: ConfigResolver.resolveAlias(userConfig) },
|
|
22
|
-
server: {
|
|
23
|
-
/**
|
|
24
|
-
* Will allow to rewrite the URL to the public path
|
|
25
|
-
* in dev mode
|
|
26
|
-
*/
|
|
27
|
-
origin: '__adonis_vite__',
|
|
28
|
-
},
|
|
29
|
-
build: {
|
|
30
|
-
assetsDir: '',
|
|
31
|
-
manifest: userConfig.build?.manifest ?? true,
|
|
32
|
-
emptyOutDir: true,
|
|
33
|
-
outDir: ConfigResolver.resolveOutDir(userConfig, options),
|
|
34
|
-
rollupOptions: {
|
|
35
|
-
input: options.entrypoints.map((entrypoint) => join(userConfig.root || '', entrypoint)),
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
return defu(config, userConfig);
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Update the user vite config to match the Adonis requirements
|
|
43
|
-
*/
|
|
44
|
-
export const config = (options) => {
|
|
45
|
-
let devServerUrl;
|
|
46
|
-
return {
|
|
47
|
-
name: 'vite-plugin-adonis:config',
|
|
48
|
-
config: configHook.bind(null, options),
|
|
49
|
-
/**
|
|
50
|
-
* Store the dev server url for further usage when rewriting URLs
|
|
51
|
-
*/
|
|
52
|
-
configureServer(server) {
|
|
53
|
-
const hotfile = new HotFile(options.hotFile);
|
|
54
|
-
server.httpServer?.once('listening', async () => {
|
|
55
|
-
devServerUrl = resolveDevServerUrl(server.httpServer.address(), server.config);
|
|
56
|
-
await hotfile.write({ url: devServerUrl });
|
|
57
|
-
});
|
|
58
|
-
server.httpServer?.on('close', () => hotfile.clean());
|
|
59
|
-
},
|
|
60
|
-
/**
|
|
61
|
-
* Rewrite URL to the public path in dev mode
|
|
62
|
-
*
|
|
63
|
-
* See : https://nystudio107.com/blog/using-vite-js-next-generation-frontend-tooling-with-craft-cms#vite-processed-assets
|
|
64
|
-
*/
|
|
65
|
-
transform: (code) => ({
|
|
66
|
-
code: code.replace(/__adonis_vite__/g, devServerUrl),
|
|
67
|
-
map: null,
|
|
68
|
-
}),
|
|
69
|
-
configResolved: async (resolvedConfig) => {
|
|
70
|
-
ConfigResolver.resolvedConfig = resolvedConfig;
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ResolvedConfig, UserConfig, AliasOptions } from 'vite';
|
|
2
|
-
import { PluginFullOptions } from './types.js';
|
|
3
|
-
export declare class ConfigResolver {
|
|
4
|
-
static resolvedConfig?: ResolvedConfig;
|
|
5
|
-
/**
|
|
6
|
-
* Resolve the `config.base` value
|
|
7
|
-
*/
|
|
8
|
-
static resolveBase(config: UserConfig, options: PluginFullOptions, command: 'build' | 'serve'): string;
|
|
9
|
-
/**
|
|
10
|
-
* Resolve the `config.resolve.alias` value
|
|
11
|
-
*
|
|
12
|
-
* Basically we are merging the user defined alias with the
|
|
13
|
-
* default alias.
|
|
14
|
-
*/
|
|
15
|
-
static resolveAlias(config: UserConfig): AliasOptions;
|
|
16
|
-
/**
|
|
17
|
-
* Resolve the `config.build.outDir` value
|
|
18
|
-
*/
|
|
19
|
-
static resolveOutDir(config: UserConfig, options: PluginFullOptions): string;
|
|
20
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/vite
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
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 { addTrailingSlash } from './utils.js';
|
|
10
|
-
export class ConfigResolver {
|
|
11
|
-
static resolvedConfig;
|
|
12
|
-
/**
|
|
13
|
-
* Resolve the `config.base` value
|
|
14
|
-
*/
|
|
15
|
-
static resolveBase(config, options, command) {
|
|
16
|
-
if (config.base) {
|
|
17
|
-
return config.base;
|
|
18
|
-
}
|
|
19
|
-
if (command === 'build') {
|
|
20
|
-
return addTrailingSlash(options.assetsUrl);
|
|
21
|
-
}
|
|
22
|
-
return '/';
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Resolve the `config.resolve.alias` value
|
|
26
|
-
*
|
|
27
|
-
* Basically we are merging the user defined alias with the
|
|
28
|
-
* default alias.
|
|
29
|
-
*/
|
|
30
|
-
static resolveAlias(config) {
|
|
31
|
-
const defaultAlias = { '@/': `/resources/js/` };
|
|
32
|
-
if (Array.isArray(config.resolve?.alias)) {
|
|
33
|
-
return [
|
|
34
|
-
...(config.resolve?.alias ?? []),
|
|
35
|
-
Object.entries(defaultAlias).map(([find, replacement]) => ({ find, replacement })),
|
|
36
|
-
];
|
|
37
|
-
}
|
|
38
|
-
return { ...defaultAlias, ...config.resolve?.alias };
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Resolve the `config.build.outDir` value
|
|
42
|
-
*/
|
|
43
|
-
static resolveOutDir(config, options) {
|
|
44
|
-
return config.build?.outDir ?? options.buildDirectory;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/vite
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Resolves a page component.
|
|
11
|
-
*/
|
|
12
|
-
export async function resolvePageComponent(name, pages) {
|
|
13
|
-
const path = Object.keys(pages)
|
|
14
|
-
.sort((a, b) => a.length - b.length)
|
|
15
|
-
.find((filepath) => filepath.endsWith(name));
|
|
16
|
-
if (!path) {
|
|
17
|
-
throw new Error(`Page component "${name}" could not be found.`);
|
|
18
|
-
}
|
|
19
|
-
let component = typeof pages[path] === 'function' ? await pages[path]() : pages[path];
|
|
20
|
-
component = component.default ?? component;
|
|
21
|
-
return component;
|
|
22
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/vite
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
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 { dirname, join } from 'node:path';
|
|
10
|
-
import { existsSync, rmSync } from 'node:fs';
|
|
11
|
-
import { mkdir, writeFile } from 'node:fs/promises';
|
|
12
|
-
import { ConfigResolver } from './config_resolver.js';
|
|
13
|
-
export class HotFile {
|
|
14
|
-
/**
|
|
15
|
-
* Path to the hot file
|
|
16
|
-
*/
|
|
17
|
-
#path;
|
|
18
|
-
/**
|
|
19
|
-
* Register hooks to clean the hot file on exit
|
|
20
|
-
*/
|
|
21
|
-
#cleanHotFileOnExit() {
|
|
22
|
-
const clean = this.clean.bind(this);
|
|
23
|
-
process.on('exit', clean);
|
|
24
|
-
process.on('SIGINT', process.exit);
|
|
25
|
-
process.on('SIGTERM', process.exit);
|
|
26
|
-
process.on('SIGHUP', process.exit);
|
|
27
|
-
process.on('SIGBREAK', process.exit);
|
|
28
|
-
}
|
|
29
|
-
constructor(path) {
|
|
30
|
-
this.#path = join(ConfigResolver.resolvedConfig.root, path);
|
|
31
|
-
this.#cleanHotFileOnExit();
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Write the hot file
|
|
35
|
-
*/
|
|
36
|
-
async write(data) {
|
|
37
|
-
await mkdir(dirname(this.#path), { recursive: true });
|
|
38
|
-
await writeFile(this.#path, JSON.stringify(data, null, 2));
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Delete the hot file
|
|
42
|
-
*/
|
|
43
|
-
clean() {
|
|
44
|
-
if (!existsSync(this.#path)) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
rmSync(this.#path);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import { ResolvedConfig } from 'vite';
|
|
3
|
-
import { AddressInfo } from 'node:net';
|
|
4
|
-
/**
|
|
5
|
-
* Resolve the dev server URL from the server address and configuration.
|
|
6
|
-
*/
|
|
7
|
-
export declare const resolveDevServerUrl: (address: AddressInfo, config: ResolvedConfig) => string;
|
|
8
|
-
/**
|
|
9
|
-
* Add a trailing slash if missing
|
|
10
|
-
*/
|
|
11
|
-
export declare const addTrailingSlash: (url: string) => string;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/vite
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
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 { networkInterfaces } from 'node:os';
|
|
10
|
-
/**
|
|
11
|
-
* Resolve the dev server URL from the server address and configuration.
|
|
12
|
-
*/
|
|
13
|
-
export const resolveDevServerUrl = (address, config) => {
|
|
14
|
-
const configHmrProtocol = typeof config.server.hmr === 'object' ? config.server.hmr.protocol : null;
|
|
15
|
-
const clientProtocol = configHmrProtocol ? (configHmrProtocol === 'wss' ? 'https' : 'http') : null;
|
|
16
|
-
const serverProtocol = config.server.https ? 'https' : 'http';
|
|
17
|
-
const protocol = clientProtocol ?? serverProtocol;
|
|
18
|
-
const configHmrHost = typeof config.server.hmr === 'object' ? config.server.hmr.host : null;
|
|
19
|
-
const configHost = typeof config.server.host === 'string' ? config.server.host : null;
|
|
20
|
-
let host = configHmrHost ?? configHost ?? address.address;
|
|
21
|
-
if (host === '::1') {
|
|
22
|
-
host = 'localhost';
|
|
23
|
-
}
|
|
24
|
-
else if (host === '::') {
|
|
25
|
-
const networkAddress = Object.values(networkInterfaces())
|
|
26
|
-
.flatMap((nInterface) => nInterface ?? [])
|
|
27
|
-
.find((detail) => {
|
|
28
|
-
return (detail &&
|
|
29
|
-
detail.address &&
|
|
30
|
-
detail.family === 'IPv4' &&
|
|
31
|
-
!detail.address.includes('127.0.0.1'));
|
|
32
|
-
});
|
|
33
|
-
if (networkAddress) {
|
|
34
|
-
host = networkAddress.address;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return `${protocol}://${host}:${address.port}`;
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Add a trailing slash if missing
|
|
41
|
-
*/
|
|
42
|
-
export const addTrailingSlash = (url) => {
|
|
43
|
-
return url.endsWith('/') ? url : url + '/';
|
|
44
|
-
};
|
package/build/stubs/main.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/vite
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
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 { getDirname } from '@poppinss/utils';
|
|
10
|
-
export const stubsRoot = getDirname(import.meta.url);
|
|
File without changes
|