-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
let the script processer pick custom transformers when present #154
Conversation
250f9d5
to
13426a0
Compare
@@ -64,7 +64,8 @@ const getBabelOptions = function loadBabelOptions(filename, options = {}) { | |||
|
|||
const getTsJestConfig = function getTsJestConfig(config) { | |||
const tr = createTransformer() | |||
return tr.configsFor(config) | |||
const { typescript } = tr.configsFor(config) | |||
return { compilerOptions: typescript.options } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we could do something like the this to make sure we dont depend on ts-jest
to fetch tsConfig options when users do not use ts-jest at all.
const getTsJestConfig = function getTsJestConfig(config = {}) {
const vueTsConfig = getVueJestConfig(config)
if (typeof vueTsConfig.tsConfig === 'string') {
return getTsConfigJson(vueTsConfig.tsConfig)
} else if (typeof vueTsConfig.tsConfig === 'object') {
return vueTsConfig.tsConfig
} else if (config.globals && config.globals['ts-jest']) {
const tr = createTransformer()
const {
typescript: { options: compilerOptions }
} = tr.configsFor(config)
return { compilerOptions }
} else {
// auto pick tsconfig from the root folder
return getTsConfigJson()
}
}
const getTsConfigJson = function getTsConfigJson(
pathToConfig = path.resolve(process.cwd(), './tsconfig.json')
) {
const configJson = ts.parseConfigFileTextToJson(
pathToConfig,
ts.sys.readFile(pathToConfig)
)
const { options: compilerOptions } = ts.parseJsonConfigFileContent(
configJson.config,
ts.sys,
ts.getDirectoryPath(pathToConfig),
{},
pathToConfig
)
return { compilerOptions }
}
Or should we use @babel/preset-typescript
to transpile .ts files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eddyerburgh thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For most use cases it would be fine to compile with Babel, it would also simplify the code. The only problem would be if users use const enums, namespaces, or export =
or import =
.
I haven't seen anyone using those features in components, so I think we can go ahead with using Babel for compiling TypeScript.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we added ts-jest, Jest added native support for TypeScript in v24 (which uses Babel), so I think we are fine to remove ts-jest and just use Babel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please make this change in a new PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this. Can you please make another PR to swap ts-jest for babel-jest?
Are you planning to open a PR to remove TypeScript and use babel instead? |
Hey @eddyerburgh , I've not had enough time to work on it. Will create a PR over the weekend |
This PR enables the use of custom script transformers, resolves extends property from tsconfig.json.
Similar to custom CSS transformers this help when we have any custom processing to the script(ts/js/coffee).
For eg. When users do not have babel.config.js at the root of the application but have it at a specific location, we can create a custom babel-transformer by passing in babel-jest's
createTransformer(babelConfig)
with the config pointing to the babel configuration.Fixes, #148, #144