-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e1f555
commit e119cd3
Showing
4 changed files
with
45 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,45 @@ | ||
const ensureRequire = require('../ensure-require') | ||
const compileBabel = require('./babel-compiler') | ||
const tsconfig = require('tsconfig') | ||
const cache = require('../cache') | ||
const logger = require('../logger') | ||
|
||
const defaultTypescriptConfig = { | ||
'compilerOptions': { | ||
'module': 'es2015', | ||
'moduleResolution': 'node', | ||
'allowSyntheticDefaultImports': true, | ||
'strict': true, | ||
'noEmit': true | ||
}, | ||
'include': [ | ||
'**/*.ts' | ||
] | ||
} | ||
|
||
function getTypescriptConfig () { | ||
// const cachedConfig = cache.get('typescript-config') | ||
// if (cachedConfig) { | ||
// return cachedConfig | ||
// } else { | ||
const { config } = tsconfig.loadSync(process.cwd()) | ||
|
||
if (!config) { | ||
logger.info('no tsconfig.json found, defaulting to default typescript options') | ||
} | ||
|
||
const typescriptConfig = config || defaultTypescriptConfig | ||
cache.set('typescript-config', typescriptConfig) | ||
return typescriptConfig | ||
// } | ||
} | ||
|
||
module.exports = function compileTypescript (scriptContent) { | ||
ensureRequire('typescript', ['typescript']) | ||
const typescript = require('typescript') | ||
const file = tsconfig.loadSync(process.cwd()) | ||
const tsConfig = getTypescriptConfig() | ||
|
||
const res = typescript.transpileModule(scriptContent, file.config) | ||
const res = typescript.transpileModule(scriptContent, tsConfig) | ||
|
||
return compileBabel(res.outputText, res.sourceMapText) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters