Skip to content

Commit

Permalink
Merge pull request #3017 from phated/phated/cts
Browse files Browse the repository at this point in the history
feat: Support .cts extension with ts-node 10+
  • Loading branch information
fvictorio committed Sep 13, 2022
2 parents d377c39 + 2489ac5 commit c7bfbbc
Show file tree
Hide file tree
Showing 29 changed files with 157 additions and 50 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -11,7 +11,7 @@
"@changesets/cli": "^2.16.0",
"prettier": "2.4.1",
"shelljs": "^0.8.5",
"typescript": "~4.5.2",
"typescript": "~4.7.4",
"wsrun": "^5.2.2"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e/package.json
Expand Up @@ -36,7 +36,7 @@
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"shelljs": "^0.8.5",
"ts-node": "^8.1.0",
"typescript": "~4.5.2"
"ts-node": "^10.8.0",
"typescript": "~4.7.4"
}
}
4 changes: 2 additions & 2 deletions packages/hardhat-chai-matchers/package.json
Expand Up @@ -57,8 +57,8 @@
"mocha": "^10.0.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
"typescript": "~4.5.2"
"ts-node": "^10.8.0",
"typescript": "~4.7.4"
},
"peerDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/hardhat-core/.mocharc.json
Expand Up @@ -3,6 +3,7 @@
"file": "./test/setup.ts",
"exclude": [
"test/fixture-projects/**/*.ts",
"test/fixture-projects/**/*.cts",
"test/fixture-projects/**/*.js",
"test/helpers/**/*.ts"
],
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-core/package.json
Expand Up @@ -93,8 +93,8 @@
"rimraf": "^3.0.2",
"sinon": "^9.0.0",
"time-require": "^0.1.2",
"ts-node": "^8.1.0",
"typescript": "~4.5.2"
"ts-node": "^10.8.0",
"typescript": "~4.7.4"
},
"dependencies": {
"@ethersproject/abi": "^5.1.2",
Expand Down
Expand Up @@ -165,6 +165,8 @@ export function analyzeModuleNotFoundError(error: any, configPath: string) {
const throwingFile = stackTrace
.filter((x) => x.file !== null)
.map((x) => x.file!)
// ignore frames related to source map support
.filter((x) => !x.includes(path.join("@cspotcode", "source-map-support")))
.find((x) => path.isAbsolute(x));

if (throwingFile === null || throwingFile === undefined) {
Expand Down
6 changes: 6 additions & 0 deletions packages/hardhat-core/src/internal/core/project-structure.ts
Expand Up @@ -8,6 +8,7 @@ import { HardhatError } from "./errors";
import { ERRORS } from "./errors-list";
const JS_CONFIG_FILENAME = "hardhat.config.js";
const TS_CONFIG_FILENAME = "hardhat.config.ts";
const CTS_CONFIG_FILENAME = "hardhat.config.cts";

export function isCwdInsideProject() {
return (
Expand All @@ -17,6 +18,11 @@ export function isCwdInsideProject() {
}

export function getUserConfigPath() {
const ctsConfigPath = findUp.sync(CTS_CONFIG_FILENAME);
if (ctsConfigPath !== null) {
return ctsConfigPath;
}

const tsConfigPath = findUp.sync(TS_CONFIG_FILENAME);
if (tsConfigPath !== null) {
return tsConfigPath;
Expand Down
Expand Up @@ -81,5 +81,5 @@ export function loadTsNode(
}

function isTypescriptFile(path: string): boolean {
return path.endsWith(".ts");
return path.endsWith(".ts") || path.endsWith(".cts");
}
Expand Up @@ -139,7 +139,7 @@ export class ConsoleLogger {

private _decode(data: Buffer, types: string[]): ConsoleLogs {
return types.map((type, i) => {
const position = i * 32;
const position: number = i * 32;
switch (types[i]) {
case Uint256Ty:
return bufferToBigInt(
Expand Down
@@ -0,0 +1,8 @@
export default {
networks: {
network: {
url: "",
},
},
solidity: "0.5.15",
};
@@ -0,0 +1,3 @@
{
"type": "module"
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "ESNext"
}
}
Expand Up @@ -33,6 +33,15 @@ describe("Typescript support", function () {
});
});

describe("hardhat.config.cts", function () {
useFixtureProject("typescript-esm-project");
useEnvironment();

it("Should load the config", function () {
assert.isDefined(this.env.config.networks.network);
});
});

describe("Typescript scripts", function () {
useFixtureProject("typescript-project");
useEnvironment();
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-docker/package.json
Expand Up @@ -44,8 +44,8 @@
"mocha": "^10.0.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
"typescript": "~4.5.2"
"ts-node": "^10.8.0",
"typescript": "~4.7.4"
},
"peerDependencies": {},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-ethers/package.json
Expand Up @@ -55,8 +55,8 @@
"mocha": "^10.0.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
"typescript": "~4.5.2"
"ts-node": "^10.8.0",
"typescript": "~4.7.4"
},
"peerDependencies": {
"ethers": "^5.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-etherscan/package.json
Expand Up @@ -67,8 +67,8 @@
"mocha": "^10.0.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
"typescript": "~4.5.2"
"ts-node": "^10.8.0",
"typescript": "~4.7.4"
},
"peerDependencies": {
"hardhat": "^2.0.4"
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-ganache/package.json
Expand Up @@ -55,8 +55,8 @@
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-interface-builder": "^0.2.0",
"ts-node": "^8.1.0",
"typescript": "~4.5.2"
"ts-node": "^10.8.0",
"typescript": "~4.7.4"
},
"peerDependencies": {
"hardhat": "^2.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-network-helpers/package.json
Expand Up @@ -56,8 +56,8 @@
"mocha": "^10.0.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
"typescript": "~4.5.2"
"ts-node": "^10.8.0",
"typescript": "~4.7.4"
},
"peerDependencies": {
"hardhat": "^2.9.5"
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-shorthand/package.json
Expand Up @@ -48,8 +48,8 @@
"mocha": "^10.0.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
"typescript": "~4.5.2"
"ts-node": "^10.8.0",
"typescript": "~4.7.4"
},
"dependencies": {
"@fvictorio/tabtab": "^0.0.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-solhint/package.json
Expand Up @@ -53,8 +53,8 @@
"mocha": "^10.0.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
"typescript": "~4.5.2"
"ts-node": "^10.8.0",
"typescript": "~4.7.4"
},
"peerDependencies": {
"hardhat": "^2.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-solpp/package.json
Expand Up @@ -53,8 +53,8 @@
"mocha": "^10.0.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
"typescript": "~4.5.2"
"ts-node": "^10.8.0",
"typescript": "~4.7.4"
},
"peerDependencies": {
"hardhat": "^2.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-toolbox/package.json
Expand Up @@ -60,9 +60,9 @@
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"solidity-coverage": "^0.7.21",
"ts-node": "^8.1.0",
"ts-node": "^10.8.0",
"typechain": "^8.1.0",
"typescript": "~4.5.2"
"typescript": "~4.7.4"
},
"peerDependencies": {
"@ethersproject/abi": "^5.4.7",
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-truffle4/package.json
Expand Up @@ -56,8 +56,8 @@
"mocha": "^10.0.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
"typescript": "~4.5.2",
"ts-node": "^10.8.0",
"typescript": "~4.7.4",
"web3": "^0.20.0"
},
"peerDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-truffle5/package.json
Expand Up @@ -56,8 +56,8 @@
"mocha": "^10.0.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
"typescript": "~4.5.2",
"ts-node": "^10.8.0",
"typescript": "~4.7.4",
"web3": "^1.0.0-beta.36"
},
"peerDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-vyper/package.json
Expand Up @@ -55,8 +55,8 @@
"mocha": "^10.0.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
"typescript": "~4.5.2"
"ts-node": "^10.8.0",
"typescript": "~4.7.4"
},
"peerDependencies": {
"hardhat": "^2.8.3"
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-waffle/package.json
Expand Up @@ -50,8 +50,8 @@
"mocha": "^10.0.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
"typescript": "~4.5.2"
"ts-node": "^10.8.0",
"typescript": "~4.7.4"
},
"peerDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-web3-legacy/package.json
Expand Up @@ -47,8 +47,8 @@
"mocha": "^10.0.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
"typescript": "~4.5.2",
"ts-node": "^10.8.0",
"typescript": "~4.7.4",
"web3": "^0.20.0"
},
"peerDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-web3/package.json
Expand Up @@ -47,8 +47,8 @@
"mocha": "^10.0.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
"typescript": "~4.5.2",
"ts-node": "^10.8.0",
"typescript": "~4.7.4",
"web3": "^1.0.0-beta.36"
},
"peerDependencies": {
Expand Down

0 comments on commit c7bfbbc

Please sign in to comment.