Skip to content

Commit

Permalink
Add support for building with Node/lts
Browse files Browse the repository at this point in the history
  • Loading branch information
arnautov-anton committed Jan 24, 2025
1 parent e3c2d29 commit e747d2c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
17 changes: 7 additions & 10 deletions scripts/bundle-cjs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import * as esbuild from 'esbuild';
import { replace } from 'esbuild-plugin-replace';
import getPackageVersion from "./getPackageVersion.mjs";
import getPackageVersion from './getPackageVersion.mjs';
import packageJson from '../package.json' with { type: 'json' };

// import.meta.dirname is not available before Node 20
const __dirname = dirname(fileURLToPath(import.meta.url));
Expand All @@ -25,12 +26,9 @@ const bundledDeps = [
'remark-gfm',
];

const packageJson = await import(resolve(__dirname, '../package.json'), {
assert: { type: 'json' },
});
const deps = Object.keys({
...packageJson.default.dependencies,
...packageJson.default.peerDependencies,
...packageJson.dependencies,
...packageJson.peerDependencies,
});
const external = deps.filter((dep) => !bundledDeps.includes(dep));

Expand All @@ -46,7 +44,6 @@ const cjsBundleConfig = {
sourcemap: 'linked',
};


// We build two CJS bundles: for browser and for node. The latter one can be
// used e.g. during SSR (although it makes little sence to SSR chat, but still
// nice for import not to break on server).
Expand All @@ -56,9 +53,9 @@ const bundles = ['browser', 'node'].map((platform) =>
entryNames: `[dir]/[name].${platform}`,
platform,
plugins: [
replace({
'__STREAM_CHAT_REACT_VERSION__': getPackageVersion(),
}),
replace({
__STREAM_CHAT_REACT_VERSION__: getPackageVersion(),
}),
],
}),
);
Expand Down
12 changes: 2 additions & 10 deletions scripts/getPackageVersion.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import { execSync } from 'node:child_process';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';

// import.meta.dirname is not available before Node 20
const __dirname = dirname(fileURLToPath(import.meta.url));

const packageJson = await import(resolve(__dirname, '../package.json'), {
assert: { type: 'json' },
});
import packageJson from '../package.json' with { type: 'json' };

// Get the latest version so that magic string __STREAM_CHAT_REACT_VERSION__ can be replaced with it in the source code (used for reporting purposes)
export default function getPackageVersion() {
Expand All @@ -23,7 +15,7 @@ export default function getPackageVersion() {
} catch (error) {
console.error(error);
console.warn('Could not get latest version from git tags, falling back to package.json');
version = packageJson.default.version;
version = packageJson.version;
}
}
console.log(`Determined the build package version to be ${version}`);
Expand Down

0 comments on commit e747d2c

Please sign in to comment.