Merge pull request #5271 from lancelot1337/bug/fix-for-5236

Update !url.startsWith condition in file.ts
This commit is contained in:
Patrik Oldsberg
2021-04-09 17:15:05 +02:00
committed by GitHub
3 changed files with 33 additions and 6 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend': patch
---
Fix for the `file://` protocol check in the `FilePreparer` being too strict, breaking Windows.
@@ -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()}`,
);
}
});
});
@@ -21,15 +21,15 @@ import { PreparerBase, PreparerOptions } from './types';
export class FilePreparer implements PreparerBase {
async prepare({ url, workspacePath }: PreparerOptions) {
if (!url.startsWith('file:///')) {
if (!url.startsWith('file://')) {
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,
});