Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(scripts): remove unused logic from tsc,api-extractor used for partial migration #25678

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/just.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function preset() {
task('ts', () => {
return series(
'ts:compile',
condition('copy-compiled', () => isConvergedPackage({ projectType: 'library' })),
'copy-compiled',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build pipeline is now driven by ts-config as the main source of truth which enables usage cross version (v8,9) without need of creating config discrepancies

'ts:postprocess',
condition('babel:postprocess', () => fs.existsSync(path.join(process.cwd(), '.babelrc.json'))),
);
Expand Down
1 change: 1 addition & 0 deletions scripts/tasks/api-extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export function apiExtractor() {
tsConfig,
tsConfigPath,
packageJson,
definitionsRootPath: 'dist/out-tsc/types',
});

config.compiler = compilerConfig;
Expand Down
15 changes: 3 additions & 12 deletions scripts/tasks/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
? {
Expand Down
12 changes: 1 addition & 11 deletions scripts/tasks/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
19 changes: 18 additions & 1 deletion scripts/tasks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string[]>;

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:
Expand Down Expand Up @@ -71,7 +87,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 }),
},
};

Expand Down