From 48fbade71bdf3c8ee3adf78bf65b7d604a6021ec Mon Sep 17 00:00:00 2001 From: FNI18300 <50654937+FNI18300@users.noreply.github.com> Date: Fri, 24 Oct 2025 08:53:45 +0200 Subject: [PATCH 1/2] Add issues/11256 behavior to track the version of extension in deployment --- .gitignore | 1 + assets/index.json | 1 + build/extension/prod-webpack.config.js | 26 +++++++++++++++++++++++++- package.json | 1 + 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 045b9df..cf52113 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ web/.classpath web/.project backend/.classpath backend/.project +assets/index.json.tmp diff --git a/assets/index.json b/assets/index.json index 9b7f784..4aec7c6 100644 --- a/assets/index.json +++ b/assets/index.json @@ -2,6 +2,7 @@ "plugins": [ { "name": "SampleExtension", + "version": "@@VERSION@@", "dependencies": [ "Toolbar" ] diff --git a/build/extension/prod-webpack.config.js b/build/extension/prod-webpack.config.js index 4ac7652..8e04886 100644 --- a/build/extension/prod-webpack.config.js +++ b/build/extension/prod-webpack.config.js @@ -1,17 +1,37 @@ const path = require("path"); +const fs = require("fs"); const createExtensionWebpackConfig = require('../../MapStore2/build/createExtensionWebpackConfig'); const CopyPlugin = require('copy-webpack-plugin'); const ZipPlugin = require('zip-webpack-plugin'); +const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const {name} = require('../../config'); const commons = require('./commons'); +// read version.txt and produce a temporary updated index.json +const versionFile = path.resolve(__dirname, "..", "..", "version.txt"); +const indexSrc = path.resolve(__dirname, "..", "..", "assets", "index.json"); +const tmpIndex = path.resolve(__dirname, "..", "..", "assets", "index.json.tmp"); + +try { + const versionText = fs.readFileSync(versionFile, 'utf8').trim().split('-')[1]; + const indexContent = JSON.parse(fs.readFileSync(indexSrc, 'utf8')); + if (Array.isArray(indexContent.plugins)) { + indexContent.plugins = indexContent.plugins.map(p => p && p.name === name ? { ...p, version: versionText } : p); + } + fs.writeFileSync(tmpIndex, JSON.stringify(indexContent, null, 4), 'utf8'); +} catch (e) { + // keep behavior silent here; build will fail later if necessary + console.error('Error updating index.json from version.txt:', e); +} + + // the build configuration for production allow to create the final zip file, compressed accordingly const plugins = [ new CopyPlugin([ { from: path.resolve(__dirname, "..", "..", "assets", "translations"), to: "translations" }, - { from: path.resolve(__dirname, "..", "..", "assets", "index.json"), to: "index.json" } + { from: tmpIndex, to: 'index.json' }, ]), new ZipPlugin({ filename: `${name}.zip`, @@ -22,6 +42,10 @@ const plugins = [ // other files have to be placed in the root, with the same name return path.basename(assetPath); } + }), + new CleanWebpackPlugin({ + cleanOnceBeforeBuildPatterns: [], + cleanAfterEveryBuildPatterns: [tmpIndex] }) ]; module.exports = createExtensionWebpackConfig({ prod: true, name, ...commons, plugins}); diff --git a/package.json b/package.json index c018ca3..422b904 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "babel-plugin-object-assign": "1.2.1", "babel-plugin-react-transform": "2.0.2", "babel-plugin-transform-imports": "2.0.0", + "clean-webpack-plugin": "^4.0.0", "copy-webpack-plugin": "5.0.2", "css-loader": "5.1.2", "css-minimizer-webpack-plugin": "3.0.2", From 1bb02202c99820dedaebadf0a737ad6b34b20d16 Mon Sep 17 00:00:00 2001 From: FNI18300 <50654937+FNI18300@users.noreply.github.com> Date: Mon, 15 Dec 2025 13:55:51 +0100 Subject: [PATCH 2/2] Use package.json to extract version instead of version.txt --- build/extension/prod-webpack.config.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/build/extension/prod-webpack.config.js b/build/extension/prod-webpack.config.js index 8e04886..96fccf7 100644 --- a/build/extension/prod-webpack.config.js +++ b/build/extension/prod-webpack.config.js @@ -9,13 +9,11 @@ const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const {name} = require('../../config'); const commons = require('./commons'); -// read version.txt and produce a temporary updated index.json -const versionFile = path.resolve(__dirname, "..", "..", "version.txt"); +// read version and produce a temporary updated index.json +const { version: versionText } = require('../../package.json'); const indexSrc = path.resolve(__dirname, "..", "..", "assets", "index.json"); const tmpIndex = path.resolve(__dirname, "..", "..", "assets", "index.json.tmp"); - try { - const versionText = fs.readFileSync(versionFile, 'utf8').trim().split('-')[1]; const indexContent = JSON.parse(fs.readFileSync(indexSrc, 'utf8')); if (Array.isArray(indexContent.plugins)) { indexContent.plugins = indexContent.plugins.map(p => p && p.name === name ? { ...p, version: versionText } : p); @@ -26,12 +24,11 @@ try { console.error('Error updating index.json from version.txt:', e); } - // the build configuration for production allow to create the final zip file, compressed accordingly const plugins = [ new CopyPlugin([ { from: path.resolve(__dirname, "..", "..", "assets", "translations"), to: "translations" }, - { from: tmpIndex, to: 'index.json' }, + { from: tmpIndex, to: 'index.json' } ]), new ZipPlugin({ filename: `${name}.zip`,