Skip to content

Commit 3068866

Browse files
authored
chore: Adjust tsconfig and Mocha settings for ESM support (#10)
- Updated tsconfig.test.json for CommonJS module resolution. - Modified Mocha test script to ensure correct tsconfig is used. - Attempted various configurations to resolve ESM loader issues with Node v18.16.0. Note: Further investigation may be needed to fully support ESM with the current Node version.
1 parent c0d96b2 commit 3068866

File tree

6 files changed

+25
-5
lines changed

6 files changed

+25
-5
lines changed

.mocharc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"require": "ts-node/register",
3+
"extension": ["ts"],
4+
"spec": "test/**/*.test.ts",
5+
"watch-files": ["src/**/*.ts", "test/**/*.ts"]
6+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
"fetchdoc": "./dist/index.js"
88
},
99
"scripts": {
10-
"build": "rollup -c",
10+
"build": "tsc -p tsconfig.json && rollup -c",
1111
"start": "node ./dist/index.js",
1212
"lint": "eslint 'src/**/*.{js,ts}'",
1313
"lint:fix": "eslint 'src/**/*.{js,ts}' --fix",
14-
"test": "mocha -r ts-node/register 'test/**/*.test.ts'",
14+
"test": "TS_NODE_PROJECT=tsconfig.test.json mocha --require ts-node/register test/**/*.test.ts",
1515
"version": "auto-changelog -p && git add CHANGELOG.md",
1616
"postbuild": "chmod +x dist/index.js"
1717
},

rollup.config.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ export default {
1212
format: 'cjs',
1313
banner: '#!/usr/bin/env node',
1414
},
15-
external: ['tslib', 'child_process', 'axios'],
15+
external: ['tslib', 'child_process', 'axios', 'yargs'],
1616
plugins: [
1717
typescript({ exclude: 'node_modules' }),
1818
nodeResolve({ exportConditions: ['node'], preferBuiltins: false }),
1919
commonjs({ includes: 'node_modules/**' }),
2020
json(),
2121
replace({
22+
preventAssignment: true,
2223
VERSION: JSON.stringify(pkg.version),
2324
}),
2425
],

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ yargs(hideBin(process.argv))
5555
description: 'Display the README in the terminal',
5656
})
5757
.help()
58-
.wrap(yargs.terminalWidth())
58+
.wrap(process.stdout.columns || 80)
5959
.check((argv) => {
6060
if (!argv.package) {
6161
throw new Error('The <package> argument is required.')

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"rootDir": "./src",
44
"target": "ESNext",
5-
"module": "CommonJS",
5+
"module": "ESNext",
66
"esModuleInterop": true,
77
"moduleResolution": "node",
88
"forceConsistentCasingInFileNames": true,

tsconfig.test.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"module": "CommonJS",
5+
"esModuleInterop": true,
6+
"moduleResolution": "node",
7+
"strict": true,
8+
"noEmit": true,
9+
"skipLibCheck": true
10+
},
11+
"include": ["test/**/*.ts"],
12+
"exclude": ["node_modules"]
13+
}

0 commit comments

Comments
 (0)