git.delta.rocks / unique-network / refs/commits / ba5a87350f03

difftreelog

test fix shared command references

Yaroslav Bolyukin2023-11-16parent: #6d1c846.patch.diff
in: master

5 files changed

modifiedjs-packages/.yarnrc.ymldiffbeforeafterboth
--- a/js-packages/.yarnrc.yml
+++ b/js-packages/.yarnrc.yml
@@ -1,3 +1,6 @@
 nodeLinker: node-modules
 
 yarnPath: .yarn/releases/yarn-3.6.1.cjs
+
+plugins:
+- ./scripts/plugins/shared.cjs
modifiedjs-packages/scripts/package.jsondiffbeforeafterboth
--- a/js-packages/scripts/package.json
+++ b/js-packages/scripts/package.json
@@ -9,15 +9,11 @@
   "type": "module",
   "version": "1.0.0",
   "main": "",
-  "dependencies": {
-    "rxjs": "^7.8.1",
-    "tslib": "^2.6.2"
-  },
   "scripts": {
-    "benchMintingFee": "ts-node benchmarks/mintFee/benchmark.ts",
-    "loadTransfer": "ts-node transfer.nload.ts",
-    "generateEnv": "ts-node --esm ./generateEnv.ts",
-    "propose-upgrade": "ts-node --esm ./proposeupgrade.ts",
-    "propose-fast-track": "ts-node --esm ./proposefasttrack.ts"
+    "benchMintingFee": "yarn ts-node benchmarks/mintFee/benchmark.ts",
+    "loadTransfer": "yarn ts-node transfer.nload.ts",
+    "generateEnv": "yarn ts-node --esm ./generateEnv.ts",
+    "propose-upgrade": "yarn ts-node --esm ./proposeupgrade.ts",
+    "propose-fast-track": "yarn ts-node --esm ./proposefasttrack.ts"
   }
 }
addedjs-packages/scripts/plugins/shared.cjsdiffbeforeafterboth
--- /dev/null
+++ b/js-packages/scripts/plugins/shared.cjs
@@ -0,0 +1,63 @@
+const npmBinsToPackageName = {
+  'ts-node': 'ts-node',
+  'eslint': 'eslint',
+  'tsc': 'typescript',
+  'mocha': 'mocha',
+};
+
+const paths = [];
+for(const k of Object.keys(npmBinsToPackageName)) {
+  paths.push([k], ['run', k]);
+}
+
+module.exports = {
+  name: 'plugin-root-bin',
+  factory: require => {
+    const {BaseCommand} = require('@yarnpkg/cli');
+    const {Option} = require('clipanion');
+
+    class ExecuteBinFromRootCommand extends BaseCommand {
+      static paths = paths;
+
+      args = Option.Proxy();
+
+      async execute() {
+        const fs = require('fs');
+        const path = require('path');
+
+        const ownPackageJson = JSON.parse(await fs.promises.readFile('package.json', 'utf-8'));
+        const cmd = this.path[this.path.length - 1];
+
+        if(ownPackageJson.scripts?.[cmd]) {
+          throw new Error(`'${cmd}' is defined in package.json but the 'plugin-root-bin' also defined it. To avoid unexpected results, please rename the script in package.json`);
+        }
+
+        const dir = await this.getBinaryPackageDirectory(fs, path, cmd, ownPackageJson);
+        const pkg = JSON.parse(await fs.promises.readFile(path.join(dir, 'package.json'), 'utf-8'));
+
+        const packageRelativeBinPath = typeof pkg.bin === 'object'
+          ? pkg.bin[cmd]
+          : pkg.bin;
+
+        const binPath = path.join(dir, packageRelativeBinPath);
+
+        process.exitCode = await this.cli.run(['node', binPath, ...this.args]);
+
+        // seems something in yarn resets the exit code, so force exit
+        process.exit();
+      }
+
+      async getBinaryPackageDirectory(_fs, path, cmd, _ownPackageJson) {
+        const res = path.resolve(__dirname, '../../node_modules', npmBinsToPackageName[cmd]);
+        console.error(res);
+        return res;
+      }
+    }
+
+    return {
+      commands: [
+        ExecuteBinFromRootCommand,
+      ],
+    };
+  },
+};
modifiedjs-packages/tests/package.jsondiffbeforeafterboth
before · js-packages/tests/package.json
1{2    "author": "",3    "license": "SEE LICENSE IN ../../../LICENSE",4    "description": "Interfaces for interacting with contracts and contract ABIs",5    "engines": {6        "node": ">=16"7    },8    "name": "@unique/tests",9    "type": "module",10    "version": "1.0.0",11    "main": "",12    "dependencies": {13        "rxjs": "^7.8.1",14        "tslib": "^2.6.2"15    },16    "devDependencies": {17        "@types/node": "^20.8.10",18        "mocha": "^10.1.0",19        "ts-node": "^10.9.1",20        "typescript": "^5.1.6"21    },22    "scripts": {23        "setup": "ts-node --esm ./util/globalSetup.ts",24        "setIdentities": "ts-node --esm ./util/identitySetter.ts",25        "checkRelayIdentities": "ts-node --esm ./util/relayIdentitiesChecker.ts",26        "_test": "yarn setup && mocha --timeout 9999999 --loader=ts-node/esm.mjs",27        "_testParallel": "yarn setup && mocha --timeout 9999999 --parallel --loader=ts-node/esm.mjs",28        "test": "yarn _test './**/*.*test.ts'",29        "testParallel": "yarn _testParallel './**/*.test.ts'",30        "testSequential": "yarn _test './**/*.seqtest.ts'",31        "testGovernance": "RUN_GOV_TESTS=1 yarn _test ./**/governance/*.*test.ts",32        "testCollators": "RUN_COLLATOR_TESTS=1 yarn _test ./**/collator-selection/**.*test.ts --timeout 49999999",33        "load": "yarn _test './**/*.load.ts'"34    }35}
modifiedjs-packages/yarn.lockdiffbeforeafterboth
--- a/js-packages/yarn.lock
+++ b/js-packages/yarn.lock
@@ -1266,9 +1266,6 @@
 "@unique/scripts@workspace:scripts":
   version: 0.0.0-use.local
   resolution: "@unique/scripts@workspace:scripts"
-  dependencies:
-    rxjs: ^7.8.1
-    tslib: ^2.6.2
   languageName: unknown
   linkType: soft