Skip to content

Commit 5b0ffd7

Browse files
committed
fix: resolve tsconfig paths with tsx
1 parent 7360437 commit 5b0ffd7

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/configuration/read.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,19 @@ const parseConfigurationFile = async (configurationPath) => {
5656
case '.ts':
5757
case '.mts': {
5858
try {
59-
const { createJiti } = require('jiti');
60-
const jiti = createJiti(null, { interopDefault: true });
59+
// const { createJiti } = require('jiti');
60+
// const jiti = createJiti(null, { interopDefault: true });
61+
// const content = await jiti.import(configurationPath, { default: true });
6162

62-
const content = await jiti.import(configurationPath, { default: true });
63+
/**
64+
* Jiti does not support `tsconfig.paths`, so we need to use tsx to load the configuration file.
65+
* @see https://github.com/unjs/jiti/issues/373
66+
* @see https://tsx.is/dev-api/tsx-require
67+
*/
68+
const tsx = require('tsx/cjs/api');
69+
const content = tsx.require(configurationPath, __filename);
6370

64-
return content;
71+
return content.default ?? content;
6572
} catch (error) {
6673
throw new ServerlessError(
6774
`Cannot parse "${path.basename(configurationPath)}": Initialization error: ${
@@ -145,6 +152,7 @@ module.exports = async (configurationPath) => {
145152
let configuration = await parseConfigurationFile(configurationPath);
146153

147154
if (!isPlainObject(configuration)) {
155+
console.log('configuration', configuration);
148156
throw new ServerlessError(
149157
`Invalid configuration at "${path.basename(configurationPath)}": Plain object expected`,
150158
'INVALID_CONFIGURATION_EXPORT'

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"strip-ansi": "^6.0.1",
7474
"supports-color": "^8.1.1",
7575
"timers-ext": "^0.1.7",
76+
"tsx": "^4.20.3",
7677
"type": "^2.7.2",
7778
"untildify": "^4.0.0",
7879
"uuid": "^9.0.0",

0 commit comments

Comments
 (0)