Merge pull request #29113 from dtrexler/29064-fsdelete-globby-path-fix
fix: fs:delete action does not delete files on windows
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend': patch
|
||||
---
|
||||
|
||||
Fixed bug in fs:delete causing no files to be deleted on windows machines
|
||||
@@ -144,4 +144,25 @@ describe('fs:delete', () => {
|
||||
expect(fileExists).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle windows style file paths', async () => {
|
||||
const files = ['unit-test-a.js', 'unit-test-b.js'];
|
||||
|
||||
files.forEach(file => {
|
||||
const filePath = resolvePath(workspacePath, file);
|
||||
const fileExists = fs.existsSync(filePath);
|
||||
expect(fileExists).toBe(true);
|
||||
});
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: { files: files.map(file => `.\\${file}`) },
|
||||
});
|
||||
|
||||
files.forEach(file => {
|
||||
const filePath = resolvePath(workspacePath, file);
|
||||
const fileExists = fs.existsSync(filePath);
|
||||
expect(fileExists).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -53,7 +53,11 @@ export const createFilesystemDeleteAction = () => {
|
||||
}
|
||||
|
||||
for (const file of ctx.input.files) {
|
||||
const safeFilepath = resolveSafeChildPath(ctx.workspacePath, file);
|
||||
// globby cannot handle backslash file separators
|
||||
const safeFilepath = resolveSafeChildPath(
|
||||
ctx.workspacePath,
|
||||
file,
|
||||
).replace(/\\/g, '/');
|
||||
const resolvedPaths = await globby(safeFilepath, {
|
||||
cwd: ctx.workspacePath,
|
||||
absolute: true,
|
||||
|
||||
Reference in New Issue
Block a user