File tree Expand file tree Collapse file tree 4 files changed +27
-3
lines changed Expand file tree Collapse file tree 4 files changed +27
-3
lines changed Original file line number Diff line number Diff line change 31
31
},
32
32
"dependencies" : {
33
33
"@app-config/core" : " ^2.2.0" ,
34
- "@app-config/extension-utils" : " ^2.2.0"
34
+ "@app-config/extension-utils" : " ^2.2.0" ,
35
+ "@app-config/node" : " ^2.2.0"
35
36
},
36
37
"devDependencies" : {
37
38
"@app-config/test-utils" : " ^2.2.0"
Original file line number Diff line number Diff line change 1
1
import { LiteralSource } from '@app-config/core' ;
2
+ import { FileSource } from '@app-config/node' ;
2
3
import { withTempFiles } from '@app-config/test-utils' ;
3
4
import jsModuleDirective from './index' ;
4
5
@@ -65,6 +66,24 @@ describe('$jsModule directive', () => {
65
66
$jsModule : inDir ( 'foo.js' ) ,
66
67
} ) ;
67
68
69
+ expect ( await source . readToJSON ( [ jsModuleDirective ( ) ] ) ) . toEqual ( 'bar' ) ;
70
+ } ,
71
+ ) ) ;
72
+
73
+ it ( 'loads file relative to app-config' , ( ) =>
74
+ withTempFiles (
75
+ {
76
+ 'config.yml' : `
77
+ $jsModule: ./foo.js
78
+ ` ,
79
+ 'foo.js' : `
80
+ module.exports.__esModule = true;
81
+ module.exports.default = 'bar';
82
+ ` ,
83
+ } ,
84
+ async ( inDir ) => {
85
+ const source = new FileSource ( inDir ( 'config.yml' ) ) ;
86
+
68
87
expect ( await source . readToJSON ( [ jsModuleDirective ( ) ] ) ) . toEqual ( 'bar' ) ;
69
88
} ,
70
89
) ) ;
Original file line number Diff line number Diff line change 1
1
import { ParsingExtension } from '@app-config/core' ;
2
2
import { forKey , validateOptions } from '@app-config/extension-utils' ;
3
+ import { resolveFilepath } from '@app-config/node' ;
3
4
4
5
/* eslint-disable @typescript-eslint/no-unsafe-call */
5
6
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
@@ -10,8 +11,10 @@ export default function jsModuleDirective(): ParsingExtension {
10
11
'$jsModule' ,
11
12
validateOptions (
12
13
( SchemaBuilder ) => SchemaBuilder . stringSchema ( ) ,
13
- ( value ) => async ( parse ) => {
14
- let loaded : any = await import ( value ) ;
14
+ ( value ) => async ( parse , _ , context ) => {
15
+ const resolvedPath = resolveFilepath ( context , value ) ;
16
+
17
+ let loaded : any = await import ( resolvedPath ) ;
15
18
16
19
if ( ! loaded ) {
17
20
return parse ( loaded , { shouldFlatten : true } ) ;
Original file line number Diff line number Diff line change 9
9
"references" : [
10
10
{ "path" : " ../app-config-test-utils" },
11
11
{ "path" : " ../app-config-core" },
12
+ { "path" : " ../app-config-node" },
12
13
{ "path" : " ../app-config-extension-utils" }
13
14
]
14
15
}
You can’t perform that action at this time.
0 commit comments