From 949083ddb41067368bc3638303683e1340614563 Mon Sep 17 00:00:00 2001 From: Isabel Tomb Date: Mon, 8 Jul 2024 13:03:39 -0500 Subject: [PATCH 1/4] Update `patchMkdocsYmlPreBuild` Update the `patchMkdocsYmlPreBuild` function to modify `repo_url` and `edit_uri` independently of each other. Prior to this change both `repo_url` and `edit_uri` would have to be missing for either to be generated which caused an issue in the situation where `repo_url` is provided in the mkdocs.yml and `edit_uri` is not because the default `edit_uri` value from mkdocs would be used instead. This value uses `master` as the branch in the link which breaks the edit link for repos that don't use `master` as the default branch. Signed-off-by: Isabel Tomb --- .changeset/mighty-geckos-kiss.md | 5 +++++ plugins/techdocs-node/src/stages/generate/mkdocsPatchers.ts | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .changeset/mighty-geckos-kiss.md diff --git a/.changeset/mighty-geckos-kiss.md b/.changeset/mighty-geckos-kiss.md new file mode 100644 index 0000000000..0761d8b257 --- /dev/null +++ b/.changeset/mighty-geckos-kiss.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-techdocs-node': patch +--- + +Update `patchMkdocsYmlPrebuild` to modify `repo_url` and `edit_uri` independently. diff --git a/plugins/techdocs-node/src/stages/generate/mkdocsPatchers.ts b/plugins/techdocs-node/src/stages/generate/mkdocsPatchers.ts index 762a1c267a..fb95c19a9c 100644 --- a/plugins/techdocs-node/src/stages/generate/mkdocsPatchers.ts +++ b/plugins/techdocs-node/src/stages/generate/mkdocsPatchers.ts @@ -108,7 +108,7 @@ export const patchMkdocsYmlPreBuild = async ( scmIntegrations: ScmIntegrationRegistry, ) => { await patchMkdocsFile(mkdocsYmlPath, logger, mkdocsYml => { - if (!('repo_url' in mkdocsYml) && !('edit_uri' in mkdocsYml)) { + if (!('repo_url' in mkdocsYml) || !('edit_uri' in mkdocsYml)) { // Add edit_uri and/or repo_url to mkdocs.yml if it is missing. // This will enable the Page edit button generated by MkDocs. // If the either has been set, keep the original value @@ -119,8 +119,8 @@ export const patchMkdocsYmlPreBuild = async ( ); if (result.repo_url || result.edit_uri) { - mkdocsYml.repo_url = result.repo_url; - mkdocsYml.edit_uri = result.edit_uri; + mkdocsYml.repo_url = mkdocsYml.repo_url || result.repo_url; + mkdocsYml.edit_uri = mkdocsYml.edit_uri || result.edit_uri; logger.info( `Set ${JSON.stringify( From 839e888e3a7e348b200cb6eeda68b782a12e782c Mon Sep 17 00:00:00 2001 From: Isabel Tomb Date: Mon, 8 Jul 2024 13:44:01 -0500 Subject: [PATCH 2/4] Add a test for new repo_url edit_uri scenario Add a test that checks that an edit_uri will be generated as expected if the mkdocs.yml contains a `repo_url` value but no `edit_uri` vlaue. Signed-off-by: Isabel Tomb --- .../src/stages/generate/helpers.test.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/plugins/techdocs-node/src/stages/generate/helpers.test.ts b/plugins/techdocs-node/src/stages/generate/helpers.test.ts index 3589b71c60..a40239c595 100644 --- a/plugins/techdocs-node/src/stages/generate/helpers.test.ts +++ b/plugins/techdocs-node/src/stages/generate/helpers.test.ts @@ -299,6 +299,31 @@ describe('helpers', () => { ); }); + it('should add edit_uri to mkdocs.yml with existing repo_url', async () => { + const parsedLocationAnnotation: ParsedLocationAnnotation = { + type: 'url', + target: 'https://github.com/neworg/newrepo/tree/main/', + }; + + await patchMkdocsYmlPreBuild( + mockDir.resolve('mkdocs_with_repo_url.yml'), + mockLogger, + parsedLocationAnnotation, + scmIntegrations, + ); + + const updatedMkdocsYml = await fs.readFile( + mockDir.resolve('mkdocs_with_repo_url.yml'), + ); + + expect(updatedMkdocsYml.toString()).toContain( + 'edit_uri: https://github.com/neworg/newrepo/edit/main/docs', + ); + expect(updatedMkdocsYml.toString()).toContain( + 'repo_url: https://github.com/backstage/backstage', + ); + }); + it('should not update mkdocs.yml if nothing should be changed', async () => { const parsedLocationAnnotation: ParsedLocationAnnotation = { type: 'dir', From 0afa044555655e07f9e31d3eceb32c2177a0c1db Mon Sep 17 00:00:00 2001 From: Isabel Tomb Date: Mon, 8 Jul 2024 13:45:50 -0500 Subject: [PATCH 3/4] Update test Update the test that checks that the existing edit_uri value in a mkdocs.yml won't be overridden by `patchMkdocsYmlPreBuild` so that it checks the value of 'edit_uri' was not updated rather than just checking for the existence of the substring. This change is needed because the substring will exist in the file but as the `repo_url` value which is expected after the changes in the previous commits. Signed-off-by: Isabel Tomb --- plugins/techdocs-node/src/stages/generate/helpers.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/techdocs-node/src/stages/generate/helpers.test.ts b/plugins/techdocs-node/src/stages/generate/helpers.test.ts index a40239c595..6ee3870845 100644 --- a/plugins/techdocs-node/src/stages/generate/helpers.test.ts +++ b/plugins/techdocs-node/src/stages/generate/helpers.test.ts @@ -295,7 +295,7 @@ describe('helpers', () => { 'edit_uri: https://github.com/backstage/backstage/edit/main/docs', ); expect(updatedMkdocsYml.toString()).not.toContain( - 'https://github.com/neworg/newrepo', + 'edit_uri: https://github.com/neworg/newrepo', ); }); From e6e7d862fec44754faac302e6e4d7021a19b9ef0 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 24 Jul 2024 15:04:05 +0200 Subject: [PATCH 4/4] cli: use lowercase es2022 Signed-off-by: Patrik Oldsberg --- .changeset/shaggy-dodos-applaud.md | 5 +++++ packages/cli/src/lib/bundler/transforms.ts | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/shaggy-dodos-applaud.md diff --git a/.changeset/shaggy-dodos-applaud.md b/.changeset/shaggy-dodos-applaud.md new file mode 100644 index 0000000000..b7f968aa39 --- /dev/null +++ b/.changeset/shaggy-dodos-applaud.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Switched the target from `'ES2022'` to `'es2022'` for better compatibility with older versions of `swc`. diff --git a/packages/cli/src/lib/bundler/transforms.ts b/packages/cli/src/lib/bundler/transforms.ts index 1be54f7a73..302b2fbe68 100644 --- a/packages/cli/src/lib/bundler/transforms.ts +++ b/packages/cli/src/lib/bundler/transforms.ts @@ -57,7 +57,7 @@ export const transforms = (options: TransformOptions): Transforms => { loader: require.resolve('swc-loader'), options: { jsc: { - target: 'ES2022', + target: 'es2022', externalHelpers: !isBackend, parser: { syntax: 'typescript', @@ -85,7 +85,7 @@ export const transforms = (options: TransformOptions): Transforms => { loader: require.resolve('swc-loader'), options: { jsc: { - target: 'ES2022', + target: 'es2022', externalHelpers: !isBackend, parser: { syntax: 'ecmascript',