From 8e3fd0f0f69d98685fd249e3bbe578fa6b39271d Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Wed, 1 Feb 2023 19:10:08 +0100 Subject: [PATCH 01/19] generate change files --- ...gration-v8-v9-ca54b58c-216f-4a2c-bc44-b19249dd8d16.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/@fluentui-react-migration-v8-v9-ca54b58c-216f-4a2c-bc44-b19249dd8d16.json diff --git a/change/@fluentui-react-migration-v8-v9-ca54b58c-216f-4a2c-bc44-b19249dd8d16.json b/change/@fluentui-react-migration-v8-v9-ca54b58c-216f-4a2c-bc44-b19249dd8d16.json new file mode 100644 index 00000000000000..e559a82c4d869e --- /dev/null +++ b/change/@fluentui-react-migration-v8-v9-ca54b58c-216f-4a2c-bc44-b19249dd8d16.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: enable build-less DX for storybook", + "packageName": "@fluentui/react-migration-v8-v9", + "email": "martinhochel@microsoft.com", + "dependentChangeType": "none" +} From 6d0df39a1efca202f9a41e5976f4842a7f871f31 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Thu, 2 Feb 2023 10:21:05 +0100 Subject: [PATCH 02/19] chore(public-docsite-v9): enable whole monorepo TS path aliases for improved DX --- apps/public-docsite-v9/tsconfig.json | 11 +- tsconfig.base.all.json | 157 +++++++++++++++++++++++++++ 2 files changed, 161 insertions(+), 7 deletions(-) create mode 100644 tsconfig.base.all.json diff --git a/apps/public-docsite-v9/tsconfig.json b/apps/public-docsite-v9/tsconfig.json index cc35ba4818249e..2f4dee1a95008e 100644 --- a/apps/public-docsite-v9/tsconfig.json +++ b/apps/public-docsite-v9/tsconfig.json @@ -1,21 +1,18 @@ { + "extends": "../../tsconfig.base.all.json", "compilerOptions": { - "target": "es5", + "module": "ESNext", + "target": "ES2019", "outDir": "lib", - "module": "commonjs", "jsx": "react", "declaration": true, "sourceMap": true, "noEmit": true, "experimentalDecorators": true, "noUnusedLocals": true, - "forceConsistentCasingInFileNames": true, "strictNullChecks": true, "noImplicitAny": true, - "moduleResolution": "node", - "preserveConstEnums": true, - "skipLibCheck": true, - "types": ["webpack-env", "@storybook/react"] + "types": ["webpack-env"] }, "include": ["src"] } diff --git a/tsconfig.base.all.json b/tsconfig.base.all.json new file mode 100644 index 00000000000000..7bfa9e5f99088c --- /dev/null +++ b/tsconfig.base.all.json @@ -0,0 +1,157 @@ +{ + "compilerOptions": { + "moduleResolution": "node", + "pretty": true, + "forceConsistentCasingInFileNames": true, + "skipLibCheck": true, + "typeRoots": ["node_modules/@types", "./typings"], + "isolatedModules": true, + "preserveConstEnums": true, + "rootDir": ".", + "baseUrl": ".", + "paths": { + "@fluentui/react-portal-compat-context": ["packages/react-components/react-portal-compat-context/src/index.ts"], + "@fluentui/a11y-testing": ["packages/a11y-testing/src/index.ts"], + "@fluentui/ability-attributes": ["packages/fluentui/ability-attributes/src/index.ts"], + "@fluentui/accessibility": ["packages/fluentui/accessibility/src/index.ts"], + "@fluentui/code-sandbox": ["packages/fluentui/code-sandbox/src/index.ts"], + "@fluentui/digest": ["packages/fluentui/digest/src/index.ts"], + "@fluentui/docs-components": ["packages/fluentui/docs-components/src/index.ts"], + "@fluentui/react-bindings": ["packages/fluentui/react-bindings/src/index.ts"], + "@fluentui/react-builder": ["packages/fluentui/react-builder/src/index.ts"], + "@fluentui/react-component-event-listener": ["packages/fluentui/react-component-event-listener/src/index.ts"], + "@fluentui/react-component-nesting-registry": ["packages/fluentui/react-component-nesting-registry/src/index.ts"], + "@fluentui/react-component-ref": ["packages/fluentui/react-component-ref/src/index.ts"], + "@fluentui/react-icons-northstar": ["packages/fluentui/react-icons-northstar/src/index.ts"], + "@fluentui/react-northstar": ["packages/fluentui/react-northstar/src/index.ts"], + "@fluentui/react-northstar-emotion-renderer": ["packages/fluentui/react-northstar-emotion-renderer/src/index.ts"], + "@fluentui/react-northstar-fela-renderer": ["packages/fluentui/react-northstar-fela-renderer/src/index.ts"], + "@fluentui/react-northstar-styles-renderer": ["packages/fluentui/react-northstar-styles-renderer/src/index.ts"], + "@fluentui/react-northstar-prototypes": ["packages/fluentui/react-northstar-prototypes/src/index.ts"], + "@fluentui/react-telemetry": ["packages/fluentui/react-telemetry/src/index.ts"], + "@fluentui/react-proptypes": ["packages/fluentui/react-proptypes/src/index.ts"], + "@fluentui/state": ["packages/fluentui/state/src/index.ts"], + "@fluentui/styles": ["packages/fluentui/styles/src/index.ts"], + "@fluentui/api-docs": ["packages/api-docs/src/index.ts"], + "@fluentui/azure-themes": ["packages/azure-themes/src/index.ts"], + "@fluentui/codemods": ["packages/codemods/src/index.ts"], + "@fluentui/date-time-utilities": ["packages/date-time-utilities/src/index.ts"], + "@fluentui/example-data": ["packages/example-data/src/index.ts"], + "@fluentui/fluent2-theme": ["packages/fluent2-theme/src/index.ts"], + "@fluentui/font-icons-mdl2": ["packages/font-icons-mdl2/src/index.ts"], + "@fluentui/foundation-legacy": ["packages/foundation-legacy/src/index.ts"], + "@fluentui/jest-serializer-merge-styles": ["packages/jest-serializer-merge-styles/src/index.ts"], + "@fluentui/merge-styles": ["packages/merge-styles/src/index.ts"], + "@fluentui/react": ["packages/react/src/index.ts"], + "@fluentui/react/lib/*": ["packages/react/src/*"], + "@fluentui/react-date-time": ["packages/react-date-time/src/index.ts"], + "@fluentui/react-experiments": ["packages/react-experiments/src/index.ts"], + "@fluentui/react-experiments/lib/*": ["packages/react-experiments/src/*"], + "@fluentui/react-file-type-icons": ["packages/react-file-type-icons/src/index.ts"], + "@fluentui/react-focus": ["packages/react-focus/src/index.ts"], + "@fluentui/react-hooks": ["packages/react-hooks/src/index.ts"], + "@fluentui/scheme-utilities": ["packages/scheme-utilities/src/index.ts"], + "@fluentui/set-version": ["packages/set-version/src/index.ts"], + "@fluentui/style-utilities": ["packages/style-utilities/src/index.ts"], + "@fluentui/test-utilities": ["packages/test-utilities/src/index.ts"], + "@fluentui/theme-samples": ["packages/theme-samples/src/index.ts"], + "@fluentui/utilities": ["packages/utilities/src/index.ts"], + "@fluentui/webpack-utilities": ["packages/utilities/src/index.ts"], + "@fluentui/dom-utilities": ["packages/dom-utilities/src/index.ts"], + "@fluentui/theme": ["packages/theme/src/index.ts"], + "@fluentui/react-cards": ["packages/react-cards/src/index.ts"], + "@fluentui/react-charting": ["packages/react-charting/src/index.ts"], + "@fluentui/react-window-provider": ["packages/react-window-provider/src/index.ts"], + "@fluentui/react-icons-mdl2": ["packages/react-icons-mdl2/src/index.ts"], + "@fluentui/react-icons-mdl2-branded": ["packages/react-icons-mdl2-branded/src/index.ts"], + "@fluentui/react-icon-provider": ["packages/react-icon-provider/src/index.ts"], + "@fluentui/react-examples": ["packages/react-examples/src/index.ts"], + "@fluentui/react-examples/lib/*": ["packages/react-examples/src/*"], + "@fluentui/public-docsite-setup": ["packages/public-docsite-setup/src/index.ts"], + "@fluentui/react-docsite-components": ["packages/react-docsite-components/src/index.ts"], + "@fluentui/react-docsite-components/lib/index2": ["packages/react-docsite-components/src/index2.ts"], + "@fluentui/monaco-editor": [ + "packages/monaco-editor/esm/vs/editor/editor.api.d.ts", + "packages/monaco-editor/src/monacoBundle.ts" + ], + "@fluentui/monaco-editor/esm/*": ["packages/monaco-editor/esm/"], + "@fluentui/monaco-editor/lib/*": ["packages/monaco-editor/src/*"], + "@fluentui/react-monaco-editor": ["packages/react-monaco-editor/src/index.ts"], + "@fluentui/storybook": ["packages/storybook/src/index.ts"], + "@fluentui/babel-preset-global-context": ["packages/react-components/babel-preset-global-context/src/index.ts"], + "@fluentui/babel-preset-storybook-full-source": [ + "packages/react-components/babel-preset-storybook-full-source/src/index.ts" + ], + "@fluentui/global-context": ["packages/react-components/global-context/src/index.ts"], + "@fluentui/keyboard-key": ["packages/keyboard-key/src/index.ts"], + "@fluentui/keyboard-keys": ["packages/react-components/keyboard-keys/src/index.ts"], + "@fluentui/priority-overflow": ["packages/react-components/priority-overflow/src/index.ts"], + "@fluentui/react-accordion": ["packages/react-components/react-accordion/src/index.ts"], + "@fluentui/react-alert": ["packages/react-components/react-alert/src/index.ts"], + "@fluentui/react-aria": ["packages/react-components/react-aria/src/index.ts"], + "@fluentui/react-avatar": ["packages/react-components/react-avatar/src/index.ts"], + "@fluentui/react-avatar-context": ["packages/react-components/react-avatar-context/src/index.ts"], + "@fluentui/react-badge": ["packages/react-components/react-badge/src/index.ts"], + "@fluentui/react-breadcrumb": ["packages/react-components/react-breadcrumb/src/index.ts"], + "@fluentui/react-button": ["packages/react-components/react-button/src/index.ts"], + "@fluentui/react-card": ["packages/react-components/react-card/src/index.ts"], + "@fluentui/react-checkbox": ["packages/react-components/react-checkbox/src/index.ts"], + "@fluentui/react-combobox": ["packages/react-components/react-combobox/src/index.ts"], + "@fluentui/react-components": ["packages/react-components/react-components/src/index.ts"], + "@fluentui/react-components/unstable": ["packages/react-components/react-components/src/unstable/index.ts"], + "@fluentui/react-conformance": ["packages/react-conformance/src/index.ts"], + "@fluentui/react-conformance-griffel": ["packages/react-components/react-conformance-griffel/src/index.ts"], + "@fluentui/react-context-selector": ["packages/react-components/react-context-selector/src/index.ts"], + "@fluentui/react-data-grid-react-window": ["packages/react-components/react-data-grid-react-window/src/index.ts"], + "@fluentui/react-datepicker-compat": ["packages/react-components/react-datepicker-compat/src/index.ts"], + "@fluentui/react-dialog": ["packages/react-components/react-dialog/src/index.ts"], + "@fluentui/react-divider": ["packages/react-components/react-divider/src/index.ts"], + "@fluentui/react-drawer": ["packages/react-components/react-drawer/src/index.ts"], + "@fluentui/react-field": ["packages/react-components/react-field/src/index.ts"], + "@fluentui/react-focus-management": ["packages/react-focus-management/src/index.ts"], + "@fluentui/react-image": ["packages/react-components/react-image/src/index.ts"], + "@fluentui/react-infobutton": ["packages/react-components/react-infobutton/src/index.ts"], + "@fluentui/react-input": ["packages/react-components/react-input/src/index.ts"], + "@fluentui/react-label": ["packages/react-components/react-label/src/index.ts"], + "@fluentui/react-link": ["packages/react-components/react-link/src/index.ts"], + "@fluentui/react-menu": ["packages/react-components/react-menu/src/index.ts"], + "@fluentui/react-migration-v0-v9": ["packages/react-components/react-migration-v0-v9/src/index.ts"], + "@fluentui/react-migration-v8-v9": ["packages/react-components/react-migration-v8-v9/src/index.ts"], + "@fluentui/react-overflow": ["packages/react-components/react-overflow/src/index.ts"], + "@fluentui/react-persona": ["packages/react-components/react-persona/src/index.ts"], + "@fluentui/react-popover": ["packages/react-components/react-popover/src/index.ts"], + "@fluentui/react-portal": ["packages/react-components/react-portal/src/index.ts"], + "@fluentui/react-portal-compat": ["packages/react-components/react-portal-compat/src/index.ts"], + "@fluentui/react-positioning": ["packages/react-components/react-positioning/src/index.ts"], + "@fluentui/react-progress": ["packages/react-components/react-progress/src/index.ts"], + "@fluentui/react-provider": ["packages/react-components/react-provider/src/index.ts"], + "@fluentui/react-radio": ["packages/react-components/react-radio/src/index.ts"], + "@fluentui/react-select": ["packages/react-components/react-select/src/index.ts"], + "@fluentui/react-shared-contexts": ["packages/react-components/react-shared-contexts/src/index.ts"], + "@fluentui/react-skeleton": ["packages/react-components/react-skeleton/src/index.ts"], + "@fluentui/react-slider": ["packages/react-components/react-slider/src/index.ts"], + "@fluentui/react-spinbutton": ["packages/react-components/react-spinbutton/src/index.ts"], + "@fluentui/react-spinner": ["packages/react-components/react-spinner/src/index.ts"], + "@fluentui/react-storybook-addon": ["packages/react-components/react-storybook-addon/src/index.ts"], + "@fluentui/react-storybook-addon-codesandbox": [ + "packages/react-components/react-storybook-addon-codesandbox/src/index.ts" + ], + "@fluentui/react-switch": ["packages/react-components/react-switch/src/index.ts"], + "@fluentui/react-table": ["packages/react-components/react-table/src/index.ts"], + "@fluentui/react-tabs": ["packages/react-components/react-tabs/src/index.ts"], + "@fluentui/react-tabster": ["packages/react-components/react-tabster/src/index.ts"], + "@fluentui/react-tags": ["packages/react-components/react-tags/src/index.ts"], + "@fluentui/react-text": ["packages/react-components/react-text/src/index.ts"], + "@fluentui/react-textarea": ["packages/react-components/react-textarea/src/index.ts"], + "@fluentui/react-theme": ["packages/react-components/react-theme/src/index.ts"], + "@fluentui/react-theme-sass": ["packages/react-components/react-theme-sass/src/index.ts"], + "@fluentui/react-toolbar": ["packages/react-components/react-toolbar/src/index.ts"], + "@fluentui/react-tooltip": ["packages/react-components/react-tooltip/src/index.ts"], + "@fluentui/react-tree": ["packages/react-components/react-tree/src/index.ts"], + "@fluentui/react-utilities": ["packages/react-components/react-utilities/src/index.ts"], + "@fluentui/react-virtualizer": ["packages/react-components/react-virtualizer/src/index.ts"], + "@fluentui/theme-designer": ["packages/react-components/theme-designer/src/index.ts"], + "@fluentui/tokens": ["packages/tokens/src/index.ts"] + } + } +} From 3acdb8010b70fe4088c25c74e0960ebae8aeed2d Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Tue, 7 Feb 2023 15:33:16 +0100 Subject: [PATCH 03/19] chore(public-docsite-v9): migrate to solution config and type-check .storybook as well --- apps/public-docsite-v9/.storybook/fix-title.js | 5 +++++ apps/public-docsite-v9/.storybook/main.js | 13 +++---------- apps/public-docsite-v9/.storybook/preview.js | 4 +++- apps/public-docsite-v9/.storybook/theme.js | 1 + apps/public-docsite-v9/.storybook/tsconfig.json | 9 +++++++++ apps/public-docsite-v9/tsconfig.app.json | 13 +++++++++++++ apps/public-docsite-v9/tsconfig.json | 15 ++++++++++----- 7 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 apps/public-docsite-v9/.storybook/tsconfig.json create mode 100644 apps/public-docsite-v9/tsconfig.app.json diff --git a/apps/public-docsite-v9/.storybook/fix-title.js b/apps/public-docsite-v9/.storybook/fix-title.js index 2bd55cf8cb82b1..3f72f01ea672c5 100644 --- a/apps/public-docsite-v9/.storybook/fix-title.js +++ b/apps/public-docsite-v9/.storybook/fix-title.js @@ -1,6 +1,11 @@ const fs = require('fs'); const path = require('path'); +/** + * + * @param {string} filePath + * @param {string} title + */ function fixTitle(filePath, title) { const htmlDocumentPath = path.resolve(__dirname, filePath); const htmlDocument = fs.readFileSync(htmlDocumentPath, 'utf-8'); diff --git a/apps/public-docsite-v9/.storybook/main.js b/apps/public-docsite-v9/.storybook/main.js index 01f295d0ccc576..a57e9a915e54d5 100644 --- a/apps/public-docsite-v9/.storybook/main.js +++ b/apps/public-docsite-v9/.storybook/main.js @@ -1,16 +1,9 @@ -// @ts-check - -const { - getPackageStoriesGlob, - createPathAliasesConfig, - registerTsPaths, - rules, - registerRules, -} = require('@fluentui/scripts-storybook'); +const path = require('path'); +const { getPackageStoriesGlob, registerTsPaths, rules, registerRules } = require('@fluentui/scripts-storybook'); const rootMain = require('../../../.storybook/main'); -const { tsConfigAllPath } = createPathAliasesConfig(); +const tsConfigAllPath = path.join(__dirname, '../../../tsconfig.base.all.json'); module.exports = /** @type {Omit} */ ({ ...rootMain, diff --git a/apps/public-docsite-v9/.storybook/preview.js b/apps/public-docsite-v9/.storybook/preview.js index ebe4c1cf402845..1963954c0e0d4f 100644 --- a/apps/public-docsite-v9/.storybook/preview.js +++ b/apps/public-docsite-v9/.storybook/preview.js @@ -1,6 +1,8 @@ +import * as rootPreview from '../../../.storybook/preview'; + import { FluentDocsContainer } from '../src/DocsComponents/FluentDocsContainer.stories'; import { FluentDocsPage } from '../src/DocsComponents/FluentDocsPage.stories'; -import * as rootPreview from '../../../.storybook/preview'; + import './docs-root-v9.css'; /** @type {NonNullable} */ diff --git a/apps/public-docsite-v9/.storybook/theme.js b/apps/public-docsite-v9/.storybook/theme.js index bd13f4a67625fa..269f6d7244393a 100644 --- a/apps/public-docsite-v9/.storybook/theme.js +++ b/apps/public-docsite-v9/.storybook/theme.js @@ -1,4 +1,5 @@ import { create } from '@storybook/theming'; + import logo from '../public/fluentui-logo.svg'; /** diff --git a/apps/public-docsite-v9/.storybook/tsconfig.json b/apps/public-docsite-v9/.storybook/tsconfig.json new file mode 100644 index 00000000000000..663aae308c427c --- /dev/null +++ b/apps/public-docsite-v9/.storybook/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "allowJs": true, + "checkJs": true, + "types": ["node", "static-assets", "storybook__addons"] + }, + "include": ["*.js"] +} diff --git a/apps/public-docsite-v9/tsconfig.app.json b/apps/public-docsite-v9/tsconfig.app.json new file mode 100644 index 00000000000000..ef06ccd867c65b --- /dev/null +++ b/apps/public-docsite-v9/tsconfig.app.json @@ -0,0 +1,13 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "ESNext", + "target": "ES2019", + "noEmit": false, + "outDir": "lib", + "jsx": "react", + "sourceMap": true, + "types": ["webpack-env"] + }, + "include": ["src"] +} diff --git a/apps/public-docsite-v9/tsconfig.json b/apps/public-docsite-v9/tsconfig.json index 2f4dee1a95008e..215391a01f5626 100644 --- a/apps/public-docsite-v9/tsconfig.json +++ b/apps/public-docsite-v9/tsconfig.json @@ -3,10 +3,6 @@ "compilerOptions": { "module": "ESNext", "target": "ES2019", - "outDir": "lib", - "jsx": "react", - "declaration": true, - "sourceMap": true, "noEmit": true, "experimentalDecorators": true, "noUnusedLocals": true, @@ -14,5 +10,14 @@ "noImplicitAny": true, "types": ["webpack-env"] }, - "include": ["src"] + "include": [], + "files": [], + "references": [ + { + "path": "./tsconfig.app.json" + }, + { + "path": "./.storybook/tsconfig.json" + } + ] } From 0b59fcfc88098d86d627b9a56e2242601f27ee51 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Tue, 7 Feb 2023 16:30:21 +0100 Subject: [PATCH 04/19] chore(react-migration-v8-v9): enable cross project TS path aliases for improved DX --- .../react-migration-v8-v9/package.json | 2 +- .../react-migration-v8-v9/tsconfig.json | 3 ++- .../tsconfig.type-check.json | 19 +++++++++++++++++++ tsconfig.base.all.json | 1 + 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 packages/react-components/react-migration-v8-v9/tsconfig.type-check.json diff --git a/packages/react-components/react-migration-v8-v9/package.json b/packages/react-components/react-migration-v8-v9/package.json index be85c40f3eb226..004629cb5afe01 100644 --- a/packages/react-components/react-migration-v8-v9/package.json +++ b/packages/react-components/react-migration-v8-v9/package.json @@ -18,7 +18,7 @@ "just": "just-scripts", "lint": "just-scripts lint", "test": "jest --passWithNoTests", - "type-check": "tsc -b tsconfig.json", + "type-check": "tsc -b tsconfig.type-check.json", "generate-api": "just-scripts generate-api", "storybook": "start-storybook", "start": "yarn storybook" diff --git a/packages/react-components/react-migration-v8-v9/tsconfig.json b/packages/react-components/react-migration-v8-v9/tsconfig.json index 1941a041d46c19..cb0beb41b1488d 100644 --- a/packages/react-components/react-migration-v8-v9/tsconfig.json +++ b/packages/react-components/react-migration-v8-v9/tsconfig.json @@ -1,6 +1,7 @@ { - "extends": "../../../tsconfig.base.json", + "extends": "../../../tsconfig.base.all.json", "compilerOptions": { + "strict": true, "target": "ES2019", "noEmit": true, "isolatedModules": true, diff --git a/packages/react-components/react-migration-v8-v9/tsconfig.type-check.json b/packages/react-components/react-migration-v8-v9/tsconfig.type-check.json new file mode 100644 index 00000000000000..fde4d991642ae9 --- /dev/null +++ b/packages/react-components/react-migration-v8-v9/tsconfig.type-check.json @@ -0,0 +1,19 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "paths": {} + }, + "include": [], + "files": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + }, + { + "path": "./.storybook/tsconfig.json" + } + ] +} diff --git a/tsconfig.base.all.json b/tsconfig.base.all.json index 7bfa9e5f99088c..63cdeedcbc9646 100644 --- a/tsconfig.base.all.json +++ b/tsconfig.base.all.json @@ -7,6 +7,7 @@ "typeRoots": ["node_modules/@types", "./typings"], "isolatedModules": true, "preserveConstEnums": true, + "sourceMap": true, "rootDir": ".", "baseUrl": ".", "paths": { From c27faccc5ad2736d9f94cf04ac088f4472a2ab84 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Tue, 7 Feb 2023 16:36:26 +0100 Subject: [PATCH 05/19] chore(react-migration-v0-v9): enable cross project TS path aliases for improved DX --- .../react-migration-v0-v9/package.json | 2 +- .../components/FormField/FormFieldShim.tsx | 3 ++- .../react-migration-v0-v9/tsconfig.json | 3 ++- .../tsconfig.type-check.json | 19 +++++++++++++++++++ 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 packages/react-components/react-migration-v0-v9/tsconfig.type-check.json diff --git a/packages/react-components/react-migration-v0-v9/package.json b/packages/react-components/react-migration-v0-v9/package.json index 518f647a8d05b8..7a68f39260527b 100644 --- a/packages/react-components/react-migration-v0-v9/package.json +++ b/packages/react-components/react-migration-v0-v9/package.json @@ -19,7 +19,7 @@ "just": "just-scripts", "lint": "just-scripts lint", "test": "jest --passWithNoTests", - "type-check": "tsc -b tsconfig.json", + "type-check": "tsc -b tsconfig.type-check.json", "generate-api": "just-scripts generate-api", "storybook": "start-storybook", "start": "yarn storybook" diff --git a/packages/react-components/react-migration-v0-v9/src/components/FormField/FormFieldShim.tsx b/packages/react-components/react-migration-v0-v9/src/components/FormField/FormFieldShim.tsx index 76ccfdf5318165..165e0537e2252e 100644 --- a/packages/react-components/react-migration-v0-v9/src/components/FormField/FormFieldShim.tsx +++ b/packages/react-components/react-migration-v0-v9/src/components/FormField/FormFieldShim.tsx @@ -5,7 +5,8 @@ import { useFieldStyles_unstable, useField_unstable, } from '@fluentui/react-components'; -import { ObjectShorthandValue } from '@fluentui/react-northstar'; +import type { ObjectShorthandValue } from '@fluentui/react-northstar'; + import * as React from 'react'; type WithContent = ObjectShorthandValue> | string; diff --git a/packages/react-components/react-migration-v0-v9/tsconfig.json b/packages/react-components/react-migration-v0-v9/tsconfig.json index 1941a041d46c19..cb0beb41b1488d 100644 --- a/packages/react-components/react-migration-v0-v9/tsconfig.json +++ b/packages/react-components/react-migration-v0-v9/tsconfig.json @@ -1,6 +1,7 @@ { - "extends": "../../../tsconfig.base.json", + "extends": "../../../tsconfig.base.all.json", "compilerOptions": { + "strict": true, "target": "ES2019", "noEmit": true, "isolatedModules": true, diff --git a/packages/react-components/react-migration-v0-v9/tsconfig.type-check.json b/packages/react-components/react-migration-v0-v9/tsconfig.type-check.json new file mode 100644 index 00000000000000..fde4d991642ae9 --- /dev/null +++ b/packages/react-components/react-migration-v0-v9/tsconfig.type-check.json @@ -0,0 +1,19 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "paths": {} + }, + "include": [], + "files": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + }, + { + "path": "./.storybook/tsconfig.json" + } + ] +} From 9bd7a3087bc68541f6d272f3a80c357e29f77b48 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Tue, 7 Feb 2023 15:37:34 +0100 Subject: [PATCH 06/19] feat(scripts-tasks): enable ts processing on projects with path aliases used only for DX --- scripts/tasks/src/ts.ts | 10 +++++----- scripts/tasks/src/utils.ts | 19 ++++++++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/scripts/tasks/src/ts.ts b/scripts/tasks/src/ts.ts index 1d7e99665ff3b0..63e432839fffbc 100644 --- a/scripts/tasks/src/ts.ts +++ b/scripts/tasks/src/ts.ts @@ -3,7 +3,7 @@ import * as path from 'path'; import { TscTaskOptions, logger, tscTask } from 'just-scripts'; import { getJustArgv } from './argv'; -import { getTsPathAliasesConfig, getTsPathAliasesConfigV8 } from './utils'; +import { getTsPathAliasesConfig, getTsPathAliasesConfigUsedOnlyForDx } from './utils'; const libPath = path.resolve(process.cwd(), 'lib'); const srcPath = path.resolve(process.cwd(), 'src'); @@ -24,13 +24,13 @@ function prepareTsTaskConfig(options: TscTaskOptions) { options.sourceMap = true; } - const { isUsingV8pathAliases, tsConfigFileV8 } = getTsPathAliasesConfigV8(); + const { isUsingPathAliasesForDx, tsConfigFileForCompilation } = getTsPathAliasesConfigUsedOnlyForDx(); - if (isUsingV8pathAliases) { - logger.info(`📣 TSC: V8 package is using TS path aliases. Overriding tsconfig settings.`); + if (isUsingPathAliasesForDx) { + logger.info(`📣 TSC: Project is using TS path aliases for DX. Disabling aliases for build.`); options.baseUrl = '.'; options.rootDir = './src'; - options.project = tsConfigFileV8; + options.project = tsConfigFileForCompilation; } const { isUsingTsSolutionConfigs, tsConfigFile, tsConfig } = getTsPathAliasesConfig(); diff --git a/scripts/tasks/src/utils.ts b/scripts/tasks/src/utils.ts index a46babceaff712..e1d14628cb5da9 100644 --- a/scripts/tasks/src/utils.ts +++ b/scripts/tasks/src/utils.ts @@ -19,13 +19,22 @@ export function getTsPathAliasesConfig() { return { tsConfig, isUsingTsSolutionConfigs, tsConfigFile, tsConfigPath, packageJson }; } -export function getTsPathAliasesConfigV8() { +export function getTsPathAliasesConfigUsedOnlyForDx() { + const tsConfigFilesWithAliases = ['tsconfig.app.json', 'tsconfig.lib.json', 'tsconfig.json']; + const tsConfigBaseFilesForDx = ['tsconfig.base.v8.json', 'tsconfig.base.all.json']; const cwd = process.cwd(); - const tsConfigFile = 'tsconfig.json'; - const tsConfigPath = path.join(cwd, `./${tsConfigFile}`); + const tsConfigPath = path.join(cwd, `./tsconfig.json`); const tsConfig = JSON.parse(stripJsonComments(fs.readFileSync(tsConfigPath, 'utf-8'))); - const isUsingV8pathAliases = tsConfig.extends && tsConfig.extends.includes('tsconfig.base.v8.json'); - return { isUsingV8pathAliases, tsConfigFileV8: tsConfigFile }; + const isUsingPathAliasesForDx = + tsConfig.extends && tsConfigBaseFilesForDx.some(relativeFilePath => tsConfig.extends.endsWith(relativeFilePath)); + + const tsConfigFileForCompilation = tsConfigFilesWithAliases.find(fileName => fs.existsSync(path.join(cwd, fileName))); + + if (!tsConfigFileForCompilation) { + throw new Error(`no tsconfig from ${tsConfigFilesWithAliases} found!`); + } + + return { isUsingPathAliasesForDx, tsConfigFileForCompilation }; } const packagesWithInvalidTypes = [ From 48e8bb74407655e325046bd6408a49ef9b4478ba Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Tue, 7 Feb 2023 15:33:56 +0100 Subject: [PATCH 07/19] fix(typings): make transformSource optional in sb addons type extensions --- typings/storybook__addons/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/storybook__addons/index.d.ts b/typings/storybook__addons/index.d.ts index 7f4a5b1f7abd2d..3f37163394817a 100644 --- a/typings/storybook__addons/index.d.ts +++ b/typings/storybook__addons/index.d.ts @@ -47,7 +47,7 @@ declare module '@storybook/addons' { * Allows to override code that will be used for "Show Code" tab. * @see https://github.com/storybookjs/storybook/blob/main/addons/docs/docs/recipes.md#customizing-source-snippets */ - transformSource: (snippet: string, story: StoryContextForEnhancers) => string | undefined; + transformSource?: (snippet: string, story: StoryContextForEnhancers) => string | undefined; container?: React.ComponentType; page?: React.ComponentType; From 142453bac8e39368698098925fc001c8bb7d1d1e Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Wed, 5 Apr 2023 15:08:07 +0200 Subject: [PATCH 08/19] chore: use tsconfig.base.all.json directly for TS path webpack plugin instead of createPathAliasesConfig() --- apps/stress-test/webpack/webpack.config.ts | 4 ++-- .../react-migration-v0-v9/.storybook/main.js | 6 ++++-- .../react-migration-v8-v9/.storybook/main.js | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/stress-test/webpack/webpack.config.ts b/apps/stress-test/webpack/webpack.config.ts index e2ff29043c58b9..b3a42e043ce9bc 100644 --- a/apps/stress-test/webpack/webpack.config.ts +++ b/apps/stress-test/webpack/webpack.config.ts @@ -2,7 +2,7 @@ import * as path from 'path'; import { fileURLToPath } from 'url'; import { CleanWebpackPlugin } from 'clean-webpack-plugin'; // eslint-disable-next-line import/no-extraneous-dependencies -import { registerTsPaths, createPathAliasesConfig, rules } from '@fluentui/scripts-storybook'; +import { registerTsPaths, rules } from '@fluentui/scripts-storybook'; import { configurePages } from './pageConfig.js'; import { configureGriffel } from './griffelConfig.js'; import * as WebpackDevServer from 'webpack-dev-server'; @@ -12,7 +12,7 @@ const enabledReactProfiling = true; const __dirname = path.dirname(fileURLToPath(import.meta.url)); -const { tsConfigAllPath } = createPathAliasesConfig(); +const tsConfigAllPath = path.join(__dirname, '../../../tsconfig.base.all.json'); type WebpackArgs = { mode: 'production' | 'development' | 'none'; diff --git a/packages/react-components/react-migration-v0-v9/.storybook/main.js b/packages/react-components/react-migration-v0-v9/.storybook/main.js index 15a002e45f8ce0..3679d73941ae18 100644 --- a/packages/react-components/react-migration-v0-v9/.storybook/main.js +++ b/packages/react-components/react-migration-v0-v9/.storybook/main.js @@ -1,7 +1,9 @@ -const { registerTsPaths, createPathAliasesConfig } = require('@fluentui/scripts-storybook'); +const path = require('path'); +const { registerTsPaths } = require('@fluentui/scripts-storybook'); + const rootMain = require('../../../../.storybook/main'); -const { tsConfigAllPath } = createPathAliasesConfig(); +const tsConfigAllPath = path.join(__dirname, '../../../../tsconfig.base.all.json'); module.exports = /** @type {Omit} */ ({ ...rootMain, diff --git a/packages/react-components/react-migration-v8-v9/.storybook/main.js b/packages/react-components/react-migration-v8-v9/.storybook/main.js index 41673434a97056..cbbdca67753d11 100644 --- a/packages/react-components/react-migration-v8-v9/.storybook/main.js +++ b/packages/react-components/react-migration-v8-v9/.storybook/main.js @@ -1,7 +1,9 @@ -const { registerTsPaths, createPathAliasesConfig, registerRules, rules } = require('@fluentui/scripts-storybook'); +const path = require('path'); +const { registerTsPaths, registerRules, rules } = require('@fluentui/scripts-storybook'); + const rootMain = require('../../../../.storybook/main'); -const { tsConfigAllPath } = createPathAliasesConfig(); +const tsConfigAllPath = path.join(__dirname, '../../../../tsconfig.base.all.json'); module.exports = /** @type {Omit} */ ({ ...rootMain, From 0cfba4dccfc9944b2337167acfab84a285b61377 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Wed, 5 Apr 2023 15:09:17 +0200 Subject: [PATCH 09/19] feat(scripts-storybook): make createPathAliasesConfigconfigurable and return resulted merge as well --- scripts/storybook/src/utils.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/scripts/storybook/src/utils.js b/scripts/storybook/src/utils.js index d4405b483335f2..2172b103a3244d 100644 --- a/scripts/storybook/src/utils.js +++ b/scripts/storybook/src/utils.js @@ -358,16 +358,27 @@ function overrideDefaultBabelLoader(options) { * Create tsconfig.json with merged "compilerOptions.paths" from v0,v8,v9 tsconfigs. * * Main purpose of this is to be used for build-less DX in webpack in tandem with {@link registerTsPaths} - * @returns + * + * @param {{relativeFolderPathFromRoot?:string}} options */ -function createPathAliasesConfig() { - const { tsConfigAllPath } = createMergedTsConfig(); - return { tsConfigAllPath }; +function createPathAliasesConfig(options = {}) { + const rootPath = workspaceRoot; + const { relativeFolderPathFromRoot = './dist' } = options; + const mergedTsConfig = createMergedTsConfig({ rootPath }); + const tsConfigAllPath = path.join(rootPath, relativeFolderPathFromRoot, 'tsconfig.base.all.json'); + + writeJsonFile(tsConfigAllPath, mergedTsConfig); + + return { tsConfigAllPath, mergedTsConfig }; } -function createMergedTsConfig() { - const rootPath = workspaceRoot; - const tsConfigAllPath = path.join(rootPath, 'dist/tsconfig.base.all.json'); +/** + * + * @param {{rootPath:string}} options + * @returns + */ +function createMergedTsConfig(options) { + const { rootPath } = options; const baseConfigs = { v0: readJsonFile(path.join(rootPath, 'tsconfig.base.v0.json')), v8: readJsonFile(path.join(rootPath, 'tsconfig.base.v8.json')), @@ -387,9 +398,7 @@ function createMergedTsConfig() { }, }; - writeJsonFile(tsConfigAllPath, mergedTsConfig); - - return { tsConfigAllPath, mergedTsConfig }; + return mergedTsConfig; } exports.getPackageStoriesGlob = getPackageStoriesGlob; From 900317a439a87e2cce6605f70ec98f135d7f1d00 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Wed, 5 Apr 2023 15:11:08 +0200 Subject: [PATCH 10/19] feat(scripts-generators): update tsconfig.base.all.json after creating new package --- scripts/generators/create-package/index.ts | 17 ++++++++++------- scripts/generators/package.json | 1 + 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/scripts/generators/create-package/index.ts b/scripts/generators/create-package/index.ts index 7a5de4a1cd02b2..528b0b2d261951 100644 --- a/scripts/generators/create-package/index.ts +++ b/scripts/generators/create-package/index.ts @@ -1,14 +1,15 @@ -import { NodePlopAPI, AddManyActionConfig } from 'plop'; -import { Actions } from 'node-plop'; +import { spawnSync } from 'child_process'; import * as path from 'path'; + +import { PackageJson, findGitRoot } from '@fluentui/scripts-monorepo'; +import { createPathAliasesConfig } from '@fluentui/scripts-storybook'; +import { WorkspaceJsonConfiguration } from '@nrwl/devkit'; +import chalk from 'chalk'; import * as fs from 'fs-extra'; import * as jju from 'jju'; import _ from 'lodash'; -import chalk from 'chalk'; -import { spawnSync } from 'child_process'; -import { WorkspaceJsonConfiguration } from '@nrwl/devkit'; - -import { findGitRoot, PackageJson } from '@fluentui/scripts-monorepo'; +import { Actions } from 'node-plop'; +import { AddManyActionConfig, NodePlopAPI } from 'plop'; const root = findGitRoot(); @@ -301,6 +302,8 @@ function updateNxWorkspace(_answers: Answers, config: { root: string; projectNam const updatedNxWorkspace = jju.update(nxWorkspaceContent, nxWorkspace, { mode: 'json', indent: 2 }); fs.writeFileSync(paths.workspace, updatedNxWorkspace, 'utf-8'); + + createPathAliasesConfig({ relativeFolderPathFromRoot: '.' }); } function getProjectMetadata(options: { root: string; name: string }) { diff --git a/scripts/generators/package.json b/scripts/generators/package.json index d49423bff685b8..1b9f35f0833864 100644 --- a/scripts/generators/package.json +++ b/scripts/generators/package.json @@ -12,6 +12,7 @@ }, "dependencies": { "@fluentui/scripts-monorepo": "*", + "@fluentui/scripts-storybook": "*", "@fluentui/scripts-projects-test": "*" } } From d2f259fb14a12f9c0b4a3d00990e840ae192c38e Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Thu, 6 Apr 2023 11:02:14 +0200 Subject: [PATCH 11/19] feat(scripts-generators): incorporate base all generation to create-package and validate integrity on CI --- azure-pipelines.yml | 4 ++ scripts/generators/create-package/index.ts | 7 ++-- .../generators/generate-ts-base-all-json.ts | 33 +++++++++++++++++ scripts/storybook/src/utils.js | 37 ++++++++++--------- tsconfig.base.all.json | 2 +- 5 files changed, 61 insertions(+), 22 deletions(-) create mode 100644 scripts/generators/generate-ts-base-all-json.ts diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3a4a437264cd75..ad0c75d11cdc80 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -41,6 +41,10 @@ jobs: yarn tsc -p ./tsconfig.json displayName: Type-check just.config.ts files + - script: | + yarn ts-node --swc scripts/generators/generate-ts-base-all-json.ts --verify + displayName: Check tsconfig.base.all.json integrity + - script: | yarn check:installed-dependencies-versions displayName: 'check packages: installed dependencies versions' diff --git a/scripts/generators/create-package/index.ts b/scripts/generators/create-package/index.ts index 528b0b2d261951..325ea736e155e8 100644 --- a/scripts/generators/create-package/index.ts +++ b/scripts/generators/create-package/index.ts @@ -2,7 +2,6 @@ import { spawnSync } from 'child_process'; import * as path from 'path'; import { PackageJson, findGitRoot } from '@fluentui/scripts-monorepo'; -import { createPathAliasesConfig } from '@fluentui/scripts-storybook'; import { WorkspaceJsonConfiguration } from '@nrwl/devkit'; import chalk from 'chalk'; import * as fs from 'fs-extra'; @@ -11,6 +10,8 @@ import _ from 'lodash'; import { Actions } from 'node-plop'; import { AddManyActionConfig, NodePlopAPI } from 'plop'; +import { main as generateTsBaseAllJson } from '../generate-ts-base-all-json'; + const root = findGitRoot(); const v8ReferencePackages = { @@ -161,6 +162,8 @@ module.exports = (plop: NodePlopAPI) => { if (migrateResult.status !== 0) { throw new Error('Something went wrong running the migration. Please check previous logs for details.'); } + + generateTsBaseAllJson(); return 'Successfully migrated package'; }, () => { @@ -302,8 +305,6 @@ function updateNxWorkspace(_answers: Answers, config: { root: string; projectNam const updatedNxWorkspace = jju.update(nxWorkspaceContent, nxWorkspace, { mode: 'json', indent: 2 }); fs.writeFileSync(paths.workspace, updatedNxWorkspace, 'utf-8'); - - createPathAliasesConfig({ relativeFolderPathFromRoot: '.' }); } function getProjectMetadata(options: { root: string; name: string }) { diff --git a/scripts/generators/generate-ts-base-all-json.ts b/scripts/generators/generate-ts-base-all-json.ts new file mode 100644 index 00000000000000..f4889b9b6b7830 --- /dev/null +++ b/scripts/generators/generate-ts-base-all-json.ts @@ -0,0 +1,33 @@ +import { createPathAliasesConfig } from '@fluentui/scripts-storybook'; +import { isEqual } from 'lodash'; +import * as yargs from 'yargs'; + +const isExecutedFromCli = require.main === module; + +if (isExecutedFromCli) { + const argv = yargs + .option('verify', { + describe: 'Run check if ts base all is up to date. Used mostly on CI', + type: 'boolean', + }) + .help().argv; + + main(argv); +} + +export function main(options?: yargs.Arguments<{ verify?: boolean }>) { + const { verify = false } = options ?? {}; + + const { mergedTsConfig, existingTsConfig, tsConfigAllFileName } = createPathAliasesConfig({ + relativeFolderPathFromRoot: '.', + writeFileToDisk: verify === false, + }); + + if (verify && !isEqual(existingTsConfig, mergedTsConfig)) { + throw new Error(` + 🚨 ${tsConfigAllFileName} is out of date. + + Please update it by running 'yarn ts-node --swc scripts/generators/generate-ts-base-all-json.ts'. + `); + } +} diff --git a/scripts/storybook/src/utils.js b/scripts/storybook/src/utils.js index 2172b103a3244d..f662abb60c046a 100644 --- a/scripts/storybook/src/utils.js +++ b/scripts/storybook/src/utils.js @@ -359,37 +359,34 @@ function overrideDefaultBabelLoader(options) { * * Main purpose of this is to be used for build-less DX in webpack in tandem with {@link registerTsPaths} * - * @param {{relativeFolderPathFromRoot?:string}} options + * @param {{relativeFolderPathFromRoot?:string,writeFileToDisk?:boolean}} options */ function createPathAliasesConfig(options = {}) { + const { relativeFolderPathFromRoot = './dist', writeFileToDisk = true } = options; const rootPath = workspaceRoot; - const { relativeFolderPathFromRoot = './dist' } = options; - const mergedTsConfig = createMergedTsConfig({ rootPath }); - const tsConfigAllPath = path.join(rootPath, relativeFolderPathFromRoot, 'tsconfig.base.all.json'); + const mergedTsConfigRoot = path.join(rootPath, relativeFolderPathFromRoot); + const tsConfigAllFileName = 'tsconfig.base.all.json'; + const tsConfigAllPath = path.join(mergedTsConfigRoot, tsConfigAllFileName); + const existingTsConfig = readJsonFile(tsConfigAllPath); - writeJsonFile(tsConfigAllPath, mergedTsConfig); - - return { tsConfigAllPath, mergedTsConfig }; -} - -/** - * - * @param {{rootPath:string}} options - * @returns - */ -function createMergedTsConfig(options) { - const { rootPath } = options; const baseConfigs = { v0: readJsonFile(path.join(rootPath, 'tsconfig.base.v0.json')), v8: readJsonFile(path.join(rootPath, 'tsconfig.base.v8.json')), v9: readJsonFile(path.join(rootPath, 'tsconfig.base.json')), }; + const tsConfigBase = rootPath === mergedTsConfigRoot ? '.' : rootPath; const mergedTsConfig = { compilerOptions: { moduleResolution: 'node', forceConsistentCasingInFileNames: true, skipLibCheck: true, - baseUrl: workspaceRoot, + typeRoots: ['node_modules/@types', './typings'], + isolatedModules: true, + preserveConstEnums: true, + sourceMap: true, + pretty: true, + rootDir: tsConfigBase, + baseUrl: tsConfigBase, paths: { ...baseConfigs.v0.compilerOptions.paths, ...baseConfigs.v8.compilerOptions.paths, @@ -398,7 +395,11 @@ function createMergedTsConfig(options) { }, }; - return mergedTsConfig; + if (writeFileToDisk) { + writeJsonFile(tsConfigAllPath, mergedTsConfig); + } + + return { tsConfigAllPath, tsConfigAllFileName, mergedTsConfig, existingTsConfig }; } exports.getPackageStoriesGlob = getPackageStoriesGlob; diff --git a/tsconfig.base.all.json b/tsconfig.base.all.json index 63cdeedcbc9646..1c35f1fc489abc 100644 --- a/tsconfig.base.all.json +++ b/tsconfig.base.all.json @@ -1,13 +1,13 @@ { "compilerOptions": { "moduleResolution": "node", - "pretty": true, "forceConsistentCasingInFileNames": true, "skipLibCheck": true, "typeRoots": ["node_modules/@types", "./typings"], "isolatedModules": true, "preserveConstEnums": true, "sourceMap": true, + "pretty": true, "rootDir": ".", "baseUrl": ".", "paths": { From 10edceae45ba6f7a39bce72a7cbb90105b5f502e Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Tue, 11 Apr 2023 11:58:35 +0200 Subject: [PATCH 12/19] chore: update tsconfig.base.all after rebase --- tsconfig.base.all.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tsconfig.base.all.json b/tsconfig.base.all.json index 1c35f1fc489abc..bcafada30120c9 100644 --- a/tsconfig.base.all.json +++ b/tsconfig.base.all.json @@ -113,6 +113,7 @@ "@fluentui/react-image": ["packages/react-components/react-image/src/index.ts"], "@fluentui/react-infobutton": ["packages/react-components/react-infobutton/src/index.ts"], "@fluentui/react-input": ["packages/react-components/react-input/src/index.ts"], + "@fluentui/react-jsx-runtime": ["packages/react-components/react-jsx-runtime/src/index.ts"], "@fluentui/react-label": ["packages/react-components/react-label/src/index.ts"], "@fluentui/react-link": ["packages/react-components/react-link/src/index.ts"], "@fluentui/react-menu": ["packages/react-components/react-menu/src/index.ts"], From 6c773b87d114eddebcbb7d5b69923af33114c08b Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Tue, 11 Apr 2023 16:52:03 +0200 Subject: [PATCH 13/19] feat(scripts-tasks): implement type-check alias, update generate-api, refactor getTsPathAliasesConfig --- scripts/tasks/src/api-extractor.ts | 6 +-- scripts/tasks/src/copy.ts | 11 +++-- scripts/tasks/src/generate-api.ts | 19 +++++--- scripts/tasks/src/presets.ts | 2 + scripts/tasks/src/ts.ts | 10 +++-- scripts/tasks/src/type-check.ts | 43 +++++++++++++++++++ scripts/tasks/src/utils.ts | 69 +++++++++++++++++++++++++----- 7 files changed, 133 insertions(+), 27 deletions(-) create mode 100644 scripts/tasks/src/type-check.ts diff --git a/scripts/tasks/src/api-extractor.ts b/scripts/tasks/src/api-extractor.ts index 336ad6667301c4..96c8cc8b6cf38f 100644 --- a/scripts/tasks/src/api-extractor.ts +++ b/scripts/tasks/src/api-extractor.ts @@ -57,7 +57,7 @@ export function apiExtractor(): TaskFunction { }; const args: ReturnType & Partial = getJustArgv(); - const { isUsingTsSolutionConfigs, packageJson, tsConfig } = getTsPathAliasesConfig(); + const { isUsingTsSolutionConfigs, packageJson, tsConfigs } = getTsPathAliasesConfig(); if (configsToExecute.length === 0) { return noop; @@ -102,14 +102,14 @@ export function apiExtractor(): TaskFunction { } function onConfigLoaded(config: Parameters>[0]) { - if (!(isUsingTsSolutionConfigs && tsConfig)) { + if (!(isUsingTsSolutionConfigs && tsConfigs.lib)) { return; } logger.info(`api-extractor: package is using TS path aliases. Overriding TS compiler settings.`); const compilerConfig = getTsPathAliasesApiExtractorConfig({ - tsConfig, + tsConfig: tsConfigs.lib, packageJson, pathAliasesTsConfigPath: isLocalBuild ? path.join(workspaceRoot, 'tsconfig.base.json') : undefined, definitionsRootPath: 'dist/out-tsc/types', diff --git a/scripts/tasks/src/copy.ts b/scripts/tasks/src/copy.ts index f750762477ce24..61e911f8333d9e 100644 --- a/scripts/tasks/src/copy.ts +++ b/scripts/tasks/src/copy.ts @@ -1,7 +1,9 @@ -import * as fs from 'fs-extra'; import * as path from 'path'; -import { series, resolveCwd, copyTask, copyInstructionsTask, logger, TaskFunction } from 'just-scripts'; -import { getProjectMetadata, findGitRoot } from '@fluentui/scripts-monorepo'; + +import { findGitRoot, getProjectMetadata } from '@fluentui/scripts-monorepo'; +import * as fs from 'fs-extra'; +import { TaskFunction, copyInstructionsTask, copyTask, logger, resolveCwd, series } from 'just-scripts'; + import { getTsPathAliasesConfig } from './utils'; export function expandSourcePath(pattern: string): string | null { @@ -38,10 +40,11 @@ export function expandSourcePath(pattern: string): string | null { * Used solely for packages that use TS solution config files with TS path aliases */ export function copyCompiled() { - const { isUsingTsSolutionConfigs, packageJson, tsConfig } = getTsPathAliasesConfig(); + const { isUsingTsSolutionConfigs, packageJson, tsConfigs } = getTsPathAliasesConfig(); const root = findGitRoot(); const packageDir = process.cwd(); + const tsConfig = tsConfigs.lib; if (!(isUsingTsSolutionConfigs && tsConfig)) { logger.warn(`copy-compiled: works only with packages that use TS solution config files. Skipping...`); diff --git a/scripts/tasks/src/generate-api.ts b/scripts/tasks/src/generate-api.ts index 829339d5cd4c89..6a598757c8eb25 100644 --- a/scripts/tasks/src/generate-api.ts +++ b/scripts/tasks/src/generate-api.ts @@ -1,17 +1,24 @@ -import { exec } from 'child_process'; -import { promisify } from 'util'; +import { execSync } from 'child_process'; import { series } from 'just-scripts'; import { apiExtractor } from './api-extractor'; - -const execAsync = promisify(exec); +import { getTsPathAliasesConfigUsedOnlyForDx } from './utils'; export function generateApi() { return series(generateTypeDeclarations, apiExtractor); } function generateTypeDeclarations() { - const cmd = 'tsc -p ./tsconfig.lib.json --emitDeclarationOnly'; - return execAsync(cmd); + const { isUsingPathAliasesForDx, tsConfigFileForCompilation } = getTsPathAliasesConfigUsedOnlyForDx(); + const cmd = [ + 'tsc', + `-p ./${tsConfigFileForCompilation}`, + '--emitDeclarationOnly', + isUsingPathAliasesForDx ? '--baseUrl .' : null, + ] + .filter(Boolean) + .join(' '); + + return execSync(cmd, { stdio: 'inherit' }); } diff --git a/scripts/tasks/src/presets.ts b/scripts/tasks/src/presets.ts index 47a4bd4b7dede6..9ddfeedbbaa4fc 100644 --- a/scripts/tasks/src/presets.ts +++ b/scripts/tasks/src/presets.ts @@ -20,6 +20,7 @@ import { hasSass, sass } from './sass'; import { buildStorybookTask, startStorybookTask } from './storybook'; import { swc } from './swc'; import { ts } from './ts'; +import { typeCheck } from './type-check'; import { webpack, webpackDevServer } from './webpack'; /** Do only the bare minimum setup of options and resolve paths */ @@ -72,6 +73,7 @@ export function preset() { task('storybook:build', buildStorybookTask()); task('babel:postprocess', babel); task('generate-api', generateApi); + task('type-check', typeCheck); task('ts:compile', () => { const moduleFlag = args.module; diff --git a/scripts/tasks/src/ts.ts b/scripts/tasks/src/ts.ts index 63e432839fffbc..89388cd5228c9c 100644 --- a/scripts/tasks/src/ts.ts +++ b/scripts/tasks/src/ts.ts @@ -31,17 +31,19 @@ function prepareTsTaskConfig(options: TscTaskOptions) { options.baseUrl = '.'; options.rootDir = './src'; options.project = tsConfigFileForCompilation; + + return options; } - const { isUsingTsSolutionConfigs, tsConfigFile, tsConfig } = getTsPathAliasesConfig(); + const { isUsingTsSolutionConfigs, tsConfigFileNames, tsConfigs } = getTsPathAliasesConfig(); - if (isUsingTsSolutionConfigs && tsConfig) { + if (isUsingTsSolutionConfigs && tsConfigs.lib) { logger.info(`📣 TSC: package is using TS path aliases. Overriding tsconfig settings.`); - const tsConfigOutDir = tsConfig.compilerOptions.outDir as string; + const tsConfigOutDir = tsConfigs.lib.compilerOptions.outDir as string; options.outDir = `${tsConfigOutDir}/${options.outDir}`; - options.project = tsConfigFile; + options.project = tsConfigFileNames.lib; } return options; diff --git a/scripts/tasks/src/type-check.ts b/scripts/tasks/src/type-check.ts new file mode 100644 index 00000000000000..72f73f2fc62fba --- /dev/null +++ b/scripts/tasks/src/type-check.ts @@ -0,0 +1,43 @@ +import * as fs from 'fs'; + +import { logger } from 'just-scripts'; +// eslint-disable-next-line import/no-extraneous-dependencies +import { exec } from 'just-scripts-utils'; + +import { getTsPathAliasesConfig } from './utils'; + +export function typeCheck() { + const { isUsingTsSolutionConfigs, tsConfigFileContents, tsConfigs, tsConfigFilePaths } = getTsPathAliasesConfig(); + + if (!isUsingTsSolutionConfigs) { + logger.info('project is not using TS solution config. skipping...'); + return; + } + + const content = tsConfigFileContents.root; + const config = tsConfigs.root; + const configPath = tsConfigFilePaths.root; + + if (!(content && config)) { + return; + } + + // turn off path aliases. + // @ts-expect-error - bad just-scripts ts types + config.compilerOptions.paths = {}; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8'); + + const cmd = 'tsc'; + const args = ['-b', '--pretty', configPath]; + const program = `${cmd} ${args.join(' ')}`; + + return exec(program) + .catch(err => { + console.error(err.stdout); + process.exit(1); + }) + .finally(() => { + // restore original tsconfig.json + fs.writeFileSync(configPath, content, 'utf-8'); + }); +} diff --git a/scripts/tasks/src/utils.ts b/scripts/tasks/src/utils.ts index e1d14628cb5da9..dca9655a309602 100644 --- a/scripts/tasks/src/utils.ts +++ b/scripts/tasks/src/utils.ts @@ -1,22 +1,66 @@ +import { execSync } from 'child_process'; import * as fs from 'fs'; import * as path from 'path'; -import { stripJsonComments } from '@nrwl/devkit'; -import * as jju from 'jju'; +import { parseJson, stripJsonComments } from '@nrwl/devkit'; import type { TscTaskOptions } from 'just-scripts'; +/** + * + * get full TS configuration for particular tsconfig.json. + * uses tsc --showConfig under the hood + */ +export function getFullTsConfig(options: { configFileName: string; cwd: string }): TsConfig | null { + const { configFileName, cwd } = options; + const configPath = path.join(cwd, configFileName); + + if (!fs.existsSync(configPath)) { + console.warn(`${configPath} doesn't exist`); + return null; + } + + const output = execSync(`tsc -p ${configFileName} --showConfig`, { cwd, encoding: 'utf-8' }); + const json = JSON.parse(output); + + return json; +} + export function getTsPathAliasesConfig() { const cwd = process.cwd(); - const tsConfigFile = 'tsconfig.lib.json'; - const tsConfigPath = path.join(cwd, './tsconfig.lib.json'); - const tsConfig: TsConfig | null = fs.existsSync(tsConfigPath) - ? jju.parse(fs.readFileSync(tsConfigPath, 'utf-8')) - : null; + const tsConfigFileNames = { + root: 'tsconfig.json', + lib: 'tsconfig.lib.json', + }; + const tsConfigFilePaths = { + root: path.join(cwd, tsConfigFileNames.root), + lib: path.join(cwd, tsConfigFileNames.lib), + }; + const tsConfigFileContents = { + root: fs.existsSync(tsConfigFilePaths.root) ? fs.readFileSync(tsConfigFilePaths.root, 'utf-8') : null, + lib: fs.existsSync(tsConfigFilePaths.lib) ? fs.readFileSync(tsConfigFilePaths.lib, 'utf-8') : null, + }; + const tsConfigs = { + root: tsConfigFileContents.root + ? (parseJson(tsConfigFileContents.root, { expectComments: true }) as TsConfig) + : null, + lib: tsConfigFileContents.lib ? (parseJson(tsConfigFileContents.lib, { expectComments: true }) as TsConfig) : null, + }; const packageJson: PackageJson = JSON.parse(fs.readFileSync(path.join(cwd, './package.json'), 'utf-8')); - const isUsingTsSolutionConfigs = Boolean(tsConfig); + const isUsingTsSolutionConfigs = + tsConfigs.root && + tsConfigs.root.references && + tsConfigs.root.references.length > 0 && + Boolean(tsConfigFileContents.lib); - return { tsConfig, isUsingTsSolutionConfigs, tsConfigFile, tsConfigPath, packageJson }; + return { + tsConfigFileNames, + tsConfigFilePaths, + tsConfigFileContents, + tsConfigs, + packageJson, + isUsingTsSolutionConfigs, + }; } export function getTsPathAliasesConfigUsedOnlyForDx() { @@ -24,6 +68,11 @@ export function getTsPathAliasesConfigUsedOnlyForDx() { const tsConfigBaseFilesForDx = ['tsconfig.base.v8.json', 'tsconfig.base.all.json']; const cwd = process.cwd(); const tsConfigPath = path.join(cwd, `./tsconfig.json`); + + if (!fs.existsSync(tsConfigPath)) { + throw new Error(`${tsConfigPath} doesn't exist`); + } + const tsConfig = JSON.parse(stripJsonComments(fs.readFileSync(tsConfigPath, 'utf-8'))); const isUsingPathAliasesForDx = tsConfig.extends && tsConfigBaseFilesForDx.some(relativeFilePath => tsConfig.extends.endsWith(relativeFilePath)); @@ -31,7 +80,7 @@ export function getTsPathAliasesConfigUsedOnlyForDx() { const tsConfigFileForCompilation = tsConfigFilesWithAliases.find(fileName => fs.existsSync(path.join(cwd, fileName))); if (!tsConfigFileForCompilation) { - throw new Error(`no tsconfig from ${tsConfigFilesWithAliases} found!`); + throw new Error(`no tsconfig from one of [${tsConfigFilesWithAliases}] found!`); } return { isUsingPathAliasesForDx, tsConfigFileForCompilation }; From 136a5e70ef9a2bb325ad742c67d0f4f2e30a6160 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Tue, 11 Apr 2023 17:51:16 +0200 Subject: [PATCH 14/19] chore: use new type-check task for cross project TS path aliases + enable type-check for v9 docs --- apps/public-docsite-v9/package.json | 1 + .../etc/react-migration-v0-v9.api.md | 6 +++--- .../react-migration-v0-v9/package.json | 2 +- .../tsconfig.type-check.json | 19 ------------------- .../react-migration-v8-v9/package.json | 2 +- .../react-migration-v8-v9/tsconfig.json | 3 ++- .../tsconfig.type-check.json | 19 ------------------- 7 files changed, 8 insertions(+), 44 deletions(-) delete mode 100644 packages/react-components/react-migration-v0-v9/tsconfig.type-check.json delete mode 100644 packages/react-components/react-migration-v8-v9/tsconfig.type-check.json diff --git a/apps/public-docsite-v9/package.json b/apps/public-docsite-v9/package.json index 8dd9d63b38b5f5..7b9107d07cf465 100644 --- a/apps/public-docsite-v9/package.json +++ b/apps/public-docsite-v9/package.json @@ -12,6 +12,7 @@ "code-style": "just-scripts code-style", "just": "just-scripts", "lint": "just-scripts lint", + "type-check": "just-scripts type-check", "start": "yarn storybook:docs", "storybook": "start-storybook --port 3000 --no-manager-cache", "storybook:docs": "yarn storybook --docs" diff --git a/packages/react-components/react-migration-v0-v9/etc/react-migration-v0-v9.api.md b/packages/react-components/react-migration-v0-v9/etc/react-migration-v0-v9.api.md index e5d6fe9b6ba211..0ba63bb5217d4b 100644 --- a/packages/react-components/react-migration-v0-v9/etc/react-migration-v0-v9.api.md +++ b/packages/react-components/react-migration-v0-v9/etc/react-migration-v0-v9.api.md @@ -7,11 +7,11 @@ import { ComponentProps } from '@fluentui/react-components'; import { GriffelStyle } from '@fluentui/react-components'; import { ObjectOf } from '@fluentui/react-northstar'; -import { ObjectShorthandValue } from '@fluentui/react-northstar'; +import type { ObjectShorthandValue } from '@fluentui/react-northstar'; import * as React_2 from 'react'; import { Slot } from '@fluentui/react-components'; import { Slot as Slot_2 } from '@fluentui/react-utilities'; -import { SlotRenderFunction } from '@fluentui/react-components'; +import { SlotRenderFunction } from '@fluentui/react-utilities'; // @public (undocumented) export const Flex: React_2.ForwardRefExoticComponent & FlexProps & React_2.RefAttributes>; @@ -133,7 +133,7 @@ export type StyledTextSlots = { }; // @public (undocumented) -export const useFlexStyles: () => Record<"fill" | "wrap" | "inline" | "flex" | "column" | "alignItemsFlexStart" | "alignItemsCenter" | "alignItemsFlexEnd" | "alignItemsStretch" | "justifyContentFlexStart" | "justifyContentCenter" | "justifyContentFlexEnd" | "justifyContentStretch" | "justifyContentSpaceAround" | "justifyContentSpaceBetween" | "justifyContentSpaceEvenly" | "gapForColumnFlexSmall" | "gapForColumnFlexSmaller" | "gapForColumnFlexMedium" | "gapForColumnFlexLarge" | "gapForRowFlexSmall" | "gapForRowFlexSmaller" | "gapForRowFlexMedium" | "gapForRowFlexLarge" | "paddingMedium", string>; +export const useFlexStyles: () => Record<"flex" | "fill" | "column" | "wrap" | "inline" | "alignItemsFlexStart" | "alignItemsCenter" | "alignItemsFlexEnd" | "alignItemsStretch" | "justifyContentFlexStart" | "justifyContentCenter" | "justifyContentFlexEnd" | "justifyContentStretch" | "justifyContentSpaceAround" | "justifyContentSpaceBetween" | "justifyContentSpaceEvenly" | "gapForColumnFlexSmall" | "gapForColumnFlexSmaller" | "gapForColumnFlexMedium" | "gapForColumnFlexLarge" | "gapForRowFlexSmall" | "gapForRowFlexSmaller" | "gapForRowFlexMedium" | "gapForRowFlexLarge" | "paddingMedium", string>; // @public (undocumented) export const useGridStyles: () => Record<"grid" | "onlyRows" | "rows1" | "rows2" | "rows3" | "columns1" | "columns2" | "columns3" | "columnsDefault", string>; diff --git a/packages/react-components/react-migration-v0-v9/package.json b/packages/react-components/react-migration-v0-v9/package.json index 7a68f39260527b..9174861f4c6d19 100644 --- a/packages/react-components/react-migration-v0-v9/package.json +++ b/packages/react-components/react-migration-v0-v9/package.json @@ -19,7 +19,7 @@ "just": "just-scripts", "lint": "just-scripts lint", "test": "jest --passWithNoTests", - "type-check": "tsc -b tsconfig.type-check.json", + "type-check": "just-scripts type-check", "generate-api": "just-scripts generate-api", "storybook": "start-storybook", "start": "yarn storybook" diff --git a/packages/react-components/react-migration-v0-v9/tsconfig.type-check.json b/packages/react-components/react-migration-v0-v9/tsconfig.type-check.json deleted file mode 100644 index fde4d991642ae9..00000000000000 --- a/packages/react-components/react-migration-v0-v9/tsconfig.type-check.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "paths": {} - }, - "include": [], - "files": [], - "references": [ - { - "path": "./tsconfig.lib.json" - }, - { - "path": "./tsconfig.spec.json" - }, - { - "path": "./.storybook/tsconfig.json" - } - ] -} diff --git a/packages/react-components/react-migration-v8-v9/package.json b/packages/react-components/react-migration-v8-v9/package.json index 004629cb5afe01..d571ebc21bc9cf 100644 --- a/packages/react-components/react-migration-v8-v9/package.json +++ b/packages/react-components/react-migration-v8-v9/package.json @@ -18,7 +18,7 @@ "just": "just-scripts", "lint": "just-scripts lint", "test": "jest --passWithNoTests", - "type-check": "tsc -b tsconfig.type-check.json", + "type-check": "just-scripts type-check", "generate-api": "just-scripts generate-api", "storybook": "start-storybook", "start": "yarn storybook" diff --git a/packages/react-components/react-migration-v8-v9/tsconfig.json b/packages/react-components/react-migration-v8-v9/tsconfig.json index cb0beb41b1488d..4908309138a098 100644 --- a/packages/react-components/react-migration-v8-v9/tsconfig.json +++ b/packages/react-components/react-migration-v8-v9/tsconfig.json @@ -8,7 +8,8 @@ "importHelpers": true, "jsx": "react", "noUnusedLocals": true, - "preserveConstEnums": true + "preserveConstEnums": true, + "paths": {} }, "include": [], "files": [], diff --git a/packages/react-components/react-migration-v8-v9/tsconfig.type-check.json b/packages/react-components/react-migration-v8-v9/tsconfig.type-check.json deleted file mode 100644 index fde4d991642ae9..00000000000000 --- a/packages/react-components/react-migration-v8-v9/tsconfig.type-check.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "paths": {} - }, - "include": [], - "files": [], - "references": [ - { - "path": "./tsconfig.lib.json" - }, - { - "path": "./tsconfig.spec.json" - }, - { - "path": "./.storybook/tsconfig.json" - } - ] -} From 1674faa49a27765bb715d191cda7bd9c6626f619 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Tue, 18 Apr 2023 16:57:17 +0200 Subject: [PATCH 15/19] fix(scripts-tasks): dont invoke api-extractor logic on every just-script call --- scripts/tasks/src/presets.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tasks/src/presets.ts b/scripts/tasks/src/presets.ts index 9ddfeedbbaa4fc..ffa8f45073515d 100644 --- a/scripts/tasks/src/presets.ts +++ b/scripts/tasks/src/presets.ts @@ -65,7 +65,7 @@ export function preset() { task('eslint', eslint); task('webpack', webpack); task('webpack-dev-server', webpackDevServer(args)); - task('api-extractor', apiExtractor()); + task('api-extractor', apiExtractor); task('lint-imports:all', lintImportTaskAll); task('lint-imports:amd', lintImportTaskAmdOnly); task('prettier', prettier); From 5b843e29b5cad6bf50abab3c0c033dc1c1c03391 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Tue, 18 Apr 2023 17:00:09 +0200 Subject: [PATCH 16/19] scaffold tsconfig-base-all generator --- tools/generators/tsconfig-base-all/README.md | 38 ++++++++++++++ .../files/constants.ts__tmpl__ | 1 + .../tsconfig-base-all/index.spec.ts | 20 ++++++++ tools/generators/tsconfig-base-all/index.ts | 50 +++++++++++++++++++ .../tsconfig-base-all/lib/utils.spec.ts | 7 +++ .../generators/tsconfig-base-all/lib/utils.ts | 5 ++ .../generators/tsconfig-base-all/schema.json | 17 +++++++ tools/generators/tsconfig-base-all/schema.ts | 6 +++ 8 files changed, 144 insertions(+) create mode 100644 tools/generators/tsconfig-base-all/README.md create mode 100644 tools/generators/tsconfig-base-all/files/constants.ts__tmpl__ create mode 100644 tools/generators/tsconfig-base-all/index.spec.ts create mode 100644 tools/generators/tsconfig-base-all/index.ts create mode 100644 tools/generators/tsconfig-base-all/lib/utils.spec.ts create mode 100644 tools/generators/tsconfig-base-all/lib/utils.ts create mode 100644 tools/generators/tsconfig-base-all/schema.json create mode 100644 tools/generators/tsconfig-base-all/schema.ts diff --git a/tools/generators/tsconfig-base-all/README.md b/tools/generators/tsconfig-base-all/README.md new file mode 100644 index 00000000000000..25c3f7714b0013 --- /dev/null +++ b/tools/generators/tsconfig-base-all/README.md @@ -0,0 +1,38 @@ +# tsconfig-base-all + +Workspace Generator ...TODO... + + + +- [Usage](#usage) + - [Examples](#examples) +- [Options](#options) + - [`name`](#name) + + + +## Usage + +```sh +yarn nx workspace-generator tsconfig-base-all ... +``` + +Show what will be generated without writing to disk: + +```sh +yarn nx workspace-generator tsconfig-base-all --dry-run +``` + +### Examples + +```sh +yarn nx workspace-generator tsconfig-base-all +``` + +## Options + +#### `name` + +Type: `string` + +TODO... diff --git a/tools/generators/tsconfig-base-all/files/constants.ts__tmpl__ b/tools/generators/tsconfig-base-all/files/constants.ts__tmpl__ new file mode 100644 index 00000000000000..d9913111a9dc76 --- /dev/null +++ b/tools/generators/tsconfig-base-all/files/constants.ts__tmpl__ @@ -0,0 +1 @@ +export const variable = "<%= name %>"; \ No newline at end of file diff --git a/tools/generators/tsconfig-base-all/index.spec.ts b/tools/generators/tsconfig-base-all/index.spec.ts new file mode 100644 index 00000000000000..219a5b3cbf3bbb --- /dev/null +++ b/tools/generators/tsconfig-base-all/index.spec.ts @@ -0,0 +1,20 @@ +import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; +import { Tree, readProjectConfiguration } from '@nrwl/devkit'; + +import generator from './index'; +import { TsconfigBaseAllGeneratorSchema } from './schema'; + +describe('tsconfig-base-all generator', () => { + let appTree: Tree; + const options: TsconfigBaseAllGeneratorSchema = { name: 'test' }; + + beforeEach(() => { + appTree = createTreeWithEmptyWorkspace(); + }); + + it('should run successfully', async () => { + await generator(appTree, options); + const config = readProjectConfiguration(appTree, 'test'); + expect(config).toBeDefined(); + }); +}); diff --git a/tools/generators/tsconfig-base-all/index.ts b/tools/generators/tsconfig-base-all/index.ts new file mode 100644 index 00000000000000..2c9c8df40214a6 --- /dev/null +++ b/tools/generators/tsconfig-base-all/index.ts @@ -0,0 +1,50 @@ +import * as path from 'path'; +import { Tree, formatFiles, installPackagesTask, names, generateFiles } from '@nrwl/devkit'; +import { libraryGenerator } from '@nrwl/workspace/generators'; + +import { getProjectConfig } from '../../utils'; + +import { TsconfigBaseAllGeneratorSchema } from './schema'; + +interface NormalizedSchema extends ReturnType {} + +export default async function (tree: Tree, schema: TsconfigBaseAllGeneratorSchema) { + await libraryGenerator(tree, { name: schema.name }); + + const normalizedOptions = normalizeOptions(tree, schema); + + addFiles(tree, normalizedOptions); + + await formatFiles(tree); + + return () => { + installPackagesTask(tree); + }; +} + +function normalizeOptions(tree: Tree, options: TsconfigBaseAllGeneratorSchema) { + const project = getProjectConfig(tree, { packageName: options.name }); + + return { + ...options, + ...project, + ...names(options.name), + }; +} + +/** + * NOTE: remove this if your generator doesn't process any static/dynamic templates + */ +function addFiles(tree: Tree, options: NormalizedSchema) { + const templateOptions = { + ...options, + tmpl: '', + }; + + generateFiles( + tree, + path.join(__dirname, 'files'), + path.join(options.projectConfig.root, options.name), + templateOptions, + ); +} diff --git a/tools/generators/tsconfig-base-all/lib/utils.spec.ts b/tools/generators/tsconfig-base-all/lib/utils.spec.ts new file mode 100644 index 00000000000000..91e05a54a86f53 --- /dev/null +++ b/tools/generators/tsconfig-base-all/lib/utils.spec.ts @@ -0,0 +1,7 @@ +import { dummyHelper } from './utils'; + +describe(`utils`, () => { + it(`should behave...`, () => { + expect(dummyHelper()).toBe(undefined); + }); +}); diff --git a/tools/generators/tsconfig-base-all/lib/utils.ts b/tools/generators/tsconfig-base-all/lib/utils.ts new file mode 100644 index 00000000000000..c340a27c29c8b0 --- /dev/null +++ b/tools/generators/tsconfig-base-all/lib/utils.ts @@ -0,0 +1,5 @@ +// use this module to define any kind of generic utilities that are used in more than 1 place within the generator implementation + +export function dummyHelper() { + return; +} diff --git a/tools/generators/tsconfig-base-all/schema.json b/tools/generators/tsconfig-base-all/schema.json new file mode 100644 index 00000000000000..31c8558e1db3eb --- /dev/null +++ b/tools/generators/tsconfig-base-all/schema.json @@ -0,0 +1,17 @@ +{ + "$schema": "http://json-schema.org/schema", + "cli": "nx", + "id": "tsconfig-base-all", + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "Library name", + "$default": { + "$source": "argv", + "index": 0 + } + } + }, + "required": ["name"] +} diff --git a/tools/generators/tsconfig-base-all/schema.ts b/tools/generators/tsconfig-base-all/schema.ts new file mode 100644 index 00000000000000..9107aef11a743e --- /dev/null +++ b/tools/generators/tsconfig-base-all/schema.ts @@ -0,0 +1,6 @@ +export interface TsconfigBaseAllGeneratorSchema { + /** + * Library name + */ + name: string; +} From cae14c631eae5fc3522183e70fd8b36ef5356fb0 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Tue, 18 Apr 2023 18:01:24 +0200 Subject: [PATCH 17/19] feat(tools): implement tsconfig-base-all generator --- tools/generators/tsconfig-base-all/README.md | 20 ++- .../files/constants.ts__tmpl__ | 1 - .../tsconfig-base-all/index.spec.ts | 115 ++++++++++++++++-- tools/generators/tsconfig-base-all/index.ts | 49 +++----- .../tsconfig-base-all/lib/utils.spec.ts | 7 -- .../generators/tsconfig-base-all/lib/utils.ts | 39 +++++- .../generators/tsconfig-base-all/schema.json | 13 +- tools/generators/tsconfig-base-all/schema.ts | 4 +- 8 files changed, 182 insertions(+), 66 deletions(-) delete mode 100644 tools/generators/tsconfig-base-all/files/constants.ts__tmpl__ delete mode 100644 tools/generators/tsconfig-base-all/lib/utils.spec.ts diff --git a/tools/generators/tsconfig-base-all/README.md b/tools/generators/tsconfig-base-all/README.md index 25c3f7714b0013..bf5861795bcb73 100644 --- a/tools/generators/tsconfig-base-all/README.md +++ b/tools/generators/tsconfig-base-all/README.md @@ -1,20 +1,22 @@ # tsconfig-base-all -Workspace Generator ...TODO... +Workspace Generator for generating/updating `/tsconfig.base.all.json`. + +> `tsconfig.base.all.json` contains all monorepo project path aliases, and reflect source of truth for all monorepo packages. - [Usage](#usage) - [Examples](#examples) - [Options](#options) - - [`name`](#name) + - [`verify`](#verify) ## Usage ```sh -yarn nx workspace-generator tsconfig-base-all ... +yarn nx workspace-generator tsconfig-base-all ``` Show what will be generated without writing to disk: @@ -31,8 +33,14 @@ yarn nx workspace-generator tsconfig-base-all ## Options -#### `name` +#### `verify` + +Type: `boolean` -Type: `string` +use this option on CI to check if base.all.json is up to date and in sync with all other base configs -TODO... +Following will throw an error if `tsconfig.base.all.json` is out of date + +```sh +yarn nx workspace-generator tsconfig-base-all --verify +``` diff --git a/tools/generators/tsconfig-base-all/files/constants.ts__tmpl__ b/tools/generators/tsconfig-base-all/files/constants.ts__tmpl__ deleted file mode 100644 index d9913111a9dc76..00000000000000 --- a/tools/generators/tsconfig-base-all/files/constants.ts__tmpl__ +++ /dev/null @@ -1 +0,0 @@ -export const variable = "<%= name %>"; \ No newline at end of file diff --git a/tools/generators/tsconfig-base-all/index.spec.ts b/tools/generators/tsconfig-base-all/index.spec.ts index 219a5b3cbf3bbb..956d08ad247a07 100644 --- a/tools/generators/tsconfig-base-all/index.spec.ts +++ b/tools/generators/tsconfig-base-all/index.spec.ts @@ -1,20 +1,121 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { Tree, readProjectConfiguration } from '@nrwl/devkit'; +import { Tree, writeJson, readJson, updateJson } from '@nrwl/devkit'; import generator from './index'; import { TsconfigBaseAllGeneratorSchema } from './schema'; describe('tsconfig-base-all generator', () => { - let appTree: Tree; - const options: TsconfigBaseAllGeneratorSchema = { name: 'test' }; + let tree: Tree; + const options: TsconfigBaseAllGeneratorSchema = {}; beforeEach(() => { - appTree = createTreeWithEmptyWorkspace(); + tree = createTreeWithEmptyWorkspace(); + writeJson(tree, '/tsconfig.base.v0.json', { + compilerOptions: { + paths: { + '@proj/v0-one': ['packages/v0-one/src/index.ts'], + '@proj/v0-two': ['packages/v0-two/src/index.ts'], + }, + }, + }); + writeJson(tree, '/tsconfig.base.v8.json', { + compilerOptions: { + paths: { + '@proj/v8-one': ['packages/v8-one/src/index.ts'], + '@proj/v8-two': ['packages/v8-two/src/index.ts'], + }, + }, + }); + writeJson(tree, '/tsconfig.base.json', { + compilerOptions: { + paths: { + '@proj/one': ['packages/one/src/index.ts'], + '@proj/two': ['packages/two/src/index.ts'], + }, + }, + }); }); it('should run successfully', async () => { - await generator(appTree, options); - const config = readProjectConfiguration(appTree, 'test'); - expect(config).toBeDefined(); + await generator(tree, options); + const baseAllJson = readJson(tree, '/tsconfig.base.all.json'); + + expect(baseAllJson).toMatchInlineSnapshot(` + Object { + "compilerOptions": Object { + "baseUrl": ".", + "forceConsistentCasingInFileNames": true, + "isolatedModules": true, + "moduleResolution": "node", + "paths": Object { + "@proj/one": Array [ + "packages/one/src/index.ts", + ], + "@proj/two": Array [ + "packages/two/src/index.ts", + ], + "@proj/v0-one": Array [ + "packages/v0-one/src/index.ts", + ], + "@proj/v0-two": Array [ + "packages/v0-two/src/index.ts", + ], + "@proj/v8-one": Array [ + "packages/v8-one/src/index.ts", + ], + "@proj/v8-two": Array [ + "packages/v8-two/src/index.ts", + ], + }, + "preserveConstEnums": true, + "pretty": true, + "rootDir": ".", + "skipLibCheck": true, + "sourceMap": true, + "typeRoots": Array [ + "node_modules/@types", + "./typings", + ], + }, + } + `); + }); + + describe(`--verify`, () => { + it(`should pass if base all config is up to date`, async () => { + expect.assertions(1); + await generator(tree, {}); + + updateJson(tree, '/tsconfig.base.json', json => { + json.compilerOptions.paths['@proj/three'] = ['packages/three/src/index.ts']; + return json; + }); + + await generator(tree, {}); + + await expect(generator(tree, { verify: true })).resolves.toBe(undefined); + }); + + it(`should fail if base all config is not up to date`, async () => { + expect.assertions(1); + await generator(tree, {}); + + updateJson(tree, '/tsconfig.base.json', json => { + json.compilerOptions.paths['@proj/three'] = ['packages/three/src/index.ts']; + return json; + }); + + try { + await generator(tree, { verify: true }); + } catch (err) { + expect((err as Error).message).toMatchInlineSnapshot(` + " + 🚨 /tsconfig.base.all.json is out of date. + + Please update it by running 'yarn nx workspace-generator tsconfig-base-all'. + " + `); + } + }); }); }); diff --git a/tools/generators/tsconfig-base-all/index.ts b/tools/generators/tsconfig-base-all/index.ts index 2c9c8df40214a6..fdad039a5f8754 100644 --- a/tools/generators/tsconfig-base-all/index.ts +++ b/tools/generators/tsconfig-base-all/index.ts @@ -1,50 +1,33 @@ -import * as path from 'path'; -import { Tree, formatFiles, installPackagesTask, names, generateFiles } from '@nrwl/devkit'; -import { libraryGenerator } from '@nrwl/workspace/generators'; - -import { getProjectConfig } from '../../utils'; +import { Tree, formatFiles, writeJson } from '@nrwl/devkit'; +import { isEqual } from 'lodash'; import { TsconfigBaseAllGeneratorSchema } from './schema'; +import { createPathAliasesConfig } from './lib/utils'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars interface NormalizedSchema extends ReturnType {} export default async function (tree: Tree, schema: TsconfigBaseAllGeneratorSchema) { - await libraryGenerator(tree, { name: schema.name }); - const normalizedOptions = normalizeOptions(tree, schema); - addFiles(tree, normalizedOptions); + const { existingTsConfig, mergedTsConfig, tsConfigAllPath } = createPathAliasesConfig(tree); - await formatFiles(tree); + if (normalizedOptions.verify && !isEqual(existingTsConfig, mergedTsConfig)) { + throw new Error(` + 🚨 ${tsConfigAllPath} is out of date. - return () => { - installPackagesTask(tree); - }; + Please update it by running 'yarn nx workspace-generator tsconfig-base-all'. + `); + } + + writeJson(tree, tsConfigAllPath, mergedTsConfig); + await formatFiles(tree); } function normalizeOptions(tree: Tree, options: TsconfigBaseAllGeneratorSchema) { - const project = getProjectConfig(tree, { packageName: options.name }); - + const defaults = { verify: false }; return { + ...defaults, ...options, - ...project, - ...names(options.name), - }; -} - -/** - * NOTE: remove this if your generator doesn't process any static/dynamic templates - */ -function addFiles(tree: Tree, options: NormalizedSchema) { - const templateOptions = { - ...options, - tmpl: '', }; - - generateFiles( - tree, - path.join(__dirname, 'files'), - path.join(options.projectConfig.root, options.name), - templateOptions, - ); } diff --git a/tools/generators/tsconfig-base-all/lib/utils.spec.ts b/tools/generators/tsconfig-base-all/lib/utils.spec.ts deleted file mode 100644 index 91e05a54a86f53..00000000000000 --- a/tools/generators/tsconfig-base-all/lib/utils.spec.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { dummyHelper } from './utils'; - -describe(`utils`, () => { - it(`should behave...`, () => { - expect(dummyHelper()).toBe(undefined); - }); -}); diff --git a/tools/generators/tsconfig-base-all/lib/utils.ts b/tools/generators/tsconfig-base-all/lib/utils.ts index c340a27c29c8b0..f9a246d4f26daf 100644 --- a/tools/generators/tsconfig-base-all/lib/utils.ts +++ b/tools/generators/tsconfig-base-all/lib/utils.ts @@ -1,5 +1,40 @@ // use this module to define any kind of generic utilities that are used in more than 1 place within the generator implementation +import * as path from 'path'; +import { readJson, Tree } from '@nrwl/devkit'; -export function dummyHelper() { - return; +/** + * + * Create tsconfig.json with merged "compilerOptions.paths" from v0,v8,v9 tsconfigs. + */ +export function createPathAliasesConfig(tree: Tree) { + const tsConfigAllPath = '/tsconfig.base.all.json'; + const existingTsConfig = tree.exists(tsConfigAllPath) ? readJson(tree, tsConfigAllPath) : null; + + const baseConfigs = { + v0: readJson(tree, path.join('/tsconfig.base.v0.json')), + v8: readJson(tree, path.join('/tsconfig.base.v8.json')), + v9: readJson(tree, path.join('/tsconfig.base.json')), + }; + const tsConfigBase = '.'; + const mergedTsConfig = { + compilerOptions: { + moduleResolution: 'node', + forceConsistentCasingInFileNames: true, + skipLibCheck: true, + typeRoots: ['node_modules/@types', './typings'], + isolatedModules: true, + preserveConstEnums: true, + sourceMap: true, + pretty: true, + rootDir: tsConfigBase, + baseUrl: tsConfigBase, + paths: { + ...baseConfigs.v0.compilerOptions.paths, + ...baseConfigs.v8.compilerOptions.paths, + ...baseConfigs.v9.compilerOptions.paths, + }, + }, + }; + + return { tsConfigAllPath, mergedTsConfig, existingTsConfig }; } diff --git a/tools/generators/tsconfig-base-all/schema.json b/tools/generators/tsconfig-base-all/schema.json index 31c8558e1db3eb..78f52b5970b631 100644 --- a/tools/generators/tsconfig-base-all/schema.json +++ b/tools/generators/tsconfig-base-all/schema.json @@ -2,16 +2,13 @@ "$schema": "http://json-schema.org/schema", "cli": "nx", "id": "tsconfig-base-all", + "description": "Create tsconfig.json with merged 'compilerOptions.paths' from v0,v8,v9 tsconfigs", "type": "object", "properties": { - "name": { - "type": "string", - "description": "Library name", - "$default": { - "$source": "argv", - "index": 0 - } + "verify": { + "type": "boolean", + "description": "Verify integrity of tsconfig.base.all.json path aliases" } }, - "required": ["name"] + "required": [] } diff --git a/tools/generators/tsconfig-base-all/schema.ts b/tools/generators/tsconfig-base-all/schema.ts index 9107aef11a743e..8188c3342d5abe 100644 --- a/tools/generators/tsconfig-base-all/schema.ts +++ b/tools/generators/tsconfig-base-all/schema.ts @@ -1,6 +1,6 @@ export interface TsconfigBaseAllGeneratorSchema { /** - * Library name + * Verify integrity of tsconfig.base.all.json path aliases */ - name: string; + verify?: boolean; } From 5735d6104c90fa497a9b42dd8aead2c467f0ebd2 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Tue, 18 Apr 2023 18:10:39 +0200 Subject: [PATCH 18/19] refactor(ci): use nx workspace generator for tsconfib.base.all.json check --- azure-pipelines.yml | 7 +-- scripts/generators/create-package/index.ts | 13 +++-- .../generators/generate-ts-base-all-json.ts | 33 ------------ scripts/generators/package.json | 1 - scripts/storybook/src/index.d.ts | 1 - scripts/storybook/src/index.js | 9 +--- scripts/storybook/src/utils.js | 51 +------------------ 7 files changed, 14 insertions(+), 101 deletions(-) delete mode 100644 scripts/generators/generate-ts-base-all-json.ts diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ad0c75d11cdc80..00e58ddc63b17e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -31,7 +31,8 @@ jobs: - script: | yarn nx workspace-lint yarn nx run @fluentui/nx-workspace-tools:check-graph - displayName: NX workspace lint + yarn nx workspace-generator tsconfig-base-all --verify + displayName: Workspace lint - script: | # @fluentui/api-docs is used within apps/public-docsite-resources/just.config.ts, thus it needs to be build in advance @@ -41,10 +42,6 @@ jobs: yarn tsc -p ./tsconfig.json displayName: Type-check just.config.ts files - - script: | - yarn ts-node --swc scripts/generators/generate-ts-base-all-json.ts --verify - displayName: Check tsconfig.base.all.json integrity - - script: | yarn check:installed-dependencies-versions displayName: 'check packages: installed dependencies versions' diff --git a/scripts/generators/create-package/index.ts b/scripts/generators/create-package/index.ts index 325ea736e155e8..335aaec0ff5868 100644 --- a/scripts/generators/create-package/index.ts +++ b/scripts/generators/create-package/index.ts @@ -10,8 +10,6 @@ import _ from 'lodash'; import { Actions } from 'node-plop'; import { AddManyActionConfig, NodePlopAPI } from 'plop'; -import { main as generateTsBaseAllJson } from '../generate-ts-base-all-json'; - const root = findGitRoot(); const v8ReferencePackages = { @@ -162,8 +160,17 @@ module.exports = (plop: NodePlopAPI) => { if (migrateResult.status !== 0) { throw new Error('Something went wrong running the migration. Please check previous logs for details.'); } + const tsConfigAllUpdate = spawnSync('yarn', ['nx', 'workspace-generator', 'tsconfig-base-all'], { + cwd: root, + stdio: 'inherit', + shell: true, + }); + if (tsConfigAllUpdate.status !== 0) { + throw new Error( + 'Something went wrong while updating tsconfig.base.all.json. Please check previous logs for details.', + ); + } - generateTsBaseAllJson(); return 'Successfully migrated package'; }, () => { diff --git a/scripts/generators/generate-ts-base-all-json.ts b/scripts/generators/generate-ts-base-all-json.ts deleted file mode 100644 index f4889b9b6b7830..00000000000000 --- a/scripts/generators/generate-ts-base-all-json.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { createPathAliasesConfig } from '@fluentui/scripts-storybook'; -import { isEqual } from 'lodash'; -import * as yargs from 'yargs'; - -const isExecutedFromCli = require.main === module; - -if (isExecutedFromCli) { - const argv = yargs - .option('verify', { - describe: 'Run check if ts base all is up to date. Used mostly on CI', - type: 'boolean', - }) - .help().argv; - - main(argv); -} - -export function main(options?: yargs.Arguments<{ verify?: boolean }>) { - const { verify = false } = options ?? {}; - - const { mergedTsConfig, existingTsConfig, tsConfigAllFileName } = createPathAliasesConfig({ - relativeFolderPathFromRoot: '.', - writeFileToDisk: verify === false, - }); - - if (verify && !isEqual(existingTsConfig, mergedTsConfig)) { - throw new Error(` - 🚨 ${tsConfigAllFileName} is out of date. - - Please update it by running 'yarn ts-node --swc scripts/generators/generate-ts-base-all-json.ts'. - `); - } -} diff --git a/scripts/generators/package.json b/scripts/generators/package.json index 1b9f35f0833864..d49423bff685b8 100644 --- a/scripts/generators/package.json +++ b/scripts/generators/package.json @@ -12,7 +12,6 @@ }, "dependencies": { "@fluentui/scripts-monorepo": "*", - "@fluentui/scripts-storybook": "*", "@fluentui/scripts-projects-test": "*" } } diff --git a/scripts/storybook/src/index.d.ts b/scripts/storybook/src/index.d.ts index 3b549d3d4dbff5..8e89d8b7855d32 100644 --- a/scripts/storybook/src/index.d.ts +++ b/scripts/storybook/src/index.d.ts @@ -3,7 +3,6 @@ export { loadWorkspaceAddon, registerTsPaths, registerRules, - createPathAliasesConfig, overrideDefaultBabelLoader, } from './utils'; diff --git a/scripts/storybook/src/index.js b/scripts/storybook/src/index.js index 7f12318ec27922..364bb4019e518f 100644 --- a/scripts/storybook/src/index.js +++ b/scripts/storybook/src/index.js @@ -1,14 +1,7 @@ const rules = require('./rules'); -const { - createPathAliasesConfig, - getPackageStoriesGlob, - loadWorkspaceAddon, - registerRules, - registerTsPaths, -} = require('./utils'); +const { getPackageStoriesGlob, loadWorkspaceAddon, registerRules, registerTsPaths } = require('./utils'); module.exports = { - createPathAliasesConfig, getPackageStoriesGlob, loadWorkspaceAddon, registerRules, diff --git a/scripts/storybook/src/utils.js b/scripts/storybook/src/utils.js index f662abb60c046a..f38cdf5e6efbf2 100644 --- a/scripts/storybook/src/utils.js +++ b/scripts/storybook/src/utils.js @@ -3,7 +3,7 @@ const path = require('path'); const { fullSourcePlugin: babelPlugin } = require('@fluentui/babel-preset-storybook-full-source'); const { isConvergedPackage, getAllPackageInfo, getProjectMetadata } = require('@fluentui/scripts-monorepo'); -const { stripIndents, offsetFromRoot, workspaceRoot, readJsonFile, writeJsonFile } = require('@nrwl/devkit'); +const { stripIndents, offsetFromRoot, workspaceRoot } = require('@nrwl/devkit'); const semver = require('semver'); const { TsconfigPathsPlugin } = require('tsconfig-paths-webpack-plugin'); @@ -354,58 +354,9 @@ function overrideDefaultBabelLoader(options) { } } -/** - * Create tsconfig.json with merged "compilerOptions.paths" from v0,v8,v9 tsconfigs. - * - * Main purpose of this is to be used for build-less DX in webpack in tandem with {@link registerTsPaths} - * - * @param {{relativeFolderPathFromRoot?:string,writeFileToDisk?:boolean}} options - */ -function createPathAliasesConfig(options = {}) { - const { relativeFolderPathFromRoot = './dist', writeFileToDisk = true } = options; - const rootPath = workspaceRoot; - const mergedTsConfigRoot = path.join(rootPath, relativeFolderPathFromRoot); - const tsConfigAllFileName = 'tsconfig.base.all.json'; - const tsConfigAllPath = path.join(mergedTsConfigRoot, tsConfigAllFileName); - const existingTsConfig = readJsonFile(tsConfigAllPath); - - const baseConfigs = { - v0: readJsonFile(path.join(rootPath, 'tsconfig.base.v0.json')), - v8: readJsonFile(path.join(rootPath, 'tsconfig.base.v8.json')), - v9: readJsonFile(path.join(rootPath, 'tsconfig.base.json')), - }; - const tsConfigBase = rootPath === mergedTsConfigRoot ? '.' : rootPath; - const mergedTsConfig = { - compilerOptions: { - moduleResolution: 'node', - forceConsistentCasingInFileNames: true, - skipLibCheck: true, - typeRoots: ['node_modules/@types', './typings'], - isolatedModules: true, - preserveConstEnums: true, - sourceMap: true, - pretty: true, - rootDir: tsConfigBase, - baseUrl: tsConfigBase, - paths: { - ...baseConfigs.v0.compilerOptions.paths, - ...baseConfigs.v8.compilerOptions.paths, - ...baseConfigs.v9.compilerOptions.paths, - }, - }, - }; - - if (writeFileToDisk) { - writeJsonFile(tsConfigAllPath, mergedTsConfig); - } - - return { tsConfigAllPath, tsConfigAllFileName, mergedTsConfig, existingTsConfig }; -} - exports.getPackageStoriesGlob = getPackageStoriesGlob; exports.loadWorkspaceAddon = loadWorkspaceAddon; exports.registerTsPaths = registerTsPaths; exports.registerRules = registerRules; -exports.createPathAliasesConfig = createPathAliasesConfig; exports.overrideDefaultBabelLoader = overrideDefaultBabelLoader; exports._createCodesandboxRule = _createCodesandboxRule; From 272bb1859dcbb53cb363222d26e31576fbeda48c Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Thu, 27 Apr 2023 17:55:06 +0200 Subject: [PATCH 19/19] fixup! chore: update tsconfig.base.all after rebase --- tsconfig.base.all.json | 1 - 1 file changed, 1 deletion(-) diff --git a/tsconfig.base.all.json b/tsconfig.base.all.json index bcafada30120c9..030c677be31982 100644 --- a/tsconfig.base.all.json +++ b/tsconfig.base.all.json @@ -91,7 +91,6 @@ "@fluentui/react-alert": ["packages/react-components/react-alert/src/index.ts"], "@fluentui/react-aria": ["packages/react-components/react-aria/src/index.ts"], "@fluentui/react-avatar": ["packages/react-components/react-avatar/src/index.ts"], - "@fluentui/react-avatar-context": ["packages/react-components/react-avatar-context/src/index.ts"], "@fluentui/react-badge": ["packages/react-components/react-badge/src/index.ts"], "@fluentui/react-breadcrumb": ["packages/react-components/react-breadcrumb/src/index.ts"], "@fluentui/react-button": ["packages/react-components/react-button/src/index.ts"],