diff --git a/.changeset/@graphql-mesh_cli-8280-dependencies.md b/.changeset/@graphql-mesh_cli-8280-dependencies.md new file mode 100644 index 0000000000000..8f873f36c68e9 --- /dev/null +++ b/.changeset/@graphql-mesh_cli-8280-dependencies.md @@ -0,0 +1,7 @@ +--- +"@graphql-mesh/cli": patch +--- +dependencies updates: + - Added dependency [`get-tsconfig@^4.7.6` ↗︎](https://www.npmjs.com/package/get-tsconfig/v/4.7.6) (to `dependencies`) + - Added dependency [`jiti@^2.0.0` ↗︎](https://www.npmjs.com/package/jiti/v/2.0.0) (to `dependencies`) + - Removed dependency [`@graphql-mesh/include@^0.2.10` ↗︎](https://www.npmjs.com/package/@graphql-mesh/include/v/0.2.10) (from `dependencies`) diff --git a/.changeset/@graphql-mesh_compose-cli-8280-dependencies.md b/.changeset/@graphql-mesh_compose-cli-8280-dependencies.md new file mode 100644 index 0000000000000..f941cb928cf47 --- /dev/null +++ b/.changeset/@graphql-mesh_compose-cli-8280-dependencies.md @@ -0,0 +1,6 @@ +--- +"@graphql-mesh/compose-cli": patch +--- +dependencies updates: + - Added dependency [`@graphql-hive/importer@1.0.0-alpha-b9f05248109748ed53b5a1ae7465317fc9fcd3ec` ↗︎](https://www.npmjs.com/package/@graphql-hive/importer/v/1.0.0) (to `dependencies`) + - Removed dependency [`@graphql-mesh/include@^0.2.10` ↗︎](https://www.npmjs.com/package/@graphql-mesh/include/v/0.2.10) (from `dependencies`) diff --git a/.changeset/hip-cougars-clap.md b/.changeset/hip-cougars-clap.md new file mode 100644 index 0000000000000..1ddd829914350 --- /dev/null +++ b/.changeset/hip-cougars-clap.md @@ -0,0 +1,5 @@ +--- +'@graphql-mesh/cli': patch +--- + +TypeScript importer and transpiler is now built-in diff --git a/.changeset/nine-trainers-walk.md b/.changeset/nine-trainers-walk.md new file mode 100644 index 0000000000000..29501dcbc6434 --- /dev/null +++ b/.changeset/nine-trainers-walk.md @@ -0,0 +1,5 @@ +--- +'@graphql-mesh/compose-cli': patch +--- + +Use `@graphql-hive/importer` for importing configs and transpiling TypeScript files diff --git a/e2e/tsconfig-paths/tsconfig-paths.test.ts b/e2e/tsconfig-paths/tsconfig-paths.test.ts index 68f5f54bd81be..7f37f9d585515 100644 --- a/e2e/tsconfig-paths/tsconfig-paths.test.ts +++ b/e2e/tsconfig-paths/tsconfig-paths.test.ts @@ -5,7 +5,7 @@ const { compose } = createTenv(__dirname); it('should compose', async () => { const proc = await compose({ env: { - MESH_INCLUDE_TSCONFIG_SEARCH_PATH: 'tsconfig-paths.tsconfig.json', + HIVE_IMPORTER_TSCONFIG_SEARCH_PATH: 'tsconfig-paths.tsconfig.json', }, }); expect(proc.result).toMatchSnapshot(); diff --git a/packages/compose-cli/package.json b/packages/compose-cli/package.json index 43069dffcf256..5d7236039120c 100644 --- a/packages/compose-cli/package.json +++ b/packages/compose-cli/package.json @@ -39,8 +39,8 @@ }, "dependencies": { "@commander-js/extra-typings": "^13.0.0", + "@graphql-hive/importer": "1.0.0-alpha-b9f05248109748ed53b5a1ae7465317fc9fcd3ec", "@graphql-mesh/fusion-composition": "^0.7.17", - "@graphql-mesh/include": "^0.2.10", "@graphql-mesh/string-interpolation": "^0.5.7", "@graphql-mesh/types": "^0.103.11", "@graphql-mesh/utils": "^0.103.11", diff --git a/packages/compose-cli/src/run.ts b/packages/compose-cli/src/run.ts index 5277e59897001..9c916f29582fe 100644 --- a/packages/compose-cli/src/run.ts +++ b/packages/compose-cli/src/run.ts @@ -58,7 +58,7 @@ export async function run({ version, }: RunOptions): Promise { module.register( - '@graphql-mesh/include/hooks', + '@graphql-hive/importer/hooks', // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore bob will complain when bundling for cjs import.meta.url, diff --git a/packages/include/CHANGELOG.md b/packages/include/CHANGELOG.md deleted file mode 100644 index 4f8cbb331c58a..0000000000000 --- a/packages/include/CHANGELOG.md +++ /dev/null @@ -1,148 +0,0 @@ -# @graphql-mesh/include - -## 0.2.10 - -### Patch Changes - -- Updated dependencies - [[`4011203`](https://github.com/ardatan/graphql-mesh/commit/40112034a2e248eda94883a39a3f8682189f4288)]: - - @graphql-mesh/utils@0.103.11 - -## 0.2.9 - -### Patch Changes - -- Updated dependencies - [[`b750a41`](https://github.com/ardatan/graphql-mesh/commit/b750a410c082d64a04f21023790f2ff2c46f5eb9)]: - - @graphql-mesh/utils@0.103.10 - -## 0.2.8 - -### Patch Changes - -- Updated dependencies - [[`10ba2c4`](https://github.com/ardatan/graphql-mesh/commit/10ba2c42549dacff9c4e6be87ee50b608be62ddc)]: - - @graphql-mesh/utils@0.103.9 - -## 0.2.7 - -### Patch Changes - -- [#8082](https://github.com/ardatan/graphql-mesh/pull/8082) - [`93fb364`](https://github.com/ardatan/graphql-mesh/commit/93fb3643d90c52084725d79b586ace8ecd570911) - Thanks [@ardatan](https://github.com/ardatan)! - Import enhancements - -- Updated dependencies - [[`93fb364`](https://github.com/ardatan/graphql-mesh/commit/93fb3643d90c52084725d79b586ace8ecd570911)]: - - @graphql-mesh/utils@0.103.8 - -## 0.2.6 - -### Patch Changes - -- Updated dependencies []: - - @graphql-mesh/utils@0.103.7 - -## 0.2.5 - -### Patch Changes - -- Updated dependencies - [[`2ef651a`](https://github.com/ardatan/graphql-mesh/commit/2ef651a8356b560478f1847399bad975a0c3f0b9)]: - - @graphql-mesh/utils@0.103.6 - -## 0.2.4 - -### Patch Changes - -- [#8007](https://github.com/ardatan/graphql-mesh/pull/8007) - [`9f9f6fe`](https://github.com/ardatan/graphql-mesh/commit/9f9f6fe61c74eaa6572866eddd97c348307107a8) - Thanks [@ardatan](https://github.com/ardatan)! - dependencies updates: - - - Added dependency - [`@graphql-mesh/utils@^0.103.4` ↗︎](https://www.npmjs.com/package/@graphql-mesh/utils/v/0.103.4) - (to `dependencies`) - -- [#8007](https://github.com/ardatan/graphql-mesh/pull/8007) - [`9f9f6fe`](https://github.com/ardatan/graphql-mesh/commit/9f9f6fe61c74eaa6572866eddd97c348307107a8) - Thanks [@ardatan](https://github.com/ardatan)! - Improvements on imports - -- Updated dependencies - [[`9f9f6fe`](https://github.com/ardatan/graphql-mesh/commit/9f9f6fe61c74eaa6572866eddd97c348307107a8)]: - - @graphql-mesh/utils@0.103.5 - -## 0.2.3 - -### Patch Changes - -- [#7725](https://github.com/ardatan/graphql-mesh/pull/7725) - [`4da6db4`](https://github.com/ardatan/graphql-mesh/commit/4da6db4c8eb570b7bdd3a2de0b026a8fff1a20b2) - Thanks [@renovate](https://github.com/apps/renovate)! - dependencies updates: - - Updated dependency [`jiti@^2.0.0` ↗︎](https://www.npmjs.com/package/jiti/v/2.0.0) (from - `^1.21.6`, in `dependencies`) - -## 0.2.2 - -### Patch Changes - -- [`f1ce73e`](https://github.com/ardatan/graphql-mesh/commit/f1ce73e30040b461f78885352e0c9d292b8b0589) - Thanks [@ardatan](https://github.com/ardatan)! - Fix bundle imports - -## 0.2.1 - -### Patch Changes - -- [`0443063`](https://github.com/ardatan/graphql-mesh/commit/04430632fb2fd5f90c264ad6ca9a0eb89a789c05) - Thanks [@ardatan](https://github.com/ardatan)! - Improve Windows support - -## 0.2.0 - -### Minor Changes - -- [#7596](https://github.com/ardatan/graphql-mesh/pull/7596) - [`b7f6ebf`](https://github.com/ardatan/graphql-mesh/commit/b7f6ebfa077957c3a1ecad1fed449e972cb09ae0) - Thanks [@enisdenjo](https://github.com/enisdenjo)! - Module hooks using sucrase transpiling only - TS with tsconfig paths support - -- [#7596](https://github.com/ardatan/graphql-mesh/pull/7596) - [`b7f6ebf`](https://github.com/ardatan/graphql-mesh/commit/b7f6ebfa077957c3a1ecad1fed449e972cb09ae0) - Thanks [@enisdenjo](https://github.com/enisdenjo)! - No more - @graphql-mesh/include/register-tsconfig-paths - -### Patch Changes - -- [#7596](https://github.com/ardatan/graphql-mesh/pull/7596) - [`b7f6ebf`](https://github.com/ardatan/graphql-mesh/commit/b7f6ebfa077957c3a1ecad1fed449e972cb09ae0) - Thanks [@enisdenjo](https://github.com/enisdenjo)! - dependencies updates: - - Added dependency [`sucrase@^3.35.0` ↗︎](https://www.npmjs.com/package/sucrase/v/3.35.0) (to - `dependencies`) - -## 0.1.0 - -### Minor Changes - -- [#7494](https://github.com/ardatan/graphql-mesh/pull/7494) - [`0594ffd`](https://github.com/ardatan/graphql-mesh/commit/0594ffdd5dacb99d73cfa351439ce8356c3aff2a) - Thanks [@enisdenjo](https://github.com/enisdenjo)! - Optional `nativeImport` argument when - including to use the native `import` function instead of jiti - -### Patch Changes - -- [#7493](https://github.com/ardatan/graphql-mesh/pull/7493) - [`78b7569`](https://github.com/ardatan/graphql-mesh/commit/78b7569dda8b797a28883ab34543b6b80f3d825a) - Thanks [@enisdenjo](https://github.com/enisdenjo)! - Return noop unregister function if no - tsconfig paths have been registered - -- [#7493](https://github.com/ardatan/graphql-mesh/pull/7493) - [`78b7569`](https://github.com/ardatan/graphql-mesh/commit/78b7569dda8b797a28883ab34543b6b80f3d825a) - Thanks [@enisdenjo](https://github.com/enisdenjo)! - Nothing to register if tsconfig does not - contain paths - -## 0.0.1 - -### Patch Changes - -- [#7427](https://github.com/ardatan/graphql-mesh/pull/7427) - [`8be81d2`](https://github.com/ardatan/graphql-mesh/commit/8be81d25aac222f37ba7bc44592c39b0f53ace95) - Thanks [@enisdenjo](https://github.com/enisdenjo)! - Library for importing and transpiling - TypeScript and JavaScript module during runtime diff --git a/packages/include/package.json b/packages/include/package.json deleted file mode 100644 index dec3ec370ba2d..0000000000000 --- a/packages/include/package.json +++ /dev/null @@ -1,74 +0,0 @@ -{ - "name": "@graphql-mesh/include", - "version": "0.2.10", - "type": "module", - "repository": { - "type": "git", - "url": "ardatan/graphql-mesh", - "directory": "packages/include" - }, - "license": "MIT", - "engines": { - "node": ">=16.0.0" - }, - "main": "dist/cjs/index.js", - "module": "dist/esm/index.js", - "exports": { - ".": { - "require": { - "types": "./dist/typings/index.d.cts", - "default": "./dist/cjs/index.js" - }, - "import": { - "types": "./dist/typings/index.d.ts", - "default": "./dist/esm/index.js" - }, - "default": { - "types": "./dist/typings/index.d.ts", - "default": "./dist/esm/index.js" - } - }, - "./hooks": { - "require": { - "types": "./dist/typings/hooks.d.cts", - "default": "./dist/cjs/hooks.js" - }, - "import": { - "types": "./dist/typings/hooks.d.ts", - "default": "./dist/esm/hooks.js" - }, - "default": { - "types": "./dist/typings/hooks.d.ts", - "default": "./dist/esm/hooks.js" - } - }, - "./package.json": "./package.json" - }, - "typings": "dist/typings/index.d.ts", - "dependencies": { - "@graphql-mesh/utils": "^0.103.11", - "dotenv": "^16.3.1", - "get-tsconfig": "^4.7.6", - "jiti": "^2.0.0", - "sucrase": "^3.35.0" - }, - "devDependencies": { - "glob": "^11.0.0" - }, - "publishConfig": { - "access": "public", - "directory": "dist" - }, - "sideEffects": false, - "buildOptions": { - "bin": { - "mesh-compose": { - "input": "src/bin.ts" - } - }, - "./package.json": "./package.json" - }, - "typescript": { - "definition": "dist/typings/index.d.ts" - } -} diff --git a/packages/include/src/hooks.ts b/packages/include/src/hooks.ts deleted file mode 100644 index 518c78bbf063a..0000000000000 --- a/packages/include/src/hooks.ts +++ /dev/null @@ -1,206 +0,0 @@ -/* eslint-disable import/no-nodejs-modules */ -// ONLY FOR NODE. register with `node --import @graphql-mesh/include/hooks ` - -import fs from 'node:fs/promises'; -import module from 'node:module'; -import path from 'node:path'; -import { fileURLToPath, pathToFileURL } from 'node:url'; -import { createPathsMatcher, getTsconfig } from 'get-tsconfig'; -import { transform, type Transform } from 'sucrase'; - -const isDebug = ['1', 'y', 'yes', 't', 'true'].includes(String(process.env.DEBUG)); - -function debug(msg: string) { - if (isDebug) { - process.stderr.write(`[${new Date().toISOString()}] HOOKS ${msg}\n`); - } -} - -// eslint-disable-next-line dot-notation -const resolveFilename: (path: string) => string = module['_resolveFilename']; - -let packedDepsPath = ''; - -let pathsMatcher: ((specifier: string) => string[]) | undefined; - -export interface InitializeData { - /** - * Packed deps will be checked first, and enforced if present, during module resolution. - * This allows us to consistently use the same module instance even if multiple are installed by the user. - */ - packedDepsPath?: string; - /** - * tsconfig search path for registering tsconfig paths. - * - * @default process.env.MESH_INCLUDE_TSCONFIG_SEARCH_PATH || 'tsconfig.json' - */ - tsconfigSearchPath?: string; -} - -export const initialize: module.InitializeHook = (data = {}) => { - if (data.packedDepsPath) { - packedDepsPath = data.packedDepsPath; - debug(`Packed dependencies available at "${packedDepsPath}"`); - } - const tsconfig = getTsconfig( - undefined, - data.tsconfigSearchPath || process.env.MESH_INCLUDE_TSCONFIG_SEARCH_PATH || 'tsconfig.json', - ); - if (tsconfig) { - debug(`tsconfig found at "${tsconfig.path}"`); - pathsMatcher = createPathsMatcher(tsconfig); - } -}; - -function fixSpecifier(specifier: string, context: module.ResolveHookContext) { - if (path.sep === '\\') { - if (context.parentURL != null && context.parentURL[1] === ':') { - context.parentURL = pathToFileURL(context.parentURL.replaceAll('/', '\\')).toString(); - } - if (specifier[1] === ':' && specifier[2] === '/') { - specifier = specifier.replaceAll('/', '\\'); - } - if (specifier.startsWith('file://')) { - specifier = fileURLToPath(specifier); - } - if (!specifier.startsWith('.') && !specifier.startsWith('file:') && specifier[1] === ':') { - specifier = pathToFileURL(specifier).toString(); - } - } - if (specifier.startsWith('node_modules/') || specifier.startsWith('node_modules\\')) { - specifier = specifier - .replace('node_modules/', '') - .replace('node_modules\\', '') - .replace(/\\/g, '/'); - } - return specifier; -} - -export const resolve: module.ResolveHook = async (specifier, context, nextResolve) => { - specifier = fixSpecifier(specifier, context); - - if (specifier.startsWith('node:')) { - return nextResolve(specifier, context); - } - if (module.builtinModules.includes(specifier)) { - return nextResolve(specifier, context); - } - - if (!specifier.startsWith('.') && packedDepsPath) { - try { - debug( - `Trying packed dependency "${specifier}" for "${context.parentURL?.toString() || '.'}"`, - ); - const resolved = resolveFilename(path.join(packedDepsPath, specifier)); - debug(`Possible packed dependency "${specifier}" to "${resolved}"`); - return await nextResolve(fixSpecifier(resolved, context), context); - } catch { - // noop - } - } - - try { - // debug(`Trying default resolve for "${specifier}"`); - return await nextResolve(specifier, context); - } catch (e) { - try { - debug(`Trying default resolve for "${specifier}" failed; trying alternatives`); - const specifierWithoutJs = specifier.endsWith('.js') ? specifier.slice(0, -3) : specifier; - const specifierWithTs = specifierWithoutJs + '.ts'; // TODO: .mts or .cts - debug(`Trying "${specifierWithTs}"`); - return await nextResolve(fixSpecifier(specifierWithTs, context), context); - } catch (e) { - try { - return await nextResolve(fixSpecifier(resolveFilename(specifier), context), context); - } catch { - try { - const specifierWithoutJs = specifier.endsWith('.js') ? specifier.slice(0, -3) : specifier; - // usual filenames tried, could be a .ts file? - return await nextResolve( - fixSpecifier( - resolveFilename( - specifierWithoutJs + '.ts', // TODO: .mts or .cts? - ), - context, - ), - context, - ); - } catch { - // not a .ts file, try the tsconfig paths if available - if (pathsMatcher) { - for (const possiblePath of pathsMatcher(specifier)) { - try { - return await nextResolve( - fixSpecifier(resolveFilename(possiblePath), context), - context, - ); - } catch { - try { - const possiblePathWithoutJs = possiblePath.endsWith('.js') - ? possiblePath.slice(0, -3) - : possiblePath; - // the tsconfig path might point to a .ts file, try it too - return await nextResolve( - fixSpecifier( - resolveFilename( - possiblePathWithoutJs + '.ts', // TODO: .mts or .cts? - ), - context, - ), - context, - ); - } catch { - // noop - } - } - } - } - } - } - } - - // none of the alternatives worked, fail with original error - throw e; - } -}; - -export const load: module.LoadHook = async (url, context, nextLoad) => { - if (path.sep === '\\' && !url.startsWith('file:') && url[1] === ':') { - debug(`Fixing Windows path at "${url}"`); - url = `file:///${url.replace(/\\/g, '/')}`; - } - if (/\.(m|c)?ts$/.test(url)) { - // debug(`Transpiling TypeScript file at "${url}"`); - const filePath = fileURLToPath(url); - let source: string; - try { - source = await fs.readFile(filePath, 'utf8'); - } catch (e) { - throw new Error(`Failed to read file at "${url}"; ${e?.stack || e}`); - } - let format: 'module' | 'commonjs'; - if (/\.ts$/.test(url)) { - // try { - // const { isSea } = await import('node:sea'); - // format = isSea() ? 'commonjs' : 'module'; - // } catch { - format = 'module'; - // } - } else if (/\.mts$/.test(url)) { - format = 'module'; - } else if (/\.cts$/.test(url)) { - format = 'commonjs'; - } - const transforms: Transform[] = ['typescript']; - if (format === 'commonjs') { - transforms.push('imports'); - } - const { code } = transform(source, { transforms }); - return { - format, - source: code, - shortCircuit: true, - }; - } - return nextLoad(url, context); -}; diff --git a/packages/include/tests/__snapshots__/include.test.ts.snap b/packages/include/tests/__snapshots__/include.test.ts.snap deleted file mode 100644 index 29614e57234fe..0000000000000 --- a/packages/include/tests/__snapshots__/include.test.ts.snap +++ /dev/null @@ -1,35 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should include in fixture cjs-imports-another-no-ext 1`] = ` -{ - "john": "doe", -} -`; - -exports[`should include in fixture cjs-imports-esm-no-ext 1`] = ` -{ - "john": "doe", -} -`; - -exports[`should include in fixture imports-another-cjs-ext-cjs 1`] = `"doe"`; - -exports[`should include in fixture imports-another-js-ext 1`] = `"doe"`; - -exports[`should include in fixture imports-another-no-ext 1`] = `"doe"`; - -exports[`should include in fixture imports-another-no-ext-cjs 1`] = `"doe"`; - -exports[`should include in fixture js-imports-another-no-ext 1`] = `"doe"`; - -exports[`should include in fixture simple-default-export 1`] = ` -{ - "john": "doe", -} -`; - -exports[`should include in fixture simple-named-export 1`] = ` -{ - "john": "doe", -} -`; diff --git a/packages/include/tests/fixtures/cjs-imports-another-no-ext/another.js b/packages/include/tests/fixtures/cjs-imports-another-no-ext/another.js deleted file mode 100644 index b07a7e9c270e8..0000000000000 --- a/packages/include/tests/fixtures/cjs-imports-another-no-ext/another.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = { john: 'doe' }; diff --git a/packages/include/tests/fixtures/cjs-imports-another-no-ext/include.txt b/packages/include/tests/fixtures/cjs-imports-another-no-ext/include.txt deleted file mode 100644 index 012a3cd68929f..0000000000000 --- a/packages/include/tests/fixtures/cjs-imports-another-no-ext/include.txt +++ /dev/null @@ -1 +0,0 @@ -index.js diff --git a/packages/include/tests/fixtures/cjs-imports-another-no-ext/index.js b/packages/include/tests/fixtures/cjs-imports-another-no-ext/index.js deleted file mode 100644 index ef9273adf4852..0000000000000 --- a/packages/include/tests/fixtures/cjs-imports-another-no-ext/index.js +++ /dev/null @@ -1,3 +0,0 @@ -const { john } = require('./another'); - -module.exports = { john }; diff --git a/packages/include/tests/fixtures/cjs-imports-esm-no-ext/another.js b/packages/include/tests/fixtures/cjs-imports-esm-no-ext/another.js deleted file mode 100644 index e20a912e15a48..0000000000000 --- a/packages/include/tests/fixtures/cjs-imports-esm-no-ext/another.js +++ /dev/null @@ -1 +0,0 @@ -export const john = 'doe'; diff --git a/packages/include/tests/fixtures/cjs-imports-esm-no-ext/include.txt b/packages/include/tests/fixtures/cjs-imports-esm-no-ext/include.txt deleted file mode 100644 index 012a3cd68929f..0000000000000 --- a/packages/include/tests/fixtures/cjs-imports-esm-no-ext/include.txt +++ /dev/null @@ -1 +0,0 @@ -index.js diff --git a/packages/include/tests/fixtures/cjs-imports-esm-no-ext/index.js b/packages/include/tests/fixtures/cjs-imports-esm-no-ext/index.js deleted file mode 100644 index ef9273adf4852..0000000000000 --- a/packages/include/tests/fixtures/cjs-imports-esm-no-ext/index.js +++ /dev/null @@ -1,3 +0,0 @@ -const { john } = require('./another'); - -module.exports = { john }; diff --git a/packages/include/tests/fixtures/imports-another-cjs-ext-cjs/another.cjs b/packages/include/tests/fixtures/imports-another-cjs-ext-cjs/another.cjs deleted file mode 100644 index b07a7e9c270e8..0000000000000 --- a/packages/include/tests/fixtures/imports-another-cjs-ext-cjs/another.cjs +++ /dev/null @@ -1 +0,0 @@ -module.exports = { john: 'doe' }; diff --git a/packages/include/tests/fixtures/imports-another-cjs-ext-cjs/include.txt b/packages/include/tests/fixtures/imports-another-cjs-ext-cjs/include.txt deleted file mode 100644 index 1e21beece364c..0000000000000 --- a/packages/include/tests/fixtures/imports-another-cjs-ext-cjs/include.txt +++ /dev/null @@ -1 +0,0 @@ -index.ts diff --git a/packages/include/tests/fixtures/imports-another-cjs-ext-cjs/index.ts b/packages/include/tests/fixtures/imports-another-cjs-ext-cjs/index.ts deleted file mode 100644 index 523d5ee6e57af..0000000000000 --- a/packages/include/tests/fixtures/imports-another-cjs-ext-cjs/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { john } from './another.cjs'; - -export default john; diff --git a/packages/include/tests/fixtures/imports-another-js-ext/another.ts b/packages/include/tests/fixtures/imports-another-js-ext/another.ts deleted file mode 100644 index e20a912e15a48..0000000000000 --- a/packages/include/tests/fixtures/imports-another-js-ext/another.ts +++ /dev/null @@ -1 +0,0 @@ -export const john = 'doe'; diff --git a/packages/include/tests/fixtures/imports-another-js-ext/include.txt b/packages/include/tests/fixtures/imports-another-js-ext/include.txt deleted file mode 100644 index 1e21beece364c..0000000000000 --- a/packages/include/tests/fixtures/imports-another-js-ext/include.txt +++ /dev/null @@ -1 +0,0 @@ -index.ts diff --git a/packages/include/tests/fixtures/imports-another-js-ext/index.ts b/packages/include/tests/fixtures/imports-another-js-ext/index.ts deleted file mode 100644 index 5ab38b6d68fe8..0000000000000 --- a/packages/include/tests/fixtures/imports-another-js-ext/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { john } from './another.js'; - -export default john; diff --git a/packages/include/tests/fixtures/imports-another-no-ext-cjs/another.ts b/packages/include/tests/fixtures/imports-another-no-ext-cjs/another.ts deleted file mode 100644 index b07a7e9c270e8..0000000000000 --- a/packages/include/tests/fixtures/imports-another-no-ext-cjs/another.ts +++ /dev/null @@ -1 +0,0 @@ -module.exports = { john: 'doe' }; diff --git a/packages/include/tests/fixtures/imports-another-no-ext-cjs/include.txt b/packages/include/tests/fixtures/imports-another-no-ext-cjs/include.txt deleted file mode 100644 index 1e21beece364c..0000000000000 --- a/packages/include/tests/fixtures/imports-another-no-ext-cjs/include.txt +++ /dev/null @@ -1 +0,0 @@ -index.ts diff --git a/packages/include/tests/fixtures/imports-another-no-ext-cjs/index.ts b/packages/include/tests/fixtures/imports-another-no-ext-cjs/index.ts deleted file mode 100644 index 63548f497a4da..0000000000000 --- a/packages/include/tests/fixtures/imports-another-no-ext-cjs/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-expect-error -import { john } from './another'; - -export default john; diff --git a/packages/include/tests/fixtures/imports-another-no-ext/another.ts b/packages/include/tests/fixtures/imports-another-no-ext/another.ts deleted file mode 100644 index e20a912e15a48..0000000000000 --- a/packages/include/tests/fixtures/imports-another-no-ext/another.ts +++ /dev/null @@ -1 +0,0 @@ -export const john = 'doe'; diff --git a/packages/include/tests/fixtures/imports-another-no-ext/include.txt b/packages/include/tests/fixtures/imports-another-no-ext/include.txt deleted file mode 100644 index 1e21beece364c..0000000000000 --- a/packages/include/tests/fixtures/imports-another-no-ext/include.txt +++ /dev/null @@ -1 +0,0 @@ -index.ts diff --git a/packages/include/tests/fixtures/imports-another-no-ext/index.ts b/packages/include/tests/fixtures/imports-another-no-ext/index.ts deleted file mode 100644 index c7174e94881f6..0000000000000 --- a/packages/include/tests/fixtures/imports-another-no-ext/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { john } from './another'; - -export default john; diff --git a/packages/include/tests/fixtures/js-imports-another-no-ext/another.js b/packages/include/tests/fixtures/js-imports-another-no-ext/another.js deleted file mode 100644 index e20a912e15a48..0000000000000 --- a/packages/include/tests/fixtures/js-imports-another-no-ext/another.js +++ /dev/null @@ -1 +0,0 @@ -export const john = 'doe'; diff --git a/packages/include/tests/fixtures/js-imports-another-no-ext/include.txt b/packages/include/tests/fixtures/js-imports-another-no-ext/include.txt deleted file mode 100644 index 012a3cd68929f..0000000000000 --- a/packages/include/tests/fixtures/js-imports-another-no-ext/include.txt +++ /dev/null @@ -1 +0,0 @@ -index.js diff --git a/packages/include/tests/fixtures/js-imports-another-no-ext/index.js b/packages/include/tests/fixtures/js-imports-another-no-ext/index.js deleted file mode 100644 index c7174e94881f6..0000000000000 --- a/packages/include/tests/fixtures/js-imports-another-no-ext/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import { john } from './another'; - -export default john; diff --git a/packages/include/tests/fixtures/simple-default-export/include.txt b/packages/include/tests/fixtures/simple-default-export/include.txt deleted file mode 100644 index 1e21beece364c..0000000000000 --- a/packages/include/tests/fixtures/simple-default-export/include.txt +++ /dev/null @@ -1 +0,0 @@ -index.ts diff --git a/packages/include/tests/fixtures/simple-default-export/index.ts b/packages/include/tests/fixtures/simple-default-export/index.ts deleted file mode 100644 index 61cb891275fd7..0000000000000 --- a/packages/include/tests/fixtures/simple-default-export/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -const john = 'doe'; -export default { john }; diff --git a/packages/include/tests/fixtures/simple-named-export/include.txt b/packages/include/tests/fixtures/simple-named-export/include.txt deleted file mode 100644 index 1e21beece364c..0000000000000 --- a/packages/include/tests/fixtures/simple-named-export/include.txt +++ /dev/null @@ -1 +0,0 @@ -index.ts diff --git a/packages/include/tests/fixtures/simple-named-export/index.ts b/packages/include/tests/fixtures/simple-named-export/index.ts deleted file mode 100644 index e20a912e15a48..0000000000000 --- a/packages/include/tests/fixtures/simple-named-export/index.ts +++ /dev/null @@ -1 +0,0 @@ -export const john = 'doe'; diff --git a/packages/include/tests/include.test.ts b/packages/include/tests/include.test.ts deleted file mode 100644 index 1c0b357084855..0000000000000 --- a/packages/include/tests/include.test.ts +++ /dev/null @@ -1,21 +0,0 @@ -import fs from 'node:fs'; -import path from 'node:path'; -import { globSync } from 'glob'; -import { include } from '../src/index'; - -const fixtures = globSync(path.join(__dirname, 'fixtures', '*')).map(p => ({ - fixture: path.basename(p), - cwd: p, - pathToInclude: path.join(p, fs.readFileSync(path.join(p, 'include.txt'), 'utf8').trim()), -})); - -it.each(fixtures)('should include in fixture $fixture', async ({ pathToInclude }) => { - // TODO: cant test tsconfig paths because jest doesnt allow manipulating Module._resolveFilename - // const unregister = registerTsconfigPaths({ cwd }); - // await using _ = { - // [Symbol.dispose]() { - // unregister(); - // }, - // }; - await expect(include(pathToInclude)).resolves.toMatchSnapshot(); -}); diff --git a/packages/legacy/cli/package.json b/packages/legacy/cli/package.json index 9d7f44a1b6ee7..83f174542ad0d 100644 --- a/packages/legacy/cli/package.json +++ b/packages/legacy/cli/package.json @@ -50,7 +50,6 @@ "@graphql-mesh/config": "^0.106.17", "@graphql-mesh/cross-helpers": "^0.4.9", "@graphql-mesh/http": "^0.105.12", - "@graphql-mesh/include": "^0.2.10", "@graphql-mesh/runtime": "^0.105.12", "@graphql-mesh/store": "^0.103.11", "@graphql-mesh/types": "^0.103.11", @@ -60,8 +59,10 @@ "change-case": "^4.1.2", "cosmiconfig": "^9.0.0", "dotenv": "^16.0.3", + "get-tsconfig": "^4.7.6", "graphql-import-node": "^0.0.5", "graphql-ws": "^6.0.0", + "jiti": "^2.0.0", "json-bigint-patch": "^0.0.8", "json5": "^2.2.3", "mkdirp": "^3.0.0", diff --git a/packages/legacy/cli/src/config.ts b/packages/legacy/cli/src/config.ts index da0ac294582fb..b9f1e8f59eab1 100644 --- a/packages/legacy/cli/src/config.ts +++ b/packages/legacy/cli/src/config.ts @@ -3,10 +3,10 @@ import { cosmiconfig, defaultLoaders } from 'cosmiconfig'; import type { ConfigProcessOptions } from '@graphql-mesh/config'; import { processConfig } from '@graphql-mesh/config'; import { path, process } from '@graphql-mesh/cross-helpers'; -import { include } from '@graphql-mesh/include'; import type { YamlConfig } from '@graphql-mesh/types'; import { jsonSchema } from '@graphql-mesh/types'; import { DefaultLogger, loadYaml } from '@graphql-mesh/utils'; +import { include } from './include.js'; export function validateConfig( config: any, diff --git a/packages/include/src/index.ts b/packages/legacy/cli/src/include.ts similarity index 100% rename from packages/include/src/index.ts rename to packages/legacy/cli/src/include.ts diff --git a/packages/legacy/cli/src/index.ts b/packages/legacy/cli/src/index.ts index 1ca81f57e085c..359dd5f6448a1 100644 --- a/packages/legacy/cli/src/index.ts +++ b/packages/legacy/cli/src/index.ts @@ -2,7 +2,6 @@ import { config as dotEnvRegister } from 'dotenv'; import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; import { fs, path as pathModule, process } from '@graphql-mesh/cross-helpers'; -import { include, registerTsconfigPaths } from '@graphql-mesh/include'; import type { GetMeshOptions, MeshInstance, ServeMeshOptions } from '@graphql-mesh/runtime'; import { getMesh } from '@graphql-mesh/runtime'; import { FsStoreStorageAdapter, MeshStore } from '@graphql-mesh/store'; @@ -19,6 +18,7 @@ import { serveMesh } from './commands/serve/serve.js'; import { generateTsArtifacts } from './commands/ts-artifacts.js'; import { findAndParseConfig } from './config.js'; import { handleFatalError } from './handleFatalError.js'; +import { include, registerTsconfigPaths } from './include.js'; export { findConfig } from './config.js'; diff --git a/tsconfig.json b/tsconfig.json index 57fd313128dff..32619b6ffc7ce 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -28,8 +28,6 @@ "paths": { "@graphql-mesh/migrate-config-cli": ["packages/legacy/migrate-config-cli/src/index.ts"], - "@graphql-mesh/include": ["packages/include/src/index.ts"], - "@graphql-mesh/include/*": ["packages/include/src/*"], "@graphql-mesh/cli": ["packages/legacy/cli/src/index.ts"], "@graphql-mesh/runtime": ["packages/legacy/runtime/src/index.ts"], "@graphql-mesh/config": ["packages/legacy/config/src/index.ts"], diff --git a/yarn.lock b/yarn.lock index dba14f0a2253c..c9c7fd0dbebf0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6080,6 +6080,13 @@ __metadata: languageName: node linkType: hard +"@graphql-hive/importer@npm:1.0.0-alpha-b9f05248109748ed53b5a1ae7465317fc9fcd3ec": + version: 1.0.0-alpha-b9f05248109748ed53b5a1ae7465317fc9fcd3ec + resolution: "@graphql-hive/importer@npm:1.0.0-alpha-b9f05248109748ed53b5a1ae7465317fc9fcd3ec" + checksum: 10c0/42d21c73e493be8aabea81b565b060aaaac27b7191b24fd61e6c22d7aa7b7856a7012a5e39ee3454dd7fb9681cce4499c287ff43954b90d67b1c24ed993002d0 + languageName: node + linkType: hard + "@graphql-hive/yoga@npm:^0.39.2": version: 0.39.2 resolution: "@graphql-hive/yoga@npm:0.39.2" @@ -6218,7 +6225,6 @@ __metadata: "@graphql-mesh/config": "npm:^0.106.17" "@graphql-mesh/cross-helpers": "npm:^0.4.9" "@graphql-mesh/http": "npm:^0.105.12" - "@graphql-mesh/include": "npm:^0.2.10" "@graphql-mesh/runtime": "npm:^0.105.12" "@graphql-mesh/store": "npm:^0.103.11" "@graphql-mesh/types": "npm:^0.103.11" @@ -6233,8 +6239,10 @@ __metadata: change-case: "npm:^4.1.2" cosmiconfig: "npm:^9.0.0" dotenv: "npm:^16.0.3" + get-tsconfig: "npm:^4.7.6" graphql-import-node: "npm:^0.0.5" graphql-ws: "npm:^6.0.0" + jiti: "npm:^2.0.0" json-bigint-patch: "npm:^0.0.8" json5: "npm:^2.2.3" mkdirp: "npm:^3.0.0" @@ -6260,8 +6268,8 @@ __metadata: resolution: "@graphql-mesh/compose-cli@workspace:packages/compose-cli" dependencies: "@commander-js/extra-typings": "npm:^13.0.0" + "@graphql-hive/importer": "npm:1.0.0-alpha-b9f05248109748ed53b5a1ae7465317fc9fcd3ec" "@graphql-mesh/fusion-composition": "npm:^0.7.17" - "@graphql-mesh/include": "npm:^0.2.10" "@graphql-mesh/string-interpolation": "npm:^0.5.7" "@graphql-mesh/types": "npm:^0.103.11" "@graphql-mesh/utils": "npm:^0.103.11" @@ -6445,18 +6453,18 @@ __metadata: languageName: unknown linkType: soft -"@graphql-mesh/include@npm:^0.2.10, @graphql-mesh/include@npm:^0.2.3, @graphql-mesh/include@workspace:packages/include": - version: 0.0.0-use.local - resolution: "@graphql-mesh/include@workspace:packages/include" +"@graphql-mesh/include@npm:^0.2.3": + version: 0.2.10 + resolution: "@graphql-mesh/include@npm:0.2.10" dependencies: "@graphql-mesh/utils": "npm:^0.103.11" dotenv: "npm:^16.3.1" get-tsconfig: "npm:^4.7.6" - glob: "npm:^11.0.0" jiti: "npm:^2.0.0" sucrase: "npm:^3.35.0" - languageName: unknown - linkType: soft + checksum: 10c0/bfe909b3722d2f26db42e54dab26288d12dafff79fbc249b94ebe7685933ee1cd90243952d1a6adfa7e84554737a00696e6106e470c7677752dbf6cecd66ae2d + languageName: node + linkType: hard "@graphql-mesh/json-schema@npm:0.108.13, @graphql-mesh/json-schema@npm:^0.108.13, @graphql-mesh/json-schema@workspace:packages/legacy/handlers/json-schema": version: 0.0.0-use.local