Skip to content

Commit 8d6341e

Browse files
committed
Allow overriding from and to git pointers
1 parent 678e053 commit 8d6341e

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ npx @typeofweb/ignore-monorepo-buildstep
3636

3737
![Ignore Build Step settings in Vercel](./docs/vercel_settings.png)
3838

39+
By default, `ignore-monorepo-buildstep` will compare `HEAD^` and `HEAD`. You can override this and use an env variable exposed by Vercel:
40+
41+
```
42+
npx @typeofweb/ignore-monorepo-buildstep $VERCEL_GIT_PREVIOUS_SHA
43+
```
44+
3945
### Result
4046

4147
When any changes are introduced to `packages/common`, both apps `a` and `b` will be built:

src/git.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { execFile } from "node:child_process";
2+
import { promisify } from "node:util";
3+
const execFileAsync = promisify(execFile);
4+
5+
export const compare = ({
6+
from,
7+
to,
8+
paths,
9+
pathsToIgnore,
10+
}: {
11+
from: string;
12+
to: string;
13+
paths: string[];
14+
pathsToIgnore: string[];
15+
}) => {
16+
return execFileAsync(`git`, [
17+
`diff`,
18+
from,
19+
to,
20+
`--quiet`,
21+
...paths,
22+
...pathsToIgnore.map((path) => `:^${path}`),
23+
]);
24+
};

src/index.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
import { existsSync } from "node:fs";
44
import Path from "node:path";
5-
import { execFile } from "node:child_process";
6-
import { promisify } from "node:util";
75
import { promiseErrorToSettled } from "./utils.js";
86
import {
97
readWorkspaceDirs,
108
readWorkspaceSettings,
119
resolveWorkspaceDeps,
1210
} from "./pnpmWorkspace.js";
13-
const execFileAsync = promisify(execFile);
11+
import { compare } from "./git.js";
1412

1513
const cwd = process.cwd();
1614

15+
const [_node, _bin, gitFromPointer = "HEAD^", gitToPointer = "HEAD"] =
16+
process.argv;
17+
1718
const rootDir = cwd
1819
.split(Path.sep)
1920
.map((_, idx) => Path.join(cwd, "../".repeat(idx)))
@@ -41,28 +42,30 @@ const result = await Promise.all([
4142
...workspaceDepsRelativePaths.map(async (path) => {
4243
return {
4344
result: await promiseErrorToSettled(
44-
execFileAsync(`git`, [`diff`, `HEAD^`, `HEAD`, `--quiet`, path]),
45+
compare({
46+
from: gitFromPointer,
47+
to: gitToPointer,
48+
paths: [path],
49+
pathsToIgnore: [],
50+
}),
4551
),
4652
path,
4753
};
4854
}),
4955
(async () => {
50-
const pathsToIgnore = (await readWorkspaceDirs({ rootDir, cwd }))
51-
.map((path) => Path.relative(cwd, path))
52-
.map((path) => `:^${path}`);
56+
const pathsToIgnore = (await readWorkspaceDirs({ rootDir, cwd })).map(
57+
(path) => Path.relative(cwd, path),
58+
);
5359
const relativeRoot = Path.relative(cwd, rootDir);
5460

5561
return {
5662
result: await promiseErrorToSettled(
57-
execFileAsync(`git`, [
58-
`diff`,
59-
`HEAD^`,
60-
`HEAD`,
61-
`--quiet`,
62-
`--`,
63-
relativeRoot,
64-
...pathsToIgnore,
65-
]),
63+
compare({
64+
from: gitFromPointer,
65+
to: gitToPointer,
66+
paths: [relativeRoot],
67+
pathsToIgnore,
68+
}),
6669
),
6770
path: relativeRoot,
6871
};

0 commit comments

Comments
 (0)