Skip to content
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: Add .cts to support typescript 4.7 #90

Merged
merged 5 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
29 changes: 29 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,32 @@ var extensions = {
},
},
],
'.cts': [
'ts-node/register',
{
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',
})
);
},
},
phated marked this conversation as resolved.
Show resolved Hide resolved
],
'.tsx': [
'ts-node/register',
'sucrase/register/tsx',
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/cts/0/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"ts-node": "^10.8.0",
"typescript": "^4.7.4"
}
}
19 changes: 19 additions & 0 deletions test/fixtures/cts/0/test.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var test: {
data: {
trueKey: boolean;
falseKey: boolean;
subKey: {
subProp: number;
};
};
} = {
data: {
trueKey: true,
falseKey: false,
subKey: {
subProp: 1,
},
},
};

export default test;
11 changes: 11 additions & 0 deletions test/fixtures/cts/0/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"sourceMap": true,
"outDir": ".tmp"
}
}
5 changes: 5 additions & 0 deletions test/fixtures/cts/1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
phated marked this conversation as resolved.
Show resolved Hide resolved
"dependencies": {
"sucrase": "^3.12.1"
}
}
25 changes: 25 additions & 0 deletions test/fixtures/cts/1/test.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var test: {
data: {
trueKey: boolean;
falseKey: boolean;
subKey: {
subProp: number;
};
};
} = {
data: {
trueKey: true,
falseKey: false,
subKey: {
subProp: 1,
},
},
};

var main: {
default: typeof test;
} = {
default: test,
};

export = main;
11 changes: 11 additions & 0 deletions test/fixtures/cts/1/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"sourceMap": true,
"outDir": ".tmp"
}
}
8 changes: 8 additions & 0 deletions test/fixtures/cts/2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"dependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.3",
"@babel/preset-typescript": "^7.1.0",
"@babel/register": "^7.0.0"
}
}
19 changes: 19 additions & 0 deletions test/fixtures/cts/2/test.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var test: {
data: {
trueKey: boolean;
falseKey: boolean;
subKey: {
subProp: number;
};
};
} = {
data: {
trueKey: true,
falseKey: false,
subKey: {
subProp: 1,
},
},
};

export default test;
6 changes: 6 additions & 0 deletions test/fixtures/cts/3/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"esbuild": "^0.14.29",
"esbuild-register": "^3.3.2"
}
}
13 changes: 13 additions & 0 deletions test/fixtures/cts/3/test.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function add(x: number, y: number): number {
return x + y;
}

export default {
data: {
trueKey: true as boolean,
falseKey: false as boolean,
subKey: {
subProp: add(0.5, 0.5),
},
},
};
6 changes: 6 additions & 0 deletions test/fixtures/cts/4/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"@swc/core": "^1.2.110",
"@swc/register": "^0.1.7"
}
}
15 changes: 15 additions & 0 deletions test/fixtures/cts/4/test.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var test = {
data: {
trueKey: true,
falseKey: false,
subKey: {
subProp: 1,
},
},
};

var main = {
default: test,
};

export = main;
4 changes: 2 additions & 2 deletions test/fixtures/ts/0/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"ts-node": "^7.0.1",
"typescript": "^3.2.2"
"ts-node": "^10.8.0",
"typescript": "^4.7.4"
}
}
4 changes: 2 additions & 2 deletions test/fixtures/tsx/0/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"ts-node": "^7.0.1",
"typescript": "^3.2.2"
"ts-node": "^10.8.0",
"typescript": "4.7.4"
}
}
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ describe('interpret.extensions', function () {

switch (extension) {
case '.ts':
case '.cts':
case '.tsx':
case '.esm.js':
case '.babel.tsx':
Expand Down