Skip to content

Commit 5e824c0

Browse files
author
Jahed Ahmed
committed
fix(protect): skip previously patched files
1 parent ca2177a commit 5e824c0

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

packages/snyk-protect/src/lib/patch.ts

+7
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ export function applyPatchToFile(patchContents: string, baseFolder: string) {
66
baseFolder,
77
extractTargetFilePathFromPatch(patchContents),
88
);
9+
10+
const flagPath = `${targetFilePath}.snyk-protect.flag`;
11+
if (fs.existsSync(flagPath)) {
12+
return targetFilePath;
13+
}
14+
915
const contentsToPatch = fs.readFileSync(targetFilePath, 'utf-8');
1016
const patchedContents = patchString(patchContents, contentsToPatch);
1117
fs.writeFileSync(targetFilePath, patchedContents);
18+
fs.writeFileSync(flagPath, '');
1219
return targetFilePath;
1320
}
1421

packages/snyk-protect/test/acceptance/fix-pr.smoke.spec.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ describe('Fix PR', () => {
99
const project = await createProject('fix-pr');
1010
const patchedLodash = await getPatchedLodash();
1111

12+
expect(
13+
await runCommand('npm', ['install'], {
14+
cwd: project.path(),
15+
}),
16+
).toEqual(
17+
expect.objectContaining<RunCLIResult>({
18+
code: 0,
19+
stdout: expect.stringContaining('Applied Snyk patches'),
20+
stderr: expect.not.stringMatching(/snyk/gi),
21+
}),
22+
);
23+
24+
await expect(
25+
project.read('node_modules/lodash/lodash.js'),
26+
).resolves.toEqual(patchedLodash);
27+
1228
expect(
1329
await runCommand('npm', ['install'], {
1430
cwd: project.path(),
@@ -17,7 +33,7 @@ describe('Fix PR', () => {
1733
expect.objectContaining<RunCLIResult>({
1834
code: 0,
1935
stdout: expect.stringContaining('Applied Snyk patches.'),
20-
stderr: expect.any(String),
36+
stderr: expect.not.stringMatching(/snyk/gi),
2137
}),
2238
);
2339

0 commit comments

Comments
 (0)