From 62a5bcdea52a763d20bb70c6f6f1831f2df4fb90 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Fri, 12 Feb 2021 18:33:36 +0100 Subject: [PATCH 1/4] chore: create new tsconfig base with path aliases --- tsconfig.base.json | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tsconfig.base.json diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 0000000000000..63146b98b580d --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ES2015", + "module": "esnext", + "moduleResolution": "node", + "lib": ["ES2015", "dom"], + "sourceMap": true, + "strict": true, + "strictFunctionTypes": false, + "forceConsistentCasingInFileNames": true, + "skipLibCheck": true, + "typeRoots": ["node_modules/@types", "./typings"], + "baseUrl": ".", + "paths": { + "@fluentui/set-version": ["packages/set-version/src/index.ts"], + "@fluentui/react-conformance": ["packages/react-conformance/src/index.ts"], + "@fluentui/react-utilities": ["packages/react-utilities/src/index.ts"], + "@fluentui/react-make-styles": ["packages/react-make-styles/src/index.ts"], + "@fluentui/keyboard-key": ["packages/keyboard-key/src/index.ts"], + "@fluentui/react-menu": ["packages/react-menu/src/index.ts"] + } + }, + "exclude": ["node_modules"] +} From e1db90e29809eaa96944edcf9ca67fff0247be39 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Fri, 12 Feb 2021 18:34:45 +0100 Subject: [PATCH 2/4] chore(scripts): make current tsc just task to work with ts aliases --- scripts/tasks/ts.ts | 71 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/scripts/tasks/ts.ts b/scripts/tasks/ts.ts index e3294a742be22..6f2dd7af8440e 100644 --- a/scripts/tasks/ts.ts +++ b/scripts/tasks/ts.ts @@ -1,5 +1,19 @@ +import fs from 'fs'; import * as path from 'path'; -import { tscTask, argv } from 'just-scripts'; +import { tscTask, argv, TscTaskOptions, resolveCwd, logger } from 'just-scripts'; +import { Arguments } from 'yargs'; +import jju from 'jju'; + +interface JustArgs extends Arguments { + production?: boolean; +} + +interface TsConfig { + extends?: string; + compilerOptions: import('typescript').CompilerOptions; + include?: string[]; + exclude?: string[]; +} const libPath = path.resolve(process.cwd(), 'lib'); const srcPath = path.resolve(process.cwd(), 'src'); @@ -7,42 +21,77 @@ const srcPath = path.resolve(process.cwd(), 'src'); const useTsBuildInfo = /[\\/]packages[\\/]fluentui[\\/]/.test(process.cwd()) && path.basename(process.cwd()) !== 'perf-test'; -function getExtraTscParams(args) { +/** + * + * Explicitly set `baseUrl` to current package root for packages (converged packages) that use TS path aliases. + * > - This is a temporary workaround for current way of building packages. + * > - Without setting baseUrl we would get all aliased packages build within outDir + */ +function backportTsAliasedPackages(options: TscTaskOptions) { + const tsConfigFilePath = resolveCwd('./tsconfig.json'); + const tsConfig: TsConfig = jju.parse(fs.readFileSync(tsConfigFilePath, 'utf-8')); + + const normalizedOptions = { ...options }; + + if (tsConfig.extends) { + logger.info(`package is using TS path aliases. Overriding baseUrl to package root.`); + normalizedOptions.baseUrl = '.'; + } + + return normalizedOptions; +} + +function getExtraTscParams(args: JustArgs) { return { - pretty: true, target: 'es5', // sourceMap must be true for inlineSources and sourceRoot to work ...(args.production && { inlineSources: true, sourceRoot: path.relative(libPath, srcPath), sourceMap: true }), }; } +function getJustArgv(): JustArgs { + return argv(); +} + export const ts = { commonjs: () => { - const extraOptions = getExtraTscParams(argv()); - return tscTask({ + const extraOptions = getExtraTscParams(getJustArgv()); + const options = backportTsAliasedPackages({ ...extraOptions, outDir: 'lib-commonjs', module: 'commonjs', ...(useTsBuildInfo && { tsBuildInfoFile: '.commonjs.tsbuildinfo' }), }); + + return tscTask(options); }, esm: () => { - const extraOptions = getExtraTscParams(argv()); + const extraOptions = getExtraTscParams(getJustArgv()); + const options = backportTsAliasedPackages({ + ...extraOptions, + outDir: 'lib', + module: 'esnext', + }); + // Use default tsbuildinfo for this variant - return tscTask({ ...extraOptions, outDir: 'lib', module: 'esnext' }); + return tscTask(options); }, amd: () => { - const extraOptions = getExtraTscParams(argv()); - return tscTask({ + const extraOptions = getExtraTscParams(getJustArgv()); + const options = backportTsAliasedPackages({ ...extraOptions, outDir: 'lib-amd', module: 'amd', ...(useTsBuildInfo && { tsBuildInfoFile: '.amd.tsbuildinfo' }), }); + + return tscTask(options); }, commonjsOnly: () => { - const extraOptions = getExtraTscParams(argv()); + const extraOptions = getExtraTscParams(getJustArgv()); // Use default tsbuildinfo for this variant (since it's the only variant) - return tscTask({ ...extraOptions, outDir: 'lib', module: 'commonjs' }); + const options = backportTsAliasedPackages({ ...extraOptions, outDir: 'lib', module: 'commonjs' }); + + return tscTask(options); }, }; From b4bab095baba441148eb14f79d8dcbd35f4407b3 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Fri, 12 Feb 2021 18:38:25 +0100 Subject: [PATCH 3/4] chore(react-menu): switch to TS path aliases config --- packages/react-menu/tsconfig.json | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/packages/react-menu/tsconfig.json b/packages/react-menu/tsconfig.json index dfb68aa05fcb9..cb2dfadd5f8eb 100644 --- a/packages/react-menu/tsconfig.json +++ b/packages/react-menu/tsconfig.json @@ -1,23 +1,16 @@ { + "extends": "../../tsconfig.base.json", "compilerOptions": { - "baseUrl": ".", + "target": "ES5", + "lib": ["ES5", "dom"], "outDir": "dist", - "target": "es5", - "module": "commonjs", "jsx": "react", "declaration": true, - "sourceMap": true, "experimentalDecorators": true, "importHelpers": true, "noUnusedLocals": true, - "forceConsistentCasingInFileNames": true, - "strict": true, - "moduleResolution": "node", "preserveConstEnums": true, - "lib": ["es5", "dom"], - "skipLibCheck": true, - "typeRoots": ["../../node_modules/@types", "../../typings"], - "types": ["jest", "webpack-env", "custom-global"] + "types": ["jest", "custom-global"] }, "include": ["src"] } From 5ff03c4ecf851912e5f3d7c5587e120b1f9d55ff Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Tue, 16 Feb 2021 18:25:52 +0100 Subject: [PATCH 4/4] Change files --- ...ui-react-menu-e77af540-58cf-4f8a-a2b3-3174bbaa408f.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/@fluentui-react-menu-e77af540-58cf-4f8a-a2b3-3174bbaa408f.json diff --git a/change/@fluentui-react-menu-e77af540-58cf-4f8a-a2b3-3174bbaa408f.json b/change/@fluentui-react-menu-e77af540-58cf-4f8a-a2b3-3174bbaa408f.json new file mode 100644 index 0000000000000..c56cdc6db3fc6 --- /dev/null +++ b/change/@fluentui-react-menu-e77af540-58cf-4f8a-a2b3-3174bbaa408f.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore(react-menu): switch to TS path aliases config", + "packageName": "@fluentui/react-menu", + "email": "martinhochel@microsoft.com", + "dependentChangeType": "none" +}