Skip to content

Commit

Permalink
fix: require ts type error not throw (#270)
Browse files Browse the repository at this point in the history
* fix: require ts type error not throw

* chore: update version
  • Loading branch information
JerrysShan authored Jan 4, 2024
1 parent 78d96c4 commit c2ae5a7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@artus/core",
"version": "2.2.0",
"version": "2.2.1",
"description": "Core package of Artus",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down Expand Up @@ -72,4 +72,4 @@
"ci": {
"version": "16, 18"
}
}
}
12 changes: 8 additions & 4 deletions src/utils/compatible_require.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ export default async function compatibleRequire(path: string, origin = false): P
/* eslint-disable-next-line @typescript-eslint/no-var-requires */
requiredModule = tslib.__importStar(require(path));
assert(requiredModule, `module '${path}' exports is undefined`);
} catch {
requiredModule = await import(path);
assert(requiredModule, `module '${path}' exports is undefined`);
requiredModule = requiredModule.__esModule ? requiredModule.default ?? requiredModule : requiredModule;
} catch (err) {
if (err.code === 'ERR_REQUIRE_ESM') {
requiredModule = await import(path);
assert(requiredModule, `module '${path}' exports is undefined`);
requiredModule = requiredModule.__esModule ? requiredModule.default ?? requiredModule : requiredModule;
} else {
throw err;
}
}

return origin ? requiredModule : (requiredModule.default || requiredModule);
Expand Down

0 comments on commit c2ae5a7

Please sign in to comment.