From 355f7dcd080f278cb165073af342aeca7730dc46 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Wed, 18 May 2022 22:50:39 -0400 Subject: [PATCH 1/5] add cts file extension, treated identically to ts --- index.js | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/index.js b/index.js index 8c79279..293c8a2 100644 --- a/index.js +++ b/index.js @@ -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'); } @@ -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', From f1e517e2401bf8b9526be458730265a24df47f3b Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Wed, 18 May 2022 23:08:09 -0400 Subject: [PATCH 2/5] Add cts tests; update ts-node dependency in tests --- test/fixtures/cts/0/package.json | 6 ++++++ test/fixtures/cts/0/test.cts | 19 +++++++++++++++++++ test/fixtures/cts/0/tsconfig.json | 11 +++++++++++ test/fixtures/cts/1/package.json | 5 +++++ test/fixtures/cts/1/test.cts | 25 +++++++++++++++++++++++++ test/fixtures/cts/1/tsconfig.json | 11 +++++++++++ test/fixtures/cts/2/package.json | 8 ++++++++ test/fixtures/cts/2/test.cts | 19 +++++++++++++++++++ test/fixtures/cts/3/package.json | 6 ++++++ test/fixtures/cts/3/test.cts | 13 +++++++++++++ test/fixtures/cts/4/package.json | 6 ++++++ test/fixtures/cts/4/test.cts | 15 +++++++++++++++ test/fixtures/ts/0/package.json | 2 +- test/fixtures/tsx/0/package.json | 2 +- test/index.js | 1 + 15 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/cts/0/package.json create mode 100644 test/fixtures/cts/0/test.cts create mode 100644 test/fixtures/cts/0/tsconfig.json create mode 100644 test/fixtures/cts/1/package.json create mode 100644 test/fixtures/cts/1/test.cts create mode 100644 test/fixtures/cts/1/tsconfig.json create mode 100644 test/fixtures/cts/2/package.json create mode 100644 test/fixtures/cts/2/test.cts create mode 100644 test/fixtures/cts/3/package.json create mode 100644 test/fixtures/cts/3/test.cts create mode 100644 test/fixtures/cts/4/package.json create mode 100644 test/fixtures/cts/4/test.cts diff --git a/test/fixtures/cts/0/package.json b/test/fixtures/cts/0/package.json new file mode 100644 index 0000000..676e9bd --- /dev/null +++ b/test/fixtures/cts/0/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "ts-node": "^10.7.0", + "typescript": "^3.2.2" + } +} diff --git a/test/fixtures/cts/0/test.cts b/test/fixtures/cts/0/test.cts new file mode 100644 index 0000000..3fa0969 --- /dev/null +++ b/test/fixtures/cts/0/test.cts @@ -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; diff --git a/test/fixtures/cts/0/tsconfig.json b/test/fixtures/cts/0/tsconfig.json new file mode 100644 index 0000000..ca687b6 --- /dev/null +++ b/test/fixtures/cts/0/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "es5", + "module": "commonjs", + "declaration": false, + "noImplicitAny": false, + "removeComments": true, + "sourceMap": true, + "outDir": ".tmp" + } +} diff --git a/test/fixtures/cts/1/package.json b/test/fixtures/cts/1/package.json new file mode 100644 index 0000000..dc0534c --- /dev/null +++ b/test/fixtures/cts/1/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "sucrase": "^3.12.1" + } +} diff --git a/test/fixtures/cts/1/test.cts b/test/fixtures/cts/1/test.cts new file mode 100644 index 0000000..c755421 --- /dev/null +++ b/test/fixtures/cts/1/test.cts @@ -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; diff --git a/test/fixtures/cts/1/tsconfig.json b/test/fixtures/cts/1/tsconfig.json new file mode 100644 index 0000000..ca687b6 --- /dev/null +++ b/test/fixtures/cts/1/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "es5", + "module": "commonjs", + "declaration": false, + "noImplicitAny": false, + "removeComments": true, + "sourceMap": true, + "outDir": ".tmp" + } +} diff --git a/test/fixtures/cts/2/package.json b/test/fixtures/cts/2/package.json new file mode 100644 index 0000000..cc3213f --- /dev/null +++ b/test/fixtures/cts/2/package.json @@ -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" + } +} diff --git a/test/fixtures/cts/2/test.cts b/test/fixtures/cts/2/test.cts new file mode 100644 index 0000000..3fa0969 --- /dev/null +++ b/test/fixtures/cts/2/test.cts @@ -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; diff --git a/test/fixtures/cts/3/package.json b/test/fixtures/cts/3/package.json new file mode 100644 index 0000000..b32c446 --- /dev/null +++ b/test/fixtures/cts/3/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "esbuild": "^0.14.29", + "esbuild-register": "^3.3.2" + } +} diff --git a/test/fixtures/cts/3/test.cts b/test/fixtures/cts/3/test.cts new file mode 100644 index 0000000..5bd9e99 --- /dev/null +++ b/test/fixtures/cts/3/test.cts @@ -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), + }, + }, +}; diff --git a/test/fixtures/cts/4/package.json b/test/fixtures/cts/4/package.json new file mode 100644 index 0000000..e345156 --- /dev/null +++ b/test/fixtures/cts/4/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "@swc/core": "^1.2.110", + "@swc/register": "^0.1.7" + } +} diff --git a/test/fixtures/cts/4/test.cts b/test/fixtures/cts/4/test.cts new file mode 100644 index 0000000..5044977 --- /dev/null +++ b/test/fixtures/cts/4/test.cts @@ -0,0 +1,15 @@ +var test = { + data: { + trueKey: true, + falseKey: false, + subKey: { + subProp: 1, + }, + }, +}; + +var main = { + default: test, +}; + +export = main; diff --git a/test/fixtures/ts/0/package.json b/test/fixtures/ts/0/package.json index 5240475..676e9bd 100644 --- a/test/fixtures/ts/0/package.json +++ b/test/fixtures/ts/0/package.json @@ -1,6 +1,6 @@ { "dependencies": { - "ts-node": "^7.0.1", + "ts-node": "^10.7.0", "typescript": "^3.2.2" } } diff --git a/test/fixtures/tsx/0/package.json b/test/fixtures/tsx/0/package.json index 5240475..676e9bd 100644 --- a/test/fixtures/tsx/0/package.json +++ b/test/fixtures/tsx/0/package.json @@ -1,6 +1,6 @@ { "dependencies": { - "ts-node": "^7.0.1", + "ts-node": "^10.7.0", "typescript": "^3.2.2" } } diff --git a/test/index.js b/test/index.js index 295a860..1f9ca83 100644 --- a/test/index.js +++ b/test/index.js @@ -154,6 +154,7 @@ describe('interpret.extensions', function () { switch (extension) { case '.ts': + case '.cts': case '.tsx': case '.esm.js': case '.babel.tsx': From 5d804fe4286bbc7e026df289567eeec70a25b2d8 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Sat, 21 May 2022 14:54:40 -0400 Subject: [PATCH 3/5] update typescript and ts-node versions, remove failing .cts hooks --- index.js | 36 -------------------------------- test/fixtures/cts/0/package.json | 4 ++-- test/fixtures/ts/0/package.json | 4 ++-- test/fixtures/tsx/0/package.json | 4 ++-- 4 files changed, 6 insertions(+), 42 deletions(-) diff --git a/index.js b/index.js index 293c8a2..caf56a0 100644 --- a/index.js +++ b/index.js @@ -430,42 +430,6 @@ 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) { diff --git a/test/fixtures/cts/0/package.json b/test/fixtures/cts/0/package.json index 676e9bd..6228386 100644 --- a/test/fixtures/cts/0/package.json +++ b/test/fixtures/cts/0/package.json @@ -1,6 +1,6 @@ { "dependencies": { - "ts-node": "^10.7.0", - "typescript": "^3.2.2" + "ts-node": "^10.8.0", + "typescript": "^4.7.1-rc" } } diff --git a/test/fixtures/ts/0/package.json b/test/fixtures/ts/0/package.json index 676e9bd..6228386 100644 --- a/test/fixtures/ts/0/package.json +++ b/test/fixtures/ts/0/package.json @@ -1,6 +1,6 @@ { "dependencies": { - "ts-node": "^10.7.0", - "typescript": "^3.2.2" + "ts-node": "^10.8.0", + "typescript": "^4.7.1-rc" } } diff --git a/test/fixtures/tsx/0/package.json b/test/fixtures/tsx/0/package.json index 676e9bd..e612847 100644 --- a/test/fixtures/tsx/0/package.json +++ b/test/fixtures/tsx/0/package.json @@ -1,6 +1,6 @@ { "dependencies": { - "ts-node": "^10.7.0", - "typescript": "^3.2.2" + "ts-node": "^10.8.0", + "typescript": "4.7.1-rc" } } From 0140599d5f8453cac6f2e38d72dbf3da72448149 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Sun, 26 Jun 2022 23:32:48 -0400 Subject: [PATCH 4/5] update ts dep --- test/fixtures/cts/0/package.json | 2 +- test/fixtures/ts/0/package.json | 2 +- test/fixtures/tsx/0/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/fixtures/cts/0/package.json b/test/fixtures/cts/0/package.json index 6228386..e11b5ba 100644 --- a/test/fixtures/cts/0/package.json +++ b/test/fixtures/cts/0/package.json @@ -1,6 +1,6 @@ { "dependencies": { "ts-node": "^10.8.0", - "typescript": "^4.7.1-rc" + "typescript": "^4.7.4" } } diff --git a/test/fixtures/ts/0/package.json b/test/fixtures/ts/0/package.json index 6228386..e11b5ba 100644 --- a/test/fixtures/ts/0/package.json +++ b/test/fixtures/ts/0/package.json @@ -1,6 +1,6 @@ { "dependencies": { "ts-node": "^10.8.0", - "typescript": "^4.7.1-rc" + "typescript": "^4.7.4" } } diff --git a/test/fixtures/tsx/0/package.json b/test/fixtures/tsx/0/package.json index e612847..b5ae145 100644 --- a/test/fixtures/tsx/0/package.json +++ b/test/fixtures/tsx/0/package.json @@ -1,6 +1,6 @@ { "dependencies": { "ts-node": "^10.8.0", - "typescript": "4.7.1-rc" + "typescript": "4.7.4" } } From fd3e4ba457a1e4a2e814518735defc1ec36b9339 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Tue, 28 Jun 2022 17:19:06 -0700 Subject: [PATCH 5/5] Remove non ts-node code --- index.js | 30 +----------------------------- test/fixtures/cts/1/package.json | 5 ----- test/fixtures/cts/1/test.cts | 25 ------------------------- test/fixtures/cts/1/tsconfig.json | 11 ----------- test/fixtures/cts/2/package.json | 8 -------- test/fixtures/cts/2/test.cts | 19 ------------------- test/fixtures/cts/3/package.json | 6 ------ test/fixtures/cts/3/test.cts | 13 ------------- test/fixtures/cts/4/package.json | 6 ------ test/fixtures/cts/4/test.cts | 15 --------------- 10 files changed, 1 insertion(+), 137 deletions(-) delete mode 100644 test/fixtures/cts/1/package.json delete mode 100644 test/fixtures/cts/1/test.cts delete mode 100644 test/fixtures/cts/1/tsconfig.json delete mode 100644 test/fixtures/cts/2/package.json delete mode 100644 test/fixtures/cts/2/test.cts delete mode 100644 test/fixtures/cts/3/package.json delete mode 100644 test/fixtures/cts/3/test.cts delete mode 100644 test/fixtures/cts/4/package.json delete mode 100644 test/fixtures/cts/4/test.cts diff --git a/index.js b/index.js index caf56a0..b951fd9 100644 --- a/index.js +++ b/index.js @@ -8,9 +8,6 @@ function endsInJsx(filename) { function endsInTs(filename) { return filename.endsWith('.ts'); } -function endsInCts(filename) { - return filename.endsWith('.cts'); -} function endsInTsx(filename) { return filename.endsWith('.tsx'); } @@ -428,32 +425,7 @@ 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', - }) - ); - }, - }, - ], + '.cts': ['ts-node/register'], '.tsx': [ 'ts-node/register', 'sucrase/register/tsx', diff --git a/test/fixtures/cts/1/package.json b/test/fixtures/cts/1/package.json deleted file mode 100644 index dc0534c..0000000 --- a/test/fixtures/cts/1/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "dependencies": { - "sucrase": "^3.12.1" - } -} diff --git a/test/fixtures/cts/1/test.cts b/test/fixtures/cts/1/test.cts deleted file mode 100644 index c755421..0000000 --- a/test/fixtures/cts/1/test.cts +++ /dev/null @@ -1,25 +0,0 @@ -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; diff --git a/test/fixtures/cts/1/tsconfig.json b/test/fixtures/cts/1/tsconfig.json deleted file mode 100644 index ca687b6..0000000 --- a/test/fixtures/cts/1/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "compilerOptions": { - "target": "es5", - "module": "commonjs", - "declaration": false, - "noImplicitAny": false, - "removeComments": true, - "sourceMap": true, - "outDir": ".tmp" - } -} diff --git a/test/fixtures/cts/2/package.json b/test/fixtures/cts/2/package.json deleted file mode 100644 index cc3213f..0000000 --- a/test/fixtures/cts/2/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "dependencies": { - "@babel/core": "^7.2.2", - "@babel/preset-env": "^7.2.3", - "@babel/preset-typescript": "^7.1.0", - "@babel/register": "^7.0.0" - } -} diff --git a/test/fixtures/cts/2/test.cts b/test/fixtures/cts/2/test.cts deleted file mode 100644 index 3fa0969..0000000 --- a/test/fixtures/cts/2/test.cts +++ /dev/null @@ -1,19 +0,0 @@ -var test: { - data: { - trueKey: boolean; - falseKey: boolean; - subKey: { - subProp: number; - }; - }; -} = { - data: { - trueKey: true, - falseKey: false, - subKey: { - subProp: 1, - }, - }, -}; - -export default test; diff --git a/test/fixtures/cts/3/package.json b/test/fixtures/cts/3/package.json deleted file mode 100644 index b32c446..0000000 --- a/test/fixtures/cts/3/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "dependencies": { - "esbuild": "^0.14.29", - "esbuild-register": "^3.3.2" - } -} diff --git a/test/fixtures/cts/3/test.cts b/test/fixtures/cts/3/test.cts deleted file mode 100644 index 5bd9e99..0000000 --- a/test/fixtures/cts/3/test.cts +++ /dev/null @@ -1,13 +0,0 @@ -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), - }, - }, -}; diff --git a/test/fixtures/cts/4/package.json b/test/fixtures/cts/4/package.json deleted file mode 100644 index e345156..0000000 --- a/test/fixtures/cts/4/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "dependencies": { - "@swc/core": "^1.2.110", - "@swc/register": "^0.1.7" - } -} diff --git a/test/fixtures/cts/4/test.cts b/test/fixtures/cts/4/test.cts deleted file mode 100644 index 5044977..0000000 --- a/test/fixtures/cts/4/test.cts +++ /dev/null @@ -1,15 +0,0 @@ -var test = { - data: { - trueKey: true, - falseKey: false, - subKey: { - subProp: 1, - }, - }, -}; - -var main = { - default: test, -}; - -export = main;