From 34fc11561d43074839497d6cffa06b8ae7b49229 Mon Sep 17 00:00:00 2001 From: Matteo Cristino <102997993+matteo-cristino@users.noreply.github.com> Date: Fri, 24 May 2024 16:06:15 +0200 Subject: [PATCH] feat: add version of plugin in the error title from the package.json (#141) * feat(core): add @slangroom/core version on parse error This should be extended to all type of errors * refactor(core): improve @slangroom&core package version print on error * feat: add version on error to almost all plugins * feat(db): add plugin version in error message * test(db): fix zencode type * feat(ignored): add plugin version in error title * chore: move module from node16 to esnext now json import is working but with a warning: (node:17829) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time (Use to show where the warning was created) * fix(json-schema): bump ajv dep to 8.13.0 that now support direct use of constructor * fix: use import instead of require to read the packge.json --------- Co-authored-by: Puria Nafisi Azizi --- package.json | 2 +- pkg/core/package.json | 3 ++- pkg/core/src/lexer.ts | 4 ++- pkg/core/src/parser.ts | 4 ++- pkg/core/test/errors.ts | 46 ++++++++++++++++++----------------- pkg/db/package.json | 3 ++- pkg/db/src/plugin.ts | 4 ++- pkg/db/test/e2e.ts | 6 +++-- pkg/db/test/raw_query.ts | 8 +++--- pkg/ethereum/package.json | 3 ++- pkg/ethereum/src/plugin.ts | 4 ++- pkg/fs/package.json | 3 ++- pkg/fs/src/plugin.ts | 4 ++- pkg/fs/test/e2e.ts | 12 +++++---- pkg/git/package.json | 3 ++- pkg/git/src/plugin.ts | 4 ++- pkg/helpers/package.json | 3 ++- pkg/helpers/src/plugin.ts | 4 ++- pkg/helpers/test/concat.ts | 4 ++- pkg/helpers/test/pick.ts | 4 ++- pkg/http/package.json | 3 ++- pkg/http/src/plugin.ts | 4 ++- pkg/http/test/e2e.ts | 4 ++- pkg/ignored/package.json | 3 ++- pkg/ignored/src/index.ts | 4 ++- pkg/json-schema/package.json | 5 ++-- pkg/json-schema/src/plugin.ts | 8 +++--- pkg/oauth/package.json | 3 ++- pkg/oauth/src/plugin.ts | 4 ++- pkg/pocketbase/package.json | 3 ++- pkg/pocketbase/src/plugin.ts | 4 ++- pkg/pocketbase/test/e2e.ts | 4 ++- pkg/qrcode/package.json | 3 ++- pkg/qrcode/src/plugin.ts | 4 ++- pkg/redis/package.json | 3 ++- pkg/redis/src/plugin.ts | 4 ++- pkg/shell/package.json | 3 ++- pkg/shell/src/plugin.ts | 6 +++-- pkg/shell/test/e2e.ts | 6 +++-- pkg/wallet/package.json | 3 ++- pkg/wallet/src/plugin.ts | 4 ++- pkg/zencode/package.json | 3 ++- pkg/zencode/src/plugin.ts | 4 ++- pkg/zencode/test/e2e.ts | 4 ++- pnpm-lock.yaml | 11 +++------ tsconfig.json | 6 ++--- 46 files changed, 154 insertions(+), 87 deletions(-) diff --git a/package.json b/package.json index fd681e4b..f563f9ef 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "test": "pnpm build && pnpm -F @slangroom/* exec ava --verbose build/esm/test", "coverage": "c8 -r text -r lcov -o .coverage --exclude '**/test/' pnpm test", "clean": "rm -rf .coverage && pnpm -F @slangroom/* exec -- rm -rf build", - "build": "pnpm -F @slangroom/* exec tsc --outdir build/esm --module node16", + "build": "pnpm -F @slangroom/* exec tsc --outdir build/esm", "publish:ci": "lerna version --no-changelog --conventional-commits --yes && pnpm publish -r --no-git-checks --filter './pkg/*'", "docs:api": "node docs/statements/index.mjs", "docs:ci": "node docs/statements/index.mjs ci", diff --git a/pkg/core/package.json b/pkg/core/package.json index 5b2b021c..2877cf30 100644 --- a/pkg/core/package.json +++ b/pkg/core/package.json @@ -23,7 +23,8 @@ "types": "./build/esm/src/*.d.ts", "default": "./build/esm/src/*.js" } - } + }, + "./package.json": "./package.json" }, "publishConfig": { "access": "public" diff --git a/pkg/core/src/lexer.ts b/pkg/core/src/lexer.ts index f03d2ba1..f1df100b 100644 --- a/pkg/core/src/lexer.ts +++ b/pkg/core/src/lexer.ts @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: 2024 Dyne.org foundation // // SPDX-License-Identifier: AGPL-3.0-or-later +// read the version from the package.json +import packageJson from '@slangroom/core/package.json' assert { type: 'json' }; /** * A whitespace-separated string of characters with position information. @@ -87,7 +89,7 @@ export class Token { export class LexError extends Error { constructor(t: Token) { super(); - this.name = 'LexError'; + this.name = 'LexError @slangroom/core@' + packageJson.version; this.message = `at ${t.lineNo}:${t.start + 1}-${t.end + 1}\n unclosed single-quote \x1b[31m${t.raw}\x1b[0m`; } } diff --git a/pkg/core/src/parser.ts b/pkg/core/src/parser.ts index 73345867..1745d2cf 100644 --- a/pkg/core/src/parser.ts +++ b/pkg/core/src/parser.ts @@ -3,6 +3,8 @@ // SPDX-License-Identifier: AGPL-3.0-or-later import { PluginMap, Token, type PluginMapKey } from '@slangroom/core'; +// read the version from the package.json +import packageJson from '@slangroom/core/package.json' assert { type: 'json' }; export const errorColor = (s: string): string => '\x1b[31m' + s + '\x1b[0m'; export const suggestedColor = (s: string): string => '\x1b[32m' + s + '\x1b[0m'; @@ -107,7 +109,7 @@ export class ParseError extends Error { */ constructor(message: string) { super(message); - this.name = 'ParseError'; + this.name = 'ParseError @slangroom/core@' + packageJson.version; } } diff --git a/pkg/core/test/errors.ts b/pkg/core/test/errors.ts index 72410e00..54614392 100644 --- a/pkg/core/test/errors.ts +++ b/pkg/core/test/errors.ts @@ -1,6 +1,8 @@ import { Plugin, Slangroom } from '@slangroom/core'; import test from 'ava'; +// read the version from the package.json +import packageJson from '@slangroom/core/package.json' assert { type: 'json' }; // error colors import { errorColor, suggestedColor, missingColor, extraColor } from '@slangroom/core'; @@ -27,25 +29,25 @@ Error colors: - ${missingColor('missing words')} - ${extraColor('extra words')} -ParseError: at 2:9-17 +ParseError @slangroom/core@${packageJson.version}: at 2:9-17 ${errorColor('gibberish')} may be ${suggestedColor('send')} -ParseError: at 2:9-17 +ParseError @slangroom/core@${packageJson.version}: at 2:9-17 must be followed by one of: ${missingColor('param')} -ParseError: at 2 +ParseError @slangroom/core@${packageJson.version}: at 2 missing one of: ${missingColor('\'\'')} -ParseError: at 2 +ParseError @slangroom/core@${packageJson.version}: at 2 missing one of: ${missingColor('and')} -ParseError: at 2 +ParseError @slangroom/core@${packageJson.version}: at 2 missing one of: ${missingColor('do')} -ParseError: at 2 +ParseError @slangroom/core@${packageJson.version}: at 2 missing one of: ${missingColor('some')} -ParseError: at 2 +ParseError @slangroom/core@${packageJson.version}: at 2 missing one of: ${missingColor('action')} ` @@ -75,7 +77,7 @@ Error colors: - ${missingColor('missing words')} - ${extraColor('extra words')} -LexError: at 2:20-44 +LexError @slangroom/core@${packageJson.version}: at 2:20-44 unclosed single-quote ${errorColor('\'param and do some action')} ` @@ -106,46 +108,46 @@ Error colors: - ${missingColor('missing words')} - ${extraColor('extra words')} -ParseError: at 2:1-9 +ParseError @slangroom/core@${packageJson.version}: at 2:1-9 ${errorColor('Gibberish')} may be ${suggestedColor('given')} or ${suggestedColor('then')} -ParseError: at 2:11-17 +ParseError @slangroom/core@${packageJson.version}: at 2:11-17 ${errorColor('connect')} may be ${suggestedColor('I')} -ParseError: at 2:19-20 +ParseError @slangroom/core@${packageJson.version}: at 2:19-20 ${errorColor('to')} may be ${suggestedColor('connect')} -ParseError: at 2:22-26 +ParseError @slangroom/core@${packageJson.version}: at 2:22-26 ${errorColor('\'url\'')} may be ${suggestedColor('to')} -ParseError: at 2:28-30 +ParseError @slangroom/core@${packageJson.version}: at 2:28-30 ${errorColor('and')} may be ${suggestedColor('\'\'')} -ParseError: at 2:32-35 +ParseError @slangroom/core@${packageJson.version}: at 2:32-35 ${errorColor('send')} may be ${suggestedColor('and')} -ParseError: at 2:37-41 +ParseError @slangroom/core@${packageJson.version}: at 2:37-41 ${errorColor('param')} may be ${suggestedColor('send')} -ParseError: at 2:43-49 +ParseError @slangroom/core@${packageJson.version}: at 2:43-49 ${errorColor('\'param\'')} may be ${suggestedColor('param')} -ParseError: at 2:51-53 +ParseError @slangroom/core@${packageJson.version}: at 2:51-53 ${errorColor('and')} may be ${suggestedColor('\'\'')} -ParseError: at 2:55-56 +ParseError @slangroom/core@${packageJson.version}: at 2:55-56 ${errorColor('do')} may be ${suggestedColor('and')} -ParseError: at 2:58-61 +ParseError @slangroom/core@${packageJson.version}: at 2:58-61 ${errorColor('some')} may be ${suggestedColor('do')} -ParseError: at 2:63-68 +ParseError @slangroom/core@${packageJson.version}: at 2:63-68 ${errorColor('action')} may be ${suggestedColor('some')} -ParseError: at 2:70-72 +ParseError @slangroom/core@${packageJson.version}: at 2:70-72 ${errorColor('and')} may be ${suggestedColor('action')} -ParseError: at 2:74-84 +ParseError @slangroom/core@${packageJson.version}: at 2:74-84 extra token ${extraColor('aoibndwebnd')} ` diff --git a/pkg/db/package.json b/pkg/db/package.json index cec1007d..3442d49d 100644 --- a/pkg/db/package.json +++ b/pkg/db/package.json @@ -23,7 +23,8 @@ "types": "./build/esm/src/*.d.ts", "default": "./build/esm/src/*.js" } - } + }, + "./package.json": "./package.json" }, "publishConfig": { "access": "public" diff --git a/pkg/db/src/plugin.ts b/pkg/db/src/plugin.ts index a5f16e6c..564308e7 100644 --- a/pkg/db/src/plugin.ts +++ b/pkg/db/src/plugin.ts @@ -4,6 +4,8 @@ import { Plugin } from '@slangroom/core'; import { BindOrReplacements, DataTypes, Model, Sequelize } from "sequelize"; +// read the version from the package.json +import packageJson from '@slangroom/db/package.json' assert { type: 'json' }; class Result extends Model { public result!: string; @@ -12,7 +14,7 @@ class Result extends Model { export class DbError extends Error { constructor(e: string) { super(e) - this.name = 'Slangroom @slangroom/db Error' + this.name = 'Slangroom @slangroom/db@' + packageJson.version + ' Error' } } diff --git a/pkg/db/test/e2e.ts b/pkg/db/test/e2e.ts index 6a8d139c..589df82a 100644 --- a/pkg/db/test/e2e.ts +++ b/pkg/db/test/e2e.ts @@ -7,6 +7,8 @@ import { Slangroom } from '@slangroom/core'; import { db } from '@slangroom/db'; import { DataTypes, Model, Sequelize } from 'sequelize'; import fs from "fs"; +// read the version from the package.json +import packageJson from '@slangroom/db/package.json' assert { type: 'json' }; process.env['FILES_DIR'] = "./test"; const dbPath1 = "sqlite://./test/db1.db"; @@ -210,7 +212,7 @@ Error colors: - missing words - extra words -Slangroom @slangroom/db Error: [DATABASE] +Slangroom @slangroom/db@${packageJson.version} Error: [DATABASE] Returned null for id "30" in table "firstTable" in db "sqlite://./test/db1.db". `); }); @@ -262,6 +264,6 @@ Error colors: - missing words - extra words -Slangroom @slangroom/db Error: [DATABASE] Database error: TypeError: Cannot read properties of null (reading 'replace') +Slangroom @slangroom/db@${packageJson.version} Error: [DATABASE] Database error: TypeError: Cannot read properties of null (reading 'replace') `); }); diff --git a/pkg/db/test/raw_query.ts b/pkg/db/test/raw_query.ts index 277b2f2b..caec2fd0 100644 --- a/pkg/db/test/raw_query.ts +++ b/pkg/db/test/raw_query.ts @@ -6,6 +6,8 @@ import test from "ava"; import { Slangroom } from '@slangroom/core'; import { db } from '@slangroom/db'; import sqlite3 from "sqlite3"; +// read the version from the package.json +import packageJson from '@slangroom/db/package.json' assert { type: 'json' }; const stripAnsiCodes = (str: string) => str.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, ''); @@ -20,7 +22,7 @@ test('Db should execute raw queries', async (t) => { Given I have a 'string dictionary' named 'result_1' Given I have a 'string dictionary' named 'result_2' Given I have a 'string dictionary' named 'result_3' - Given I have a 'string dictionary' named 'result_4' + Given I have a 'string array' named 'result_4' Given I have a 'string dictionary' named 'result_5' Given I have a 'string dictionary' named 'result_6' Then print all data @@ -111,7 +113,7 @@ Error colors: - missing words - extra words -Slangroom @slangroom/db Error: SQLITE_ERROR: no such table: member +Slangroom @slangroom/db@${packageJson.version} Error: SQLITE_ERROR: no such table: member `); }); @@ -148,6 +150,6 @@ Error colors: - missing words - extra words -Slangroom @slangroom/db Error: SQLITE_ERROR: near "INSTERT": syntax error +Slangroom @slangroom/db@${packageJson.version} Error: SQLITE_ERROR: near "INSTERT": syntax error `); }); diff --git a/pkg/ethereum/package.json b/pkg/ethereum/package.json index 28821669..a5278530 100644 --- a/pkg/ethereum/package.json +++ b/pkg/ethereum/package.json @@ -25,7 +25,8 @@ "types": "./build/esm/src/*.d.ts", "default": "./build/esm/src/*.js" } - } + }, + "./package.json": "./package.json" }, "publishConfig": { "access": "public" diff --git a/pkg/ethereum/src/plugin.ts b/pkg/ethereum/src/plugin.ts index 5b2e63d4..38c56360 100644 --- a/pkg/ethereum/src/plugin.ts +++ b/pkg/ethereum/src/plugin.ts @@ -6,13 +6,15 @@ import { Plugin, type PluginExecutor } from '@slangroom/core'; import { erc20abi } from '@slangroom/ethereum'; import { Web3 } from 'web3'; import { isAddress } from 'web3-validator'; +// read the version from the package.json +import packageJson from '@slangroom/ethereum/package.json' assert { type: 'json' }; const p = new Plugin(); export class EthereumError extends Error { constructor(e: string) { super(e) - this.name = 'Slangroom @slangroom/ethereum Error' + this.name = 'Slangroom @slangroom/ethereum@' + packageJson.version + ' Error' } } diff --git a/pkg/fs/package.json b/pkg/fs/package.json index 62e44d49..e7e950a4 100644 --- a/pkg/fs/package.json +++ b/pkg/fs/package.json @@ -32,7 +32,8 @@ "types": "./build/cjs/src/*.d.ts", "default": "./build/cjs/src/*.js" } - } + }, + "./package.json": "./package.json" }, "publishConfig": { "access": "public" diff --git a/pkg/fs/src/plugin.ts b/pkg/fs/src/plugin.ts index d780ae84..22ee5d69 100644 --- a/pkg/fs/src/plugin.ts +++ b/pkg/fs/src/plugin.ts @@ -9,11 +9,13 @@ import * as fspkg from 'node:fs/promises'; import * as os from 'node:os'; import axios from 'axios'; import extractZip from 'extract-zip'; +// read the version from the package.json +import packageJson from '@slangroom/fs/package.json' assert { type: 'json' }; export class FsError extends Error { constructor(e: string) { super(e) - this.name = 'Slangroom @slangroom/fs Error' + this.name = 'Slangroom @slangroom/fs@' + packageJson.version + ' Error' } } diff --git a/pkg/fs/test/e2e.ts b/pkg/fs/test/e2e.ts index 2192400d..b38861af 100644 --- a/pkg/fs/test/e2e.ts +++ b/pkg/fs/test/e2e.ts @@ -5,6 +5,8 @@ import test from 'ava'; import { Slangroom } from '@slangroom/core'; import { fs } from '@slangroom/fs'; +// read the version from the package.json +import packageJson from '@slangroom/fs/package.json' assert { type: 'json' }; const stripAnsiCodes = (str: string) => str.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, ''); @@ -37,7 +39,7 @@ Error colors: - missing words - extra words -Slangroom @slangroom/fs Error: $FILES_DIR must be provided +Slangroom @slangroom/fs@${packageJson.version} Error: $FILES_DIR must be provided `); }); @@ -62,7 +64,7 @@ Error colors: - missing words - extra words -Slangroom @slangroom/fs Error: ENOENT: no such file or directory, open 'test.txt' +Slangroom @slangroom/fs@${packageJson.version} Error: ENOENT: no such file or directory, open 'test.txt' `); }); @@ -105,7 +107,7 @@ Error colors: - missing words - extra words -Slangroom @slangroom/fs Error: path must be string +Slangroom @slangroom/fs@${packageJson.version} Error: path must be string `); }); @@ -147,7 +149,7 @@ Error colors: - missing words - extra words -Slangroom @slangroom/fs Error: no such file or directory: test/test_not_exist.txt +Slangroom @slangroom/fs@${packageJson.version} Error: no such file or directory: test/test_not_exist.txt `); }); @@ -179,7 +181,7 @@ Error colors: - missing words - extra words -Slangroom @slangroom/fs Error: file or directory found under: test/test.txt +Slangroom @slangroom/fs@${packageJson.version} Error: file or directory found under: test/test.txt `); const resultNotExists = slangroom.execute(verifyDoesNotExists, { data: { diff --git a/pkg/git/package.json b/pkg/git/package.json index 32f9021b..2daa9966 100644 --- a/pkg/git/package.json +++ b/pkg/git/package.json @@ -30,7 +30,8 @@ "types": "./build/cjs/src/*.d.ts", "default": "./build/cjs/src/*.js" } - } + }, + "./package.json": "./package.json" }, "publishConfig": { "access": "public" diff --git a/pkg/git/src/plugin.ts b/pkg/git/src/plugin.ts index 8f3f5abf..c3b1d8fb 100644 --- a/pkg/git/src/plugin.ts +++ b/pkg/git/src/plugin.ts @@ -8,11 +8,13 @@ import gitpkg from 'isomorphic-git'; import http from 'isomorphic-git/http/node/index.js'; import * as fs from 'node:fs/promises'; import * as path from 'node:path'; +// read the version from the package.json +import packageJson from '@slangroom/git/package.json' assert { type: 'json' }; export class GitError extends Error { constructor(e: string) { super(e) - this.name = 'Slangroom @slangroom/git Error' + this.name = 'Slangroom @slangroom/git@' + packageJson.version + ' Error' } } diff --git a/pkg/helpers/package.json b/pkg/helpers/package.json index 566bcfc9..4bd3d8aa 100644 --- a/pkg/helpers/package.json +++ b/pkg/helpers/package.json @@ -24,7 +24,8 @@ "types": "./build/esm/src/*.d.ts", "default": "./build/esm/src/*.js" } - } + }, + "./package.json": "./package.json" }, "publishConfig": { "access": "public" diff --git a/pkg/helpers/src/plugin.ts b/pkg/helpers/src/plugin.ts index 6575e8ea..bd46b511 100644 --- a/pkg/helpers/src/plugin.ts +++ b/pkg/helpers/src/plugin.ts @@ -4,13 +4,15 @@ import { Plugin } from '@slangroom/core'; import _ from 'lodash'; +// read the version from the package.json +import packageJson from '@slangroom/helpers/package.json' assert { type: 'json' }; const p = new Plugin() class HelperError extends Error { constructor(e: Error) { super(e.message) - this.name = 'Slangroom @slangroom/helper Error' + this.name = 'Slangroom @slangroom/helper@' + packageJson.version + ' Error' } } diff --git a/pkg/helpers/test/concat.ts b/pkg/helpers/test/concat.ts index de19820a..7cf64815 100644 --- a/pkg/helpers/test/concat.ts +++ b/pkg/helpers/test/concat.ts @@ -5,6 +5,8 @@ import { Slangroom } from '@slangroom/core'; import { helpers } from '@slangroom/helpers'; import test from 'ava'; +// read the version from the package.json +import packageJson from '@slangroom/helpers/package.json' assert { type: 'json' }; const stripAnsiCodes = (str: string) => str.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, ''); @@ -65,7 +67,7 @@ Error colors: - missing words - extra words -ParseError: at 2:51-56 +ParseError @slangroom/core@${packageJson.version}: at 2:51-56 concat may be compact `); }); diff --git a/pkg/helpers/test/pick.ts b/pkg/helpers/test/pick.ts index ffa0bd54..a4c2117d 100644 --- a/pkg/helpers/test/pick.ts +++ b/pkg/helpers/test/pick.ts @@ -5,6 +5,8 @@ import { Slangroom } from '@slangroom/core'; import { helpers } from '@slangroom/helpers'; import test from 'ava'; +// read the version from the package.json +import packageJson from '@slangroom/helpers/package.json' assert { type: 'json' }; const stripAnsiCodes = (str: string) => str.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, ''); @@ -190,7 +192,7 @@ Error colors: - missing words - extra words -Slangroom @slangroom/helper Error: MANIPULATION ERRROR: +Slangroom @slangroom/helper@${packageJson.version} Error: MANIPULATION ERRROR: None of the properties "a" diff --git a/pkg/http/package.json b/pkg/http/package.json index a413cc29..dba5ab26 100644 --- a/pkg/http/package.json +++ b/pkg/http/package.json @@ -23,7 +23,8 @@ "types": "./build/esm/src/*.d.ts", "default": "./build/esm/src/*.js" } - } + }, + "./package.json": "./package.json" }, "publishConfig": { "access": "public" diff --git a/pkg/http/src/plugin.ts b/pkg/http/src/plugin.ts index a8667e90..6bb4aaa0 100644 --- a/pkg/http/src/plugin.ts +++ b/pkg/http/src/plugin.ts @@ -5,11 +5,13 @@ import type { JsonableArray, JsonableObject } from '@slangroom/shared'; import { Plugin, type PluginExecutor } from '@slangroom/core'; import axios, { type AxiosRequestConfig } from 'axios'; +// read the version from the package.json +import packageJson from '@slangroom/http/package.json' assert { type: 'json' }; export class HttpError extends Error { constructor(message: string) { super(message); - this.name = 'Slangroom @slangroom/http Error'; + this.name = 'Slangroom @slangroom/http@' + packageJson.version + ' Error'; } } diff --git a/pkg/http/test/e2e.ts b/pkg/http/test/e2e.ts index 50d704c4..24bd2dbc 100644 --- a/pkg/http/test/e2e.ts +++ b/pkg/http/test/e2e.ts @@ -6,6 +6,8 @@ import test from 'ava'; import nock from 'nock'; import { Slangroom } from '@slangroom/core'; import { http } from '@slangroom/http'; +// read the version from the package.json +import packageJson from '@slangroom/http/package.json' assert { type: 'json' }; const stripAnsiCodes = (str: string) => str.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, ''); @@ -123,6 +125,6 @@ Error colors: - missing words - extra words -Slangroom @slangroom/http Error: sequential requests are not implemented +Slangroom @slangroom/http@${packageJson.version} Error: sequential requests are not implemented `); }); diff --git a/pkg/ignored/package.json b/pkg/ignored/package.json index 4003d5d5..34fb06a5 100644 --- a/pkg/ignored/package.json +++ b/pkg/ignored/package.json @@ -22,7 +22,8 @@ "types": "./build/esm/src/*.d.ts", "default": "./build/esm/src/*.js" } - } + }, + "./package.json": "./package.json" }, "publishConfig": { "access": "public" diff --git a/pkg/ignored/src/index.ts b/pkg/ignored/src/index.ts index 3c1188e9..60f71d63 100644 --- a/pkg/ignored/src/index.ts +++ b/pkg/ignored/src/index.ts @@ -3,6 +3,8 @@ // SPDX-License-Identifier: AGPL-3.0-or-later import { zencodeParse } from '@slangroom/shared'; +// read the version from the package.json +import packageJson from '@slangroom/ignored/package.json' assert { type: 'json' }; /** * Represent zencode invalid statement error @@ -11,7 +13,7 @@ export class InvalidStatementError extends Error { constructor(e: string, couldBeIgnore: boolean) { if (couldBeIgnore) e = 'Maybe missing: \x1b[35mRule unknown ignore\x1b[0m\n' + e; super(e); - this.name = 'Zencode Invalid Statement Error'; + this.name = 'Zencode Invalid Statement @slangroom/ignored@' + packageJson.version + ' Error'; } } diff --git a/pkg/json-schema/package.json b/pkg/json-schema/package.json index 99171d74..9092e50d 100644 --- a/pkg/json-schema/package.json +++ b/pkg/json-schema/package.json @@ -4,7 +4,7 @@ "dependencies": { "@slangroom/core": "workspace:*", "@slangroom/shared": "workspace:*", - "ajv": "^8.12.0" + "ajv": "^8.13.0" }, "repository": "https://github.com/dyne/slangroom", "license": "AGPL-3.0-only", @@ -23,7 +23,8 @@ "types": "./build/esm/src/*.d.ts", "default": "./build/esm/src/*.js" } - } + }, + "./package.json": "./package.json" }, "publishConfig": { "access": "public" diff --git a/pkg/json-schema/src/plugin.ts b/pkg/json-schema/src/plugin.ts index a8a2d0f5..3477041a 100644 --- a/pkg/json-schema/src/plugin.ts +++ b/pkg/json-schema/src/plugin.ts @@ -3,14 +3,16 @@ // SPDX-License-Identifier: AGPL-3.0-or-later import { Plugin } from '@slangroom/core'; -import Ajv, { type ValidationError } from 'ajv'; +import { Ajv, type ValidationError } from 'ajv'; +// read the version from the package.json +import packageJson from '@slangroom/json-schema/package.json' assert { type: 'json' }; export { ValidationError }; export class JsonSchemaError extends Error { constructor(message: string) { super(message); - this.name = 'Slangroom @slangroom/json-schema Error'; + this.name = 'Slangroom @slangroom/json-schema@' + packageJson.version + ' Error'; } } @@ -37,7 +39,7 @@ export const validateJSON = p.new( const schema = ctx.fetch(ARG_JSON_SCHEMA); try { - const ajv = new Ajv.default({ allErrors: true }); + const ajv = new Ajv({ allErrors: true }); // @ts-ignore const validate = ajv.compile(schema); diff --git a/pkg/oauth/package.json b/pkg/oauth/package.json index a2cdbfaf..53093e30 100644 --- a/pkg/oauth/package.json +++ b/pkg/oauth/package.json @@ -25,7 +25,8 @@ "types": "./build/esm/src/*.d.ts", "default": "./build/esm/src/*.js" } - } + }, + "./package.json": "./package.json" }, "publishConfig": { "access": "public" diff --git a/pkg/oauth/src/plugin.ts b/pkg/oauth/src/plugin.ts index 1220df1e..74e8dae2 100644 --- a/pkg/oauth/src/plugin.ts +++ b/pkg/oauth/src/plugin.ts @@ -8,11 +8,13 @@ import { Request, Response } from '@node-oauth/oauth2-server'; import { AuthenticateHandler, InMemoryCache, AuthorizeHandler } from '@slangroom/oauth'; import { JsonableObject } from '@slangroom/shared'; import { JWK } from 'jose'; +// read the version from the package.json +import packageJson from '@slangroom/oauth/package.json' assert { type: 'json' }; export class OauthError extends Error { constructor(message: string) { super(message); - this.name = 'Slangroom @slangroom/oauth Error'; + this.name = 'Slangroom @slangroom/oauth@' + packageJson.version + ' Error'; } } diff --git a/pkg/pocketbase/package.json b/pkg/pocketbase/package.json index 3ae3c0b1..f1574b69 100644 --- a/pkg/pocketbase/package.json +++ b/pkg/pocketbase/package.json @@ -26,7 +26,8 @@ "types": "./build/esm/src/*.d.ts", "default": "./build/esm/src/*.js" } - } + }, + "./package.json": "./package.json" }, "publishConfig": { "access": "public" diff --git a/pkg/pocketbase/src/plugin.ts b/pkg/pocketbase/src/plugin.ts index c6ebc079..0e447a9c 100644 --- a/pkg/pocketbase/src/plugin.ts +++ b/pkg/pocketbase/src/plugin.ts @@ -7,11 +7,13 @@ import type { FullListOptions, ListResult, RecordModel, RecordOptions } from 'po import { Plugin } from '@slangroom/core'; import { z } from 'zod'; import { Preferences } from '@capacitor/preferences'; +// read the version from the package.json +import packageJson from '@slangroom/pocketbase/package.json' assert { type: 'json' }; export class PocketBaseError extends Error { constructor(message: string) { super(message); - this.name = 'Slangroom @slangroom/pocketbase Error'; + this.name = 'Slangroom @slangroom/pocketbase@' + packageJson.version + ' Error'; } } diff --git a/pkg/pocketbase/test/e2e.ts b/pkg/pocketbase/test/e2e.ts index 1097bf87..86a298e2 100644 --- a/pkg/pocketbase/test/e2e.ts +++ b/pkg/pocketbase/test/e2e.ts @@ -15,6 +15,8 @@ import { pocketbase } from '@slangroom/pocketbase'; import test from 'ava'; import { Slangroom } from '@slangroom/core'; import { JsonableObject } from '@slangroom/shared'; +// read the version from the package.json +import packageJson from '@slangroom/pocketbase/package.json' assert { type: 'json' }; const stripAnsiCodes = (str: string) => str.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, ''); @@ -70,7 +72,7 @@ Error colors: - missing words - extra words -Slangroom @slangroom/pocketbase Error: Can not start capacitor client in node environment +Slangroom @slangroom/pocketbase@${packageJson.version} Error: Can not start capacitor client in node environment `); }); diff --git a/pkg/qrcode/package.json b/pkg/qrcode/package.json index 2395fa26..9d5d408c 100644 --- a/pkg/qrcode/package.json +++ b/pkg/qrcode/package.json @@ -22,7 +22,8 @@ "types": "./build/esm/src/*.d.ts", "default": "./build/esm/src/*.js" } - } + }, + "./package.json": "./package.json" }, "publishConfig": { "access": "public" diff --git a/pkg/qrcode/src/plugin.ts b/pkg/qrcode/src/plugin.ts index 7a469ddb..c4656621 100644 --- a/pkg/qrcode/src/plugin.ts +++ b/pkg/qrcode/src/plugin.ts @@ -4,11 +4,13 @@ import { Plugin } from '@slangroom/core'; import QrCode from 'qrcode' +// read the version from the package.json +import packageJson from '@slangroom/qrcode/package.json' assert { type: 'json' }; export class QrCodeError extends Error { constructor(message: string) { super(message); - this.name = 'Slangroom @slangroom/qrcode Error'; + this.name = 'Slangroom @slangroom/qrcode@' + packageJson.version + ' Error'; } } diff --git a/pkg/redis/package.json b/pkg/redis/package.json index 93ecd8bb..778ad99b 100644 --- a/pkg/redis/package.json +++ b/pkg/redis/package.json @@ -23,7 +23,8 @@ "types": "./build/esm/src/*.d.ts", "default": "./build/esm/src/*.js" } - } + }, + "./package.json": "./package.json" }, "publishConfig": { "access": "public" diff --git a/pkg/redis/src/plugin.ts b/pkg/redis/src/plugin.ts index b83843c9..c0b34673 100644 --- a/pkg/redis/src/plugin.ts +++ b/pkg/redis/src/plugin.ts @@ -5,11 +5,13 @@ import { Plugin, PluginContext } from '@slangroom/core'; import type { JsonableObject } from '@slangroom/shared'; import * as redisClient from "@redis/client"; +// read the version from the package.json +import packageJson from '@slangroom/redis/package.json' assert { type: 'json' }; export class RedisError extends Error { constructor(message: string) { super(message); - this.name = 'Slangroom @slangroom/redis Error'; + this.name = 'Slangroom @slangroom/redis@' + packageJson.version + ' Error'; } } diff --git a/pkg/shell/package.json b/pkg/shell/package.json index 35eebdfc..6e27daec 100644 --- a/pkg/shell/package.json +++ b/pkg/shell/package.json @@ -22,7 +22,8 @@ "types": "./build/esm/src/*.d.ts", "default": "./build/esm/src/*.js" } - } + }, + "./package.json": "./package.json" }, "publishConfig": { "access": "public" diff --git a/pkg/shell/src/plugin.ts b/pkg/shell/src/plugin.ts index 7b7dc0a3..be54a30a 100644 --- a/pkg/shell/src/plugin.ts +++ b/pkg/shell/src/plugin.ts @@ -3,12 +3,14 @@ // SPDX-License-Identifier: AGPL-3.0-or-later import { Plugin } from '@slangroom/core'; -import { execaCommand } from 'execa' +import { execaCommand } from 'execa'; +// read the version from the package.json +import packageJson from '@slangroom/shell/package.json' assert { type: 'json' }; export class ShellError extends Error { constructor(message: string) { super(message); - this.name = 'Slangroom @slangroom/shell Error'; + this.name = 'Slangroom @slangroom/shell@' + packageJson.version + ' Error'; } } diff --git a/pkg/shell/test/e2e.ts b/pkg/shell/test/e2e.ts index 582bc2e1..60182854 100644 --- a/pkg/shell/test/e2e.ts +++ b/pkg/shell/test/e2e.ts @@ -6,6 +6,8 @@ import test from 'ava'; import { Slangroom } from '@slangroom/core'; import { shell } from '@slangroom/shell'; import { $ } from 'execa'; +// read the version from the package.json +import packageJson from '@slangroom/shell/package.json' assert { type: 'json' }; const stripAnsiCodes = (str: string) => str.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, ''); @@ -55,7 +57,7 @@ Error colors: - missing words - extra words -Slangroom @slangroom/shell Error: Command failed with ENOENT: notfound -v +Slangroom @slangroom/shell@${packageJson.version} Error: Command failed with ENOENT: notfound -v spawn notfound ENOENT `); }); @@ -88,7 +90,7 @@ Error colors: - missing words - extra words -Slangroom @slangroom/shell Error: Command failed with exit code 1: cat notfound.txt +Slangroom @slangroom/shell@${packageJson.version} Error: Command failed with exit code 1: cat notfound.txt cat: notfound.txt: No such file or directory `); }); diff --git a/pkg/wallet/package.json b/pkg/wallet/package.json index 052d12ce..f63227a8 100644 --- a/pkg/wallet/package.json +++ b/pkg/wallet/package.json @@ -26,7 +26,8 @@ "types": "./build/esm/src/*.d.ts", "default": "./build/esm/src/*.js" } - } + }, + "./package.json": "./package.json" }, "publishConfig": { "access": "public" diff --git a/pkg/wallet/src/plugin.ts b/pkg/wallet/src/plugin.ts index c72aacf6..e9232b5e 100644 --- a/pkg/wallet/src/plugin.ts +++ b/pkg/wallet/src/plugin.ts @@ -35,11 +35,13 @@ import { type VCClaims, } from '@meeco/sd-jwt-vc'; import type { JsonableArray, JsonableObject } from '@slangroom/shared'; +// read the version from the package.json +import packageJson from '@slangroom/wallet/package.json' assert { type: 'json' }; export class WalletError extends Error { constructor(message: string) { super(message); - this.name = 'Slangroom @slangroom/wallet Error'; + this.name = 'Slangroom @slangroom/wallet@' + packageJson.version + ' Error'; } } diff --git a/pkg/zencode/package.json b/pkg/zencode/package.json index b78dba76..5ced3d8c 100644 --- a/pkg/zencode/package.json +++ b/pkg/zencode/package.json @@ -22,7 +22,8 @@ "types": "./build/esm/src/*.d.ts", "default": "./build/esm/src/*.js" } - } + }, + "./package.json": "./package.json" }, "publishConfig": { "access": "public" diff --git a/pkg/zencode/src/plugin.ts b/pkg/zencode/src/plugin.ts index cf5a05d9..0f9f3289 100644 --- a/pkg/zencode/src/plugin.ts +++ b/pkg/zencode/src/plugin.ts @@ -5,11 +5,13 @@ import { Plugin } from '@slangroom/core'; import type { JsonableObject } from '@slangroom/shared'; import { zencodeExec } from '@slangroom/shared'; +// read the version from the package.json +import packageJson from '@slangroom/zencode/package.json' assert { type: 'json' }; export class ZencodeError extends Error { constructor(message: string) { super(message); - this.name = 'Slangroom @slangroom/zencode Error'; + this.name = 'Slangroom @slangroom/zencode@' + packageJson.version + ' Error'; } } diff --git a/pkg/zencode/test/e2e.ts b/pkg/zencode/test/e2e.ts index 8b3b63b6..3f2376eb 100644 --- a/pkg/zencode/test/e2e.ts +++ b/pkg/zencode/test/e2e.ts @@ -6,6 +6,8 @@ import test from 'ava'; import { Slangroom } from '@slangroom/core'; import { zencode } from '@slangroom/zencode'; import type { JsonableObject } from '@slangroom/shared'; +// read the version from the package.json +import packageJson from '@slangroom/zencode/package.json' assert { type: 'json' }; const stripAnsiCodes = (str: string) => str.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, ''); @@ -105,7 +107,7 @@ Error colors: - missing words - extra words -Slangroom @slangroom/zencode Error:`)) +Slangroom @slangroom/zencode@${packageJson.version} Error:`)) t.true(((error as Error).message).includes("[!] Zencode runtime error")); t.true(((error as Error).message).includes("Zencode line 2: Given I have the 'string' named 'variable_that_does_not_exists'")); }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dd19c786..f70f4b3b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -253,8 +253,8 @@ importers: specifier: workspace:* version: link:../shared ajv: - specifier: ^8.12.0 - version: 8.12.0 + specifier: ^8.13.0 + version: 8.13.0 pkg/oauth: dependencies: @@ -2572,8 +2572,8 @@ packages: uri-js: 4.4.1 dev: true - /ajv@8.12.0: - resolution: {integrity: sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==} + /ajv@8.13.0: + resolution: {integrity: sha512-PRA911Blj99jR5RMeTunVbNXMF6Lp4vZXnk5GQjcnUWUTsrXtekg/pnmFFI2u/I36Y/2bITGS30GZCXei6uNkA==} dependencies: fast-deep-equal: 3.1.3 json-schema-traverse: 1.0.0 @@ -6438,9 +6438,6 @@ packages: /sqlite3@5.1.7: resolution: {integrity: sha512-GGIyOiFaG+TUra3JIfkI/zGP8yZYLPQ0pl1bH+ODjiX57sPhrLU5sQJn1y9bDKZUFYkX1crlrPfSYt0BKKdkog==} requiresBuild: true - peerDependenciesMeta: - node-gyp: - optional: true dependencies: bindings: 1.5.0 node-addon-api: 7.1.0 diff --git a/tsconfig.json b/tsconfig.json index 73567624..779950e1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,9 +2,9 @@ "include": ["src/**/*", "test/**/*"], "compilerOptions": { "rootDir": ".", - "target": "es2016", - "module": "Node16", - "moduleResolution": "node16", + "target": "ESNext", + "module": "esnext", + "moduleResolution": "bundler", "incremental": true, "newLine": "lf", "declaration": true,