diff --git a/.changeset/forty-paws-drum.md b/.changeset/forty-paws-drum.md new file mode 100644 index 0000000000..1f3b587b8a --- /dev/null +++ b/.changeset/forty-paws-drum.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': patch +--- + +Fix for the `file://` protocol check in the `FilePreparer` being too strict, breaking Windows. diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/prepare/file.test.ts b/plugins/scaffolder-backend/src/scaffolder/stages/prepare/file.test.ts index f6e5600a83..24a3ef4112 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/prepare/file.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/prepare/file.test.ts @@ -31,7 +31,7 @@ describe('File preparer', () => { const targetPath = path.resolve(workspacePath, 'template'); await preparer.prepare({ - url: `file:///${root}path/to/template`, + url: `file://${root}path/to/template`, logger, workspacePath, }); @@ -46,12 +46,34 @@ describe('File preparer', () => { await expect( preparer.prepare({ - url: 'file://not/full/path', + url: 'http://not/file/path', logger, workspacePath, }), ).rejects.toThrow( - "Wrong location protocol, should be 'file', file://not/full/path", + "Wrong location protocol, should be 'file', http://not/file/path", ); + + if (os.platform() === 'win32') { + // eslint-disable-next-line jest/no-conditional-expect + await expect( + preparer.prepare({ + url: 'file:///unix/file/path', + logger, + workspacePath, + }), + ).rejects.toThrow('File URL path must be absolute'); + } else { + // eslint-disable-next-line jest/no-conditional-expect + await expect( + preparer.prepare({ + url: 'file://not/full/path', + logger, + workspacePath, + }), + ).rejects.toThrow( + `File URL host must be "localhost" or empty on ${os.platform()}`, + ); + } }); }); diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/prepare/file.ts b/plugins/scaffolder-backend/src/scaffolder/stages/prepare/file.ts index 728a67a588..b02c496ff5 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/prepare/file.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/prepare/file.ts @@ -25,11 +25,11 @@ export class FilePreparer implements PreparerBase { throw new InputError(`Wrong location protocol, should be 'file', ${url}`); } + const templatePath = fileURLToPath(url); + const targetDir = path.join(workspacePath, 'template'); await fs.ensureDir(targetDir); - const templatePath = fileURLToPath(url); - await fs.copy(templatePath, targetDir, { recursive: true, });