From 99656a9e1ab5773f7d22ab34a1c5d7ac92e775d9 Mon Sep 17 00:00:00 2001 From: djamaile Date: Tue, 13 Dec 2022 14:51:00 +0100 Subject: [PATCH 01/10] fix: include asset types for repo tools package Signed-off-by: djamaile --- .../src/commands/api-reports/api-extractor.ts | 3 +- .../api-reports/asset-types/asset-types.d.ts | 131 ++++++++++++++++++ 2 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 packages/repo-tools/src/commands/api-reports/asset-types/asset-types.d.ts diff --git a/packages/repo-tools/src/commands/api-reports/api-extractor.ts b/packages/repo-tools/src/commands/api-reports/api-extractor.ts index 46f4ea984b..2fba8eaf76 100644 --- a/packages/repo-tools/src/commands/api-reports/api-extractor.ts +++ b/packages/repo-tools/src/commands/api-reports/api-extractor.ts @@ -232,7 +232,8 @@ export async function createTemporaryTsConfig(includedPackageDirs: string[]) { extends: './tsconfig.json', include: [ // These two contain global definitions that are needed for stable API report generation - 'packages/cli/asset-types/asset-types.d.ts', + // eslint-disable-next-line no-restricted-syntax + `${resolvePath(__dirname)}/asset-types/asset-types.d.ts`, ...includedPackageDirs.map(dir => join(dir, 'src')), ], }); diff --git a/packages/repo-tools/src/commands/api-reports/asset-types/asset-types.d.ts b/packages/repo-tools/src/commands/api-reports/asset-types/asset-types.d.ts new file mode 100644 index 0000000000..0bd0922004 --- /dev/null +++ b/packages/repo-tools/src/commands/api-reports/asset-types/asset-types.d.ts @@ -0,0 +1,131 @@ +/* + * Copyright 2020 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* eslint-disable import/no-extraneous-dependencies */ + +/// +/// +/// + +declare module '*.bmp' { + const src: string; + export default src; +} + +declare module '*.gif' { + const src: string; + export default src; +} + +declare module '*.jpg' { + const src: string; + export default src; +} + +declare module '*.jpeg' { + const src: string; + export default src; +} + +declare module '*.png' { + const src: string; + export default src; +} + +declare module '*.webp' { + const src: string; + export default src; +} + +declare module '*.yaml' { + const src: string; + export default src; +} + +declare module '*.icon.svg' { + import { ComponentType } from 'react'; + import { SvgIconProps } from '@material-ui/core'; + + const Icon: ComponentType; + export default Icon; +} + +declare module '*.svg' { + const src: string; + export default src; +} + +declare module '*.eot' { + const src: string; + export default src; +} + +declare module '*.woff' { + const src: string; + export default src; +} + +declare module '*.woff2' { + const src: string; + export default src; +} + +declare module '*.ttf' { + const src: string; + export default src; +} + +declare module '*.css' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.scss' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.sass' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.module.css' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.module.scss' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.module.sass' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +// NOTE(freben): Both the fix, and the placement of the fix, are not great. +// +// The fix is because the PositionError was renamed to +// GeolocationPositionError outside of our control, and react-use is dependent +// on the old name. +// +// The placement is because it's the one location we have at the moment, where +// a central .d.ts file is imported by the frontend and can be amended. +// +// After both TS and react-use are bumped high enough, this should be removed. +type PositionError = GeolocationPositionError; From 25ec5c0c3a5204d59c8f0cc6963d52f01e55e05e Mon Sep 17 00:00:00 2001 From: djamaile Date: Tue, 13 Dec 2022 14:54:30 +0100 Subject: [PATCH 02/10] fix: add changeset Signed-off-by: djamaile --- .changeset/soft-lies-watch.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/soft-lies-watch.md diff --git a/.changeset/soft-lies-watch.md b/.changeset/soft-lies-watch.md new file mode 100644 index 0000000000..6e38e0f1fa --- /dev/null +++ b/.changeset/soft-lies-watch.md @@ -0,0 +1,5 @@ +--- +'@backstage/repo-tools': patch +--- + +Include asset-types.d.ts while running the api report command From b21d440cdb659ecae60bfba24c34e43bd0bb5617 Mon Sep 17 00:00:00 2001 From: djamaile Date: Tue, 13 Dec 2022 14:59:17 +0100 Subject: [PATCH 03/10] fix: use resolvePath instead Signed-off-by: djamaile --- .../repo-tools/src/commands/api-reports/api-extractor.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/repo-tools/src/commands/api-reports/api-extractor.ts b/packages/repo-tools/src/commands/api-reports/api-extractor.ts index 2fba8eaf76..cd69251594 100644 --- a/packages/repo-tools/src/commands/api-reports/api-extractor.ts +++ b/packages/repo-tools/src/commands/api-reports/api-extractor.ts @@ -66,6 +66,7 @@ import { import { IMarkdownEmitterContext } from '@microsoft/api-documenter/lib/markdown/MarkdownEmitter'; import { AstDeclaration } from '@microsoft/api-extractor/lib/analyzer/AstDeclaration'; import { paths as cliPaths } from '../../lib/paths'; +import { resolvePackagePath as resolvePackagePathBackend } from '@backstage/backend-common'; import minimatch from 'minimatch'; @@ -228,12 +229,13 @@ export async function createTemporaryTsConfig(includedPackageDirs: string[]) { fs.removeSync(path); }); + console.log(resolvePackagePathBackend('@backstage/cli', 'asset-types/asset-types.d.ts')); + await fs.writeJson(path, { extends: './tsconfig.json', include: [ // These two contain global definitions that are needed for stable API report generation - // eslint-disable-next-line no-restricted-syntax - `${resolvePath(__dirname)}/asset-types/asset-types.d.ts`, + `${resolvePackagePathBackend('@backstage/cli', 'asset-types/asset-types.d.ts')}`, ...includedPackageDirs.map(dir => join(dir, 'src')), ], }); From 713100a2c02351f36e82f34788d5ac3a3c438472 Mon Sep 17 00:00:00 2001 From: djamaile Date: Tue, 13 Dec 2022 15:00:47 +0100 Subject: [PATCH 04/10] chore: remove clutter Signed-off-by: djamaile --- .../src/commands/api-reports/api-extractor.ts | 2 - .../api-reports/asset-types/asset-types.d.ts | 131 ------------------ 2 files changed, 133 deletions(-) delete mode 100644 packages/repo-tools/src/commands/api-reports/asset-types/asset-types.d.ts diff --git a/packages/repo-tools/src/commands/api-reports/api-extractor.ts b/packages/repo-tools/src/commands/api-reports/api-extractor.ts index cd69251594..24999a0257 100644 --- a/packages/repo-tools/src/commands/api-reports/api-extractor.ts +++ b/packages/repo-tools/src/commands/api-reports/api-extractor.ts @@ -229,8 +229,6 @@ export async function createTemporaryTsConfig(includedPackageDirs: string[]) { fs.removeSync(path); }); - console.log(resolvePackagePathBackend('@backstage/cli', 'asset-types/asset-types.d.ts')); - await fs.writeJson(path, { extends: './tsconfig.json', include: [ diff --git a/packages/repo-tools/src/commands/api-reports/asset-types/asset-types.d.ts b/packages/repo-tools/src/commands/api-reports/asset-types/asset-types.d.ts deleted file mode 100644 index 0bd0922004..0000000000 --- a/packages/repo-tools/src/commands/api-reports/asset-types/asset-types.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2020 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* eslint-disable import/no-extraneous-dependencies */ - -/// -/// -/// - -declare module '*.bmp' { - const src: string; - export default src; -} - -declare module '*.gif' { - const src: string; - export default src; -} - -declare module '*.jpg' { - const src: string; - export default src; -} - -declare module '*.jpeg' { - const src: string; - export default src; -} - -declare module '*.png' { - const src: string; - export default src; -} - -declare module '*.webp' { - const src: string; - export default src; -} - -declare module '*.yaml' { - const src: string; - export default src; -} - -declare module '*.icon.svg' { - import { ComponentType } from 'react'; - import { SvgIconProps } from '@material-ui/core'; - - const Icon: ComponentType; - export default Icon; -} - -declare module '*.svg' { - const src: string; - export default src; -} - -declare module '*.eot' { - const src: string; - export default src; -} - -declare module '*.woff' { - const src: string; - export default src; -} - -declare module '*.woff2' { - const src: string; - export default src; -} - -declare module '*.ttf' { - const src: string; - export default src; -} - -declare module '*.css' { - const classes: { readonly [key: string]: string }; - export default classes; -} - -declare module '*.scss' { - const classes: { readonly [key: string]: string }; - export default classes; -} - -declare module '*.sass' { - const classes: { readonly [key: string]: string }; - export default classes; -} - -declare module '*.module.css' { - const classes: { readonly [key: string]: string }; - export default classes; -} - -declare module '*.module.scss' { - const classes: { readonly [key: string]: string }; - export default classes; -} - -declare module '*.module.sass' { - const classes: { readonly [key: string]: string }; - export default classes; -} - -// NOTE(freben): Both the fix, and the placement of the fix, are not great. -// -// The fix is because the PositionError was renamed to -// GeolocationPositionError outside of our control, and react-use is dependent -// on the old name. -// -// The placement is because it's the one location we have at the moment, where -// a central .d.ts file is imported by the frontend and can be amended. -// -// After both TS and react-use are bumped high enough, this should be removed. -type PositionError = GeolocationPositionError; From dc7123d1e38e8f0617ce390fd4b559ad8a106e4c Mon Sep 17 00:00:00 2001 From: djamaile Date: Tue, 13 Dec 2022 15:02:32 +0100 Subject: [PATCH 05/10] chore: remove string ip Signed-off-by: djamaile --- packages/repo-tools/src/commands/api-reports/api-extractor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/repo-tools/src/commands/api-reports/api-extractor.ts b/packages/repo-tools/src/commands/api-reports/api-extractor.ts index 24999a0257..c14a90152f 100644 --- a/packages/repo-tools/src/commands/api-reports/api-extractor.ts +++ b/packages/repo-tools/src/commands/api-reports/api-extractor.ts @@ -233,7 +233,7 @@ export async function createTemporaryTsConfig(includedPackageDirs: string[]) { extends: './tsconfig.json', include: [ // These two contain global definitions that are needed for stable API report generation - `${resolvePackagePathBackend('@backstage/cli', 'asset-types/asset-types.d.ts')}`, + resolvePackagePathBackend('@backstage/cli', 'asset-types/asset-types.d.ts'), ...includedPackageDirs.map(dir => join(dir, 'src')), ], }); From 4cb7d2fbf43ee753067c9687eb49e9c402c6d73a Mon Sep 17 00:00:00 2001 From: djamaile Date: Tue, 13 Dec 2022 17:44:05 +0100 Subject: [PATCH 06/10] chore: add empty exclude Signed-off-by: djamaile --- packages/repo-tools/src/commands/api-reports/api-extractor.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/repo-tools/src/commands/api-reports/api-extractor.ts b/packages/repo-tools/src/commands/api-reports/api-extractor.ts index c14a90152f..63387afe54 100644 --- a/packages/repo-tools/src/commands/api-reports/api-extractor.ts +++ b/packages/repo-tools/src/commands/api-reports/api-extractor.ts @@ -236,6 +236,8 @@ export async function createTemporaryTsConfig(includedPackageDirs: string[]) { resolvePackagePathBackend('@backstage/cli', 'asset-types/asset-types.d.ts'), ...includedPackageDirs.map(dir => join(dir, 'src')), ], + // we don't exclude node_modules so that we can use the asset-types.d.ts file + exclude: [], }); return path; From ab3dcebd3a9d8918aedcd400c50aa1a41ef4167b Mon Sep 17 00:00:00 2001 From: djamaile Date: Tue, 13 Dec 2022 18:14:09 +0100 Subject: [PATCH 07/10] chore: run prettier Signed-off-by: djamaile --- .../repo-tools/src/commands/api-reports/api-extractor.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/repo-tools/src/commands/api-reports/api-extractor.ts b/packages/repo-tools/src/commands/api-reports/api-extractor.ts index 63387afe54..43ef750322 100644 --- a/packages/repo-tools/src/commands/api-reports/api-extractor.ts +++ b/packages/repo-tools/src/commands/api-reports/api-extractor.ts @@ -233,7 +233,10 @@ export async function createTemporaryTsConfig(includedPackageDirs: string[]) { extends: './tsconfig.json', include: [ // These two contain global definitions that are needed for stable API report generation - resolvePackagePathBackend('@backstage/cli', 'asset-types/asset-types.d.ts'), + resolvePackagePathBackend( + '@backstage/cli', + 'asset-types/asset-types.d.ts', + ), ...includedPackageDirs.map(dir => join(dir, 'src')), ], // we don't exclude node_modules so that we can use the asset-types.d.ts file From fe1d2269cde1c513174cd918fd94c1d665890ed3 Mon Sep 17 00:00:00 2001 From: djamaile Date: Wed, 14 Dec 2022 15:06:07 +0100 Subject: [PATCH 08/10] chore: use require resolve Signed-off-by: djamaile --- .../repo-tools/src/commands/api-reports/api-extractor.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/repo-tools/src/commands/api-reports/api-extractor.ts b/packages/repo-tools/src/commands/api-reports/api-extractor.ts index 43ef750322..6441de2770 100644 --- a/packages/repo-tools/src/commands/api-reports/api-extractor.ts +++ b/packages/repo-tools/src/commands/api-reports/api-extractor.ts @@ -66,8 +66,6 @@ import { import { IMarkdownEmitterContext } from '@microsoft/api-documenter/lib/markdown/MarkdownEmitter'; import { AstDeclaration } from '@microsoft/api-extractor/lib/analyzer/AstDeclaration'; import { paths as cliPaths } from '../../lib/paths'; -import { resolvePackagePath as resolvePackagePathBackend } from '@backstage/backend-common'; - import minimatch from 'minimatch'; const tmpDir = cliPaths.resolveTargetRoot( @@ -233,10 +231,7 @@ export async function createTemporaryTsConfig(includedPackageDirs: string[]) { extends: './tsconfig.json', include: [ // These two contain global definitions that are needed for stable API report generation - resolvePackagePathBackend( - '@backstage/cli', - 'asset-types/asset-types.d.ts', - ), + require.resolve('@backstage/cli/asset-types/asset-types.d.ts'), ...includedPackageDirs.map(dir => join(dir, 'src')), ], // we don't exclude node_modules so that we can use the asset-types.d.ts file From 82bd45528a0545a3bca8951df51ac6dabf65650a Mon Sep 17 00:00:00 2001 From: djamaile Date: Thu, 15 Dec 2022 13:53:02 +0100 Subject: [PATCH 09/10] chore: add try and catch around require resolve Signed-off-by: djamaile --- .../src/commands/api-reports/api-extractor.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/repo-tools/src/commands/api-reports/api-extractor.ts b/packages/repo-tools/src/commands/api-reports/api-extractor.ts index 6441de2770..414c0ba4d3 100644 --- a/packages/repo-tools/src/commands/api-reports/api-extractor.ts +++ b/packages/repo-tools/src/commands/api-reports/api-extractor.ts @@ -14,9 +14,6 @@ * limitations under the License. */ -/* eslint-disable import/no-extraneous-dependencies */ -/* eslint-disable no-restricted-imports */ - import { resolve as resolvePath, relative as relativePath, @@ -227,11 +224,21 @@ export async function createTemporaryTsConfig(includedPackageDirs: string[]) { fs.removeSync(path); }); + let assetTypeFile: string[] = []; + + try { + assetTypeFile = [ + require.resolve('@backstage/cli/asset-types/asset-types.d.ts'), + ]; + } catch { + /** ignore */ + } + await fs.writeJson(path, { extends: './tsconfig.json', include: [ // These two contain global definitions that are needed for stable API report generation - require.resolve('@backstage/cli/asset-types/asset-types.d.ts'), + ...assetTypeFile, ...includedPackageDirs.map(dir => join(dir, 'src')), ], // we don't exclude node_modules so that we can use the asset-types.d.ts file From c210d70218344e51d52ac7bafab1305a840ceb05 Mon Sep 17 00:00:00 2001 From: djamaile Date: Thu, 15 Dec 2022 14:46:21 +0100 Subject: [PATCH 10/10] chore: add try and catch around require resolve Signed-off-by: djamaile --- packages/repo-tools/src/commands/api-reports/api-extractor.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/repo-tools/src/commands/api-reports/api-extractor.ts b/packages/repo-tools/src/commands/api-reports/api-extractor.ts index 414c0ba4d3..e6f1ffb101 100644 --- a/packages/repo-tools/src/commands/api-reports/api-extractor.ts +++ b/packages/repo-tools/src/commands/api-reports/api-extractor.ts @@ -14,6 +14,8 @@ * limitations under the License. */ +/* eslint-disable import/no-extraneous-dependencies */ +/* eslint-disable no-restricted-imports */ import { resolve as resolvePath, relative as relativePath,