-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent require cycles because the Metro bundler warns about them, even in libraries. GitOrigin-RevId: cc0578cbb97b84fdbb886b6c9f81d8e57a541d7f
- Loading branch information
1 parent
4539827
commit b9ada8f
Showing
8 changed files
with
76 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env node | ||
import { fileURLToPath } from "url"; | ||
import { dirname } from "path"; | ||
import skott from "skott"; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
const __root = dirname(__dirname); | ||
|
||
async function entrypointHasCycles(entrypoint) { | ||
// Note that skott can do a lot of other things too! | ||
const { useGraph } = await skott({ | ||
entrypoint: `./dist/esm/${entrypoint}/index.js`, | ||
incremental: false, | ||
cwd: __root, | ||
includeBaseDir: true, | ||
verbose: false, | ||
}); | ||
const { findCircularDependencies } = useGraph(); | ||
|
||
const circular = findCircularDependencies(); | ||
if (circular.length) { | ||
console.log("Found import cycles by traversing", entrypoint); | ||
console.log(circular); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
let allOk = true; | ||
// These haven't been fixed yet so we don't fail if they have cycles. | ||
for (const entrypoint of [ | ||
"bundler", | ||
"nextjs", | ||
"react", | ||
"react-auth0", | ||
"react-clerk", | ||
"values", | ||
// don't care about cycles in CLI | ||
]) { | ||
const ok = await entrypointHasCycles(entrypoint); | ||
allOk &&= ok; | ||
} | ||
|
||
if (!(await entrypointHasCycles("server"))) { | ||
process.exit(1); | ||
} else { | ||
console.log("No import cycles found in server."); | ||
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
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,9 @@ | ||
export const toReferencePath = Symbol.for("toReferencePath"); | ||
|
||
export function extractReferencePath(reference: any): string | null { | ||
return reference[toReferencePath] ?? null; | ||
} | ||
|
||
export function isFunctionHandle(s: string): boolean { | ||
return s.startsWith("function://"); | ||
} |
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,4 @@ | ||
/** | ||
* A symbol for accessing the name of a {@link FunctionReference} at runtime. | ||
*/ | ||
export const functionName = Symbol.for("functionName"); |
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,4 @@ | ||
/** | ||
* A symbol for accessing the name of a {@link FunctionReference} at runtime. | ||
*/ | ||
export const functionName = Symbol.for("functionName"); |
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