-
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.
feat: use ts-jest for TypeScript config resolution (#139)
BREAKING CHANGE: removes tsConfig options
- Loading branch information
1 parent
9888245
commit 842467b
Showing
30 changed files
with
1,980 additions
and
1,296 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,7 +1,3 @@ | ||
{ | ||
"env": { | ||
"test": { | ||
"presets": ["env"] | ||
} | ||
} | ||
"presets": ["@babel/env"] | ||
} |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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
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,34 +1,35 @@ | ||
const ensureRequire = require('../ensure-require') | ||
const loadBabelConfig = require('../load-babel-config.js') | ||
const { loadTypescriptConfig } = require('../load-typescript-config') | ||
const babelJest = require('babel-jest') | ||
const getVueJestConfig = require('../get-vue-jest-config') | ||
const getBabelOptions = require('../utils').getBabelOptions | ||
const getTsJestConfig = require('../utils').getTsJestConfig | ||
const stripInlineSourceMap = require('../utils').stripInlineSourceMap | ||
|
||
module.exports = function compileTypescript(scriptContent, filePath, config) { | ||
ensureRequire('typescript', ['typescript']) | ||
const vueJestConfig = getVueJestConfig(config) | ||
const typescript = require('typescript') | ||
const tsConfig = loadTypescriptConfig(vueJestConfig) | ||
|
||
const res = typescript.transpileModule(scriptContent, tsConfig) | ||
const { tsconfig } = getTsJestConfig(config) | ||
const babelOptions = getBabelOptions(filePath) | ||
|
||
const res = typescript.transpileModule(scriptContent, tsconfig) | ||
|
||
res.outputText = stripInlineSourceMap(res.outputText) | ||
|
||
const inputSourceMap = | ||
res.sourceMapText !== undefined ? JSON.parse(res.sourceMapText) : '' | ||
|
||
// handle ES modules in TS source code in case user uses non commonjs module | ||
// output and there is no .babelrc. | ||
let inlineBabelConfig = {} | ||
if ( | ||
tsConfig.compilerOptions.module !== 'commonjs' && | ||
!loadBabelConfig(vueJestConfig) | ||
) { | ||
inlineBabelConfig = { | ||
plugins: [require('babel-plugin-transform-es2015-modules-commonjs')] | ||
let inlineBabelOptions = {} | ||
if (tsconfig.compilerOptions.module !== 'commonjs' && !babelOptions) { | ||
inlineBabelOptions = { | ||
plugins: [require('@babel/plugin-transform-modules-commonjs')] | ||
} | ||
} | ||
|
||
const transformer = babelJest.createTransformer( | ||
Object.assign(inlineBabelConfig, { | ||
inputSourceMap | ||
}) | ||
Object.assign(inlineBabelOptions, { inputSourceMap }) | ||
) | ||
|
||
return transformer.process(res.outputText, filePath, config) | ||
} |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.