Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: require ts type error not throw #270

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading