diff --git a/.changeset/sad-taxes-bake.md b/.changeset/sad-taxes-bake.md new file mode 100644 index 0000000000..61a843a265 --- /dev/null +++ b/.changeset/sad-taxes-bake.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': patch +--- + +Fixed bug in fs:delete that prevented wildcard patterns from matching paths starting with "." diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/delete.examples.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/delete.examples.ts index a32249f210..8fa15fd2d7 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/delete.examples.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/delete.examples.ts @@ -48,4 +48,19 @@ export const examples: TemplateExample[] = [ ], }), }, + { + description: 'Delete all files in workspace', + example: yaml.stringify({ + steps: [ + { + action: 'fs:delete', + id: 'deleteFiles', + name: 'Delete files', + input: { + files: ['**'], + }, + }, + ], + }), + }, ]; diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/delete.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/delete.test.ts index b0b16c6d12..efc2fe3143 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/delete.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/delete.test.ts @@ -40,8 +40,14 @@ describe('fs:delete', () => { [workspacePath]: { 'unit-test-a.js': 'hello', 'unit-test-b.js': 'world', - 'a-folder': { - 'unit-test-in-a-folder.js2': 'content', + '.dotfile': 'content', + '.dotdir': { + '.dotfile': 'content', + 'reg-file.js': 'content', + }, + regdir: { + '.dotfile': 'content', + 'reg-file.js': 'content', }, }, }); @@ -165,4 +171,62 @@ describe('fs:delete', () => { expect(fileExists).toBe(false); }); }); + + it('. pattern should match nested and hidden files', async () => { + const files = [ + 'unit-test-a.js', + 'unit-test-b.js', + '.dotfile', + '.dotdir/.dotfile', + '.dotdir/reg-file.js', + 'regdir/.dotfile', + 'regdir/reg-file.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.forEach(file => { + const filePath = resolvePath(workspacePath, file); + const fileExists = fs.existsSync(filePath); + expect(fileExists).toBe(false); + }); + }); + + it('** pattern should match nested and hidden files', async () => { + const files = [ + 'unit-test-a.js', + 'unit-test-b.js', + '.dotfile', + '.dotdir/.dotfile', + '.dotdir/reg-file.js', + 'regdir/.dotfile', + 'regdir/reg-file.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.forEach(file => { + const filePath = resolvePath(workspacePath, file); + const fileExists = fs.existsSync(filePath); + expect(fileExists).toBe(false); + }); + }); }); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/delete.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/delete.ts index b2f9cddea4..5f894a4b3e 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/delete.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/delete.ts @@ -61,6 +61,7 @@ export const createFilesystemDeleteAction = () => { const resolvedPaths = await globby(safeFilepath, { cwd: ctx.workspacePath, absolute: true, + dot: true, }); for (const filepath of resolvedPaths) {