@@ -6,6 +6,7 @@ import type { AddressInfo } from 'node:net'
66import debug from 'debug'
77import { globSync } from 'glob'
88import 'dotenv/config'
9+ import { merge } from 'smob'
910
1011export const PLUGIN_NAME = 'vite-plugin-java'
1112const filter = process . env . VITE_DEBUG_FILTER
@@ -32,45 +33,71 @@ export function createDebugger(
3233}
3334
3435/**
35- * Creates a Rollup input configuration object based on the specified pattern and base directory .
36+ * Creates the Rollup input configuration object.
3637 *
37- * @param pattern - The file pattern to match for input files. Defaults to src/~/main.ts
38- * @param baseDir - The base directory for the input files. Defaults to 'src'.
38+ * @param pattern - The glob pattern to match the entry files.
39+ * @param baseDir - The base directory for the entry files.
40+ * @param options - Additional options for the glob pattern matching.
3941 * @returns The Rollup input configuration object.
4042 */
4143export function createRollupInputConfig (
4244 pattern : string | string [ ] = 'src/**/main.ts' ,
4345 baseDir = 'src' ,
46+ options : Parameters < typeof globSync > [ 1 ] = { } ,
4447) : { [ entryAlias : string ] : string } {
48+ const cwd = process . cwd ( )
49+ const globOptions = merge ( options , { cwd } )
50+
4551 return Object . fromEntries (
46- globSync ( pattern ) . map ( ( file ) => {
52+ globSync ( pattern , globOptions ) . map ( ( file ) => {
53+ const filepath : string = typeof file === 'string' ? file : file . path
54+ const absolutePath = path . resolve ( cwd , filepath )
55+
4756 return [
48- path . relative ( baseDir , path . basename ( file , path . extname ( file ) ) ) ,
49- fileURLToPath ( new URL ( file , import . meta . url ) ) ,
57+ path . relative ( baseDir , filepath . slice ( 0 , filepath . length - path . extname ( filepath ) . length ) ) ,
58+ absolutePath ,
5059 ]
5160 } ) ,
5261 )
5362}
5463
64+ /**
65+ * Checks if the given address is an IPv6 address.
66+ *
67+ * @param address - The address to check.
68+ * @returns True if the address is an IPv6 address, false otherwise.
69+ */
5570export function isIpv6 ( address : AddressInfo ) : boolean {
5671 return address . family === 'IPv6'
57- // In node >=18.0 <18.4 this was an integer value. This was changed in a minor version.
58- // See: https://github.com/laravel/vite-plugin/issues/103
59- // @ts -expect-error-next-line
72+ // In node >=18.0 <18.4 this was an integer value. This was changed in a minor version.
73+ // See: https://github.com/laravel/vite-plugin/issues/103
74+ // @ts -expect-error-next-line
6075 || address . family === 6
6176}
6277
6378/**
64- * The directory of the current file.
79+ * Returns the directory of the current file.
80+ *
81+ * @returns The directory of the current file.
6582 */
6683export function dirname ( ) : string {
6784 return fileURLToPath ( new URL ( '.' , import . meta. url ) )
6885}
6986
87+ /**
88+ * Checks if the current project is a Maven project.
89+ *
90+ * @returns True if the current project is a Maven project, false otherwise.
91+ */
7092export function isMavenProject ( ) : boolean {
7193 return fs . existsSync ( path . join ( process . cwd ( ) , 'pom.xml' ) )
7294}
7395
96+ /**
97+ * Checks if the current project is a Gradle project.
98+ *
99+ * @returns True if the current project is a Gradle project, false otherwise.
100+ */
74101export function isGradleProject ( ) : boolean {
75102 return fs . existsSync ( path . join ( process . cwd ( ) , 'build.gradle' ) )
76103}
0 commit comments