Skip to content

Commit f18d24b

Browse files
authored
fix(javascript): use package version in rollup (#232)
1 parent 72af690 commit f18d24b

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

clients/algoliasearch-client-javascript/rollup.config.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fs from 'fs';
12
import path from 'path';
23

34
import babel from '@rollup/plugin-babel';
@@ -9,16 +10,14 @@ import ts from 'rollup-plugin-typescript2';
910

1011
import generatorConfig from '../../openapitools.json';
1112

12-
import { version } from './version';
13-
1413
// Retrieve package to build
1514
const client = process.env.CLIENT?.replace(
1615
'@experimental-api-clients-automation/',
1716
''
1817
);
1918
const UTILS = ['client-common', 'requester-browser-xhr', 'requester-node-http'];
2019

21-
function createLicence(name) {
20+
function createLicence(name, version) {
2221
return `/*! ${name}.umd.js | ${version} | © Algolia, inc. | https://github.com/algolia/algoliasearch-client-javascript */`;
2322
}
2423

@@ -113,7 +112,7 @@ function initPackagesConfig() {
113112
const availableClients = getAvailableClients();
114113

115114
if (availableClients.length === 0) {
116-
throw new Error(`No clients matching ${client}.`);
115+
throw new Error(`No clients matches '${client}'.`);
117116
}
118117

119118
return availableClients.flatMap((packageName) => {
@@ -169,6 +168,14 @@ const rollupConfig = [];
169168

170169
packagesConfig.forEach((packageConfig) => {
171170
const clientPath = path.resolve('packages', packageConfig.package);
171+
const clientPackage = JSON.parse(
172+
fs.readFileSync(path.resolve(clientPath, 'package.json'))
173+
);
174+
175+
if (!clientPackage) {
176+
throw new Error(`No package.json found for '${packageConfig.name}'`);
177+
}
178+
172179
const bundlers = createBundlers({
173180
output: packageConfig.output,
174181
clientPath,
@@ -183,7 +190,10 @@ packagesConfig.forEach((packageConfig) => {
183190

184191
if (isUmdBuild) {
185192
output.name = packageConfig.name;
186-
output.banner = createLicence(packageConfig.package);
193+
output.banner = createLicence(
194+
packageConfig.package,
195+
clientPackage.version
196+
);
187197
}
188198

189199
const compressorPlugins = isUmdBuild ? [terser()] : [];

clients/algoliasearch-client-javascript/version.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)