diff --git a/.changeset/@graphprotocol_graph-cli-1914-dependencies.md b/.changeset/@graphprotocol_graph-cli-1914-dependencies.md new file mode 100644 index 000000000..5e220d3bd --- /dev/null +++ b/.changeset/@graphprotocol_graph-cli-1914-dependencies.md @@ -0,0 +1,5 @@ +--- +"@graphprotocol/graph-cli": patch +--- +dependencies updates: + - Removed dependency [`binary-install@^1.1.0` ↗︎](https://www.npmjs.com/package/binary-install/v/1.1.0) (from `dependencies`) diff --git a/.changeset/afraid-cycles-act.md b/.changeset/afraid-cycles-act.md new file mode 100644 index 000000000..e9bfcab04 --- /dev/null +++ b/.changeset/afraid-cycles-act.md @@ -0,0 +1,5 @@ +--- +'@graphprotocol/graph-cli': patch +--- + +fix bug with graph test #1904 diff --git a/packages/cli/package.json b/packages/cli/package.json index 6fd6dbd3a..fbd723ccd 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -39,7 +39,6 @@ "@pinax/graph-networks-registry": "^0.6.5", "@whatwg-node/fetch": "^0.10.1", "assemblyscript": "0.19.23", - "binary-install": "^1.1.0", "chokidar": "4.0.1", "debug": "4.3.7", "docker-compose": "1.1.0", diff --git a/packages/cli/src/commands/binary-install.d.ts b/packages/cli/src/commands/binary-install.d.ts deleted file mode 100644 index 6cbce6ef3..000000000 --- a/packages/cli/src/commands/binary-install.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'binary-install'; diff --git a/packages/cli/src/commands/test.ts b/packages/cli/src/commands/test.ts index 9fb698bee..d8e6fba03 100644 --- a/packages/cli/src/commands/test.ts +++ b/packages/cli/src/commands/test.ts @@ -1,13 +1,15 @@ import { exec, spawn } from 'node:child_process'; +import events from 'node:events'; +import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; -import { Binary } from 'binary-install'; +import { pipeline } from 'node:stream/promises'; +import { fileURLToPath } from 'node:url'; import { filesystem, patching, print, system } from 'gluegun'; import yaml from 'js-yaml'; import semver from 'semver'; import { Args, Command, Flags } from '@oclif/core'; import { GRAPH_CLI_SHARED_HEADERS } from '../constants.js'; -import fetch from '../fetch.js'; export default class TestCommand extends Command { static description = 'Runs rust binary for subgraph testing.'; @@ -144,32 +146,52 @@ async function runBinary( }, ) { const coverageOpt = opts.coverage; - const forceOpt = opts.force; const logsOpt = opts.logs; const versionOpt = opts.version; const latestVersion = opts.latestVersion; const recompileOpt = opts.recompile; + let binPath = ''; - const platform = await getPlatform.bind(this)(versionOpt || latestVersion, logsOpt); + try { + const platform = await getPlatform.bind(this)(versionOpt || latestVersion, logsOpt); - const url = `https://github.com/LimeChain/matchstick/releases/download/${ - versionOpt || latestVersion - }/${platform}`; + const url = `https://github.com/LimeChain/matchstick/releases/download/${versionOpt || latestVersion}/${platform}`; + const binDir = path.join(path.dirname(fileURLToPath(import.meta.url)), 'node_modules', '.bin'); + binPath = path.join(binDir, `matchstick-${platform}`); - if (logsOpt) { - this.log(`Download link: ${url}`); + if (logsOpt) { + this.log(`Download link: ${url}`); + this.log(`Binary path: ${binPath}`); + } + + if (!fs.existsSync(binPath)) { + this.log(`Downloading matchstick binary: ${url}`); + await fs.promises.mkdir(binDir, { recursive: true }); + const response = await fetch(url); + if (!response.ok) throw new Error(`Status: ${response.statusText}`); + if (!response.body) throw new Error('No response body received'); + + const fileStream = fs.createWriteStream(binPath); + await pipeline(response.body, fileStream); + await fs.promises.chmod(binPath, '755'); + } + } catch (e) { + this.error( + `Failed to get matchstick binary: ${e.message}\nConsider using -d flag to run it in Docker instead:\n graph test -d`, + { exit: 1 }, + ); } - const binary = new Binary(platform, url, versionOpt || latestVersion); - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - forceOpt ? await binary.install(true) : await binary.install(false); const args = []; - if (coverageOpt) args.push('-c'); if (recompileOpt) args.push('-r'); if (datasource) args.push(datasource); - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - args.length > 0 ? binary.run(...args) : binary.run(); + + const child = spawn(binPath, args, { stdio: 'inherit' }); + const [code] = await events.once(child, 'exit'); + if (code !== 0) { + this.error('Matchstick failed', { exit: 1 }); + } } async function getPlatform( @@ -180,7 +202,7 @@ async function getPlatform( const type = os.type(); const arch = os.arch(); const cpuCore = os.cpus()[0]; - const isAppleSilicon = arch === 'arm64' && /Apple (M1|M2|M3|M4|processor)/.test(cpuCore.model); + const isAppleSilicon = arch === 'arm64' && /Apple (M[0-9]|processor)/.test(cpuCore.model); const linuxInfo = type === 'Linux' ? await getLinuxInfo.bind(this)() : {}; const linuxDistro = linuxInfo.name; const release = linuxInfo.version || os.release(); @@ -204,7 +226,7 @@ async function getPlatform( } return 'binary-macos-12'; } - if (type === 'Linux' && majorVersion === 22) { + if (type === 'Linux' && (majorVersion === 22 || majorVersion === 24)) { return 'binary-linux-22'; } } else { @@ -283,10 +305,6 @@ async function runDocker( const latestVersion = opts.latestVersion; const recompileOpt = opts.recompile; - // Remove binary-install binaries, because docker has permission issues - // when building the docker images - filesystem.remove('./node_modules/binary-install/bin'); - // Get current working directory const current_folder = filesystem.cwd(); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ecdbb63ea..1f8bac320 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -257,15 +257,12 @@ importers: assemblyscript: specifier: 0.19.23 version: 0.19.23 - binary-install: - specifier: ^1.1.0 - version: 1.1.0(debug@4.3.7) chokidar: specifier: 4.0.1 version: 4.0.1 debug: specifier: 4.3.7 - version: 4.3.7(supports-color@5.5.0) + version: 4.3.7(supports-color@8.1.1) docker-compose: specifier: 1.1.0 version: 1.1.0 @@ -4427,9 +4424,6 @@ packages: axios@0.21.4: resolution: {integrity: sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==} - axios@0.26.1: - resolution: {integrity: sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==} - axios@1.7.9: resolution: {integrity: sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==} @@ -4527,10 +4521,6 @@ packages: resolution: {integrity: sha512-v7ms6N/H7iciuk6QInon3/n2mu7oRX+6knJ9xFPsJ3rQePgAqcR3CRTwUheFd8SLbiq4LL7Z4G/44L9zscdt9A==} engines: {node: '>=10'} - binary-install@1.1.0: - resolution: {integrity: sha512-rkwNGW+3aQVSZoD0/o3mfPN6Yxh3Id0R/xzTVBVVpGNlVz8EGwusksxRlbk/A5iKTZt9zkMn3qIqmAt3vpfbzg==} - engines: {node: '>=10'} - binaryen@101.0.0-nightly.20210723: resolution: {integrity: sha512-eioJNqhHlkguVSbblHOtLqlhtC882SOEPKmNFZaDuz1hzQjolxZ+eu3/kaS10n3sGPONsIZsO7R9fR00UyhEUA==} hasBin: true @@ -15376,12 +15366,6 @@ snapshots: transitivePeerDependencies: - debug - axios@0.26.1(debug@4.3.7): - dependencies: - follow-redirects: 1.15.9(debug@4.3.7) - transitivePeerDependencies: - - debug - axios@1.7.9: dependencies: follow-redirects: 1.15.9(debug@4.3.7) @@ -15573,14 +15557,6 @@ snapshots: transitivePeerDependencies: - debug - binary-install@1.1.0(debug@4.3.7): - dependencies: - axios: 0.26.1(debug@4.3.7) - rimraf: 3.0.2 - tar: 6.2.1 - transitivePeerDependencies: - - debug - binaryen@101.0.0-nightly.20210723: {} binaryen@102.0.0-nightly.20211028: {} @@ -17494,7 +17470,7 @@ snapshots: follow-redirects@1.15.9(debug@4.3.7): optionalDependencies: - debug: 4.3.7(supports-color@5.5.0) + debug: 4.3.7(supports-color@8.1.1) for-each@0.3.3: dependencies: @@ -18063,7 +18039,7 @@ snapshots: http-call@5.3.0: dependencies: content-type: 1.0.5 - debug: 4.3.7(supports-color@5.5.0) + debug: 4.3.7(supports-color@8.1.1) is-retry-allowed: 1.2.0 is-stream: 2.0.1 parse-json: 4.0.0 @@ -19666,7 +19642,7 @@ snapshots: async-retry: 1.3.3 chalk: 4.1.2 change-case: 4.1.2 - debug: 4.3.7(supports-color@5.5.0) + debug: 4.3.7(supports-color@8.1.1) ejs: 3.1.10 find-yarn-workspace-root: 2.0.0 fs-extra: 8.1.0 @@ -21767,7 +21743,7 @@ snapshots: vite-node@2.1.8(@types/node@22.10.1): dependencies: cac: 6.7.14 - debug: 4.3.7(supports-color@5.5.0) + debug: 4.3.7(supports-color@8.1.1) es-module-lexer: 1.5.4 pathe: 1.1.2 vite: 5.4.11(@types/node@22.10.1) @@ -21821,7 +21797,7 @@ snapshots: '@vitest/spy': 2.1.8 '@vitest/utils': 2.1.8 chai: 5.1.2 - debug: 4.3.7(supports-color@5.5.0) + debug: 4.3.7(supports-color@8.1.1) expect-type: 1.1.0 magic-string: 0.30.14 pathe: 1.1.2