function doTraverseAndReplace()

in src/shared/sam/debugger/awsSamDebugConfigurationValidator.ts [301:332]


function doTraverseAndReplace(object: { [key: string]: any }, fspath: string | undefined): any {
    const wsfRegex = /^(.*)(\$\{workspaceFolder\})(.*)$/g
    if (!vscode.workspace.workspaceFolders && !fspath) {
        throw new Error('No workspace folders available; cannot resolve workspaceFolder variable.')
    }
    const keys = Object.keys(object)
    const final = JSON.parse(JSON.stringify(object))
    for (const key of keys) {
        const val = object[key]
        if (typeof val === 'string') {
            const result = wsfRegex.exec(val)
            if (result) {
                if (!fspath) {
                    for (const wsf of vscode.workspace.workspaceFolders!) {
                        if (fs.existsSync(path.join(result[1], wsf.uri.fsPath, result[3]))) {
                            fspath = wsf.uri.fsPath
                            break
                        }
                    }
                }
                if (!fspath) {
                    throw new Error(`No compatible workspace folders for path: ${val}`)
                }
                final[key] = path.join(result[1], fspath, result[3])
            }
        } else if (typeof val === 'object') {
            final[key] = doTraverseAndReplace(val, fspath)
        }
    }

    return final
}