From beda3188d226a29a220ca525ae320dd55e54379d Mon Sep 17 00:00:00 2001 From: Scott Twiname Date: Tue, 24 Oct 2023 10:54:17 +1300 Subject: [PATCH] Fix ts manifest build failing because of missing deps --- packages/cli/package.json | 1 + packages/cli/src/utils/build.ts | 16 +++---- yarn.lock | 75 +++++++++++++++++---------------- 3 files changed, 48 insertions(+), 44 deletions(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index 023936090b..0f583432f4 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -35,6 +35,7 @@ "terser-webpack-plugin": "^5.3.7", "ts-loader": "^9.2.6", "tslib": "^2.3.1", + "typescript": ">=5.2.2", "update-notifier": "5.1.0", "webpack": "^5.76.0", "webpack-merge": "^5.8.0", diff --git a/packages/cli/src/utils/build.ts b/packages/cli/src/utils/build.ts index 56219a74e1..321e4c7940 100644 --- a/packages/cli/src/utils/build.ts +++ b/packages/cli/src/utils/build.ts @@ -1,12 +1,11 @@ // Copyright 2020-2023 SubQuery Pte Ltd authors & contributors // SPDX-License-Identifier: GPL-3.0 -import {execFile} from 'child_process'; import {existsSync, lstatSync} from 'fs'; -import util from 'node:util'; import path from 'path'; import {Command} from '@oclif/core'; -import {DEFAULT_TS_MANIFEST, extensionIsTs, tsProjectYamlPath} from '@subql/common'; +import {DEFAULT_TS_MANIFEST, tsProjectYamlPath} from '@subql/common'; +import * as ts from 'typescript'; const requireScriptWrapper = (scriptPath: string, outputPath: string): string => `import {toJsonObject} from '@subql/common';` + @@ -38,14 +37,15 @@ export async function buildManifestFromLocation(location: string, command: Comma return directory; } +// eslint-disable-next-line @typescript-eslint/require-await async function generateManifestFromTs(projectManifestEntry: string, command: Command): Promise { const projectYamlPath = tsProjectYamlPath(projectManifestEntry); try { - await util.promisify(execFile)( - 'npx', - ['ts-node', '-e', requireScriptWrapper(projectManifestEntry, projectYamlPath)], - {cwd: path.dirname(projectManifestEntry)} - ); + const result = ts.transpileModule(requireScriptWrapper(projectManifestEntry, projectYamlPath), {}); + + // Run the compiled output + eval(result.outputText); + command.log(`Project manifest generated to ${projectYamlPath}`); } catch (error) { throw new Error(`Failed to build ${projectManifestEntry}: ${error}`); diff --git a/yarn.lock b/yarn.lock index 293b4f011e..fb9591ae7b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6246,6 +6246,7 @@ __metadata: terser-webpack-plugin: ^5.3.7 ts-loader: ^9.2.6 tslib: ^2.3.1 + typescript: ^5.2.2 update-notifier: 5.1.0 webpack: ^5.76.0 webpack-merge: ^5.8.0 @@ -6388,11 +6389,19 @@ __metadata: languageName: unknown linkType: soft -"@subql/common@npm:3.1.1": - version: 3.1.1 - resolution: "@subql/common@npm:3.1.1" +"@subql/common@^3.1.0, @subql/common@^3.1.1, @subql/common@workspace:*, @subql/common@workspace:packages/common": + version: 0.0.0-use.local + resolution: "@subql/common@workspace:packages/common" dependencies: - "@subql/types-core": 0.1.1 + "@subql/types-core": "workspace:*" + "@types/bn.js": 4.11.6 + "@types/detect-port": ^1 + "@types/fs-extra": ^9.0.13 + "@types/js-yaml": ^4.0.5 + "@types/pino": ^6.3.12 + "@types/semver": ^7.3.9 + "@types/tar": ^6.1.1 + "@types/update-notifier": ^6 axios: ^0.27.2 class-transformer: ^0.5.1 class-validator: ^0.14.0 @@ -6402,13 +6411,12 @@ __metadata: reflect-metadata: ^0.1.13 semver: ^7.5.2 update-notifier: 5.1.0 - checksum: 1d1e3070f0a2f2368a7ba24f9b98012ca88362d51e7e53ed146026aa8c2844e8d58335496a19341facf4422aa2cac89b05e87860b0a4f73e542ca91f8240cdd0 - languageName: node - linkType: hard + languageName: unknown + linkType: soft -"@subql/common@npm:^3.1.0, @subql/common@npm:^3.1.1": - version: 3.1.2 - resolution: "@subql/common@npm:3.1.2" +"@subql/common@npm:3.1.1": + version: 3.1.1 + resolution: "@subql/common@npm:3.1.1" dependencies: "@subql/types-core": 0.1.1 axios: ^0.27.2 @@ -6420,35 +6428,10 @@ __metadata: reflect-metadata: ^0.1.13 semver: ^7.5.2 update-notifier: 5.1.0 - checksum: e979fac54089276de67a3a498bdf53396ac3726542d9f38350bced06f45921ab937a885a9c6cf183f3f5e7c82877c8ce9e27a5a5bf1f6fae6113baf68b4b3e55 + checksum: 1d1e3070f0a2f2368a7ba24f9b98012ca88362d51e7e53ed146026aa8c2844e8d58335496a19341facf4422aa2cac89b05e87860b0a4f73e542ca91f8240cdd0 languageName: node linkType: hard -"@subql/common@workspace:*, @subql/common@workspace:packages/common": - version: 0.0.0-use.local - resolution: "@subql/common@workspace:packages/common" - dependencies: - "@subql/types-core": "workspace:*" - "@types/bn.js": 4.11.6 - "@types/detect-port": ^1 - "@types/fs-extra": ^9.0.13 - "@types/js-yaml": ^4.0.5 - "@types/pino": ^6.3.12 - "@types/semver": ^7.3.9 - "@types/tar": ^6.1.1 - "@types/update-notifier": ^6 - axios: ^0.27.2 - class-transformer: ^0.5.1 - class-validator: ^0.14.0 - fs-extra: ^10.1.0 - ipfs-http-client: 56 - js-yaml: ^4.1.0 - reflect-metadata: ^0.1.13 - semver: ^7.5.2 - update-notifier: 5.1.0 - languageName: unknown - linkType: soft - "@subql/node-core@workspace:*, @subql/node-core@workspace:packages/node-core": version: 0.0.0-use.local resolution: "@subql/node-core@workspace:packages/node-core" @@ -21685,6 +21668,16 @@ __metadata: languageName: node linkType: hard +"typescript@npm:^5.2.2": + version: 5.2.2 + resolution: "typescript@npm:5.2.2" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: 7912821dac4d962d315c36800fe387cdc0a6298dba7ec171b350b4a6e988b51d7b8f051317786db1094bd7431d526b648aba7da8236607febb26cf5b871d2d3c + languageName: node + linkType: hard + "typescript@patch:typescript@^4.9.5#~builtin": version: 4.9.5 resolution: "typescript@patch:typescript@npm%3A4.9.5#~builtin::version=4.9.5&hash=493e53" @@ -21695,6 +21688,16 @@ __metadata: languageName: node linkType: hard +"typescript@patch:typescript@^5.2.2#~builtin": + version: 5.2.2 + resolution: "typescript@patch:typescript@npm%3A5.2.2#~builtin::version=5.2.2&hash=493e53" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: 07106822b4305de3f22835cbba949a2b35451cad50888759b6818421290ff95d522b38ef7919e70fb381c5fe9c1c643d7dea22c8b31652a717ddbd57b7f4d554 + languageName: node + linkType: hard + "typical@npm:^4.0.0": version: 4.0.0 resolution: "typical@npm:4.0.0"