Skip to content

Commit

Permalink
normalize path for multimatch. (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Aug 18, 2024
1 parent bd82951 commit 7685ac8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/actions/copy-async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ export async function copyAsync(
const diskFiles = globbySync(fromGlob, globOptions).map((filepath) => path.resolve(filepath));
const storeFiles: string[] = [];
this.store.each((file) => {
const normalizedFilepath = normalize(file.path);
// The store may have a glob path and when we try to copy it will fail because not real file
if (
!isDynamicPattern(normalize(file.path)) &&
multimatch([file.path], fromGlob).length !== 0 &&
!isDynamicPattern(normalizedFilepath) &&
multimatch([normalizedFilepath], fromGlob).length !== 0 &&
!diskFiles.includes(file.path)
) {
storeFiles.push(file.path);
Expand Down
5 changes: 3 additions & 2 deletions src/actions/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ export function copy(

const storeFiles: string[] = [];
this.store.each((file) => {
const normalizedFilepath = normalize(file.path);
// The store may have a glob path and when we try to copy it will fail because not real file
if (
!diskFiles.includes(file.path) &&
!isDynamicPattern(normalize(file.path)) &&
multimatch([file.path], fromGlob).length !== 0
!isDynamicPattern(normalizedFilepath) &&
multimatch([normalizedFilepath], fromGlob).length !== 0
) {
storeFiles.push(file.path);
}
Expand Down
3 changes: 2 additions & 1 deletion src/actions/delete.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path';
import { globbySync, type Options as GlobbyOptions } from 'globby';
import multimatch from 'multimatch';
import normalize from 'normalize-path';

import type { MemFsEditor, MemFsEditorFile } from '../index.js';
import type { Store } from 'mem-fs';
Expand Down Expand Up @@ -34,7 +35,7 @@ export default function deleteAction(
});

this.store.each((file) => {
if (multimatch([file.path], paths).length !== 0) {
if (multimatch([normalize(file.path)], paths).length !== 0) {
deleteFile(file.path, this.store);
}
});
Expand Down

0 comments on commit 7685ac8

Please sign in to comment.