From 79a502366b0905dbd93d35e00b8a5185937b4bb5 Mon Sep 17 00:00:00 2001 From: Dmitry Remezov Date: Sat, 21 Oct 2023 23:55:01 +0300 Subject: [PATCH 1/3] fix(vfs): fix incorrect resolving absolute paths --- libs/vfs/src/__tests__/vsf.test.ts | 33 +++++++++++++++++--- libs/vfs/src/implementations/abstract-vfs.ts | 6 ++-- libs/vfs/src/implementations/virtual-fs.ts | 2 +- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/libs/vfs/src/__tests__/vsf.test.ts b/libs/vfs/src/__tests__/vsf.test.ts index 343a397..d679649 100644 --- a/libs/vfs/src/__tests__/vsf.test.ts +++ b/libs/vfs/src/__tests__/vsf.test.ts @@ -93,20 +93,20 @@ describe('Tree', () => { test('should ignore equal changes', async () => { const vfs = await factory(); - await vfs.write('/parent/parent-file.ts', 'new content'); + await vfs.write('parent/parent-file.ts', 'new content'); await vfs.delete('root-file.ts'); - await vfs.rename('/parent/child/child-file.ts', '/another-dir/file.ts'); + await vfs.rename('parent/child/child-file.ts', 'another-dir/file.ts'); // Rename === write + delete expect(await vfs.getChanges()).toHaveLength(4); expectArrayEq(await vfs.readDir(), ['parent', 'another-dir']); await vfs.write('root-file.ts', Buffer.from('root content')); - await vfs.write('/parent/parent-file.ts', 'parent content'); + await vfs.write('parent/parent-file.ts', 'parent content'); // Instead of rename - await vfs.delete('/another-dir/file.ts'); - await vfs.write('/parent/child/child-file.ts', 'child content'); + await vfs.delete('another-dir/file.ts'); + await vfs.write('parent/child/child-file.ts', 'child content'); expect(await vfs.getChanges()).toHaveLength(0); }); @@ -232,6 +232,29 @@ describe('Tree', () => { expect(await vfs.read('src/ignored.ejs', 'utf-8')).toBe('<%=foo% > ___'); }); }); + + test('should resolve different paths', async () => { + const vfs = createVfs('/root/path', { + virtual: true, + log + }); + + await vfs.write('relative', 'content'); + await vfs.write('./relative-dot', 'content'); + await vfs.write('../path/relative-jump', 'content'); + await vfs.write('/root/path/absolute', 'content'); + await vfs.write('/root/other/file-1', 'content'); + await vfs.write('../other/file-2', 'content'); + + await vfs.applyChanges(); + expectArrayEq(await vfs.readDir('../other'), ['file-1', 'file-2']); + expectArrayEq(await vfs.readDir('.'), [ + 'relative', + 'relative-dot', + 'relative-jump', + 'absolute' + ]); + }); }); // eslint-disable-next-line @typescript-eslint/require-array-sort-compare diff --git a/libs/vfs/src/implementations/abstract-vfs.ts b/libs/vfs/src/implementations/abstract-vfs.ts index 29db683..dbe3816 100644 --- a/libs/vfs/src/implementations/abstract-vfs.ts +++ b/libs/vfs/src/implementations/abstract-vfs.ts @@ -2,7 +2,7 @@ import { colors } from '@neodx/colors'; import type { LoggerMethods } from '@neodx/log'; import { createLogger, pretty } from '@neodx/log/node'; import { compact, uniq } from '@neodx/std'; -import { dirname, join, relative, sep } from 'pathe'; +import { dirname, join, relative, resolve, sep } from 'pathe'; import type { BaseVFS, ContentLike, FileChange } from '../types'; import { FileChangeType } from '../types'; @@ -129,7 +129,7 @@ export abstract class AbstractVfs implements BaseVFS { } } - async readDir(path = '/'): Promise { + async readDir(path = '.'): Promise { const normalized = this.normalizePath(path); const currentList = await this.readDirImpl(normalized); @@ -185,7 +185,7 @@ export abstract class AbstractVfs implements BaseVFS { } protected normalizePath(path: string) { - return relative(this.root, join(this.root, path)).replaceAll(sep, '/'); + return relative(this.root, resolve(this.root, path)).replaceAll(sep, '/'); } protected getNotDeletedChangesStartsFrom(path: string) { diff --git a/libs/vfs/src/implementations/virtual-fs.ts b/libs/vfs/src/implementations/virtual-fs.ts index eed9b2a..33140a4 100644 --- a/libs/vfs/src/implementations/virtual-fs.ts +++ b/libs/vfs/src/implementations/virtual-fs.ts @@ -95,7 +95,7 @@ export class VirtualFs extends AbstractVfs { const names = Array.from(this.virtualFs.keys()); if (path === '') { - return names.map(name => name.split('/')[0]); + return names.map(name => name.split('/')[0]).filter(name => !name.startsWith('.')); } return names .filter(name => name.startsWith(`${path}/`)) From 2f5a58a2a97329a73f872f3f8a61e3903505ea63 Mon Sep 17 00:00:00 2001 From: Dmitry Remezov Date: Sat, 21 Oct 2023 23:58:46 +0300 Subject: [PATCH 2/3] changeset(vfs): fix paths --- .changeset/slow-points-drive.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/slow-points-drive.md diff --git a/.changeset/slow-points-drive.md b/.changeset/slow-points-drive.md new file mode 100644 index 0000000..2eb0f58 --- /dev/null +++ b/.changeset/slow-points-drive.md @@ -0,0 +1,5 @@ +--- +'@neodx/vfs': patch +--- + +Fix incorrect resolving absolute paths From 714812d119ed78bb5f628576aef2d7f6f63f4b50 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 21 Oct 2023 21:08:05 +0000 Subject: [PATCH 3/3] Version Packages --- .changeset/slow-points-drive.md | 5 ----- libs/codegen/package.json | 2 +- libs/figma/CHANGELOG.md | 7 +++++++ libs/figma/package.json | 4 ++-- libs/svg/CHANGELOG.md | 7 +++++++ libs/svg/package.json | 4 ++-- libs/vfs/CHANGELOG.md | 6 ++++++ libs/vfs/package.json | 2 +- yarn.lock | 8 ++++---- 9 files changed, 30 insertions(+), 15 deletions(-) delete mode 100644 .changeset/slow-points-drive.md diff --git a/.changeset/slow-points-drive.md b/.changeset/slow-points-drive.md deleted file mode 100644 index 2eb0f58..0000000 --- a/.changeset/slow-points-drive.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@neodx/vfs': patch ---- - -Fix incorrect resolving absolute paths diff --git a/libs/codegen/package.json b/libs/codegen/package.json index 64b5851..6ccaee5 100644 --- a/libs/codegen/package.json +++ b/libs/codegen/package.json @@ -63,7 +63,7 @@ "@neodx/fs": "0.0.10", "@neodx/pkg-misc": "0.0.8", "@neodx/std": "0.2.0", - "@neodx/vfs": "0.1.10", + "@neodx/vfs": "0.1.11", "ejs": "3.1.9", "jsonc-parser": "3.2.0", "picocolors": "1.0.0", diff --git a/libs/figma/CHANGELOG.md b/libs/figma/CHANGELOG.md index 7a600f1..bd367e8 100644 --- a/libs/figma/CHANGELOG.md +++ b/libs/figma/CHANGELOG.md @@ -1,5 +1,12 @@ # @neodx/figma +## 0.4.1 + +### Patch Changes + +- Updated dependencies [[`2f5a58a`](https://github.com/secundant/neodx/commit/2f5a58a2a97329a73f872f3f8a61e3903505ea63)]: + - @neodx/vfs@0.1.11 + ## 0.4.0 ### Minor Changes diff --git a/libs/figma/package.json b/libs/figma/package.json index db578fa..8697ade 100644 --- a/libs/figma/package.json +++ b/libs/figma/package.json @@ -1,6 +1,6 @@ { "name": "@neodx/figma", - "version": "0.4.0", + "version": "0.4.1", "packageManager": "yarn@3.2.0", "description": "No description", "type": "module", @@ -57,7 +57,7 @@ "dependencies": { "@neodx/log": "0.3.0", "@neodx/std": "0.2.0", - "@neodx/vfs": "0.1.10", + "@neodx/vfs": "0.1.11", "colord": "2.9.3", "commander": "11.0.0", "cosmiconfig": "8.3.6", diff --git a/libs/svg/CHANGELOG.md b/libs/svg/CHANGELOG.md index 85e15c4..c1a6070 100644 --- a/libs/svg/CHANGELOG.md +++ b/libs/svg/CHANGELOG.md @@ -1,5 +1,12 @@ # @neodx/svg +## 0.6.1 + +### Patch Changes + +- Updated dependencies [[`2f5a58a`](https://github.com/secundant/neodx/commit/2f5a58a2a97329a73f872f3f8a61e3903505ea63)]: + - @neodx/vfs@0.1.11 + ## 0.6.0 ### Minor Changes diff --git a/libs/svg/package.json b/libs/svg/package.json index b668f67..d0b387f 100644 --- a/libs/svg/package.json +++ b/libs/svg/package.json @@ -1,7 +1,7 @@ { "name": "@neodx/svg", "packageManager": "yarn@3.2.0", - "version": "0.6.0", + "version": "0.6.1", "description": "Supercharge your icons ⚡️", "author": { "name": "Dmitry Remezov", @@ -62,7 +62,7 @@ "@neodx/fs": "0.0.10", "@neodx/log": "0.3.0", "@neodx/std": "0.2.0", - "@neodx/vfs": "0.1.10", + "@neodx/vfs": "0.1.11", "chokidar": "3.5.3", "colord": "2.9.3", "commander": "11.0.0", diff --git a/libs/vfs/CHANGELOG.md b/libs/vfs/CHANGELOG.md index e284e89..32e15c4 100644 --- a/libs/vfs/CHANGELOG.md +++ b/libs/vfs/CHANGELOG.md @@ -1,5 +1,11 @@ # @neodx/vfs +## 0.1.11 + +### Patch Changes + +- [`2f5a58a`](https://github.com/secundant/neodx/commit/2f5a58a2a97329a73f872f3f8a61e3903505ea63) Thanks [@secundant](https://github.com/secundant)! - Fix incorrect resolving absolute paths + ## 0.1.10 ### Patch Changes diff --git a/libs/vfs/package.json b/libs/vfs/package.json index 2d7ab5f..2a35cc9 100644 --- a/libs/vfs/package.json +++ b/libs/vfs/package.json @@ -1,6 +1,6 @@ { "name": "@neodx/vfs", - "version": "0.1.10", + "version": "0.1.11", "description": "Simple virtual file system - working dir context, lazy changes, different modes, integrations and moreover", "type": "module", "main": "./dist/cjs/index.cjs", diff --git a/yarn.lock b/yarn.lock index 7074b37..06622b0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1564,7 +1564,7 @@ __metadata: "@neodx/fs": 0.0.10 "@neodx/pkg-misc": 0.0.8 "@neodx/std": 0.2.0 - "@neodx/vfs": 0.1.10 + "@neodx/vfs": 0.1.11 "@types/ejs": 3.1.3 "@types/semver": 7.5.3 "@types/tmp": 0.2.4 @@ -1601,7 +1601,7 @@ __metadata: "@neodx/autobuild": "*" "@neodx/log": 0.3.0 "@neodx/std": 0.2.0 - "@neodx/vfs": 0.1.10 + "@neodx/vfs": 0.1.11 colord: 2.9.3 commander: 11.0.0 cosmiconfig: 8.3.6 @@ -1747,7 +1747,7 @@ __metadata: "@neodx/fs": 0.0.10 "@neodx/log": 0.3.0 "@neodx/std": 0.2.0 - "@neodx/vfs": 0.1.10 + "@neodx/vfs": 0.1.11 "@swc/helpers": 0.5.3 "@types/react": 18.2.25 "@types/react-dom": 18.2.11 @@ -1774,7 +1774,7 @@ __metadata: languageName: unknown linkType: soft -"@neodx/vfs@*, @neodx/vfs@0.1.10, @neodx/vfs@workspace:libs/vfs": +"@neodx/vfs@*, @neodx/vfs@0.1.11, @neodx/vfs@workspace:libs/vfs": version: 0.0.0-use.local resolution: "@neodx/vfs@workspace:libs/vfs" dependencies: