From 922276d9ac5f51bd8d18bcf2f78597e8d1692a66 Mon Sep 17 00:00:00 2001 From: Dmytro Demchenko Date: Fri, 22 Nov 2024 13:58:14 +0200 Subject: [PATCH] refactor: update-versions.js script to use ESM (#446) --- packages/p2p-media-loader-core/package.json | 2 +- .../p2p-media-loader-core/src/utils/version.ts | 2 +- packages/p2p-media-loader-demo/package.json | 2 +- packages/p2p-media-loader-hlsjs/package.json | 2 +- packages/p2p-media-loader-shaka/package.json | 2 +- scripts/update-versions.js | 14 +++++++++----- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/p2p-media-loader-core/package.json b/packages/p2p-media-loader-core/package.json index a1ac6a49..bf9979d4 100644 --- a/packages/p2p-media-loader-core/package.json +++ b/packages/p2p-media-loader-core/package.json @@ -26,7 +26,7 @@ "ecdn", "cdn" ], - "version": "1.0.0", + "version": "2.1.0", "files": [ "dist", "lib", diff --git a/packages/p2p-media-loader-core/src/utils/version.ts b/packages/p2p-media-loader-core/src/utils/version.ts index e5bb80f6..e8682f14 100644 --- a/packages/p2p-media-loader-core/src/utils/version.ts +++ b/packages/p2p-media-loader-core/src/utils/version.ts @@ -1,2 +1,2 @@ -export const PACKAGE_VERSION = "1.0.0"; +export const PACKAGE_VERSION = "2.1.0"; diff --git a/packages/p2p-media-loader-demo/package.json b/packages/p2p-media-loader-demo/package.json index 9e2462f3..4fb85b42 100644 --- a/packages/p2p-media-loader-demo/package.json +++ b/packages/p2p-media-loader-demo/package.json @@ -26,7 +26,7 @@ "ecdn", "cdn" ], - "version": "0.0.0", + "version": "2.1.0", "type": "module", "files": [ "lib", diff --git a/packages/p2p-media-loader-hlsjs/package.json b/packages/p2p-media-loader-hlsjs/package.json index 2d1f9ed0..0f010cd7 100644 --- a/packages/p2p-media-loader-hlsjs/package.json +++ b/packages/p2p-media-loader-hlsjs/package.json @@ -1,6 +1,6 @@ { "name": "p2p-media-loader-hlsjs", - "version": "1.0.0", + "version": "2.1.0", "description": "P2P Media Loader hls.js integration", "license": "Apache-2.0", "author": "Novage", diff --git a/packages/p2p-media-loader-shaka/package.json b/packages/p2p-media-loader-shaka/package.json index 8209ca7a..a8025c9a 100644 --- a/packages/p2p-media-loader-shaka/package.json +++ b/packages/p2p-media-loader-shaka/package.json @@ -1,6 +1,6 @@ { "name": "p2p-media-loader-shaka", - "version": "1.0.0", + "version": "2.1.0", "description": "P2P Media Loader Shaka Player integration", "license": "Apache-2.0", "author": "Novage", diff --git a/scripts/update-versions.js b/scripts/update-versions.js index 78a59220..2744e75a 100644 --- a/scripts/update-versions.js +++ b/scripts/update-versions.js @@ -1,5 +1,9 @@ -const fs = require("fs"); -const path = require("path"); +import fs from "fs"; +import path from "path"; +import { fileURLToPath } from "url"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); const packages = [ "../packages/p2p-media-loader-core/package.json", @@ -11,7 +15,7 @@ const packages = [ const versionFile = "../packages/p2p-media-loader-core/src/utils/version.ts"; function updateVersionFile(versionFilePath, newVersion) { - const fullPath = path.resolve(versionFilePath); + const fullPath = path.resolve(__dirname, versionFilePath); let fileContent = fs.readFileSync(fullPath, "utf8"); fileContent = fileContent.replace(/"(.*?)"/, `"${newVersion}"`); @@ -20,8 +24,8 @@ function updateVersionFile(versionFilePath, newVersion) { } function updateVersion(packagePath, newVersion) { - const fullPath = path.resolve(packagePath); - const packageJson = require(fullPath); + const fullPath = path.resolve(__dirname, packagePath); + const packageJson = JSON.parse(fs.readFileSync(fullPath, "utf8")); const updatedPackageJson = { ...packageJson, version: newVersion }; fs.writeFileSync( fullPath,