File tree 4 files changed +33
-8
lines changed
packages/hardhat-core/src
4 files changed +33
-8
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " hardhat " : patch
3
+ ---
4
+
5
+ Added experimental support for using ESM modules with TypeScript
Original file line number Diff line number Diff line change @@ -7,7 +7,11 @@ import { HARDHAT_NETWORK_NAME } from "../internal/constants";
7
7
import { subtask , task } from "../internal/core/config/config-env" ;
8
8
import { HardhatError } from "../internal/core/errors" ;
9
9
import { ERRORS } from "../internal/core/errors-list" ;
10
- import { isRunningWithTypescript } from "../internal/core/typescript-support" ;
10
+ import {
11
+ isJavascriptFile ,
12
+ isRunningWithTypescript ,
13
+ isTypescriptFile ,
14
+ } from "../internal/core/typescript-support" ;
11
15
import { getForkCacheDirPath } from "../internal/hardhat-network/provider/utils/disk-cache" ;
12
16
import { showForkRecommendationsBannerIfNecessary } from "../internal/hardhat-network/provider/utils/fork-recomendations-banner" ;
13
17
import { pluralize } from "../internal/util/strings" ;
@@ -40,15 +44,16 @@ subtask(TASK_TEST_GET_TEST_FILES)
40
44
41
45
const jsFiles = await getAllFilesMatching (
42
46
config . paths . tests ,
43
- ( f ) => f . endsWith ( ".js" ) || f . endsWith ( ".cjs" ) || f . endsWith ( ".mjs" )
47
+ isJavascriptFile
44
48
) ;
45
49
46
50
if ( ! isRunningWithTypescript ( config ) ) {
47
51
return jsFiles ;
48
52
}
49
53
50
- const tsFiles = await getAllFilesMatching ( config . paths . tests , ( f ) =>
51
- f . endsWith ( ".ts" )
54
+ const tsFiles = await getAllFilesMatching (
55
+ config . paths . tests ,
56
+ isTypescriptFile
52
57
) ;
53
58
54
59
return [ ...jsFiles , ...tsFiles ] ;
Original file line number Diff line number Diff line change @@ -10,10 +10,12 @@ import { ERRORS } from "./errors-list";
10
10
const JS_CONFIG_FILENAME = "hardhat.config.js" ;
11
11
const CJS_CONFIG_FILENAME = "hardhat.config.cjs" ;
12
12
const TS_CONFIG_FILENAME = "hardhat.config.ts" ;
13
+ const CTS_CONFIG_FILENAME = "hardhat.config.cts" ;
13
14
14
15
export function isCwdInsideProject ( ) {
15
16
return (
16
17
findUp . sync ( TS_CONFIG_FILENAME ) !== null ||
18
+ findUp . sync ( CTS_CONFIG_FILENAME ) !== null ||
17
19
findUp . sync ( CJS_CONFIG_FILENAME ) !== null ||
18
20
findUp . sync ( JS_CONFIG_FILENAME ) !== null
19
21
) ;
@@ -25,6 +27,11 @@ export function getUserConfigPath() {
25
27
return tsConfigPath ;
26
28
}
27
29
30
+ const ctsConfigPath = findUp . sync ( CTS_CONFIG_FILENAME ) ;
31
+ if ( ctsConfigPath !== null ) {
32
+ return ctsConfigPath ;
33
+ }
34
+
28
35
const cjsConfigPath = findUp . sync ( CJS_CONFIG_FILENAME ) ;
29
36
if ( cjsConfigPath !== null ) {
30
37
return cjsConfigPath ;
Original file line number Diff line number Diff line change @@ -13,14 +13,14 @@ let cachedIsTypescriptSupported: boolean | undefined;
13
13
*/
14
14
export function willRunWithTypescript ( configPath ?: string ) : boolean {
15
15
const config = resolveConfigPath ( configPath ) ;
16
- return isTypescriptFile ( config ) ;
16
+ return isNonEsmTypescriptFile ( config ) ;
17
17
}
18
18
19
19
/**
20
20
* Returns true if an Hardhat is already running with typescript.
21
21
*/
22
22
export function isRunningWithTypescript ( config : HardhatConfig ) : boolean {
23
- return isTypescriptFile ( config . paths . configFile ) ;
23
+ return isNonEsmTypescriptFile ( config . paths . configFile ) ;
24
24
}
25
25
26
26
export function isTypescriptSupported ( ) {
@@ -80,6 +80,14 @@ export function loadTsNode(
80
80
require ( tsNodeRequirement ) ;
81
81
}
82
82
83
- function isTypescriptFile ( path : string ) : boolean {
84
- return path . endsWith ( ".ts" ) ;
83
+ function isNonEsmTypescriptFile ( path : string ) : boolean {
84
+ return / \. ( t s | c t s ) $ / i. test ( path ) ;
85
+ }
86
+
87
+ export function isTypescriptFile ( path : string ) : boolean {
88
+ return / \. ( t s | c t s | m t s ) $ / i. test ( path ) ;
89
+ }
90
+
91
+ export function isJavascriptFile ( path : string ) : boolean {
92
+ return / \. ( j s | c j s | m j s ) $ / i. test ( path ) ;
85
93
}
You can’t perform that action at this time.
0 commit comments