Skip to content

Commit

Permalink
fix(typescript): extended config file path (#157)
Browse files Browse the repository at this point in the history
* fix(typescript) extended config file path

* fix(plugin/typescript) fix bug when tsconfig path given

* fix(typescript) add tests

* fix(typescript) change join with resolve
  • Loading branch information
hasangenc0 authored and shellscape committed Jan 11, 2020
1 parent 463dd10 commit e4f4e9e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/typescript/src/options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { readFileSync } from 'fs';
import { resolve } from 'path';

export function getDefaultOptions() {
return {
Expand All @@ -17,9 +18,16 @@ export function readTsConfig(ts: typeof import('typescript'), tsconfigPath: stri
if (!existingTsConfig) {
return {};
}

const tsconfig = ts.readConfigFile(existingTsConfig, (path) => readFileSync(path, 'utf8'));

if (!tsconfig.config || !tsconfig.config.compilerOptions) return { compilerOptions: {} };

const extendedTsConfig: string = tsconfig.config.extends;
if (tsconfigPath && extendedTsConfig) {
tsconfig.config.extends = resolve(process.cwd(), existingTsConfig, '..', extendedTsConfig);
}

return tsconfig.config;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default <span {...props}>Yo!</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../tsconfig.base",
"compilerOptions": {
"allowJs": true
}
}
15 changes: 15 additions & 0 deletions packages/typescript/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,21 @@ test.serial('should support extends property in tsconfig', async (t) => {
t.not(usage, -1, 'should contain usage');
});

test.serial('should support extends property with given tsconfig', async (t) => {
process.chdir('fixtures/tsconfig-extends/ts-config-extends-child');

const bundle = await rollup({
input: 'main.tsx',
plugins: [typescript({
tsconfig: './tsconfig.json',
})]
});
const code = await getCode(bundle, outputOptions);

const usage = code.indexOf('React.createElement("span", __assign({}, props), "Yo!")');
t.not(usage, -1, 'should contain usage');
});

test('allows specifying a path for tsconfig.json', async (t) => {
const bundle = await rollup({
input: 'fixtures/tsconfig-jsx/main.tsx',
Expand Down

0 comments on commit e4f4e9e

Please sign in to comment.