difftreelog
test fix shared command references
in: master
5 files changed
js-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
js-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"
}
}
js-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,
+ ],
+ };
+ },
+};
js-packages/tests/package.jsondiffbeforeafterboth--- a/js-packages/tests/package.json
+++ b/js-packages/tests/package.json
@@ -9,22 +9,15 @@
"type": "module",
"version": "1.0.0",
"main": "",
- "dependencies": {
- "rxjs": "^7.8.1",
- "tslib": "^2.6.2"
- },
"devDependencies": {
- "@types/node": "^20.8.10",
- "mocha": "^10.1.0",
- "ts-node": "^10.9.1",
- "typescript": "^5.1.6"
+ "mocha": "^10.1.0"
},
"scripts": {
- "setup": "ts-node --esm ./util/globalSetup.ts",
- "setIdentities": "ts-node --esm ./util/identitySetter.ts",
- "checkRelayIdentities": "ts-node --esm ./util/relayIdentitiesChecker.ts",
- "_test": "yarn setup && mocha --timeout 9999999 --loader=ts-node/esm.mjs",
- "_testParallel": "yarn setup && mocha --timeout 9999999 --parallel --loader=ts-node/esm.mjs",
+ "setup": "yarn ts-node --esm ./util/globalSetup.ts",
+ "setIdentities": "yarn ts-node --esm ./util/identitySetter.ts",
+ "checkRelayIdentities": "yarn ts-node --esm ./util/relayIdentitiesChecker.ts",
+ "_test": "yarn setup && yarn mocha --timeout 9999999 --loader=ts-node/esm.mjs",
+ "_testParallel": "yarn setup && yarn mocha --timeout 9999999 --parallel --loader=ts-node/esm.mjs",
"test": "yarn _test './**/*.*test.ts'",
"testParallel": "yarn _testParallel './**/*.test.ts'",
"testSequential": "yarn _test './**/*.seqtest.ts'",
js-packages/yarn.lockdiffbeforeafterboth1266"@unique/scripts@workspace:scripts":1266"@unique/scripts@workspace:scripts":1267 version: 0.0.0-use.local1267 version: 0.0.0-use.local1268 resolution: "@unique/scripts@workspace:scripts"1268 resolution: "@unique/scripts@workspace:scripts"1269 dependencies:1270 rxjs: ^7.8.11271 tslib: ^2.6.21272 languageName: unknown1269 languageName: unknown1273 linkType: soft1270 linkType: soft12741271