Skip to content

Commit c2ae5a7

Browse files
authored
fix: require ts type error not throw (#270)
* fix: require ts type error not throw * chore: update version
1 parent 78d96c4 commit c2ae5a7

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@artus/core",
3-
"version": "2.2.0",
3+
"version": "2.2.1",
44
"description": "Core package of Artus",
55
"main": "./lib/index.js",
66
"types": "./lib/index.d.ts",
@@ -72,4 +72,4 @@
7272
"ci": {
7373
"version": "16, 18"
7474
}
75-
}
75+
}

src/utils/compatible_require.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ export default async function compatibleRequire(path: string, origin = false): P
1515
/* eslint-disable-next-line @typescript-eslint/no-var-requires */
1616
requiredModule = tslib.__importStar(require(path));
1717
assert(requiredModule, `module '${path}' exports is undefined`);
18-
} catch {
19-
requiredModule = await import(path);
20-
assert(requiredModule, `module '${path}' exports is undefined`);
21-
requiredModule = requiredModule.__esModule ? requiredModule.default ?? requiredModule : requiredModule;
18+
} catch (err) {
19+
if (err.code === 'ERR_REQUIRE_ESM') {
20+
requiredModule = await import(path);
21+
assert(requiredModule, `module '${path}' exports is undefined`);
22+
requiredModule = requiredModule.__esModule ? requiredModule.default ?? requiredModule : requiredModule;
23+
} else {
24+
throw err;
25+
}
2226
}
2327

2428
return origin ? requiredModule : (requiredModule.default || requiredModule);

0 commit comments

Comments
 (0)