-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(legacy/utils,legacy/cli): no jiti in utils, but use it as default…
… JS importer in cli (#7360) * no jiti utils * chore(dependencies): updated changesets for modified dependencies * changewset * jiti in cli as defaultImportFn * changeset * chore(dependencies): updated changesets for modified dependencies * use .js * cli defaultImportFn gets default * create jiti on-demand --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
6bbe249
commit 5e5dec5
Showing
11 changed files
with
69 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@graphql-mesh/cli": patch | ||
--- | ||
dependencies updates: | ||
- Added dependency [`jiti@^1.21.6` ↗︎](https://www.npmjs.com/package/jiti/v/1.21.6) (to `dependencies`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@graphql-mesh/utils": patch | ||
--- | ||
dependencies updates: | ||
- Removed dependency [`jiti@^1.21.6` ↗︎](https://www.npmjs.com/package/jiti/v/1.21.6) (from `dependencies`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@graphql-mesh/utils': patch | ||
--- | ||
|
||
No jiti, keep the utils JS env agnostic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@graphql-mesh/cli': patch | ||
--- | ||
|
||
Use jiti as default JS importer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import createJITI, { type JITI } from 'jiti'; | ||
import type { ImportFn } from '@graphql-mesh/types'; | ||
|
||
let jiti: JITI; | ||
function getOrCreateImportFn(): ImportFn { | ||
if (!jiti) { | ||
// we instantiate on demand because sometimes jiti is not used | ||
jiti = createJITI(__filename); | ||
} | ||
return id => jiti.import(id, {}) as Promise<any>; | ||
} | ||
|
||
export const defaultImportFn: ImportFn = async id => { | ||
let module: any = await getOrCreateImportFn()(id); | ||
if (module.default != null) { | ||
module = module.default; | ||
} | ||
if (typeof module === 'object' && module != null) { | ||
const prototypeOfObject = Object.getPrototypeOf(module); | ||
if (prototypeOfObject == null || prototypeOfObject === Object.prototype) { | ||
const normalizedVal: Record<string, any> = {}; | ||
for (const key in module) { | ||
normalizedVal[key] = module[key]; | ||
} | ||
return normalizedVal; | ||
} | ||
} | ||
return module; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters