From b6ca30c5d8d74a2d100dff8864bbfb1f973a3b10 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Tue, 15 Nov 2022 15:08:50 +0100 Subject: [PATCH 1/2] chore(scripts): remove unused logic from tsc,api-extractor used for partial migration --- scripts/just.config.ts | 2 +- scripts/tasks/copy.ts | 15 +++------------ scripts/tasks/ts.ts | 12 +----------- scripts/tasks/utils.ts | 3 ++- 4 files changed, 7 insertions(+), 25 deletions(-) diff --git a/scripts/just.config.ts b/scripts/just.config.ts index f5c24179e09549..6e730821b92579 100644 --- a/scripts/just.config.ts +++ b/scripts/just.config.ts @@ -90,7 +90,7 @@ export function preset() { task('ts', () => { return series( 'ts:compile', - condition('copy-compiled', () => isConvergedPackage({ projectType: 'library' })), + 'copy-compiled', 'ts:postprocess', condition('babel:postprocess', () => fs.existsSync(path.join(process.cwd(), '.babelrc.json'))), ); diff --git a/scripts/tasks/copy.ts b/scripts/tasks/copy.ts index edaa6e0cc29b8a..1f4df98005e0f9 100644 --- a/scripts/tasks/copy.ts +++ b/scripts/tasks/copy.ts @@ -39,29 +39,20 @@ export function expandSourcePath(pattern: string): string | null { */ export function copyCompiled() { const { isUsingTsSolutionConfigs, packageJson, tsConfig } = getTsPathAliasesConfig(); - const root = findGitRoot(); - - const packageDir = process.cwd(); if (!(isUsingTsSolutionConfigs && tsConfig)) { - throw new Error(`this task compliant only with packages that use TS solution config files.`); - } - - // TODO: remove after all v9 is migrated to new build and .d.ts API stripping - const hasNewCompilationSetup = (tsConfig.compilerOptions.outDir as string).includes('dist/out-tsc'); - - if (!hasNewCompilationSetup) { - logger.info('copy-compiled: noop '); - + logger.warn(`This task works only with packages that use TS solution config files. Skipping...`); return; } + const root = findGitRoot(); const projectMetadata = getProjectMetadata({ root, name: packageJson.name }); if (!projectMetadata.sourceRoot) { throw new Error(`${packageJson.name} is missing 'sourceRoot' in workspace.json`); } + const packageDir = process.cwd(); const paths = { esm: packageJson.module ? { diff --git a/scripts/tasks/ts.ts b/scripts/tasks/ts.ts index 30a3e54b941dfc..74f321bbf74c86 100644 --- a/scripts/tasks/ts.ts +++ b/scripts/tasks/ts.ts @@ -28,17 +28,7 @@ function prepareTsTaskConfig(options: TscTaskOptions) { logger.info(`📣 TSC: package is using TS path aliases. Overriding tsconfig settings.`); const tsConfigOutDir = tsConfig.compilerOptions.outDir as string; - - const hasNewCompilationSetup = tsConfigOutDir.includes('dist/out-tsc'); - - if (hasNewCompilationSetup) { - options.outDir = `${tsConfigOutDir}/${options.outDir}`; - } else { - // TODO: remove after all v9 is migrated to new build and .d.ts API stripping - options.baseUrl = '.'; - options.rootDir = './src'; - } - + options.outDir = `${tsConfigOutDir}/${options.outDir}`; options.project = tsConfigFile; } diff --git a/scripts/tasks/utils.ts b/scripts/tasks/utils.ts index 66214acb223424..2901197358d7bd 100644 --- a/scripts/tasks/utils.ts +++ b/scripts/tasks/utils.ts @@ -71,7 +71,8 @@ export function getTsPathAliasesApiExtractorConfig(options: { /** * just-scripts provides invalid types for tsconfig, thus `paths` cannot be set to dictionary,nor null or `{}` */ - paths: undefined, + // @ts-expect-error - just-scripts provides invalid types + paths: createNormalizedTsPaths({ definitionsRootPath: options.definitionsRootPath, rootTsConfig }), }, }; From 675d36c2d4e38f719d9d6127f5e2ccd2cb9f22e0 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Tue, 15 Nov 2022 17:29:24 +0100 Subject: [PATCH 2/2] chore(scripts): add back code from bad cherry pick conflict resolution --- scripts/tasks/api-extractor.ts | 1 + scripts/tasks/utils.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/scripts/tasks/api-extractor.ts b/scripts/tasks/api-extractor.ts index 00bb6182ad4881..68ae9021cfde9f 100644 --- a/scripts/tasks/api-extractor.ts +++ b/scripts/tasks/api-extractor.ts @@ -147,6 +147,7 @@ export function apiExtractor() { tsConfig, tsConfigPath, packageJson, + definitionsRootPath: 'dist/out-tsc/types', }); config.compiler = compilerConfig; diff --git a/scripts/tasks/utils.ts b/scripts/tasks/utils.ts index 2901197358d7bd..f3b9f3c6ccf744 100644 --- a/scripts/tasks/utils.ts +++ b/scripts/tasks/utils.ts @@ -39,10 +39,26 @@ function enableAllowSyntheticDefaultImports(options: { pkgJson: PackageJson }) { return shouldEnable ? { allowSyntheticDefaultImports: true } : null; } +const rootTsConfig = JSON.parse( + fs.readFileSync(path.resolve(__dirname, '../../tsconfig.base.json'), 'utf-8'), +) as TsConfig; + +function createNormalizedTsPaths(options: { definitionsRootPath: string; rootTsConfig: TsConfig }) { + const paths = (options.rootTsConfig.compilerOptions.paths as unknown) as Record; + + const normalizedPaths = Object.entries(paths).reduce((acc, [pkgName, pathAliases]) => { + acc[pkgName] = [path.join(options.definitionsRootPath, pathAliases[0].replace('index.ts', 'index.d.ts'))]; + return acc; + }, {} as typeof paths); + + return normalizedPaths; +} + export function getTsPathAliasesApiExtractorConfig(options: { tsConfig: TsConfig; tsConfigPath: string; packageJson: PackageJson; + definitionsRootPath: string; }) { /** * Customized TSConfig that uses `tsconfig.lib.json` as base with some required overrides: