Skip to content

Commit

Permalink
chore: fix root path issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrove committed Jan 22, 2022
1 parent ae9df1f commit b68fb54
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/lib/one-graph/cli-netlify-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ const internalConsole = {

InternalConsole.registerConsole(internalConsole)

/**
* Remove any relative path components from the given path
* @param {string[]} items Filesystem path items to filter
* @return {string[]} Filtered filesystem path items
*/
const filterRelativePathItems = (items) => items.filter((part) => part !== '')

/**
* Return a full NetlifyGraph config with any defaults overridden by netlify.toml
* @param {import('../base-command').BaseCommand} command
Expand Down Expand Up @@ -44,7 +51,7 @@ const getNetlifyGraphConfig = async ({ command, options }) => {
error(detectServerSettingsError)
}

const siteRoot = [path.sep, ...site.root.split(path.sep).filter((part) => part !== '')]
const siteRoot = [path.sep, ...filterRelativePathItems(site.root.split(path.sep))]

const tsConfig = 'tsconfig.json'
const autodetectedLanguage = fs.existsSync(tsConfig) ? 'typescript' : 'javascript'
Expand All @@ -53,10 +60,12 @@ const getNetlifyGraphConfig = async ({ command, options }) => {
const isNextjs = framework === 'Next.js'
const detectedFunctionsPathString = getFunctionsDir({ config, options })
const detectedFunctionsPath = detectedFunctionsPathString ? detectedFunctionsPathString.split(path.sep) : null
const functionsPath = isNextjs ? [...siteRoot, 'pages', 'api'] : [...siteRoot, ...detectedFunctionsPath]
const netlifyGraphPath = isNextjs
? [...siteRoot, 'lib', 'netlifyGraph']
: [...siteRoot, ...NetlifyGraph.defaultNetlifyGraphConfig.netlifyGraphPath]
const functionsPath = filterRelativePathItems(isNextjs ? [...siteRoot, 'pages', 'api'] : [...detectedFunctionsPath])
const netlifyGraphPath = filterRelativePathItems(
isNextjs
? [...siteRoot, 'lib', 'netlifyGraph']
: [...siteRoot, ...NetlifyGraph.defaultNetlifyGraphConfig.netlifyGraphPath],
)
const baseConfig = { ...NetlifyGraph.defaultNetlifyGraphConfig, ...userSpecifiedConfig }
const netlifyGraphImplementationFilename = [...netlifyGraphPath, `index.${baseConfig.extension}`]
const netlifyGraphTypeDefinitionsFilename = [...netlifyGraphPath, `index.d.ts`]
Expand Down Expand Up @@ -224,7 +233,7 @@ const generateHandler = (netlifyGraphConfig, schema, operationId, handlerOptions
const defaultBaseFilename = `${operationName}.${fileExtension}`
const baseFilename = defaultBaseFilename

filenameArr = [...netlifyGraphConfig.functionsPath, baseFilename]
filenameArr = [path.sep, ...netlifyGraphConfig.functionsPath, baseFilename]
}

const absoluteFilename = path.resolve(...filenameArr)
Expand Down

0 comments on commit b68fb54

Please sign in to comment.