Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions packages/monorepo-tools/src/precommit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,35 @@ import pkgUp from 'pkg-up';
import { promisify } from 'util';
import { execFile } from 'child_process';
import * as fs from 'fs/promises';
import findUp from 'find-up';
const execFileAsync = promisify(execFile);

const monorepoRoot = path.resolve(__dirname, '..', '..');
const repoRoot = path.resolve(monorepoRoot, '..');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ I can't seem to make sense of why ../.. and ../../.. were chosen to be the "monorepo root" and "repo root", respectively – but this must have been intentional, right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess monorepo root is packages/ and root is the repo root? where .git is?


async function main(fileList: string[]) {
const monorepoGit = await findUp('.git', {
cwd: __dirname,
type: 'directory',
});
if (!monorepoGit) {
throw new Error(
`Could not find .git directory for monorepo starting from ${__dirname}`,
);
}
const monorepoRoot = path.dirname(monorepoGit);

const filesToPrettify: string[] = [];

const submodules = [
...(
await fs.readFile(path.resolve(repoRoot, '.gitmodules'), {
encoding: 'utf8',
})
await fs
.readFile(path.resolve(monorepoRoot, '.gitmodules'), {
encoding: 'utf8',
})
.catch(() => '')
).matchAll(/^\s+path = (?<submodulePath>.*)$/gm),
]
.map((r) => r.groups?.submodulePath)
.filter((p) => p)
.map((p) => path.resolve(repoRoot, p!));
.filter((p): p is string => !!p)
.map((p) => path.resolve(monorepoRoot, p));

await Promise.all(
fileList.map(async (filePath) => {
Expand Down
Loading