Skip to content

Commit

Permalink
Support user's typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Binns-Smith committed Jun 1, 2019
1 parent 7615a17 commit b84af3f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/transformers/typescript-tsc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"main": "src/TSCTransformer",
"dependencies": {
"@parcel/local-require": "^2.0.0-alpha.0",
"@parcel/plugin": "^2.0.0-alpha.0",
"typescript": "^3.4.5"
}
Expand Down
17 changes: 11 additions & 6 deletions packages/transformers/typescript-tsc/src/TSCTransformer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// @flow strict-local

import {Transformer} from '@parcel/plugin';
// $FlowFixMe
import typescript from 'typescript';
import localRequire from '@parcel/local-require';

type TypescriptCompilerOptions = {
module?: mixed,
Expand All @@ -24,6 +23,12 @@ export default new Transformer({
async transform({asset, config}) {
asset.type = 'js';

let typescript =
config == null
? // $FlowFixMe
require('typescript')
: await localRequire('typescript', asset.filePath);

// require typescript, installed locally in the app
let transpilerOptions: TypescriptTranspilerOptions = {
compilerOptions: {
Expand All @@ -40,10 +45,10 @@ export default new Transformer({

// Overwrite default if config is found
if (config) {
transpilerOptions.compilerOptions = Object.assign(
transpilerOptions.compilerOptions,
config.compilerOptions
);
transpilerOptions.compilerOptions = {
...transpilerOptions.compilerOptions,
...config.compilerOptions
};
}
transpilerOptions.compilerOptions.noEmit = false;
// transpilerOptions.compilerOptions.sourceMap = options.sourceMaps;
Expand Down

0 comments on commit b84af3f

Please sign in to comment.