@@ -17,6 +17,13 @@ const internalConsole = {
17
17
18
18
InternalConsole . registerConsole ( internalConsole )
19
19
20
+ /**
21
+ * Remove any relative path components from the given path
22
+ * @param {string[] } items Filesystem path items to filter
23
+ * @return {string[] } Filtered filesystem path items
24
+ */
25
+ const filterRelativePathItems = ( items ) => items . filter ( ( part ) => part !== '' )
26
+
20
27
/**
21
28
* Return a full NetlifyGraph config with any defaults overridden by netlify.toml
22
29
* @param {import('../base-command').BaseCommand } command
@@ -44,7 +51,7 @@ const getNetlifyGraphConfig = async ({ command, options }) => {
44
51
error ( detectServerSettingsError )
45
52
}
46
53
47
- const siteRoot = [ path . sep , ...site . root . split ( path . sep ) . filter ( ( part ) => part !== '' ) ]
54
+ const siteRoot = [ path . sep , ...filterRelativePathItems ( site . root . split ( path . sep ) ) ]
48
55
49
56
const tsConfig = 'tsconfig.json'
50
57
const autodetectedLanguage = fs . existsSync ( tsConfig ) ? 'typescript' : 'javascript'
@@ -53,10 +60,12 @@ const getNetlifyGraphConfig = async ({ command, options }) => {
53
60
const isNextjs = framework === 'Next.js'
54
61
const detectedFunctionsPathString = getFunctionsDir ( { config, options } )
55
62
const detectedFunctionsPath = detectedFunctionsPathString ? detectedFunctionsPathString . split ( path . sep ) : null
56
- const functionsPath = isNextjs ? [ ...siteRoot , 'pages' , 'api' ] : [ ...siteRoot , ...detectedFunctionsPath ]
57
- const netlifyGraphPath = isNextjs
58
- ? [ ...siteRoot , 'lib' , 'netlifyGraph' ]
59
- : [ ...siteRoot , ...NetlifyGraph . defaultNetlifyGraphConfig . netlifyGraphPath ]
63
+ const functionsPath = filterRelativePathItems ( isNextjs ? [ ...siteRoot , 'pages' , 'api' ] : [ ...detectedFunctionsPath ] )
64
+ const netlifyGraphPath = filterRelativePathItems (
65
+ isNextjs
66
+ ? [ ...siteRoot , 'lib' , 'netlifyGraph' ]
67
+ : [ ...siteRoot , ...NetlifyGraph . defaultNetlifyGraphConfig . netlifyGraphPath ] ,
68
+ )
60
69
const baseConfig = { ...NetlifyGraph . defaultNetlifyGraphConfig , ...userSpecifiedConfig }
61
70
const netlifyGraphImplementationFilename = [ ...netlifyGraphPath , `index.${ baseConfig . extension } ` ]
62
71
const netlifyGraphTypeDefinitionsFilename = [ ...netlifyGraphPath , `index.d.ts` ]
@@ -224,7 +233,7 @@ const generateHandler = (netlifyGraphConfig, schema, operationId, handlerOptions
224
233
const defaultBaseFilename = `${ operationName } .${ fileExtension } `
225
234
const baseFilename = defaultBaseFilename
226
235
227
- filenameArr = [ ...netlifyGraphConfig . functionsPath , baseFilename ]
236
+ filenameArr = [ path . sep , ...netlifyGraphConfig . functionsPath , baseFilename ]
228
237
}
229
238
230
239
const absoluteFilename = path . resolve ( ...filenameArr )
0 commit comments