From 9e28af615362d5367d345c281cd9274f57164891 Mon Sep 17 00:00:00 2001
From: Bartek Wrona <wrona@syncad.com>
Date: Tue, 18 Feb 2025 00:56:39 +0100
Subject: [PATCH 1/6] Initial definition of common pnpm config using pnpm
 catalogs feature

---
 pnpm-config/.npmrc              |  2 ++
 pnpm-config/pnpm-workspace.yaml | 24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+)
 create mode 100644 pnpm-config/.npmrc
 create mode 100644 pnpm-config/pnpm-workspace.yaml

diff --git a/pnpm-config/.npmrc b/pnpm-config/.npmrc
new file mode 100644
index 0000000..c09005d
--- /dev/null
+++ b/pnpm-config/.npmrc
@@ -0,0 +1,2 @@
+# https://gitlab.syncad.com/hive group specification, offering aggregated package view: https://gitlab.syncad.com/groups/hive/-/packages
+@hiveio:registry=https://gitlab.syncad.com/api/v4/groups/136/-/packages/npm/
diff --git a/pnpm-config/pnpm-workspace.yaml b/pnpm-config/pnpm-workspace.yaml
new file mode 100644
index 0000000..a6e4b6c
--- /dev/null
+++ b/pnpm-config/pnpm-workspace.yaml
@@ -0,0 +1,24 @@
+packages:
+  - ./* # maybe we can constrain it to some common subdirs
+
+catalogs:
+  # Can be referenced through "catalog:rollup-toolset"
+  rollup-toolset:
+    rollup: ^4.22.4
+    rollup-plugin-copy: ^3.5.0
+    rollup-plugin-dts: ^6.1.1
+    "@rollup/plugin-commonjs": ^27.0.0
+    "@rollup/plugin-node-resolve": ^15.3.0
+    "@rollup/plugin-replace": ^6.0.1
+
+  typedoc-toolset:
+    "typedoc": "0.27.3"
+    "typedoc-gitlab-wiki-theme": "^2.1.0"
+    "typedoc-plugin-markdown": "4.3.1"
+
+  typescript:
+    typescript: 5.7.3
+
+  # We can make also separate entries to allow choosing just a part of toolset defined above
+  rollup:
+    rollup: ^4.22.4
-- 
GitLab


From 5483b83c19ea671a35e9fd3cdea757334b9c8266 Mon Sep 17 00:00:00 2001
From: mtyszczak <mateusz.tyszczak@gmail.com>
Date: Tue, 18 Feb 2025 14:10:38 +0100
Subject: [PATCH 2/6] Add more catalogs to pnpm workspace

---
 pnpm-config/.npmrc              |  3 +++
 pnpm-config/pnpm-workspace.yaml | 26 ++++++++++++++++++++++----
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/pnpm-config/.npmrc b/pnpm-config/.npmrc
index c09005d..9f4565c 100644
--- a/pnpm-config/.npmrc
+++ b/pnpm-config/.npmrc
@@ -1,2 +1,5 @@
 # https://gitlab.syncad.com/hive group specification, offering aggregated package view: https://gitlab.syncad.com/groups/hive/-/packages
 @hiveio:registry=https://gitlab.syncad.com/api/v4/groups/136/-/packages/npm/
+
+# Enforce strict engine-versions from package.json
+engine-strict=true
diff --git a/pnpm-config/pnpm-workspace.yaml b/pnpm-config/pnpm-workspace.yaml
index a6e4b6c..ebf88f1 100644
--- a/pnpm-config/pnpm-workspace.yaml
+++ b/pnpm-config/pnpm-workspace.yaml
@@ -16,9 +16,27 @@ catalogs:
     "typedoc-gitlab-wiki-theme": "^2.1.0"
     "typedoc-plugin-markdown": "4.3.1"
 
-  typescript:
+  typescript-toolset:
     typescript: 5.7.3
+    tslib: ^2.8.1
+    tsx: ^4.19.2
+
+  proto-toolset:
+    protobufjs: ^7.2.5
+    ts-proto: ^1.172.0
+
+  playwright-toolset:
+    "@playwright/test": ^1.49.1
+    playwright: 1.49.1
+    http-server: ^14.1.1
+
+  husky:
+    husky: 8.0.3
+
+  terser:
+    terser: ^5.39.0
+
+  size-limit-toolset:
+    size-limit: ^11.1.6
+    "@size-limit/file": ^11.1.6
 
-  # We can make also separate entries to allow choosing just a part of toolset defined above
-  rollup:
-    rollup: ^4.22.4
-- 
GitLab


From 19a39f4df311c3f95385afad749ae86ba6d48724 Mon Sep 17 00:00:00 2001
From: mtyszczak <mateusz.tyszczak@gmail.com>
Date: Tue, 18 Feb 2025 14:17:24 +0100
Subject: [PATCH 3/6] Add terser script to ts common scripts

---
 ts-common/terser.ts | 66 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100644 ts-common/terser.ts

diff --git a/ts-common/terser.ts b/ts-common/terser.ts
new file mode 100644
index 0000000..275a18d
--- /dev/null
+++ b/ts-common/terser.ts
@@ -0,0 +1,66 @@
+import type { MinifyOptions } from "terser";
+import { minify } from "terser";
+import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
+import { resolve, join, dirname } from "node:path";
+import { fileURLToPath } from 'node:url';
+import { existsSync } from "node:fs";
+
+const __dirname = dirname(fileURLToPath(import.meta.url));
+
+const packageJsonLocation = join(process.cwd(), "package.json");
+const { files } = JSON.parse(readFileSync(packageJsonLocation, { encoding: "utf-8" }));
+
+// =============== #1 ANALYZE "files" in package.json and collect all .js sources ===============
+const jsSources: string[] = [];
+const analyzePath = (path: string) => {
+  if (!existsSync(path)) {
+    console.warn(`The path ${path} does not exist`);
+
+    return;
+  }
+
+  if (statSync(path).isFile()) {
+    if (path.endsWith(".js"))
+      jsSources.push(resolve(__dirname, path));
+
+    return;
+  }
+
+  for(const file of readdirSync(path, { withFileTypes: true }))
+    analyzePath(join(file.parentPath, file.name));
+}
+
+for(const file of files)
+  analyzePath(resolve(file));
+
+// =============== #2 Define terser minification configuration ===============
+
+const minifyOptions: MinifyOptions = {
+  compress: true,
+  mangle: false,
+  ecma: 2020,
+  ie8: false,
+  keep_classnames: true,
+  keep_fnames: true,
+  sourceMap: false,
+  format: {
+    inline_script: false,
+    comments: false,
+    max_line_len: 100
+  }
+};
+
+// =============== #3 Minify the files ===============
+
+for(const file of jsSources) {
+  const inputCode = readFileSync(file, { encoding: "utf-8" });
+
+  void minify(inputCode, minifyOptions).then(({ code }) => {
+    if (!code)
+      throw new Error(`Failed to minify the file ${file}`);
+
+    writeFileSync(file, code, { encoding: "utf-8" });
+
+    console.log(`Minified ${file}`);
+  });
+}
-- 
GitLab


From ac350708292497d1d1764a69c87de8208aa31d5b Mon Sep 17 00:00:00 2001
From: mtyszczak <mateusz.tyszczak@gmail.com>
Date: Tue, 18 Feb 2025 14:43:04 +0100
Subject: [PATCH 4/6] Use pnpm for publishing and packing purposes instead of
 npm

---
 scripts/bash/npm-helpers/npm_pack_package.sh | 2 +-
 scripts/bash/npm-helpers/npm_publish.sh      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/bash/npm-helpers/npm_pack_package.sh b/scripts/bash/npm-helpers/npm_pack_package.sh
index 54d2718..6ceb7a9 100755
--- a/scripts/bash/npm-helpers/npm_pack_package.sh
+++ b/scripts/bash/npm-helpers/npm_pack_package.sh
@@ -15,7 +15,7 @@ pushd "${SOURCE_DIR}" # move to the project directory (where package.json file i
 
 "${SCRIPTPATH}/npm_generate_version.sh" "${SOURCE_DIR}" "${REGISTRY_URL}" "${SCOPE}" "${PROJECT_NAME}" "${COMMIT_REF_PROTECTED}" "${COMMIT_TAG}"
 
-npm pack --pack-destination "${OUTPUT_DIR}" --json > "${OUTPUT_DIR}/built_package_info.json"
+pnpm pack --pack-destination "${OUTPUT_DIR}" --json > "${OUTPUT_DIR}/built_package_info.json"
 BUILT_PACKAGE_NAME=$(jq -r .[].filename "${OUTPUT_DIR}/built_package_info.json")
 {
   echo PACKAGE_SOURCE_DIR="${SOURCE_DIR}"
diff --git a/scripts/bash/npm-helpers/npm_publish.sh b/scripts/bash/npm-helpers/npm_publish.sh
index d48e3fb..e1a8bef 100755
--- a/scripts/bash/npm-helpers/npm_publish.sh
+++ b/scripts/bash/npm-helpers/npm_publish.sh
@@ -40,7 +40,7 @@ else
   set -e
   echo "Publishing ${NAME}@${VERSION} to tag ${PACKAGE_DIST_TAG}"
   # We are going to repack the tarball as there are registry-dependent data in each job for package.json
-  npm publish --access=public --tag "${PACKAGE_DIST_TAG}"
+  pnpm publish --access=public --tag "${PACKAGE_DIST_TAG}"
 fi
 
 popd
-- 
GitLab


From 25d6622de0c584a4b3280c18b6c4b97d3b828d5a Mon Sep 17 00:00:00 2001
From: mtyszczak <mateusz.tyszczak@gmail.com>
Date: Wed, 19 Feb 2025 13:50:03 +0100
Subject: [PATCH 5/6] Fix pnpm pack output generation skipping pnpm echo lines

---
 scripts/bash/npm-helpers/npm_pack_package.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/scripts/bash/npm-helpers/npm_pack_package.sh b/scripts/bash/npm-helpers/npm_pack_package.sh
index 6ceb7a9..04f1c4a 100755
--- a/scripts/bash/npm-helpers/npm_pack_package.sh
+++ b/scripts/bash/npm-helpers/npm_pack_package.sh
@@ -15,11 +15,11 @@ pushd "${SOURCE_DIR}" # move to the project directory (where package.json file i
 
 "${SCRIPTPATH}/npm_generate_version.sh" "${SOURCE_DIR}" "${REGISTRY_URL}" "${SCOPE}" "${PROJECT_NAME}" "${COMMIT_REF_PROTECTED}" "${COMMIT_TAG}"
 
-pnpm pack --pack-destination "${OUTPUT_DIR}" --json > "${OUTPUT_DIR}/built_package_info.json"
-BUILT_PACKAGE_NAME=$(jq -r .[].filename "${OUTPUT_DIR}/built_package_info.json")
+pnpm pack --pack-destination "${OUTPUT_DIR}" --json | tail -n +5 > "${OUTPUT_DIR}/built_package_info.json"
+BUILT_PACKAGE_NAME=$(jq -r .filename "${OUTPUT_DIR}/built_package_info.json")
 {
   echo PACKAGE_SOURCE_DIR="${SOURCE_DIR}"
-  echo BUILT_PACKAGE_PATH="${OUTPUT_DIR}/${BUILT_PACKAGE_NAME}"
+  echo BUILT_PACKAGE_PATH="${BUILT_PACKAGE_NAME}"
 } > "${SOURCE_DIR}/built_package_info.env"
 
 echo "built_package_info.env file contents:"
-- 
GitLab


From ed209c4ac8ed21c84d997e011f17ac6af53e4bf0 Mon Sep 17 00:00:00 2001
From: mtyszczak <mateusz.tyszczak@gmail.com>
Date: Wed, 19 Feb 2025 15:40:32 +0100
Subject: [PATCH 6/6] Add base tsconfig

---
 ts-common/tsconfig.base.json | 52 ++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 ts-common/tsconfig.base.json

diff --git a/ts-common/tsconfig.base.json b/ts-common/tsconfig.base.json
new file mode 100644
index 0000000..621da5c
--- /dev/null
+++ b/ts-common/tsconfig.base.json
@@ -0,0 +1,52 @@
+{
+  "compilerOptions": {
+    "emitDecoratorMetadata": true,
+    "resolveJsonModule": true,
+    "experimentalDecorators": true,
+
+    "incremental": false,
+
+    "target": "ES2020",
+    "lib": [
+      "DOM",
+      "ES2020"
+    ],
+    "module": "ES2020",
+    "moduleResolution": "bundler",
+
+    "noEmit": false,
+
+    "declaration": true,
+    "declarationMap": false,
+    "sourceMap": false,
+
+    "noImplicitAny": false,
+    "noLib": false,
+
+    "allowUnreachableCode": false,
+    "allowSyntheticDefaultImports": true,
+    "allowUnusedLabels": false,
+    "strictNullChecks": true,
+    "strictPropertyInitialization": true,
+    "noFallthroughCasesInSwitch": false,
+    "noImplicitReturns": true,
+    "noImplicitThis": true,
+    "noUnusedLocals": true,
+    "noUnusedParameters": true,
+
+    "removeComments": false,
+    "checkJs": false,
+    "strict": true,
+    "alwaysStrict": true,
+
+    "allowJs": false,
+
+    "esModuleInterop": true,
+
+    "noErrorTruncation": true,
+  },
+  "buildOptions": {
+    "force": true,
+    "verbose": true
+  }
+}
\ No newline at end of file
-- 
GitLab