Skip to content
Open
Show file tree
Hide file tree
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
39 changes: 39 additions & 0 deletions .yarn/versions/e8bbcd71.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/fslib": patch
"@yarnpkg/plugin-patch": patch

declined:
- "@yarnpkg/plugin-catalog"
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-jsr"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- vscode-zipfs
- "@yarnpkg/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
- "@yarnpkg/libzip"
- "@yarnpkg/nm"
- "@yarnpkg/pnp"
- "@yarnpkg/pnpify"
- "@yarnpkg/sdks"
- "@yarnpkg/shell"
2 changes: 2 additions & 0 deletions packages/plugin-patch/sources/tools/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ export async function applyPatch({hunks, path}: FilePatch, {baseFs, dryRun = fal

const fileContents = await baseFs.readFileSync(path, `utf8`);
const fileLines = fileContents.split(/\n/);
if (fileLines.at(-1) !== ``)
fileLines.push(``);

const result: Array<Array<Modification>> = [];

Expand Down
38 changes: 38 additions & 0 deletions packages/plugin-patch/tests/apply.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type {PortablePath} from '@yarnpkg/fslib';
import {npath, NodeFS, ppath, CwdFS, xfs} from '@yarnpkg/fslib';

import {applyPatchFile} from '../sources/patchUtils';
import {parsePatchFile} from '../sources/tools/parse';

async function dirSnapshot(p: PortablePath) {
const entries = await xfs.readdirPromise(p, {withFileTypes: true, recursive: true});
return Object.fromEntries(
await Promise.all(entries.map(async entry => {
const rel = ppath.relative(p, ppath.join(entry.parentPath, entry.name));
return [rel, entry.isDirectory() ? null : await xfs.readFilePromise(ppath.join(entry.parentPath, entry.name), `utf8`)];
})),
);
}

describe(`apply`, () => {
const fs = new NodeFS();
const fixtures = ppath.join(npath.toPortablePath(__dirname), `fixtures`, `apply`);

for (const iterator of fs.readdirSync(npath.toPortablePath(fixtures))) {
it(`Applies patch for '${iterator}'`, async () => {
const fixture = ppath.join(fixtures, iterator);

const snapshot = await xfs.mktempPromise(async tmp => {
await xfs.copyPromise(tmp, ppath.join(fixture, `a`));
await applyPatchFile(
parsePatchFile(await fs.readFilePromise(ppath.join(fixture, `patch.patch`), `utf8`)),
{baseFs: new CwdFS(tmp)},
);

return await dirSnapshot(tmp);
});

expect(snapshot).toMatchObject(await dirSnapshot(ppath.join(fixture, `b`)));
});
}
});
2 changes: 1 addition & 1 deletion packages/plugin-patch/tests/diffFolders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {parsePatchFile} from '../sources/tools/parse';

describe(`diffFolders`, () => {
const fs = new NodeFS();
const fixtures = npath.join(__dirname, `fixtures`);
const fixtures = npath.join(__dirname, `fixtures`, `diff`);

for (const iterator of fs.readdirSync(npath.toPortablePath(fixtures))) {
it(`Makes and parses diff for '${iterator}'`, async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo
bar
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
diff --git a/foo.txt b/foo.txt
index 19102815663d23f8b75a47e7a01965dcdc96468c..a907ec3f431eeb6b1c75799a7e4ba73ca6dc627a 100644
--- a/foo.txt
+++ b/foo.txt
@@ -1 +1,2 @@
foo
+bar
\ No newline at end of file
2 changes: 2 additions & 0 deletions packages/yarnpkg-fslib/sources/NodeFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ function direntToPortable(dirent: Dirent<NativePath>): Dirent<PortablePath> {

if (typeof dirent.path === `string`)
portableDirent.path = npath.toPortablePath(dirent.path);
if (typeof dirent.parentPath === `string`)
portableDirent.parentPath = npath.toPortablePath(dirent.parentPath);

return portableDirent;
}
Expand Down
Loading