-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
feat: allow passing TS config loader options #15234
Conversation
✅ Deploy Preview for jestjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
swc: extraTSLoaderOptions?.swc, | ||
transpileOnly: extraTSLoaderOptions?.transpileOnly, |
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.
Instead of setting these two, can we just spread the config passed?
i.e.
tsLoader.register({
compilerOptions: {
module: 'CommonJS',
},
moduleTypes: {
'**': 'cjs',
},
...extraTSLoaderOptions,
});
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.
I thought the same but not sure if it's a good idea to expose all options or not, done 4223489
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.
if people misconfigure, that's on them. I think exposing the API is better than having to expose more in the future
|
||
if (typeof docblockTSLoaderOptions === 'string') { | ||
extraTSLoaderOptions = JSON.parse(docblockTSLoaderOptions); |
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.
these should be passed to esbuild-register
as well
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! I like this approach 👍
@@ -89,13 +89,19 @@ export default async function readConfigFileAndSetRootDir( | |||
} | |||
|
|||
// Load the TypeScript configuration | |||
let extraTSLoaderOptions: Record<string, unknown>; | |||
|
|||
const loadTSConfigFile = async ( | |||
configPath: string, | |||
): Promise<Config.InitialOptions> => { | |||
// Get registered TypeScript compiler instance | |||
const docblockPragmas = parse(extract(fs.readFileSync(configPath, 'utf8'))); | |||
const tsLoader = docblockPragmas['jest-config-loader'] || 'ts-node'; |
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.
should we also change this default behavior of using ts-node if no loader is passed in a separate PR? it will be a breaking change though
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.
that's a separate thing, yeah. happy to take a 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!
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Follow up #15190
this will allow us to pass config loader options in a docblock comment.
Currently, valid options are
swc
andtranspileOnly
, these options are useful if someone is usingts-node
for loading ts config files.Test plan
Added e2e test