Skip to content

Commit

Permalink
simple_tsify to ignore transpiling json files.
Browse files Browse the repository at this point in the history
  • Loading branch information
sainthkh committed Dec 18, 2019
1 parent 866ed80 commit aae6ce1
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions packages/server/lib/plugins/simple_tsify.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
let through = require('through2')

const isJson = (code) => {
try {
JSON.parse(code)
} catch (e) {
return false
}

return true
}

module.exports = function (b, opts) {
return through(function (buf, enc, next) {
const ts = opts.typescript
const text = buf.toString()

this.push(ts.transpileModule(buf.toString(), {
compilerOptions: {
esModuleInterop: true,
jsx: 'react',
},
}).outputText)
if (isJson(text)) {
this.push(text)
} else {
this.push(ts.transpileModule(text, {
compilerOptions: {
esModuleInterop: true,
jsx: 'react',
},
}).outputText)
}

next()
})
Expand Down

0 comments on commit aae6ce1

Please sign in to comment.