Move docs directory validation to after copying README.md

Signed-off-by: Ruslans Tarasovs <ruslan@tarasovs.com>
This commit is contained in:
Ruslans Tarasovs
2026-03-16 12:38:46 +02:00
committed by Ruslans Tarasovs
parent fd1854e3bc
commit 6ce84626ab
3 changed files with 25 additions and 5 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-techdocs-node': patch
---
Fixed bug causing --legacyCopyReadmeMdToIndexMd option to fail if docs directory is not present
@@ -60,6 +60,7 @@ jest.setTimeout(timeout * 2);
describe('end-to-end', () => {
const cwd = path.resolve(__dirname, '../src/example-docs');
const legacyCwd = path.resolve(__dirname, '../src/legacy-docs');
const entryPoint = path.resolve(__dirname, '../bin/techdocs-cli');
afterEach(async () => {
@@ -106,6 +107,19 @@ describe('end-to-end', () => {
expect(proc.exit).toEqual(0);
});
it('can generate with --legacyCopyReadmeMdToIndexMd option', async () => {
const proc = await executeCommand(
entryPoint,
['generate', '--no-docker', '--legacyCopyReadmeMdToIndexMd'],
{
legacyCwd,
timeout,
},
);
expect(proc.stdout).toContain('Successfully generated docs');
expect(proc.exit).toEqual(0);
});
it('can serve in mkdocs', async () => {
const proc = await executeCommand(
entryPoint,
@@ -121,11 +121,6 @@ export class TechdocsGenerator implements GeneratorBase {
this.options.dangerouslyAllowAdditionalKeys,
);
// Validate that no symlinks in the docs directory point outside the input directory
// This prevents path traversal attacks where malicious symlinks could leak host files
const resolvedDocsDir = path.join(inputDir, docsDir ?? 'docs');
await validateDocsDirectory(resolvedDocsDir, inputDir);
if (parsedLocationAnnotation) {
await patchMkdocsYmlPreBuild(
mkdocsYmlPath,
@@ -139,6 +134,12 @@ export class TechdocsGenerator implements GeneratorBase {
await patchIndexPreBuild({ inputDir, logger: childLogger, docsDir });
}
// Validate that no symlinks in the docs directory point outside the input directory
// This prevents path traversal attacks where malicious symlinks could leak host files
const resolvedDocsDir = path.join(inputDir, docsDir ?? 'docs');
await validateDocsDirectory(resolvedDocsDir, inputDir);
// patch the list of mkdocs plugins
const defaultPlugins = this.options.defaultPlugins ?? [];