Skip to content

Commit

Permalink
fix: use tsx instead of ts-node for the cli (#7131)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
enisdenjo and github-actions[bot] committed Jun 25, 2024
1 parent ed441b5 commit bc0c083
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 62 deletions.
8 changes: 8 additions & 0 deletions .changeset/@graphql-mesh_cli-7131-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@graphql-mesh/cli": patch
---
dependencies updates:
- Added dependency [`tsx@^4.7.1` ↗︎](https://www.npmjs.com/package/tsx/v/4.7.1) (to `dependencies`)
- Removed dependency [`json5@^2.2.3` ↗︎](https://www.npmjs.com/package/json5/v/2.2.3) (from `dependencies`)
- Removed dependency [`ts-node@^10.9.2` ↗︎](https://www.npmjs.com/package/ts-node/v/10.9.2) (from `dependencies`)
- Removed dependency [`tsconfig-paths@^4.2.0` ↗︎](https://www.npmjs.com/package/tsconfig-paths/v/4.2.0) (from `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/slimy-icons-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-mesh/cli': minor
---

use tsx instead of ts-node
2 changes: 1 addition & 1 deletion packages/json-machete/src/types.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { JSONSchema, JSONSchemaObject } from '@json-schema-tools/meta-schema';
export type { JSONSchema, JSONSchemaObject } from '@json-schema-tools/meta-schema';
4 changes: 1 addition & 3 deletions packages/legacy/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,12 @@
"graphql-import-node": "^0.0.5",
"graphql-ws": "^5.12.1",
"json-bigint-patch": "^0.0.8",
"json5": "^2.2.3",
"mkdirp": "^3.0.0",
"open": "^7.4.2",
"pascal-case": "^3.1.2",
"rimraf": "^5.0.0",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"tslib": "^2.4.0",
"tsx": "^4.7.1",
"typescript": "^5.4.2",
"ws": "^8.17.0",
"yargs": "^17.7.1"
Expand Down
3 changes: 3 additions & 0 deletions packages/legacy/cli/src/bin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/env node
import 'tsx/cjs'; // support importing typescript configs in CommonJS
import 'tsx/esm'; // support importing typescript configs in ESM

// eslint-disable-next-line import/no-extraneous-dependencies
import { DEFAULT_CLI_PARAMS, graphqlMesh, handleFatalError } from '@graphql-mesh/cli';
import { DefaultLogger } from '@graphql-mesh/utils';
Expand Down
43 changes: 0 additions & 43 deletions packages/legacy/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
/* eslint-disable import/no-nodejs-modules */
import { register } from 'node:module';
import { pathToFileURL } from 'node:url';
import { config as dotEnvRegister } from 'dotenv';
import JSON5 from 'json5';
import { register as tsNodeRegister } from 'ts-node';
import { register as tsConfigPathsRegister } from 'tsconfig-paths';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { fs, path as pathModule, process } from '@graphql-mesh/cross-helpers';
Expand All @@ -25,11 +19,6 @@ import { generateTsArtifacts } from './commands/ts-artifacts.js';
import { findAndParseConfig } from './config.js';
import { handleFatalError } from './handleFatalError.js';

// Note: required to make build command compatible with esm
if (register) {
register('ts-node/esm', pathToFileURL('./'));
}

export { generateTsArtifacts, serveMesh, findAndParseConfig, handleFatalError };

export interface GraphQLMeshCLIParams {
Expand Down Expand Up @@ -66,12 +55,6 @@ export const DEFAULT_CLI_PARAMS: GraphQLMeshCLIParams = {
additionalPackagePrefixes: [],
};

function getTsConfigBaseDir(baseDir: string) {
const tsConfigPath = pathModule.join(baseDir, 'tsconfig.json');
const tsConfigExists = fs.existsSync(tsConfigPath);
return tsConfigExists ? baseDir : process.cwd();
}

export async function graphqlMesh(
cliParams = DEFAULT_CLI_PARAMS,
args = hideBin(process.argv),
Expand Down Expand Up @@ -109,32 +92,6 @@ export async function graphqlMesh(
} else {
baseDir = pathModule.resolve(cwdPath, dir);
}
const tsConfigBaseDir = getTsConfigBaseDir(baseDir);
const tsConfigPath = pathModule.join(tsConfigBaseDir, 'tsconfig.json');
const tsConfigExists = fs.existsSync(tsConfigPath);
tsNodeRegister({
transpileOnly: true,
typeCheck: false,
dir: tsConfigBaseDir,
require: ['graphql-import-node/register'],
compilerOptions: {
module: 'commonjs',
},
});
if (tsConfigExists) {
try {
const tsConfigStr = fs.readFileSync(tsConfigPath, 'utf-8');
const tsConfig = JSON5.parse(tsConfigStr);
if (tsConfig.compilerOptions?.paths) {
tsConfigPathsRegister({
baseUrl: tsConfigBaseDir,
paths: tsConfig.compilerOptions.paths,
});
}
} catch (e) {
logger.warn(`Unable to read TSConfig file ${tsConfigPath};\n`, e);
}
}
if (fs.existsSync(pathModule.join(baseDir, '.env'))) {
dotEnvRegister({
path: pathModule.join(baseDir, '.env'),
Expand Down
17 changes: 2 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4677,15 +4677,13 @@ __metadata:
graphql-import-node: "npm:^0.0.5"
graphql-ws: "npm:^5.12.1"
json-bigint-patch: "npm:^0.0.8"
json5: "npm:^2.2.3"
mkdirp: "npm:^3.0.0"
node-libcurl: "npm:^4.0.0"
open: "npm:^7.4.2"
pascal-case: "npm:^3.1.2"
rimraf: "npm:^5.0.0"
ts-node: "npm:^10.9.2"
tsconfig-paths: "npm:^4.2.0"
tslib: "npm:^2.4.0"
tsx: "npm:^4.7.1"
typescript: "npm:^5.4.2"
uWebSockets.js: "uNetworking/uWebSockets.js#semver:^20"
ws: "npm:^8.17.0"
Expand Down Expand Up @@ -22949,7 +22947,7 @@ __metadata:
languageName: node
linkType: hard

"json5@npm:^2.1.1, json5@npm:^2.1.2, json5@npm:^2.2.0, json5@npm:^2.2.2, json5@npm:^2.2.3":
"json5@npm:^2.1.1, json5@npm:^2.1.2, json5@npm:^2.2.0, json5@npm:^2.2.3":
version: 2.2.3
resolution: "json5@npm:2.2.3"
bin:
Expand Down Expand Up @@ -33256,17 +33254,6 @@ __metadata:
languageName: node
linkType: hard

"tsconfig-paths@npm:^4.2.0":
version: 4.2.0
resolution: "tsconfig-paths@npm:4.2.0"
dependencies:
json5: "npm:^2.2.2"
minimist: "npm:^1.2.6"
strip-bom: "npm:^3.0.0"
checksum: 10c0/09a5877402d082bb1134930c10249edeebc0211f36150c35e1c542e5b91f1047b1ccf7da1e59babca1ef1f014c525510f4f870de7c9bda470c73bb4e2721b3ea
languageName: node
linkType: hard

"tsconfig@npm:^7.0.0":
version: 7.0.0
resolution: "tsconfig@npm:7.0.0"
Expand Down

0 comments on commit bc0c083

Please sign in to comment.