Skip to content

feat: Add .cts to support typescript 4.7 #90

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

Merged
merged 5 commits into from
Jun 29, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add cts file extension, treated identically to ts
  • Loading branch information
cspotcode committed May 19, 2022
commit 355f7dcd080f278cb165073af342aeca7730dc46
65 changes: 65 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ function endsInJsx(filename) {
function endsInTs(filename) {
return filename.endsWith('.ts');
}
function endsInCts(filename) {
return filename.endsWith('.cts');
}
function endsInTsx(filename) {
return filename.endsWith('.tsx');
}
Expand Down Expand Up @@ -425,6 +428,68 @@ var extensions = {
},
},
],
'.cts': [
'ts-node/register',
'sucrase/register/ts',
{
module: '@babel/register',
register: function (hook, config) {
config = config || {
rootMode: 'upward-optional',
overrides: [
{
only: [endsInCts],
presets: ['@babel/preset-env', '@babel/preset-typescript'],
},
],
};

hook(
Object.assign({}, config, {
extensions: '.cts',
})
);
},
},
{
module: 'esbuild-register/dist/node',
register: function (mod, config) {
config = config || {
target: 'node' + process.version.slice(1),
hookMatcher: endsInTs,
};

mod.register(
Object.assign({}, config, {
extensions: ['.cts'],
})
);
},
},
{
module: '@swc/register',
register: function (hook, config) {
config = config || {
only: [endsInCts],
ignore: [isNodeModules],
jsc: {
parser: {
syntax: 'typescript',
},
},
module: {
type: 'commonjs',
},
};

hook(
Object.assign({}, config, {
extensions: '.cts',
})
);
},
},
],
'.tsx': [
'ts-node/register',
'sucrase/register/tsx',
Expand Down