From f18d24be4c013f41749f8a36f8a078f7de12dc57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= <20689156+shortcuts@users.noreply.github.com> Date: Mon, 7 Mar 2022 15:45:47 +0100 Subject: [PATCH] fix(javascript): use package version in rollup (#232) --- .../rollup.config.js | 20 ++++++++++++++----- .../version.js | 1 - 2 files changed, 15 insertions(+), 6 deletions(-) delete mode 100644 clients/algoliasearch-client-javascript/version.js diff --git a/clients/algoliasearch-client-javascript/rollup.config.js b/clients/algoliasearch-client-javascript/rollup.config.js index b87f6acd7c..2b68794b3a 100644 --- a/clients/algoliasearch-client-javascript/rollup.config.js +++ b/clients/algoliasearch-client-javascript/rollup.config.js @@ -1,3 +1,4 @@ +import fs from 'fs'; import path from 'path'; import babel from '@rollup/plugin-babel'; @@ -9,8 +10,6 @@ import ts from 'rollup-plugin-typescript2'; import generatorConfig from '../../openapitools.json'; -import { version } from './version'; - // Retrieve package to build const client = process.env.CLIENT?.replace( '@experimental-api-clients-automation/', @@ -18,7 +17,7 @@ const client = process.env.CLIENT?.replace( ); const UTILS = ['client-common', 'requester-browser-xhr', 'requester-node-http']; -function createLicence(name) { +function createLicence(name, version) { return `/*! ${name}.umd.js | ${version} | © Algolia, inc. | https://github.com/algolia/algoliasearch-client-javascript */`; } @@ -113,7 +112,7 @@ function initPackagesConfig() { const availableClients = getAvailableClients(); if (availableClients.length === 0) { - throw new Error(`No clients matching ${client}.`); + throw new Error(`No clients matches '${client}'.`); } return availableClients.flatMap((packageName) => { @@ -169,6 +168,14 @@ const rollupConfig = []; packagesConfig.forEach((packageConfig) => { const clientPath = path.resolve('packages', packageConfig.package); + const clientPackage = JSON.parse( + fs.readFileSync(path.resolve(clientPath, 'package.json')) + ); + + if (!clientPackage) { + throw new Error(`No package.json found for '${packageConfig.name}'`); + } + const bundlers = createBundlers({ output: packageConfig.output, clientPath, @@ -183,7 +190,10 @@ packagesConfig.forEach((packageConfig) => { if (isUmdBuild) { output.name = packageConfig.name; - output.banner = createLicence(packageConfig.package); + output.banner = createLicence( + packageConfig.package, + clientPackage.version + ); } const compressorPlugins = isUmdBuild ? [terser()] : []; diff --git a/clients/algoliasearch-client-javascript/version.js b/clients/algoliasearch-client-javascript/version.js deleted file mode 100644 index 339c9bbf69..0000000000 --- a/clients/algoliasearch-client-javascript/version.js +++ /dev/null @@ -1 +0,0 @@ -export const version = '0.0.4';