File tree 2 files changed +45
-3
lines changed
src/context/directory/handlers
2 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -28,9 +28,12 @@ function parse(context: DirectoryContext): ParsedActions {
28
28
const actionFolder = path . join ( constants . ACTIONS_DIRECTORY , `${ action . name } ` ) ;
29
29
30
30
if ( action . code ) {
31
- const toUnixPath = ( somePath ) =>
32
- somePath . replace ( / [ \\ / ] + / g, '/' ) . replace ( / ^ ( [ a - z A - Z ] + : | \. \/ ) / , '' ) ;
33
- action . code = context . loadFile ( toUnixPath ( action . code ) , actionFolder ) ;
31
+ const unixPath = action . code . replace ( / [ \\ / ] + / g, '/' ) . replace ( / ^ ( [ a - z A - Z ] + : | \. \/ ) / , '' ) ;
32
+ if ( fs . existsSync ( unixPath ) ) {
33
+ action . code = context . loadFile ( unixPath , actionFolder ) ;
34
+ } else {
35
+ action . code = context . loadFile ( path . join ( context . filePath , action . code ) , actionFolder ) ;
36
+ }
34
37
}
35
38
36
39
return action ;
Original file line number Diff line number Diff line change @@ -111,6 +111,45 @@ describe('#directory context actions', () => {
111
111
expect ( context . assets . actions ) . to . deep . equal ( actionsTarget ) ;
112
112
} ) ;
113
113
114
+ it ( 'should process actions when code is stored in path relative to input file' , async ( ) => {
115
+ const repoDir = path . join ( testDataDir , 'directory' , 'test5' ) ;
116
+ const files = {
117
+ 'separate-directory' : {
118
+ 'action-code.js' :
119
+ '/** @type {PostLoginAction} */ module.exports = async (event, context) => { console.log("test-action"); return {}; };' ,
120
+ } ,
121
+ [ constants . ACTIONS_DIRECTORY ] : {
122
+ 'action-one.json' : `{
123
+ "name": "action-one",
124
+ "code": "./separate-directory/action-code.js",
125
+ "runtime": "node12",
126
+ "dependencies": [
127
+ {
128
+ "name": "lodash",
129
+ "version": "4.17.20"
130
+ }
131
+ ],
132
+ "secrets": [],
133
+ "status": "built",
134
+ "supported_triggers": [
135
+ {
136
+ "id": "post-login",
137
+ "version": "v1"
138
+ }
139
+ ],
140
+ "deployed": true
141
+ }` ,
142
+ } ,
143
+ } ;
144
+ createDir ( repoDir , files ) ;
145
+ const config = {
146
+ AUTH0_INPUT_FILE : repoDir ,
147
+ } ;
148
+ const context = new Context ( config , mockMgmtClient ( ) ) ;
149
+ await context . loadAssetsFromLocal ( ) ;
150
+ expect ( context . assets . actions ) . to . deep . equal ( actionsTarget ) ;
151
+ } ) ;
152
+
114
153
it ( 'should ignore bad actions directory' , async ( ) => {
115
154
const repoDir = path . join ( testDataDir , 'directory' , 'test2' ) ;
116
155
cleanThenMkdir ( repoDir ) ;
You can’t perform that action at this time.
0 commit comments