-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/callstack-internal/Expensif…
…y-App into hur/perf/issue-35704
- Loading branch information
Showing
447 changed files
with
11,689 additions
and
8,149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import {parse} from 'csv-parse'; | ||
import fs from 'fs'; | ||
|
||
const parser = parse(); | ||
|
||
const adjacencyList: Record<string, string[]> = {}; | ||
const visited: Map<string, boolean> = new Map<string, boolean>(); | ||
const backEdges: Map<string, boolean> = new Map<string, boolean>(); | ||
|
||
function addEdge(source: string, target: string) { | ||
if (!adjacencyList[source]) { | ||
adjacencyList[source] = []; | ||
} | ||
adjacencyList[source].push(target); | ||
} | ||
|
||
function isCyclic(currentNode: string): boolean { | ||
visited.set(currentNode, true); | ||
backEdges.set(currentNode, true); | ||
|
||
// Do a depth first search for all the neighbours. If a node is found in backedge, a cycle is detected. | ||
const neighbours = adjacencyList[currentNode]; | ||
if (neighbours) { | ||
for (const node of neighbours) { | ||
if (!visited.has(node)) { | ||
if (isCyclic(node)) { | ||
return true; | ||
} | ||
} else if (backEdges.has(node)) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
backEdges.delete(currentNode); | ||
|
||
return false; | ||
} | ||
|
||
function detectCycle(): boolean { | ||
for (const [node] of Object.entries(adjacencyList)) { | ||
if (!visited.has(node)) { | ||
if (isCyclic(node)) { | ||
const cycle = Array.from(backEdges.keys()); | ||
console.log(`Infinite redirect found in the cycle: ${cycle.join(' -> ')} -> ${node}`); | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
fs.createReadStream(`${process.cwd()}/docs/redirects.csv`) | ||
.pipe(parser) | ||
.on('data', (row) => { | ||
// Create a directed graph of sourceURL -> targetURL | ||
addEdge(row[0], row[1]); | ||
}) | ||
.on('end', () => { | ||
if (detectCycle()) { | ||
process.exit(1); | ||
} | ||
process.exit(0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
# HelpDot - Verifies that redirects.csv does not have any duplicates | ||
# Duplicate sourceURLs break redirection on cloudflare pages | ||
|
||
declare -r REDIRECTS_FILE="docs/redirects.csv" | ||
|
||
declare -r RED='\033[0;31m' | ||
declare -r GREEN='\033[0;32m' | ||
declare -r NC='\033[0m' | ||
|
||
duplicates=$(awk -F, 'a[$1]++{print $1}' $REDIRECTS_FILE) | ||
if [[ -n "$duplicates" ]]; then | ||
echo "${RED}duplicate redirects are not allowed: $duplicates ${NC}" | ||
exit 1 | ||
fi | ||
|
||
npm run detectRedirectCycle | ||
DETECT_CYCLE_EXIT_CODE=$? | ||
if [[ DETECT_CYCLE_EXIT_CODE -eq 1 ]]; then | ||
echo -e "${RED}The redirects.csv has a cycle. Please remove the redirect cycle because it will cause an infinite redirect loop ${NC}" | ||
exit 1 | ||
fi | ||
|
||
echo -e "${GREEN}The redirects.csv is valid!${NC}" | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.