-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support ESM projects using TypeScript with ts-node/esm (#22118)
* fix: support ESM projects using TypeScript with ts-node/esm * better error handling * fix test * indentation * register ts-node via --require hook * be less aggressive with erroring * update fix system tests * remove obsolete test * handle case of not using typescript * replicate 9.x behavior for legacy plugins w/ ts-node * make test project valid and adjust tests accordingly * use ts-node/esm transpile only * dummy * extract util function * merge in refactor using projectFixtureDirectory * fix test
- Loading branch information
1 parent
fccce5d
commit abd986a
Showing
63 changed files
with
318 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export function hasTypeScriptInstalled (projectRoot: string) { | ||
try { | ||
require.resolve('typescript', { paths: [projectRoot] }) | ||
|
||
return true | ||
} catch (e) { | ||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/data-context/test/unit/util/hasTypescript.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { expect } from 'chai' | ||
import path from 'path' | ||
import { hasTypeScriptInstalled } from '../../../src/util' | ||
import { scaffoldMigrationProject } from '../helper' | ||
|
||
describe('hasTypeScript', () => { | ||
it('returns true when installed', async () => { | ||
const monorepoRoot = path.join(__dirname, '..', '..', '..', '..', '..') | ||
|
||
expect(hasTypeScriptInstalled(monorepoRoot)).to.be.true | ||
}) | ||
|
||
it('returns false when not installed', async () => { | ||
const projectRoot = await scaffoldMigrationProject('config-with-js') | ||
|
||
expect(hasTypeScriptInstalled(projectRoot)).to.be.false | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const minimist = require('minimist') | ||
const debugLib = require('debug') | ||
const { register } = require('./ts_node') | ||
|
||
const debug = debugLib('cypress:server:register-ts-node') | ||
|
||
const args = minimist(process.argv) | ||
|
||
debug('executing register_ts_node with args %o', args) | ||
|
||
const { projectRoot, file } = args | ||
|
||
if (projectRoot && file) { | ||
debug('registering ts-node for projectRoot: %s and file: %s', projectRoot, file) | ||
register(projectRoot, file) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
7 changes: 0 additions & 7 deletions
7
system-tests/projects/config-cjs-and-esm/config-with-cjs-tsconfig-es5/cypress/e2e/app.cy.js
This file was deleted.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
system-tests/projects/config-cjs-and-esm/config-with-cjs-tsconfig-es5/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"devDependencies": { | ||
"typescript": "4.7.3" | ||
}, | ||
"projectFixtureDirectory": "simple_passing" | ||
} |
8 changes: 8 additions & 0 deletions
8
system-tests/projects/config-cjs-and-esm/config-with-cjs-tsconfig-es5/yarn.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
typescript@4.7.3: | ||
version "4.7.3" | ||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.3.tgz#8364b502d5257b540f9de4c40be84c98e23a129d" | ||
integrity sha512-WOkT3XYvrpXx4vMMqlD+8R8R37fZkjyLGlxavMc4iB8lrl8L0DeTcHbYgw/v0N/z9wAFsgBhcsF0ruoySS22mA== |
3 changes: 3 additions & 0 deletions
3
system-tests/projects/config-cjs-and-esm/config-with-cjs/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"projectFixtureDirectory": "simple_passing" | ||
} |
4 changes: 4 additions & 0 deletions
4
system-tests/projects/config-cjs-and-esm/config-with-cjs/yarn.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
3 changes: 0 additions & 3 deletions
3
system-tests/projects/config-cjs-and-esm/config-with-js-module/cypress/e2e/app.cy.js
This file was deleted.
Oops, something went wrong.
3 changes: 2 additions & 1 deletion
3
system-tests/projects/config-cjs-and-esm/config-with-js-module/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"type": "module" | ||
"type": "module", | ||
"projectFixtureDirectory": "simple_passing" | ||
} |
4 changes: 4 additions & 0 deletions
4
system-tests/projects/config-cjs-and-esm/config-with-js-module/yarn.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
7 changes: 0 additions & 7 deletions
7
...em-tests/projects/config-cjs-and-esm/config-with-js-tsconfig-es2015/cypress/e2e/app.cy.js
This file was deleted.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
system-tests/projects/config-cjs-and-esm/config-with-js-tsconfig-es2015/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"devDependencies": { | ||
"typescript": "4.7.3" | ||
}, | ||
"projectFixtureDirectory": "simple_passing" | ||
} |
1 change: 0 additions & 1 deletion
1
system-tests/projects/config-cjs-and-esm/config-with-js-tsconfig-es2015/src/foo.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
abd986a
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.
Circle has built the
linux x64
version of the Test Runner.Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally:
abd986a
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.
Circle has built the
darwin x64
version of the Test Runner.Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally:
abd986a
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.
Circle has built the
win32 x64
version of the Test Runner.Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally: