diff --git a/.changeset/flat-spiders-grin.md b/.changeset/flat-spiders-grin.md new file mode 100644 index 000000000..4459ba58f --- /dev/null +++ b/.changeset/flat-spiders-grin.md @@ -0,0 +1,5 @@ +--- +'@graphprotocol/graph-cli': patch +--- + +Fix `import.meta.url` not being parsed as path properly diff --git a/packages/cli/src/command-helpers/network.test.ts b/packages/cli/src/command-helpers/network.test.ts index 8edcc6a84..bc222be9c 100644 --- a/packages/cli/src/command-helpers/network.test.ts +++ b/packages/cli/src/command-helpers/network.test.ts @@ -1,11 +1,13 @@ import path from 'node:path'; +import { fileURLToPath } from 'node:url'; import * as toolbox from 'gluegun'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; import yaml from 'yaml'; import { initNetworksConfig, updateSubgraphNetwork } from './network.js'; const SUBGRAPH_PATH_BASE = path.join( - `${process.platform === 'win32' ? '' : '/'}${/file:\/{2,3}(.+)\/[^/]/.exec(import.meta.url)![1]}`, + fileURLToPath(import.meta.url), + '..', '..', '..', '..', diff --git a/packages/cli/src/commands/local.ts b/packages/cli/src/commands/local.ts index 6551de54e..b9bd3b8db 100644 --- a/packages/cli/src/commands/local.ts +++ b/packages/cli/src/commands/local.ts @@ -2,6 +2,7 @@ import { ChildProcess, spawn } from 'node:child_process'; import http from 'node:http'; import net from 'node:net'; import path from 'node:path'; +import { fileURLToPath } from 'node:url'; import compose from 'docker-compose'; import { filesystem, patching } from 'gluegun'; import stripAnsi from 'strip-ansi'; @@ -93,9 +94,8 @@ export default class LocalCommand extends Command { const composeFile = composeFileFlag || path.join( - `${process.platform === 'win32' ? '' : '/'}${ - /file:\/{2,3}(.+)\/[^/]/.exec(import.meta.url)![1] - }`, + fileURLToPath(import.meta.url), + '..', '..', '..', 'resources', diff --git a/packages/cli/src/subgraph.ts b/packages/cli/src/subgraph.ts index cdd59cffa..93b84fcf4 100644 --- a/packages/cli/src/subgraph.ts +++ b/packages/cli/src/subgraph.ts @@ -1,4 +1,5 @@ import path from 'node:path'; +import { fileURLToPath } from 'node:url'; import fs from 'fs-extra'; import * as graphql from 'graphql/language/index.js'; import immutable from 'immutable'; @@ -53,7 +54,8 @@ export default class Subgraph { const schema = graphql.parse( await fs.readFile( path.join( - `${process.platform === 'win32' ? '' : '/'}${/file:\/{2,3}(.+)\/[^/]/.exec(import.meta.url)![1]}`, + fileURLToPath(import.meta.url), + '..', 'protocols', // TODO: substreams/triggers is a special case, should be handled better protocol.name === 'substreams/triggers' ? 'substreams' : protocol.name, diff --git a/packages/cli/src/version.ts b/packages/cli/src/version.ts index 26971c752..e9fee6872 100644 --- a/packages/cli/src/version.ts +++ b/packages/cli/src/version.ts @@ -1,15 +1,12 @@ import fs from 'node:fs'; import path from 'node:path'; +import { fileURLToPath } from 'node:url'; const packageJson = JSON.parse( fs .readFileSync( // works even when bundled/built because the path to package.json is the same - path.join( - `${process.platform === 'win32' ? '' : '/'}${/file:\/{2,3}(.+)\/[^/]/.exec(import.meta.url)![1]}`, - '..', - 'package.json', - ), + path.join(fileURLToPath(import.meta.url), '..', '..', 'package.json'), ) .toString(), );