Skip to content

Commit

Permalink
feat(scripts): add v8 package compilation if TS path aliases are used
Browse files Browse the repository at this point in the history
  • Loading branch information
Hotell committed Nov 25, 2022
1 parent d1b232c commit 5dde7c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion scripts/tasks/ts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'path';
import { tscTask, TscTaskOptions, logger } from 'just-scripts';
import { getJustArgv } from './argv';
import { getTsPathAliasesConfig } from './utils';
import { getTsPathAliasesConfig, getTsPathAliasesConfigV8 } from './utils';

const libPath = path.resolve(process.cwd(), 'lib');
const srcPath = path.resolve(process.cwd(), 'src');
Expand All @@ -22,6 +22,15 @@ function prepareTsTaskConfig(options: TscTaskOptions) {
options.sourceMap = true;
}

const { isUsingV8pathAliases, tsConfigFileV8 } = getTsPathAliasesConfigV8();

if (isUsingV8pathAliases) {
logger.info(`📣 TSC: V8 package is using TS path aliases. Overriding tsconfig settings.`);
options.baseUrl = '.';
options.rootDir = './src';
options.project = tsConfigFileV8;
}

const { isUsingTsSolutionConfigs, tsConfigFile, tsConfig } = getTsPathAliasesConfig();

if (isUsingTsSolutionConfigs && tsConfig) {
Expand Down
10 changes: 10 additions & 0 deletions scripts/tasks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as fs from 'fs';
import * as path from 'path';
import * as jju from 'jju';
import type { TscTaskOptions } from 'just-scripts';
import { stripJsonComments } from '@nrwl/devkit';

export function getTsPathAliasesConfig() {
const cwd = process.cwd();
Expand All @@ -17,6 +18,15 @@ export function getTsPathAliasesConfig() {
return { tsConfig, isUsingTsSolutionConfigs, tsConfigFile, tsConfigPath, packageJson };
}

export function getTsPathAliasesConfigV8() {
const cwd = process.cwd();
const tsConfigFile = 'tsconfig.json';
const tsConfigPath = path.join(cwd, `./${tsConfigFile}`);
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 packagesWithInvalidTypes = [
/**
* @see @storybook/api/dist/ts3.9/lib/stories.d.ts:1:8 - `import React from 'react'`
Expand Down

0 comments on commit 5dde7c6

Please sign in to comment.