Skip to content

Feature/watcher esm #27

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

Merged
merged 8 commits into from
Apr 8, 2025
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
3 changes: 1 addition & 2 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,13 @@ steps:
- sleep 30

- name: watcher test
image: node:16.19.0-alpine
image: node:22.14-alpine3.21
commands:
- apk update && apk upgrade
- node -v
- cd watcher/
- npm ci
- npm run ci-test-token
- npm run ci-test-token-enterprise
- npm run ci-test-native

services:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## NEXT

- dropped support for iExec Enterprise (ERlc)
- migrate watcher to ESM
- upgrade watcher runtime to node 22
- upgrade watcher deps ethers to v6

## v6.4.1

- fix openapi for `GET /requestorders`
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.watcher
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16.19.0-alpine
FROM node:22.14-alpine3.21

RUN mkdir -p /app
WORKDIR /app
Expand Down
60 changes: 46 additions & 14 deletions watcher/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,18 +1,50 @@
{
"extends": ["airbnb-base", "prettier"],
"env": {
"es2020": true
},
"parserOptions": {
"ecmaVersion": 2020
},
"plugins": ["sonarjs"],
"extends": [
"airbnb-base",
"plugin:import/recommended",
"plugin:sonarjs/recommended",
"prettier"
],
"rules": {
"no-await-in-loop": "off",
"no-console": 0,
"no-constant-condition": ["error", { "checkLoops": false }],
"no-param-reassign": [
"error",
{ "props": true, "ignorePropertyModificationsFor": ["ret"] }
],
"no-underscore-dangle": [
"error",
{ "allow": ["_id", "_isBigNumber", "_websocket"] }
],
"default-param-last": "off",
"new-cap": "off",
"no-console": "error",
"no-underscore-dangle": "off",
"no-template-curly-in-string": "off",
"max-classes-per-file": "off",
"max-len": "off",
"max-classes-per-file": "off"
}
"import/prefer-default-export": "off",
"import/extensions": ["error", "always"],
"sonarjs/cognitive-complexity": ["warn", 15],
"sonarjs/no-duplicate-string": "off"
},
"overrides": [
{
"files": ["generateEsModulesFromJson.cjs"],
"rules": {
"no-console": "off"
}
},
{
"files": ["./test/**/*"],
"parser": "@babel/eslint-parser",
"parserOptions": {
"requireConfigFile": false,
"ecmaVersion": 2020
},
"env": {
"jest": true
},
"rules": {
"no-console": "off"
}
}
]
}
93 changes: 93 additions & 0 deletions watcher/generateEsModulesFromJson.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
const path = require('path');
const { writeFile, stat, mkdir } = require('fs/promises');

const minifiers = {
package: ({ name, version, description }) => ({ name, version, description }),
abi: ({ abi }) => ({ abi }),
truffleDeployment: ({ abi, networks }) => ({
abi,
networks: Object.fromEntries(
Object.entries(networks).map(([chainId, { address }]) => [
chainId,
{ address },
]),
),
}),
hardhatDeployment: ({ address }) => ({ address }),
};

const sources = [
[
'@iexec/poco/artifacts/contracts/registries/RegistryEntry.sol/RegistryEntry.json',
{ dir: '@iexec/poco', minifier: minifiers.abi },
],
[
'@iexec/poco/artifacts/contracts/IexecInterfaceToken.sol/IexecInterfaceToken.json',
{ dir: '@iexec/poco', minifier: minifiers.abi },
],
[
'@iexec/poco/artifacts/contracts/IexecInterfaceNative.sol/IexecInterfaceNative.json',
{ dir: '@iexec/poco', minifier: minifiers.abi },
],
[
'@iexec/poco/artifacts/contracts/registries/apps/AppRegistry.sol/AppRegistry.json',
{ dir: '@iexec/poco', minifier: minifiers.abi },
],
[
'@iexec/poco/artifacts/contracts/registries/workerpools/WorkerpoolRegistry.sol/WorkerpoolRegistry.json',
{ dir: '@iexec/poco', minifier: minifiers.abi },
],
[
'@iexec/poco/artifacts/contracts/registries/datasets/DatasetRegistry.sol/DatasetRegistry.json',
{ dir: '@iexec/poco', minifier: minifiers.abi },
],
[
'@iexec/poco/artifacts/contracts/registries/apps/App.sol/App.json',
{ dir: '@iexec/poco', minifier: minifiers.abi },
],
[
'@iexec/poco/artifacts/contracts/registries/workerpools/Workerpool.sol/Workerpool.json',
{ dir: '@iexec/poco', minifier: minifiers.abi },
],
[
'@iexec/poco/artifacts/contracts/registries/datasets/Dataset.sol/Dataset.json',
{ dir: '@iexec/poco', minifier: minifiers.abi },
],
];

const createEsModule = (jsonObj) => {
let module =
'// this file is auto generated do not edit it\n/* eslint-disable */\n';
Object.entries(jsonObj).forEach(([key, value]) => {
module += `export const ${key} = ${JSON.stringify(value)};\n`;
});
module += `export default { ${Object.keys(jsonObj).join(', ')} };`;
return module;
};

console.log('converting json files to es modules');

sources.map(async ([src, options]) => {
// eslint-disable-next-line import/no-dynamic-require, global-require
const jsonObj = require(src);
const minifiedJsonObj = options.minifier
? options.minifier(jsonObj)
: jsonObj;
const name =
(options && options.name) ||
`${src.split('/').pop().split('.json').shift()}.js`;
const module = createEsModule(minifiedJsonObj);
const outDir = path.join(`src/generated`, options && options.dir);

const outDirExists = await stat(outDir)
.then((outDirStat) => outDirStat.isDirectory())
.catch(() => false);
if (!outDirExists) {
await mkdir(outDir, {
recursive: true,
});
}
const outPath = path.join(outDir, name);
await writeFile(outPath, module);
console.log(`${src} => ${outPath}`);
});
Loading