Skip to content

Commit

Permalink
chore(js): update dependencies, fix linter (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
osipov-mit authored Jan 28, 2025
1 parent 59b8488 commit aeb0973
Show file tree
Hide file tree
Showing 37 changed files with 1,948 additions and 1,737 deletions.
7 changes: 6 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ updates:
schedule:
interval: "weekly"
- package-ecosystem: "npm"
directory: "./js"
directory: "/"
schedule:
interval: "weekly"
versioning-strategy: "increase"
groups:
development:
dependency-type: "development"
production:
dependency-type: "production"
8 changes: 4 additions & 4 deletions .github/workflows/js-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ jobs:
- name: 'Install: dependencies'
run: yarn install

- name: 'Prepare: build all'
run: yarn build

- name: 'Prepare: fmt'
- name: 'Check lint'
run: yarn lint

- name: 'Build'
run: yarn build

- name: 'Prepare: download Gear node'
run: |
wget -O ./gear https://github.com/gear-tech/gear/releases/download/build/gear
Expand Down
925 changes: 0 additions & 925 deletions .yarn/releases/yarn-4.4.1.cjs

This file was deleted.

934 changes: 934 additions & 0 deletions .yarn/releases/yarn-4.6.0.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
yarnPath: .yarn/releases/yarn-4.4.1.cjs
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-4.6.0.cjs
45 changes: 37 additions & 8 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,46 @@
import globals from 'globals';
import pluginJs from '@eslint/js';
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslintPluginUnicorn from 'eslint-plugin-unicorn';
import globals from 'globals';

const files = ['js/**/src/**/*.ts', 'js/test/*.ts'];

export default [
{ files: ['js/**/src/**/*.{ts}'] },
{ languageOptions: { globals: { ...globals.browser, ...globals.node } } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
{
ignores: ['js/cli/build/**', '.yarn/**', '**/lib/**', 'js/test/demo/**'],
},
...[eslint.configs.recommended, ...tseslint.configs.recommended, eslintPluginUnicorn.configs['flat/recommended']].map(
(config) => ({
...config,
files,
}),
),
{
files,
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'all',
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-this-alias': 'off',
'no-unexpected-multiline': 'off',
'@typescript-eslint/no-empty-object-type': ['error', { allowInterfaces: 'with-single-extends' }],
'prefer-rest-params': 'off',
'unicorn/prevent-abbreviations': 'off',
'unicorn/no-null': 'off',
},
languageOptions: {
globals: {
...globals.browser,
...globals.es2020,
...globals.node,
},
},
},
];
8 changes: 8 additions & 0 deletions js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG

## 0.3.2

### Compatibility
- Sails-RS v0.7.1

### Changes
- Ability to get `gasInfo` in `TransactionBuilder` in https://github.com/gear-tech/sails/pull/745

## 0.3.1

### Compatibility
Expand Down
13 changes: 8 additions & 5 deletions js/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "sails-js-cli",
"description": "CLI allowing to generate Typescript library based on Sails IDL files",
"version": "0.3.1",
"preferGlobal": true,
"type": "module",
Expand All @@ -11,7 +12,8 @@
"homepage": "https://github.com/gear-tech/sails/tree/master/js#readme",
"repository": {
"type": "git",
"url": "git+https://githib.com/gear-tech/sails.git"
"url": "git+https://githib.com/gear-tech/sails.git",
"directory": "js/cli"
},
"keywords": [
"gear",
Expand All @@ -21,15 +23,16 @@
"sails-js": "./build/app.js"
},
"devDependencies": {
"@inquirer/prompts": "^7.1.0",
"commander": "^12.1.0",
"inquirer": "^12.1.0",
"@inquirer/prompts": "^7.2.3",
"commander": "^13.1.0",
"inquirer": "^12.3.2",
"sails-js": "workspace:*",
"sails-js-parser": "workspace:*",
"sails-js-util": "workspace:^"
},
"scripts": {
"build": "npx rollup --config rollup.config.js"
"build": "npx rollup --config rollup.config.js",
"clean": "rm -rf build"
},
"files": [
"build"
Expand Down
10 changes: 5 additions & 5 deletions js/cli/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFileSync, rmSync, writeFileSync } from 'fs';
import { readFileSync, rmSync, writeFileSync } from 'node:fs';
import commonjs from '@rollup/plugin-commonjs';
import nodeResolve from '@rollup/plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';
Expand All @@ -17,14 +17,14 @@ function updateConfigVersions() {
return {
name: 'update-config-versions',
buildStart() {
const sailsJs = JSON.parse(readFileSync('../package.json', 'utf-8'));
const rootPkgJson = JSON.parse(readFileSync('../../package.json', 'utf-8'));
const config = JSON.parse(readFileSync('src/config.json', 'utf-8'));
const sailsJs = JSON.parse(readFileSync('../package.json', 'utf8'));
const rootPackageJson = JSON.parse(readFileSync('../../package.json', 'utf8'));
const config = JSON.parse(readFileSync('src/config.json', 'utf8'));

config.versions['gear-js'] = sailsJs.peerDependencies['@gear-js/api'];
config.versions['polkadot-api'] = sailsJs.peerDependencies['@polkadot/api'];
config.versions['sails-js'] = sailsJs.version;
config.versions['typescript'] = rootPkgJson.devDependencies.typescript;
config.versions['typescript'] = rootPackageJson.devDependencies.typescript;

writeFileSync('src/config.json', JSON.stringify(config, null, 2));
},
Expand Down
6 changes: 3 additions & 3 deletions js/cli/src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
]
},
"versions": {
"gear-js": "0.38.3",
"polkadot-api": "13.2.1",
"gear-js": "0.40.0",
"polkadot-api": "15.4.1",
"sails-js": "0.3.1",
"typescript": "^5.7.2"
"typescript": "^5.7.3"
}
}
15 changes: 7 additions & 8 deletions js/cli/src/generate/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { confirm } from '@inquirer/prompts';
import { Sails } from 'sails-js';

import path from 'node:path';
import { ServiceGenerator } from './service-gen.js';
import { TypesGenerator } from './types-gen.js';
import { Output } from './output.js';
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
import path from 'path';
import { confirm } from '@inquirer/prompts';
import * as config from '../config.json';

export class ProjectBuilder {
Expand Down Expand Up @@ -50,14 +49,14 @@ export class ProjectBuilder {
}

setIdlPath(path: string) {
const idl = readFileSync(path, 'utf-8');
const idl = readFileSync(path, 'utf8');
this.sails.parseIdl(idl);

return this;
}

setRootPath(path: string) {
this.projectPath[0] = path ? path : '.';
this.projectPath[0] = path ?? '.';

return this;
}
Expand Down Expand Up @@ -89,15 +88,15 @@ export class ProjectBuilder {
if (await this.canCreateFile(libFile)) {
writeFileSync(libFile, libCode);
} else {
process.exit(0);
throw new Error(`Failed to write file ${libFile}`);
}

const typesCode = this.generateTypes();
const typesFile = path.join(libPath, 'global.d.ts');
if (await this.canCreateFile(typesFile)) {
writeFileSync(typesFile, typesCode);
} else {
process.exit(0);
throw new Error(`Failed to write file ${typesFile}`);
}

if (!this.isProject) {
Expand Down
12 changes: 6 additions & 6 deletions js/cli/src/generate/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ export class Output {
}

lines(data: string[], semicolon = true) {
data.forEach((line) => this.line(line, semicolon));
for (const line of data) this.line(line, semicolon);
return this;
}

block(beginning: string, content?: () => void, bracket: '{' | '[' | '(' = '{') {
const openBracket = bracket;
const closeBracket = openBracket === '{' ? '}' : openBracket === '[' ? '];' : ');';
this._rows.push(`${this._indent}${beginning} ${openBracket}${!content ? ' ' + closeBracket : ''}`);
const closeBracket = openBracket === '{' ? '}' : (openBracket === '[' ? '];' : ');');
this._rows.push(`${this._indent}${beginning} ${openBracket}${content ? '' : ' ' + closeBracket}`);
if (content) {
this.increaseIndent();
content();
Expand All @@ -64,14 +64,14 @@ export class Output {
}

reduceIndent() {
this._indent = this._indent.substring(2);
this._indent = this._indent.slice(2);
return this;
}

finalize() {
const result = [];
const imports = Array.from(this._imports).map(
([module_, imports_]) => `import { ${Array.from(imports_).join(', ')} } from '${module_}';`,
const imports = [...this._imports].map(
([module_, imports_]) => `import { ${[...imports_].join(', ')} } from '${module_}';`,
);
if (imports.length > 0) result.push(imports.join('\n'));

Expand Down
17 changes: 7 additions & 10 deletions js/cli/src/generate/service-gen.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { getPayloadMethod, getScaleCodecDef, PayloadMethod, toLowerCaseFirst } from 'sails-js-util';
import { ISailsFuncParam, ISailsProgram, ISailsService } from 'sails-js-types';

import { Output } from './output.js';
import { BaseGenerator } from './base.js';
import { formatDocs } from './format.js';
Expand All @@ -14,13 +13,11 @@ const getFuncName = (name: string) => {
};

const createPayload = (serviceName: string, fnName: string, params: ISailsFuncParam[]) => {
if (params.length === 0) {
return `const payload = this._program.registry.createType('(String, String)', ['${serviceName}', '${fnName}']).toHex()`;
} else {
return `const payload = this._program.registry.createType('(String, String, ${params
.map(({ def }) => getScaleCodecDef(def))
.join(', ')})', ['${serviceName}', '${fnName}', ${params.map(({ name }) => name).join(', ')}]).toHex()`;
}
return params.length === 0
? `const payload = this._program.registry.createType('(String, String)', ['${serviceName}', '${fnName}']).toHex()`
: `const payload = this._program.registry.createType('(String, String, ${params
.map(({ def }) => getScaleCodecDef(def))
.join(', ')})', ['${serviceName}', '${fnName}', ${params.map(({ name }) => name).join(', ')}]).toHex()`;
};

export class ServiceGenerator extends BaseGenerator {
Expand Down Expand Up @@ -90,7 +87,7 @@ export class ServiceGenerator extends BaseGenerator {
$.lines(ctorDocs, false)
.block(
`${getFuncName(name)}CtorFromCode(code: Uint8Array | Buffer${
args !== null ? ', ' + args : ''
args === null ? '' : ', ' + args
}): TransactionBuilder<null>`,
() => {
$.line(`const builder = new TransactionBuilder<null>(`, false)
Expand Down Expand Up @@ -120,7 +117,7 @@ export class ServiceGenerator extends BaseGenerator {
.line()
.lines(ctorDocs, false)
.block(
`${getFuncName(name)}CtorFromCodeId(codeId: ${HEX_STRING_TYPE}${args !== null ? ', ' + args : ''})`,
`${getFuncName(name)}CtorFromCodeId(codeId: ${HEX_STRING_TYPE}${args === null ? '' : ', ' + args})`,
() => {
$.line(`const builder = new TransactionBuilder<null>(`, false)
.increaseIndent()
Expand Down
6 changes: 1 addition & 5 deletions js/cli/src/generate/types-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ export class TypesGenerator extends BaseGenerator {
}

private getEnumFieldString(f: ISailsEnumVariant) {
if (!f.def) {
return `{ ${toLowerCaseFirst(f.name)}: null }`;
} else {
return `{ ${toLowerCaseFirst(f.name)}: ${this.getType(f.def)} }`;
}
return f.def ? `{ ${toLowerCaseFirst(f.name)}: ${this.getType(f.def)} }` : `{ ${toLowerCaseFirst(f.name)}: null }`;
}
}
2 changes: 1 addition & 1 deletion js/config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"sails-rs": "0.7.0"
"sails-rs": "0.7.1"
}
11 changes: 6 additions & 5 deletions js/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
"private": true,
"type": "module",
"dependencies": {
"@gear-js/api": "0.40.0",
"@polkadot/api": "15.0.1",
"sails-js": "0.3.0"
"@gear-js/api": "0.41.0",
"@polkadot/api": "15.4.1",
"sails-js": "0.3.1"
},
"devDependencies": {
"typescript": "^5.7.2"
"typescript": "^5.7.3"
},
"scripts": {
"build": "tsc"
"build": "tsc",
"clean": "rm -rf lib"
}
}
9 changes: 2 additions & 7 deletions js/example/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GearApi } from '@gear-js/api';
import { Keyring } from '@polkadot/api';
import { Program } from './lib.js';
import { readFileSync } from 'fs';
import { readFileSync } from 'node:fs';

const main = async () => {
const api = await GearApi.create();
Expand Down Expand Up @@ -34,9 +34,4 @@ const main = async () => {
console.log(`\nProgram replied: \n\t${JSON.stringify(reply)}`);
};

main()
.then(() => process.exit(0))
.catch((error) => {
console.log(error);
process.exit(1);
});
await main();
Loading

0 comments on commit aeb0973

Please sign in to comment.