Skip to content

Commit

Permalink
fix(javascript): use package version in rollup (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Mar 7, 2022
1 parent 72af690 commit f18d24b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
20 changes: 15 additions & 5 deletions clients/algoliasearch-client-javascript/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'fs';
import path from 'path';

import babel from '@rollup/plugin-babel';
Expand All @@ -9,16 +10,14 @@ 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/',
''
);
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 */`;
}

Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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,
Expand All @@ -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()] : [];
Expand Down
1 change: 0 additions & 1 deletion clients/algoliasearch-client-javascript/version.js

This file was deleted.

0 comments on commit f18d24b

Please sign in to comment.