Skip to content

Commit

Permalink
(fix): parse tsconfig extends, trailing commas, and comments
Browse files Browse the repository at this point in the history
- use ts.readConfigFile to properly parse a tsconfig instead of just
  trying to readJSON
  • Loading branch information
agilgur5 committed Feb 4, 2020
1 parent 1632ef8 commit ab0e3f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/createRollupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import replace from '@rollup/plugin-replace';
import resolve from '@rollup/plugin-node-resolve';
import sourceMaps from 'rollup-plugin-sourcemaps';
import typescript from 'rollup-plugin-typescript2';
import ts from 'typescript';

import { extractErrors } from './errors/extractErrors';
import { babelPluginTsdx } from './babelPluginTsdx';
import { TsdxOptions } from './types';
import * as fs from 'fs-extra';

const errorCodeOpts = {
errorMapFilePath: paths.appErrorsJson,
Expand Down Expand Up @@ -45,8 +46,12 @@ export async function createRollupConfig(

let tsconfigJSON;
try {
tsconfigJSON = await fs.readJSON(opts.tsconfig || paths.tsconfigJson);
} catch (e) {}
const tsconfigPath = opts.tsconfig || paths.tsconfigJson;
// borrowed from https://github.com/facebook/create-react-app/pull/7248
tsconfigJSON = ts.readConfigFile(tsconfigPath, ts.sys.readFile).config;
} catch (e) {
console.error(e);
}

return {
// Tell Rollup the entry point to the package
Expand Down Expand Up @@ -136,7 +141,7 @@ export async function createRollupConfig(
},
},
typescript({
typescript: require('typescript'),
typescript: ts,
cacheRoot: `./node_modules/.cache/tsdx/${opts.format}/`,
tsconfig: opts.tsconfig,
tsconfigDefaults: {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/build-default/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
"jsx": "react",
"esModuleInterop": true
},
"include": ["src", "types"]
"include": ["src", "types"], // test parsing of trailing comma & comment
}

0 comments on commit ab0e3f9

Please sign in to comment.