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

Use jiti instead of tsx for importing TS and JS config files #7261

Merged
merged 10 commits into from
Jul 10, 2024
Merged

Conversation

enisdenjo
Copy link
Collaborator

@enisdenjo enisdenjo commented Jul 10, 2024

Closes #7225, closes #7213, supersedes #7131

JITI has two main benefits: it is zero-dep and it does not pollute node's environment - it has its own standalone import function.

Changes apply to both v0 and v1.

Copy link
Contributor

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@graphql-mesh/cache-cfw-kv 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/cache-file 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/cache-localforage 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/cache-redis 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/compose-cli 0.5.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/fusion-composition 0.1.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/fusion-runtime 0.5.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/apollo-link 0.100.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/cli 0.92.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/config 0.101.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/graphql 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/grpc 0.101.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/json-schema 0.102.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/mongoose 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/mysql 0.100.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/neo4j 0.100.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/odata 0.100.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/openapi 0.102.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/postgraphile 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/raml 0.102.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/soap 0.101.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/supergraph 0.5.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/thrift 0.101.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/tuql 0.100.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/http 0.100.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/merger-bare 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/merger-federation 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/merger-stitching 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/runtime 0.100.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/store 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-cache 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-encapsulate 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-extend 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-federation 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-filter-schema 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-hive 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-hoist-field 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-naming-convention 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-prefix 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-prune 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-rate-limit 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-rename 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-replace-field 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-resolvers-composition 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-transfer-schema 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-type-merging 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/types 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/urql-exchange 0.100.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/utils 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@omnigraph/json-schema 0.102.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@omnigraph/mysql 0.4.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@omnigraph/neo4j 0.4.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@omnigraph/openapi 0.102.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@omnigraph/raml 0.102.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@omnigraph/soap 0.101.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@omnigraph/sqlite 0.3.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@omnigraph/thrift 0.4.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-deduplicate-request 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-hive 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-http-cache 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-http-details-extensions 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-live-query 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-mock 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-newrelic 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-operation-field-permissions 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-operation-headers 0.3.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-prometheus 0.102.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-rate-limit 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-response-cache 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-snapshot 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-statsd 0.99.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/serve-cli 0.7.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/serve-runtime 0.5.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-common 0.4.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-http 0.3.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-mysql 0.4.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-neo4j 0.4.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-rest 0.4.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-soap 0.4.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-sqlite 0.3.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-thrift 0.4.0-alpha-20240710165540-0930b21e00aa9380e7bad7d2ad6977f1b5107329 npm ↗︎ unpkg ↗︎

@enisdenjo enisdenjo requested a review from ardatan July 10, 2024 16:58
Copy link
Contributor

💻 Website Preview

The latest changes are available as preview in: https://bd6cc2f3.graphql-mesh.pages.dev

@enisdenjo enisdenjo merged commit a8e3f00 into master Jul 10, 2024
23 checks passed
@enisdenjo enisdenjo deleted the bye-tsx branch July 10, 2024 17:57
ardatan pushed a commit that referenced this pull request Jul 11, 2024
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@Warxcell
Copy link
Contributor

This one breaks when config is TS.

│ $ mesh start                                                                                                                                                                                                                                                                                                             │
│ 🕸  Mesh 💥Error: Cannot find module './../.meshrc.js'                                                                                                                                                                                                                                                                   │
│ Require stack:                                                                                                                                                                                                                                                                                                           │
│ - /app/.mesh/index.js                                                                                                                                                                                                                                                                                                    │
│     at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)                                                                                                                                                                                                                                                │
│     at Function.resolve (node:internal/modules/helpers:190:19)                                                                                                                                                                                                                                                           │
│     at _resolve (/app/node_modules/@graphql-mesh/utils/node_modules/jiti/dist/jiti.js:1:241814)                                                                                                                                                                                                                          │
│     at jiti (/app/node_modules/@graphql-mesh/utils/node_modules/jiti/dist/jiti.js:1:244531)                                                                                                                                                                                                                              │
│     at /app/.mesh/index.js:49:39                                                                                                                                                                                                                                                                                         │
│     at evalModule (/app/node_modules/@graphql-mesh/utils/node_modules/jiti/dist/jiti.js:1:247313)                                                                                                                                                                                                                        │
│     at jiti (/app/node_modules/@graphql-mesh/utils/node_modules/jiti/dist/jiti.js:1:245241)                                                                                                                                                                                                                              │
│     at /app/node_modules/@graphql-mesh/utils/node_modules/jiti/dist/jiti.js:1:248272                                                                                                                                                                                                                                     │
│     at Generator.next (<anonymous>)                                                                                                                                                                                                                                                                                      │
│     at /app/node_modules/@graphql-mesh/utils/node_modules/jiti/dist/jiti.js:1:238153 

@enisdenjo
Copy link
Collaborator Author

Damnit, sorry @Warxcell. Parsing of external JS files is always tricky. I'll get on this ASAP - thanks for reporting.

@Warxcell
Copy link
Contributor

Damnit, sorry @Warxcell. Parsing of external JS files is always tricky. I'll get on this ASAP - thanks for reporting.

No worry, I downgraded to previous version. Btw same reproducible could be used https://github.com/Warxcell/mesh-ts-reproducible/ - just packages needs to be upgraded.

@enisdenjo
Copy link
Collaborator Author

@Warxcell using the repro repo and pulling the latest cli @graphql-mesh/cli@^0.92.2 works for me. Can you also check?

@Warxcell
Copy link
Contributor

@Warxcell using the repro repo and pulling the latest cli @graphql-mesh/cli@^0.92.2 works for me. Can you also check?

Yeah, it works. Probably it was issue on my side - there was TSC compiler that emitted .JS and with TSX it was probably picking .TS files, no matter that .JS exists. I've stopped compiler and now JITI picks up the .TS files correctly.

Thanks!

@ejkg
Copy link

ejkg commented Jul 30, 2024

I have a similar issue with this update. I am unable to build my application which has tsconfig paths. When I run mesh build I get a jiti error that looks like this:

[2024-07-29T13:16:56.224Z] 🕸️  Mesh 💥 Error: Cannot find module '@config'
Require stack:
- /project/path/src/graphql/envelop-plugins.ts
    at Module._resolveFilename (node:internal/modules/cjs/loader:1219:15)
    at Function.resolve (node:internal/modules/helpers:133:19)
    at _resolve (/project/path/node_modules/jiti/dist/jiti.js:1:241814)
    at jiti (/project/path/node_modules/jiti/dist/jiti.js:1:244531)
    at /project/path/src/graphql/envelop-plugins.ts:1:252
    at evalModule (/project/path/node_modules/jiti/dist/jiti.js:1:247313)
    at jiti (/project/path/node_modules/jiti/dist/jiti.js:1:245241)
    at /project/path/node_modules/jiti/dist/jiti.js:1:248272
    at Generator.next (<anonymous>)
    at /project/path/node_modules/jiti/dist/jiti.js:1:238153

this output is cleaned to remove sensitive info

As you can see there's an issue when modules are named using typescript aliases. I've narrowed it down to the codegen implementation in mesh is not able to traverse typescript aliases anymore following this update. This doesn't happen on 0.92.2 for me.

@Warxcell
Copy link
Contributor

Just updated to latest versions of mesh and this happened:

import {Kind, SelectionSetNode} from "graphql";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (node:internal/modules/cjs/loader:1281:20)
    at Module._compile (node:internal/modules/cjs/loader:1321:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)
    at /graphql-mesh/node_modules/@graphql-mesh/utils/cjs/defaultImportFn.js:29:74
    at async defaultImportFn (/graphql-mesh/node_modules/@graphql-mesh/utils/cjs/defaultImportFn.js:29:18)

tho no idea where it came from.

@enisdenjo
Copy link
Collaborator Author

enisdenjo commented Jul 30, 2024

@ejkg sorry but that doesn't tell me much. Can you maybe share a repro? Or is it just about aliases?

@Warxcell I can use the same repro? This one?

@enisdenjo
Copy link
Collaborator Author

@Warxcell the repro works for me on latest mesh cli. 😭

@enisdenjo
Copy link
Collaborator Author

@Warxcell latest v0.92.6 should have the esm/cjs mix work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants