Skip to content

Commit

Permalink
feat(scripts-tasks): enable ts processing on projects with path alias…
Browse files Browse the repository at this point in the history
…es used only for DX
  • Loading branch information
Hotell committed Apr 3, 2023
1 parent 94bd1d1 commit 010c34d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
10 changes: 5 additions & 5 deletions scripts/tasks/src/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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();
Expand Down
19 changes: 14 additions & 5 deletions scripts/tasks/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit 010c34d

Please sign in to comment.