Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update codegen pathing for protogen #196

Merged
merged 3 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/common-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Update codegen pathing for OS consistency (#196)

## [3.1.1] - 2023-10-26
### Changed
Expand Down
20 changes: 19 additions & 1 deletion packages/common-cosmos/src/codegen/codegen-controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-3.0

import fs from 'fs';
import os from 'os';
import path from 'path';
import {promisify} from 'util';
import {CosmosRuntimeDatasource} from '@subql/types-cosmos';
Expand All @@ -16,9 +17,12 @@ import {
processProtoFilePath,
tempProtoDir,
} from './codegen-controller';
import {loadCosmwasmAbis} from './util';
import {loadCosmwasmAbis, tmpProtoDir} from './util';

const PROJECT_PATH = path.join(__dirname, '../../test/protoTest1');
const describeIf = (condition: boolean, ...args: Parameters<typeof describe>) =>
// eslint-disable-next-line jest/valid-describe-callback, jest/valid-title, jest/no-disabled-tests
condition ? describe(...args) : describe.skip(...args);

describe('Codegen cosmos', () => {
describe('Protobuf to ts', () => {
Expand Down Expand Up @@ -191,4 +195,18 @@ describe('Codegen cosmos', () => {
await promisify(rimraf)(path.join(PROJECT_PATH, 'test.ts'));
});
});
it('ensure correct protoDir on macos', () => {
const protoPath = '/Users/ben/subql-workspace/node/subql/node_modules/@protobufs/amino';
const tmpDir = '/var/folders/ks/720tmlnn3fj6m4sg91c7spjm0000gn/T/wS0Gob';
const macosPath = path.join(tmpDir, `${protoPath.replace(path.dirname(protoPath), '')}`);
expect(tmpProtoDir(tmpDir, protoPath)).toEqual(macosPath);
});
describeIf(os.platform() === 'win32', 'ensure correct protoDir on windowsOs', () => {
it('correct pathing on windows', () => {
const winProtoPath = 'C:\\Users\\zzz\\subql\\subql\\node_modules@protobufs\\amino';
const winTmpDir = 'C:\\Users\\zzz\\AppData\\Local\\Temp\\GZTuPZ';

expect(tmpProtoDir(winTmpDir, winProtoPath)).toEqual('C:\\Users\\zzz\\AppData\\Local\\Temp\\GZTuPZ\\amino');
});
});
});
4 changes: 2 additions & 2 deletions packages/common-cosmos/src/codegen/codegen-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {copySync} from 'fs-extra';
import {IDLObject} from 'wasm-ast-types';
import {isRuntimeCosmosDs} from '../project';
import {COSMWASM_OPTS, TELESCOPE_OPTS} from './constants';
import {loadCosmwasmAbis} from './util';
import {loadCosmwasmAbis, tmpProtoDir} from './util';

const TYPE_ROOT_DIR = 'src/types';

Expand Down Expand Up @@ -186,7 +186,7 @@ export async function tempProtoDir(projectPath: string): Promise<string> {

commonProtoPaths.forEach((p) => {
// ensure output format is a dir
copySync(p, path.join(tmpDir, `${p.replace(path.dirname(p), '')}`));
copySync(p, tmpProtoDir(tmpDir, p));
});
copySync(userProto, tmpDir, {overwrite: true});
return tmpDir;
Expand Down
5 changes: 5 additions & 0 deletions packages/common-cosmos/src/codegen/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import path from 'path';
import {loadFromJsonOrYaml} from '@subql/common';
import {IDLObject} from 'wasm-ast-types';
import {parseCosmosProjectManifest, ProjectManifestImpls} from '../project';
Expand All @@ -16,3 +17,7 @@ export function validateCosmosManifest(manifest: unknown): manifest is ProjectMa
export function loadCosmwasmAbis(filePath: string): IDLObject {
return loadFromJsonOrYaml(filePath) as IDLObject;
}

export function tmpProtoDir(tmpDir: string, protoPath: string): string {
return path.join(tmpDir, path.basename(protoPath));
}