@@ -4,39 +4,46 @@ import { ConfigLoadingOptions, loadValidatedConfig } from '@app-config/config';
4
4
import { asEnvOptions , currentEnvironment } from '@app-config/node' ;
5
5
import type { SchemaLoadingOptions } from '@app-config/schema' ;
6
6
7
- interface Options {
7
+ export interface Options {
8
8
readGlobal ?: boolean ;
9
9
injectValidationFunction ?: boolean ;
10
10
loadingOptions ?: ConfigLoadingOptions ;
11
11
schemaLoadingOptions ?: SchemaLoadingOptions ;
12
12
}
13
13
14
14
// vite resolves first before passing to the rollup plugin
15
- const manualImport = / ( a p p - c o n f i g | a p p - c o n f i g - m a i n ) \/ d i s t ( \/ e s ) ? \/ i n d e x \. j s / ;
15
+ export const appConfigImportRegex = / ( a p p - c o n f i g | a p p - c o n f i g - m a i n ) \/ d i s t ( \/ e s ) ? \/ i n d e x \. j s / ;
16
16
17
17
export default function appConfigRollup ( {
18
18
readGlobal,
19
19
injectValidationFunction,
20
20
loadingOptions,
21
21
schemaLoadingOptions,
22
- } : Options = { } ) : Plugin {
22
+ } : Options = { } ) : Plugin & { currentFilePaths ?: string [ ] } {
23
+ const currentFilePaths : string [ ] = [ ] ;
24
+
23
25
return {
24
26
name : '@app-config/rollup' ,
27
+ currentFilePaths,
25
28
resolveId ( source ) {
26
- if ( packageNameRegex . exec ( source ) || manualImport . exec ( source ) ) {
29
+ if ( packageNameRegex . exec ( source ) || appConfigImportRegex . exec ( source ) ) {
27
30
return '.config-placeholder' ;
28
31
}
29
32
30
33
return null ;
31
34
} ,
32
35
async load ( id ) {
33
- if ( packageNameRegex . exec ( id ) || manualImport . exec ( id ) ) {
34
- const { parsed : config , validationFunctionCode } = await loadValidatedConfig (
35
- loadingOptions ,
36
- schemaLoadingOptions ,
37
- ) ;
38
-
39
- // TODO: alternative for addDependecy with filePaths
36
+ if ( packageNameRegex . exec ( id ) || appConfigImportRegex . exec ( id ) ) {
37
+ const {
38
+ parsed : config ,
39
+ validationFunctionCode,
40
+ filePaths,
41
+ } = await loadValidatedConfig ( loadingOptions , schemaLoadingOptions ) ;
42
+
43
+ if ( filePaths ) {
44
+ currentFilePaths . length = 0 ;
45
+ currentFilePaths . push ( ...filePaths ) ;
46
+ }
40
47
41
48
let generatedText : string ;
42
49
0 commit comments